xref: /aosp_15_r20/external/webrtc/modules/video_coding/svc/scalable_video_controller_no_layering.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 #include "modules/video_coding/svc/scalable_video_controller_no_layering.h"
11 
12 #include <utility>
13 #include <vector>
14 
15 #include "api/transport/rtp/dependency_descriptor.h"
16 #include "rtc_base/checks.h"
17 
18 namespace webrtc {
19 
20 ScalableVideoControllerNoLayering::~ScalableVideoControllerNoLayering() =
21     default;
22 
23 ScalableVideoController::StreamLayersConfig
StreamConfig() const24 ScalableVideoControllerNoLayering::StreamConfig() const {
25   StreamLayersConfig result;
26   result.num_spatial_layers = 1;
27   result.num_temporal_layers = 1;
28   result.uses_reference_scaling = false;
29   return result;
30 }
31 
32 FrameDependencyStructure
DependencyStructure() const33 ScalableVideoControllerNoLayering::DependencyStructure() const {
34   FrameDependencyStructure structure;
35   structure.num_decode_targets = 1;
36   structure.num_chains = 1;
37   structure.decode_target_protected_by_chain = {0};
38 
39   FrameDependencyTemplate key_frame;
40   key_frame.decode_target_indications = {DecodeTargetIndication::kSwitch};
41   key_frame.chain_diffs = {0};
42   structure.templates.push_back(key_frame);
43 
44   FrameDependencyTemplate delta_frame;
45   delta_frame.decode_target_indications = {DecodeTargetIndication::kSwitch};
46   delta_frame.chain_diffs = {1};
47   delta_frame.frame_diffs = {1};
48   structure.templates.push_back(delta_frame);
49 
50   return structure;
51 }
52 
53 std::vector<ScalableVideoController::LayerFrameConfig>
NextFrameConfig(bool restart)54 ScalableVideoControllerNoLayering::NextFrameConfig(bool restart) {
55   if (!enabled_) {
56     return {};
57   }
58   std::vector<LayerFrameConfig> result(1);
59   if (restart || start_) {
60     result[0].Id(0).Keyframe().Update(0);
61   } else {
62     result[0].Id(0).ReferenceAndUpdate(0);
63   }
64   start_ = false;
65   return result;
66 }
67 
OnEncodeDone(const LayerFrameConfig & config)68 GenericFrameInfo ScalableVideoControllerNoLayering::OnEncodeDone(
69     const LayerFrameConfig& config) {
70   RTC_DCHECK_EQ(config.Id(), 0);
71   GenericFrameInfo frame_info;
72   frame_info.encoder_buffers = config.Buffers();
73   if (config.IsKeyframe()) {
74     for (auto& buffer : frame_info.encoder_buffers) {
75       buffer.referenced = false;
76     }
77   }
78   frame_info.decode_target_indications = {DecodeTargetIndication::kSwitch};
79   frame_info.part_of_chain = {true};
80   return frame_info;
81 }
82 
OnRatesUpdated(const VideoBitrateAllocation & bitrates)83 void ScalableVideoControllerNoLayering::OnRatesUpdated(
84     const VideoBitrateAllocation& bitrates) {
85   enabled_ = bitrates.GetBitrate(0, 0) > 0;
86 }
87 
88 }  // namespace webrtc
89