From 8f06d2558e91a2bdbe9f981c3e47b4f5cc495e46 Mon Sep 17 00:00:00 2001 From: martii Date: Sun, 21 Jul 2013 14:54:57 +0200 Subject: [PATCH] libeplayer3/container_ffmpeg: fix mono->stereo conversion --- libeplayer3/container/container_ffmpeg.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libeplayer3/container/container_ffmpeg.c b/libeplayer3/container/container_ffmpeg.c index a622143..825767e 100644 --- a/libeplayer3/container/container_ffmpeg.c +++ b/libeplayer3/container/container_ffmpeg.c @@ -339,6 +339,7 @@ static void FFMPEGThread(Context_t *context) { SwrContext *swr = NULL; AVFrame *decoded_frame = NULL; int out_sample_rate = 44100; + int out_channels = 2; uint64_t out_channel_layout = AV_CH_LAYOUT_STEREO; ffmpeg_printf(10, "\n"); @@ -566,6 +567,7 @@ static void FFMPEGThread(Context_t *context) { rate++; out_sample_rate = *rate ? *rate : 44100; swr = swr_alloc(); + out_channels = c->channels; if (c->channel_layout == 0) { // FIXME -- need to guess, looks pretty much like a bug in the FFMPEG WMA decoder c->channel_layout = AV_CH_LAYOUT_STEREO; @@ -573,7 +575,10 @@ static void FFMPEGThread(Context_t *context) { out_channel_layout = c->channel_layout; // player2 won't play mono - out_channel_layout = (c->channel_layout == AV_CH_LAYOUT_MONO) ? AV_CH_LAYOUT_STEREO : c->channel_layout; + if (out_channel_layout == AV_CH_LAYOUT_MONO) { + out_channel_layout = AV_CH_LAYOUT_STEREO; + out_channels = 2; + } av_opt_set_int(swr, "in_channel_layout", c->channel_layout, 0); av_opt_set_int(swr, "out_channel_layout", out_channel_layout, 0); @@ -618,7 +623,7 @@ static void FFMPEGThread(Context_t *context) { extradata.bLittleEndian = 1; avOut.data = output; - avOut.len = out_samples * sizeof(short) * c->channels; + avOut.len = out_samples * sizeof(short) * out_channels; avOut.pts = pts; avOut.extradata = (unsigned char *) &extradata;