From 130e77c8c4c8373807dc86e9c01aaa299ae33839 Mon Sep 17 00:00:00 2001 From: Andrew Osmond Date: Mon, 27 May 2024 17:03:13 +0000 Subject: [PATCH] Bug 1896758 - Part 4. Expose more GMP parameters/methods for/to encoders. r=media-playback-reviewers,padenot This patch moves a method used to determine if one is on the GMP thread from a static method for GMPVideoDecoder into GMPUtils. This allows for sharing it between the decoder and encoder implementations. It also ensures we can pack/unpack the latest GMPVideoCodec structure which has parameters relevant for encoding. Differential Revision: https://phabricator.services.mozilla.com/D211653 --- dom/media/gmp/GMPMessageUtils.h | 35 +++++++++++++++++-- dom/media/gmp/GMPUtils.cpp | 11 ++++++ dom/media/gmp/GMPUtils.h | 2 ++ .../agnostic/gmp/GMPVideoDecoder.cpp | 13 ------- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/dom/media/gmp/GMPMessageUtils.h b/dom/media/gmp/GMPMessageUtils.h index dd84c8cc2011..edf65e6d2b3c 100644 --- a/dom/media/gmp/GMPMessageUtils.h +++ b/dom/media/gmp/GMPMessageUtils.h @@ -55,6 +55,26 @@ struct ParamTraits : public ContiguousEnumSerializerInclusive {}; +template <> +struct ParamTraits + : public ContiguousEnumSerializerInclusive {}; + +template <> +struct ParamTraits + : public ContiguousEnumSerializerInclusive< + GMPProfile, kGMPH264ProfileUnknown, kGMPH264ProfileScalableHigh> {}; + +template <> +struct ParamTraits + : public ContiguousEnumSerializerInclusive< + GMPRateControlMode, kGMPRateControlUnknown, kGMPRateControlOff> {}; + +template <> +struct ParamTraits + : public ContiguousEnumSerializerInclusive {}; + template <> struct ParamTraits : public ContiguousEnumSerializer { WriteParam(aWriter, aParam.mMode); WriteParam(aWriter, aParam.mUseThreadedDecode); WriteParam(aWriter, aParam.mLogLevel); + WriteParam(aWriter, aParam.mLevel); + WriteParam(aWriter, aParam.mProfile); + WriteParam(aWriter, aParam.mRateControlMode); + WriteParam(aWriter, aParam.mSliceMode); + WriteParam(aWriter, aParam.mUseThreadedEncode); } static bool Read(MessageReader* aReader, paramType* aResult) { // NOTE: make sure this matches any versions supported if (!ReadParam(aReader, &(aResult->mGMPApiVersion)) || (aResult->mGMPApiVersion != kGMPVersion33 && - aResult->mGMPApiVersion != kGMPVersion34)) { + aResult->mGMPApiVersion != kGMPVersion34 && + aResult->mGMPApiVersion != kGMPVersion35)) { return false; } if (!ReadParam(aReader, &(aResult->mCodecType))) { @@ -177,7 +203,12 @@ struct ParamTraits { if (!ReadParam(aReader, &(aResult->mMode)) || !ReadParam(aReader, &(aResult->mUseThreadedDecode)) || - !ReadParam(aReader, &(aResult->mLogLevel))) { + !ReadParam(aReader, &(aResult->mLogLevel)) || + !ReadParam(aReader, &(aResult->mLevel)) || + !ReadParam(aReader, &(aResult->mProfile)) || + !ReadParam(aReader, &(aResult->mRateControlMode)) || + !ReadParam(aReader, &(aResult->mSliceMode)) || + !ReadParam(aReader, &(aResult->mUseThreadedEncode))) { return false; } diff --git a/dom/media/gmp/GMPUtils.cpp b/dom/media/gmp/GMPUtils.cpp index d16057736d05..833dd12a5542 100644 --- a/dom/media/gmp/GMPUtils.cpp +++ b/dom/media/gmp/GMPUtils.cpp @@ -191,6 +191,17 @@ bool HaveGMPFor(const nsACString& aAPI, const nsTArray& aTags) { return hasPlugin; } +bool IsOnGMPThread() { + nsCOMPtr mps = + do_GetService("@mozilla.org/gecko-media-plugin-service;1"); + MOZ_ASSERT(mps); + + nsCOMPtr gmpThread; + nsresult rv = mps->GetThread(getter_AddRefs(gmpThread)); + MOZ_ASSERT(gmpThread); + return NS_SUCCEEDED(rv) && gmpThread && gmpThread->IsOnCurrentThread(); +} + void LogToConsole(const nsAString& aMsg) { nsCOMPtr console( do_GetService("@mozilla.org/consoleservice;1")); diff --git a/dom/media/gmp/GMPUtils.h b/dom/media/gmp/GMPUtils.h index d65df99bd831..e562e91788d9 100644 --- a/dom/media/gmp/GMPUtils.h +++ b/dom/media/gmp/GMPUtils.h @@ -72,6 +72,8 @@ bool ReadIntoString(nsIFile* aFile, nsCString& aOutDst, size_t aMaxLength); bool HaveGMPFor(const nsACString& aAPI, const nsTArray& aTags); +bool IsOnGMPThread(); + void LogToConsole(const nsAString& aMsg); already_AddRefed GetGMPThread(); diff --git a/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp b/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp index 374c1ab010fe..4087352e0c27 100644 --- a/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp +++ b/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp @@ -22,19 +22,6 @@ namespace mozilla { -#if defined(DEBUG) -static bool IsOnGMPThread() { - nsCOMPtr mps = - do_GetService("@mozilla.org/gecko-media-plugin-service;1"); - MOZ_ASSERT(mps); - - nsCOMPtr gmpThread; - nsresult rv = mps->GetThread(getter_AddRefs(gmpThread)); - MOZ_ASSERT(NS_SUCCEEDED(rv) && gmpThread); - return gmpThread->IsOnCurrentThread(); -} -#endif - GMPVideoDecoderParams::GMPVideoDecoderParams(const CreateDecoderParams& aParams) : mConfig(aParams.VideoConfig()), mImageContainer(aParams.mImageContainer),