From b597a55a60ff3d9581bcd50909e1f2eac330fe26 Mon Sep 17 00:00:00 2001 From: John Lin Date: Thu, 19 Aug 2021 19:01:20 +0000 Subject: [PATCH] Bug 1665776 - p6: implement VPx support in WMF encoder. r=bryce Differential Revision: https://phabricator.services.mozilla.com/D121023 --- dom/media/platforms/wmf/MFTEncoder.cpp | 12 +++++++++- dom/media/platforms/wmf/WMFEncoderModule.cpp | 22 ++++++++---------- .../platforms/wmf/WMFMediaDataEncoder.cpp | 23 ++++++++++++------- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/dom/media/platforms/wmf/MFTEncoder.cpp b/dom/media/platforms/wmf/MFTEncoder.cpp index b0d6e51d8e7f..41c46c484445 100644 --- a/dom/media/platforms/wmf/MFTEncoder.cpp +++ b/dom/media/platforms/wmf/MFTEncoder.cpp @@ -74,7 +74,15 @@ static const char* ErrorStr(HRESULT hr) { } static const char* CodecStr(const GUID& aGUID) { - return IsEqualGUID(aGUID, MFVideoFormat_H264) ? "H.264" : "???"; + if (IsEqualGUID(aGUID, MFVideoFormat_H264)) { + return "H.264"; + } else if (IsEqualGUID(aGUID, MFVideoFormat_VP80)) { + return "VP8"; + } else if (IsEqualGUID(aGUID, MFVideoFormat_VP90)) { + return "VP9"; + } else { + return "Unsupported codec"; + } } static UINT32 EnumHW(const GUID& aSubtype, IMFActivate**& aActivates) { @@ -160,6 +168,8 @@ nsTArray MFTEncoder::Enumerate() { } PopulateHWEncoderInfo(MFVideoFormat_H264, infos); + PopulateHWEncoderInfo(MFVideoFormat_VP90, infos); + PopulateHWEncoderInfo(MFVideoFormat_VP80, infos); wmf::MFShutdown(); return infos; diff --git a/dom/media/platforms/wmf/WMFEncoderModule.cpp b/dom/media/platforms/wmf/WMFEncoderModule.cpp index 6cb9e296b204..1a0d87337517 100644 --- a/dom/media/platforms/wmf/WMFEncoderModule.cpp +++ b/dom/media/platforms/wmf/WMFEncoderModule.cpp @@ -6,36 +6,32 @@ #include "WMFEncoderModule.h" -#include "MP4Decoder.h" #include "WMFMediaDataEncoder.h" namespace mozilla { extern LazyLogModule sPEMLog; -static MediaDataEncoder::CodecType MimeTypeToCodecType( - const nsACString& aMimeType) { - if (MP4Decoder::IsH264(aMimeType)) { - return MediaDataEncoder::CodecType::H264; - } else { - MOZ_ASSERT(false, "Unsupported Mimetype"); - return MediaDataEncoder::CodecType::Unknown; - } -} - bool WMFEncoderModule::SupportsMimeType(const nsACString& aMimeType) const { - return CanCreateWMFEncoder(MimeTypeToCodecType(aMimeType)); + return CanCreateWMFEncoder(CreateEncoderParams::CodecTypeForMime(aMimeType)); } already_AddRefed WMFEncoderModule::CreateVideoEncoder( const CreateEncoderParams& aParams) const { MediaDataEncoder::CodecType codec = - MimeTypeToCodecType(aParams.mConfig.mMimeType); + CreateEncoderParams::CodecTypeForMime(aParams.mConfig.mMimeType); RefPtr encoder; switch (codec) { case MediaDataEncoder::CodecType::H264: encoder = new WMFMediaDataEncoder( aParams.ToH264Config(), aParams.mTaskQueue); break; + case MediaDataEncoder::CodecType::VP8: + encoder = new WMFMediaDataEncoder( + aParams.ToVP8Config(), aParams.mTaskQueue); + case MediaDataEncoder::CodecType::VP9: + encoder = new WMFMediaDataEncoder( + aParams.ToVP9Config(), aParams.mTaskQueue); + break; default: // Do nothing. break; diff --git a/dom/media/platforms/wmf/WMFMediaDataEncoder.cpp b/dom/media/platforms/wmf/WMFMediaDataEncoder.cpp index de04c4527dbe..1f20a089bc07 100644 --- a/dom/media/platforms/wmf/WMFMediaDataEncoder.cpp +++ b/dom/media/platforms/wmf/WMFMediaDataEncoder.cpp @@ -27,6 +27,10 @@ static const GUID CodecToSubtype(MediaDataEncoder::CodecType aCodec) { switch (aCodec) { case MediaDataEncoder::CodecType::H264: return MFVideoFormat_H264; + case MediaDataEncoder::CodecType::VP8: + return MFVideoFormat_VP80; + case MediaDataEncoder::CodecType::VP9: + return MFVideoFormat_VP90; default: MOZ_ASSERT(false, "Unsupported codec"); return GUID_NULL; @@ -186,9 +190,14 @@ already_AddRefed CreateInputType(Config& aConfig) { : nullptr; } -static HRESULT SetCodecSpecific( - IMFMediaType* aOutputType, - const MediaDataEncoder::H264Specific& aSpecific) { +template +HRESULT SetCodecSpecific(IMFMediaType* aOutputType, const T& aSpecific) { + return S_OK; +} + +template <> +HRESULT SetCodecSpecific(IMFMediaType* aOutputType, + const MediaDataEncoder::H264Specific& aSpecific) { return aOutputType->SetUINT32(MF_MT_MPEG2_PROFILE, GetProfile(aSpecific.mProfileLevel)); } @@ -446,11 +455,9 @@ RefPtr WMFMediaDataEncoder::SetBitrate( }); } -template <> -nsCString -WMFMediaDataEncoder::GetDescriptionName() const { - MOZ_ASSERT(mConfig.mCodecType == CodecType::H264); - return MFTEncoder::GetFriendlyName(MFVideoFormat_H264); +template +nsCString WMFMediaDataEncoder::GetDescriptionName() const { + return MFTEncoder::GetFriendlyName(CodecToSubtype(mConfig.mCodecType)); } } // namespace mozilla