tor-browser

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

encoded_frame.cc (5347B)


      1 /*
      2 *  Copyright (c) 2018 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/encoded_frame.h"
     12 
     13 #include <cstddef>
     14 #include <cstdint>
     15 #include <optional>
     16 
     17 #include "api/units/timestamp.h"
     18 #include "api/video/video_codec_type.h"
     19 #include "modules/rtp_rtcp/source/rtp_video_header.h"
     20 #include "modules/video_coding/codecs/interface/common_constants.h"
     21 #include "modules/video_coding/codecs/vp8/include/vp8_globals.h"
     22 #include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
     23 
     24 namespace webrtc {
     25 
     26 std::optional<Timestamp> EncodedFrame::ReceivedTimestamp() const {
     27  return ReceivedTime() >= 0
     28             ? std::make_optional(Timestamp::Millis(ReceivedTime()))
     29             : std::nullopt;
     30 }
     31 
     32 std::optional<Timestamp> EncodedFrame::RenderTimestamp() const {
     33  return RenderTimeMs() >= 0
     34             ? std::make_optional(Timestamp::Millis(RenderTimeMs()))
     35             : std::nullopt;
     36 }
     37 
     38 bool EncodedFrame::delayed_by_retransmission() const {
     39  return false;
     40 }
     41 
     42 void EncodedFrame::CopyCodecSpecific(const RTPVideoHeader* header) {
     43  if (header) {
     44    switch (header->codec) {
     45      case kVideoCodecVP8: {
     46        const auto& vp8_header =
     47            std::get<RTPVideoHeaderVP8>(header->video_type_header);
     48        if (_codecSpecificInfo.codecType != kVideoCodecVP8) {
     49          // This is the first packet for this frame.
     50          _codecSpecificInfo.codecSpecific.VP8.temporalIdx = 0;
     51          _codecSpecificInfo.codecSpecific.VP8.layerSync = false;
     52          _codecSpecificInfo.codecSpecific.VP8.keyIdx = -1;
     53          _codecSpecificInfo.codecType = kVideoCodecVP8;
     54        }
     55        _codecSpecificInfo.codecSpecific.VP8.nonReference =
     56            vp8_header.nonReference;
     57        if (vp8_header.temporalIdx != kNoTemporalIdx) {
     58          _codecSpecificInfo.codecSpecific.VP8.temporalIdx =
     59              vp8_header.temporalIdx;
     60          _codecSpecificInfo.codecSpecific.VP8.layerSync = vp8_header.layerSync;
     61        }
     62        if (vp8_header.keyIdx != kNoKeyIdx) {
     63          _codecSpecificInfo.codecSpecific.VP8.keyIdx = vp8_header.keyIdx;
     64        }
     65        break;
     66      }
     67      case kVideoCodecVP9: {
     68        const auto& vp9_header =
     69            std::get<RTPVideoHeaderVP9>(header->video_type_header);
     70        if (_codecSpecificInfo.codecType != kVideoCodecVP9) {
     71          // This is the first packet for this frame.
     72          _codecSpecificInfo.codecSpecific.VP9.temporal_idx = 0;
     73          _codecSpecificInfo.codecSpecific.VP9.gof_idx = 0;
     74          _codecSpecificInfo.codecSpecific.VP9.inter_layer_predicted = false;
     75          _codecSpecificInfo.codecType = kVideoCodecVP9;
     76        }
     77        _codecSpecificInfo.codecSpecific.VP9.inter_pic_predicted =
     78            vp9_header.inter_pic_predicted;
     79        _codecSpecificInfo.codecSpecific.VP9.flexible_mode =
     80            vp9_header.flexible_mode;
     81        _codecSpecificInfo.codecSpecific.VP9.num_ref_pics =
     82            vp9_header.num_ref_pics;
     83        for (uint8_t r = 0; r < vp9_header.num_ref_pics; ++r) {
     84          _codecSpecificInfo.codecSpecific.VP9.p_diff[r] =
     85              vp9_header.pid_diff[r];
     86        }
     87        _codecSpecificInfo.codecSpecific.VP9.ss_data_available =
     88            vp9_header.ss_data_available;
     89        if (vp9_header.temporal_idx != kNoTemporalIdx) {
     90          _codecSpecificInfo.codecSpecific.VP9.temporal_idx =
     91              vp9_header.temporal_idx;
     92          _codecSpecificInfo.codecSpecific.VP9.temporal_up_switch =
     93              vp9_header.temporal_up_switch;
     94        }
     95        if (vp9_header.spatial_idx != kNoSpatialIdx) {
     96          _codecSpecificInfo.codecSpecific.VP9.inter_layer_predicted =
     97              vp9_header.inter_layer_predicted;
     98          SetSpatialIndex(vp9_header.spatial_idx);
     99        }
    100        if (vp9_header.gof_idx != kNoGofIdx) {
    101          _codecSpecificInfo.codecSpecific.VP9.gof_idx = vp9_header.gof_idx;
    102        }
    103        if (vp9_header.ss_data_available) {
    104          _codecSpecificInfo.codecSpecific.VP9.num_spatial_layers =
    105              vp9_header.num_spatial_layers;
    106          _codecSpecificInfo.codecSpecific.VP9
    107              .spatial_layer_resolution_present =
    108              vp9_header.spatial_layer_resolution_present;
    109          if (vp9_header.spatial_layer_resolution_present) {
    110            for (size_t i = 0; i < vp9_header.num_spatial_layers; ++i) {
    111              _codecSpecificInfo.codecSpecific.VP9.width[i] =
    112                  vp9_header.width[i];
    113              _codecSpecificInfo.codecSpecific.VP9.height[i] =
    114                  vp9_header.height[i];
    115            }
    116          }
    117          _codecSpecificInfo.codecSpecific.VP9.gof.CopyGofInfoVP9(
    118              vp9_header.gof);
    119        }
    120        break;
    121      }
    122      case kVideoCodecH264: {
    123        _codecSpecificInfo.codecType = kVideoCodecH264;
    124        break;
    125      }
    126      case kVideoCodecAV1: {
    127        _codecSpecificInfo.codecType = kVideoCodecAV1;
    128        break;
    129      }
    130      default: {
    131        _codecSpecificInfo.codecType = kVideoCodecGeneric;
    132        break;
    133      }
    134    }
    135  }
    136 }
    137 
    138 }  // namespace webrtc