blob: 22916a7dd5197e9c274b9ea598b8306af7b8d046 [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 Aloncde8ab22019-03-20 11:56:20 +010038size_t Vp8TemporalLayers::StreamCount() const {
39 return controllers_.size();
40}
41
42bool Vp8TemporalLayers::SupportsEncoderFrameDropping(
43 size_t stream_index) const {
44 RTC_DCHECK_LT(stream_index, controllers_.size());
45 return controllers_[stream_index]->SupportsEncoderFrameDropping(0);
46}
47
48void Vp8TemporalLayers::OnRatesUpdated(
49 size_t stream_index,
50 const std::vector<uint32_t>& bitrates_bps,
51 int framerate_fps) {
52 RTC_DCHECK_LT(stream_index, controllers_.size());
53 return controllers_[stream_index]->OnRatesUpdated(0, bitrates_bps,
54 framerate_fps);
55}
56
Elad Alonfb087812019-05-02 23:25:34 +020057Vp8EncoderConfig Vp8TemporalLayers::UpdateConfiguration(size_t stream_index) {
Elad Aloncde8ab22019-03-20 11:56:20 +010058 RTC_DCHECK_LT(stream_index, controllers_.size());
Elad Alonfb087812019-05-02 23:25:34 +020059 return controllers_[stream_index]->UpdateConfiguration(0);
Elad Aloncde8ab22019-03-20 11:56:20 +010060}
61
Elad Alon979c4422019-04-17 12:53:08 +020062Vp8FrameConfig Vp8TemporalLayers::NextFrameConfig(size_t stream_index,
63 uint32_t rtp_timestamp) {
Elad Aloncde8ab22019-03-20 11:56:20 +010064 RTC_DCHECK_LT(stream_index, controllers_.size());
Elad Alon979c4422019-04-17 12:53:08 +020065 return controllers_[stream_index]->NextFrameConfig(0, rtp_timestamp);
Elad Aloncde8ab22019-03-20 11:56:20 +010066}
67
68void Vp8TemporalLayers::OnEncodeDone(size_t stream_index,
69 uint32_t rtp_timestamp,
70 size_t size_bytes,
71 bool is_keyframe,
72 int qp,
73 CodecSpecificInfo* info) {
74 RTC_DCHECK_LT(stream_index, controllers_.size());
75 return controllers_[stream_index]->OnEncodeDone(0, rtp_timestamp, size_bytes,
76 is_keyframe, qp, info);
77}
78
Elad Alon6796ec22019-04-15 10:07:50 +020079void Vp8TemporalLayers::OnFrameDropped(size_t stream_index,
80 uint32_t rtp_timestamp) {
81 RTC_DCHECK_LT(stream_index, controllers_.size());
82 controllers_[stream_index]->OnFrameDropped(stream_index, rtp_timestamp);
83}
84
Elad Aloncde8ab22019-03-20 11:56:20 +010085void Vp8TemporalLayers::OnPacketLossRateUpdate(float packet_loss_rate) {
86 for (auto& controller : controllers_) {
87 controller->OnPacketLossRateUpdate(packet_loss_rate);
88 }
89}
90
91void Vp8TemporalLayers::OnRttUpdate(int64_t rtt_ms) {
92 for (auto& controller : controllers_) {
93 controller->OnRttUpdate(rtt_ms);
94 }
95}
96
Elad Alon6c371ca2019-04-04 12:28:51 +020097void Vp8TemporalLayers::OnLossNotification(
Elad Alon123ee9b2019-04-17 12:48:06 +020098 const VideoEncoder::LossNotification& loss_notification) {
Elad Alon6c371ca2019-04-04 12:28:51 +020099 for (auto& controller : controllers_) {
100 controller->OnLossNotification(loss_notification);
101 }
102}
103
Elad Aloncde8ab22019-03-20 11:56:20 +0100104} // namespace webrtc