avfoundation - streaming images over bonjour between two iOS device -


My goal is to bring the images captured from an iOS device through AVCpatureInput to the other in the stream.

Here's my current method:

1) Capture frame with video input

  - Capture capture (Capture Capture): (AVCaptureOutput *) Output Sample Buffer: (CMSampleBufferRef) Connection to sampleBuffer: (AVCaptureConnection *) Connection {/ * code to convert sampleBuffer into UIImage * / NSData * imageData = UIImageJPEGRepresentation (Image, 1.0); [Connection sendImage: image]; } Send the raw image to the network - Send to (Zero) ROI Image packet: (UIImage *) Image: Send  {// Encoded Packet NSData * imageData = UIImageJPEG Report (Image, 1.0); NSDTA * rawpackets = [NSKEADAirir archivesDataDhitAbject: imageData]; // Written Header: Length of raw packet int packet = [raw pocket length]; [Outgoing Datahop Appendbits: & amp; Packet length line length: size (int)]; [Outgoetabity appendamenta: rawpacket]; // Try typing to stream [self-writingoutingburststream]; }   

3) Read the data and read many bytes from

  // Change the image to the image to appear on the UIImageView of the available device. Stream in form and try to remove meaningful packets - (zero) readFromStreamIntoIncomingBuffer {// Temporary buffer UINT8 buf to read data in [1024]; // While trying to read data while reading (CFRStreamHandsBitts Available (ReadStream)) {CIFINDEX LAN = CF ReadStream Read (RedDream, Buff, SIFF (Buff)); If (lane and lt; = 0) {// either the stream stopped or error occurred. Close everything and treat it as "connection ended" [self-directed]; [Connection Relief: Self]; Return; } [Incoming Databuffer Appendabits: Length of the Buff: Lane]; // Try removing the packet from buffer. // // Protocol: Header + Body / Header: An integer that indicates body length / body: Bytes that represent encoded NSDictionary // We have more than one message in buffer - this is the reason That we should be reading this while loop is inside (yes) {// have we read the title yet? If (packetBodySize == -1) {// Do we have enough bytes in the buffer to read the header? If ([incommodetfafer length]> gt; = sizeof (int)) // Removal length memcpy (& amp; amp; amp; amp; amp; amp; packet bodiesis; [incoming data buffer bytes], sizeof // buffer removed the segment from the NSRange rangeDeliedLeat = {0, size (int)}; [Incoming data buffer mirrored outdoors: remove with borderbaysbits: zero length: 0]; } Else {// We'll wait for more data so far are not enough breakage; }} // Now we should have a header, if the body time to remove ([Baphari length of the incoming data]> gt; = packetBodySize) {// Now we have enough data to remove meaningful packets. NSDTA * Raw = [NSDTATA DataWithbites: [incoming gate bytes] Length: Packet Body Size]; // Tell our representative about it NSDTa * ImageData = [NSKEYWorkerUniversalIndustrialWidadata: Raw]; UIImage * image = [UIImage imageWithData: imageData]; [Received NetworkRisijation: Connection via Image: Self]; // Remove that part from buffer NSRange range TooDelete = {0, packetBodySize}; [Incoming data buffer mirrored outdoors: remove with borderbaysbits: zero length: 0]; // We have processed the packet reset the state PacketBodySize = -1; } Else {// will not wait enough data yet. break; However, when the connection gets choppy, UIImage throws an error that it can not render JPEG.  

How should I pass images through WiFi?

That's okay if you leave some frames, I need a way to tell UIImage incorrectly to leave "batch".

Thank you!

>

UIImage does not conform to NSCoding - & gt; NSKeyedArchiver fails.

You must use UIImagePNGRepresentation () to get image data. Or use UIImageJPEGRepresentation () for compressed data.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -