From d03bbd1e3e30753a52c88390880603e061d68648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 21 May 2008 07:39:56 +0000 Subject: [PATCH] gst-libs/gst/audio/multichannel.c: Allow non-standard 2 channel layouts. Original commit message from CVS: * gst-libs/gst/audio/multichannel.c: (gst_audio_check_channel_positions): Allow non-standard 2 channel layouts. * tests/check/elements/audioconvert.c: (GST_START_TEST): Add some tests for converting and remapping non-standard 1 and 2 channel layouts. --- ChangeLog | 10 ++ gst-libs/gst/audio/multichannel.c | 2 + tests/check/elements/audioconvert.c | 233 ++++++++++++++++++++++++++++ 3 files changed, 245 insertions(+) diff --git a/ChangeLog b/ChangeLog index 48b9aaa4b4..fb19bc410a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-05-21 Sebastian Dröge + + * gst-libs/gst/audio/multichannel.c: + (gst_audio_check_channel_positions): + Allow non-standard 2 channel layouts. + + * tests/check/elements/audioconvert.c: (GST_START_TEST): + Add some tests for converting and remapping non-standard 1 and 2 + channel layouts. + 2008-05-21 Sebastian Dröge * gst/audioconvert/gstchannelmix.c: diff --git a/gst-libs/gst/audio/multichannel.c b/gst-libs/gst/audio/multichannel.c index 76a3c6d6d0..435b1c1d96 100644 --- a/gst-libs/gst/audio/multichannel.c +++ b/gst-libs/gst/audio/multichannel.c @@ -135,12 +135,14 @@ gst_audio_check_channel_positions (const GstAudioChannelPosition * pos, /* Throw warning if we encounter an unusual 2-channel configuration, * at least until someone finds a reason why we should not */ +#if 0 if (channels == 2 && (pos[0] != GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT || pos[1] != GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT)) { g_warning ("channels=2 implies stereo, but channel positions are " "< %d, %d>", pos[0], pos[1]); return FALSE; } +#endif return TRUE; } diff --git a/tests/check/elements/audioconvert.c b/tests/check/elements/audioconvert.c index 92e62db878..511475252a 100644 --- a/tests/check/elements/audioconvert.c +++ b/tests/check/elements/audioconvert.c @@ -827,6 +827,119 @@ GST_START_TEST (test_multichannel_conversion) TRUE)); } + { + gint16 in[] = { 1, 2 }; + gint16 out[] = { 1, 1, 2, 2 }; + GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstAudioChannelPosition in_layout[1] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO }; + GstAudioChannelPosition out_layout[2] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, + GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT + }; + + set_channel_positions (in_caps, 1, in_layout); + set_channel_positions (out_caps, 2, out_layout); + + RUN_CONVERSION ("1 channels to 2 with standard layout", in, + in_caps, out, out_caps); + } + + { + gint16 in[] = { 1, 2 }; + gint16 out[] = { 1, 0, 2, 0 }; + GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstAudioChannelPosition in_layout[1] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT }; + GstAudioChannelPosition out_layout[2] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, + GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT + }; + + set_channel_positions (in_caps, 1, in_layout); + set_channel_positions (out_caps, 2, out_layout); + + RUN_CONVERSION ("1 channels to 2 with non-standard layout", in, + in_caps, out, out_caps); + } + + { + gint16 in[] = { 1, 2, 3, 4 }; + gint16 out[] = { 2, 4 }; + GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstAudioChannelPosition in_layout[2] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, + GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT + }; + GstAudioChannelPosition out_layout[1] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER }; + + set_channel_positions (in_caps, 2, in_layout); + set_channel_positions (out_caps, 1, out_layout); + + RUN_CONVERSION ("2 channels to 1 with non-standard layout", in, + in_caps, out, out_caps); + } + + { + gint16 in[] = { 1, 2, 3, 4 }; + gint16 out[] = { 2, 4 }; + GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstAudioChannelPosition in_layout[2] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, + GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT + }; + GstAudioChannelPosition out_layout[1] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO }; + + set_channel_positions (in_caps, 2, in_layout); + set_channel_positions (out_caps, 1, out_layout); + + RUN_CONVERSION ("2 channels to 1 with standard layout", in, + in_caps, out, out_caps); + } + + { + gint16 in[] = { 1, 2, 3, 4 }; + gint16 out[] = { 2, 4 }; + GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstAudioChannelPosition in_layout[2] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, + GST_AUDIO_CHANNEL_POSITION_REAR_CENTER + }; + GstAudioChannelPosition out_layout[1] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO }; + + set_channel_positions (in_caps, 2, in_layout); + set_channel_positions (out_caps, 1, out_layout); + + RUN_CONVERSION ("2 channels to 1 with non-standard layout", in, + in_caps, out, out_caps); + } + + { + gint16 in[] = { 1, 2, 3, 4 }; + gint16 out[] = { 1, 3 }; + GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstAudioChannelPosition in_layout[2] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, + GST_AUDIO_CHANNEL_POSITION_REAR_LEFT + }; + GstAudioChannelPosition out_layout[1] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO }; + + set_channel_positions (in_caps, 2, in_layout); + set_channel_positions (out_caps, 1, out_layout); + + RUN_CONVERSION ("2 channels to 1 with non-standard layout", in, + in_caps, out, out_caps); + } } GST_END_TEST; @@ -923,6 +1036,126 @@ GST_START_TEST (test_channel_remapping) RUN_CONVERSION ("3 channels layout remapping float32 --> int16", in, in_caps, out, out_caps); } + + /* gint16 to gint16 with 2 channels and non-standard layout */ + { + gint16 in[] = { 1, 2, 3, 4 }; + gint16 out[] = { -1, 2, -2, 4 }; + GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstAudioChannelPosition in_layout[2] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, + GST_AUDIO_CHANNEL_POSITION_LFE + }; + GstAudioChannelPosition out_layout[2] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, + GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT + }; + + set_channel_positions (in_caps, 2, in_layout); + set_channel_positions (out_caps, 2, out_layout); + + RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in, + in_caps, out, out_caps); + } + + /* gint16 to gint16 with 2 channels and non-standard layout */ + { + gint16 in[] = { 1, 2, 3, 4 }; + gint16 out[] = { 2, 1, 4, 3 }; + GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstAudioChannelPosition in_layout[2] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, + GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT + }; + GstAudioChannelPosition out_layout[2] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, + GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT + }; + + set_channel_positions (in_caps, 2, in_layout); + set_channel_positions (out_caps, 2, out_layout); + + RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in, + in_caps, out, out_caps); + } + + /* gint16 to gint16 with 2 channels and non-standard layout */ + { + gint16 in[] = { 1, 2, 3, 4 }; + gint16 out[] = { -1, 2, -3, 4 }; + GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstAudioChannelPosition in_layout[2] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, + GST_AUDIO_CHANNEL_POSITION_REAR_CENTER + }; + GstAudioChannelPosition out_layout[2] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, + GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT + }; + + set_channel_positions (in_caps, 2, in_layout); + set_channel_positions (out_caps, 2, out_layout); + + RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in, + in_caps, out, out_caps); + } + + /* gint16 to gint16 with 1 channel and non-standard layout */ + { + gint16 in[] = { 1, 2, 3, 4 }; + gint16 out[] = { 0, 0, 0, 0 }; + GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstAudioChannelPosition in_layout[1] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT }; + GstAudioChannelPosition out_layout[1] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT }; + + set_channel_positions (in_caps, 1, in_layout); + set_channel_positions (out_caps, 1, out_layout); + + RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in, + in_caps, out, out_caps); + } + + /* gint16 to gint16 with 1 channel and non-standard layout */ + { + gint16 in[] = { 1, 2, 3, 4 }; + gint16 out[] = { 1, 2, 3, 4 }; + GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstAudioChannelPosition in_layout[1] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO }; + GstAudioChannelPosition out_layout[1] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER }; + + set_channel_positions (in_caps, 1, in_layout); + set_channel_positions (out_caps, 1, out_layout); + + RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in, + in_caps, out, out_caps); + } + + /* gint16 to gint16 with 1 channel and non-standard layout */ + { + gint16 in[] = { 1, 2, 3, 4 }; + gint16 out[] = { -1, -2, -3, -4 }; + GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); + GstAudioChannelPosition in_layout[1] = + { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO }; + GstAudioChannelPosition out_layout[1] = + { GST_AUDIO_CHANNEL_POSITION_REAR_LEFT }; + + set_channel_positions (in_caps, 1, in_layout); + set_channel_positions (out_caps, 1, out_layout); + + RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in, + in_caps, out, out_caps); + } } GST_END_TEST;