diff options
author | Tim-Philipp Müller <tim@centricular.net> | 2013-02-16 12:14:31 +0000 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.net> | 2013-02-16 12:14:31 +0000 |
commit | c5c34dda9b8a71159ca8aee2b5d822b60e0a6ea4 (patch) | |
tree | 6dd804994b0a637f61957ccf1afdf218b5ddc0d7 | |
parent | 9362d986a4742cc9afc4ba5110546babf4a1a251 (diff) | |
download | gstreamer-plugins-base-c5c34dda9b8a71159ca8aee2b5d822b60e0a6ea4.tar.gz |
audio: fix gst_audio_format_from_caps() for 8-bit formats
The endianness field is not present in 8-bit audio caps, so don't
fail because of that when parsing caps into an GstAudioInfo structure.
And if it is present, it should be ignored, because the format
table we match against has a 0 value for endianness, so we need
to look for 0 as well.
https://bugzilla.gnome.org/show_bug.cgi?id=693166
-rw-r--r-- | gst-libs/gst/audio/audio.c | 8 | ||||
-rw-r--r-- | tests/check/libs/audio.c | 36 |
2 files changed, 40 insertions, 4 deletions
diff --git a/gst-libs/gst/audio/audio.c b/gst-libs/gst/audio/audio.c index d2d15c394..1044bb059 100644 --- a/gst-libs/gst/audio/audio.c +++ b/gst-libs/gst/audio/audio.c @@ -340,7 +340,7 @@ static GstAudioFormatInfo formats[] = { static GstAudioFormat gst_audio_format_from_caps_structure (const GstStructure * s) { - gint endianness, width, depth; + gint endianness = 0, width, depth; guint i; if (gst_structure_has_name (s, "audio/x-raw-int")) { @@ -349,15 +349,15 @@ gst_audio_format_from_caps_structure (const GstStructure * s) if (!gst_structure_get_boolean (s, "signed", &sign)) goto missing_field_signed; - if (!gst_structure_get_int (s, "endianness", &endianness)) - goto missing_field_endianness; - if (!gst_structure_get_int (s, "width", &width)) goto missing_field_width; if (!gst_structure_get_int (s, "depth", &depth)) goto missing_field_depth; + if (width > 8 && !gst_structure_get_int (s, "endianness", &endianness)) + goto missing_field_endianness; + for (i = 0; i < G_N_ELEMENTS (formats); i++) { if (GST_AUDIO_FORMAT_INFO_IS_INTEGER (&formats[i]) && sign == GST_AUDIO_FORMAT_INFO_IS_SIGNED (&formats[i]) && diff --git a/tests/check/libs/audio.c b/tests/check/libs/audio.c index f5fab5701..d2fc2e21c 100644 --- a/tests/check/libs/audio.c +++ b/tests/check/libs/audio.c @@ -524,6 +524,41 @@ GST_START_TEST (test_channel_layout_value_intersect) GST_END_TEST; +GST_START_TEST (test_format_from_caps) +{ + GstAudioInfo info = { NULL, }; + GstCaps *caps; + + caps = gst_caps_from_string ("audio/x-raw-int, " + "signed=(boolean)true, rate=(int)44100, channels=(int)2, " + "width=(int)8, depth=(int)8"); + fail_unless (gst_audio_info_from_caps (&info, caps)); + fail_unless_equals_int (GST_AUDIO_INFO_FORMAT (&info), GST_AUDIO_FORMAT_S8); + fail_unless_equals_int (GST_AUDIO_INFO_WIDTH (&info), 8); + fail_unless_equals_int (GST_AUDIO_INFO_DEPTH (&info), 8); + fail_unless_equals_int (GST_AUDIO_INFO_BPF (&info), sizeof (guint8) * 2); + fail_unless_equals_int (GST_AUDIO_INFO_RATE (&info), 44100); + fail_unless_equals_int (GST_AUDIO_INFO_CHANNELS (&info), 2); + fail_unless_equals_int (GST_AUDIO_INFO_ENDIANNESS (&info), 0); + gst_caps_unref (caps); + + /* superfluous endianess field should not break stuff */ + caps = gst_caps_from_string ("audio/x-raw-int, endianness=(int)1234, " + "signed=(boolean)false, rate=(int)44100, channels=(int)2, " + "width=(int)8, depth=(int)8"); + fail_unless (gst_audio_info_from_caps (&info, caps)); + fail_unless_equals_int (GST_AUDIO_INFO_FORMAT (&info), GST_AUDIO_FORMAT_U8); + fail_unless_equals_int (GST_AUDIO_INFO_WIDTH (&info), 8); + fail_unless_equals_int (GST_AUDIO_INFO_DEPTH (&info), 8); + fail_unless_equals_int (GST_AUDIO_INFO_BPF (&info), sizeof (guint8) * 2); + fail_unless_equals_int (GST_AUDIO_INFO_RATE (&info), 44100); + fail_unless_equals_int (GST_AUDIO_INFO_CHANNELS (&info), 2); + fail_unless_equals_int (GST_AUDIO_INFO_ENDIANNESS (&info), 0); + gst_caps_unref (caps); +} + +GST_END_TEST; + static Suite * audio_suite (void) { @@ -536,6 +571,7 @@ audio_suite (void) tcase_add_test (tc_chain, test_buffer_clipping_time); tcase_add_test (tc_chain, test_buffer_clipping_samples); tcase_add_test (tc_chain, test_channel_layout_value_intersect); + tcase_add_test (tc_chain, test_format_from_caps); return s; } |