blob: dd75c616d8f170528aeac47d4ed70aa40f63760b [file] [log] [blame]
Elad Aloncde8ab22019-03-20 10:56:201/*
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 20:53:0715#include "absl/algorithm/container.h"
Elad Aloncde8ab22019-03-20 10:56:2016#include "rtc_base/checks.h"
17
18namespace webrtc {
19
20Vp8TemporalLayers::Vp8TemporalLayers(
Elad Alon45befc52019-07-02 09:20:0921 std::vector<std::unique_ptr<Vp8FrameBufferController>>&& controllers,
22 FecControllerOverride* fec_controller_override)
Elad Aloncde8ab22019-03-20 10:56:2023 : controllers_(std::move(controllers)) {
24 RTC_DCHECK(!controllers_.empty());
Steve Antona59dcc32019-03-25 20:53:0725 RTC_DCHECK(absl::c_none_of(
26 controllers_,
Elad Aloncde8ab22019-03-20 10:56:2027 [](const std::unique_ptr<Vp8FrameBufferController>& controller) {
28 return controller.get() == nullptr;
29 }));
Elad Alon45befc52019-07-02 09:20:0930 if (fec_controller_override) {
31 fec_controller_override->SetFecAllowed(true);
32 }
Elad Aloncde8ab22019-03-20 10:56:2033}
34
Elad Alonfb087812019-05-02 21:25:3435void 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
Elad Aloncde8ab22019-03-20 10:56:2042size_t Vp8TemporalLayers::StreamCount() const {
43 return controllers_.size();
44}
45
46bool 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
52void 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
Elad Alonfb087812019-05-02 21:25:3461Vp8EncoderConfig Vp8TemporalLayers::UpdateConfiguration(size_t stream_index) {
Elad Aloncde8ab22019-03-20 10:56:2062 RTC_DCHECK_LT(stream_index, controllers_.size());
Elad Alonfb087812019-05-02 21:25:3463 return controllers_[stream_index]->UpdateConfiguration(0);
Elad Aloncde8ab22019-03-20 10:56:2064}
65
Elad Alon979c4426a2019-04-17 10:53:0866Vp8FrameConfig Vp8TemporalLayers::NextFrameConfig(size_t stream_index,
67 uint32_t rtp_timestamp) {
Elad Aloncde8ab22019-03-20 10:56:2068 RTC_DCHECK_LT(stream_index, controllers_.size());
Elad Alon979c4426a2019-04-17 10:53:0869 return controllers_[stream_index]->NextFrameConfig(0, rtp_timestamp);
Elad Aloncde8ab22019-03-20 10:56:2070}
71
72void 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
Elad Alon6796ec22019-04-15 08:07:5083void 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
Elad Aloncde8ab22019-03-20 10:56:2089void Vp8TemporalLayers::OnPacketLossRateUpdate(float packet_loss_rate) {
90 for (auto& controller : controllers_) {
91 controller->OnPacketLossRateUpdate(packet_loss_rate);
92 }
93}
94
95void Vp8TemporalLayers::OnRttUpdate(int64_t rtt_ms) {
96 for (auto& controller : controllers_) {
97 controller->OnRttUpdate(rtt_ms);
98 }
99}
100
Elad Alon6c371ca2019-04-04 10:28:51101void Vp8TemporalLayers::OnLossNotification(
Elad Alon123ee9b2019-04-17 10:48:06102 const VideoEncoder::LossNotification& loss_notification) {
Elad Alon6c371ca2019-04-04 10:28:51103 for (auto& controller : controllers_) {
104 controller->OnLossNotification(loss_notification);
105 }
106}
107
Elad Aloncde8ab22019-03-20 10:56:20108} // namespace webrtc