Bug 1050667 - fix the non-synchronous waiting state between MediaDecoderStataMachine and MediaCodecReader. r=sotaro

This commit is contained in:
Benjamin Chen 2014-10-02 14:01:16 +08:00
Родитель 255f395915
Коммит 67eca6183a
2 изменённых файлов: 29 добавлений и 1 удалений

Просмотреть файл

@ -285,6 +285,7 @@ MediaCodecReader::MediaCodecReader(AbstractMediaDecoder* aDecoder)
, mParseDataFromCache(true)
, mNextParserPosition(INT64_C(0))
, mParsedDataLength(INT64_C(0))
, mIsWaitingResources(false)
{
mHandler = new MessageHandler(this);
mVideoListener = new VideoResourceListener(this);
@ -304,7 +305,14 @@ MediaCodecReader::Init(MediaDecoderReader* aCloneDonor)
bool
MediaCodecReader::IsWaitingMediaResources()
{
return mVideoTrack.mCodec != nullptr && !mVideoTrack.mCodec->allocated();
return mIsWaitingResources;
}
void
MediaCodecReader::UpdateIsWaitingMediaResources()
{
mIsWaitingResources = (mVideoTrack.mCodec != nullptr) &&
(!mVideoTrack.mCodec->allocated());
}
bool
@ -647,6 +655,13 @@ MediaCodecReader::ParseDataSegment(const char* aBuffer,
return true;
}
void
MediaCodecReader::PreReadMetadata()
{
UpdateIsWaitingMediaResources();
}
nsresult
MediaCodecReader::ReadMetadata(MediaInfo* aInfo,
MetadataTags** aTags)
@ -661,6 +676,11 @@ MediaCodecReader::ReadMetadata(MediaInfo* aInfo,
return NS_ERROR_FAILURE;
}
// Bug 1050667, both MediaDecoderStateMachine and MediaCodecReader
// relies on IsWaitingMediaResources() function. And the waiting state will be
// changed by binder thread, so we store the waiting state in a cache value to
// make them in the same waiting state.
UpdateIsWaitingMediaResources();
if (IsWaitingMediaResources()) {
return NS_OK;
}

Просмотреть файл

@ -78,6 +78,7 @@ public:
virtual bool HasAudio();
virtual bool HasVideo();
virtual void PreReadMetadata() MOZ_OVERRIDE;
// Read header data for all bitstreams in the file. Fills aInfo with
// the data required to present the media, and optionally fills *aTags
// with tag metadata from the file.
@ -152,7 +153,14 @@ protected:
virtual bool CreateExtractor();
// Check the underlying HW resource is available and store the result in
// mIsWaitingResources.
void UpdateIsWaitingMediaResources();
android::sp<android::MediaExtractor> mExtractor;
// A cache value updated by UpdateIsWaitingMediaResources(), makes the
// "waiting resources state" is synchronous to StateMachine.
bool mIsWaitingResources;
private:
// An intermediary class that can be managed by android::sp<T>.