summaryrefslogtreecommitdiffstats
path: root/dom/media/webcodecs/VideoEncoder.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /dom/media/webcodecs/VideoEncoder.cpp
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz
firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/webcodecs/VideoEncoder.cpp')
-rw-r--r--dom/media/webcodecs/VideoEncoder.cpp103
1 files changed, 44 insertions, 59 deletions
diff --git a/dom/media/webcodecs/VideoEncoder.cpp b/dom/media/webcodecs/VideoEncoder.cpp
index 0e71417cb0..f593f70c77 100644
--- a/dom/media/webcodecs/VideoEncoder.cpp
+++ b/dom/media/webcodecs/VideoEncoder.cpp
@@ -101,8 +101,7 @@ VideoEncoderConfigInternal::VideoEncoderConfigInternal(
mBitrateMode(aConfig.mBitrateMode),
mLatencyMode(aConfig.mLatencyMode),
mContentHint(aConfig.mContentHint),
- mAvc(aConfig.mAvc) {
-}
+ mAvc(aConfig.mAvc) {}
VideoEncoderConfigInternal::VideoEncoderConfigInternal(
const VideoEncoderConfig& aConfig)
@@ -119,8 +118,7 @@ VideoEncoderConfigInternal::VideoEncoderConfigInternal(
mBitrateMode(aConfig.mBitrateMode),
mLatencyMode(aConfig.mLatencyMode),
mContentHint(OptionalToMaybe(aConfig.mContentHint)),
- mAvc(OptionalToMaybe(aConfig.mAvc)) {
-}
+ mAvc(OptionalToMaybe(aConfig.mAvc)) {}
nsString VideoEncoderConfigInternal::ToString() const {
nsString rv;
@@ -137,26 +135,20 @@ nsString VideoEncoderConfigInternal::ToString() const {
if (mFramerate.isSome()) {
rv.AppendPrintf(", %lfHz", mFramerate.value());
}
- rv.AppendPrintf(
- " hw: %s",
- HardwareAccelerationValues::GetString(mHardwareAcceleration).data());
- rv.AppendPrintf(", alpha: %s", AlphaOptionValues::GetString(mAlpha).data());
+ rv.AppendPrintf(" hw: %s", GetEnumString(mHardwareAcceleration).get());
+ rv.AppendPrintf(", alpha: %s", GetEnumString(mAlpha).get());
if (mScalabilityMode.isSome()) {
rv.AppendPrintf(", scalability mode: %s",
NS_ConvertUTF16toUTF8(mScalabilityMode.value()).get());
}
- rv.AppendPrintf(
- ", bitrate mode: %s",
- VideoEncoderBitrateModeValues::GetString(mBitrateMode).data());
- rv.AppendPrintf(", latency mode: %s",
- LatencyModeValues::GetString(mLatencyMode).data());
+ rv.AppendPrintf(", bitrate mode: %s", GetEnumString(mBitrateMode).get());
+ rv.AppendPrintf(", latency mode: %s", GetEnumString(mLatencyMode).get());
if (mContentHint.isSome()) {
rv.AppendPrintf(", content hint: %s",
NS_ConvertUTF16toUTF8(mContentHint.value()).get());
}
if (mAvc.isSome()) {
- rv.AppendPrintf(", avc-specific: %s",
- AvcBitstreamFormatValues::GetString(mAvc->mFormat).data());
+ rv.AppendPrintf(", avc-specific: %s", GetEnumString(mAvc->mFormat).get());
}
return rv;
@@ -238,43 +230,57 @@ EncoderConfig VideoEncoderConfigInternal::ToEncoderConfig() const {
if (ExtractH264CodecDetails(mCodec, profile, constraints, level)) {
if (profile == H264_PROFILE_BASE || profile == H264_PROFILE_MAIN ||
profile == H264_PROFILE_EXTENDED || profile == H264_PROFILE_HIGH) {
- specific.emplace(
- H264Specific(static_cast<H264_PROFILE>(profile), static_cast<H264_LEVEL>(level), format));
+ specific.emplace(H264Specific(static_cast<H264_PROFILE>(profile),
+ static_cast<H264_LEVEL>(level), 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());
- }
+ uint8_t numTemporalLayers = 1;
MediaDataEncoder::ScalabilityMode scalabilityMode;
if (mScalabilityMode) {
if (mScalabilityMode->EqualsLiteral("L1T2")) {
scalabilityMode = MediaDataEncoder::ScalabilityMode::L1T2;
+ numTemporalLayers = 2;
} else if (mScalabilityMode->EqualsLiteral("L1T3")) {
scalabilityMode = MediaDataEncoder::ScalabilityMode::L1T3;
+ numTemporalLayers = 3;
} else {
scalabilityMode = MediaDataEncoder::ScalabilityMode::None;
}
} else {
scalabilityMode = MediaDataEncoder::ScalabilityMode::None;
}
- return EncoderConfig(
- codecType, {mWidth, mHeight}, usage, ImageBitmapFormat::RGBA32, ImageBitmapFormat::RGBA32,
- AssertedCast<uint8_t>(mFramerate.refOr(0.f)), 0, mBitrate.refOr(0),
- mBitrateMode == VideoEncoderBitrateMode::Constant
- ? MediaDataEncoder::BitrateMode::Constant
- : MediaDataEncoder::BitrateMode::Variable,
- hwPref, scalabilityMode, specific);
+ // 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(
+ VPXComplexity::Normal, /* Complexity */
+ true, /* Resilience */
+ numTemporalLayers, /* Number of temporal layers */
+ true, /* Denoising */
+ false, /* Auto resize */
+ false, /* Frame dropping */
+ true, /* Adaptive Qp */
+ 1, /* Number of spatial layers */
+ false /* Flexible */
+ ));
+ }
+ return EncoderConfig(codecType, {mWidth, mHeight}, usage,
+ ImageBitmapFormat::RGBA32, ImageBitmapFormat::RGBA32,
+ AssertedCast<uint8_t>(mFramerate.refOr(0.f)), 0,
+ mBitrate.refOr(0),
+ mBitrateMode == VideoEncoderBitrateMode::Constant
+ ? MediaDataEncoder::BitrateMode::Constant
+ : MediaDataEncoder::BitrateMode::Variable,
+ hwPref, scalabilityMode, specific);
}
already_AddRefed<WebCodecsConfigurationChangeList>
VideoEncoderConfigInternal::Diff(
@@ -326,27 +332,6 @@ VideoEncoderConfigInternal::Diff(
return list.forget();
}
-/*
- * The followings are helpers for VideoEncoder methods
- */
-static bool IsEncodeSupportedCodec(const nsAString& aCodec) {
- LOG("IsEncodeSupported: %s", NS_ConvertUTF16toUTF8(aCodec).get());
- if (!IsVP9CodecString(aCodec) && !IsVP8CodecString(aCodec) &&
- !IsH264CodecString(aCodec) && !IsAV1CodecString(aCodec)) {
- return false;
- }
-
- // Gecko allows codec string starts with vp9 or av1 but Webcodecs requires to
- // starts with av01 and vp09.
- // https://www.w3.org/TR/webcodecs-codec-registry/#video-codec-registry
- if (StringBeginsWith(aCodec, u"vp9"_ns) ||
- StringBeginsWith(aCodec, u"av1"_ns)) {
- return false;
- }
-
- return true;
-}
-
// https://w3c.github.io/webcodecs/#check-configuration-support
static bool CanEncode(const RefPtr<VideoEncoderConfigInternal>& aConfig) {
auto parsedCodecString =
@@ -355,7 +340,7 @@ static bool CanEncode(const RefPtr<VideoEncoderConfigInternal>& aConfig) {
if (IsOnAndroid()) {
return false;
}
- if (!IsEncodeSupportedCodec(parsedCodecString)) {
+ if (!IsSupportedVideoCodec(parsedCodecString)) {
return false;
}