Loading media/libmediaplayerservice/nuplayer/DecoderWrapper.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -151,6 +151,7 @@ struct DecoderWrapper::WrapperReader : public AHandler { const sp<AMessage> ¬ify); void start(); void stop(); void readMore(bool flush = false); protected: Loading Loading @@ -189,6 +190,10 @@ void DecoderWrapper::WrapperReader::start() { readMore(); } void DecoderWrapper::WrapperReader::stop() { CHECK_EQ(mDecoder->stop(), (status_t)OK); } void DecoderWrapper::WrapperReader::readMore(bool flush) { if (!flush && mEOS) { return; Loading Loading @@ -351,6 +356,10 @@ void DecoderWrapper::onMessageReceived(const sp<AMessage> &msg) { onSetup(msg); break; case kWhatShutdown: onShutdown(); break; case kWhatInputDataRequested: { postFillBuffer(); Loading Loading @@ -493,6 +502,25 @@ void DecoderWrapper::onSetup(const sp<AMessage> &msg) { ++mNumPendingDecodes; } void DecoderWrapper::onShutdown() { mReaderLooper->stop(); mReaderLooper.clear(); mReader->stop(); mReader.clear(); mSource.clear(); mNumOutstandingInputBuffers = 0; mNumOutstandingOutputBuffers = 0; mNumPendingDecodes = 0; mFlushing = false; sp<AMessage> notify = mNotify->dup(); notify->setInt32("what", ACodec::kWhatShutdownCompleted); notify->post(); } void DecoderWrapper::postFillBuffer() { sp<AMessage> notify = mNotify->dup(); notify->setInt32("what", ACodec::kWhatFillThisBuffer); Loading media/libmediaplayerservice/nuplayer/DecoderWrapper.h +1 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ private: bool mFlushing; void onSetup(const sp<AMessage> &msg); void onShutdown(); void onFlush(); void onResume(); Loading media/libmediaplayerservice/nuplayer/NuPlayer.cpp +82 −18 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include "NuPlayerRenderer.h" #include "NuPlayerStreamListener.h" #include <media/stagefright/foundation/hexdump.h> #include <media/stagefright/foundation/ABuffer.h> #include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/foundation/AMessage.h> Loading @@ -31,6 +32,8 @@ #include <media/stagefright/MetaData.h> #include <surfaceflinger/Surface.h> #define SHUTDOWN_ON_DISCONTINUITY 0 namespace android { //////////////////////////////////////////////////////////////////////////////// Loading Loading @@ -132,10 +135,16 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { case kWhatScanSources: { instantiateDecoder(false, &mVideoDecoder); instantiateDecoder( false, &mVideoDecoder, false /* ignoreCodecSpecificData */); if (mAudioSink != NULL) { instantiateDecoder(true, &mAudioDecoder); instantiateDecoder( true, &mAudioDecoder, false /* ignoreCodecSpecificData */); } if (mEOS) { Loading Loading @@ -182,22 +191,20 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { LOGI("decoder %s flush completed", audio ? "audio" : "video"); if (mFlushingAudio == FLUSHED && mFlushingVideo == FLUSHED) { LOGI("both audio and video are flushed now."); mRenderer->signalTimeDiscontinuity(); #if SHUTDOWN_ON_DISCONTINUITY LOGI("initiating %s decoder shutdown", audio ? "audio" : "video"); if (mAudioDecoder != NULL) { mAudioDecoder->signalResume(); } (audio ? mAudioDecoder : mVideoDecoder)->initiateShutdown(); if (mVideoDecoder != NULL) { mVideoDecoder->signalResume(); if (audio) { mFlushingAudio = SHUTTING_DOWN_DECODER; } else { mFlushingVideo = SHUTTING_DOWN_DECODER; } #endif mFlushingAudio = NONE; mFlushingVideo = NONE; } finishFlushIfPossible(); } else if (what == ACodec::kWhatOutputFormatChanged) { CHECK(audio); Loading @@ -213,6 +220,23 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { mAudioSink->close(); CHECK_EQ(mAudioSink->open(sampleRate, numChannels), (status_t)OK); mAudioSink->start(); mRenderer->signalAudioSinkChanged(); } else if (what == ACodec::kWhatShutdownCompleted) { LOGI("%s shutdown completed", audio ? "audio" : "video"); if (audio) { mAudioDecoder.clear(); CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER); mFlushingAudio = SHUT_DOWN; } else { mVideoDecoder.clear(); CHECK_EQ((int)mFlushingVideo, (int)SHUTTING_DOWN_DECODER); mFlushingVideo = SHUT_DOWN; } finishFlushIfPossible(); } else { CHECK_EQ((int)what, (int)ACodec::kWhatDrainThisBuffer); Loading Loading @@ -265,6 +289,43 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { } } void NuPlayer::finishFlushIfPossible() { if (mFlushingAudio != FLUSHED && mFlushingAudio != SHUT_DOWN) { return; } if (mFlushingVideo != FLUSHED && mFlushingVideo != SHUT_DOWN) { return; } LOGI("both audio and video are flushed now."); mRenderer->signalTimeDiscontinuity(); if (mFlushingAudio == SHUT_DOWN) { instantiateDecoder( true, &mAudioDecoder, true /* ignoreCodecSpecificData */); CHECK(mAudioDecoder != NULL); } else if (mAudioDecoder != NULL) { mAudioDecoder->signalResume(); } if (mFlushingVideo == SHUT_DOWN) { instantiateDecoder( false, &mVideoDecoder, true /* ignoreCodecSpecificData */); CHECK(mVideoDecoder != NULL); } else if (mVideoDecoder != NULL) { mVideoDecoder->signalResume(); } mFlushingAudio = NONE; mFlushingVideo = NONE; } void NuPlayer::feedMoreTSData() { CHECK(!mEOS); Loading @@ -285,7 +346,10 @@ void NuPlayer::feedMoreTSData() { } else { if (buffer[0] == 0x00) { // XXX legacy mTSParser->signalDiscontinuity(ATSParser::DISCONTINUITY_SEEK); mTSParser->signalDiscontinuity( buffer[1] == 0x00 ? ATSParser::DISCONTINUITY_SEEK : ATSParser::DISCONTINUITY_FORMATCHANGE); } else { mTSParser->feedTSPacket(buffer, sizeof(buffer)); } Loading Loading @@ -354,7 +418,7 @@ status_t NuPlayer::dequeueAccessUnit( } status_t NuPlayer::instantiateDecoder( bool audio, sp<Decoder> *decoder) { bool audio, sp<Decoder> *decoder, bool ignoreCodecSpecificData) { if (*decoder != NULL) { return OK; } Loading @@ -378,7 +442,7 @@ status_t NuPlayer::instantiateDecoder( looper()->registerHandler(*decoder); const sp<MetaData> &meta = source->getFormat(); (*decoder)->configure(meta); (*decoder)->configure(meta, ignoreCodecSpecificData); return OK; } Loading media/libmediaplayerservice/nuplayer/NuPlayer.h +6 −2 Original line number Diff line number Diff line Loading @@ -79,14 +79,16 @@ private: NONE, AWAITING_DISCONTINUITY, FLUSHING_DECODER, FLUSHED SHUTTING_DOWN_DECODER, FLUSHED, SHUT_DOWN, }; FlushStatus mFlushingAudio; FlushStatus mFlushingVideo; status_t instantiateDecoder( bool audio, sp<Decoder> *decoder); bool audio, sp<Decoder> *decoder, bool ignoreCodecSpecificData); status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); void renderBuffer(bool audio, const sp<AMessage> &msg); Loading @@ -100,6 +102,8 @@ private: void feedMoreTSData(); void notifyListener(int msg, int ext1, int ext2); void finishFlushIfPossible(); DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); }; Loading media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp +15 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,8 @@ NuPlayer::Decoder::Decoder( NuPlayer::Decoder::~Decoder() { } void NuPlayer::Decoder::configure(const sp<MetaData> &meta) { void NuPlayer::Decoder::configure( const sp<MetaData> &meta, bool ignoreCodecSpecificData) { CHECK(mCodec == NULL); CHECK(mWrapper == NULL); Loading @@ -54,6 +55,10 @@ void NuPlayer::Decoder::configure(const sp<MetaData> &meta) { sp<AMessage> format = makeFormat(meta); if (ignoreCodecSpecificData) { mCSD.clear(); } if (mSurface != NULL) { format->setObject("surface", mSurface); } Loading Loading @@ -282,5 +287,14 @@ void NuPlayer::Decoder::signalResume() { } } void NuPlayer::Decoder::initiateShutdown() { if (mCodec != NULL) { mCodec->initiateShutdown(); } else { CHECK(mWrapper != NULL); mWrapper->initiateShutdown(); } } } // namespace android Loading
media/libmediaplayerservice/nuplayer/DecoderWrapper.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -151,6 +151,7 @@ struct DecoderWrapper::WrapperReader : public AHandler { const sp<AMessage> ¬ify); void start(); void stop(); void readMore(bool flush = false); protected: Loading Loading @@ -189,6 +190,10 @@ void DecoderWrapper::WrapperReader::start() { readMore(); } void DecoderWrapper::WrapperReader::stop() { CHECK_EQ(mDecoder->stop(), (status_t)OK); } void DecoderWrapper::WrapperReader::readMore(bool flush) { if (!flush && mEOS) { return; Loading Loading @@ -351,6 +356,10 @@ void DecoderWrapper::onMessageReceived(const sp<AMessage> &msg) { onSetup(msg); break; case kWhatShutdown: onShutdown(); break; case kWhatInputDataRequested: { postFillBuffer(); Loading Loading @@ -493,6 +502,25 @@ void DecoderWrapper::onSetup(const sp<AMessage> &msg) { ++mNumPendingDecodes; } void DecoderWrapper::onShutdown() { mReaderLooper->stop(); mReaderLooper.clear(); mReader->stop(); mReader.clear(); mSource.clear(); mNumOutstandingInputBuffers = 0; mNumOutstandingOutputBuffers = 0; mNumPendingDecodes = 0; mFlushing = false; sp<AMessage> notify = mNotify->dup(); notify->setInt32("what", ACodec::kWhatShutdownCompleted); notify->post(); } void DecoderWrapper::postFillBuffer() { sp<AMessage> notify = mNotify->dup(); notify->setInt32("what", ACodec::kWhatFillThisBuffer); Loading
media/libmediaplayerservice/nuplayer/DecoderWrapper.h +1 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ private: bool mFlushing; void onSetup(const sp<AMessage> &msg); void onShutdown(); void onFlush(); void onResume(); Loading
media/libmediaplayerservice/nuplayer/NuPlayer.cpp +82 −18 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ #include "NuPlayerRenderer.h" #include "NuPlayerStreamListener.h" #include <media/stagefright/foundation/hexdump.h> #include <media/stagefright/foundation/ABuffer.h> #include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/foundation/AMessage.h> Loading @@ -31,6 +32,8 @@ #include <media/stagefright/MetaData.h> #include <surfaceflinger/Surface.h> #define SHUTDOWN_ON_DISCONTINUITY 0 namespace android { //////////////////////////////////////////////////////////////////////////////// Loading Loading @@ -132,10 +135,16 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { case kWhatScanSources: { instantiateDecoder(false, &mVideoDecoder); instantiateDecoder( false, &mVideoDecoder, false /* ignoreCodecSpecificData */); if (mAudioSink != NULL) { instantiateDecoder(true, &mAudioDecoder); instantiateDecoder( true, &mAudioDecoder, false /* ignoreCodecSpecificData */); } if (mEOS) { Loading Loading @@ -182,22 +191,20 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { LOGI("decoder %s flush completed", audio ? "audio" : "video"); if (mFlushingAudio == FLUSHED && mFlushingVideo == FLUSHED) { LOGI("both audio and video are flushed now."); mRenderer->signalTimeDiscontinuity(); #if SHUTDOWN_ON_DISCONTINUITY LOGI("initiating %s decoder shutdown", audio ? "audio" : "video"); if (mAudioDecoder != NULL) { mAudioDecoder->signalResume(); } (audio ? mAudioDecoder : mVideoDecoder)->initiateShutdown(); if (mVideoDecoder != NULL) { mVideoDecoder->signalResume(); if (audio) { mFlushingAudio = SHUTTING_DOWN_DECODER; } else { mFlushingVideo = SHUTTING_DOWN_DECODER; } #endif mFlushingAudio = NONE; mFlushingVideo = NONE; } finishFlushIfPossible(); } else if (what == ACodec::kWhatOutputFormatChanged) { CHECK(audio); Loading @@ -213,6 +220,23 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { mAudioSink->close(); CHECK_EQ(mAudioSink->open(sampleRate, numChannels), (status_t)OK); mAudioSink->start(); mRenderer->signalAudioSinkChanged(); } else if (what == ACodec::kWhatShutdownCompleted) { LOGI("%s shutdown completed", audio ? "audio" : "video"); if (audio) { mAudioDecoder.clear(); CHECK_EQ((int)mFlushingAudio, (int)SHUTTING_DOWN_DECODER); mFlushingAudio = SHUT_DOWN; } else { mVideoDecoder.clear(); CHECK_EQ((int)mFlushingVideo, (int)SHUTTING_DOWN_DECODER); mFlushingVideo = SHUT_DOWN; } finishFlushIfPossible(); } else { CHECK_EQ((int)what, (int)ACodec::kWhatDrainThisBuffer); Loading Loading @@ -265,6 +289,43 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { } } void NuPlayer::finishFlushIfPossible() { if (mFlushingAudio != FLUSHED && mFlushingAudio != SHUT_DOWN) { return; } if (mFlushingVideo != FLUSHED && mFlushingVideo != SHUT_DOWN) { return; } LOGI("both audio and video are flushed now."); mRenderer->signalTimeDiscontinuity(); if (mFlushingAudio == SHUT_DOWN) { instantiateDecoder( true, &mAudioDecoder, true /* ignoreCodecSpecificData */); CHECK(mAudioDecoder != NULL); } else if (mAudioDecoder != NULL) { mAudioDecoder->signalResume(); } if (mFlushingVideo == SHUT_DOWN) { instantiateDecoder( false, &mVideoDecoder, true /* ignoreCodecSpecificData */); CHECK(mVideoDecoder != NULL); } else if (mVideoDecoder != NULL) { mVideoDecoder->signalResume(); } mFlushingAudio = NONE; mFlushingVideo = NONE; } void NuPlayer::feedMoreTSData() { CHECK(!mEOS); Loading @@ -285,7 +346,10 @@ void NuPlayer::feedMoreTSData() { } else { if (buffer[0] == 0x00) { // XXX legacy mTSParser->signalDiscontinuity(ATSParser::DISCONTINUITY_SEEK); mTSParser->signalDiscontinuity( buffer[1] == 0x00 ? ATSParser::DISCONTINUITY_SEEK : ATSParser::DISCONTINUITY_FORMATCHANGE); } else { mTSParser->feedTSPacket(buffer, sizeof(buffer)); } Loading Loading @@ -354,7 +418,7 @@ status_t NuPlayer::dequeueAccessUnit( } status_t NuPlayer::instantiateDecoder( bool audio, sp<Decoder> *decoder) { bool audio, sp<Decoder> *decoder, bool ignoreCodecSpecificData) { if (*decoder != NULL) { return OK; } Loading @@ -378,7 +442,7 @@ status_t NuPlayer::instantiateDecoder( looper()->registerHandler(*decoder); const sp<MetaData> &meta = source->getFormat(); (*decoder)->configure(meta); (*decoder)->configure(meta, ignoreCodecSpecificData); return OK; } Loading
media/libmediaplayerservice/nuplayer/NuPlayer.h +6 −2 Original line number Diff line number Diff line Loading @@ -79,14 +79,16 @@ private: NONE, AWAITING_DISCONTINUITY, FLUSHING_DECODER, FLUSHED SHUTTING_DOWN_DECODER, FLUSHED, SHUT_DOWN, }; FlushStatus mFlushingAudio; FlushStatus mFlushingVideo; status_t instantiateDecoder( bool audio, sp<Decoder> *decoder); bool audio, sp<Decoder> *decoder, bool ignoreCodecSpecificData); status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); void renderBuffer(bool audio, const sp<AMessage> &msg); Loading @@ -100,6 +102,8 @@ private: void feedMoreTSData(); void notifyListener(int msg, int ext1, int ext2); void finishFlushIfPossible(); DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); }; Loading
media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp +15 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,8 @@ NuPlayer::Decoder::Decoder( NuPlayer::Decoder::~Decoder() { } void NuPlayer::Decoder::configure(const sp<MetaData> &meta) { void NuPlayer::Decoder::configure( const sp<MetaData> &meta, bool ignoreCodecSpecificData) { CHECK(mCodec == NULL); CHECK(mWrapper == NULL); Loading @@ -54,6 +55,10 @@ void NuPlayer::Decoder::configure(const sp<MetaData> &meta) { sp<AMessage> format = makeFormat(meta); if (ignoreCodecSpecificData) { mCSD.clear(); } if (mSurface != NULL) { format->setObject("surface", mSurface); } Loading Loading @@ -282,5 +287,14 @@ void NuPlayer::Decoder::signalResume() { } } void NuPlayer::Decoder::initiateShutdown() { if (mCodec != NULL) { mCodec->initiateShutdown(); } else { CHECK(mWrapper != NULL); mWrapper->initiateShutdown(); } } } // namespace android