Elad Alon | cde8ab2 | 2019-03-20 10:56:20 | [diff] [blame] | 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 | |
Steve Anton | a59dcc3 | 2019-03-25 20:53:07 | [diff] [blame] | 15 | #include "absl/algorithm/container.h" |
Elad Alon | cde8ab2 | 2019-03-20 10:56:20 | [diff] [blame] | 16 | #include "rtc_base/checks.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | Vp8TemporalLayers::Vp8TemporalLayers( |
Elad Alon | 45befc5 | 2019-07-02 09:20:09 | [diff] [blame] | 21 | std::vector<std::unique_ptr<Vp8FrameBufferController>>&& controllers, |
| 22 | FecControllerOverride* fec_controller_override) |
Elad Alon | cde8ab2 | 2019-03-20 10:56:20 | [diff] [blame] | 23 | : controllers_(std::move(controllers)) { |
| 24 | RTC_DCHECK(!controllers_.empty()); |
Steve Anton | a59dcc3 | 2019-03-25 20:53:07 | [diff] [blame] | 25 | RTC_DCHECK(absl::c_none_of( |
| 26 | controllers_, |
Elad Alon | cde8ab2 | 2019-03-20 10:56:20 | [diff] [blame] | 27 | [](const std::unique_ptr<Vp8FrameBufferController>& controller) { |
| 28 | return controller.get() == nullptr; |
| 29 | })); |
Elad Alon | 45befc5 | 2019-07-02 09:20:09 | [diff] [blame] | 30 | if (fec_controller_override) { |
| 31 | fec_controller_override->SetFecAllowed(true); |
| 32 | } |
Elad Alon | cde8ab2 | 2019-03-20 10:56:20 | [diff] [blame] | 33 | } |
| 34 | |
Elad Alon | fb08781 | 2019-05-02 21:25:34 | [diff] [blame] | 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 | |
Elad Alon | cde8ab2 | 2019-03-20 10:56:20 | [diff] [blame] | 42 | size_t Vp8TemporalLayers::StreamCount() const { |
| 43 | return controllers_.size(); |
| 44 | } |
| 45 | |
| 46 | 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 | |
| 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 | |
Elad Alon | fb08781 | 2019-05-02 21:25:34 | [diff] [blame] | 61 | Vp8EncoderConfig Vp8TemporalLayers::UpdateConfiguration(size_t stream_index) { |
Elad Alon | cde8ab2 | 2019-03-20 10:56:20 | [diff] [blame] | 62 | RTC_DCHECK_LT(stream_index, controllers_.size()); |
Elad Alon | fb08781 | 2019-05-02 21:25:34 | [diff] [blame] | 63 | return controllers_[stream_index]->UpdateConfiguration(0); |
Elad Alon | cde8ab2 | 2019-03-20 10:56:20 | [diff] [blame] | 64 | } |
| 65 | |
Elad Alon | 979c4426a | 2019-04-17 10:53:08 | [diff] [blame] | 66 | Vp8FrameConfig Vp8TemporalLayers::NextFrameConfig(size_t stream_index, |
| 67 | uint32_t rtp_timestamp) { |
Elad Alon | cde8ab2 | 2019-03-20 10:56:20 | [diff] [blame] | 68 | RTC_DCHECK_LT(stream_index, controllers_.size()); |
Elad Alon | 979c4426a | 2019-04-17 10:53:08 | [diff] [blame] | 69 | return controllers_[stream_index]->NextFrameConfig(0, rtp_timestamp); |
Elad Alon | cde8ab2 | 2019-03-20 10:56:20 | [diff] [blame] | 70 | } |
| 71 | |
| 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 | |
Elad Alon | 6796ec2 | 2019-04-15 08:07:50 | [diff] [blame] | 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 | |
Elad Alon | cde8ab2 | 2019-03-20 10:56:20 | [diff] [blame] | 89 | void Vp8TemporalLayers::OnPacketLossRateUpdate(float packet_loss_rate) { |
| 90 | for (auto& controller : controllers_) { |
| 91 | controller->OnPacketLossRateUpdate(packet_loss_rate); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | void Vp8TemporalLayers::OnRttUpdate(int64_t rtt_ms) { |
| 96 | for (auto& controller : controllers_) { |
| 97 | controller->OnRttUpdate(rtt_ms); |
| 98 | } |
| 99 | } |
| 100 | |
Elad Alon | 6c371ca | 2019-04-04 10:28:51 | [diff] [blame] | 101 | void Vp8TemporalLayers::OnLossNotification( |
Elad Alon | 123ee9b | 2019-04-17 10:48:06 | [diff] [blame] | 102 | const VideoEncoder::LossNotification& loss_notification) { |
Elad Alon | 6c371ca | 2019-04-04 10:28:51 | [diff] [blame] | 103 | for (auto& controller : controllers_) { |
| 104 | controller->OnLossNotification(loss_notification); |
| 105 | } |
| 106 | } |
| 107 | |
Elad Alon | cde8ab2 | 2019-03-20 10:56:20 | [diff] [blame] | 108 | } // namespace webrtc |