blob: df4dfa7c115cb3e37d5fcbb6d3beb8ee3b2775f3 [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
31size_t Vp8TemporalLayers::StreamCount() const {
32 return controllers_.size();
33}
34
35bool Vp8TemporalLayers::SupportsEncoderFrameDropping(
36 size_t stream_index) const {
37 RTC_DCHECK_LT(stream_index, controllers_.size());
38 return controllers_[stream_index]->SupportsEncoderFrameDropping(0);
39}
40
41void Vp8TemporalLayers::OnRatesUpdated(
42 size_t stream_index,
43 const std::vector<uint32_t>& bitrates_bps,
44 int framerate_fps) {
45 RTC_DCHECK_LT(stream_index, controllers_.size());
46 return controllers_[stream_index]->OnRatesUpdated(0, bitrates_bps,
47 framerate_fps);
48}
49
50bool Vp8TemporalLayers::UpdateConfiguration(size_t stream_index,
51 Vp8EncoderConfig* cfg) {
52 RTC_DCHECK_LT(stream_index, controllers_.size());
53 return controllers_[stream_index]->UpdateConfiguration(0, cfg);
54}
55
56Vp8FrameConfig Vp8TemporalLayers::UpdateLayerConfig(size_t stream_index,
57 uint32_t rtp_timestamp) {
58 RTC_DCHECK_LT(stream_index, controllers_.size());
59 return controllers_[stream_index]->UpdateLayerConfig(0, rtp_timestamp);
60}
61
62void Vp8TemporalLayers::OnEncodeDone(size_t stream_index,
63 uint32_t rtp_timestamp,
64 size_t size_bytes,
65 bool is_keyframe,
66 int qp,
67 CodecSpecificInfo* info) {
68 RTC_DCHECK_LT(stream_index, controllers_.size());
69 return controllers_[stream_index]->OnEncodeDone(0, rtp_timestamp, size_bytes,
70 is_keyframe, qp, info);
71}
72
73void Vp8TemporalLayers::OnPacketLossRateUpdate(float packet_loss_rate) {
74 for (auto& controller : controllers_) {
75 controller->OnPacketLossRateUpdate(packet_loss_rate);
76 }
77}
78
79void Vp8TemporalLayers::OnRttUpdate(int64_t rtt_ms) {
80 for (auto& controller : controllers_) {
81 controller->OnRttUpdate(rtt_ms);
82 }
83}
84
85} // namespace webrtc