diff -up cheese-2.23.91/src/cheese-webcam.c.coocoo cheese-2.23.91/src/cheese-webcam.c --- cheese-2.23.91/src/cheese-webcam.c.coocoo 2008-09-03 20:34:12.000000000 +0200 +++ cheese-2.23.91/src/cheese-webcam.c 2008-09-03 22:36:43.000000000 +0200 @@ -48,6 +48,8 @@ G_DEFINE_TYPE (CheeseWebcam, cheese_webc #define CHEESE_WEBCAM_ERROR cheese_webcam_error_quark () +static void find_highest_framerate (CheeseVideoFormat *format); + enum CheeseWebcamError { CHEESE_WEBCAM_ERROR_UNKNOWN, @@ -444,6 +446,33 @@ cheese_webcam_get_supported_framerates ( } static void +cheese_webcam_add_video_format (CheeseWebcamDevice *webcam_device, + CheeseVideoFormat *video_format, GstStructure *format_structure) +{ + int i; + + cheese_webcam_get_supported_framerates (video_format, format_structure); + find_highest_framerate (video_format); + + g_print ("%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++) + { + g_print ("%d/%d ", video_format->framerates[i].numerator, + video_format->framerates[i].denominator); + } + g_print ("\n"); + + g_array_append_val (webcam_device->video_formats, *video_format); + g_hash_table_insert (webcam_device->supported_resolutions, + g_strdup_printf ("%ix%i", video_format->width, + video_format->height), + GINT_TO_POINTER(webcam_device->num_video_formats + 1)); + + webcam_device->num_video_formats++; +} + +static void cheese_webcam_get_supported_video_formats (CheeseWebcamDevice *webcam_device, GstCaps *caps) { int i; @@ -476,10 +505,7 @@ cheese_webcam_get_supported_video_format video_format.mimetype = g_strdup (gst_structure_get_name (structure)); gst_structure_get_int (structure, "width", &(video_format.width)); gst_structure_get_int (structure, "height", &(video_format.height)); - cheese_webcam_get_supported_framerates (&video_format, structure); - - g_array_append_val (webcam_device->video_formats, video_format); - webcam_device->num_video_formats++; + cheese_webcam_add_video_format(webcam_device, &video_format, structure); } else if (GST_VALUE_HOLDS_INT_RANGE (width)) { @@ -500,9 +526,7 @@ cheese_webcam_get_supported_video_format video_format.mimetype = g_strdup (gst_structure_get_name (structure)); video_format.width = cur_width; video_format.height = cur_height; - cheese_webcam_get_supported_framerates (&video_format, structure); - g_array_append_val (webcam_device->video_formats, video_format); - webcam_device->num_video_formats++; + cheese_webcam_add_video_format(webcam_device, &video_format, structure); cur_width *= 2; cur_height *= 2; } @@ -516,9 +540,7 @@ cheese_webcam_get_supported_video_format video_format.mimetype = g_strdup (gst_structure_get_name (structure)); video_format.width = cur_width; video_format.height = cur_height; - cheese_webcam_get_supported_framerates (&video_format, structure); - g_array_append_val (webcam_device->video_formats, video_format); - webcam_device->num_video_formats++; + cheese_webcam_add_video_format(webcam_device, &video_format, structure); cur_width /= 2; cur_height /= 2; } @@ -540,7 +562,6 @@ cheese_webcam_get_webcam_device_data (Ch GstStateChangeReturn ret; GstMessage *msg; GstBus *bus; - int i, j; { pipeline_desc = g_strdup_printf ("%s name=source device=%s ! fakesink", @@ -575,6 +596,7 @@ cheese_webcam_get_webcam_device_data (Ch name = "Unknown"; g_print ("Detected webcam: %s\n", name); + g_print ("device: %s\n", webcam_device->video_device); pad = gst_element_get_pad (src, "src"); caps = gst_pad_get_caps (pad); gst_object_unref (pad); @@ -589,27 +611,6 @@ cheese_webcam_get_webcam_device_data (Ch g_free (pipeline_desc); } - - g_print ("device: %s\n", webcam_device->video_device); - for (i = 0; i < webcam_device->num_video_formats; i++) - { - CheeseVideoFormat video_format; - - video_format = g_array_index (webcam_device->video_formats, CheeseVideoFormat, i); - g_hash_table_insert (webcam_device->supported_resolutions, - g_strdup_printf ("%ix%i", video_format.width, - video_format.height), - &g_array_index (webcam_device->video_formats, - CheeseVideoFormat, i)); - g_print ("%s %d x %d num_framerates %d\n", video_format.mimetype, video_format.width, - video_format.height, video_format.num_framerates); - for (j = 0; j < video_format.num_framerates; j++) - { - g_print ("%d/%d ", video_format.framerates[j].numerator, - video_format.framerates[j].denominator); - } - g_print ("\n"); - } } static void @@ -651,8 +652,7 @@ cheese_webcam_detect_webcam_devices (Che } static void -find_highest_framerate (CheeseVideoFormat *format, int *numerator, - int *denominator) +find_highest_framerate (CheeseVideoFormat *format) { int framerate_numerator; int framerate_denominator; @@ -672,8 +672,8 @@ find_highest_framerate (CheeseVideoForma } } - *numerator = framerate_numerator; - *denominator = framerate_denominator; + format->highest_framerate.numerator = framerate_numerator; + format->highest_framerate.denominator = framerate_denominator; } static gboolean @@ -695,7 +695,6 @@ cheese_webcam_create_webcam_source_bin ( { CheeseVideoFormat *format; int i; - int framerate_numerator, framerate_denominator; gchar *resolution; /* If we have a matching video device use that one, otherwise use the first */ @@ -714,7 +713,12 @@ cheese_webcam_create_webcam_source_bin ( /* Use the previously set resolution from gconf if it is set and the * camera supports it. */ if (priv->x_resolution != 0 && priv->y_resolution != 0) - format = g_hash_table_lookup (selected_webcam->supported_resolutions, resolution); + { + i = GPOINTER_TO_INT(g_hash_table_lookup (selected_webcam->supported_resolutions, resolution)); + if (i) + format = &g_array_index (selected_webcam->video_formats, + CheeseVideoFormat, i - 1); + } if (!format) { @@ -738,21 +742,18 @@ cheese_webcam_create_webcam_source_bin ( if (format == NULL) goto fallback; - find_highest_framerate (format, &framerate_numerator, - &framerate_denominator); - webcam_input = g_strdup_printf ( "%s name=video_source device=%s ! capsfilter name=capsfilter caps=video/x-raw-rgb,width=%d,height=%d,framerate=%d/%d;video/x-raw-yuv,width=%d,height=%d,framerate=%d/%d ! identity", selected_webcam->gstreamer_src, selected_webcam->video_device, format->width, format->height, - framerate_numerator, - framerate_denominator, + format->highest_framerate.numerator, + format->highest_framerate.denominator, format->width, format->height, - framerate_numerator, - framerate_denominator); + format->highest_framerate.numerator, + format->highest_framerate.denominator); g_print ("%s\n", webcam_input); priv->webcam_source_bin = gst_parse_bin_from_description (webcam_input, @@ -1539,10 +1540,6 @@ cheese_webcam_set_video_format (CheeseWe CheeseWebcamPrivate *priv = CHEESE_WEBCAM_GET_PRIVATE (webcam); GstCaps *new_caps; - int framerate_numerator; - int framerate_denominator; - - find_highest_framerate (format, &framerate_numerator, &framerate_denominator); new_caps = gst_caps_new_simple ("video/x-raw-rgb", "width", G_TYPE_INT, @@ -1550,8 +1547,8 @@ cheese_webcam_set_video_format (CheeseWe "height", G_TYPE_INT, format->height, "framerate", GST_TYPE_FRACTION, - framerate_numerator, - framerate_denominator, + format->highest_framerate.numerator, + format->highest_framerate.denominator, NULL); gst_caps_append(new_caps, gst_caps_new_simple ("video/x-raw-yuv", @@ -1560,8 +1557,8 @@ cheese_webcam_set_video_format (CheeseWe "height", G_TYPE_INT, format->height, "framerate", GST_TYPE_FRACTION, - framerate_numerator, - framerate_denominator, + format->highest_framerate.numerator, + format->highest_framerate.denominator, NULL)); priv->current_format = format; diff -up cheese-2.23.91/src/cheese-webcam.h.coocoo cheese-2.23.91/src/cheese-webcam.h --- cheese-2.23.91/src/cheese-webcam.h.coocoo 2008-09-03 20:27:59.000000000 +0200 +++ cheese-2.23.91/src/cheese-webcam.h 2008-09-03 22:31:42.000000000 +0200 @@ -49,6 +49,7 @@ typedef struct int height; int num_framerates; CheeseFramerate *framerates; + CheeseFramerate highest_framerate; } CheeseVideoFormat; typedef struct