Bug 1155498 - Part 5 - Use new FenceHandle to handle Decoder fence. r=sotaro

--HG--
extra : rebase_source : 07572915abb33e362bbd3e3817fb57e6296ae871
This commit is contained in:
Ethan Lin 2015-05-13 00:38:00 +02:00
parent 7980550521
commit 683fb496b3
3 changed files with 14 additions and 32 deletions

View File

@ -787,16 +787,9 @@ MediaCodecReader::TextureClientRecycleCallback(TextureClient* aClient)
return; return;
} }
#if MOZ_WIDGET_GONK && ANDROID_VERSION >= 17 FenceHandle handle = aClient->GetAndResetReleaseFenceHandle();
sp<Fence> fence = aClient->GetReleaseFenceHandle().mFence; mPendingReleaseItems.AppendElement(ReleaseItem(index, handle));
if (fence.get() && fence->isValid()) {
mPendingReleaseItems.AppendElement(ReleaseItem(index, fence));
} else {
mPendingReleaseItems.AppendElement(ReleaseItem(index, nullptr));
}
#else
mPendingReleaseItems.AppendElement(ReleaseItem(index));
#endif
mTextureClientIndexes.Remove(aClient); mTextureClientIndexes.Remove(aClient);
} }
@ -819,13 +812,13 @@ MediaCodecReader::WaitFenceAndReleaseOutputBuffer()
} }
for (size_t i = 0; i < releasingItems.Length(); i++) { for (size_t i = 0; i < releasingItems.Length(); i++) {
if (releasingItems[i].mReleaseFence.IsValid()) {
#if MOZ_WIDGET_GONK && ANDROID_VERSION >= 17 #if MOZ_WIDGET_GONK && ANDROID_VERSION >= 17
sp<Fence> fence; nsRefPtr<FenceHandle::FdObj> fdObj = releasingItems[i].mReleaseFence.GetAndResetFdObj();
fence = releasingItems[i].mReleaseFence; sp<Fence> fence = new Fence(fdObj->GetAndResetFd());
if (fence.get() && fence->isValid()) {
fence->waitForever("MediaCodecReader"); fence->waitForever("MediaCodecReader");
}
#endif #endif
}
if (mVideoTrack.mCodec != nullptr) { if (mVideoTrack.mCodec != nullptr) {
mVideoTrack.mCodec->releaseOutputBuffer(releasingItems[i].mReleaseIndex); mVideoTrack.mCodec->releaseOutputBuffer(releasingItems[i].mReleaseIndex);
} }

View File

@ -439,25 +439,17 @@ private:
int64_t mNextParserPosition; int64_t mNextParserPosition;
int64_t mParsedDataLength; int64_t mParsedDataLength;
nsAutoPtr<MP3FrameParser> mMP3FrameParser; nsAutoPtr<MP3FrameParser> mMP3FrameParser;
#if MOZ_WIDGET_GONK && ANDROID_VERSION >= 17
// mReleaseIndex corresponding to a graphic buffer, and the mReleaseFence is // mReleaseIndex corresponding to a graphic buffer, and the mReleaseFence is
// the graohic buffer's fence. We must wait for the fence signaled by // the graohic buffer's fence. We must wait for the fence signaled by
// compositor, otherwise we will see the flicker because the HW decoder and // compositor, otherwise we will see the flicker because the HW decoder and
// compositor use the buffer concurrently. // compositor use the buffer concurrently.
struct ReleaseItem { struct ReleaseItem {
ReleaseItem(size_t aIndex, const android::sp<android::Fence>& aFence) ReleaseItem(size_t aIndex, const FenceHandle& aFence)
: mReleaseIndex(aIndex) : mReleaseIndex(aIndex)
, mReleaseFence(aFence) {} , mReleaseFence(aFence) {}
size_t mReleaseIndex; size_t mReleaseIndex;
android::sp<android::Fence> mReleaseFence; FenceHandle mReleaseFence;
}; };
#else
struct ReleaseItem {
ReleaseItem(size_t aIndex)
: mReleaseIndex(aIndex) {}
size_t mReleaseIndex;
};
#endif
nsTArray<ReleaseItem> mPendingReleaseItems; nsTArray<ReleaseItem> mPendingReleaseItems;
}; };

View File

@ -355,7 +355,7 @@ void OmxDecoder::ReleaseMediaResources() {
GrallocTextureClientOGL* client = static_cast<GrallocTextureClientOGL*>(*it); GrallocTextureClientOGL* client = static_cast<GrallocTextureClientOGL*>(*it);
client->ClearRecycleCallback(); client->ClearRecycleCallback();
if (client->GetMediaBuffer()) { if (client->GetMediaBuffer()) {
mPendingVideoBuffers.push(BufferItem(client->GetMediaBuffer(), client->GetReleaseFenceHandle())); mPendingVideoBuffers.push(BufferItem(client->GetMediaBuffer(), client->GetAndResetReleaseFenceHandle()));
} }
} }
mPendingRecycleTexutreClients.clear(); mPendingRecycleTexutreClients.clear();
@ -873,12 +873,9 @@ void OmxDecoder::ReleaseAllPendingVideoBuffersLocked()
MediaBuffer *buffer; MediaBuffer *buffer;
buffer = releasingVideoBuffers[i].mMediaBuffer; buffer = releasingVideoBuffers[i].mMediaBuffer;
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
android::sp<Fence> fence; nsRefPtr<FenceHandle::FdObj> fdObj = releasingVideoBuffers.editItemAt(i).mReleaseFenceHandle.GetAndResetFdObj();
int fenceFd = -1; int fenceFd = fdObj->GetAndResetFd();
fence = releasingVideoBuffers[i].mReleaseFenceHandle.mFence;
if (fence.get() && fence->isValid()) {
fenceFd = fence->dup();
}
MOZ_ASSERT(buffer->refcount() == 1); MOZ_ASSERT(buffer->refcount() == 1);
// This code expect MediaBuffer's ref count is 1. // This code expect MediaBuffer's ref count is 1.
// Return gralloc buffer to ANativeWindow // Return gralloc buffer to ANativeWindow
@ -910,7 +907,7 @@ void OmxDecoder::RecycleCallbackImp(TextureClient* aClient)
mPendingRecycleTexutreClients.erase(aClient); mPendingRecycleTexutreClients.erase(aClient);
GrallocTextureClientOGL* client = static_cast<GrallocTextureClientOGL*>(aClient); GrallocTextureClientOGL* client = static_cast<GrallocTextureClientOGL*>(aClient);
if (client->GetMediaBuffer()) { if (client->GetMediaBuffer()) {
mPendingVideoBuffers.push(BufferItem(client->GetMediaBuffer(), client->GetReleaseFenceHandle())); mPendingVideoBuffers.push(BufferItem(client->GetMediaBuffer(), client->GetAndResetReleaseFenceHandle()));
} }
} }
sp<AMessage> notify = sp<AMessage> notify =