audio: Properly handle signedness in gst_audio_format_build_integer()

This commit is contained in:
Edward Hervey 2011-10-17 12:00:16 +02:00
parent 45c4a19472
commit b4858253dc
2 changed files with 19 additions and 1 deletions

View file

@ -153,17 +153,21 @@ gst_audio_format_build_integer (gboolean sign, gint endianness,
/* must be int */ /* must be int */
if (!GST_AUDIO_FORMAT_INFO_IS_INTEGER (finfo)) if (!GST_AUDIO_FORMAT_INFO_IS_INTEGER (finfo))
continue; continue;
/* width and depth must match */ /* width and depth must match */
if (width != GST_AUDIO_FORMAT_INFO_WIDTH (finfo)) if (width != GST_AUDIO_FORMAT_INFO_WIDTH (finfo))
continue; continue;
if (depth != GST_AUDIO_FORMAT_INFO_DEPTH (finfo)) if (depth != GST_AUDIO_FORMAT_INFO_DEPTH (finfo))
continue; continue;
/* if there is endianness, it must match */ /* if there is endianness, it must match */
e = GST_AUDIO_FORMAT_INFO_ENDIANNESS (finfo); e = GST_AUDIO_FORMAT_INFO_ENDIANNESS (finfo);
if (e && e != endianness) if (e && e != endianness)
continue; continue;
/* check sign */ /* check sign */
if (sign && !GST_AUDIO_FORMAT_INFO_IS_SIGNED (finfo)) if ((sign && !GST_AUDIO_FORMAT_INFO_IS_SIGNED (finfo)) ||
(!sign && GST_AUDIO_FORMAT_INFO_IS_SIGNED (finfo)))
continue; continue;
return GST_AUDIO_FORMAT_INFO_FORMAT (finfo); return GST_AUDIO_FORMAT_INFO_FORMAT (finfo);

View file

@ -551,6 +551,19 @@ GST_START_TEST (test_channel_layout_value_intersect)
GST_END_TEST; GST_END_TEST;
GST_START_TEST (test_audio_info)
{
GstAudioFormat fmt;
fmt = gst_audio_format_build_integer (TRUE, G_BYTE_ORDER, 8, 8);
fail_unless (fmt == GST_AUDIO_FORMAT_S8);
fmt = gst_audio_format_build_integer (FALSE, G_BYTE_ORDER, 8, 8);
fail_unless (fmt == GST_AUDIO_FORMAT_U8);
}
GST_END_TEST;
static Suite * static Suite *
audio_suite (void) audio_suite (void)
{ {
@ -559,6 +572,7 @@ audio_suite (void)
TCase *tc_chain = tcase_create ("general"); TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain); suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_audio_info);
tcase_add_test (tc_chain, test_multichannel_checks); tcase_add_test (tc_chain, test_multichannel_checks);
tcase_add_test (tc_chain, test_buffer_clipping_time); tcase_add_test (tc_chain, test_buffer_clipping_time);
tcase_add_test (tc_chain, test_buffer_clipping_samples); tcase_add_test (tc_chain, test_buffer_clipping_samples);