Let PCF.GetRtpSenderCapabilities return codecs' scalabilityModes.

Also move ScalabilityModeToString to api and add RTC_EXPORT so that
Chromium can use it.

Bug: chromium:986069
Change-Id: I5dbbb6de9b14ca20f3ae0630552dcd44595ad5ef
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/267780
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com>
Cr-Commit-Position: refs/heads/main@{#37444}
This commit is contained in:
Byoungchan Lee
2022-07-05 21:06:28 +09:00
committed by WebRTC LUCI CQ
parent e1c707c40f
commit a1a7c638ec
29 changed files with 340 additions and 104 deletions

View File

@ -14,7 +14,15 @@ if (is_android) {
rtc_source_set("scalability_mode") {
visibility = [ "*" ]
sources = [ "scalability_mode.h" ]
sources = [
"scalability_mode.cc",
"scalability_mode.h",
]
deps = [
"../../rtc_base:checks",
"../../rtc_base/system:rtc_export",
]
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
}
rtc_library("video_codecs_api") {
@ -144,6 +152,8 @@ rtc_source_set("video_encoder_factory_template_libvpx_vp8_adapter") {
"../../modules/video_coding:webrtc_vp8",
"../../modules/video_coding:webrtc_vp8_scalability",
]
absl_deps = [ "//third_party/abseil-cpp/absl/container:inlined_vector" ]
}
rtc_source_set("video_encoder_factory_template_libvpx_vp9_adapter") {
@ -173,6 +183,7 @@ rtc_source_set("video_encoder_factory_template_libaom_av1_adapter") {
"../../modules/video_coding/codecs/av1:libaom_av1_encoder",
"../../modules/video_coding/svc:scalability_mode_util",
]
absl_deps = [ "//third_party/abseil-cpp/absl/container:inlined_vector" ]
}
rtc_library("vp8_temporal_layers_factory") {

View File

@ -0,0 +1,77 @@
/*
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "api/video_codecs/scalability_mode.h"
#include "rtc_base/checks.h"
namespace webrtc {
absl::string_view ScalabilityModeToString(ScalabilityMode scalability_mode) {
switch (scalability_mode) {
case ScalabilityMode::kL1T1:
return "L1T1";
case ScalabilityMode::kL1T2:
return "L1T2";
case ScalabilityMode::kL1T2h:
return "L1T2h";
case ScalabilityMode::kL1T3:
return "L1T3";
case ScalabilityMode::kL1T3h:
return "L1T3h";
case ScalabilityMode::kL2T1:
return "L2T1";
case ScalabilityMode::kL2T1h:
return "L2T1h";
case ScalabilityMode::kL2T1_KEY:
return "L2T1_KEY";
case ScalabilityMode::kL2T2:
return "L2T2";
case ScalabilityMode::kL2T2h:
return "L2T2h";
case ScalabilityMode::kL2T2_KEY:
return "L2T2_KEY";
case ScalabilityMode::kL2T2_KEY_SHIFT:
return "L2T2_KEY_SHIFT";
case ScalabilityMode::kL2T3:
return "L2T3";
case ScalabilityMode::kL2T3h:
return "L2T3h";
case ScalabilityMode::kL2T3_KEY:
return "L2T3_KEY";
case ScalabilityMode::kL3T1:
return "L3T1";
case ScalabilityMode::kL3T1h:
return "L3T1h";
case ScalabilityMode::kL3T1_KEY:
return "L3T1_KEY";
case ScalabilityMode::kL3T2:
return "L3T2";
case ScalabilityMode::kL3T2h:
return "L3T2h";
case ScalabilityMode::kL3T2_KEY:
return "L3T2_KEY";
case ScalabilityMode::kL3T3:
return "L3T3";
case ScalabilityMode::kL3T3h:
return "L3T3h";
case ScalabilityMode::kL3T3_KEY:
return "L3T3_KEY";
case ScalabilityMode::kS2T1:
return "S2T1";
case ScalabilityMode::kS2T3:
return "S2T3";
case ScalabilityMode::kS3T3:
return "S3T3";
}
RTC_CHECK_NOTREACHED();
}
} // namespace webrtc

View File

@ -11,6 +11,12 @@
#ifndef API_VIDEO_CODECS_SCALABILITY_MODE_H_
#define API_VIDEO_CODECS_SCALABILITY_MODE_H_
#include <stddef.h>
#include <stdint.h>
#include "absl/strings/string_view.h"
#include "rtc_base/system/rtc_export.h"
namespace webrtc {
// Supported scalability modes. Most applications should use the
@ -18,7 +24,7 @@ namespace webrtc {
// This list of currently recognized modes is intended for the api boundary
// between webrtc and injected encoders. Any application usage outside of
// injected encoders is strongly discouraged.
enum class ScalabilityMode {
enum class ScalabilityMode : uint8_t {
kL1T1,
kL1T2,
kL1T2h,
@ -48,5 +54,44 @@ enum class ScalabilityMode {
kS3T3,
};
inline constexpr ScalabilityMode kAllScalabilityModes[] = {
// clang-format off
ScalabilityMode::kL1T1,
ScalabilityMode::kL1T2,
ScalabilityMode::kL1T2h,
ScalabilityMode::kL1T3,
ScalabilityMode::kL1T3h,
ScalabilityMode::kL2T1,
ScalabilityMode::kL2T1h,
ScalabilityMode::kL2T1_KEY,
ScalabilityMode::kL2T2,
ScalabilityMode::kL2T2h,
ScalabilityMode::kL2T2_KEY,
ScalabilityMode::kL2T2_KEY_SHIFT,
ScalabilityMode::kL2T3,
ScalabilityMode::kL2T3h,
ScalabilityMode::kL2T3_KEY,
ScalabilityMode::kL3T1,
ScalabilityMode::kL3T1h,
ScalabilityMode::kL3T1_KEY,
ScalabilityMode::kL3T2,
ScalabilityMode::kL3T2h,
ScalabilityMode::kL3T2_KEY,
ScalabilityMode::kL3T3,
ScalabilityMode::kL3T3h,
ScalabilityMode::kL3T3_KEY,
ScalabilityMode::kS2T1,
ScalabilityMode::kS2T3,
ScalabilityMode::kS3T3,
// clang-format on
};
inline constexpr size_t kScalabilityModeCount =
sizeof(kAllScalabilityModes) / sizeof(ScalabilityMode);
RTC_EXPORT
absl::string_view ScalabilityModeToString(ScalabilityMode scalability_mode);
} // namespace webrtc
#endif // API_VIDEO_CODECS_SCALABILITY_MODE_H_

View File

@ -70,6 +70,15 @@ SdpVideoFormat::SdpVideoFormat(const std::string& name,
const Parameters& parameters)
: name(name), parameters(parameters) {}
SdpVideoFormat::SdpVideoFormat(
const std::string& name,
const Parameters& parameters,
const absl::InlinedVector<ScalabilityMode, kScalabilityModeCount>&
scalability_modes)
: name(name),
parameters(parameters),
scalability_modes(scalability_modes) {}
SdpVideoFormat::SdpVideoFormat(const SdpVideoFormat&) = default;
SdpVideoFormat::SdpVideoFormat(SdpVideoFormat&&) = default;
SdpVideoFormat& SdpVideoFormat::operator=(const SdpVideoFormat&) = default;
@ -80,9 +89,24 @@ SdpVideoFormat::~SdpVideoFormat() = default;
std::string SdpVideoFormat::ToString() const {
rtc::StringBuilder builder;
builder << "Codec name: " << name << ", parameters: {";
for (const auto& kv : parameters)
for (const auto& kv : parameters) {
builder << " " << kv.first << "=" << kv.second;
}
builder << " }";
if (!scalability_modes.empty()) {
builder << ", scalability_modes: [";
bool first = true;
for (const auto scalability_mode : scalability_modes) {
if (first) {
first = false;
} else {
builder << ", ";
}
builder << ScalabilityModeToString(scalability_mode);
}
builder << "]";
}
return builder.str();
}
@ -105,7 +129,8 @@ bool SdpVideoFormat::IsCodecInList(
}
bool operator==(const SdpVideoFormat& a, const SdpVideoFormat& b) {
return a.name == b.name && a.parameters == b.parameters;
return a.name == b.name && a.parameters == b.parameters &&
a.scalability_modes == b.scalability_modes;
}
} // namespace webrtc

View File

@ -14,7 +14,9 @@
#include <map>
#include <string>
#include "absl/container/inlined_vector.h"
#include "api/array_view.h"
#include "api/video_codecs/scalability_mode.h"
#include "rtc_base/system/rtc_export.h"
namespace webrtc {
@ -26,6 +28,11 @@ struct RTC_EXPORT SdpVideoFormat {
explicit SdpVideoFormat(const std::string& name);
SdpVideoFormat(const std::string& name, const Parameters& parameters);
SdpVideoFormat(
const std::string& name,
const Parameters& parameters,
const absl::InlinedVector<ScalabilityMode, kScalabilityModeCount>&
scalability_modes);
SdpVideoFormat(const SdpVideoFormat&);
SdpVideoFormat(SdpVideoFormat&&);
SdpVideoFormat& operator=(const SdpVideoFormat&);
@ -51,6 +58,7 @@ struct RTC_EXPORT SdpVideoFormat {
std::string name;
Parameters parameters;
absl::InlinedVector<ScalabilityMode, kScalabilityModeCount> scalability_modes;
};
} // namespace webrtc

View File

@ -17,6 +17,7 @@
#include "test/gmock.h"
#include "test/gtest.h"
using ::testing::Contains;
using ::testing::Each;
using ::testing::Eq;
using ::testing::Field;
@ -125,9 +126,12 @@ TEST(VideoEncoderFactoryTemplate, TwoTemplateAdaptersCodecSupport) {
TEST(VideoEncoderFactoryTemplate, LibvpxVp8) {
VideoEncoderFactoryTemplate<LibvpxVp8EncoderTemplateAdapter> factory;
const SdpVideoFormat kVp8Sdp("VP8");
EXPECT_THAT(factory.GetSupportedFormats(), UnorderedElementsAre(kVp8Sdp));
EXPECT_THAT(factory.CreateVideoEncoder(kVp8Sdp), Ne(nullptr));
auto formats = factory.GetSupportedFormats();
EXPECT_THAT(formats.size(), 1);
EXPECT_THAT(formats[0], Field(&SdpVideoFormat::name, "VP8"));
EXPECT_THAT(formats[0], Field(&SdpVideoFormat::scalability_modes,
Contains(ScalabilityMode::kL1T3)));
EXPECT_THAT(factory.CreateVideoEncoder(formats[0]), Ne(nullptr));
}
TEST(VideoEncoderFactoryTemplate, LibvpxVp9) {
@ -135,6 +139,8 @@ TEST(VideoEncoderFactoryTemplate, LibvpxVp9) {
auto formats = factory.GetSupportedFormats();
EXPECT_THAT(formats, Not(IsEmpty()));
EXPECT_THAT(formats, Each(Field(&SdpVideoFormat::name, "VP9")));
EXPECT_THAT(formats, Each(Field(&SdpVideoFormat::scalability_modes,
Contains(ScalabilityMode::kL3T3_KEY))));
EXPECT_THAT(factory.CreateVideoEncoder(formats[0]), Ne(nullptr));
}
@ -146,15 +152,20 @@ TEST(VideoEncoderFactoryTemplate, OpenH264) {
auto formats = factory.GetSupportedFormats();
EXPECT_THAT(formats, Not(IsEmpty()));
EXPECT_THAT(formats, Each(Field(&SdpVideoFormat::name, "H264")));
EXPECT_THAT(formats, Each(Field(&SdpVideoFormat::scalability_modes,
Contains(ScalabilityMode::kL1T3))));
EXPECT_THAT(factory.CreateVideoEncoder(formats[0]), Ne(nullptr));
}
#endif // defined(WEBRTC_USE_H264)
TEST(VideoEncoderFactoryTemplate, LibaomAv1) {
VideoEncoderFactoryTemplate<LibaomAv1EncoderTemplateAdapter> factory;
const SdpVideoFormat kAv1Sdp("AV1");
EXPECT_THAT(factory.GetSupportedFormats(), UnorderedElementsAre(kAv1Sdp));
EXPECT_THAT(factory.CreateVideoEncoder(kAv1Sdp), Ne(nullptr));
auto formats = factory.GetSupportedFormats();
EXPECT_THAT(formats.size(), 1);
EXPECT_THAT(formats[0], Field(&SdpVideoFormat::name, "AV1"));
EXPECT_THAT(formats[0], Field(&SdpVideoFormat::scalability_modes,
Contains(ScalabilityMode::kL3T3_KEY)));
EXPECT_THAT(factory.CreateVideoEncoder(formats[0]), Ne(nullptr));
}
} // namespace

View File

@ -14,13 +14,17 @@
#include <memory>
#include <vector>
#include "absl/container/inlined_vector.h"
#include "modules/video_coding/codecs/av1/av1_svc_config.h"
#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h"
namespace webrtc {
struct LibaomAv1EncoderTemplateAdapter {
static std::vector<SdpVideoFormat> SupportedFormats() {
return {SdpVideoFormat("AV1")};
absl::InlinedVector<ScalabilityMode, kScalabilityModeCount>
scalability_modes = LibaomAv1EncoderSupportedScalabilityModes();
return {
SdpVideoFormat("AV1", SdpVideoFormat::Parameters(), scalability_modes)};
}
static std::unique_ptr<VideoEncoder> CreateEncoder(

View File

@ -14,13 +14,21 @@
#include <memory>
#include <vector>
#include "absl/container/inlined_vector.h"
#include "modules/video_coding/codecs/vp8/include/vp8.h"
#include "modules/video_coding/codecs/vp8/vp8_scalability.h"
namespace webrtc {
struct LibvpxVp8EncoderTemplateAdapter {
static std::vector<SdpVideoFormat> SupportedFormats() {
return {SdpVideoFormat("VP8")};
absl::InlinedVector<ScalabilityMode, kScalabilityModeCount>
scalability_modes;
for (const auto scalability_mode : kVP8SupportedScalabilityModes) {
scalability_modes.push_back(scalability_mode);
}
return {
SdpVideoFormat("VP8", SdpVideoFormat::Parameters(), scalability_modes)};
}
static std::unique_ptr<VideoEncoder> CreateEncoder(

View File

@ -19,7 +19,7 @@
namespace webrtc {
struct LibvpxVp9EncoderTemplateAdapter {
static std::vector<SdpVideoFormat> SupportedFormats() {
return SupportedVP9Codecs();
return SupportedVP9Codecs(/*add_scalability_modes=*/true);
}
static std::unique_ptr<VideoEncoder> CreateEncoder(

View File

@ -22,7 +22,7 @@ namespace webrtc {
#if defined(WEBRTC_USE_H264)
struct OpenH264EncoderTemplateAdapter {
static std::vector<SdpVideoFormat> SupportedFormats() {
return SupportedH264Codecs();
return SupportedH264Codecs(/*add_scalability_modes=*/true);
}
static std::unique_ptr<VideoEncoder> CreateEncoder(