Elad Alon | cde8ab2 | 2019-03-20 11:56:20 +0100 | [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 13:53:07 -0700 | [diff] [blame] | 15 | #include "absl/algorithm/container.h" |
Elad Alon | cde8ab2 | 2019-03-20 11:56:20 +0100 | [diff] [blame] | 16 | #include "rtc_base/checks.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | Vp8TemporalLayers::Vp8TemporalLayers( |
| 21 | std::vector<std::unique_ptr<Vp8FrameBufferController>>&& controllers) |
| 22 | : controllers_(std::move(controllers)) { |
| 23 | RTC_DCHECK(!controllers_.empty()); |
Steve Anton | a59dcc3 | 2019-03-25 13:53:07 -0700 | [diff] [blame] | 24 | RTC_DCHECK(absl::c_none_of( |
| 25 | controllers_, |
Elad Alon | cde8ab2 | 2019-03-20 11:56:20 +0100 | [diff] [blame] | 26 | [](const std::unique_ptr<Vp8FrameBufferController>& controller) { |
| 27 | return controller.get() == nullptr; |
| 28 | })); |
| 29 | } |
| 30 | |
| 31 | size_t Vp8TemporalLayers::StreamCount() const { |
| 32 | return controllers_.size(); |
| 33 | } |
| 34 | |
| 35 | bool 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 | |
| 41 | void 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 | |
| 50 | bool 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 | |
| 56 | Vp8FrameConfig 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 | |
| 62 | void 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 | |
Elad Alon | 6796ec2 | 2019-04-15 10:07:50 +0200 | [diff] [blame] | 73 | void Vp8TemporalLayers::OnFrameDropped(size_t stream_index, |
| 74 | uint32_t rtp_timestamp) { |
| 75 | RTC_DCHECK_LT(stream_index, controllers_.size()); |
| 76 | controllers_[stream_index]->OnFrameDropped(stream_index, rtp_timestamp); |
| 77 | } |
| 78 | |
Elad Alon | cde8ab2 | 2019-03-20 11:56:20 +0100 | [diff] [blame] | 79 | void Vp8TemporalLayers::OnPacketLossRateUpdate(float packet_loss_rate) { |
| 80 | for (auto& controller : controllers_) { |
| 81 | controller->OnPacketLossRateUpdate(packet_loss_rate); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void Vp8TemporalLayers::OnRttUpdate(int64_t rtt_ms) { |
| 86 | for (auto& controller : controllers_) { |
| 87 | controller->OnRttUpdate(rtt_ms); |
| 88 | } |
| 89 | } |
| 90 | |
Elad Alon | 6c371ca | 2019-04-04 12:28:51 +0200 | [diff] [blame] | 91 | void Vp8TemporalLayers::OnLossNotification( |
Elad Alon | 123ee9b | 2019-04-17 12:48:06 +0200 | [diff] [blame^] | 92 | const VideoEncoder::LossNotification& loss_notification) { |
Elad Alon | 6c371ca | 2019-04-04 12:28:51 +0200 | [diff] [blame] | 93 | for (auto& controller : controllers_) { |
| 94 | controller->OnLossNotification(loss_notification); |
| 95 | } |
| 96 | } |
| 97 | |
Elad Alon | cde8ab2 | 2019-03-20 11:56:20 +0100 | [diff] [blame] | 98 | } // namespace webrtc |