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/codecs/av1/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   return result;
29 }
30 
31 FrameDependencyStructure
DependencyStructure() const32 ScalableVideoControllerNoLayering::DependencyStructure() const {
33   FrameDependencyStructure structure;
34   structure.num_decode_targets = 1;
35   FrameDependencyTemplate a_template;
36   a_template.decode_target_indications = {DecodeTargetIndication::kSwitch};
37   structure.templates.push_back(a_template);
38   return structure;
39 }
40 
41 std::vector<ScalableVideoController::LayerFrameConfig>
NextFrameConfig(bool restart)42 ScalableVideoControllerNoLayering::NextFrameConfig(bool restart) {
43   std::vector<LayerFrameConfig> result(1);
44   if (restart || start_) {
45     result[0].Id(0).Keyframe().Update(0);
46   } else {
47     result[0].Id(0).ReferenceAndUpdate(0);
48   }
49   start_ = false;
50   return result;
51 }
52 
53 absl::optional<GenericFrameInfo>
OnEncodeDone(LayerFrameConfig config)54 ScalableVideoControllerNoLayering::OnEncodeDone(LayerFrameConfig config) {
55   RTC_DCHECK_EQ(config.Id(), 0);
56   absl::optional<GenericFrameInfo> frame_info(absl::in_place);
57   frame_info->encoder_buffers = config.Buffers();
58   if (config.IsKeyframe()) {
59     for (auto& buffer : frame_info->encoder_buffers) {
60       buffer.referenced = false;
61     }
62   }
63   frame_info->decode_target_indications = {DecodeTargetIndication::kSwitch};
64   return frame_info;
65 }
66 
67 }  // namespace webrtc
68