1 /*
2 * Copyright (c) 2019 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
11 #include "api/video_codecs/vp8_temporal_layers.h"
12
13 #include <utility>
14
15 #include "absl/algorithm/container.h"
16 #include "rtc_base/checks.h"
17
18 namespace webrtc {
19
Vp8TemporalLayers(std::vector<std::unique_ptr<Vp8FrameBufferController>> && controllers,FecControllerOverride * fec_controller_override)20 Vp8TemporalLayers::Vp8TemporalLayers(
21 std::vector<std::unique_ptr<Vp8FrameBufferController>>&& controllers,
22 FecControllerOverride* fec_controller_override)
23 : controllers_(std::move(controllers)) {
24 RTC_DCHECK(!controllers_.empty());
25 RTC_DCHECK(absl::c_none_of(
26 controllers_,
27 [](const std::unique_ptr<Vp8FrameBufferController>& controller) {
28 return controller.get() == nullptr;
29 }));
30 if (fec_controller_override) {
31 fec_controller_override->SetFecAllowed(true);
32 }
33 }
34
SetQpLimits(size_t stream_index,int min_qp,int max_qp)35 void Vp8TemporalLayers::SetQpLimits(size_t stream_index,
36 int min_qp,
37 int max_qp) {
38 RTC_DCHECK_LT(stream_index, controllers_.size());
39 return controllers_[stream_index]->SetQpLimits(0, min_qp, max_qp);
40 }
41
StreamCount() const42 size_t Vp8TemporalLayers::StreamCount() const {
43 return controllers_.size();
44 }
45
SupportsEncoderFrameDropping(size_t stream_index) const46 bool Vp8TemporalLayers::SupportsEncoderFrameDropping(
47 size_t stream_index) const {
48 RTC_DCHECK_LT(stream_index, controllers_.size());
49 return controllers_[stream_index]->SupportsEncoderFrameDropping(0);
50 }
51
OnRatesUpdated(size_t stream_index,const std::vector<uint32_t> & bitrates_bps,int framerate_fps)52 void Vp8TemporalLayers::OnRatesUpdated(
53 size_t stream_index,
54 const std::vector<uint32_t>& bitrates_bps,
55 int framerate_fps) {
56 RTC_DCHECK_LT(stream_index, controllers_.size());
57 return controllers_[stream_index]->OnRatesUpdated(0, bitrates_bps,
58 framerate_fps);
59 }
60
UpdateConfiguration(size_t stream_index)61 Vp8EncoderConfig Vp8TemporalLayers::UpdateConfiguration(size_t stream_index) {
62 RTC_DCHECK_LT(stream_index, controllers_.size());
63 return controllers_[stream_index]->UpdateConfiguration(0);
64 }
65
NextFrameConfig(size_t stream_index,uint32_t rtp_timestamp)66 Vp8FrameConfig Vp8TemporalLayers::NextFrameConfig(size_t stream_index,
67 uint32_t rtp_timestamp) {
68 RTC_DCHECK_LT(stream_index, controllers_.size());
69 return controllers_[stream_index]->NextFrameConfig(0, rtp_timestamp);
70 }
71
OnEncodeDone(size_t stream_index,uint32_t rtp_timestamp,size_t size_bytes,bool is_keyframe,int qp,CodecSpecificInfo * info)72 void Vp8TemporalLayers::OnEncodeDone(size_t stream_index,
73 uint32_t rtp_timestamp,
74 size_t size_bytes,
75 bool is_keyframe,
76 int qp,
77 CodecSpecificInfo* info) {
78 RTC_DCHECK_LT(stream_index, controllers_.size());
79 return controllers_[stream_index]->OnEncodeDone(0, rtp_timestamp, size_bytes,
80 is_keyframe, qp, info);
81 }
82
OnFrameDropped(size_t stream_index,uint32_t rtp_timestamp)83 void Vp8TemporalLayers::OnFrameDropped(size_t stream_index,
84 uint32_t rtp_timestamp) {
85 RTC_DCHECK_LT(stream_index, controllers_.size());
86 controllers_[stream_index]->OnFrameDropped(stream_index, rtp_timestamp);
87 }
88
OnPacketLossRateUpdate(float packet_loss_rate)89 void Vp8TemporalLayers::OnPacketLossRateUpdate(float packet_loss_rate) {
90 for (auto& controller : controllers_) {
91 controller->OnPacketLossRateUpdate(packet_loss_rate);
92 }
93 }
94
OnRttUpdate(int64_t rtt_ms)95 void Vp8TemporalLayers::OnRttUpdate(int64_t rtt_ms) {
96 for (auto& controller : controllers_) {
97 controller->OnRttUpdate(rtt_ms);
98 }
99 }
100
OnLossNotification(const VideoEncoder::LossNotification & loss_notification)101 void Vp8TemporalLayers::OnLossNotification(
102 const VideoEncoder::LossNotification& loss_notification) {
103 for (auto& controller : controllers_) {
104 controller->OnLossNotification(loss_notification);
105 }
106 }
107
108 } // namespace webrtc
109