[alsa-devel] [PATCH - alsa-plugins 1/2] a52 - fix 5.1 channel order with recent libavcodec
As of SVN r18540 libavcodec expects 5.1 channel audio with SMPTE channel order. Fix ALSA a52 plugin to use that order when built against such a libavcodec. Minor version of libavcodec was raised on the same day (Apr 17th 2009), so use that for the check.
Signed-off-by: Anssi Hannula anssi.hannula@iki.fi --- a52/pcm_a52.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/a52/pcm_a52.c b/a52/pcm_a52.c index 1abfdaa..b95d7d4 100644 --- a/a52/pcm_a52.c +++ b/a52/pcm_a52.c @@ -170,7 +170,13 @@ static int fill_data(snd_pcm_ioplug_t *io, static unsigned int ch_index[3][6] = { { 0, 1 }, { 0, 1, 2, 3 }, +#if LIBAVCODEC_VERSION_MAJOR > 52 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR >= 26) + /* current libavcodec expects SMPTE order */ + { 0, 1, 4, 5, 2, 3 }, +#else + /* libavcodec older than r18540 expects A52 order */ { 0, 4, 1, 2, 3, 5 }, +#endif }; /* flatten copy to n-channel interleaved */ dst_step = io->channels;
As of SVN r18631 (2009-04-20) A52 encoder of libavcodec outputs a warning at run-time if channel layout is not specified.
Fix that by setting the channel layout in a52_prepare() when building against libavcodec revision that supports this.
Signed-off-by: Anssi Hannula anssi.hannula@iki.fi --- a52/pcm_a52.c | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/a52/pcm_a52.c b/a52/pcm_a52.c index b95d7d4..ed491b3 100644 --- a/a52/pcm_a52.c +++ b/a52/pcm_a52.c @@ -436,6 +436,21 @@ static int a52_prepare(snd_pcm_ioplug_t *io) rec->avctx->bit_rate = rec->bitrate * 1000; rec->avctx->sample_rate = io->rate; rec->avctx->channels = io->channels; +#if LIBAVCODEC_VERSION_MAJOR > 52 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR >= 3) + switch (io->channels) { + case 2: + rec->avctx->channel_layout = CH_LAYOUT_STEREO; + break; + case 4: + rec->avctx->channel_layout = CH_LAYOUT_QUAD; + break; + case 6: + rec->avctx->channel_layout = CH_LAYOUT_5POINT1; + break; + default: + break; + } +#endif
if (avcodec_open(rec->avctx, rec->codec) < 0) return -EINVAL;
At Fri, 27 Nov 2009 17:15:45 +0200, Anssi Hannula wrote:
As of SVN r18540 libavcodec expects 5.1 channel audio with SMPTE channel order. Fix ALSA a52 plugin to use that order when built against such a libavcodec. Minor version of libavcodec was raised on the same day (Apr 17th 2009), so use that for the check.
Signed-off-by: Anssi Hannula anssi.hannula@iki.fi
Thanks, applied both patches now to GIT tree.
Takashi
a52/pcm_a52.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/a52/pcm_a52.c b/a52/pcm_a52.c index 1abfdaa..b95d7d4 100644 --- a/a52/pcm_a52.c +++ b/a52/pcm_a52.c @@ -170,7 +170,13 @@ static int fill_data(snd_pcm_ioplug_t *io, static unsigned int ch_index[3][6] = { { 0, 1 }, { 0, 1, 2, 3 }, +#if LIBAVCODEC_VERSION_MAJOR > 52 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR >= 26)
/* current libavcodec expects SMPTE order */
{ 0, 1, 4, 5, 2, 3 },
+#else
/* libavcodec older than r18540 expects A52 order */ { 0, 4, 1, 2, 3, 5 },
+#endif }; /* flatten copy to n-channel interleaved */ dst_step = io->channels; -- 1.6.4.4
participants (2)
-
Anssi Hannula
-
Takashi Iwai