blob: b29cf654746abbb0d9e17db6c66d6d093545ea0b [file] [log] [blame]
Elad Aloncde8ab22019-03-20 11:56:20 +01001/*
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
Steve Antona59dcc32019-03-25 13:53:07 -070015#include "absl/algorithm/container.h"
Elad Aloncde8ab22019-03-20 11:56:20 +010016#include "rtc_base/checks.h"
17
18namespace webrtc {
19
20Vp8TemporalLayers::Vp8TemporalLayers(
21 std::vector<std::unique_ptr<Vp8FrameBufferController>>&& controllers)
22 : controllers_(std::move(controllers)) {
23 RTC_DCHECK(!controllers_.empty());
Steve Antona59dcc32019-03-25 13:53:07 -070024 RTC_DCHECK(absl::c_none_of(
25 controllers_,
Elad Aloncde8ab22019-03-20 11:56:20 +010026 [](const std::unique_ptr<Vp8FrameBufferController>& controller) {
27 return controller.get() == nullptr;
28 }));
29}
30
Elad Alonfb087812019-05-02 23:25:34 +020031void Vp8TemporalLayers::SetQpLimits(size_t stream_index,
32 int min_qp,
33 int max_qp) {
34 RTC_DCHECK_LT(stream_index, controllers_.size());
35 return controllers_[stream_index]->SetQpLimits(0, min_qp, max_qp);
36}
37
Elad Alon7e00c672019-06-28 18:12:15 +020038void Vp8TemporalLayers::SetFecControllerOverride(
39 FecControllerOverride* fec_controller_override) {
40 // Ignore.
41}
42
Elad Aloncde8ab22019-03-20 11:56:20 +010043size_t Vp8TemporalLayers::StreamCount() const {
44 return controllers_.size();
45}
46
47bool Vp8TemporalLayers::SupportsEncoderFrameDropping(
48 size_t stream_index) const {
49 RTC_DCHECK_LT(stream_index, controllers_.size());
50 return controllers_[stream_index]->SupportsEncoderFrameDropping(0);
51}
52
53void Vp8TemporalLayers::OnRatesUpdated(
54 size_t stream_index,
55 const std::vector<uint32_t>& bitrates_bps,
56 int framerate_fps) {
57 RTC_DCHECK_LT(stream_index, controllers_.size());
58 return controllers_[stream_index]->OnRatesUpdated(0, bitrates_bps,
59 framerate_fps);
60}
61
Elad Alonfb087812019-05-02 23:25:34 +020062Vp8EncoderConfig Vp8TemporalLayers::UpdateConfiguration(size_t stream_index) {
Elad Aloncde8ab22019-03-20 11:56:20 +010063 RTC_DCHECK_LT(stream_index, controllers_.size());
Elad Alonfb087812019-05-02 23:25:34 +020064 return controllers_[stream_index]->UpdateConfiguration(0);
Elad Aloncde8ab22019-03-20 11:56:20 +010065}
66
Elad Alon979c4422019-04-17 12:53:08 +020067Vp8FrameConfig Vp8TemporalLayers::NextFrameConfig(size_t stream_index,
68 uint32_t rtp_timestamp) {
Elad Aloncde8ab22019-03-20 11:56:20 +010069 RTC_DCHECK_LT(stream_index, controllers_.size());
Elad Alon979c4422019-04-17 12:53:08 +020070 return controllers_[stream_index]->NextFrameConfig(0, rtp_timestamp);
Elad Aloncde8ab22019-03-20 11:56:20 +010071}
72
73void Vp8TemporalLayers::OnEncodeDone(size_t stream_index,
74 uint32_t rtp_timestamp,
75 size_t size_bytes,
76 bool is_keyframe,
77 int qp,
78 CodecSpecificInfo* info) {
79 RTC_DCHECK_LT(stream_index, controllers_.size());
80 return controllers_[stream_index]->OnEncodeDone(0, rtp_timestamp, size_bytes,
81 is_keyframe, qp, info);
82}
83
Elad Alon6796ec22019-04-15 10:07:50 +020084void Vp8TemporalLayers::OnFrameDropped(size_t stream_index,
85 uint32_t rtp_timestamp) {
86 RTC_DCHECK_LT(stream_index, controllers_.size());
87 controllers_[stream_index]->OnFrameDropped(stream_index, rtp_timestamp);
88}
89
Elad Aloncde8ab22019-03-20 11:56:20 +010090void Vp8TemporalLayers::OnPacketLossRateUpdate(float packet_loss_rate) {
91 for (auto& controller : controllers_) {
92 controller->OnPacketLossRateUpdate(packet_loss_rate);
93 }
94}
95
96void Vp8TemporalLayers::OnRttUpdate(int64_t rtt_ms) {
97 for (auto& controller : controllers_) {
98 controller->OnRttUpdate(rtt_ms);
99 }
100}
101
Elad Alon6c371ca2019-04-04 12:28:51 +0200102void Vp8TemporalLayers::OnLossNotification(
Elad Alon123ee9b2019-04-17 12:48:06 +0200103 const VideoEncoder::LossNotification& loss_notification) {
Elad Alon6c371ca2019-04-04 12:28:51 +0200104 for (auto& controller : controllers_) {
105 controller->OnLossNotification(loss_notification);
106 }
107}
108
Elad Aloncde8ab22019-03-20 11:56:20 +0100109} // namespace webrtc