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
This commit is contained in:
Andrew Osmond 2024-05-27 17:03:13 +00:00
parent 11d14def25
commit 130e77c8c4
4 changed files with 46 additions and 15 deletions

View File

@ -55,6 +55,26 @@ struct ParamTraits<GMPLogLevel>
: public ContiguousEnumSerializerInclusive<GMPLogLevel, kGMPLogDefault,
kGMPLogInvalid> {};
template <>
struct ParamTraits<GMPLevel>
: public ContiguousEnumSerializerInclusive<GMPLevel, kGMPH264LevelUnknown,
kGMPH264Level5_2> {};
template <>
struct ParamTraits<GMPProfile>
: public ContiguousEnumSerializerInclusive<
GMPProfile, kGMPH264ProfileUnknown, kGMPH264ProfileScalableHigh> {};
template <>
struct ParamTraits<GMPRateControlMode>
: public ContiguousEnumSerializerInclusive<
GMPRateControlMode, kGMPRateControlUnknown, kGMPRateControlOff> {};
template <>
struct ParamTraits<GMPSliceMode>
: public ContiguousEnumSerializerInclusive<GMPSliceMode, kGMPSliceUnknown,
kGMPSliceSizeLimited> {};
template <>
struct ParamTraits<GMPBufferType>
: public ContiguousEnumSerializer<GMPBufferType, GMP_BufferSingle,
@ -126,13 +146,19 @@ struct ParamTraits<GMPVideoCodec> {
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<GMPVideoCodec> {
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;
}

View File

@ -191,6 +191,17 @@ bool HaveGMPFor(const nsACString& aAPI, const nsTArray<nsCString>& aTags) {
return hasPlugin;
}
bool IsOnGMPThread() {
nsCOMPtr<mozIGeckoMediaPluginService> mps =
do_GetService("@mozilla.org/gecko-media-plugin-service;1");
MOZ_ASSERT(mps);
nsCOMPtr<nsIThread> gmpThread;
nsresult rv = mps->GetThread(getter_AddRefs(gmpThread));
MOZ_ASSERT(gmpThread);
return NS_SUCCEEDED(rv) && gmpThread && gmpThread->IsOnCurrentThread();
}
void LogToConsole(const nsAString& aMsg) {
nsCOMPtr<nsIConsoleService> console(
do_GetService("@mozilla.org/consoleservice;1"));

View File

@ -72,6 +72,8 @@ bool ReadIntoString(nsIFile* aFile, nsCString& aOutDst, size_t aMaxLength);
bool HaveGMPFor(const nsACString& aAPI, const nsTArray<nsCString>& aTags);
bool IsOnGMPThread();
void LogToConsole(const nsAString& aMsg);
already_AddRefed<nsISerialEventTarget> GetGMPThread();

View File

@ -22,19 +22,6 @@
namespace mozilla {
#if defined(DEBUG)
static bool IsOnGMPThread() {
nsCOMPtr<mozIGeckoMediaPluginService> mps =
do_GetService("@mozilla.org/gecko-media-plugin-service;1");
MOZ_ASSERT(mps);
nsCOMPtr<nsIThread> 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),