static void add_video_format (ofGstDevice &webcam_device, ofGstVideoFormat *video_format, GstStructure &format_structure) { int i; gchar *resolution; get_supported_framerates (*video_format, format_structure); find_highest_framerate (*video_format); // ofLog(OF_LOG_VERBOSE,"%s %d x %d num_framerates %d\n", video_format->mimetype, video_format->width, // video_format->height, video_format->num_framerates); for (i = 0; i < video_format->num_framerates; i++) { // ofLog(OF_LOG_VERBOSE,"%d/%d ", video_format->framerates[i].numerator, // video_format->framerates[i].denominator); } resolution = g_strdup_printf ("%ix%i", video_format->width, video_format->height); i = GPOINTER_TO_INT(g_hash_table_lookup ( webcam_device.supported_resolutions, resolution)); if (i) { /* Resolution already added ? */ float new_framerate = (float)video_format->highest_framerate.numerator / video_format->highest_framerate.denominator; float curr_framerate = (float)webcam_device.current_format->highest_framerate.numerator / webcam_device.current_format->highest_framerate.denominator; if (new_framerate > curr_framerate) { // ofLog(OF_LOG_VERBOSE,"higher framerate replacing existing format\n"); webcam_device.current_format = video_format; } // else // ofLog(OF_LOG_VERBOSE,"already added, skipping\n"); g_free (resolution); return; } webcam_device.video_formats.push_back(video_format); g_hash_table_insert (webcam_device.supported_resolutions, resolution, GINT_TO_POINTER(webcam_device.num_video_formats + 1)); webcam_device.num_video_formats++; }
static void add_video_format (ofGstDevice &webcam_device, ofGstVideoFormat &video_format, GstStructure &format_structure, int desired_framerate) { ofLog(OF_LOG_NOTICE,"%s %d x %d framerates:", video_format.mimetype.c_str(), video_format.width, video_format.height); get_supported_framerates (video_format, format_structure); find_framerate (video_format, desired_framerate); int i = find_resolution(webcam_device,video_format.width, video_format.height); if (i!=-1) { // Resolution already added ? float new_framerate = (float)video_format.choosen_framerate.numerator / video_format.choosen_framerate.denominator; float curr_framerate = (float)webcam_device.video_formats[i].choosen_framerate.numerator / webcam_device.video_formats[i].choosen_framerate.denominator; if (desired_framerate == -1){ if(new_framerate > curr_framerate) { ofLog(OF_LOG_VERBOSE,"higher framerate replacing existing format\n"); webcam_device.video_formats[i] = video_format; }else{ ofLog(OF_LOG_VERBOSE,"already added, skipping\n"); } }else{ if(fabs(new_framerate - desired_framerate) < fabs(curr_framerate - desired_framerate) ){ ofLog(OF_LOG_VERBOSE,"more similar framerate replacing existing format\n"); webcam_device.video_formats[i] = video_format; }else{ ofLog(OF_LOG_VERBOSE,"already added, skipping\n"); } } return; } webcam_device.video_formats.push_back(video_format); }