Bug 1105209 - Add media resource request API. r=kentuckyfriedtakahe

This commit is contained in:
Alfredo Yang 2014-12-15 22:25:00 -05:00
parent 108d4524d5
commit a0051050f9
12 changed files with 77 additions and 15 deletions

View File

@ -2734,6 +2734,12 @@ MediaDecoderStateMachine::FlushDecoding()
DecodeTaskQueue()->FlushAndDispatch(task);
}
// These flags will be reset when the decoded data returned in OnAudioDecoded()
// and OnVideoDecoded(). Because the decode tasks are flushed, these flags need
// to be reset here.
mAudioRequestPending = false;
mVideoRequestPending = false;
// We must reset playback so that all references to frames queued
// in the state machine are dropped, else subsequent calls to Shutdown()
// or ReleaseMediaResources() can fail on B2G.

View File

@ -204,6 +204,14 @@ private:
};
#endif
void MP4Reader::RequestCodecResource() {
#ifdef MOZ_GONK_MEDIACODEC
if(mVideo.mDecoder) {
mVideo.mDecoder->AllocateMediaResources();
}
#endif
}
bool MP4Reader::IsWaitingOnCodecResource() {
#ifdef MOZ_GONK_MEDIACODEC
return mVideo.mDecoder && mVideo.mDecoder->IsWaitingMediaResources();
@ -273,6 +281,14 @@ MP4Reader::IsSupportedVideoMimeType(const char* aMimeType)
mPlatform->SupportsVideoMimeType(aMimeType);
}
void
MP4Reader::PreReadMetadata()
{
if (mPlatform) {
RequestCodecResource();
}
}
nsresult
MP4Reader::ReadMetadata(MediaInfo* aInfo,
MetadataTags** aTags)
@ -729,6 +745,7 @@ MP4Reader::Flush(TrackType aTrack)
data.RejectPromise(CANCELED, __func__);
}
data.mDiscontinuity = true;
data.mUpdateScheduled = false;
}
if (aTrack == kVideo) {
mQueuedVideoSample = nullptr;

View File

@ -45,6 +45,11 @@ public:
virtual bool HasAudio() MOZ_OVERRIDE;
virtual bool HasVideo() MOZ_OVERRIDE;
// PreReadMetadata() is called by MediaDecoderStateMachine::DecodeMetadata()
// before checking hardware resource. In Gonk, it requests hardware codec so
// MediaDecoderStateMachine could go to DORMANT state if the hardware codec is
// not available.
virtual void PreReadMetadata() MOZ_OVERRIDE;
virtual nsresult ReadMetadata(MediaInfo* aInfo,
MetadataTags** aTags) MOZ_OVERRIDE;
@ -107,6 +112,7 @@ private:
bool IsSupportedAudioMimeType(const char* aMimeType);
bool IsSupportedVideoMimeType(const char* aMimeType);
void NotifyResourcesStatusChanged();
void RequestCodecResource();
bool IsWaitingOnCodecResource();
virtual bool IsWaitingOnCDMResource() MOZ_OVERRIDE;

View File

@ -231,6 +231,7 @@ public:
virtual bool IsDormantNeeded() {
return false;
};
virtual void AllocateMediaResources() {}
virtual void ReleaseMediaResources() {}
virtual void ReleaseDecoder() {}
};

View File

@ -164,6 +164,12 @@ GonkMediaDataDecoder::IsDormantNeeded() {
return mDecoder.get() ? true : false;
}
void
GonkMediaDataDecoder::AllocateMediaResources()
{
mManager->AllocateMediaResources();
}
void
GonkMediaDataDecoder::ReleaseMediaResources() {
mManager->ReleaseMediaResources();

View File

@ -35,6 +35,8 @@ public:
nsRefPtr<MediaData>& aOutput) = 0;
virtual nsresult Flush() = 0;
virtual void AllocateMediaResources() {};
virtual void ReleaseMediaResources() {};
};
@ -65,6 +67,8 @@ public:
virtual bool IsDormantNeeded() MOZ_OVERRIDE;
virtual void AllocateMediaResources() MOZ_OVERRIDE;
virtual void ReleaseMediaResources() MOZ_OVERRIDE;
private:

View File

@ -474,6 +474,12 @@ GonkVideoDecoderManager::Flush()
return NS_OK;
}
void
GonkVideoDecoderManager::AllocateMediaResources()
{
mDecoder->RequestMediaResources();
}
void
GonkVideoDecoderManager::codecReserved()
{

View File

@ -52,6 +52,8 @@ public:
virtual nsresult Flush() MOZ_OVERRIDE;
virtual void AllocateMediaResources();
virtual void ReleaseMediaResources();
static void RecycleCallback(TextureClient* aClient, void* aClosure);

View File

@ -135,6 +135,12 @@ MediaCodecProxy::requestResource()
return true;
}
void
MediaCodecProxy::RequestMediaResources()
{
requestResource();
}
void
MediaCodecProxy::cancelResource()
{
@ -572,7 +578,6 @@ status_t MediaCodecProxy::Output(MediaBuffer** aBuffer, int64_t aTimeoutUs)
status_t err = dequeueOutputBuffer(&index, &offset, &size,
&timeUs, &flags, aTimeoutUs);
if (err != OK) {
ALOG("Output returned %d", err);
return err;
}
@ -598,9 +603,10 @@ status_t MediaCodecProxy::Output(MediaBuffer** aBuffer, int64_t aTimeoutUs)
bool MediaCodecProxy::IsWaitingResources()
{
// Write Lock for mCodec
RWLock::AutoWLock awl(mCodecLock);
return mCodec == nullptr;
if (mResourceHandler.get()) {
return mResourceHandler->IsWaitingResource();
}
return false;
}
bool MediaCodecProxy::IsDormantNeeded()

View File

@ -131,6 +131,7 @@ public:
bool Prepare();
bool IsWaitingResources();
bool IsDormantNeeded();
void RequestMediaResources();
void ReleaseMediaResources();
// This updates mOutputBuffer when receiving INFO_OUTPUT_BUFFERS_CHANGED event.
bool UpdateOutputBuffers();

View File

@ -5,15 +5,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MediaResourceHandler.h"
#include "mozilla/NullPtr.h"
namespace android {
MediaResourceHandler::MediaResourceHandler(const wp<ResourceListener> &aListener)
: mListener(aListener)
, mState(MediaResourceManagerClient::CLIENT_STATE_WAIT_FOR_RESOURCE)
, mType(IMediaResourceManagerService::INVALID_RESOURCE_TYPE)
, mWaitingResource(false)
{
}
@ -22,6 +21,13 @@ MediaResourceHandler::~MediaResourceHandler()
cancelResource();
}
bool
MediaResourceHandler::IsWaitingResource()
{
Mutex::Autolock al(mLock);
return mWaitingResource;
}
bool
MediaResourceHandler::requestResource(IMediaResourceManagerService::ResourceType aType)
{
@ -45,6 +51,7 @@ MediaResourceHandler::requestResource(IMediaResourceManagerService::ResourceType
mClient = client;
mService = service;
mType = aType;
mWaitingResource = true;
return true;
}
@ -58,6 +65,7 @@ MediaResourceHandler::cancelResource()
mService->cancelClient(mClient, (int)mType);
}
mWaitingResource = false;
mClient = nullptr;
mService = nullptr;
}
@ -70,19 +78,15 @@ MediaResourceHandler::statusChanged(int aEvent)
Mutex::Autolock autoLock(mLock);
MediaResourceManagerClient::State state = (MediaResourceManagerClient::State)aEvent;
if (state == mState) {
return;
}
mState = state;
listener = mListener.promote();
if (listener == nullptr) {
return;
}
if (mState == MediaResourceManagerClient::CLIENT_STATE_RESOURCE_ASSIGNED) {
mWaitingResource = false;
MediaResourceManagerClient::State state = (MediaResourceManagerClient::State)aEvent;
if (state == MediaResourceManagerClient::CLIENT_STATE_RESOURCE_ASSIGNED) {
listener->resourceReserved();
} else {
listener->resourceCanceled();

View File

@ -42,6 +42,8 @@ public:
// Cancel Resource
void cancelResource();
bool IsWaitingResource();
protected:
// MediaResourceManagerClient::EventListener::statusChanged()
virtual void statusChanged(int event);
@ -57,10 +59,11 @@ private:
// Resource Management
Mutex mLock;
MediaResourceManagerClient::State mState;
sp<IMediaResourceManagerClient> mClient;
sp<IMediaResourceManagerService> mService;
IMediaResourceManagerService::ResourceType mType;
bool mWaitingResource;
};
} // namespace android