opusdec: refactor getcaps repeated code into a function

Easier to read and maintain
This commit is contained in:
Thiago Santos 2016-05-01 23:19:57 -03:00
parent 8375ed7763
commit b1153e0f7d

View File

@ -863,33 +863,13 @@ gst_opus_dec_set_property (GObject * object, guint prop_id,
} }
} }
GstCaps * /* caps must be writable */
gst_opus_dec_getcaps (GstAudioDecoder * dec, GstCaps * filter) static void
gst_opus_dec_caps_extend_channels_options (GstCaps * caps)
{ {
GstCaps *caps;
unsigned n; unsigned n;
int channels; int channels;
if (filter) {
filter = gst_caps_copy (filter);
for (n = 0; n < gst_caps_get_size (filter); ++n) {
GstStructure *s = gst_caps_get_structure (filter, n);
if (gst_structure_get_int (s, "channels", &channels)) {
if (channels == 1 || channels == 2) {
GValue v = { 0 };
g_value_init (&v, GST_TYPE_INT_RANGE);
gst_value_set_int_range (&v, 1, 2);
gst_structure_set_value (s, "channels", &v);
g_value_unset (&v);
}
}
}
}
caps = gst_audio_decoder_proxy_getcaps (dec, NULL, filter);
if (filter)
gst_caps_unref (filter);
if (caps) {
caps = gst_caps_make_writable (caps);
for (n = 0; n < gst_caps_get_size (caps); ++n) { for (n = 0; n < gst_caps_get_size (caps); ++n) {
GstStructure *s = gst_caps_get_structure (caps, n); GstStructure *s = gst_caps_get_structure (caps, n);
if (gst_structure_get_int (s, "channels", &channels)) { if (gst_structure_get_int (s, "channels", &channels)) {
@ -902,6 +882,23 @@ gst_opus_dec_getcaps (GstAudioDecoder * dec, GstCaps * filter)
} }
} }
} }
}
GstCaps *
gst_opus_dec_getcaps (GstAudioDecoder * dec, GstCaps * filter)
{
GstCaps *caps;
if (filter) {
filter = gst_caps_copy (filter);
gst_opus_dec_caps_extend_channels_options (filter);
}
caps = gst_audio_decoder_proxy_getcaps (dec, NULL, filter);
if (filter)
gst_caps_unref (filter);
if (caps) {
caps = gst_caps_make_writable (caps);
gst_opus_dec_caps_extend_channels_options (caps);
} }
return caps; return caps;
} }