tor-browser

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

h264_globals.h (3866B)


      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 // This file contains codec dependent definitions that are needed in
     12 // order to compile the WebRTC codebase, even if this codec is not used.
     13 
     14 #ifndef MODULES_VIDEO_CODING_CODECS_H264_INCLUDE_H264_GLOBALS_H_
     15 #define MODULES_VIDEO_CODING_CODECS_H264_INCLUDE_H264_GLOBALS_H_
     16 
     17 #include <cstdint>
     18 #include <string>
     19 #include <vector>
     20 
     21 #include "rtc_base/checks.h"
     22 
     23 namespace webrtc {
     24 
     25 // The packetization types that we support: single, aggregated, and fragmented.
     26 enum H264PacketizationTypes {
     27  kH264SingleNalu,  // This packet contains a single NAL unit.
     28  kH264StapA,       // This packet contains STAP-A (single time
     29                    // aggregation) packets. If this packet has an
     30                    // associated NAL unit type, it'll be for the
     31                    // first such aggregated packet.
     32  kH264FuA,         // This packet contains a FU-A (fragmentation
     33                    // unit) packet, meaning it is a part of a frame
     34                    // that was too large to fit into a single packet.
     35 };
     36 
     37 // Packetization modes are defined in RFC 6184 section 6
     38 // Due to the structure containing this being initialized with zeroes
     39 // in some places, and mode 1 being default, mode 1 needs to have the value
     40 // zero. https://crbug.com/webrtc/6803
     41 enum class H264PacketizationMode {
     42  NonInterleaved = 0,  // Mode 1 - STAP-A, FU-A is allowed
     43  SingleNalUnit        // Mode 0 - only single NALU allowed
     44 };
     45 
     46 // This function is declared inline because it is not clear which
     47 // .cc file it should belong to.
     48 // TODO(hta): Refactor. https://bugs.webrtc.org/6842
     49 // TODO(jonasolsson): Use absl::string_view instead when that's available.
     50 inline std::string ToString(H264PacketizationMode mode) {
     51  if (mode == H264PacketizationMode::NonInterleaved) {
     52    return "NonInterleaved";
     53  } else if (mode == H264PacketizationMode::SingleNalUnit) {
     54    return "SingleNalUnit";
     55  }
     56  RTC_DCHECK_NOTREACHED();
     57  return "";
     58 }
     59 
     60 struct NaluInfo {
     61  uint8_t type;
     62  int sps_id;
     63  int pps_id;
     64 
     65  friend bool operator==(const NaluInfo& lhs, const NaluInfo& rhs) {
     66    return lhs.type == rhs.type && lhs.sps_id == rhs.sps_id &&
     67           lhs.pps_id == rhs.pps_id;
     68  }
     69 
     70  friend bool operator!=(const NaluInfo& lhs, const NaluInfo& rhs) {
     71    return !(lhs == rhs);
     72  }
     73 };
     74 
     75 struct RTPVideoHeaderH264 {
     76  // The NAL unit type. If this is a header for a
     77  // fragmented packet, it's the NAL unit type of
     78  // the original data. If this is the header for an
     79  // aggregated packet, it's the NAL unit type of
     80  // the first NAL unit in the packet.
     81  uint8_t nalu_type;
     82  // The packetization type of this buffer - single, aggregated or fragmented.
     83  H264PacketizationTypes packetization_type;
     84  std::vector<NaluInfo> nalus;
     85  // The packetization mode of this transport. Packetization mode
     86  // determines which packetization types are allowed when packetizing.
     87  H264PacketizationMode packetization_mode;
     88 
     89  friend bool operator==(const RTPVideoHeaderH264& lhs,
     90                         const RTPVideoHeaderH264& rhs) {
     91    return lhs.nalu_type == rhs.nalu_type &&
     92           lhs.packetization_type == rhs.packetization_type &&
     93           lhs.nalus == rhs.nalus &&
     94           lhs.packetization_mode == rhs.packetization_mode;
     95  }
     96 
     97  friend bool operator!=(const RTPVideoHeaderH264& lhs,
     98                         const RTPVideoHeaderH264& rhs) {
     99    return !(lhs == rhs);
    100  }
    101 };
    102 
    103 }  // namespace webrtc
    104 
    105 #endif  // MODULES_VIDEO_CODING_CODECS_H264_INCLUDE_H264_GLOBALS_H_