tor-browser

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

video_codec_interface.h (4862B)


      1 /*
      2 *  Copyright (c) 2012 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 #ifndef MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_
     12 #define MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 #include <optional>
     17 #include <type_traits>
     18 
     19 #include "api/transport/rtp/dependency_descriptor.h"
     20 #include "api/video/corruption_detection/frame_instrumentation_data.h"
     21 #include "api/video/video_codec_type.h"
     22 #include "api/video_codecs/scalability_mode.h"
     23 #include "api/video_codecs/video_encoder.h"
     24 #include "common_video/generic_frame_descriptor/generic_frame_info.h"
     25 #include "modules/video_coding/codecs/h264/include/h264_globals.h"
     26 #include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
     27 #include "rtc_base/system/rtc_export.h"
     28 
     29 namespace webrtc {
     30 
     31 // Note: If any pointers are added to this struct, it must be fitted
     32 // with a copy-constructor. See below.
     33 // Hack alert - the code assumes that thisstruct is memset when constructed.
     34 struct CodecSpecificInfoVP8 {
     35  bool nonReference;
     36  uint8_t temporalIdx;
     37  bool layerSync;
     38  int8_t keyIdx;  // Negative value to skip keyIdx.
     39 
     40  // Used to generate the list of dependency frames.
     41  // `referencedBuffers` and `updatedBuffers` contain buffer IDs.
     42  // Note that the buffer IDs here have a one-to-one mapping with the actual
     43  // codec buffers, but the exact mapping (i.e. whether 0 refers to Last,
     44  // to Golden or to Arf) is not pre-determined.
     45  // More references may be specified than are strictly necessary, but not less.
     46  // TODO(bugs.webrtc.org/10242): Remove `useExplicitDependencies` once all
     47  // encoder-wrappers are updated.
     48  bool useExplicitDependencies;
     49  static constexpr size_t kBuffersCount = 3;
     50  size_t referencedBuffers[kBuffersCount];
     51  size_t referencedBuffersCount;
     52  size_t updatedBuffers[kBuffersCount];
     53  size_t updatedBuffersCount;
     54 };
     55 static_assert(std::is_trivial_v<CodecSpecificInfoVP8> &&
     56                  std::is_standard_layout_v<CodecSpecificInfoVP8>,
     57              "");
     58 
     59 // Hack alert - the code assumes that thisstruct is memset when constructed.
     60 struct CodecSpecificInfoVP9 {
     61  bool first_frame_in_picture;  // First frame, increment picture_id.
     62  bool inter_pic_predicted;     // This layer frame is dependent on previously
     63                                // coded frame(s).
     64  bool flexible_mode;
     65  bool ss_data_available;
     66  bool non_ref_for_inter_layer_pred;
     67 
     68  uint8_t temporal_idx;
     69  bool temporal_up_switch;
     70  bool inter_layer_predicted;  // Frame is dependent on directly lower spatial
     71                               // layer frame.
     72  uint8_t gof_idx;
     73 
     74  // SS data.
     75  size_t num_spatial_layers;  // Always populated.
     76  size_t first_active_layer;
     77  bool spatial_layer_resolution_present;
     78  uint16_t width[kMaxVp9NumberOfSpatialLayers];
     79  uint16_t height[kMaxVp9NumberOfSpatialLayers];
     80  GofInfoVP9 gof;
     81 
     82  // Frame reference data.
     83  uint8_t num_ref_pics;
     84  uint8_t p_diff[kMaxVp9RefPics];
     85 };
     86 static_assert(std::is_trivial_v<CodecSpecificInfoVP9> &&
     87                  std::is_standard_layout_v<CodecSpecificInfoVP9>,
     88              "");
     89 
     90 // Hack alert - the code assumes that thisstruct is memset when constructed.
     91 struct CodecSpecificInfoH264 {
     92  H264PacketizationMode packetization_mode;
     93  uint8_t temporal_idx;
     94  bool base_layer_sync;
     95  bool idr_frame;
     96 };
     97 static_assert(std::is_trivial_v<CodecSpecificInfoH264> &&
     98                  std::is_standard_layout_v<CodecSpecificInfoH264>,
     99              "");
    100 
    101 union CodecSpecificInfoUnion {
    102  CodecSpecificInfoVP8 VP8;
    103  CodecSpecificInfoVP9 VP9;
    104  CodecSpecificInfoH264 H264;
    105 };
    106 static_assert(std::is_trivial_v<CodecSpecificInfoUnion> &&
    107                  std::is_standard_layout_v<CodecSpecificInfoUnion>,
    108              "");
    109 
    110 // Note: if any pointers are added to this struct or its sub-structs, it
    111 // must be fitted with a copy-constructor. This is because it is copied
    112 // in the copy-constructor of VCMEncodedFrame.
    113 struct RTC_EXPORT CodecSpecificInfo {
    114  CodecSpecificInfo();
    115  CodecSpecificInfo(const CodecSpecificInfo&);
    116  ~CodecSpecificInfo();
    117 
    118  VideoCodecType codecType;
    119  CodecSpecificInfoUnion codecSpecific;
    120  bool end_of_picture = true;
    121  std::optional<GenericFrameInfo> generic_frame_info;
    122  std::optional<FrameDependencyStructure> template_structure;
    123  std::optional<ScalabilityMode> scalability_mode;
    124 
    125  // Required for automatic corruption detection.
    126  std::optional<FrameInstrumentationData> frame_instrumentation_data;
    127 };
    128 
    129 }  // namespace webrtc
    130 
    131 #endif  // MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_