Move scalability structures from av1 into own subfolder
To make it natural to reuse them for vp9 Bug: webrtc:11999 Change-Id: If2ef7ca16b8be96e0e03bb19211d9f5eb74b2d3d Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/188620 Reviewed-by: Philip Eliasson <philipel@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32414}
This commit is contained in:
committed by
Commit Bot
parent
4c54f8638c
commit
da7fe39b84
@ -34,74 +34,13 @@ rtc_library("libaom_av1_decoder") {
|
||||
}
|
||||
}
|
||||
|
||||
rtc_source_set("scalable_video_controller") {
|
||||
sources = [
|
||||
"scalable_video_controller.h",
|
||||
"scalable_video_controller_no_layering.cc",
|
||||
"scalable_video_controller_no_layering.h",
|
||||
]
|
||||
deps = [
|
||||
"../../../../api/transport/rtp:dependency_descriptor",
|
||||
"../../../../api/video:video_bitrate_allocation",
|
||||
"../../../../common_video/generic_frame_descriptor",
|
||||
"../../../../rtc_base:checks",
|
||||
]
|
||||
absl_deps = [
|
||||
"//third_party/abseil-cpp/absl/container:inlined_vector",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
}
|
||||
|
||||
rtc_source_set("scalability_structures") {
|
||||
sources = [
|
||||
"create_scalability_structure.cc",
|
||||
"create_scalability_structure.h",
|
||||
"scalability_structure_full_svc.cc",
|
||||
"scalability_structure_full_svc.h",
|
||||
"scalability_structure_l1t2.cc",
|
||||
"scalability_structure_l1t2.h",
|
||||
"scalability_structure_l1t3.cc",
|
||||
"scalability_structure_l1t3.h",
|
||||
"scalability_structure_l2t1.cc",
|
||||
"scalability_structure_l2t1.h",
|
||||
"scalability_structure_l2t1_key.cc",
|
||||
"scalability_structure_l2t1_key.h",
|
||||
"scalability_structure_l2t1h.cc",
|
||||
"scalability_structure_l2t1h.h",
|
||||
"scalability_structure_l2t2.cc",
|
||||
"scalability_structure_l2t2.h",
|
||||
"scalability_structure_l2t2_key.cc",
|
||||
"scalability_structure_l2t2_key.h",
|
||||
"scalability_structure_l2t2_key_shift.cc",
|
||||
"scalability_structure_l2t2_key_shift.h",
|
||||
"scalability_structure_l3t1.cc",
|
||||
"scalability_structure_l3t1.h",
|
||||
"scalability_structure_l3t3.cc",
|
||||
"scalability_structure_l3t3.h",
|
||||
"scalability_structure_s2t1.cc",
|
||||
"scalability_structure_s2t1.h",
|
||||
]
|
||||
deps = [
|
||||
":scalable_video_controller",
|
||||
"../../../../api/transport/rtp:dependency_descriptor",
|
||||
"../../../../common_video/generic_frame_descriptor",
|
||||
"../../../../rtc_base:checks",
|
||||
"../../../../rtc_base:logging",
|
||||
]
|
||||
absl_deps = [
|
||||
"//third_party/abseil-cpp/absl/base:core_headers",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
}
|
||||
|
||||
rtc_library("libaom_av1_encoder") {
|
||||
visibility = [ "*" ]
|
||||
poisonous = [ "software_video_codecs" ]
|
||||
public = [ "libaom_av1_encoder.h" ]
|
||||
deps = [
|
||||
":scalable_video_controller",
|
||||
"../../../../api/video_codecs:video_codecs_api",
|
||||
"../../svc:scalable_video_controller",
|
||||
]
|
||||
absl_deps = [
|
||||
"//third_party/abseil-cpp/absl/algorithm:container",
|
||||
@ -127,28 +66,6 @@ rtc_library("libaom_av1_encoder") {
|
||||
}
|
||||
|
||||
if (rtc_include_tests) {
|
||||
rtc_library("scalability_structure_tests") {
|
||||
testonly = true
|
||||
sources = [
|
||||
"scalability_structure_l3t3_unittest.cc",
|
||||
"scalability_structure_test_helpers.cc",
|
||||
"scalability_structure_test_helpers.h",
|
||||
"scalability_structure_unittest.cc",
|
||||
]
|
||||
deps = [
|
||||
":scalability_structures",
|
||||
":scalable_video_controller",
|
||||
"../..:chain_diff_calculator",
|
||||
"../..:frame_dependencies_calculator",
|
||||
"../../../../api/transport/rtp:dependency_descriptor",
|
||||
"../../../../api/video:video_bitrate_allocation",
|
||||
"../../../../api/video:video_frame_type",
|
||||
"../../../../common_video/generic_frame_descriptor",
|
||||
"../../../../test:test_support",
|
||||
]
|
||||
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
|
||||
}
|
||||
|
||||
rtc_library("video_coding_codecs_av1_tests") {
|
||||
testonly = true
|
||||
|
||||
@ -160,8 +77,6 @@ if (rtc_include_tests) {
|
||||
deps = [
|
||||
":libaom_av1_decoder",
|
||||
":libaom_av1_encoder",
|
||||
":scalability_structures",
|
||||
":scalable_video_controller",
|
||||
"../..:encoded_video_frame_producer",
|
||||
"../..:video_codec_interface",
|
||||
"../../../../api:mock_video_encoder",
|
||||
@ -170,6 +85,8 @@ if (rtc_include_tests) {
|
||||
"../../../../api/video:video_frame",
|
||||
"../../../../api/video_codecs:video_codecs_api",
|
||||
"../../../../test:test_support",
|
||||
"../../svc:scalability_structures",
|
||||
"../../svc:scalable_video_controller",
|
||||
]
|
||||
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
|
||||
}
|
||||
|
||||
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/create_scalability_structure.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_l1t2.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_l1t3.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_l2t1.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_l2t1_key.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_l2t1h.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_l2t2.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_l2t2_key.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_l2t2_key_shift.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_l3t1.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_l3t3.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_s2t1.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller_no_layering.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
struct NamedStructureFactory {
|
||||
absl::string_view name;
|
||||
// Use function pointer to make NamedStructureFactory trivally destructable.
|
||||
std::unique_ptr<ScalableVideoController> (*factory)();
|
||||
};
|
||||
|
||||
// Wrap std::make_unique function to have correct return type.
|
||||
template <typename T>
|
||||
std::unique_ptr<ScalableVideoController> Create() {
|
||||
return std::make_unique<T>();
|
||||
}
|
||||
|
||||
constexpr NamedStructureFactory kFactories[] = {
|
||||
{"NONE", Create<ScalableVideoControllerNoLayering>},
|
||||
{"L1T2", Create<ScalabilityStructureL1T2>},
|
||||
{"L1T3", Create<ScalabilityStructureL1T3>},
|
||||
{"L2T1", Create<ScalabilityStructureL2T1>},
|
||||
{"L2T1h", Create<ScalabilityStructureL2T1h>},
|
||||
{"L2T1_KEY", Create<ScalabilityStructureL2T1Key>},
|
||||
{"L2T2", Create<ScalabilityStructureL2T2>},
|
||||
{"L2T2_KEY", Create<ScalabilityStructureL2T2Key>},
|
||||
{"L2T2_KEY_SHIFT", Create<ScalabilityStructureL2T2KeyShift>},
|
||||
{"L3T1", Create<ScalabilityStructureL3T1>},
|
||||
{"L3T3", Create<ScalabilityStructureL3T3>},
|
||||
{"S2T1", Create<ScalabilityStructureS2T1>},
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<ScalableVideoController> CreateScalabilityStructure(
|
||||
absl::string_view name) {
|
||||
RTC_DCHECK(!name.empty());
|
||||
for (const auto& entry : kFactories) {
|
||||
if (entry.name == name) {
|
||||
return entry.factory();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_CREATE_SCALABILITY_STRUCTURE_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_CREATE_SCALABILITY_STRUCTURE_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Creates a structure by name according to
|
||||
// https://w3c.github.io/webrtc-svc/#scalabilitymodes*
|
||||
// Returns nullptr for unknown name.
|
||||
std::unique_ptr<ScalableVideoController> CreateScalabilityStructure(
|
||||
absl::string_view name);
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_CREATE_SCALABILITY_STRUCTURE_H_
|
||||
@ -25,10 +25,10 @@
|
||||
#include "api/video/video_frame.h"
|
||||
#include "api/video_codecs/video_codec.h"
|
||||
#include "api/video_codecs/video_encoder.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller_no_layering.h"
|
||||
#include "modules/video_coding/include/video_codec_interface.h"
|
||||
#include "modules/video_coding/include/video_error_codes.h"
|
||||
#include "modules/video_coding/svc/scalable_video_controller.h"
|
||||
#include "modules/video_coding/svc/scalable_video_controller_no_layering.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "third_party/libaom/source/libaom/aom/aom_codec.h"
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "api/video_codecs/video_encoder.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
#include "modules/video_coding/svc/scalable_video_controller.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
|
||||
@ -16,9 +16,9 @@
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/video_codecs/video_codec.h"
|
||||
#include "api/video_codecs/video_encoder.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_l1t2.h"
|
||||
#include "modules/video_coding/codecs/test/encoded_video_frame_producer.h"
|
||||
#include "modules/video_coding/include/video_error_codes.h"
|
||||
#include "modules/video_coding/svc/scalability_structure_l1t2.h"
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
|
||||
@ -22,14 +22,14 @@
|
||||
#include "api/units/time_delta.h"
|
||||
#include "api/video_codecs/video_codec.h"
|
||||
#include "api/video_codecs/video_encoder.h"
|
||||
#include "modules/video_coding/codecs/av1/create_scalability_structure.h"
|
||||
#include "modules/video_coding/codecs/av1/libaom_av1_decoder.h"
|
||||
#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller_no_layering.h"
|
||||
#include "modules/video_coding/codecs/test/encoded_video_frame_producer.h"
|
||||
#include "modules/video_coding/include/video_codec_interface.h"
|
||||
#include "modules/video_coding/include/video_error_codes.h"
|
||||
#include "modules/video_coding/svc/create_scalability_structure.h"
|
||||
#include "modules/video_coding/svc/scalable_video_controller.h"
|
||||
#include "modules/video_coding/svc/scalable_video_controller_no_layering.h"
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
|
||||
@ -1,285 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_full_svc.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
enum : int { kKey, kDelta };
|
||||
} // namespace
|
||||
|
||||
constexpr int ScalabilityStructureFullSvc::kMaxNumSpatialLayers;
|
||||
constexpr int ScalabilityStructureFullSvc::kMaxNumTemporalLayers;
|
||||
constexpr absl::string_view ScalabilityStructureFullSvc::kFramePatternNames[];
|
||||
|
||||
ScalabilityStructureFullSvc::ScalabilityStructureFullSvc(
|
||||
int num_spatial_layers,
|
||||
int num_temporal_layers)
|
||||
: num_spatial_layers_(num_spatial_layers),
|
||||
num_temporal_layers_(num_temporal_layers),
|
||||
active_decode_targets_(
|
||||
(uint32_t{1} << (num_spatial_layers * num_temporal_layers)) - 1) {
|
||||
RTC_DCHECK_LE(num_spatial_layers, kMaxNumSpatialLayers);
|
||||
RTC_DCHECK_LE(num_temporal_layers, kMaxNumTemporalLayers);
|
||||
}
|
||||
|
||||
ScalabilityStructureFullSvc::~ScalabilityStructureFullSvc() = default;
|
||||
|
||||
ScalabilityStructureFullSvc::StreamLayersConfig
|
||||
ScalabilityStructureFullSvc::StreamConfig() const {
|
||||
StreamLayersConfig result;
|
||||
result.num_spatial_layers = num_spatial_layers_;
|
||||
result.num_temporal_layers = num_temporal_layers_;
|
||||
result.scaling_factor_num[num_spatial_layers_ - 1] = 1;
|
||||
result.scaling_factor_den[num_spatial_layers_ - 1] = 1;
|
||||
for (int sid = num_spatial_layers_ - 1; sid > 0; --sid) {
|
||||
result.scaling_factor_num[sid - 1] = 1;
|
||||
result.scaling_factor_den[sid - 1] = 2 * result.scaling_factor_den[sid];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ScalabilityStructureFullSvc::TemporalLayerIsActive(int tid) const {
|
||||
if (tid >= num_temporal_layers_) {
|
||||
return false;
|
||||
}
|
||||
for (int sid = 0; sid < num_spatial_layers_; ++sid) {
|
||||
if (DecodeTargetIsActive(sid, tid)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DecodeTargetIndication ScalabilityStructureFullSvc::Dti(
|
||||
int sid,
|
||||
int tid,
|
||||
const LayerFrameConfig& config) {
|
||||
if (sid < config.SpatialId() || tid < config.TemporalId()) {
|
||||
return DecodeTargetIndication::kNotPresent;
|
||||
}
|
||||
if (sid == config.SpatialId()) {
|
||||
if (tid == 0) {
|
||||
RTC_DCHECK_EQ(config.TemporalId(), 0);
|
||||
return DecodeTargetIndication::kSwitch;
|
||||
}
|
||||
if (tid == config.TemporalId()) {
|
||||
return DecodeTargetIndication::kDiscardable;
|
||||
}
|
||||
if (tid > config.TemporalId()) {
|
||||
RTC_DCHECK_GT(tid, config.TemporalId());
|
||||
return DecodeTargetIndication::kSwitch;
|
||||
}
|
||||
}
|
||||
RTC_DCHECK_GT(sid, config.SpatialId());
|
||||
RTC_DCHECK_GE(tid, config.TemporalId());
|
||||
if (config.IsKeyframe() || config.Id() == kKey) {
|
||||
return DecodeTargetIndication::kSwitch;
|
||||
}
|
||||
return DecodeTargetIndication::kRequired;
|
||||
}
|
||||
|
||||
ScalabilityStructureFullSvc::FramePattern
|
||||
ScalabilityStructureFullSvc::NextPattern() const {
|
||||
switch (last_pattern_) {
|
||||
case kNone:
|
||||
case kDeltaT2B:
|
||||
return kDeltaT0;
|
||||
case kDeltaT2A:
|
||||
if (TemporalLayerIsActive(1)) {
|
||||
return kDeltaT1;
|
||||
}
|
||||
return kDeltaT0;
|
||||
case kDeltaT1:
|
||||
if (TemporalLayerIsActive(2)) {
|
||||
return kDeltaT2B;
|
||||
}
|
||||
return kDeltaT0;
|
||||
case kDeltaT0:
|
||||
if (TemporalLayerIsActive(2)) {
|
||||
return kDeltaT2A;
|
||||
}
|
||||
if (TemporalLayerIsActive(1)) {
|
||||
return kDeltaT1;
|
||||
}
|
||||
return kDeltaT0;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<ScalableVideoController::LayerFrameConfig>
|
||||
ScalabilityStructureFullSvc::NextFrameConfig(bool restart) {
|
||||
std::vector<LayerFrameConfig> configs;
|
||||
if (active_decode_targets_.none()) {
|
||||
last_pattern_ = kNone;
|
||||
return configs;
|
||||
}
|
||||
configs.reserve(num_spatial_layers_);
|
||||
|
||||
if (last_pattern_ == kNone || restart) {
|
||||
can_reference_t0_frame_for_spatial_id_.reset();
|
||||
last_pattern_ = kNone;
|
||||
}
|
||||
FramePattern current_pattern = NextPattern();
|
||||
|
||||
absl::optional<int> spatial_dependency_buffer_id;
|
||||
switch (current_pattern) {
|
||||
case kDeltaT0:
|
||||
// Disallow temporal references cross T0 on higher temporal layers.
|
||||
can_reference_t1_frame_for_spatial_id_.reset();
|
||||
for (int sid = 0; sid < num_spatial_layers_; ++sid) {
|
||||
if (!DecodeTargetIsActive(sid, /*tid=*/0)) {
|
||||
// Next frame from the spatial layer `sid` shouldn't depend on
|
||||
// potentially old previous frame from the spatial layer `sid`.
|
||||
can_reference_t0_frame_for_spatial_id_.reset(sid);
|
||||
continue;
|
||||
}
|
||||
configs.emplace_back();
|
||||
ScalableVideoController::LayerFrameConfig& config = configs.back();
|
||||
config.Id(last_pattern_ == kNone ? kKey : kDelta).S(sid).T(0);
|
||||
|
||||
if (spatial_dependency_buffer_id) {
|
||||
config.Reference(*spatial_dependency_buffer_id);
|
||||
} else if (last_pattern_ == kNone) {
|
||||
config.Keyframe();
|
||||
}
|
||||
|
||||
if (can_reference_t0_frame_for_spatial_id_[sid]) {
|
||||
config.ReferenceAndUpdate(BufferIndex(sid, /*tid=*/0));
|
||||
} else {
|
||||
// TODO(bugs.webrtc.org/11999): Propagate chain restart on delta frame
|
||||
// to ChainDiffCalculator
|
||||
config.Update(BufferIndex(sid, /*tid=*/0));
|
||||
}
|
||||
|
||||
can_reference_t0_frame_for_spatial_id_.set(sid);
|
||||
spatial_dependency_buffer_id = BufferIndex(sid, /*tid=*/0);
|
||||
}
|
||||
break;
|
||||
case kDeltaT1:
|
||||
for (int sid = 0; sid < num_spatial_layers_; ++sid) {
|
||||
if (!DecodeTargetIsActive(sid, /*tid=*/1) ||
|
||||
!can_reference_t0_frame_for_spatial_id_[sid]) {
|
||||
continue;
|
||||
}
|
||||
configs.emplace_back();
|
||||
ScalableVideoController::LayerFrameConfig& config = configs.back();
|
||||
config.Id(kDelta).S(sid).T(1);
|
||||
// Temporal reference.
|
||||
config.Reference(BufferIndex(sid, /*tid=*/0));
|
||||
// Spatial reference unless this is the lowest active spatial layer.
|
||||
if (spatial_dependency_buffer_id) {
|
||||
config.Reference(*spatial_dependency_buffer_id);
|
||||
}
|
||||
// No frame reference top layer frame, so no need save it into a buffer.
|
||||
if (num_temporal_layers_ > 2 || sid < num_spatial_layers_ - 1) {
|
||||
config.Update(BufferIndex(sid, /*tid=*/1));
|
||||
can_reference_t1_frame_for_spatial_id_.set(sid);
|
||||
}
|
||||
spatial_dependency_buffer_id = BufferIndex(sid, /*tid=*/1);
|
||||
}
|
||||
break;
|
||||
case kDeltaT2A:
|
||||
case kDeltaT2B:
|
||||
for (int sid = 0; sid < num_spatial_layers_; ++sid) {
|
||||
if (!DecodeTargetIsActive(sid, /*tid=*/2) ||
|
||||
!can_reference_t0_frame_for_spatial_id_[sid]) {
|
||||
continue;
|
||||
}
|
||||
configs.emplace_back();
|
||||
ScalableVideoController::LayerFrameConfig& config = configs.back();
|
||||
config.Id(kDelta).S(sid).T(2);
|
||||
// Temporal reference.
|
||||
if (current_pattern == kDeltaT2B &&
|
||||
can_reference_t1_frame_for_spatial_id_[sid]) {
|
||||
config.Reference(BufferIndex(sid, /*tid=*/1));
|
||||
} else {
|
||||
config.Reference(BufferIndex(sid, /*tid=*/0));
|
||||
}
|
||||
// Spatial reference unless this is the lowest active spatial layer.
|
||||
if (spatial_dependency_buffer_id) {
|
||||
config.Reference(*spatial_dependency_buffer_id);
|
||||
}
|
||||
// No frame reference top layer frame, so no need save it into a buffer.
|
||||
if (sid < num_spatial_layers_ - 1) {
|
||||
config.Update(BufferIndex(sid, /*tid=*/2));
|
||||
}
|
||||
spatial_dependency_buffer_id = BufferIndex(sid, /*tid=*/2);
|
||||
}
|
||||
break;
|
||||
case kNone:
|
||||
RTC_NOTREACHED();
|
||||
break;
|
||||
}
|
||||
|
||||
if (configs.empty() && !restart) {
|
||||
RTC_LOG(LS_WARNING) << "Failed to generate configuration for L"
|
||||
<< num_spatial_layers_ << "T" << num_temporal_layers_
|
||||
<< " with active decode targets "
|
||||
<< active_decode_targets_.to_string('-').substr(
|
||||
active_decode_targets_.size() -
|
||||
num_spatial_layers_ * num_temporal_layers_)
|
||||
<< " and transition from "
|
||||
<< kFramePatternNames[last_pattern_] << " to "
|
||||
<< kFramePatternNames[current_pattern]
|
||||
<< ". Resetting.";
|
||||
return NextFrameConfig(/*restart=*/true);
|
||||
}
|
||||
|
||||
last_pattern_ = current_pattern;
|
||||
return configs;
|
||||
}
|
||||
|
||||
GenericFrameInfo ScalabilityStructureFullSvc::OnEncodeDone(
|
||||
const LayerFrameConfig& config) {
|
||||
GenericFrameInfo frame_info;
|
||||
frame_info.spatial_id = config.SpatialId();
|
||||
frame_info.temporal_id = config.TemporalId();
|
||||
frame_info.encoder_buffers = config.Buffers();
|
||||
frame_info.decode_target_indications.reserve(num_spatial_layers_ *
|
||||
num_temporal_layers_);
|
||||
for (int sid = 0; sid < num_spatial_layers_; ++sid) {
|
||||
for (int tid = 0; tid < num_temporal_layers_; ++tid) {
|
||||
frame_info.decode_target_indications.push_back(Dti(sid, tid, config));
|
||||
}
|
||||
}
|
||||
if (config.TemporalId() == 0) {
|
||||
frame_info.part_of_chain.resize(num_spatial_layers_);
|
||||
for (int sid = 0; sid < num_spatial_layers_; ++sid) {
|
||||
frame_info.part_of_chain[sid] = config.SpatialId() <= sid;
|
||||
}
|
||||
} else {
|
||||
frame_info.part_of_chain.assign(num_spatial_layers_, false);
|
||||
}
|
||||
frame_info.active_decode_targets = active_decode_targets_;
|
||||
return frame_info;
|
||||
}
|
||||
|
||||
void ScalabilityStructureFullSvc::OnRatesUpdated(
|
||||
const VideoBitrateAllocation& bitrates) {
|
||||
for (int sid = 0; sid < num_spatial_layers_; ++sid) {
|
||||
// Enable/disable spatial layers independetely.
|
||||
bool active = true;
|
||||
for (int tid = 0; tid < num_temporal_layers_; ++tid) {
|
||||
// To enable temporal layer, require bitrates for lower temporal layers.
|
||||
active = active && bitrates.GetBitrate(sid, tid) > 0;
|
||||
SetDecodeTargetIsActive(sid, tid, active);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_FULL_SVC_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_FULL_SVC_H_
|
||||
|
||||
#include <bitset>
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "common_video/generic_frame_descriptor/generic_frame_info.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class ScalabilityStructureFullSvc : public ScalableVideoController {
|
||||
public:
|
||||
ScalabilityStructureFullSvc(int num_spatial_layers, int num_temporal_layers);
|
||||
~ScalabilityStructureFullSvc() override;
|
||||
|
||||
StreamLayersConfig StreamConfig() const override;
|
||||
|
||||
std::vector<LayerFrameConfig> NextFrameConfig(bool restart) override;
|
||||
GenericFrameInfo OnEncodeDone(const LayerFrameConfig& config) override;
|
||||
void OnRatesUpdated(const VideoBitrateAllocation& bitrates) override;
|
||||
|
||||
private:
|
||||
enum FramePattern {
|
||||
kNone,
|
||||
kDeltaT2A,
|
||||
kDeltaT1,
|
||||
kDeltaT2B,
|
||||
kDeltaT0,
|
||||
};
|
||||
static constexpr absl::string_view kFramePatternNames[] = {
|
||||
"None", "DeltaT2A", "DeltaT1", "DeltaT2B", "DeltaT0"};
|
||||
static constexpr int kMaxNumSpatialLayers = 3;
|
||||
static constexpr int kMaxNumTemporalLayers = 3;
|
||||
|
||||
// Index of the buffer to store last frame for layer (`sid`, `tid`)
|
||||
int BufferIndex(int sid, int tid) const {
|
||||
return tid * num_spatial_layers_ + sid;
|
||||
}
|
||||
bool DecodeTargetIsActive(int sid, int tid) const {
|
||||
return active_decode_targets_[sid * num_temporal_layers_ + tid];
|
||||
}
|
||||
void SetDecodeTargetIsActive(int sid, int tid, bool value) {
|
||||
active_decode_targets_.set(sid * num_temporal_layers_ + tid, value);
|
||||
}
|
||||
FramePattern NextPattern() const;
|
||||
bool TemporalLayerIsActive(int tid) const;
|
||||
static DecodeTargetIndication Dti(int sid,
|
||||
int tid,
|
||||
const LayerFrameConfig& frame);
|
||||
|
||||
const int num_spatial_layers_;
|
||||
const int num_temporal_layers_;
|
||||
|
||||
FramePattern last_pattern_ = kNone;
|
||||
std::bitset<kMaxNumSpatialLayers> can_reference_t0_frame_for_spatial_id_ = 0;
|
||||
std::bitset<kMaxNumSpatialLayers> can_reference_t1_frame_for_spatial_id_ = 0;
|
||||
std::bitset<32> active_decode_targets_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_FULL_SVC_H_
|
||||
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_l1t2.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
ScalabilityStructureL1T2::~ScalabilityStructureL1T2() = default;
|
||||
|
||||
FrameDependencyStructure ScalabilityStructureL1T2::DependencyStructure() const {
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 2;
|
||||
structure.num_chains = 1;
|
||||
structure.decode_target_protected_by_chain = {0, 0};
|
||||
structure.templates.resize(3);
|
||||
structure.templates[0].T(0).Dtis("SS").ChainDiffs({0});
|
||||
structure.templates[1].T(0).Dtis("SS").ChainDiffs({2}).FrameDiffs({2});
|
||||
structure.templates[2].T(1).Dtis("-D").ChainDiffs({1}).FrameDiffs({1});
|
||||
return structure;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L1T2_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L1T2_H_
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_full_svc.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class ScalabilityStructureL1T2 : public ScalabilityStructureFullSvc {
|
||||
public:
|
||||
ScalabilityStructureL1T2() : ScalabilityStructureFullSvc(1, 2) {}
|
||||
~ScalabilityStructureL1T2() override;
|
||||
|
||||
FrameDependencyStructure DependencyStructure() const override;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L1T2_H_
|
||||
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_l1t3.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
ScalabilityStructureL1T3::~ScalabilityStructureL1T3() = default;
|
||||
|
||||
FrameDependencyStructure ScalabilityStructureL1T3::DependencyStructure() const {
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 3;
|
||||
structure.num_chains = 1;
|
||||
structure.decode_target_protected_by_chain = {0, 0, 0};
|
||||
structure.templates.resize(5);
|
||||
structure.templates[0].T(0).Dtis("SSS").ChainDiffs({0});
|
||||
structure.templates[1].T(0).Dtis("SSS").ChainDiffs({4}).FrameDiffs({4});
|
||||
structure.templates[2].T(1).Dtis("-DS").ChainDiffs({2}).FrameDiffs({2});
|
||||
structure.templates[3].T(2).Dtis("--D").ChainDiffs({1}).FrameDiffs({1});
|
||||
structure.templates[4].T(2).Dtis("--D").ChainDiffs({3}).FrameDiffs({1});
|
||||
return structure;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L1T3_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L1T3_H_
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_full_svc.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// T2 0 0 0 0
|
||||
// | / | /
|
||||
// T1 / 0 / 0 ...
|
||||
// |_/ |_/
|
||||
// T0 0-------0------
|
||||
// Time-> 0 1 2 3 4 5 6 7
|
||||
class ScalabilityStructureL1T3 : public ScalabilityStructureFullSvc {
|
||||
public:
|
||||
ScalabilityStructureL1T3() : ScalabilityStructureFullSvc(1, 3) {}
|
||||
~ScalabilityStructureL1T3() override;
|
||||
|
||||
FrameDependencyStructure DependencyStructure() const override;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L1T3_H_
|
||||
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_l2t1.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
ScalabilityStructureL2T1::~ScalabilityStructureL2T1() = default;
|
||||
|
||||
FrameDependencyStructure ScalabilityStructureL2T1::DependencyStructure() const {
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 2;
|
||||
structure.num_chains = 2;
|
||||
structure.decode_target_protected_by_chain = {0, 1};
|
||||
structure.templates.resize(4);
|
||||
structure.templates[0].S(0).Dtis("SR").ChainDiffs({2, 1}).FrameDiffs({2});
|
||||
structure.templates[1].S(0).Dtis("SS").ChainDiffs({0, 0});
|
||||
structure.templates[2].S(1).Dtis("-S").ChainDiffs({1, 1}).FrameDiffs({2, 1});
|
||||
structure.templates[3].S(1).Dtis("-S").ChainDiffs({1, 1}).FrameDiffs({1});
|
||||
return structure;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T1_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T1_H_
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_full_svc.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// S1 0--0--0-
|
||||
// | | | ...
|
||||
// S0 0--0--0-
|
||||
class ScalabilityStructureL2T1 : public ScalabilityStructureFullSvc {
|
||||
public:
|
||||
ScalabilityStructureL2T1() : ScalabilityStructureFullSvc(2, 1) {}
|
||||
~ScalabilityStructureL2T1() override;
|
||||
|
||||
FrameDependencyStructure DependencyStructure() const override;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T1_H_
|
||||
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_l2t1_key.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/macros.h"
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
constexpr auto kNotPresent = DecodeTargetIndication::kNotPresent;
|
||||
constexpr auto kSwitch = DecodeTargetIndication::kSwitch;
|
||||
|
||||
constexpr DecodeTargetIndication kDtis[3][2] = {
|
||||
{kSwitch, kSwitch}, // Key, S0
|
||||
{kSwitch, kNotPresent}, // Delta, S0
|
||||
{kNotPresent, kSwitch}, // Key and Delta, S1
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
ScalabilityStructureL2T1Key::~ScalabilityStructureL2T1Key() = default;
|
||||
|
||||
ScalableVideoController::StreamLayersConfig
|
||||
ScalabilityStructureL2T1Key::StreamConfig() const {
|
||||
StreamLayersConfig result;
|
||||
result.num_spatial_layers = 2;
|
||||
result.num_temporal_layers = 1;
|
||||
result.scaling_factor_num[0] = 1;
|
||||
result.scaling_factor_den[0] = 2;
|
||||
return result;
|
||||
}
|
||||
|
||||
FrameDependencyStructure ScalabilityStructureL2T1Key::DependencyStructure()
|
||||
const {
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 2;
|
||||
structure.num_chains = 2;
|
||||
structure.decode_target_protected_by_chain = {0, 1};
|
||||
structure.templates.resize(4);
|
||||
structure.templates[0].S(0).Dtis("S-").ChainDiffs({2, 1}).FrameDiffs({2});
|
||||
structure.templates[1].S(0).Dtis("SS").ChainDiffs({0, 0});
|
||||
structure.templates[2].S(1).Dtis("-S").ChainDiffs({1, 2}).FrameDiffs({2});
|
||||
structure.templates[3].S(1).Dtis("-S").ChainDiffs({1, 1}).FrameDiffs({1});
|
||||
return structure;
|
||||
}
|
||||
|
||||
ScalableVideoController::LayerFrameConfig
|
||||
ScalabilityStructureL2T1Key::KeyFrameConfig() const {
|
||||
return LayerFrameConfig().Id(0).S(0).Keyframe().Update(0);
|
||||
}
|
||||
|
||||
std::vector<ScalableVideoController::LayerFrameConfig>
|
||||
ScalabilityStructureL2T1Key::NextFrameConfig(bool restart) {
|
||||
std::vector<LayerFrameConfig> result(2);
|
||||
|
||||
// Buffer0 keeps latest S0T0 frame, Buffer1 keeps latest S1T0 frame.
|
||||
if (restart || keyframe_) {
|
||||
result[0] = KeyFrameConfig();
|
||||
result[1].Id(2).S(1).Reference(0).Update(1);
|
||||
keyframe_ = false;
|
||||
} else {
|
||||
result[0].Id(1).S(0).ReferenceAndUpdate(0);
|
||||
result[1].Id(2).S(1).ReferenceAndUpdate(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
GenericFrameInfo ScalabilityStructureL2T1Key::OnEncodeDone(
|
||||
const LayerFrameConfig& config) {
|
||||
RTC_CHECK_GE(config.Id(), 0);
|
||||
RTC_CHECK_LT(config.Id(), ABSL_ARRAYSIZE(kDtis));
|
||||
|
||||
GenericFrameInfo frame_info;
|
||||
frame_info.spatial_id = config.SpatialId();
|
||||
frame_info.temporal_id = config.TemporalId();
|
||||
frame_info.encoder_buffers = config.Buffers();
|
||||
int config_id = config.IsKeyframe() ? 0 : config.Id();
|
||||
frame_info.decode_target_indications.assign(std::begin(kDtis[config_id]),
|
||||
std::end(kDtis[config_id]));
|
||||
if (config.IsKeyframe()) {
|
||||
frame_info.part_of_chain = {true, true};
|
||||
} else {
|
||||
frame_info.part_of_chain = {config.SpatialId() == 0,
|
||||
config.SpatialId() == 1};
|
||||
}
|
||||
return frame_info;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T1_KEY_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T1_KEY_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "common_video/generic_frame_descriptor/generic_frame_info.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// S1 0--0--0-
|
||||
// | ...
|
||||
// S0 0--0--0-
|
||||
class ScalabilityStructureL2T1Key : public ScalableVideoController {
|
||||
public:
|
||||
~ScalabilityStructureL2T1Key() override;
|
||||
|
||||
StreamLayersConfig StreamConfig() const override;
|
||||
FrameDependencyStructure DependencyStructure() const override;
|
||||
|
||||
std::vector<LayerFrameConfig> NextFrameConfig(bool restart) override;
|
||||
GenericFrameInfo OnEncodeDone(const LayerFrameConfig& config) override;
|
||||
|
||||
private:
|
||||
LayerFrameConfig KeyFrameConfig() const;
|
||||
|
||||
bool keyframe_ = true;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T1_KEY_H_
|
||||
@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_l2t1h.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/macros.h"
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
ScalabilityStructureL2T1h::~ScalabilityStructureL2T1h() = default;
|
||||
|
||||
ScalableVideoController::StreamLayersConfig
|
||||
ScalabilityStructureL2T1h::StreamConfig() const {
|
||||
StreamLayersConfig result;
|
||||
result.num_spatial_layers = 2;
|
||||
result.num_temporal_layers = 1;
|
||||
// 1.5:1 scaling, see https://w3c.github.io/webrtc-svc/#scalabilitymodes*
|
||||
result.scaling_factor_num[0] = 2;
|
||||
result.scaling_factor_den[0] = 3;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T1H_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T1H_H_
|
||||
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_l2t1.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class ScalabilityStructureL2T1h : public ScalabilityStructureL2T1 {
|
||||
public:
|
||||
~ScalabilityStructureL2T1h() override;
|
||||
|
||||
StreamLayersConfig StreamConfig() const override;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T1H_H_
|
||||
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_l2t2.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
ScalabilityStructureL2T2::~ScalabilityStructureL2T2() = default;
|
||||
|
||||
FrameDependencyStructure ScalabilityStructureL2T2::DependencyStructure() const {
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 4;
|
||||
structure.num_chains = 2;
|
||||
structure.decode_target_protected_by_chain = {0, 0, 1, 1};
|
||||
structure.templates.resize(6);
|
||||
auto& templates = structure.templates;
|
||||
templates[0].S(0).T(0).Dtis("SSSS").ChainDiffs({0, 0});
|
||||
templates[1].S(0).T(0).Dtis("SSRR").ChainDiffs({4, 3}).FrameDiffs({4});
|
||||
templates[2].S(0).T(1).Dtis("-D-R").ChainDiffs({2, 1}).FrameDiffs({2});
|
||||
templates[3].S(1).T(0).Dtis("--SS").ChainDiffs({1, 1}).FrameDiffs({1});
|
||||
templates[4].S(1).T(0).Dtis("--SS").ChainDiffs({1, 1}).FrameDiffs({4, 1});
|
||||
templates[5].S(1).T(1).Dtis("---D").ChainDiffs({3, 2}).FrameDiffs({2, 1});
|
||||
return structure;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T2_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T2_H_
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_full_svc.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// S1T1 0 0
|
||||
// /| /| /
|
||||
// S1T0 0-+-0-+-0
|
||||
// | | | | | ...
|
||||
// S0T1 | 0 | 0 |
|
||||
// |/ |/ |/
|
||||
// S0T0 0---0---0--
|
||||
// Time-> 0 1 2 3 4
|
||||
class ScalabilityStructureL2T2 : public ScalabilityStructureFullSvc {
|
||||
public:
|
||||
ScalabilityStructureL2T2() : ScalabilityStructureFullSvc(2, 2) {}
|
||||
~ScalabilityStructureL2T2() override;
|
||||
|
||||
FrameDependencyStructure DependencyStructure() const override;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T2_H_
|
||||
@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_l2t2_key.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/macros.h"
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
constexpr auto kNotPresent = DecodeTargetIndication::kNotPresent;
|
||||
constexpr auto kDiscardable = DecodeTargetIndication::kDiscardable;
|
||||
constexpr auto kSwitch = DecodeTargetIndication::kSwitch;
|
||||
|
||||
// decode targets: S0T0, S0T1, S1T0, S1T1
|
||||
constexpr DecodeTargetIndication kDtis[6][4] = {
|
||||
{kSwitch, kSwitch, kSwitch, kSwitch}, // kKey, S0
|
||||
{kNotPresent, kNotPresent, kSwitch, kSwitch}, // kKey, S1
|
||||
{kNotPresent, kDiscardable, kNotPresent, kNotPresent}, // kDeltaT1, S0
|
||||
{kNotPresent, kNotPresent, kNotPresent, kDiscardable}, // kDeltaT1, S1
|
||||
{kSwitch, kSwitch, kNotPresent, kNotPresent}, // kDeltaT0, S0
|
||||
{kNotPresent, kNotPresent, kSwitch, kSwitch}, // kDeltaT0, S1
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
ScalabilityStructureL2T2Key::~ScalabilityStructureL2T2Key() = default;
|
||||
|
||||
ScalableVideoController::StreamLayersConfig
|
||||
ScalabilityStructureL2T2Key::StreamConfig() const {
|
||||
StreamLayersConfig result;
|
||||
result.num_spatial_layers = 2;
|
||||
result.num_temporal_layers = 2;
|
||||
result.scaling_factor_num[0] = 1;
|
||||
result.scaling_factor_den[0] = 2;
|
||||
return result;
|
||||
}
|
||||
|
||||
FrameDependencyStructure ScalabilityStructureL2T2Key::DependencyStructure()
|
||||
const {
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 4;
|
||||
structure.num_chains = 2;
|
||||
structure.decode_target_protected_by_chain = {0, 0, 1, 1};
|
||||
structure.templates.resize(6);
|
||||
auto& templates = structure.templates;
|
||||
templates[0].S(0).T(0).Dtis("SSSS").ChainDiffs({0, 0});
|
||||
templates[1].S(0).T(0).Dtis("SS--").ChainDiffs({4, 3}).FrameDiffs({4});
|
||||
templates[2].S(0).T(1).Dtis("-D--").ChainDiffs({2, 1}).FrameDiffs({2});
|
||||
templates[3].S(1).T(0).Dtis("--SS").ChainDiffs({1, 1}).FrameDiffs({1});
|
||||
templates[4].S(1).T(0).Dtis("--SS").ChainDiffs({1, 4}).FrameDiffs({4});
|
||||
templates[5].S(1).T(1).Dtis("---D").ChainDiffs({3, 2}).FrameDiffs({2});
|
||||
return structure;
|
||||
}
|
||||
|
||||
ScalableVideoController::LayerFrameConfig
|
||||
ScalabilityStructureL2T2Key::KeyFrameConfig() const {
|
||||
return LayerFrameConfig().Id(0).Keyframe().S(0).T(0).Update(0);
|
||||
}
|
||||
|
||||
std::vector<ScalableVideoController::LayerFrameConfig>
|
||||
ScalabilityStructureL2T2Key::NextFrameConfig(bool restart) {
|
||||
if (restart) {
|
||||
next_pattern_ = kKey;
|
||||
}
|
||||
std::vector<LayerFrameConfig> result(2);
|
||||
|
||||
// Buffer0 keeps latest S0T0 frame,
|
||||
// Buffer1 keeps latest S1T0 frame.
|
||||
switch (next_pattern_) {
|
||||
case kKey:
|
||||
result[0] = KeyFrameConfig();
|
||||
result[1].Id(1).S(1).T(0).Reference(0).Update(1);
|
||||
next_pattern_ = kDeltaT1;
|
||||
break;
|
||||
case kDeltaT1:
|
||||
result[0].Id(2).S(0).T(1).Reference(0);
|
||||
result[1].Id(3).S(1).T(1).Reference(1);
|
||||
next_pattern_ = kDeltaT0;
|
||||
break;
|
||||
case kDeltaT0:
|
||||
result[0].Id(4).S(0).T(0).ReferenceAndUpdate(0);
|
||||
result[1].Id(5).S(1).T(0).ReferenceAndUpdate(1);
|
||||
next_pattern_ = kDeltaT1;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
GenericFrameInfo ScalabilityStructureL2T2Key::OnEncodeDone(
|
||||
const LayerFrameConfig& config) {
|
||||
RTC_CHECK_GE(config.Id(), 0);
|
||||
RTC_CHECK_LT(config.Id(), ABSL_ARRAYSIZE(kDtis));
|
||||
|
||||
GenericFrameInfo frame_info;
|
||||
frame_info.spatial_id = config.SpatialId();
|
||||
frame_info.temporal_id = config.TemporalId();
|
||||
frame_info.encoder_buffers = config.Buffers();
|
||||
int config_id = config.IsKeyframe() ? 0 : config.Id();
|
||||
frame_info.decode_target_indications.assign(std::begin(kDtis[config_id]),
|
||||
std::end(kDtis[config_id]));
|
||||
if (config.IsKeyframe()) {
|
||||
frame_info.part_of_chain = {true, true};
|
||||
} else if (config.TemporalId() == 0) {
|
||||
frame_info.part_of_chain = {config.SpatialId() == 0,
|
||||
config.SpatialId() == 1};
|
||||
} else {
|
||||
frame_info.part_of_chain = {false, false};
|
||||
}
|
||||
return frame_info;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T2_KEY_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T2_KEY_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "common_video/generic_frame_descriptor/generic_frame_info.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// S1T1 0 0
|
||||
// / / /
|
||||
// S1T0 0---0---0
|
||||
// | ...
|
||||
// S0T1 | 0 0
|
||||
// |/ / /
|
||||
// S0T0 0---0---0
|
||||
// Time-> 0 1 2 3 4
|
||||
class ScalabilityStructureL2T2Key : public ScalableVideoController {
|
||||
public:
|
||||
~ScalabilityStructureL2T2Key() override;
|
||||
|
||||
StreamLayersConfig StreamConfig() const override;
|
||||
FrameDependencyStructure DependencyStructure() const override;
|
||||
|
||||
std::vector<LayerFrameConfig> NextFrameConfig(bool restart) override;
|
||||
GenericFrameInfo OnEncodeDone(const LayerFrameConfig& config) override;
|
||||
|
||||
private:
|
||||
enum FramePattern {
|
||||
kKey,
|
||||
kDeltaT1,
|
||||
kDeltaT0,
|
||||
};
|
||||
LayerFrameConfig KeyFrameConfig() const;
|
||||
|
||||
FramePattern next_pattern_ = kKey;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T2_KEY_H_
|
||||
@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_l2t2_key_shift.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/macros.h"
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
constexpr auto kNotPresent = DecodeTargetIndication::kNotPresent;
|
||||
constexpr auto kDiscardable = DecodeTargetIndication::kDiscardable;
|
||||
constexpr auto kSwitch = DecodeTargetIndication::kSwitch;
|
||||
|
||||
constexpr DecodeTargetIndication kDtis[6][4] = {
|
||||
{kSwitch, kSwitch, kSwitch, kSwitch}, // kKey, S0T0
|
||||
{kNotPresent, kNotPresent, kSwitch, kSwitch}, // kKey, S1T0
|
||||
{kSwitch, kSwitch, kNotPresent, kNotPresent}, // kDelta0, S0T0
|
||||
{kNotPresent, kNotPresent, kNotPresent, kDiscardable}, // kDelta0, S1T1
|
||||
{kNotPresent, kDiscardable, kNotPresent, kNotPresent}, // kDelta1, S0T1
|
||||
{kNotPresent, kNotPresent, kSwitch, kSwitch}, // kDelta1, S1T0
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
ScalabilityStructureL2T2KeyShift::~ScalabilityStructureL2T2KeyShift() = default;
|
||||
|
||||
ScalableVideoController::StreamLayersConfig
|
||||
ScalabilityStructureL2T2KeyShift::StreamConfig() const {
|
||||
StreamLayersConfig result;
|
||||
result.num_spatial_layers = 2;
|
||||
result.num_temporal_layers = 2;
|
||||
result.scaling_factor_num[0] = 1;
|
||||
result.scaling_factor_den[0] = 2;
|
||||
return result;
|
||||
}
|
||||
|
||||
FrameDependencyStructure ScalabilityStructureL2T2KeyShift::DependencyStructure()
|
||||
const {
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 4;
|
||||
structure.num_chains = 2;
|
||||
structure.decode_target_protected_by_chain = {0, 0, 1, 1};
|
||||
structure.templates.resize(7);
|
||||
auto& templates = structure.templates;
|
||||
templates[0].S(0).T(0).Dtis("SSSS").ChainDiffs({0, 0});
|
||||
templates[1].S(0).T(0).Dtis("SS--").ChainDiffs({2, 1}).FrameDiffs({2});
|
||||
templates[2].S(0).T(0).Dtis("SS--").ChainDiffs({4, 1}).FrameDiffs({4});
|
||||
templates[3].S(0).T(1).Dtis("-D--").ChainDiffs({2, 3}).FrameDiffs({2});
|
||||
templates[4].S(1).T(0).Dtis("--SS").ChainDiffs({1, 1}).FrameDiffs({1});
|
||||
templates[5].S(1).T(0).Dtis("--SS").ChainDiffs({3, 4}).FrameDiffs({4});
|
||||
templates[6].S(1).T(1).Dtis("---D").ChainDiffs({1, 2}).FrameDiffs({2});
|
||||
return structure;
|
||||
}
|
||||
|
||||
ScalableVideoController::LayerFrameConfig
|
||||
ScalabilityStructureL2T2KeyShift::KeyFrameConfig() const {
|
||||
return LayerFrameConfig().Id(0).Keyframe().S(0).T(0).Update(0);
|
||||
}
|
||||
|
||||
std::vector<ScalableVideoController::LayerFrameConfig>
|
||||
ScalabilityStructureL2T2KeyShift::NextFrameConfig(bool restart) {
|
||||
if (restart) {
|
||||
next_pattern_ = kKey;
|
||||
}
|
||||
std::vector<LayerFrameConfig> result(2);
|
||||
|
||||
// Buffer0 keeps latest S0T0 frame,
|
||||
// Buffer1 keeps latest S1T0 frame.
|
||||
switch (next_pattern_) {
|
||||
case kKey:
|
||||
result[0] = KeyFrameConfig();
|
||||
result[1].Id(1).S(1).T(0).Reference(0).Update(1);
|
||||
next_pattern_ = kDelta0;
|
||||
break;
|
||||
case kDelta0:
|
||||
result[0].Id(2).S(0).T(0).ReferenceAndUpdate(0);
|
||||
result[1].Id(3).S(1).T(1).Reference(1);
|
||||
next_pattern_ = kDelta1;
|
||||
break;
|
||||
case kDelta1:
|
||||
result[0].Id(4).S(0).T(1).Reference(0);
|
||||
result[1].Id(5).S(1).T(0).ReferenceAndUpdate(1);
|
||||
next_pattern_ = kDelta0;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
GenericFrameInfo ScalabilityStructureL2T2KeyShift::OnEncodeDone(
|
||||
const LayerFrameConfig& config) {
|
||||
RTC_CHECK_GE(config.Id(), 0);
|
||||
RTC_CHECK_LT(config.Id(), ABSL_ARRAYSIZE(kDtis));
|
||||
|
||||
GenericFrameInfo frame_info;
|
||||
frame_info.spatial_id = config.SpatialId();
|
||||
frame_info.temporal_id = config.TemporalId();
|
||||
frame_info.encoder_buffers = config.Buffers();
|
||||
int config_id = config.IsKeyframe() ? 0 : config.Id();
|
||||
frame_info.decode_target_indications.assign(std::begin(kDtis[config_id]),
|
||||
std::end(kDtis[config_id]));
|
||||
if (config.IsKeyframe()) {
|
||||
frame_info.part_of_chain = {true, true};
|
||||
} else if (config.TemporalId() == 0) {
|
||||
frame_info.part_of_chain = {config.SpatialId() == 0,
|
||||
config.SpatialId() == 1};
|
||||
} else {
|
||||
frame_info.part_of_chain = {false, false};
|
||||
}
|
||||
return frame_info;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T2_KEY_SHIFT_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T2_KEY_SHIFT_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "common_video/generic_frame_descriptor/generic_frame_info.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// S1T1 0 0
|
||||
// / / /
|
||||
// S1T0 0---0---0
|
||||
// | ...
|
||||
// S0T1 | 0 0
|
||||
// | / /
|
||||
// S0T0 0-0---0--
|
||||
// Time-> 0 1 2 3 4
|
||||
class ScalabilityStructureL2T2KeyShift : public ScalableVideoController {
|
||||
public:
|
||||
~ScalabilityStructureL2T2KeyShift() override;
|
||||
|
||||
StreamLayersConfig StreamConfig() const override;
|
||||
FrameDependencyStructure DependencyStructure() const override;
|
||||
|
||||
std::vector<LayerFrameConfig> NextFrameConfig(bool restart) override;
|
||||
GenericFrameInfo OnEncodeDone(const LayerFrameConfig& config) override;
|
||||
|
||||
private:
|
||||
enum FramePattern {
|
||||
kKey,
|
||||
kDelta0,
|
||||
kDelta1,
|
||||
};
|
||||
LayerFrameConfig KeyFrameConfig() const;
|
||||
|
||||
FramePattern next_pattern_ = kKey;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L2T2_KEY_SHIFT_H_
|
||||
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_l3t1.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
ScalabilityStructureL3T1::~ScalabilityStructureL3T1() = default;
|
||||
|
||||
FrameDependencyStructure ScalabilityStructureL3T1::DependencyStructure() const {
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 3;
|
||||
structure.num_chains = 3;
|
||||
structure.decode_target_protected_by_chain = {0, 1, 2};
|
||||
auto& templates = structure.templates;
|
||||
templates.resize(6);
|
||||
templates[0].S(0).Dtis("SRR").ChainDiffs({3, 2, 1}).FrameDiffs({3});
|
||||
templates[1].S(0).Dtis("SSS").ChainDiffs({0, 0, 0});
|
||||
templates[2].S(1).Dtis("-SR").ChainDiffs({1, 1, 1}).FrameDiffs({3, 1});
|
||||
templates[3].S(1).Dtis("-SS").ChainDiffs({1, 1, 1}).FrameDiffs({1});
|
||||
templates[4].S(2).Dtis("--S").ChainDiffs({2, 1, 1}).FrameDiffs({3, 1});
|
||||
templates[5].S(2).Dtis("--S").ChainDiffs({2, 1, 1}).FrameDiffs({1});
|
||||
return structure;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L3T1_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L3T1_H_
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_full_svc.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// S2 0-0-0-
|
||||
// | | |
|
||||
// S1 0-0-0-...
|
||||
// | | |
|
||||
// S0 0-0-0-
|
||||
// Time-> 0 1 2
|
||||
class ScalabilityStructureL3T1 : public ScalabilityStructureFullSvc {
|
||||
public:
|
||||
ScalabilityStructureL3T1() : ScalabilityStructureFullSvc(3, 1) {}
|
||||
~ScalabilityStructureL3T1() override;
|
||||
|
||||
FrameDependencyStructure DependencyStructure() const override;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L3T1_H_
|
||||
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_l3t3.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
ScalabilityStructureL3T3::~ScalabilityStructureL3T3() = default;
|
||||
|
||||
FrameDependencyStructure ScalabilityStructureL3T3::DependencyStructure() const {
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 9;
|
||||
structure.num_chains = 3;
|
||||
structure.decode_target_protected_by_chain = {0, 0, 0, 1, 1, 1, 2, 2, 2};
|
||||
auto& t = structure.templates;
|
||||
t.resize(15);
|
||||
// Templates are shown in the order frames following them appear in the
|
||||
// stream, but in `structure.templates` array templates are sorted by
|
||||
// (`spatial_id`, `temporal_id`) since that is a dependency descriptor
|
||||
// requirement. Indexes are written in hex for nicer alignment.
|
||||
t[0x1].S(0).T(0).Dtis("SSSSSSSSS").ChainDiffs({0, 0, 0});
|
||||
t[0x6].S(1).T(0).Dtis("---SSSSSS").ChainDiffs({1, 1, 1}).FrameDiffs({1});
|
||||
t[0xB].S(2).T(0).Dtis("------SSS").ChainDiffs({2, 1, 1}).FrameDiffs({1});
|
||||
t[0x3].S(0).T(2).Dtis("--D--R--R").ChainDiffs({3, 2, 1}).FrameDiffs({3});
|
||||
t[0x8].S(1).T(2).Dtis("-----D--R").ChainDiffs({4, 3, 2}).FrameDiffs({3, 1});
|
||||
t[0xD].S(2).T(2).Dtis("--------D").ChainDiffs({5, 4, 3}).FrameDiffs({3, 1});
|
||||
t[0x2].S(0).T(1).Dtis("-DS-RR-RR").ChainDiffs({6, 5, 4}).FrameDiffs({6});
|
||||
t[0x7].S(1).T(1).Dtis("----DS-RR").ChainDiffs({7, 6, 5}).FrameDiffs({6, 1});
|
||||
t[0xC].S(2).T(1).Dtis("-------DS").ChainDiffs({8, 7, 6}).FrameDiffs({6, 1});
|
||||
t[0x4].S(0).T(2).Dtis("--D--R--R").ChainDiffs({9, 8, 7}).FrameDiffs({3});
|
||||
t[0x9].S(1).T(2).Dtis("-----D--R").ChainDiffs({10, 9, 8}).FrameDiffs({3, 1});
|
||||
t[0xE].S(2).T(2).Dtis("--------D").ChainDiffs({11, 10, 9}).FrameDiffs({3, 1});
|
||||
t[0x0].S(0).T(0).Dtis("SSSRRRRRR").ChainDiffs({12, 11, 10}).FrameDiffs({12});
|
||||
t[0x5].S(1).T(0).Dtis("---SSSRRR").ChainDiffs({1, 1, 1}).FrameDiffs({12, 1});
|
||||
t[0xA].S(2).T(0).Dtis("------SSS").ChainDiffs({2, 1, 1}).FrameDiffs({12, 1});
|
||||
return structure;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L3T3_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L3T3_H_
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_full_svc.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// https://aomediacodec.github.io/av1-rtp-spec/#a63-l3t3-full-svc
|
||||
class ScalabilityStructureL3T3 : public ScalabilityStructureFullSvc {
|
||||
public:
|
||||
ScalabilityStructureL3T3() : ScalabilityStructureFullSvc(3, 3) {}
|
||||
~ScalabilityStructureL3T3() override;
|
||||
|
||||
FrameDependencyStructure DependencyStructure() const override;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_L3T3_H_
|
||||
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_l3t3.h"
|
||||
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_test_helpers.h"
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
using ::testing::IsEmpty;
|
||||
using ::testing::SizeIs;
|
||||
|
||||
TEST(ScalabilityStructureL3T3Test, SkipS1T1FrameKeepsStructureValid) {
|
||||
ScalabilityStructureL3T3 structure;
|
||||
ScalabilityStructureWrapper wrapper(structure);
|
||||
|
||||
structure.OnRatesUpdated(EnableTemporalLayers(/*s0=*/3, /*s1=*/3));
|
||||
auto frames = wrapper.GenerateFrames(/*num_temporal_units=*/1);
|
||||
EXPECT_THAT(frames, SizeIs(2));
|
||||
EXPECT_EQ(frames[0].temporal_id, 0);
|
||||
|
||||
frames = wrapper.GenerateFrames(/*num_temporal_units=*/1);
|
||||
EXPECT_THAT(frames, SizeIs(2));
|
||||
EXPECT_EQ(frames[0].temporal_id, 2);
|
||||
|
||||
structure.OnRatesUpdated(EnableTemporalLayers(/*s0=*/3, /*s1=*/0));
|
||||
frames = wrapper.GenerateFrames(/*num_temporal_units=*/1);
|
||||
EXPECT_THAT(frames, SizeIs(1));
|
||||
EXPECT_EQ(frames[0].temporal_id, 1);
|
||||
|
||||
structure.OnRatesUpdated(EnableTemporalLayers(/*s0=*/3, /*s1=*/3));
|
||||
// Rely on checks inside GenerateFrames frame references are valid.
|
||||
frames = wrapper.GenerateFrames(/*num_temporal_units=*/1);
|
||||
EXPECT_THAT(frames, SizeIs(2));
|
||||
EXPECT_EQ(frames[0].temporal_id, 2);
|
||||
}
|
||||
|
||||
TEST(ScalabilityStructureL3T3Test, SwitchSpatialLayerBeforeT1Frame) {
|
||||
ScalabilityStructureL3T3 structure;
|
||||
ScalabilityStructureWrapper wrapper(structure);
|
||||
|
||||
structure.OnRatesUpdated(EnableTemporalLayers(/*s0=*/2, /*s1=*/0));
|
||||
EXPECT_THAT(wrapper.GenerateFrames(1), SizeIs(1));
|
||||
structure.OnRatesUpdated(EnableTemporalLayers(/*s0=*/0, /*s1=*/2));
|
||||
auto frames = wrapper.GenerateFrames(1);
|
||||
ASSERT_THAT(frames, SizeIs(1));
|
||||
EXPECT_THAT(frames[0].frame_diffs, IsEmpty());
|
||||
EXPECT_EQ(frames[0].temporal_id, 0);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace webrtc
|
||||
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_s2t1.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/macros.h"
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
constexpr auto kNotPresent = DecodeTargetIndication::kNotPresent;
|
||||
constexpr auto kSwitch = DecodeTargetIndication::kSwitch;
|
||||
|
||||
constexpr DecodeTargetIndication kDtis[2][2] = {
|
||||
{kSwitch, kNotPresent}, // S0
|
||||
{kNotPresent, kSwitch}, // S1
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
ScalabilityStructureS2T1::~ScalabilityStructureS2T1() = default;
|
||||
|
||||
ScalableVideoController::StreamLayersConfig
|
||||
ScalabilityStructureS2T1::StreamConfig() const {
|
||||
StreamLayersConfig result;
|
||||
result.num_spatial_layers = 2;
|
||||
result.num_temporal_layers = 1;
|
||||
result.scaling_factor_num[0] = 1;
|
||||
result.scaling_factor_den[0] = 2;
|
||||
return result;
|
||||
}
|
||||
|
||||
FrameDependencyStructure ScalabilityStructureS2T1::DependencyStructure() const {
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 2;
|
||||
structure.num_chains = 2;
|
||||
structure.decode_target_protected_by_chain = {0, 1};
|
||||
structure.templates.resize(4);
|
||||
structure.templates[0].S(0).Dtis("S-").ChainDiffs({2, 1}).FrameDiffs({2});
|
||||
structure.templates[1].S(0).Dtis("S-").ChainDiffs({0, 0});
|
||||
structure.templates[2].S(1).Dtis("-S").ChainDiffs({1, 2}).FrameDiffs({2});
|
||||
structure.templates[3].S(1).Dtis("-S").ChainDiffs({1, 0});
|
||||
return structure;
|
||||
}
|
||||
|
||||
std::vector<ScalableVideoController::LayerFrameConfig>
|
||||
ScalabilityStructureS2T1::NextFrameConfig(bool restart) {
|
||||
std::vector<LayerFrameConfig> result(2);
|
||||
// Buffer0 keeps latest S0T0 frame, Buffer1 keeps latest S1T0 frame.
|
||||
if (restart || keyframe_) {
|
||||
result[0].S(0).Keyframe().Update(0);
|
||||
result[1].S(1).Keyframe().Update(1);
|
||||
keyframe_ = false;
|
||||
} else {
|
||||
result[0].S(0).ReferenceAndUpdate(0);
|
||||
result[1].S(1).ReferenceAndUpdate(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
GenericFrameInfo ScalabilityStructureS2T1::OnEncodeDone(
|
||||
const LayerFrameConfig& config) {
|
||||
GenericFrameInfo frame_info;
|
||||
if (config.SpatialId() < 0 ||
|
||||
config.SpatialId() >= int{ABSL_ARRAYSIZE(kDtis)}) {
|
||||
RTC_LOG(LS_ERROR) << "Unexpected spatial id " << config.SpatialId();
|
||||
return frame_info;
|
||||
}
|
||||
frame_info.spatial_id = config.SpatialId();
|
||||
frame_info.temporal_id = config.TemporalId();
|
||||
frame_info.encoder_buffers = std::move(config.Buffers());
|
||||
frame_info.decode_target_indications.assign(
|
||||
std::begin(kDtis[config.SpatialId()]),
|
||||
std::end(kDtis[config.SpatialId()]));
|
||||
frame_info.part_of_chain = {config.SpatialId() == 0, config.SpatialId() == 1};
|
||||
return frame_info;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_S2T1_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_S2T1_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "common_video/generic_frame_descriptor/generic_frame_info.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// S1 0--0--0-
|
||||
// ...
|
||||
// S0 0--0--0-
|
||||
class ScalabilityStructureS2T1 : public ScalableVideoController {
|
||||
public:
|
||||
~ScalabilityStructureS2T1() override;
|
||||
|
||||
StreamLayersConfig StreamConfig() const override;
|
||||
FrameDependencyStructure DependencyStructure() const override;
|
||||
|
||||
std::vector<LayerFrameConfig> NextFrameConfig(bool restart) override;
|
||||
GenericFrameInfo OnEncodeDone(const LayerFrameConfig& config) override;
|
||||
|
||||
private:
|
||||
bool keyframe_ = true;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_S2T1_H_
|
||||
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalability_structure_test_helpers.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "api/video/video_bitrate_allocation.h"
|
||||
#include "api/video/video_frame_type.h"
|
||||
#include "modules/video_coding/chain_diff_calculator.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
#include "modules/video_coding/frame_dependencies_calculator.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
VideoBitrateAllocation EnableTemporalLayers(int s0, int s1, int s2) {
|
||||
VideoBitrateAllocation bitrate;
|
||||
for (int tid = 0; tid < s0; ++tid) {
|
||||
bitrate.SetBitrate(0, tid, 1'000'000);
|
||||
}
|
||||
for (int tid = 0; tid < s1; ++tid) {
|
||||
bitrate.SetBitrate(1, tid, 1'000'000);
|
||||
}
|
||||
for (int tid = 0; tid < s2; ++tid) {
|
||||
bitrate.SetBitrate(2, tid, 1'000'000);
|
||||
}
|
||||
return bitrate;
|
||||
}
|
||||
|
||||
std::vector<GenericFrameInfo> ScalabilityStructureWrapper::GenerateFrames(
|
||||
int num_temporal_units,
|
||||
bool restart) {
|
||||
std::vector<GenericFrameInfo> frames;
|
||||
for (int i = 0; i < num_temporal_units; ++i) {
|
||||
for (auto& layer_frame : structure_controller_.NextFrameConfig(restart)) {
|
||||
int64_t frame_id = ++frame_id_;
|
||||
bool is_keyframe = layer_frame.IsKeyframe();
|
||||
|
||||
absl::optional<GenericFrameInfo> frame_info =
|
||||
structure_controller_.OnEncodeDone(std::move(layer_frame));
|
||||
EXPECT_TRUE(frame_info.has_value());
|
||||
if (is_keyframe) {
|
||||
chain_diff_calculator_.Reset(frame_info->part_of_chain);
|
||||
}
|
||||
frame_info->chain_diffs =
|
||||
chain_diff_calculator_.From(frame_id, frame_info->part_of_chain);
|
||||
for (int64_t base_frame_id : frame_deps_calculator_.FromBuffersUsage(
|
||||
is_keyframe ? VideoFrameType::kVideoFrameKey
|
||||
: VideoFrameType::kVideoFrameDelta,
|
||||
frame_id, frame_info->encoder_buffers)) {
|
||||
EXPECT_LT(base_frame_id, frame_id);
|
||||
EXPECT_GE(base_frame_id, 0);
|
||||
frame_info->frame_diffs.push_back(frame_id - base_frame_id);
|
||||
}
|
||||
|
||||
frames.push_back(*std::move(frame_info));
|
||||
}
|
||||
restart = false;
|
||||
}
|
||||
|
||||
if (restart) {
|
||||
buffer_contains_frame_.reset();
|
||||
}
|
||||
for (const GenericFrameInfo& frame : frames) {
|
||||
for (const CodecBufferUsage& buffer_usage : frame.encoder_buffers) {
|
||||
if (buffer_usage.id < 0 || buffer_usage.id >= 8) {
|
||||
ADD_FAILURE() << "Invalid buffer id " << buffer_usage.id
|
||||
<< ". Up to 8 buffers are supported.";
|
||||
continue;
|
||||
}
|
||||
if (buffer_usage.referenced && !buffer_contains_frame_[buffer_usage.id]) {
|
||||
ADD_FAILURE() << "buffer " << buffer_usage.id
|
||||
<< " was reference before updated.";
|
||||
}
|
||||
if (buffer_usage.updated) {
|
||||
buffer_contains_frame_.set(buffer_usage.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_TEST_HELPERS_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_TEST_HELPERS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "api/video/video_bitrate_allocation.h"
|
||||
#include "common_video/generic_frame_descriptor/generic_frame_info.h"
|
||||
#include "modules/video_coding/chain_diff_calculator.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
#include "modules/video_coding/frame_dependencies_calculator.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Creates bitrate allocation with non-zero bitrate for given number of temporal
|
||||
// layers for each spatial layer.
|
||||
VideoBitrateAllocation EnableTemporalLayers(int s0, int s1 = 0, int s2 = 0);
|
||||
|
||||
class ScalabilityStructureWrapper {
|
||||
public:
|
||||
explicit ScalabilityStructureWrapper(ScalableVideoController& structure)
|
||||
: structure_controller_(structure) {}
|
||||
|
||||
std::vector<GenericFrameInfo> GenerateFrames(int num_tempral_units,
|
||||
bool restart);
|
||||
|
||||
std::vector<GenericFrameInfo> GenerateFrames(int num_temporal_units) {
|
||||
return GenerateFrames(num_temporal_units, /*restart=*/false);
|
||||
}
|
||||
|
||||
private:
|
||||
ScalableVideoController& structure_controller_;
|
||||
std::bitset<8> buffer_contains_frame_ = 0;
|
||||
FrameDependenciesCalculator frame_deps_calculator_;
|
||||
ChainDiffCalculator chain_diff_calculator_;
|
||||
int64_t frame_id_ = 0;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABILITY_STRUCTURE_TEST_HELPERS_H_
|
||||
@ -1,331 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "modules/video_coding/codecs/av1/create_scalability_structure.h"
|
||||
#include "modules/video_coding/codecs/av1/scalability_structure_test_helpers.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
using ::testing::AllOf;
|
||||
using ::testing::Contains;
|
||||
using ::testing::Each;
|
||||
using ::testing::Field;
|
||||
using ::testing::Ge;
|
||||
using ::testing::IsEmpty;
|
||||
using ::testing::Le;
|
||||
using ::testing::Lt;
|
||||
using ::testing::Not;
|
||||
using ::testing::SizeIs;
|
||||
using ::testing::TestWithParam;
|
||||
using ::testing::Values;
|
||||
|
||||
struct SvcTestParam {
|
||||
friend std::ostream& operator<<(std::ostream& os, const SvcTestParam& param) {
|
||||
return os << param.name;
|
||||
}
|
||||
|
||||
std::string name;
|
||||
int num_temporal_units;
|
||||
};
|
||||
|
||||
class ScalabilityStructureTest : public TestWithParam<SvcTestParam> {};
|
||||
|
||||
TEST_P(ScalabilityStructureTest,
|
||||
NumberOfDecodeTargetsAndChainsAreInRangeAndConsistent) {
|
||||
FrameDependencyStructure structure =
|
||||
CreateScalabilityStructure(GetParam().name)->DependencyStructure();
|
||||
EXPECT_GT(structure.num_decode_targets, 0);
|
||||
EXPECT_LE(structure.num_decode_targets,
|
||||
DependencyDescriptor::kMaxDecodeTargets);
|
||||
EXPECT_GE(structure.num_chains, 0);
|
||||
EXPECT_LE(structure.num_chains, structure.num_decode_targets);
|
||||
if (structure.num_chains == 0) {
|
||||
EXPECT_THAT(structure.decode_target_protected_by_chain, IsEmpty());
|
||||
} else {
|
||||
EXPECT_THAT(structure.decode_target_protected_by_chain,
|
||||
AllOf(SizeIs(structure.num_decode_targets), Each(Ge(0)),
|
||||
Each(Lt(structure.num_chains))));
|
||||
}
|
||||
EXPECT_THAT(structure.templates,
|
||||
SizeIs(Lt(size_t{DependencyDescriptor::kMaxTemplates})));
|
||||
}
|
||||
|
||||
TEST_P(ScalabilityStructureTest, TemplatesAreSortedByLayerId) {
|
||||
FrameDependencyStructure structure =
|
||||
CreateScalabilityStructure(GetParam().name)->DependencyStructure();
|
||||
ASSERT_THAT(structure.templates, Not(IsEmpty()));
|
||||
const auto& first_templates = structure.templates.front();
|
||||
EXPECT_EQ(first_templates.spatial_id, 0);
|
||||
EXPECT_EQ(first_templates.temporal_id, 0);
|
||||
for (size_t i = 1; i < structure.templates.size(); ++i) {
|
||||
const auto& prev_template = structure.templates[i - 1];
|
||||
const auto& next_template = structure.templates[i];
|
||||
if (next_template.spatial_id == prev_template.spatial_id &&
|
||||
next_template.temporal_id == prev_template.temporal_id) {
|
||||
// Same layer, next_layer_idc == 0
|
||||
} else if (next_template.spatial_id == prev_template.spatial_id &&
|
||||
next_template.temporal_id == prev_template.temporal_id + 1) {
|
||||
// Next temporal layer, next_layer_idc == 1
|
||||
} else if (next_template.spatial_id == prev_template.spatial_id + 1 &&
|
||||
next_template.temporal_id == 0) {
|
||||
// Next spatial layer, next_layer_idc == 2
|
||||
} else {
|
||||
// everything else is invalid.
|
||||
ADD_FAILURE() << "Invalid templates order. Template #" << i
|
||||
<< " with layer (" << next_template.spatial_id << ","
|
||||
<< next_template.temporal_id
|
||||
<< ") follows template with layer ("
|
||||
<< prev_template.spatial_id << ","
|
||||
<< prev_template.temporal_id << ").";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ScalabilityStructureTest, TemplatesMatchNumberOfDecodeTargetsAndChains) {
|
||||
FrameDependencyStructure structure =
|
||||
CreateScalabilityStructure(GetParam().name)->DependencyStructure();
|
||||
EXPECT_THAT(
|
||||
structure.templates,
|
||||
Each(AllOf(Field(&FrameDependencyTemplate::decode_target_indications,
|
||||
SizeIs(structure.num_decode_targets)),
|
||||
Field(&FrameDependencyTemplate::chain_diffs,
|
||||
SizeIs(structure.num_chains)))));
|
||||
}
|
||||
|
||||
TEST_P(ScalabilityStructureTest, FrameInfoMatchesFrameDependencyStructure) {
|
||||
std::unique_ptr<ScalableVideoController> svc_controller =
|
||||
CreateScalabilityStructure(GetParam().name);
|
||||
FrameDependencyStructure structure = svc_controller->DependencyStructure();
|
||||
std::vector<GenericFrameInfo> frame_infos =
|
||||
ScalabilityStructureWrapper(*svc_controller)
|
||||
.GenerateFrames(GetParam().num_temporal_units);
|
||||
for (size_t frame_id = 0; frame_id < frame_infos.size(); ++frame_id) {
|
||||
const auto& frame = frame_infos[frame_id];
|
||||
EXPECT_GE(frame.spatial_id, 0) << " for frame " << frame_id;
|
||||
EXPECT_GE(frame.temporal_id, 0) << " for frame " << frame_id;
|
||||
EXPECT_THAT(frame.decode_target_indications,
|
||||
SizeIs(structure.num_decode_targets))
|
||||
<< " for frame " << frame_id;
|
||||
EXPECT_THAT(frame.part_of_chain, SizeIs(structure.num_chains))
|
||||
<< " for frame " << frame_id;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ScalabilityStructureTest, ThereIsAPerfectTemplateForEachFrame) {
|
||||
std::unique_ptr<ScalableVideoController> svc_controller =
|
||||
CreateScalabilityStructure(GetParam().name);
|
||||
FrameDependencyStructure structure = svc_controller->DependencyStructure();
|
||||
std::vector<GenericFrameInfo> frame_infos =
|
||||
ScalabilityStructureWrapper(*svc_controller)
|
||||
.GenerateFrames(GetParam().num_temporal_units);
|
||||
for (size_t frame_id = 0; frame_id < frame_infos.size(); ++frame_id) {
|
||||
EXPECT_THAT(structure.templates, Contains(frame_infos[frame_id]))
|
||||
<< " for frame " << frame_id;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ScalabilityStructureTest, FrameDependsOnSameOrLowerLayer) {
|
||||
std::unique_ptr<ScalableVideoController> svc_controller =
|
||||
CreateScalabilityStructure(GetParam().name);
|
||||
std::vector<GenericFrameInfo> frame_infos =
|
||||
ScalabilityStructureWrapper(*svc_controller)
|
||||
.GenerateFrames(GetParam().num_temporal_units);
|
||||
int64_t num_frames = frame_infos.size();
|
||||
|
||||
for (int64_t frame_id = 0; frame_id < num_frames; ++frame_id) {
|
||||
const auto& frame = frame_infos[frame_id];
|
||||
for (int frame_diff : frame.frame_diffs) {
|
||||
int64_t base_frame_id = frame_id - frame_diff;
|
||||
const auto& base_frame = frame_infos[base_frame_id];
|
||||
EXPECT_GE(frame.spatial_id, base_frame.spatial_id)
|
||||
<< "Frame " << frame_id << " depends on frame " << base_frame_id;
|
||||
EXPECT_GE(frame.temporal_id, base_frame.temporal_id)
|
||||
<< "Frame " << frame_id << " depends on frame " << base_frame_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ScalabilityStructureTest, NoFrameDependsOnDiscardableOrNotPresent) {
|
||||
std::unique_ptr<ScalableVideoController> svc_controller =
|
||||
CreateScalabilityStructure(GetParam().name);
|
||||
std::vector<GenericFrameInfo> frame_infos =
|
||||
ScalabilityStructureWrapper(*svc_controller)
|
||||
.GenerateFrames(GetParam().num_temporal_units);
|
||||
int64_t num_frames = frame_infos.size();
|
||||
FrameDependencyStructure structure = svc_controller->DependencyStructure();
|
||||
|
||||
for (int dt = 0; dt < structure.num_decode_targets; ++dt) {
|
||||
for (int64_t frame_id = 0; frame_id < num_frames; ++frame_id) {
|
||||
const auto& frame = frame_infos[frame_id];
|
||||
if (frame.decode_target_indications[dt] ==
|
||||
DecodeTargetIndication::kNotPresent) {
|
||||
continue;
|
||||
}
|
||||
for (int frame_diff : frame.frame_diffs) {
|
||||
int64_t base_frame_id = frame_id - frame_diff;
|
||||
const auto& base_frame = frame_infos[base_frame_id];
|
||||
EXPECT_NE(base_frame.decode_target_indications[dt],
|
||||
DecodeTargetIndication::kNotPresent)
|
||||
<< "Frame " << frame_id << " depends on frame " << base_frame_id
|
||||
<< " that is not part of decode target#" << dt;
|
||||
EXPECT_NE(base_frame.decode_target_indications[dt],
|
||||
DecodeTargetIndication::kDiscardable)
|
||||
<< "Frame " << frame_id << " depends on frame " << base_frame_id
|
||||
<< " that is discardable for decode target#" << dt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ScalabilityStructureTest, NoFrameDependsThroughSwitchIndication) {
|
||||
std::unique_ptr<ScalableVideoController> svc_controller =
|
||||
CreateScalabilityStructure(GetParam().name);
|
||||
FrameDependencyStructure structure = svc_controller->DependencyStructure();
|
||||
std::vector<GenericFrameInfo> frame_infos =
|
||||
ScalabilityStructureWrapper(*svc_controller)
|
||||
.GenerateFrames(GetParam().num_temporal_units);
|
||||
int64_t num_frames = frame_infos.size();
|
||||
std::vector<std::set<int64_t>> full_deps(num_frames);
|
||||
|
||||
// For each frame calculate set of all frames it depends on, both directly and
|
||||
// indirectly.
|
||||
for (int64_t frame_id = 0; frame_id < num_frames; ++frame_id) {
|
||||
std::set<int64_t> all_base_frames;
|
||||
for (int frame_diff : frame_infos[frame_id].frame_diffs) {
|
||||
int64_t base_frame_id = frame_id - frame_diff;
|
||||
all_base_frames.insert(base_frame_id);
|
||||
const auto& indirect = full_deps[base_frame_id];
|
||||
all_base_frames.insert(indirect.begin(), indirect.end());
|
||||
}
|
||||
full_deps[frame_id] = std::move(all_base_frames);
|
||||
}
|
||||
|
||||
// Now check the switch indication: frames after the switch indication mustn't
|
||||
// depend on any addition frames before the switch indications.
|
||||
for (int dt = 0; dt < structure.num_decode_targets; ++dt) {
|
||||
for (int64_t switch_frame_id = 0; switch_frame_id < num_frames;
|
||||
++switch_frame_id) {
|
||||
if (frame_infos[switch_frame_id].decode_target_indications[dt] !=
|
||||
DecodeTargetIndication::kSwitch) {
|
||||
continue;
|
||||
}
|
||||
for (int64_t later_frame_id = switch_frame_id + 1;
|
||||
later_frame_id < num_frames; ++later_frame_id) {
|
||||
if (frame_infos[later_frame_id].decode_target_indications[dt] ==
|
||||
DecodeTargetIndication::kNotPresent) {
|
||||
continue;
|
||||
}
|
||||
for (int frame_diff : frame_infos[later_frame_id].frame_diffs) {
|
||||
int64_t early_frame_id = later_frame_id - frame_diff;
|
||||
if (early_frame_id < switch_frame_id) {
|
||||
EXPECT_THAT(full_deps[switch_frame_id], Contains(early_frame_id))
|
||||
<< "For decode target #" << dt << " frame " << later_frame_id
|
||||
<< " depends on the frame " << early_frame_id
|
||||
<< " that switch indication frame " << switch_frame_id
|
||||
<< " doesn't directly on indirectly depend on.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(danilchap): Merge with ScalabilityStructureTest when SetRates
|
||||
// implemented for all tested structures.
|
||||
class ScalabilityStructureSetRatesTest : public ScalabilityStructureTest {};
|
||||
|
||||
TEST_P(ScalabilityStructureSetRatesTest, ProduceNoFrameForDisabledLayers) {
|
||||
std::unique_ptr<ScalableVideoController> svc_controller =
|
||||
CreateScalabilityStructure(GetParam().name);
|
||||
ScalableVideoController::StreamLayersConfig structure =
|
||||
svc_controller->StreamConfig();
|
||||
|
||||
VideoBitrateAllocation all_bitrates;
|
||||
for (int sid = 0; sid < structure.num_spatial_layers; ++sid) {
|
||||
for (int tid = 0; tid < structure.num_temporal_layers; ++tid) {
|
||||
all_bitrates.SetBitrate(sid, tid, 100'000);
|
||||
}
|
||||
}
|
||||
|
||||
svc_controller->OnRatesUpdated(all_bitrates);
|
||||
ScalabilityStructureWrapper wrapper(*svc_controller);
|
||||
std::vector<GenericFrameInfo> frames =
|
||||
wrapper.GenerateFrames(GetParam().num_temporal_units);
|
||||
|
||||
for (int sid = 0; sid < structure.num_spatial_layers; ++sid) {
|
||||
for (int tid = 0; tid < structure.num_temporal_layers; ++tid) {
|
||||
// When all layers were enabled, expect there was a frame for each layer.
|
||||
EXPECT_THAT(frames,
|
||||
Contains(AllOf(Field(&GenericFrameInfo::spatial_id, sid),
|
||||
Field(&GenericFrameInfo::temporal_id, tid))))
|
||||
<< "For layer (" << sid << "," << tid << ")";
|
||||
// Restore bitrates for all layers before disabling single layer.
|
||||
VideoBitrateAllocation bitrates = all_bitrates;
|
||||
bitrates.SetBitrate(sid, tid, 0);
|
||||
svc_controller->OnRatesUpdated(bitrates);
|
||||
// With layer (sid, tid) disabled, expect no frames are produced for it.
|
||||
EXPECT_THAT(
|
||||
wrapper.GenerateFrames(GetParam().num_temporal_units),
|
||||
Not(Contains(AllOf(Field(&GenericFrameInfo::spatial_id, sid),
|
||||
Field(&GenericFrameInfo::temporal_id, tid)))))
|
||||
<< "For layer (" << sid << "," << tid << ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
Svc,
|
||||
ScalabilityStructureTest,
|
||||
Values(SvcTestParam{"L1T2", /*num_temporal_units=*/4},
|
||||
SvcTestParam{"L1T3", /*num_temporal_units=*/8},
|
||||
SvcTestParam{"L2T1", /*num_temporal_units=*/3},
|
||||
SvcTestParam{"L2T1_KEY", /*num_temporal_units=*/3},
|
||||
SvcTestParam{"L3T1", /*num_temporal_units=*/3},
|
||||
SvcTestParam{"L3T3", /*num_temporal_units=*/8},
|
||||
SvcTestParam{"S2T1", /*num_temporal_units=*/3},
|
||||
SvcTestParam{"L2T2", /*num_temporal_units=*/4},
|
||||
SvcTestParam{"L2T2_KEY", /*num_temporal_units=*/4},
|
||||
SvcTestParam{"L2T2_KEY_SHIFT", /*num_temporal_units=*/4}),
|
||||
[](const testing::TestParamInfo<SvcTestParam>& info) {
|
||||
return info.param.name;
|
||||
});
|
||||
|
||||
// TODO(danilchap): Merge with ScalabilityStructureTest when the functionality
|
||||
// is implemented for all tested structures.
|
||||
INSTANTIATE_TEST_SUITE_P(Svc,
|
||||
ScalabilityStructureSetRatesTest,
|
||||
Values(SvcTestParam{"L1T2",
|
||||
/*num_temporal_units=*/4},
|
||||
SvcTestParam{"L1T3", /*num_temporal_units=*/8},
|
||||
SvcTestParam{"L2T1",
|
||||
/*num_temporal_units=*/3},
|
||||
SvcTestParam{"L2T2",
|
||||
/*num_temporal_units=*/4},
|
||||
SvcTestParam{"L3T1", /*num_temporal_units=*/3},
|
||||
SvcTestParam{"L3T3", /*num_temporal_units=*/8}),
|
||||
[](const testing::TestParamInfo<SvcTestParam>& info) {
|
||||
return info.param.name;
|
||||
});
|
||||
|
||||
} // namespace
|
||||
} // namespace webrtc
|
||||
@ -1,139 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABLE_VIDEO_CONTROLLER_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABLE_VIDEO_CONTROLLER_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "absl/container/inlined_vector.h"
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "api/video/video_bitrate_allocation.h"
|
||||
#include "common_video/generic_frame_descriptor/generic_frame_info.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Controls how video should be encoded to be scalable. Outputs results as
|
||||
// buffer usage configuration for encoder and enough details to communicate the
|
||||
// scalability structure via dependency descriptor rtp header extension.
|
||||
class ScalableVideoController {
|
||||
public:
|
||||
struct StreamLayersConfig {
|
||||
int num_spatial_layers = 1;
|
||||
int num_temporal_layers = 1;
|
||||
// Spatial layers scaling. Frames with spatial_id = i expected to be encoded
|
||||
// with original_resolution * scaling_factor_num[i] / scaling_factor_den[i].
|
||||
int scaling_factor_num[DependencyDescriptor::kMaxSpatialIds] = {1, 1, 1, 1};
|
||||
int scaling_factor_den[DependencyDescriptor::kMaxSpatialIds] = {1, 1, 1, 1};
|
||||
};
|
||||
class LayerFrameConfig {
|
||||
public:
|
||||
// Builders/setters.
|
||||
LayerFrameConfig& Id(int value);
|
||||
LayerFrameConfig& Keyframe();
|
||||
LayerFrameConfig& S(int value);
|
||||
LayerFrameConfig& T(int value);
|
||||
LayerFrameConfig& Reference(int buffer_id);
|
||||
LayerFrameConfig& Update(int buffer_id);
|
||||
LayerFrameConfig& ReferenceAndUpdate(int buffer_id);
|
||||
|
||||
// Getters.
|
||||
int Id() const { return id_; }
|
||||
bool IsKeyframe() const { return is_keyframe_; }
|
||||
int SpatialId() const { return spatial_id_; }
|
||||
int TemporalId() const { return temporal_id_; }
|
||||
const absl::InlinedVector<CodecBufferUsage, kMaxEncoderBuffers>& Buffers()
|
||||
const {
|
||||
return buffers_;
|
||||
}
|
||||
|
||||
private:
|
||||
// Id to match configuration returned by NextFrameConfig with
|
||||
// (possibly modified) configuration passed back via OnEncoderDone.
|
||||
// The meaning of the id is an implementation detail of
|
||||
// the ScalableVideoController.
|
||||
int id_ = 0;
|
||||
|
||||
// Indication frame should be encoded as a key frame. In particular when
|
||||
// `is_keyframe=true` property `CodecBufferUsage::referenced` should be
|
||||
// ignored and treated as false.
|
||||
bool is_keyframe_ = false;
|
||||
|
||||
int spatial_id_ = 0;
|
||||
int temporal_id_ = 0;
|
||||
// Describes how encoder which buffers encoder allowed to reference and
|
||||
// which buffers encoder should update.
|
||||
absl::InlinedVector<CodecBufferUsage, kMaxEncoderBuffers> buffers_;
|
||||
};
|
||||
|
||||
virtual ~ScalableVideoController() = default;
|
||||
|
||||
// Returns video structure description for encoder to configure itself.
|
||||
virtual StreamLayersConfig StreamConfig() const = 0;
|
||||
|
||||
// Returns video structure description in format compatible with
|
||||
// dependency descriptor rtp header extension.
|
||||
virtual FrameDependencyStructure DependencyStructure() const = 0;
|
||||
|
||||
// Notifies Controller with updated bitrates per layer. In particular notifies
|
||||
// when certain layers should be disabled.
|
||||
// Controller shouldn't produce LayerFrameConfig for disabled layers.
|
||||
// TODO(bugs.webrtc.org/11404): Make pure virtual when implemented by all
|
||||
// structures.
|
||||
virtual void OnRatesUpdated(const VideoBitrateAllocation& bitrates) {}
|
||||
|
||||
// When `restart` is true, first `LayerFrameConfig` should have `is_keyframe`
|
||||
// set to true.
|
||||
// Returned vector shouldn't be empty.
|
||||
virtual std::vector<LayerFrameConfig> NextFrameConfig(bool restart) = 0;
|
||||
|
||||
// Returns configuration to pass to EncoderCallback.
|
||||
virtual GenericFrameInfo OnEncodeDone(const LayerFrameConfig& config) = 0;
|
||||
};
|
||||
|
||||
// Below are implementation details.
|
||||
inline ScalableVideoController::LayerFrameConfig&
|
||||
ScalableVideoController::LayerFrameConfig::Id(int value) {
|
||||
id_ = value;
|
||||
return *this;
|
||||
}
|
||||
inline ScalableVideoController::LayerFrameConfig&
|
||||
ScalableVideoController::LayerFrameConfig::Keyframe() {
|
||||
is_keyframe_ = true;
|
||||
return *this;
|
||||
}
|
||||
inline ScalableVideoController::LayerFrameConfig&
|
||||
ScalableVideoController::LayerFrameConfig::S(int value) {
|
||||
spatial_id_ = value;
|
||||
return *this;
|
||||
}
|
||||
inline ScalableVideoController::LayerFrameConfig&
|
||||
ScalableVideoController::LayerFrameConfig::T(int value) {
|
||||
temporal_id_ = value;
|
||||
return *this;
|
||||
}
|
||||
inline ScalableVideoController::LayerFrameConfig&
|
||||
ScalableVideoController::LayerFrameConfig::Reference(int buffer_id) {
|
||||
buffers_.emplace_back(buffer_id, /*referenced=*/true, /*updated=*/false);
|
||||
return *this;
|
||||
}
|
||||
inline ScalableVideoController::LayerFrameConfig&
|
||||
ScalableVideoController::LayerFrameConfig::Update(int buffer_id) {
|
||||
buffers_.emplace_back(buffer_id, /*referenced=*/false, /*updated=*/true);
|
||||
return *this;
|
||||
}
|
||||
inline ScalableVideoController::LayerFrameConfig&
|
||||
ScalableVideoController::LayerFrameConfig::ReferenceAndUpdate(int buffer_id) {
|
||||
buffers_.emplace_back(buffer_id, /*referenced=*/true, /*updated=*/true);
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABLE_VIDEO_CONTROLLER_H_
|
||||
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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 "modules/video_coding/codecs/av1/scalable_video_controller_no_layering.h"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
ScalableVideoControllerNoLayering::~ScalableVideoControllerNoLayering() =
|
||||
default;
|
||||
|
||||
ScalableVideoController::StreamLayersConfig
|
||||
ScalableVideoControllerNoLayering::StreamConfig() const {
|
||||
StreamLayersConfig result;
|
||||
result.num_spatial_layers = 1;
|
||||
result.num_temporal_layers = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
FrameDependencyStructure
|
||||
ScalableVideoControllerNoLayering::DependencyStructure() const {
|
||||
FrameDependencyStructure structure;
|
||||
structure.num_decode_targets = 1;
|
||||
FrameDependencyTemplate a_template;
|
||||
a_template.decode_target_indications = {DecodeTargetIndication::kSwitch};
|
||||
structure.templates.push_back(a_template);
|
||||
return structure;
|
||||
}
|
||||
|
||||
std::vector<ScalableVideoController::LayerFrameConfig>
|
||||
ScalableVideoControllerNoLayering::NextFrameConfig(bool restart) {
|
||||
std::vector<LayerFrameConfig> result(1);
|
||||
if (restart || start_) {
|
||||
result[0].Id(0).Keyframe().Update(0);
|
||||
} else {
|
||||
result[0].Id(0).ReferenceAndUpdate(0);
|
||||
}
|
||||
start_ = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
GenericFrameInfo ScalableVideoControllerNoLayering::OnEncodeDone(
|
||||
const LayerFrameConfig& config) {
|
||||
RTC_DCHECK_EQ(config.Id(), 0);
|
||||
GenericFrameInfo frame_info;
|
||||
frame_info.encoder_buffers = config.Buffers();
|
||||
if (config.IsKeyframe()) {
|
||||
for (auto& buffer : frame_info.encoder_buffers) {
|
||||
buffer.referenced = false;
|
||||
}
|
||||
}
|
||||
frame_info.decode_target_indications = {DecodeTargetIndication::kSwitch};
|
||||
return frame_info;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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.
|
||||
*/
|
||||
#ifndef MODULES_VIDEO_CODING_CODECS_AV1_SCALABLE_VIDEO_CONTROLLER_NO_LAYERING_H_
|
||||
#define MODULES_VIDEO_CODING_CODECS_AV1_SCALABLE_VIDEO_CONTROLLER_NO_LAYERING_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "api/transport/rtp/dependency_descriptor.h"
|
||||
#include "common_video/generic_frame_descriptor/generic_frame_info.h"
|
||||
#include "modules/video_coding/codecs/av1/scalable_video_controller.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class ScalableVideoControllerNoLayering : public ScalableVideoController {
|
||||
public:
|
||||
~ScalableVideoControllerNoLayering() override;
|
||||
|
||||
StreamLayersConfig StreamConfig() const override;
|
||||
FrameDependencyStructure DependencyStructure() const override;
|
||||
|
||||
std::vector<LayerFrameConfig> NextFrameConfig(bool restart) override;
|
||||
GenericFrameInfo OnEncodeDone(const LayerFrameConfig& config) override;
|
||||
|
||||
private:
|
||||
bool start_ = true;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_VIDEO_CODING_CODECS_AV1_SCALABLE_VIDEO_CONTROLLER_NO_LAYERING_H_
|
||||
Reference in New Issue
Block a user