I believe there is a memory leak in the jpeg_write_scanlines() function. The
code below takes a frame image from a dc1394 camera and turns it into a jpeg
inside a while loop. The memory usage increases 0.1% about every 5 seconds
on an embedded ARM processor with very little memory and processor power.
static struct jpeg_compress_struct cinfo;
static struct jpeg_error_mgr jerr;
static JSAMPROW row_pointer[1];
cinfo.err = jpeg_std_error( &jerr );
jpeg_create_compress(&cinfo);
while( !pglobal->stop ) {
pthread_mutex_lock( &pglobal->db );
err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT,
&frames[0]);
memcpy(latestFrame, frames[0]->image, frameWidth * frameHeight);
static unsigned char *jpeg = NULL;
static long unsigned jpegSize = 0;
jpeg_mem_dest(&cinfo, &jpeg, &jpegSize);
cinfo.image_width = frameWidth;
cinfo.image_height = frameHeight;
cinfo.input_components = 1;
cinfo.in_color_space = JCS_GRAYSCALE;
jpeg_set_defaults( &cinfo );
jpeg_start_compress( &cinfo, TRUE );
while( cinfo.next_scanline < cinfo.image_height ) {
row_pointer[0] = &latestFrame[ cinfo.next_scanline *
cinfo.image_width * cinfo.input_components];
jpeg_write_scanlines( &cinfo, row_pointer, 1 );
}
jpeg_finish_compress( &cinfo );
err = dc1394_capture_enqueue(camera, frames[0]);
pglobal->size = jpegSize;
memcpy(pglobal->buf, jpeg, pglobal->size);
pthread_cond_broadcast(&pglobal->db_update);
pthread_mutex_unlock( &pglobal->db );
if(trigger==0)usleep(1000*delay);
}
jpeg_destroy_compress( &cinfo );
If I comment out the code from "jpeg_start_compress( &cinfo, TRUE );" to
"jpeg_finish_compress( &cinfo );" (like below) the memory usage stays
consistent.
//jpeg_set_defaults( &cinfo );
//jpeg_start_compress( &cinfo, TRUE );
//while( cinfo.next_scanline < cinfo.image_height ) {
// row_pointer[0] = &latestFrame[ cinfo.next_scanline *
cinfo.image_width * cinfo.input_components];
// jpeg_write_scanlines( &cinfo, row_pointer, 1 );
//}
//jpeg_finish_compress( &cinfo );
Any help would be appreciated,
-Justin
|