From 00f4951088805442e86ff9c2a20ddad79fc2410a Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Wed, 11 May 2011 14:15:13 -0700 Subject: The decoder wrapper is no longer needed. Also disable building old-style decoders. Change-Id: Ie022f1a6dffe619c1b0385aa13f63e097282cfe4 --- media/libmediaplayerservice/nuplayer/Android.mk | 1 - .../nuplayer/DecoderWrapper.cpp | 576 --------------------- .../nuplayer/DecoderWrapper.h | 82 --- .../nuplayer/NuPlayerDecoder.cpp | 34 +- .../nuplayer/NuPlayerDecoder.h | 2 - media/libstagefright/Android.mk | 2 +- 6 files changed, 5 insertions(+), 692 deletions(-) delete mode 100644 media/libmediaplayerservice/nuplayer/DecoderWrapper.cpp delete mode 100644 media/libmediaplayerservice/nuplayer/DecoderWrapper.h diff --git a/media/libmediaplayerservice/nuplayer/Android.mk b/media/libmediaplayerservice/nuplayer/Android.mk index c20e279..e761509 100644 --- a/media/libmediaplayerservice/nuplayer/Android.mk +++ b/media/libmediaplayerservice/nuplayer/Android.mk @@ -8,7 +8,6 @@ LOCAL_SRC_FILES:= \ NuPlayerDriver.cpp \ NuPlayerRenderer.cpp \ NuPlayerStreamListener.cpp \ - DecoderWrapper.cpp \ StreamingSource.cpp \ LOCAL_C_INCLUDES := \ diff --git a/media/libmediaplayerservice/nuplayer/DecoderWrapper.cpp b/media/libmediaplayerservice/nuplayer/DecoderWrapper.cpp deleted file mode 100644 index 802d1fb..0000000 --- a/media/libmediaplayerservice/nuplayer/DecoderWrapper.cpp +++ /dev/null @@ -1,576 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//#define LOG_NDEBUG 0 -#define LOG_TAG "DecoderWrapper" -#include - -#include "DecoderWrapper.h" - -#include "AACDecoder.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace android { - -struct DecoderWrapper::WrapperSource : public MediaSource { - WrapperSource( - const sp &meta, - const sp ¬ify); - - virtual status_t start(MetaData *params); - virtual status_t stop(); - virtual sp getFormat(); - - virtual status_t read( - MediaBuffer **buffer, const ReadOptions *options); - - void queueBuffer(const sp &buffer); - void queueEOS(status_t finalResult); - void clear(); - -protected: - virtual ~WrapperSource(); - -private: - Mutex mLock; - Condition mCondition; - - sp mMeta; - sp mNotify; - - List > mQueue; - status_t mFinalResult; - - DISALLOW_EVIL_CONSTRUCTORS(WrapperSource); -}; - -DecoderWrapper::WrapperSource::WrapperSource( - const sp &meta, const sp ¬ify) - : mMeta(meta), - mNotify(notify), - mFinalResult(OK) { -} - -DecoderWrapper::WrapperSource::~WrapperSource() { -} - -status_t DecoderWrapper::WrapperSource::start(MetaData *params) { - return OK; -} - -status_t DecoderWrapper::WrapperSource::stop() { - return OK; -} - -sp DecoderWrapper::WrapperSource::getFormat() { - return mMeta; -} - -status_t DecoderWrapper::WrapperSource::read( - MediaBuffer **out, const ReadOptions *options) { - Mutex::Autolock autoLock(mLock); - - bool requestedBuffer = false; - - while (mQueue.empty() && mFinalResult == OK) { - if (!requestedBuffer) { - mNotify->dup()->post(); - requestedBuffer = true; - } - - mCondition.wait(mLock); - } - - if (mQueue.empty()) { - return mFinalResult; - } - - sp src = *mQueue.begin(); - mQueue.erase(mQueue.begin()); - - MediaBuffer *dst = new MediaBuffer(src->size()); - memcpy(dst->data(), src->data(), src->size()); - - int64_t timeUs; - CHECK(src->meta()->findInt64("timeUs", &timeUs)); - - dst->meta_data()->setInt64(kKeyTime, timeUs); - - *out = dst; - - return OK; -} - -void DecoderWrapper::WrapperSource::queueBuffer(const sp &buffer) { - Mutex::Autolock autoLock(mLock); - mQueue.push_back(buffer); - mCondition.broadcast(); -} - -void DecoderWrapper::WrapperSource::queueEOS(status_t finalResult) { - CHECK_NE(finalResult, (status_t)OK); - - Mutex::Autolock autoLock(mLock); - mFinalResult = finalResult; - mCondition.broadcast(); -} - -void DecoderWrapper::WrapperSource::clear() { - Mutex::Autolock autoLock(mLock); - mQueue.clear(); - mFinalResult = OK; -} - -//////////////////////////////////////////////////////////////////////////////// - -struct DecoderWrapper::WrapperReader : public AHandler { - WrapperReader( - const sp &decoder, - const sp ¬ify); - - void start(); - void stop(); - void readMore(bool flush = false); - -protected: - virtual ~WrapperReader(); - - virtual void onMessageReceived(const sp &msg); - -private: - enum { - kWhatRead - }; - - sp mDecoder; - sp mNotify; - bool mEOS; - bool mSentFormat; - - void sendFormatChange(); - - DISALLOW_EVIL_CONSTRUCTORS(WrapperReader); -}; - -DecoderWrapper::WrapperReader::WrapperReader( - const sp &decoder, const sp ¬ify) - : mDecoder(decoder), - mNotify(notify), - mEOS(false), - mSentFormat(false) { -} - -DecoderWrapper::WrapperReader::~WrapperReader() { -} - -void DecoderWrapper::WrapperReader::start() { - CHECK_EQ(mDecoder->start(), (status_t)OK); - readMore(); -} - -void DecoderWrapper::WrapperReader::stop() { - CHECK_EQ(mDecoder->stop(), (status_t)OK); -} - -void DecoderWrapper::WrapperReader::readMore(bool flush) { - if (!flush && mEOS) { - return; - } - - sp msg = new AMessage(kWhatRead, id()); - msg->setInt32("flush", static_cast(flush)); - msg->post(); -} - -void DecoderWrapper::WrapperReader::onMessageReceived( - const sp &msg) { - switch (msg->what()) { - case kWhatRead: - { - int32_t flush; - CHECK(msg->findInt32("flush", &flush)); - - MediaSource::ReadOptions options; - if (flush) { - // Dummy seek - options.setSeekTo(0); - mEOS = false; - } - - CHECK(!mEOS); - - MediaBuffer *src; - status_t err = mDecoder->read(&src, &options); - - if (err == OK) { - if (!mSentFormat) { - sendFormatChange(); - mSentFormat = true; - } - - sp notify = mNotify->dup(); - - sp realNotify; - CHECK(notify->findMessage("real-notify", &realNotify)); - - realNotify->setInt32("what", ACodec::kWhatDrainThisBuffer); - - sp dst = new ABuffer(src->range_length()); - memcpy(dst->data(), - (const uint8_t *)src->data() + src->range_offset(), - src->range_length()); - - int64_t timeUs; - CHECK(src->meta_data()->findInt64(kKeyTime, &timeUs)); - src->release(); - src = NULL; - - dst->meta()->setInt64("timeUs", timeUs); - - realNotify->setObject("buffer", dst); - - notify->post(); - } else if (err == INFO_FORMAT_CHANGED) { - sendFormatChange(); - - readMore(false /* flush */); - } else { - sp notify = mNotify->dup(); - - sp realNotify; - CHECK(notify->findMessage("real-notify", &realNotify)); - - realNotify->setInt32("what", ACodec::kWhatEOS); - mEOS = true; - - notify->post(); - } - break; - } - - default: - TRESPASS(); - break; - } -} - -void DecoderWrapper::WrapperReader::sendFormatChange() { - sp notify = mNotify->dup(); - - sp realNotify; - CHECK(notify->findMessage("real-notify", &realNotify)); - - realNotify->setInt32("what", ACodec::kWhatOutputFormatChanged); - - sp meta = mDecoder->getFormat(); - - const char *mime; - CHECK(meta->findCString(kKeyMIMEType, &mime)); - - realNotify->setString("mime", mime); - - if (!strncasecmp("audio/", mime, 6)) { - int32_t numChannels; - CHECK(meta->findInt32(kKeyChannelCount, &numChannels)); - - int32_t sampleRate; - CHECK(meta->findInt32(kKeySampleRate, &sampleRate)); - - realNotify->setInt32("channel-count", numChannels); - realNotify->setInt32("sample-rate", sampleRate); - } else { - CHECK(!strncasecmp("video/", mime, 6)); - - int32_t width, height; - CHECK(meta->findInt32(kKeyWidth, &width)); - CHECK(meta->findInt32(kKeyHeight, &height)); - - realNotify->setInt32("width", width); - realNotify->setInt32("height", height); - - int32_t cropLeft, cropTop, cropRight, cropBottom; - if (!meta->findRect( - kKeyCropRect, - &cropLeft, &cropTop, &cropRight, &cropBottom)) { - cropLeft = 0; - cropTop = 0; - cropRight = width - 1; - cropBottom = height - 1; - } - - realNotify->setRect("crop", cropLeft, cropTop, cropRight, cropBottom); - } - - notify->post(); - - mSentFormat = true; -} - -//////////////////////////////////////////////////////////////////////////////// - -DecoderWrapper::DecoderWrapper() - : mNumOutstandingInputBuffers(0), - mNumOutstandingOutputBuffers(0), - mNumPendingDecodes(0), - mFlushing(false) { -} - -DecoderWrapper::~DecoderWrapper() { -} - -void DecoderWrapper::setNotificationMessage(const sp &msg) { - mNotify = msg; -} - -void DecoderWrapper::initiateSetup(const sp &msg) { - msg->setWhat(kWhatSetup); - msg->setTarget(id()); - msg->post(); -} - -void DecoderWrapper::initiateShutdown() { - (new AMessage(kWhatShutdown, id()))->post(); -} - -void DecoderWrapper::signalFlush() { - (new AMessage(kWhatFlush, id()))->post(); -} - -void DecoderWrapper::signalResume() { - (new AMessage(kWhatResume, id()))->post(); -} - -void DecoderWrapper::onMessageReceived(const sp &msg) { - switch (msg->what()) { - case kWhatSetup: - onSetup(msg); - break; - - case kWhatShutdown: - onShutdown(); - break; - - case kWhatInputDataRequested: - { - postFillBuffer(); - ++mNumOutstandingInputBuffers; - break; - } - - case kWhatInputBufferFilled: - { - CHECK_GT(mNumOutstandingInputBuffers, 0); - --mNumOutstandingInputBuffers; - - if (mFlushing) { - mSource->queueEOS(INFO_DISCONTINUITY); - - completeFlushIfPossible(); - break; - } - - sp obj; - if (!msg->findObject("buffer", &obj)) { - int32_t err = OK; - CHECK(msg->findInt32("err", &err)); - - mSource->queueEOS(err); - break; - } - - sp buffer = static_cast(obj.get()); - - mSource->queueBuffer(buffer); - break; - } - - case kWhatFillBufferDone: - { - sp notify; - CHECK(msg->findMessage("real-notify", ¬ify)); - - int32_t what; - CHECK(notify->findInt32("what", &what)); - - if (what == ACodec::kWhatDrainThisBuffer) { - CHECK_GT(mNumPendingDecodes, 0); - --mNumPendingDecodes; - - sp reply = - new AMessage(kWhatOutputBufferDrained, id()); - - notify->setMessage("reply", reply); - - ++mNumOutstandingOutputBuffers; - } else if (what == ACodec::kWhatEOS) { - CHECK_GT(mNumPendingDecodes, 0); - --mNumPendingDecodes; - - if (mFlushing) { - completeFlushIfPossible(); - break; - } - } - - notify->post(); - break; - } - - case kWhatOutputBufferDrained: - { - CHECK_GT(mNumOutstandingOutputBuffers, 0); - --mNumOutstandingOutputBuffers; - - if (mFlushing) { - completeFlushIfPossible(); - break; - } - - ++mNumPendingDecodes; - mReader->readMore(); - break; - } - - case kWhatFlush: - { - onFlush(); - break; - } - - case kWhatResume: - { - onResume(); - break; - } - - default: - TRESPASS(); - break; - } -} - -void DecoderWrapper::onSetup(const sp &msg) { - AString mime; - CHECK(msg->findString("mime", &mime)); - - CHECK(!strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_AAC)); - - int32_t numChannels, sampleRate; - CHECK(msg->findInt32("channel-count", &numChannels)); - CHECK(msg->findInt32("sample-rate", &sampleRate)); - - sp obj; - CHECK(msg->findObject("esds", &obj)); - sp esds = static_cast(obj.get()); - - sp meta = new MetaData; - meta->setCString(kKeyMIMEType, mime.c_str()); - meta->setInt32(kKeySampleRate, sampleRate); - meta->setInt32(kKeyChannelCount, numChannels); - meta->setData(kKeyESDS, 0, esds->data(), esds->size()); - - mSource = new WrapperSource( - meta, new AMessage(kWhatInputDataRequested, id())); - - sp decoder = new AACDecoder(mSource); - - mReaderLooper = new ALooper; - mReaderLooper->setName("DecoderWrapper looper"); - - mReaderLooper->start( - false, /* runOnCallingThread */ - false, /* canCallJava */ - PRIORITY_AUDIO); - - sp notify = new AMessage(kWhatFillBufferDone, id()); - notify->setMessage("real-notify", mNotify); - - mReader = new WrapperReader(decoder, notify); - mReaderLooper->registerHandler(mReader); - - mReader->start(); - ++mNumPendingDecodes; -} - -void DecoderWrapper::onShutdown() { - mReaderLooper->stop(); - mReaderLooper.clear(); - - mReader->stop(); - mReader.clear(); - - mSource.clear(); - - mNumOutstandingInputBuffers = 0; - mNumOutstandingOutputBuffers = 0; - mNumPendingDecodes = 0; - mFlushing = false; - - sp notify = mNotify->dup(); - notify->setInt32("what", ACodec::kWhatShutdownCompleted); - notify->post(); -} - -void DecoderWrapper::postFillBuffer() { - sp notify = mNotify->dup(); - notify->setInt32("what", ACodec::kWhatFillThisBuffer); - sp reply = new AMessage(kWhatInputBufferFilled, id()); - notify->setMessage("reply", reply); - notify->post(); -} - -void DecoderWrapper::onFlush() { - CHECK(!mFlushing); - mFlushing = true; - - completeFlushIfPossible(); -} - -void DecoderWrapper::completeFlushIfPossible() { - CHECK(mFlushing); - - if (mNumOutstandingInputBuffers > 0 - || mNumOutstandingOutputBuffers > 0 - || mNumPendingDecodes > 0) { - return; - } - - mFlushing = false; - - sp notify = mNotify->dup(); - notify->setInt32("what", ACodec::kWhatFlushCompleted); - notify->post(); -} - -void DecoderWrapper::onResume() { - CHECK(!mFlushing); - - ++mNumPendingDecodes; - - mSource->clear(); - mReader->readMore(true /* flush */); -} - -} // namespace android diff --git a/media/libmediaplayerservice/nuplayer/DecoderWrapper.h b/media/libmediaplayerservice/nuplayer/DecoderWrapper.h deleted file mode 100644 index b9be12c..0000000 --- a/media/libmediaplayerservice/nuplayer/DecoderWrapper.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DECODER_WRAPPER_H_ - -#define DECODER_WRAPPER_H_ - -#include - -namespace android { - -struct MediaSource; - -struct DecoderWrapper : public AHandler { - DecoderWrapper(); - - void setNotificationMessage(const sp &msg); - void initiateSetup(const sp &msg); - void initiateShutdown(); - void signalFlush(); - void signalResume(); - -protected: - virtual ~DecoderWrapper(); - - virtual void onMessageReceived(const sp &msg); - -private: - struct WrapperSource; - struct WrapperReader; - - enum { - kWhatSetup, - kWhatInputBufferFilled, - kWhatOutputBufferDrained, - kWhatShutdown, - kWhatFillBufferDone, - kWhatInputDataRequested, - kWhatFlush, - kWhatResume, - }; - - sp mNotify; - - sp mSource; - - sp mReaderLooper; - sp mReader; - - int32_t mNumOutstandingInputBuffers; - int32_t mNumOutstandingOutputBuffers; - int32_t mNumPendingDecodes; - bool mFlushing; - - void onSetup(const sp &msg); - void onShutdown(); - void onFlush(); - void onResume(); - - void postFillBuffer(); - void completeFlushIfPossible(); - - DISALLOW_EVIL_CONSTRUCTORS(DecoderWrapper); -}; - -} // namespace android - -#endif // DECODER_WRAPPER_H_ - diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp index 517acc9..81b41ef 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp @@ -20,7 +20,6 @@ #include "NuPlayerDecoder.h" -#include "DecoderWrapper.h" #include "ESDS.h" #include @@ -47,7 +46,6 @@ NuPlayer::Decoder::~Decoder() { void NuPlayer::Decoder::configure(const sp &meta) { CHECK(mCodec == NULL); - CHECK(mWrapper == NULL); const char *mime; CHECK(meta->findCString(kKeyMIMEType, &mime)); @@ -61,19 +59,11 @@ void NuPlayer::Decoder::configure(const sp &meta) { format->setObject("native-window", mNativeWindow); } - if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AAC)) { - mWrapper = new DecoderWrapper; - looper()->registerHandler(mWrapper); + mCodec = new ACodec; + looper()->registerHandler(mCodec); - mWrapper->setNotificationMessage(notifyMsg); - mWrapper->initiateSetup(format); - } else { - mCodec = new ACodec; - looper()->registerHandler(mCodec); - - mCodec->setNotificationMessage(notifyMsg); - mCodec->initiateSetup(format); - } + mCodec->setNotificationMessage(notifyMsg); + mCodec->initiateSetup(format); } void NuPlayer::Decoder::onMessageReceived(const sp &msg) { @@ -214,7 +204,6 @@ sp NuPlayer::Decoder::makeFormat(const sp &meta) { msg->setObject("csd", buffer); } else if (meta->findData(kKeyESDS, &type, &data, &size)) { -#if 0 ESDS esds((const char *)data, size); CHECK_EQ(esds.InitCheck(), (status_t)OK); @@ -230,12 +219,6 @@ sp NuPlayer::Decoder::makeFormat(const sp &meta) { buffer->meta()->setInt32("csd", true); mCSD.push(buffer); -#else - sp buffer = new ABuffer(size); - memcpy(buffer->data(), data, size); - - msg->setObject("esds", buffer); -#endif } return msg; @@ -270,27 +253,18 @@ void NuPlayer::Decoder::onFillThisBuffer(const sp &msg) { void NuPlayer::Decoder::signalFlush() { if (mCodec != NULL) { mCodec->signalFlush(); - } else { - CHECK(mWrapper != NULL); - mWrapper->signalFlush(); } } void NuPlayer::Decoder::signalResume() { if (mCodec != NULL) { mCodec->signalResume(); - } else { - CHECK(mWrapper != NULL); - mWrapper->signalResume(); } } void NuPlayer::Decoder::initiateShutdown() { if (mCodec != NULL) { mCodec->initiateShutdown(); - } else { - CHECK(mWrapper != NULL); - mWrapper->initiateShutdown(); } } diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h index 732f090..fabc606 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.h @@ -25,7 +25,6 @@ namespace android { struct ABuffer; -struct DecoderWrapper; struct NuPlayer::Decoder : public AHandler { Decoder(const sp ¬ify, @@ -51,7 +50,6 @@ private: sp mNativeWindow; sp mCodec; - sp mWrapper; Vector > mCSD; size_t mCSDIndex; diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk index d8cf810..f731dfb 100644 --- a/media/libstagefright/Android.mk +++ b/media/libstagefright/Android.mk @@ -3,7 +3,7 @@ include $(CLEAR_VARS) include frameworks/base/media/libstagefright/codecs/common/Config.mk -BUILD_WITH_SOFTWARE_DECODERS := true +BUILD_WITH_SOFTWARE_DECODERS := false LOCAL_SRC_FILES:= \ ACodec.cpp \ -- cgit v1.1