static void get_supported_framerates (ofGstVideoFormat &video_format, GstStructure &structure) { const GValue *framerates; int i, j; framerates = gst_structure_get_value (&structure, "framerate"); if (GST_VALUE_HOLDS_FRACTION (framerates)) { video_format.num_framerates = 1; video_format.framerates = new ofGstFramerate[video_format.num_framerates]; video_format.framerates[0].numerator = gst_value_get_fraction_numerator (framerates); video_format.framerates[0].denominator = gst_value_get_fraction_denominator (framerates); } else if (GST_VALUE_HOLDS_LIST (framerates)) { video_format.num_framerates = gst_value_list_get_size (framerates); video_format.framerates = new ofGstFramerate[video_format.num_framerates]; for (i = 0; i < video_format.num_framerates; i++) { const GValue *value; value = gst_value_list_get_value (framerates, i); video_format.framerates[i].numerator = gst_value_get_fraction_numerator (value); video_format.framerates[i].denominator = gst_value_get_fraction_denominator (value); } } else if (GST_VALUE_HOLDS_FRACTION_RANGE (framerates)) { int numerator_min, denominator_min, numerator_max, denominator_max; const GValue *fraction_range_min; const GValue *fraction_range_max; fraction_range_min = gst_value_get_fraction_range_min (framerates); numerator_min = gst_value_get_fraction_numerator (fraction_range_min); denominator_min = gst_value_get_fraction_denominator (fraction_range_min); fraction_range_max = gst_value_get_fraction_range_max (framerates); numerator_max = gst_value_get_fraction_numerator (fraction_range_max); denominator_max = gst_value_get_fraction_denominator (fraction_range_max); g_print ("FractionRange: %d/%d - %d/%d\n", numerator_min, denominator_min, numerator_max, denominator_max); video_format.num_framerates = (numerator_max - numerator_min + 1) * (denominator_max - denominator_min + 1); video_format.framerates = new ofGstFramerate[video_format.num_framerates]; int k = 0; for (i = numerator_min; i <= numerator_max; i++) { for (j = denominator_min; j <= denominator_max; j++) { video_format.framerates[k].numerator = i; video_format.framerates[k].denominator = j; k++; } } } else { g_critical ("GValue type %s, cannot be handled for framerates", G_VALUE_TYPE_NAME (framerates)); } }
static void gst_value_fraction_get_extremes (const GValue * v, gint * min_num, gint * min_denom, gint * max_num, gint * max_denom) { if (GST_VALUE_HOLDS_FRACTION (v)) { *min_num = *max_num = gst_value_get_fraction_numerator (v); *min_denom = *max_denom = gst_value_get_fraction_denominator (v); } else if (GST_VALUE_HOLDS_FRACTION_RANGE (v)) { const GValue *min, *max; min = gst_value_get_fraction_range_min (v); *min_num = gst_value_get_fraction_numerator (min); *min_denom = gst_value_get_fraction_denominator (min); max = gst_value_get_fraction_range_max (v); *max_num = gst_value_get_fraction_numerator (max); *max_denom = gst_value_get_fraction_denominator (max); } else if (GST_VALUE_HOLDS_LIST (v)) { gint min_n = G_MAXINT, min_d = 1, max_n = 0, max_d = 1; int i, n; *min_num = G_MAXINT; *min_denom = 1; *max_num = 0; *max_denom = 1; n = gst_value_list_get_size (v); g_assert (n > 0); for (i = 0; i < n; i++) { const GValue *t = gst_value_list_get_value (v, i); gst_value_fraction_get_extremes (t, &min_n, &min_d, &max_n, &max_d); if (gst_util_fraction_compare (min_n, min_d, *min_num, *min_denom) < 0) { *min_num = min_n; *min_denom = min_d; } if (gst_util_fraction_compare (max_n, max_d, *max_num, *max_denom) > 0) { *max_num = max_n; *max_denom = max_d; } } } else { g_warning ("Unknown type for framerate"); *min_num = 0; *min_denom = 1; *max_num = G_MAXINT; *max_denom = 1; } }
static void get_supported_framerates (ofGstVideoFormat &video_format, GstStructure &structure) { const GValue *framerates; ofGstFramerate framerate; framerates = gst_structure_get_value (&structure, "framerate"); if (GST_VALUE_HOLDS_FRACTION (framerates)){ framerate.numerator = gst_value_get_fraction_numerator (framerates); framerate.denominator = gst_value_get_fraction_denominator (framerates); video_format.framerates.push_back(framerate); ofLog(OF_LOG_NOTICE,"%d/%d ", framerate.numerator, framerate.denominator); }else if (GST_VALUE_HOLDS_LIST (framerates)){ int num_framerates = gst_value_list_get_size (framerates); for (int i = 0; i < num_framerates; i++){ const GValue *value = gst_value_list_get_value (framerates, i); framerate.numerator = gst_value_get_fraction_numerator (value); framerate.denominator = gst_value_get_fraction_denominator (value); video_format.framerates.push_back(framerate); ofLog(OF_LOG_NOTICE,"%d/%d ", framerate.numerator, framerate.denominator); } }else if (GST_VALUE_HOLDS_FRACTION_RANGE (framerates)){ int numerator_min, denominator_min, numerator_max, denominator_max; const GValue *fraction_range_min; const GValue *fraction_range_max; fraction_range_min = gst_value_get_fraction_range_min (framerates); numerator_min = gst_value_get_fraction_numerator (fraction_range_min); denominator_min = gst_value_get_fraction_denominator (fraction_range_min); fraction_range_max = gst_value_get_fraction_range_max (framerates); numerator_max = gst_value_get_fraction_numerator (fraction_range_max); denominator_max = gst_value_get_fraction_denominator (fraction_range_max); ofLog(OF_LOG_NOTICE,"from %d/%d to %d/%d", numerator_min, denominator_max, numerator_max, denominator_min); for (int i = numerator_min; i <= numerator_max; i++){ for (int j = denominator_min; j <= denominator_max; j++){ framerate.numerator = i; framerate.denominator = j; video_format.framerates.push_back(framerate); } } }else{ ofLog (OF_LOG_WARNING,"unknown GValue type %s for framerates", G_VALUE_TYPE_NAME (framerates)); } }
static void _get_fraction_range (GstStructure * s, const gchar * field, gint * fps_n_min, gint * fps_d_min, gint * fps_n_max, gint * fps_d_max) { const GValue *value; const GValue *min_v, *max_v; value = gst_structure_get_value (s, field); fail_unless (value != NULL); fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (value)); min_v = gst_value_get_fraction_range_min (value); fail_unless (GST_VALUE_HOLDS_FRACTION (min_v)); *fps_n_min = gst_value_get_fraction_numerator (min_v); *fps_d_min = gst_value_get_fraction_denominator (min_v); max_v = gst_value_get_fraction_range_max (value); fail_unless (GST_VALUE_HOLDS_FRACTION (max_v)); *fps_n_max = gst_value_get_fraction_numerator (max_v); *fps_d_max = gst_value_get_fraction_denominator (max_v); }
void test_simplify() { GstStructure *s1, *s2; gboolean did_simplify; GstCaps *caps; caps = gst_caps_from_string (non_simple_caps_string); fail_unless (caps != NULL, "gst_caps_from_string (non_simple_caps_string) failed"); did_simplify = gst_caps_do_simplify (caps); fail_unless (did_simplify == TRUE, "gst_caps_do_simplify() should have worked"); /* check simplified caps, should be: * * video/x-raw-rgb, bpp=(int)8, depth=(int)8, endianness=(int)1234, * framerate=(fraction)[ 1/100, 100 ], width=(int)[ 16, 4096 ], * height=(int)[ 16, 4096 ]; * video/x-raw-yuv, format=(fourcc){ YV12, YUY2, I420 }, * width=(int)[ 16, 4096 ], height=(int)[ 16, 4096 ], * framerate=(fraction)[ 1/100, 100 ] */ fail_unless (gst_caps_get_size (caps) == 2); s1 = gst_caps_get_structure (caps, 0); s2 = gst_caps_get_structure (caps, 1); fail_unless (s1 != NULL); fail_unless (s2 != NULL); if (!gst_structure_has_name (s1, "video/x-raw-rgb")) { GstStructure *tmp; tmp = s1; s1 = s2; s2 = tmp; } fail_unless (gst_structure_has_name (s1, "video/x-raw-rgb")); { const GValue *framerate_value; const GValue *width_value; const GValue *height_value; const GValue *val_fps; GValue test_fps = { 0, }; gint bpp, depth, endianness; gint min_width, max_width; gint min_height, max_height; fail_unless (gst_structure_get_int (s1, "bpp", &bpp)); fail_unless (bpp == 8); fail_unless (gst_structure_get_int (s1, "depth", &depth)); fail_unless (depth == 8); fail_unless (gst_structure_get_int (s1, "endianness", &endianness)); fail_unless (endianness == G_LITTLE_ENDIAN); g_value_init (&test_fps, GST_TYPE_FRACTION); framerate_value = gst_structure_get_value (s1, "framerate"); fail_unless (framerate_value != NULL); fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value)); val_fps = gst_value_get_fraction_range_min (framerate_value); gst_value_set_fraction (&test_fps, 1, 100); fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL); val_fps = gst_value_get_fraction_range_max (framerate_value); gst_value_set_fraction (&test_fps, 100, 1); fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL); g_value_unset (&test_fps); width_value = gst_structure_get_value (s1, "width"); fail_unless (width_value != NULL); fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value)); min_width = gst_value_get_int_range_min (width_value); max_width = gst_value_get_int_range_max (width_value); fail_unless (min_width == 16 && max_width == 4096); height_value = gst_structure_get_value (s1, "height"); fail_unless (height_value != NULL); fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value)); min_height = gst_value_get_int_range_min (height_value); max_height = gst_value_get_int_range_max (height_value); fail_unless (min_height == 16 && max_height == 4096); } fail_unless (gst_structure_has_name (s2, "video/x-raw-yuv")); { const GValue *framerate_value; const GValue *format_value; const GValue *width_value; const GValue *height_value; const GValue *val_fps; GValue test_fps = { 0, }; gint min_width, max_width; gint min_height, max_height; format_value = gst_structure_get_value (s2, "format"); fail_unless (format_value != NULL); fail_unless (GST_VALUE_HOLDS_LIST (format_value)); fail_unless (gst_value_list_get_size (format_value) == 3); fail_unless (check_fourcc_list (format_value) == TRUE); g_value_init (&test_fps, GST_TYPE_FRACTION); framerate_value = gst_structure_get_value (s2, "framerate"); fail_unless (framerate_value != NULL); fail_unless (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value)); val_fps = gst_value_get_fraction_range_min (framerate_value); gst_value_set_fraction (&test_fps, 1, 100); fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL); val_fps = gst_value_get_fraction_range_max (framerate_value); gst_value_set_fraction (&test_fps, 100, 1); fail_unless (gst_value_compare (&test_fps, val_fps) == GST_VALUE_EQUAL); g_value_unset (&test_fps); width_value = gst_structure_get_value (s2, "width"); fail_unless (width_value != NULL); fail_unless (GST_VALUE_HOLDS_INT_RANGE (width_value)); min_width = gst_value_get_int_range_min (width_value); max_width = gst_value_get_int_range_max (width_value); fail_unless (min_width == 16 && max_width == 4096); height_value = gst_structure_get_value (s2, "height"); fail_unless (height_value != NULL); fail_unless (GST_VALUE_HOLDS_INT_RANGE (height_value)); min_height = gst_value_get_int_range_min (height_value); max_height = gst_value_get_int_range_max (height_value); fail_unless (min_height == 16 && max_height == 4096); } gst_caps_unref (caps); }