Streaming JPEG, JPEG End Detection

I created a java server that takes screenshots, resizes them and sends them over TCP / IP to my iPhone application. The application then uses NSInputStream to collect incoming image data, create an instance of NSMutableData with a byte buffer, and create an UIImage object to display on the iPhone. Screenshots, in fact. My iPhone code for collecting image data currently looks like this:

- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent{


if(streamEvent == NSStreamEventHasBytesAvailable && [iStream hasBytesAvailable]){
        uint8_t buffer[1024];

    while([iStream hasBytesAvailable]){
        NSLog(@"New Data");

        int len = [iStream read:buffer maxLength:sizeof(buffer)];

        [imgdata appendBytes:buffer length:len];
        fullen=fullen+len;

        /*Here is where the problem lies.  What should be in this
         if statement in order to make it test the last byte of
         the incoming buffer, to tell if it is the End of Image marker
         for the end of incoming JPEG file?
         */
        if(buffer[len]=='FFD9'){
        UIImage *img = [[UIImage alloc] initWithData:imgdata];
        NSLog(@"NUMBER OF BYTES: %u", len);

        image.image = img;
        }
    }

}
}

, , , NSMutableData UIImage. , JPEG - (EOI) (FFD9) - , . ? - , , JPEG, !

+3
1

, , .

, . , , # , , .

, . , , , . .

, , . , , . , , .

, , , , (., , VNC).

+3

Source: https://habr.com/ru/post/1735535/


All Articles