Index: netcam.c =================================================================== --- netcam.c (revision 498) +++ netcam.c (working copy) @@ -1351,6 +1351,12 @@ netcam->receiving->image_time = curtime; + /* Fix starting of JPEG if needed , some cameras introduce thrash before + SOI 0xFFD8 Start Of Image + */ + + netcam_fix_jpeg_header(netcam); + /* * Calculate our "running average" time for this netcam's * frame transmissions (except for the first time). Index: netcam.h =================================================================== --- netcam.h (revision 498) +++ netcam.h (working copy) @@ -287,7 +287,9 @@ */ /* Within netcam_jpeg.c */ int netcam_proc_jpeg (struct netcam_context *, unsigned char *); +void netcam_fix_jpeg_header(struct netcam_context *); void netcam_get_dimensions (struct netcam_context *); + /* Within netcam.c */ int netcam_start (struct context *); int netcam_next (struct context *, unsigned char *); Index: netcam_jpeg.c =================================================================== --- netcam_jpeg.c (revision 498) +++ netcam_jpeg.c (working copy) @@ -486,7 +486,44 @@ return retval; } + /** + * netcam_fix_jpeg_header + * + * Routine to decode an image received from a netcam into a YUV420P buffer + * suitable for processing by motion. + * + * Parameters: + * netcam pointer to the netcam_context structure + * + * Returns: Nothing + * + */ +void netcam_fix_jpeg_header(netcam_context_ptr netcam) +{ + char *ptr_buffer; + + ptr_buffer = memmem(netcam->receiving->ptr, netcam->receiving->used, "\xff\xd8", 2); + + if (ptr_buffer != NULL) { + size_t soi_position = 0; + + soi_position = ptr_buffer - netcam->receiving->ptr; + + if (soi_position > 0) { + memmove(netcam->receiving->ptr, netcam->receiving->ptr + soi_position, + netcam->receiving->used - soi_position); + netcam->receiving->used -= soi_position; + } + + if (debug_level > CAMERA_INFO) + motion_log(LOG_INFO, 0, "%s: SOI found , position %d", + __FUNCTION__, soi_position); + } +} + + +/** * netcam_get_dimensions * * This function gets the height and width of the JPEG image