mpg123: fix compiler warning and simplify checks in set_caps

https://bugzilla.gnome.org/show_bug.cgi?id=740195
This commit is contained in:
Tim-Philipp Müller 2015-01-11 01:08:08 +00:00
parent ece6426810
commit 9aaf12aae0

View file

@ -485,6 +485,9 @@ gst_mpg123_audio_dec_set_format (GstAudioDecoder * dec, GstCaps * input_caps)
"srcpad is not linked (yet) -> using S16 sample format"); "srcpad is not linked (yet) -> using S16 sample format");
format = GST_AUDIO_FORMAT_S16; format = GST_AUDIO_FORMAT_S16;
encoding = MPG123_ENC_SIGNED_16; encoding = MPG123_ENC_SIGNED_16;
} else if (gst_caps_is_empty (allowed_srccaps)) {
gst_caps_unref (allowed_srccaps);
goto done;
} else { } else {
gchar const *format_str; gchar const *format_str;
GValue const *format_value; GValue const *format_value;
@ -493,7 +496,10 @@ gst_mpg123_audio_dec_set_format (GstAudioDecoder * dec, GstCaps * input_caps)
GstStructure *structure = gst_caps_get_structure (allowed_srccaps, 0); GstStructure *structure = gst_caps_get_structure (allowed_srccaps, 0);
format_value = gst_structure_get_value (structure, "format"); format_value = gst_structure_get_value (structure, "format");
if (GST_VALUE_HOLDS_LIST (format_value)) { if (format_value == NULL) {
gst_caps_unref (allowed_srccaps);
goto done;
} else if (GST_VALUE_HOLDS_LIST (format_value)) {
/* if value is a format list, pick the first entry */ /* if value is a format list, pick the first entry */
GValue const *fmt_list_value = GValue const *fmt_list_value =
gst_value_list_get_value (format_value, 0); gst_value_list_get_value (format_value, 0);
@ -502,56 +508,45 @@ gst_mpg123_audio_dec_set_format (GstAudioDecoder * dec, GstCaps * input_caps)
/* if value is a string, use it directly */ /* if value is a string, use it directly */
format_str = g_value_get_string (format_value); format_str = g_value_get_string (format_value);
} else { } else {
GST_ERROR_OBJECT (mpg123_decoder, GST_ERROR_OBJECT (mpg123_decoder, "unexpected type for 'format' field "
"format value in caps structure %" GST_PTR_FORMAT "in caps structure %" GST_PTR_FORMAT, structure);
" is of invalid type (must be plain string or string list)", gst_caps_unref (allowed_srccaps);
structure); goto done;
format_str = NULL;
} }
format = GST_AUDIO_FORMAT_UNKNOWN;
/* get the format value from the string */ /* get the format value from the string */
if (G_LIKELY (format_str != NULL)) { format = gst_audio_format_from_string (format_str);
format = gst_audio_format_from_string (format_str); gst_caps_unref (allowed_srccaps);
if (G_UNLIKELY (format == GST_AUDIO_FORMAT_UNKNOWN)) {
GST_ERROR_OBJECT (mpg123_decoder, "format \"%s\" is invalid", g_assert (format != GST_AUDIO_FORMAT_UNKNOWN);
format_str);
}
}
/* convert format to mpg123 encoding */ /* convert format to mpg123 encoding */
if (G_LIKELY (format != GST_AUDIO_FORMAT_UNKNOWN)) { switch (format) {
switch (format) { case GST_AUDIO_FORMAT_S16:
case GST_AUDIO_FORMAT_S16: encoding = MPG123_ENC_SIGNED_16;
encoding = MPG123_ENC_SIGNED_16; break;
break; case GST_AUDIO_FORMAT_S24:
case GST_AUDIO_FORMAT_S24: encoding = MPG123_ENC_SIGNED_24;
encoding = MPG123_ENC_SIGNED_24; break;
break; case GST_AUDIO_FORMAT_S32:
case GST_AUDIO_FORMAT_S32: encoding = MPG123_ENC_SIGNED_32;
encoding = MPG123_ENC_SIGNED_32; break;
break; case GST_AUDIO_FORMAT_U16:
case GST_AUDIO_FORMAT_U16: encoding = MPG123_ENC_UNSIGNED_16;
encoding = MPG123_ENC_UNSIGNED_16; break;
break; case GST_AUDIO_FORMAT_U24:
case GST_AUDIO_FORMAT_U24: encoding = MPG123_ENC_UNSIGNED_24;
encoding = MPG123_ENC_UNSIGNED_24; break;
break; case GST_AUDIO_FORMAT_U32:
case GST_AUDIO_FORMAT_U32: encoding = MPG123_ENC_UNSIGNED_32;
encoding = MPG123_ENC_UNSIGNED_32; break;
break; case GST_AUDIO_FORMAT_F32:
case GST_AUDIO_FORMAT_F32: encoding = MPG123_ENC_FLOAT_32;
encoding = MPG123_ENC_FLOAT_32; break;
break; default:
default: g_assert_not_reached ();
GST_DEBUG_OBJECT (dec, goto done;
"Format %s in srccaps is not supported", format_str);
goto done;
}
} }
gst_caps_unref (allowed_srccaps);
} }
} }