Backed out changeset ddb936f4e78a (bug 1160914) for build bustage CLOSED TREE

This commit is contained in:
Wes Kocher 2015-05-04 16:32:41 -07:00
parent bdc1fc1fa2
commit 1481c9f857
7 changed files with 66 additions and 100 deletions

View File

@ -32,8 +32,6 @@ AudioDecoder::AudioDecoder(GMPAudioHost *aHostAPI)
, mNumInputTasks(0)
, mHasShutdown(false)
{
// We drop the ref in DecodingComplete().
AddRef();
}
AudioDecoder::~AudioDecoder()
@ -86,9 +84,9 @@ AudioDecoder::Decode(GMPAudioSamples* aInput)
AutoLock lock(mMutex);
mNumInputTasks++;
}
mWorkerThread->Post(WrapTaskRefCounted(this,
&AudioDecoder::DecodeTask,
aInput));
mWorkerThread->Post(WrapTask(this,
&AudioDecoder::DecodeTask,
aInput));
}
void
@ -260,8 +258,8 @@ AudioDecoder::Drain()
return;
}
EnsureWorker();
mWorkerThread->Post(WrapTaskRefCounted(this,
&AudioDecoder::DrainTask));
mWorkerThread->Post(WrapTask(this,
&AudioDecoder::DrainTask));
}
void
@ -272,19 +270,24 @@ AudioDecoder::DecodingComplete()
}
mHasShutdown = true;
// Release the reference we added in the constructor. There may be
// WrapRefCounted tasks that also hold references to us, and keep
// us alive a little longer.
Release();
// Worker thread might have dispatched more tasks to the main thread that need this object.
// Append another task to delete |this|.
GetPlatform()->runonmainthread(WrapTask(this, &AudioDecoder::Destroy));
}
void
AudioDecoder::MaybeRunOnMainThread(GMPTask* aTask)
AudioDecoder::Destroy()
{
delete this;
}
void
AudioDecoder::MaybeRunOnMainThread(gmp_task_args_base* aTask)
{
class MaybeRunTask : public GMPTask
{
public:
MaybeRunTask(AudioDecoder* aDecoder, GMPTask* aTask)
MaybeRunTask(AudioDecoder* aDecoder, gmp_task_args_base* aTask)
: mDecoder(aDecoder), mTask(aTask)
{ }
@ -304,8 +307,8 @@ AudioDecoder::MaybeRunOnMainThread(GMPTask* aTask)
}
private:
RefPtr<AudioDecoder> mDecoder;
GMPTask* mTask;
AudioDecoder* mDecoder;
gmp_task_args_base* mTask;
};
GetPlatform()->runonmainthread(new MaybeRunTask(this, aTask));

View File

@ -21,16 +21,16 @@
#include "gmp-audio-host.h"
#include "gmp-task-utils.h"
#include "WMFAACDecoder.h"
#include "RefCounted.h"
#include "mfobjects.h"
class AudioDecoder : public GMPAudioDecoder
, public RefCounted
{
public:
AudioDecoder(GMPAudioHost *aHostAPI);
virtual ~AudioDecoder();
virtual void InitDecode(const GMPAudioCodec& aCodecSettings,
GMPAudioDecoderCallback* aCallback) override;
@ -45,7 +45,6 @@ public:
bool HasShutdown() { return mHasShutdown; }
private:
virtual ~AudioDecoder();
void EnsureWorker();
@ -57,7 +56,8 @@ private:
HRESULT MFToGMPSample(IMFSample* aSample,
GMPAudioSamples* aAudioFrame);
void MaybeRunOnMainThread(GMPTask* aTask);
void MaybeRunOnMainThread(gmp_task_args_base* aTask);
void Destroy();
GMPAudioHost *mHostAPI; // host-owned, invalid at DecodingComplete
GMPAudioDecoderCallback* mCallback; // host-owned, invalid at DecodingComplete

View File

@ -48,6 +48,7 @@ ClearKeySessionManager::ClearKeySessionManager()
ClearKeySessionManager::~ClearKeySessionManager()
{
CK_LOGD("ClearKeySessionManager dtor %p", this);
assert(!mRefCount);
}
static bool
@ -386,9 +387,9 @@ ClearKeySessionManager::Decrypt(GMPBuffer* aBuffer,
return;
}
mThread->Post(WrapTaskRefCounted(this,
&ClearKeySessionManager::DoDecrypt,
aBuffer, aMetadata));
mThread->Post(WrapTask(this,
&ClearKeySessionManager::DoDecrypt,
aBuffer, aMetadata));
}
void

View File

@ -18,10 +18,8 @@
#define __RefCount_h__
#include <stdint.h>
#include <atomic>
#include <assert.h>
// Note: Thread safe.
// Note: Not thread safe!
class RefCounted {
public:
void AddRef() {
@ -43,9 +41,8 @@ protected:
}
virtual ~RefCounted()
{
assert(!mRefCount);
}
std::atomic<uint32_t> mRefCount;
uint32_t mRefCount;
};
template<class T>

View File

@ -35,8 +35,6 @@ VideoDecoder::VideoDecoder(GMPVideoHost *aHostAPI)
, mSentExtraData(false)
, mHasShutdown(false)
{
// We drop the ref in DecodingComplete().
AddRef();
}
VideoDecoder::~VideoDecoder()
@ -114,9 +112,9 @@ VideoDecoder::Decode(GMPVideoEncodedFrame* aInputFrame,
// Note: we don't need the codec specific info on a per-frame basis.
// It's mostly useful for WebRTC use cases.
mWorkerThread->Post(WrapTaskRefCounted(this,
&VideoDecoder::DecodeTask,
aInputFrame));
mWorkerThread->Post(WrapTask(this,
&VideoDecoder::DecodeTask,
aInputFrame));
}
class AutoReleaseVideoFrame {
@ -199,12 +197,12 @@ VideoDecoder::DecodeTask(GMPVideoEncodedFrame* aInput)
CK_LOGD("VideoDecoder::DecodeTask() output ret=0x%x\n", hr);
if (hr == S_OK) {
MaybeRunOnMainThread(
WrapTaskRefCounted(this,
&VideoDecoder::ReturnOutput,
CComPtr<IMFSample>(output),
mDecoder->GetFrameWidth(),
mDecoder->GetFrameHeight(),
mDecoder->GetStride()));
WrapTask(this,
&VideoDecoder::ReturnOutput,
CComPtr<IMFSample>(output),
mDecoder->GetFrameWidth(),
mDecoder->GetFrameHeight(),
mDecoder->GetStride()));
}
if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) {
AutoLock lock(mMutex);
@ -234,20 +232,11 @@ VideoDecoder::ReturnOutput(IMFSample* aSample,
HRESULT hr;
GMPVideoFrame* f = nullptr;
auto err = mHostAPI->CreateFrame(kGMPI420VideoFrame, &f);
if (GMP_FAILED(err) || !f) {
mHostAPI->CreateFrame(kGMPI420VideoFrame, &f);
if (!f) {
CK_LOGE("Failed to create i420 frame!\n");
return;
}
if (HasShutdown()) {
// Note: GMPVideoHost::CreateFrame() can process messages before returning,
// including a message that calls VideoDecoder::DecodingComplete(), i.e.
// we can shutdown during the call!
CK_LOGD("Shutdown while waiting on GMPVideoHost::CreateFrame()!\n");
f->Destroy();
return;
}
auto vf = static_cast<GMPVideoi420Frame*>(f);
hr = SampleToVideoFrame(aSample, aWidth, aHeight, aStride, vf);
@ -302,10 +291,9 @@ VideoDecoder::SampleToVideoFrame(IMFSample* aSample,
int32_t halfStride = (stride + 1) / 2;
int32_t halfHeight = (aHeight + 1) / 2;
auto err = aVideoFrame->CreateEmptyFrame(stride, aHeight, stride, halfStride, halfStride);
ENSURE(GMP_SUCCEEDED(err), E_FAIL);
aVideoFrame->CreateEmptyFrame(stride, aHeight, stride, halfStride, halfStride);
err = aVideoFrame->SetWidth(aWidth);
auto err = aVideoFrame->SetWidth(aWidth);
ENSURE(GMP_SUCCEEDED(err), E_FAIL);
err = aVideoFrame->SetHeight(aHeight);
ENSURE(GMP_SUCCEEDED(err), E_FAIL);
@ -367,12 +355,12 @@ VideoDecoder::DrainTask()
CK_LOGD("VideoDecoder::DrainTask() output ret=0x%x\n", hr);
if (hr == S_OK) {
MaybeRunOnMainThread(
WrapTaskRefCounted(this,
&VideoDecoder::ReturnOutput,
CComPtr<IMFSample>(output),
mDecoder->GetFrameWidth(),
mDecoder->GetFrameHeight(),
mDecoder->GetStride()));
WrapTask(this,
&VideoDecoder::ReturnOutput,
CComPtr<IMFSample>(output),
mDecoder->GetFrameWidth(),
mDecoder->GetFrameHeight(),
mDecoder->GetStride()));
}
}
MaybeRunOnMainThread(WrapTask(mCallback, &GMPVideoDecoderCallback::DrainComplete));
@ -388,8 +376,8 @@ VideoDecoder::Drain()
return;
}
EnsureWorker();
mWorkerThread->Post(WrapTaskRefCounted(this,
&VideoDecoder::DrainTask));
mWorkerThread->Post(WrapTask(this,
&VideoDecoder::DrainTask));
}
void
@ -400,19 +388,24 @@ VideoDecoder::DecodingComplete()
}
mHasShutdown = true;
// Release the reference we added in the constructor. There may be
// WrapRefCounted tasks that also hold references to us, and keep
// us alive a little longer.
Release();
// Worker thread might have dispatched more tasks to the main thread that need this object.
// Append another task to delete |this|.
GetPlatform()->runonmainthread(WrapTask(this, &VideoDecoder::Destroy));
}
void
VideoDecoder::MaybeRunOnMainThread(GMPTask* aTask)
VideoDecoder::Destroy()
{
delete this;
}
void
VideoDecoder::MaybeRunOnMainThread(gmp_task_args_base* aTask)
{
class MaybeRunTask : public GMPTask
{
public:
MaybeRunTask(VideoDecoder* aDecoder, GMPTask* aTask)
MaybeRunTask(VideoDecoder* aDecoder, gmp_task_args_base* aTask)
: mDecoder(aDecoder), mTask(aTask)
{ }
@ -432,8 +425,8 @@ VideoDecoder::MaybeRunOnMainThread(GMPTask* aTask)
}
private:
RefPtr<VideoDecoder> mDecoder;
GMPTask* mTask;
VideoDecoder* mDecoder;
gmp_task_args_base* mTask;
};
GetPlatform()->runonmainthread(new MaybeRunTask(this, aTask));

View File

@ -25,11 +25,12 @@
#include "mfobjects.h"
class VideoDecoder : public GMPVideoDecoder
, public RefCounted
{
public:
VideoDecoder(GMPVideoHost *aHostAPI);
virtual ~VideoDecoder();
virtual void InitDecode(const GMPVideoCodec& aCodecSettings,
const uint8_t* aCodecSpecific,
uint32_t aCodecSpecificLength,
@ -52,8 +53,6 @@ public:
private:
virtual ~VideoDecoder();
void EnsureWorker();
void DrainTask();
@ -71,7 +70,8 @@ private:
int32_t aStride,
GMPVideoi420Frame* aVideoFrame);
void MaybeRunOnMainThread(GMPTask* aTask);
void MaybeRunOnMainThread(gmp_task_args_base* aTask);
void Destroy();
GMPVideoHost *mHostAPI; // host-owned, invalid at DecodingComplete
GMPVideoDecoderCallback* mCallback; // host-owned, invalid at DecodingComplete

View File

@ -14,7 +14,6 @@
* limitations under the License.
*/
#include "RefCounted.h"
// 0 arguments --
template<typename M> class gmp_task_args_nm_0 : public gmp_task_args_base {
@ -1909,30 +1908,3 @@ gmp_task_args_m_14_ret<C, M, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A
(o, m, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, r);
}
class RefCountTaskWrapper : public gmp_task_args_base {
public:
RefCountTaskWrapper(GMPTask* aTask, RefCounted* aRefCounted)
: mTask(aTask)
, mRefCounted(aRefCounted)
{}
virtual void Run() override {
mTask->Run();
}
virtual void Destroy() {
mTask->Destroy();
gmp_task_args_base::Destroy();
}
private:
~RefCountTaskWrapper() {}
GMPTask* mTask;
RefPtr<RefCounted> mRefCounted;
};
template<typename Type, typename Method, typename... Args>
GMPTask*
WrapTaskRefCounted(Type* aType, Method aMethod, Args... args)
{
GMPTask* t = WrapTask(aType, aMethod, args...);
return new RefCountTaskWrapper(t, aType);
}