Bug 1281632 - P5: Extract parameters to GMPVideoDecoder into struct. r=gerald
MozReview-Commit-ID: UICBFgDHBm
--- a/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
@@ -239,22 +239,18 @@ already_AddRefed<MediaDataDecoder>
EMEDecoderModule::CreateVideoDecoder(const CreateDecoderParams& aParams)
{
MOZ_ASSERT(aParams.mConfig.mCrypto.mValid);
if (SupportsMimeType(aParams.mConfig.mMimeType, nullptr)) {
// GMP decodes. Assume that means it can decrypt too.
RefPtr<MediaDataDecoderProxy> wrapper =
CreateDecoderWrapper(aParams.mCallback, mProxy, aParams.mTaskQueue);
- wrapper->SetProxyTarget(new EMEVideoDecoder(mProxy,
- aParams.VideoConfig(),
- aParams.mLayersBackend,
- aParams.mImageContainer,
- aParams.mTaskQueue,
- wrapper->Callback()));
+ auto params = GMPVideoDecoderParams(aParams).WithCallback(wrapper);
+ wrapper->SetProxyTarget(new EMEVideoDecoder(mProxy, params));
return wrapper.forget();
}
MOZ_ASSERT(mPDM);
RefPtr<MediaDataDecoder> decoder(mPDM->CreateDecoder(aParams));
if (!decoder) {
return nullptr;
}
--- a/dom/media/platforms/agnostic/eme/EMEVideoDecoder.cpp
+++ b/dom/media/platforms/agnostic/eme/EMEVideoDecoder.cpp
@@ -19,30 +19,21 @@ EMEVideoCallbackAdapter::Error(GMPErr aE
// happen if a key expires or a session is closed during playback.
NS_WARNING("GMP failed to decrypt due to lack of key");
return;
}
VideoCallbackAdapter::Error(aErr);
}
EMEVideoDecoder::EMEVideoDecoder(CDMProxy* aProxy,
- const VideoInfo& aConfig,
- layers::LayersBackend aLayersBackend,
- layers::ImageContainer* aImageContainer,
- TaskQueue* aTaskQueue,
- MediaDataDecoderCallbackProxy* aCallback)
- : GMPVideoDecoder(aConfig,
- aLayersBackend,
- aImageContainer,
- aTaskQueue,
- aCallback,
- new EMEVideoCallbackAdapter(aCallback,
- VideoInfo(aConfig.mDisplay.width,
- aConfig.mDisplay.height),
- aImageContainer))
+ const GMPVideoDecoderParams& aParams)
+ : GMPVideoDecoder(GMPVideoDecoderParams(aParams).WithAdapter(
+ new EMEVideoCallbackAdapter(aParams.mCallback,
+ VideoInfo(aParams.mConfig.mDisplay),
+ aParams.mImageContainer)))
, mProxy(aProxy)
{}
void
EMEVideoDecoder::InitTags(nsTArray<nsCString>& aTags)
{
aTags.AppendElement(NS_LITERAL_CSTRING("h264"));
aTags.AppendElement(NS_ConvertUTF16toUTF8(mProxy->KeySystem()));
--- a/dom/media/platforms/agnostic/eme/EMEVideoDecoder.h
+++ b/dom/media/platforms/agnostic/eme/EMEVideoDecoder.h
@@ -23,22 +23,17 @@ public:
: VideoCallbackAdapter(aCallback, aVideoInfo, aImageContainer)
{}
void Error(GMPErr aErr) override;
};
class EMEVideoDecoder : public GMPVideoDecoder {
public:
- EMEVideoDecoder(CDMProxy* aProxy,
- const VideoInfo& aConfig,
- layers::LayersBackend aLayersBackend,
- layers::ImageContainer* aImageContainer,
- TaskQueue* aTaskQueue,
- MediaDataDecoderCallbackProxy* aCallback);
+ EMEVideoDecoder(CDMProxy* aProxy, const GMPVideoDecoderParams& aParams);
private:
void InitTags(nsTArray<nsCString>& aTags) override;
nsCString GetNodeId() override;
GMPUniquePtr<GMPVideoEncodedFrame> CreateFrame(MediaRawData* aSample) override;
RefPtr<CDMProxy> mProxy;
};
--- a/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
@@ -55,22 +55,18 @@ GMPDecoderModule::CreateVideoDecoder(con
if (aParams.mDiagnostics) {
const Maybe<nsCString> preferredGMP = PreferredGMP(aParams.mConfig.mMimeType);
if (preferredGMP.isSome()) {
aParams.mDiagnostics->SetGMP(preferredGMP.value());
}
}
RefPtr<MediaDataDecoderProxy> wrapper = CreateDecoderWrapper(aParams.mCallback);
- wrapper->SetProxyTarget(new GMPVideoDecoder(aParams.VideoConfig(),
- aParams.mLayersBackend,
- aParams.mImageContainer,
- aParams.mTaskQueue,
- wrapper->Callback(),
- nullptr));
+ auto params = GMPVideoDecoderParams(aParams).WithCallback(wrapper);
+ wrapper->SetProxyTarget(new GMPVideoDecoder(params));
return wrapper.forget();
}
already_AddRefed<MediaDataDecoder>
GMPDecoderModule::CreateAudioDecoder(const CreateDecoderParams& aParams)
{
if (!aParams.mConfig.mMimeType.EqualsLiteral("audio/mp4a-latm")) {
return nullptr;
--- a/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp
@@ -99,35 +99,59 @@ VideoCallbackAdapter::Error(GMPErr aErr)
void
VideoCallbackAdapter::Terminated()
{
// Note that this *may* be called from the proxy thread also.
NS_WARNING("H.264 GMP decoder terminated.");
mCallback->Error(MediaDataDecoderError::FATAL_ERROR);
}
-GMPVideoDecoder::GMPVideoDecoder(const VideoInfo& aConfig,
- layers::LayersBackend aLayersBackend,
- layers::ImageContainer* aImageContainer,
- TaskQueue* aTaskQueue,
- MediaDataDecoderCallbackProxy* aCallback,
- VideoCallbackAdapter* aAdapter)
- : mConfig(aConfig)
- , mCallback(aCallback)
+GMPVideoDecoderParams::GMPVideoDecoderParams(const CreateDecoderParams& aParams)
+ : mConfig(aParams.VideoConfig())
+ , mTaskQueue(aParams.mTaskQueue)
+ , mCallback(nullptr)
+ , mAdapter(nullptr)
+ , mImageContainer(aParams.mImageContainer)
+ , mLayersBackend(aParams.mLayersBackend)
+{}
+
+GMPVideoDecoderParams&
+GMPVideoDecoderParams::WithCallback(MediaDataDecoderProxy* aWrapper)
+{
+ MOZ_ASSERT(aWrapper);
+ MOZ_ASSERT(!mCallback); // Should only be called once per instance.
+ mCallback = aWrapper->Callback();
+ mAdapter = nullptr;
+ return *this;
+}
+
+GMPVideoDecoderParams&
+GMPVideoDecoderParams::WithAdapter(VideoCallbackAdapter* aAdapter)
+{
+ MOZ_ASSERT(aAdapter);
+ MOZ_ASSERT(!mAdapter); // Should only be called once per instance.
+ mCallback = aAdapter->Callback();
+ mAdapter = aAdapter;
+ return *this;
+}
+
+GMPVideoDecoder::GMPVideoDecoder(const GMPVideoDecoderParams& aParams)
+ : mConfig(aParams.mConfig)
+ , mCallback(aParams.mCallback)
, mGMP(nullptr)
, mHost(nullptr)
- , mAdapter(aAdapter)
+ , mAdapter(aParams.mAdapter)
, mConvertNALUnitLengths(false)
{
- MOZ_ASSERT(!aAdapter || mCallback == aAdapter->Callback());
- if (!aAdapter) {
- mAdapter = new VideoCallbackAdapter(aCallback,
- VideoInfo(aConfig.mDisplay.width,
- aConfig.mDisplay.height),
- aImageContainer);
+ MOZ_ASSERT(!mAdapter || mCallback == mAdapter->Callback());
+ if (!mAdapter) {
+ mAdapter = new VideoCallbackAdapter(mCallback,
+ VideoInfo(mConfig.mDisplay.width,
+ mConfig.mDisplay.height),
+ aParams.mImageContainer);
}
}
void
GMPVideoDecoder::InitTags(nsTArray<nsCString>& aTags)
{
aTags.AppendElement(NS_LITERAL_CSTRING("h264"));
const Maybe<nsCString> gmp(
--- a/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.h
+++ b/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.h
@@ -46,24 +46,32 @@ public:
private:
MediaDataDecoderCallbackProxy* mCallback;
int64_t mLastStreamOffset;
VideoInfo mVideoInfo;
RefPtr<layers::ImageContainer> mImageContainer;
};
+struct GMPVideoDecoderParams {
+ explicit GMPVideoDecoderParams(const CreateDecoderParams& aParams);
+ GMPVideoDecoderParams& WithCallback(MediaDataDecoderProxy* aWrapper);
+ GMPVideoDecoderParams& WithAdapter(VideoCallbackAdapter* aAdapter);
+
+ const VideoInfo& mConfig;
+ TaskQueue* mTaskQueue;
+ MediaDataDecoderCallbackProxy* mCallback;
+ VideoCallbackAdapter* mAdapter;
+ layers::ImageContainer* mImageContainer;
+ layers::LayersBackend mLayersBackend;
+};
+
class GMPVideoDecoder : public MediaDataDecoder {
-protected:
- GMPVideoDecoder(const VideoInfo& aConfig,
- layers::LayersBackend aLayersBackend,
- layers::ImageContainer* aImageContainer,
- TaskQueue* aTaskQueue,
- MediaDataDecoderCallbackProxy* aCallback,
- VideoCallbackAdapter* aAdapter);
+public:
+ explicit GMPVideoDecoder(const GMPVideoDecoderParams& aParams);
RefPtr<InitPromise> Init() override;
nsresult Input(MediaRawData* aSample) override;
nsresult Flush() override;
nsresult Drain() override;
nsresult Shutdown() override;
const char* GetDescriptionName() const override
{