2

I just obtained a WIFI camera. I need to develop a iPad application to send a url request to this camera and then play the mpeg4 streaming in the iPad.

After receiving the request, this camera send back network packets to iPad. At the beginning of each packet, it contain 8 bit of unsigned char which indicated the type of this packet, such as video or audio.

Since the NSData is in 16bit format, how can i obtain the first 8bit unsigned char and recognized the type of this packet?

I think i am in the wrong track. I should focus on packet layer and find out how to use C language to deal with network packet. However, i am not good in the C language now. Can any one tell me how to using C to control network packet.

Fan Wu
  • 237
  • 1
  • 4
  • 11
  • Objective-C is a superset of C. If you code in Objective-C, you should definitively learn a few more things on C. – Macmade Nov 16 '11 at 00:40
  • Thank you Macmade. I definitively need to learn more C programming. I missing too much basic conception in C. – Fan Wu Nov 16 '11 at 00:55
  • It's not that hard if you know how to code in Objective-C. Especially learn about pointer/pointers arithmetics, casts, intrinsic types, structures, dynamic memory allocation... Beeing a good C programmer will just make you a better Objective-C programmer. – Macmade Nov 16 '11 at 01:06

1 Answers1

1

If you are using a NSData object, you can use the bytes method to retrieve a pointer to the NSData contents.

This method returns a void pointer. You can assign it to whatever you want.

For instance:

unsigned char * x = [ myDataObject bytes ];

Will allow you to read the NSData contents byte per byte (8bits), as you've got a char pointer.

x[ 0 ] will be the first byte, x[ 1 ] the second, etc.

If you use another type, you'll get different results. For instance:

unsigned short int * x = [ myDataObject bytes ];

Assuming an unsigned short int is 16 bits on your platform (it might be different), you'll then access the NSData contents by 16bits.

In the last example, x[ 0 ] will be the first 16 bits, etc...

It's also the same with pointer arithmetic.

Macmade
  • 52,708
  • 13
  • 106
  • 123
  • Hi Macmade, I have tried this in my application. However, it just gave me the unreadable char. typedef struct { guchar content_type; gint media_header_length; } stSTREAM. This is the format at the beginning of packet. This is the reson why i do it in this way. – Fan Wu Nov 16 '11 at 02:22