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