static GstCaps * mulawenc_getcaps (GstPad * pad) { GstMuLawEnc *mulawenc; GstPad *otherpad; GstCaps *base_caps, *othercaps; mulawenc = GST_MULAWENC (GST_PAD_PARENT (pad)); base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); if (pad == mulawenc->srcpad) { otherpad = mulawenc->sinkpad; } else { otherpad = mulawenc->srcpad; } othercaps = gst_pad_peer_get_caps (otherpad); if (othercaps) { GstStructure *structure; const GValue *orate, *ochans; const GValue *rate, *chans; GValue irate = { 0 }, ichans = { 0}; if (gst_caps_is_empty (othercaps) || gst_caps_is_any (othercaps)) goto done; structure = gst_caps_get_structure (othercaps, 0); orate = gst_structure_get_value (structure, "rate"); ochans = gst_structure_get_value (structure, "channels"); if (!orate || !ochans) goto done; structure = gst_caps_get_structure (base_caps, 0); rate = gst_structure_get_value (structure, "rate"); chans = gst_structure_get_value (structure, "channels"); if (!rate || !chans) goto done; gst_value_intersect (&irate, orate, rate); gst_value_intersect (&ichans, ochans, chans); /* Set the samplerate/channels on the to-be-returned caps */ structure = gst_caps_get_structure (base_caps, 0); gst_structure_set_value (structure, "rate", &irate); gst_structure_set_value (structure, "channels", &ichans); done: gst_caps_unref (othercaps); } return base_caps; }
void test_channel_layout_value_intersect() { GValue layout = { 0, }; GValue list = { 0, }; GValue res = { 0, }; xmlfile = "test_channel_layout_value_intersect"; std_log(LOG_FILENAME_LINE, "Test Started test_channel_layout_value_intersect"); g_value_init (&list, GST_TYPE_LIST); init_value_to_channel_layout (&layout, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT); gst_value_list_append_value (&list, &layout); g_value_unset (&layout); init_value_to_channel_layout (&layout, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT); gst_value_list_append_value (&list, &layout); g_value_unset (&layout); init_value_to_channel_layout (&layout, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT); /* we should get the second layout in the list, as it matches the input */ fail_unless (gst_value_intersect (&res, &layout, &list)); g_value_unset (&layout); fail_unless (GST_VALUE_HOLDS_ARRAY (&res)); fail_unless_equals_int (gst_value_array_get_size (&res), 2); fail_unless_equals_int (g_value_get_enum (gst_value_array_get_value (&res, 0)), GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT); fail_unless_equals_int (g_value_get_enum (gst_value_array_get_value (&res, 1)), GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT); g_value_unset (&res); /* this (with rear position) should not yield any results */ init_value_to_channel_layout (&layout, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT); fail_if (gst_value_intersect (&res, &layout, &list)); g_value_unset (&layout); g_value_unset (&list); std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); }
static gboolean _find_structure_incompatible_fields (GQuark field_id, const GValue * value, StructureIncompatibleFieldsInfo * info) { gchar *value_str, *filter_str; GValue intersect = { 0, }; const GValue *filter_value = gst_structure_id_get_value (info->filter, field_id); if (!filter_value) return TRUE; value_str = gst_value_serialize (value); filter_str = gst_value_serialize (filter_value); if (!gst_value_can_intersect (value, filter_value)) { _incompatible_fields_info_set_found (info); g_string_append_printf (info->str, "\n -> Field '%s' downstream value from structure %d '(%s)%s' can't intersect with" " filter value from structure number %d '(%s)%s' because of their types.", g_quark_to_string (field_id), info->caps_struct_num, G_VALUE_TYPE_NAME (value), value_str, info->filter_caps_struct_num, G_VALUE_TYPE_NAME (filter_value), filter_str); return TRUE; } if (gst_value_intersect (&intersect, value, filter_value)) { g_value_reset (&intersect); return TRUE; } _incompatible_fields_info_set_found (info); g_string_append_printf (info->str, "\n -> Field '%s' downstream value from structure %d '(%s)%s' can't intersect with" " filter value from structure number %d '(%s)%s'", g_quark_to_string (field_id), info->caps_struct_num, G_VALUE_TYPE_NAME (value), value_str, info->filter_caps_struct_num, G_VALUE_TYPE_NAME (filter_value), filter_str); g_free (value_str); g_free (filter_str); return TRUE; }
/* Clamp the framerate in a caps structure to be a smaller range then * [1...max_rate], otherwise return false */ static gboolean gst_video_max_rate_clamp_structure (GstStructure * s, gint maxrate, gint * min_num, gint * min_denom, gint * max_num, gint * max_denom) { gboolean ret = FALSE; if (!gst_structure_has_field (s, "framerate")) { /* No framerate field implies any framerate, clamping would result in * [1..max_rate] so not a real subset */ goto out; } else { const GValue *v; GValue intersection = { 0, }; GValue clamp = { 0, }; gint tmp_num, tmp_denom; g_value_init (&clamp, GST_TYPE_FRACTION_RANGE); gst_value_set_fraction_range_full (&clamp, 0, 1, maxrate, 1); v = gst_structure_get_value (s, "framerate"); ret = gst_value_intersect (&intersection, v, &clamp); g_value_unset (&clamp); if (!ret) goto out; gst_value_fraction_get_extremes (&intersection, min_num, min_denom, max_num, max_denom); gst_value_fraction_get_extremes (v, &tmp_num, &tmp_denom, max_num, max_denom); if (gst_util_fraction_compare (*max_num, *max_denom, maxrate, 1) > 0) { *max_num = maxrate; *max_denom = 1; } gst_structure_take_value (s, "framerate", &intersection); } out: return ret; }