Bug 1749047 - Wire up more codecs from VideoEncoder to the new FFmpeg PEM. r=chunmin

Differential Revision: https://phabricator.services.mozilla.com/D196108
This commit is contained in:
Paul Adenot 2023-12-22 21:39:13 +00:00
Родитель ed6d3e74ec
Коммит adbaa958f4
6 изменённых файлов: 45 добавлений и 3 удалений

Просмотреть файл

@ -259,7 +259,7 @@ bool ExtractVPXCodecDetails(const nsAString& aCodec, uint8_t& aProfile,
bool ExtractVPXCodecDetails(const nsAString& aCodec, uint8_t& aProfile,
uint8_t& aLevel, uint8_t& aBitDepth,
uint8_t& aChromaSubsampling,
VideoColorSpace& aColorSpace);
mozilla::VideoColorSpace& aColorSpace);
// Extracts AV1 codecs parameter string.
// See https://aomediacodec.github.io/av1-isobmff/#codecsparam
@ -268,7 +268,7 @@ bool ExtractAV1CodecDetails(const nsAString& aCodec, uint8_t& aProfile,
uint8_t& aLevel, uint8_t& aTier, uint8_t& aBitDepth,
bool& aMonochrome, bool& aSubsamplingX,
bool& aSubsamplingY, uint8_t& aChromaSamplePosition,
VideoColorSpace& aColorSpace);
mozilla::VideoColorSpace& aColorSpace);
// Use a cryptographic quality PRNG to generate raw random bytes
// and convert that to a base64 string.

Просмотреть файл

@ -21,6 +21,8 @@ const char* GetCodecTypeString(const CodecType& aCodecType) {
return "VP8";
case CodecType::VP9:
return "VP9";
case CodecType::AV1:
return "AV1";
case CodecType::_EndVideo_: // CodecType::_BeginAudio_
return "_EndVideo_/_BeginAudio_";
case CodecType::Opus:

Просмотреть файл

@ -32,6 +32,7 @@ enum class CodecType {
H264,
VP8,
VP9,
AV1,
_EndVideo_,
_BeginAudio_ = _EndVideo_,
Opus,

Просмотреть файл

@ -216,7 +216,13 @@ EncoderConfig VideoEncoderConfigInternal::ToEncoderConfig() const {
mozilla::dom::HardwareAcceleration::Prefer_software) {
hwPref = MediaDataEncoder::HardwarePreference::RequireSoftware;
}
CodecType codecType = CodecType::H264;
CodecType codecType;
auto maybeCodecType = CodecStringToCodecType(mCodec);
if (maybeCodecType.isSome()) {
codecType = maybeCodecType.value();
} else {
MOZ_CRASH("The string should always contain a valid codec at this point.");
}
Maybe<EncoderConfig::CodecSpecific> specific;
if (codecType == CodecType::H264) {
uint8_t profile, constraints, level;
@ -231,6 +237,19 @@ EncoderConfig VideoEncoderConfigInternal::ToEncoderConfig() const {
ExtractH264CodecDetails(mCodec, profile, constraints, level);
specific.emplace(H264Specific(static_cast<H264_PROFILE>(profile), format));
}
// Only for vp9, not vp8
if (codecType == CodecType::VP9) {
uint8_t profile, level, bitdepth, chromasubsampling;
mozilla::VideoColorSpace colorspace;
DebugOnly<bool> rv = ExtractVPXCodecDetails(
mCodec, profile, level, bitdepth, chromasubsampling, colorspace);
#ifdef DEBUG
if (!rv) {
LOGE("Error extracting VPX codec details, non fatal");
}
#endif
specific.emplace(VP9Specific());
}
return EncoderConfig(
codecType, {mWidth, mHeight}, usage, ImageBitmapFormat::RGBA32, ImageBitmapFormat::RGBA32,
AssertedCast<uint8_t>(mFramerate.refOr(0.f)), 0, mBitrate.refOr(0),

Просмотреть файл

@ -532,4 +532,21 @@ VideoColorSpaceInit FallbackColorSpaceForWebContent() {
colorSpace.mPrimaries = VideoColorPrimaries::Bt709;
return colorSpace;
}
Maybe<CodecType> CodecStringToCodecType(const nsAString& aCodecString) {
if (StringBeginsWith(aCodecString, u"av01"_ns)) {
return Some(CodecType::AV1);
}
if (StringBeginsWith(aCodecString, u"vp8"_ns)) {
return Some(CodecType::VP8);
}
if (StringBeginsWith(aCodecString, u"vp09"_ns)) {
return Some(CodecType::VP9);
}
if (StringBeginsWith(aCodecString, u"avc1"_ns)) {
return Some(CodecType::H264);
}
return Nothing();
}
}; // namespace mozilla::dom

Просмотреть файл

@ -18,6 +18,7 @@
#include "mozilla/dom/UnionTypes.h"
#include "mozilla/dom/VideoEncoderBinding.h"
#include "mozilla/dom/VideoFrameBinding.h"
#include "PlatformEncoderModule.h"
namespace mozilla {
@ -224,6 +225,8 @@ RefPtr<TaskQueue> GetWebCodecsEncoderTaskQueue();
VideoColorSpaceInit FallbackColorSpaceForVideoContent();
VideoColorSpaceInit FallbackColorSpaceForWebContent();
Maybe<CodecType> CodecStringToCodecType(const nsAString& aCodecString);
} // namespace dom
} // namespace mozilla