Original Post
Hi, im trying to get my program to read from multiple cameras that are hooked up to the machine. Before i was not using threading and i was reading each frame from the cameras at a time and the processing them. This was too slow and inefficent as the cameras would not be synced up. So i dove into multithreading and i have a thread all set up but when i try and open a device (camera) the thread stops. so i took the open sequence out of the thread and then when the thread tries to read from the camrea the thread stops. i didnt change the reading code at all, or the open camera code from the other version of the program that did not use threading. All the values of what i pass into the thread function are ok, like the device name, width, height, etc. i have checked them many times over. Here is the thread code. This is how im creating all the threads. Is there perhaps some problem with the way i am creating the thread that will not let it access devices attached to the computer? edit: source tags [Edited by - Bacardi34 on August 24, 2004 11:09:09 AM]
struct thread_data
{
char deviceName[40];
int device;
char name[200];
int maxFrames;
int xOffset;
int yOffset;
char experiment;
char nopng;
int cam;
char isbottom;
pthread_mutex_t the_mutex;
};
void * cam_read( void * theInfo )
{
int width, height, depth;
int i, result;
unsigned char * image;
struct thread_data *data;
data = (struct thread_data *)theInfo;
char prefix[200];
printf( "%s\n", data->deviceName );
data->device = open_camera( data->deviceName, data->the_mutex );
printf( "%s %d\n", "hi", data->device );
for( i = 0; i < data->maxFrames; i++ )
{
printf( "%s %i\n", "READ FRAME:", i );
// read the cam image
result = qcam_read( data->device, &width, &height, &depth,
ℑ, data->the_mutex );
printf( "%d\n", result );
if( !result )
{
printf( "%s %i\n", "BLEAH:", i );
get_actual_image( image, width, height, depth,
data->xOffset, data->yOffset, data->isbottom, 1 );
}
if( !data->nopng )
{
if( !data->experiment )
{
sprintf( prefix, "../var/%s_%d/%s_%d %03d.png", data->name, data->cam, data->name, data->cam, i );
}
else if ( data->experiment )
{
sprintf( prefix, "../var/experiments/image_sequences/%s/%s_%d/%s_%d %03d.png", data->name,
data->name, data->cam, data->name,
data->cam, i );
}
// Ends up looknig like "dirname_cam/frame.png"
png_write_qcam( prefix, width, height, i, image, data->isbottom );
//fprintf( stdout, "%s\n", prefix );
}
free( image );
}
close_camera( data->device );
pthread_exit(0);
}
// Make all the threads
for( i = 0; i < numDirs; i++ )
{
info = ( struct thread_data* )malloc( sizeof( struct thread_data ));
sprintf( info->deviceName, "/dev/video%d", i );
strcpy( info->name, name );
info->maxFrames = maxFrames;
info->xOffset = xOffSet;
info->yOffset = yOffSet;
info->nopng = nopng;
info->experiment = experiment;
info->cam = i;
info->isbottom = isbottom;
info->the_mutex = a_mutex;
pthread_create( &threads, 0,
cam_read,
(void *)info);
}