From 73e1b07e2d5bb1efdc6719d7a41ec57981dcbc96 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 8 Dec 2012 12:20:29 +0100 Subject: [PATCH] Fix playback of mono mpeg audio --- audioomx.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/audioomx.cc b/audioomx.cc index 1d72d2b..a803c1c 100644 --- a/audioomx.cc +++ b/audioomx.cc @@ -2032,6 +2032,7 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, int dsize = av_samples_get_buffer_size(NULL, current_context->channels, decode_frame_libav->nb_samples, current_context->sample_fmt, 1); + if (current_context->channels==1) dsize*=2; // we convert mono to stereo if ((cur_input_buf_omx->nFilledLen + dsize) > cur_input_buf_omx->nAllocLen ) { // I doubt that this will ever happen @@ -2075,8 +2076,22 @@ UINT AudioOMX::DeliverMediaPacket(MediaPacket packet, const UCHAR* buffer, } //Log::getInstance()->log("Audio", Log::DEBUG,"memcpy in %d %d %d" ,dsize,current_context->sample_rate,cur_input_buf_omx->nFilledLen); - memcpy(cur_input_buf_omx->pBuffer + cur_input_buf_omx->nFilledLen, - decode_frame_libav->data[0], dsize); + if (current_context->channels!=1) { + memcpy(cur_input_buf_omx->pBuffer + cur_input_buf_omx->nFilledLen, + decode_frame_libav->data[0], dsize); + } else { //convert to stereo + unsigned short* startbuffer=(unsigned short* )decode_frame_libav->data[0]; + unsigned short* endbuffer=(unsigned short* )(decode_frame_libav->data[0]+dsize/2); + unsigned short* destbuffer=(unsigned short* )(cur_input_buf_omx->pBuffer + cur_input_buf_omx->nFilledLen); + while (startbuffer!=endbuffer) { + unsigned short temp=*startbuffer; + *destbuffer=temp; + destbuffer++; + *destbuffer=temp; + destbuffer++; + startbuffer++; + } + } //Log::getInstance()->log("Audio", Log::DEBUG,"memcpy out"); cur_input_buf_omx->nFilledLen += dsize; } else { -- 2.39.5