Example #1
0
// TODO: gets formats for cameras, when a format returns a range it gets
// in steps /2 and *2 from min to max and max to min, for format7 it should be free to get any size
static void get_supported_video_formats (ofGstDevice &webcam_device, GstCaps &caps, int desired_framerate)
{

	int num_structures;

	num_structures = gst_caps_get_size (&caps);
	for (int i = 0; i < num_structures; i++){
		GstStructure *structure;
		const GValue *width, *height;
		structure = gst_caps_get_structure (&caps, i);

		width  = gst_structure_get_value (structure, "width");
		height = gst_structure_get_value (structure, "height");

		if (G_VALUE_HOLDS_INT (width)){
			ofGstVideoFormat video_format;

			video_format.mimetype = gst_structure_get_name (structure);
			gst_structure_get_int (structure, "width", &(video_format.width));
			gst_structure_get_int (structure, "height", &(video_format.height));
			add_video_format(webcam_device, video_format, *structure, desired_framerate);
		}else if (GST_VALUE_HOLDS_INT_RANGE (width)){
			int min_width, max_width, min_height, max_height;
			int cur_width, cur_height;

			min_width  = gst_value_get_int_range_min (width);
			max_width  = gst_value_get_int_range_max (width);
			min_height = gst_value_get_int_range_min (height);
			max_height = gst_value_get_int_range_max (height);

			cur_width  = min_width;
			cur_height = min_height;
			while (cur_width <= max_width && cur_height <= max_height){
				ofGstVideoFormat video_format;

				video_format.mimetype = gst_structure_get_name (structure);
				video_format.width    = cur_width;
				video_format.height   = cur_height;
				add_video_format(webcam_device, video_format, *structure, desired_framerate);
				cur_width  *= 2;
				cur_height *= 2;
			}

			cur_width  = max_width;
			cur_height = max_height;
			while (cur_width > min_width && cur_height > min_height){
				ofGstVideoFormat video_format;

				video_format.mimetype = gst_structure_get_name (structure);
				video_format.width    = cur_width;
				video_format.height   = cur_height;
				add_video_format(webcam_device, video_format, *structure, desired_framerate);
				cur_width  /= 2;
				cur_height /= 2;
			}
		}else{
			ofLog(OF_LOG_ERROR, "unknown GValue type %s, for resolution width", G_VALUE_TYPE_NAME (width));
		}
	}
}
Example #2
0
// TODO: gets formats for cameras, when a format return a range it gets
// in steps /2 and *2 from min to max, for format7 it should be free to get any size
static void
get_supported_video_formats (ofGstDevice &webcam_device, GstCaps &caps)
{
    int i;
    int num_structures;

    num_structures = gst_caps_get_size (&caps);
    for (i = 0; i < num_structures; i++)
    {
        GstStructure *structure;
        const GValue *width, *height;
        structure = gst_caps_get_structure (&caps, i);

        width  = gst_structure_get_value (structure, "width");
        height = gst_structure_get_value (structure, "height");

        if (G_VALUE_HOLDS_INT (width))
        {
            ofGstVideoFormat * video_format = new ofGstVideoFormat;

            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));
            add_video_format(webcam_device, video_format, *structure);
        }
        else if (GST_VALUE_HOLDS_INT_RANGE (width))
        {
            int min_width, max_width, min_height, max_height;
            int cur_width, cur_height;

            min_width  = gst_value_get_int_range_min (width);
            max_width  = gst_value_get_int_range_max (width);
            min_height = gst_value_get_int_range_min (height);
            max_height = gst_value_get_int_range_max (height);

            cur_width  = min_width;
            cur_height = min_height;
            /* Gstreamer will sometimes give us a range with min_xxx == max_xxx,
             we use <= here (and not below) to make this work */
            while (cur_width <= max_width && cur_height <= max_height)
            {
                ofGstVideoFormat * video_format = new ofGstVideoFormat;

                video_format->mimetype = g_strdup (gst_structure_get_name (structure));
                video_format->width    = cur_width;
                video_format->height   = cur_height;
                add_video_format(webcam_device, video_format, *structure);
                cur_width  *= 2;
                cur_height *= 2;
            }

            cur_width  = max_width;
            cur_height = max_height;
            while (cur_width > min_width && cur_height > min_height)
            {
                ofGstVideoFormat * video_format = new ofGstVideoFormat;

                video_format->mimetype = g_strdup (gst_structure_get_name (structure));
                video_format->width    = cur_width;
                video_format->height   = cur_height;
                add_video_format(webcam_device, video_format, *structure);
                cur_width  /= 2;
                cur_height /= 2;
            }
        }
        else
        {
            g_critical ("GValue type %s, cannot be handled for resolution width", G_VALUE_TYPE_NAME (width));
        }
    }

    /* Sort the format array (so that it will show sorted in the resolution
    selection GUI), and rebuild the hashtable (as that will be invalid after
    the sorting) */
    sort (webcam_device.video_formats.begin(), webcam_device.video_formats.end(), resolution_compare);
    g_hash_table_remove_all (webcam_device.supported_resolutions);
    for (i = 0; i < webcam_device.num_video_formats; i++) {
        ofGstVideoFormat * format = webcam_device.video_formats[i];

        g_hash_table_insert (webcam_device.supported_resolutions,
                             g_strdup_printf ("%ix%i", format->width,
                                              format->height),
                             GINT_TO_POINTER(i + 1));
    }
}