From 43ad6eaf7710e21d4d0df373103c3d99137d4ecc Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Tue, 1 Sep 2009 16:02:43 -0700 Subject: [PATCH] Squashed commit of the following: commit c45bfbb97ccd05982008df47181f9c73abaf0497 Author: Andreas Huber Date: Tue Sep 1 15:58:12 2009 -0700 This quirk should not be enabled by default in order to make the bug reproducible by the vendor. commit 21d72e80e795fcae53d9c3bcc8ba6312b081e420 Author: Andreas Huber Date: Tue Sep 1 15:55:45 2009 -0700 Undoing the hack to temporarily give up the lock to facilitate reading from the buffer source. This simply causes too many issues, there need to be independent threads providing input buffers and dequeuing output buffers. commit 84d507def8999c146ce124cc8edfe106c9ca70c2 Author: Andreas Huber Date: Tue Sep 1 15:16:23 2009 -0700 The AAC components appear to output stereo data even if the input data is mono... --- include/media/stagefright/OMXCodec.h | 2 +- media/libstagefright/OMXCodec.cpp | 46 +++++++++++++++++----------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/include/media/stagefright/OMXCodec.h b/include/media/stagefright/OMXCodec.h index 29cdf216f031b..5b0e0b4b573b4 100644 --- a/include/media/stagefright/OMXCodec.h +++ b/include/media/stagefright/OMXCodec.h @@ -136,7 +136,7 @@ private: void clearCodecSpecificData(); void setAMRFormat(); - void setAACFormat(); + void setAACFormat(int32_t numChannels, int32_t sampleRate); status_t setVideoPortFormatType( OMX_U32 portIndex, diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp index 3a065ae9e394c..7c8defc02ddd2 100644 --- a/media/libstagefright/OMXCodec.cpp +++ b/media/libstagefright/OMXCodec.cpp @@ -302,7 +302,11 @@ sp OMXCodec::Create( codec->setAMRFormat(); } if (!createEncoder && !strcasecmp("audio/mp4a-latm", mime)) { - codec->setAACFormat(); + int32_t numChannels, sampleRate; + CHECK(meta->findInt32(kKeyChannelCount, &numChannels)); + CHECK(meta->findInt32(kKeySampleRate, &sampleRate)); + + codec->setAACFormat(numChannels, sampleRate); } if (!strncasecmp(mime, "video/", 6)) { int32_t width, height; @@ -1321,10 +1325,6 @@ void OMXCodec::drainInputBuffer(BufferInfo *info) { return; } - // We're going to temporarily give up the lock while reading data - // from the source. A certain client unfortunately chose to have the - // thread supplying input data and reading output data be the same... - MediaBuffer *srcBuffer; status_t err; if (mSeekTimeUs >= 0) { @@ -1332,13 +1332,10 @@ void OMXCodec::drainInputBuffer(BufferInfo *info) { options.setSeekTo(mSeekTimeUs); mSeekTimeUs = -1; - mLock.unlock(); err = mSource->read(&srcBuffer, &options); } else { - mLock.unlock(); err = mSource->read(&srcBuffer); } - mLock.lock(); OMX_U32 flags = OMX_BUFFERFLAG_ENDOFFRAME; OMX_TICKS timestamp = 0; @@ -1496,20 +1493,22 @@ void OMXCodec::setAMRFormat() { } } -void OMXCodec::setAACFormat() { - OMX_AUDIO_PARAM_AACPROFILETYPE def; - def.nSize = sizeof(def); - def.nVersion.s.nVersionMajor = 1; - def.nVersion.s.nVersionMinor = 1; - def.nPortIndex = kPortIndexInput; +void OMXCodec::setAACFormat(int32_t numChannels, int32_t sampleRate) { + OMX_AUDIO_PARAM_AACPROFILETYPE profile; + profile.nSize = sizeof(profile); + profile.nVersion.s.nVersionMajor = 1; + profile.nVersion.s.nVersionMinor = 1; + profile.nPortIndex = kPortIndexInput; status_t err = - mOMX->get_parameter(mNode, OMX_IndexParamAudioAac, &def, sizeof(def)); + mOMX->get_parameter(mNode, OMX_IndexParamAudioAac, &profile, sizeof(profile)); CHECK_EQ(err, OK); - def.eAACStreamFormat = OMX_AUDIO_AACStreamFormatMP4ADTS; + profile.nChannels = numChannels; + profile.nSampleRate = sampleRate; + profile.eAACStreamFormat = OMX_AUDIO_AACStreamFormatMP4ADTS; - err = mOMX->set_parameter(mNode, OMX_IndexParamAudioAac, &def, sizeof(def)); + err = mOMX->set_parameter(mNode, OMX_IndexParamAudioAac, &profile, sizeof(profile)); CHECK_EQ(err, OK); } @@ -2123,8 +2122,19 @@ void OMXCodec::initOutputFormat(const sp &inputFormat) { inputFormat->findInt32(kKeyChannelCount, &numChannels); inputFormat->findInt32(kKeySampleRate, &sampleRate); + if ((OMX_U32)numChannels != params.nChannels) { + LOGW("Codec outputs a different number of channels than " + "the input stream contains."); + } + mOutputFormat->setCString(kKeyMIMEType, "audio/raw"); - mOutputFormat->setInt32(kKeyChannelCount, numChannels); + + // Use the codec-advertised number of channels, as some + // codecs appear to output stereo even if the input data is + // mono. + mOutputFormat->setInt32(kKeyChannelCount, params.nChannels); + + // The codec-reported sampleRate is not reliable... mOutputFormat->setInt32(kKeySampleRate, sampleRate); break; }