tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

vp8_temporal_layers.cc (4077B)


      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 <cstddef>
     14 #include <cstdint>
     15 #include <memory>
     16 #include <utility>
     17 #include <vector>
     18 
     19 #include "absl/algorithm/container.h"
     20 #include "api/fec_controller_override.h"
     21 #include "api/video_codecs/video_encoder.h"
     22 #include "api/video_codecs/vp8_frame_buffer_controller.h"
     23 #include "api/video_codecs/vp8_frame_config.h"
     24 #include "rtc_base/checks.h"
     25 
     26 namespace webrtc {
     27 
     28 Vp8TemporalLayers::Vp8TemporalLayers(
     29    std::vector<std::unique_ptr<Vp8FrameBufferController>>&& controllers,
     30    FecControllerOverride* fec_controller_override)
     31    : controllers_(std::move(controllers)) {
     32  RTC_DCHECK(!controllers_.empty());
     33  RTC_DCHECK(absl::c_none_of(
     34      controllers_,
     35      [](const std::unique_ptr<Vp8FrameBufferController>& controller) {
     36        return controller.get() == nullptr;
     37      }));
     38  if (fec_controller_override) {
     39    fec_controller_override->SetFecAllowed(true);
     40  }
     41 }
     42 
     43 void Vp8TemporalLayers::SetQpLimits(size_t stream_index,
     44                                    int min_qp,
     45                                    int max_qp) {
     46  RTC_DCHECK_LT(stream_index, controllers_.size());
     47  return controllers_[stream_index]->SetQpLimits(0, min_qp, max_qp);
     48 }
     49 
     50 size_t Vp8TemporalLayers::StreamCount() const {
     51  return controllers_.size();
     52 }
     53 
     54 bool Vp8TemporalLayers::SupportsEncoderFrameDropping(
     55    size_t stream_index) const {
     56  RTC_DCHECK_LT(stream_index, controllers_.size());
     57  return controllers_[stream_index]->SupportsEncoderFrameDropping(0);
     58 }
     59 
     60 void Vp8TemporalLayers::OnRatesUpdated(
     61    size_t stream_index,
     62    const std::vector<uint32_t>& bitrates_bps,
     63    int framerate_fps) {
     64  RTC_DCHECK_LT(stream_index, controllers_.size());
     65  return controllers_[stream_index]->OnRatesUpdated(0, bitrates_bps,
     66                                                    framerate_fps);
     67 }
     68 
     69 Vp8EncoderConfig Vp8TemporalLayers::UpdateConfiguration(size_t stream_index) {
     70  RTC_DCHECK_LT(stream_index, controllers_.size());
     71  return controllers_[stream_index]->UpdateConfiguration(0);
     72 }
     73 
     74 Vp8FrameConfig Vp8TemporalLayers::NextFrameConfig(size_t stream_index,
     75                                                  uint32_t rtp_timestamp) {
     76  RTC_DCHECK_LT(stream_index, controllers_.size());
     77  return controllers_[stream_index]->NextFrameConfig(0, rtp_timestamp);
     78 }
     79 
     80 void Vp8TemporalLayers::OnEncodeDone(size_t stream_index,
     81                                     uint32_t rtp_timestamp,
     82                                     size_t size_bytes,
     83                                     bool is_keyframe,
     84                                     int qp,
     85                                     CodecSpecificInfo* info) {
     86  RTC_DCHECK_LT(stream_index, controllers_.size());
     87  return controllers_[stream_index]->OnEncodeDone(0, rtp_timestamp, size_bytes,
     88                                                  is_keyframe, qp, info);
     89 }
     90 
     91 void Vp8TemporalLayers::OnFrameDropped(size_t stream_index,
     92                                       uint32_t rtp_timestamp) {
     93  RTC_DCHECK_LT(stream_index, controllers_.size());
     94  controllers_[stream_index]->OnFrameDropped(stream_index, rtp_timestamp);
     95 }
     96 
     97 void Vp8TemporalLayers::OnPacketLossRateUpdate(float packet_loss_rate) {
     98  for (auto& controller : controllers_) {
     99    controller->OnPacketLossRateUpdate(packet_loss_rate);
    100  }
    101 }
    102 
    103 void Vp8TemporalLayers::OnRttUpdate(int64_t rtt_ms) {
    104  for (auto& controller : controllers_) {
    105    controller->OnRttUpdate(rtt_ms);
    106  }
    107 }
    108 
    109 void Vp8TemporalLayers::OnLossNotification(
    110    const VideoEncoder::LossNotification& loss_notification) {
    111  for (auto& controller : controllers_) {
    112    controller->OnLossNotification(loss_notification);
    113  }
    114 }
    115 
    116 }  // namespace webrtc