OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ | 11 #ifndef WEBRTC_MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ |
12 #define WEBRTC_MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ | 12 #define WEBRTC_MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ |
13 | 13 |
14 #include <assert.h> | 14 #include <assert.h> |
15 #include <string.h> // memcpy | 15 #include <string.h> // memcpy |
16 | 16 |
17 #include <algorithm> | 17 #include <algorithm> |
18 #include <limits> | 18 #include <limits> |
19 | 19 |
20 #include "webrtc/base/constructormagic.h" | 20 #include "webrtc/base/constructormagic.h" |
21 #include "webrtc/base/deprecation.h" | 21 #include "webrtc/base/deprecation.h" |
22 #include "webrtc/base/safe_conversions.h" | 22 #include "webrtc/base/safe_conversions.h" |
23 #include "webrtc/common_types.h" | 23 #include "webrtc/common_types.h" |
24 #include "webrtc/common_video/rotation.h" | 24 #include "webrtc/common_video/rotation.h" |
| 25 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_globals.h" |
| 26 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9_globals.h" |
| 27 #include "webrtc/modules/video_coding/codecs/h264/include/h264_globals.h" |
25 #include "webrtc/typedefs.h" | 28 #include "webrtc/typedefs.h" |
26 | 29 |
27 namespace webrtc { | 30 namespace webrtc { |
28 | 31 |
29 struct RTPAudioHeader { | 32 struct RTPAudioHeader { |
30 uint8_t numEnergy; // number of valid entries in arrOfEnergy | 33 uint8_t numEnergy; // number of valid entries in arrOfEnergy |
31 uint8_t arrOfEnergy[kRtpCsrcSize]; // one energy byte (0-9) per channel | 34 uint8_t arrOfEnergy[kRtpCsrcSize]; // one energy byte (0-9) per channel |
32 bool isCNG; // is this CNG | 35 bool isCNG; // is this CNG |
33 size_t channel; // number of channels 2 = stereo | 36 size_t channel; // number of channels 2 = stereo |
34 }; | 37 }; |
35 | 38 |
36 const int16_t kNoPictureId = -1; | |
37 const int16_t kMaxOneBytePictureId = 0x7F; // 7 bits | |
38 const int16_t kMaxTwoBytePictureId = 0x7FFF; // 15 bits | |
39 const int16_t kNoTl0PicIdx = -1; | |
40 const uint8_t kNoTemporalIdx = 0xFF; | |
41 const uint8_t kNoSpatialIdx = 0xFF; | |
42 const uint8_t kNoGofIdx = 0xFF; | |
43 const uint8_t kNumVp9Buffers = 8; | |
44 const size_t kMaxVp9RefPics = 3; | |
45 const size_t kMaxVp9FramesInGof = 0xFF; // 8 bits | |
46 const size_t kMaxVp9NumberOfSpatialLayers = 8; | |
47 const int kNoKeyIdx = -1; | |
48 | |
49 struct RTPVideoHeaderVP8 { | |
50 void InitRTPVideoHeaderVP8() { | |
51 nonReference = false; | |
52 pictureId = kNoPictureId; | |
53 tl0PicIdx = kNoTl0PicIdx; | |
54 temporalIdx = kNoTemporalIdx; | |
55 layerSync = false; | |
56 keyIdx = kNoKeyIdx; | |
57 partitionId = 0; | |
58 beginningOfPartition = false; | |
59 } | |
60 | |
61 bool nonReference; // Frame is discardable. | |
62 int16_t pictureId; // Picture ID index, 15 bits; | |
63 // kNoPictureId if PictureID does not exist. | |
64 int16_t tl0PicIdx; // TL0PIC_IDX, 8 bits; | |
65 // kNoTl0PicIdx means no value provided. | |
66 uint8_t temporalIdx; // Temporal layer index, or kNoTemporalIdx. | |
67 bool layerSync; // This frame is a layer sync frame. | |
68 // Disabled if temporalIdx == kNoTemporalIdx. | |
69 int keyIdx; // 5 bits; kNoKeyIdx means not used. | |
70 int partitionId; // VP8 partition ID | |
71 bool beginningOfPartition; // True if this packet is the first | |
72 // in a VP8 partition. Otherwise false | |
73 }; | |
74 | |
75 enum TemporalStructureMode { | |
76 kTemporalStructureMode1, // 1 temporal layer structure - i.e., IPPP... | |
77 kTemporalStructureMode2, // 2 temporal layers 01... | |
78 kTemporalStructureMode3, // 3 temporal layers 0212... | |
79 kTemporalStructureMode4 // 3 temporal layers 02120212... | |
80 }; | |
81 | |
82 struct GofInfoVP9 { | |
83 void SetGofInfoVP9(TemporalStructureMode tm) { | |
84 switch (tm) { | |
85 case kTemporalStructureMode1: | |
86 num_frames_in_gof = 1; | |
87 temporal_idx[0] = 0; | |
88 temporal_up_switch[0] = false; | |
89 num_ref_pics[0] = 1; | |
90 pid_diff[0][0] = 1; | |
91 break; | |
92 case kTemporalStructureMode2: | |
93 num_frames_in_gof = 2; | |
94 temporal_idx[0] = 0; | |
95 temporal_up_switch[0] = false; | |
96 num_ref_pics[0] = 1; | |
97 pid_diff[0][0] = 2; | |
98 | |
99 temporal_idx[1] = 1; | |
100 temporal_up_switch[1] = true; | |
101 num_ref_pics[1] = 1; | |
102 pid_diff[1][0] = 1; | |
103 break; | |
104 case kTemporalStructureMode3: | |
105 num_frames_in_gof = 4; | |
106 temporal_idx[0] = 0; | |
107 temporal_up_switch[0] = false; | |
108 num_ref_pics[0] = 1; | |
109 pid_diff[0][0] = 4; | |
110 | |
111 temporal_idx[1] = 2; | |
112 temporal_up_switch[1] = true; | |
113 num_ref_pics[1] = 1; | |
114 pid_diff[1][0] = 1; | |
115 | |
116 temporal_idx[2] = 1; | |
117 temporal_up_switch[2] = true; | |
118 num_ref_pics[2] = 1; | |
119 pid_diff[2][0] = 2; | |
120 | |
121 temporal_idx[3] = 2; | |
122 temporal_up_switch[3] = false; | |
123 num_ref_pics[3] = 2; | |
124 pid_diff[3][0] = 1; | |
125 pid_diff[3][1] = 2; | |
126 break; | |
127 case kTemporalStructureMode4: | |
128 num_frames_in_gof = 8; | |
129 temporal_idx[0] = 0; | |
130 temporal_up_switch[0] = false; | |
131 num_ref_pics[0] = 1; | |
132 pid_diff[0][0] = 4; | |
133 | |
134 temporal_idx[1] = 2; | |
135 temporal_up_switch[1] = true; | |
136 num_ref_pics[1] = 1; | |
137 pid_diff[1][0] = 1; | |
138 | |
139 temporal_idx[2] = 1; | |
140 temporal_up_switch[2] = true; | |
141 num_ref_pics[2] = 1; | |
142 pid_diff[2][0] = 2; | |
143 | |
144 temporal_idx[3] = 2; | |
145 temporal_up_switch[3] = false; | |
146 num_ref_pics[3] = 2; | |
147 pid_diff[3][0] = 1; | |
148 pid_diff[3][1] = 2; | |
149 | |
150 temporal_idx[4] = 0; | |
151 temporal_up_switch[0] = false; | |
152 num_ref_pics[4] = 1; | |
153 pid_diff[4][0] = 4; | |
154 | |
155 temporal_idx[5] = 2; | |
156 temporal_up_switch[1] = false; | |
157 num_ref_pics[5] = 2; | |
158 pid_diff[5][0] = 1; | |
159 pid_diff[5][1] = 2; | |
160 | |
161 temporal_idx[6] = 1; | |
162 temporal_up_switch[2] = false; | |
163 num_ref_pics[6] = 2; | |
164 pid_diff[6][0] = 2; | |
165 pid_diff[6][1] = 4; | |
166 | |
167 temporal_idx[7] = 2; | |
168 temporal_up_switch[3] = false; | |
169 num_ref_pics[7] = 2; | |
170 pid_diff[7][0] = 1; | |
171 pid_diff[7][1] = 2; | |
172 break; | |
173 default: | |
174 assert(false); | |
175 } | |
176 } | |
177 | |
178 void CopyGofInfoVP9(const GofInfoVP9& src) { | |
179 num_frames_in_gof = src.num_frames_in_gof; | |
180 for (size_t i = 0; i < num_frames_in_gof; ++i) { | |
181 temporal_idx[i] = src.temporal_idx[i]; | |
182 temporal_up_switch[i] = src.temporal_up_switch[i]; | |
183 num_ref_pics[i] = src.num_ref_pics[i]; | |
184 for (uint8_t r = 0; r < num_ref_pics[i]; ++r) { | |
185 pid_diff[i][r] = src.pid_diff[i][r]; | |
186 } | |
187 } | |
188 } | |
189 | |
190 size_t num_frames_in_gof; | |
191 uint8_t temporal_idx[kMaxVp9FramesInGof]; | |
192 bool temporal_up_switch[kMaxVp9FramesInGof]; | |
193 uint8_t num_ref_pics[kMaxVp9FramesInGof]; | |
194 uint8_t pid_diff[kMaxVp9FramesInGof][kMaxVp9RefPics]; | |
195 uint16_t pid_start; | |
196 }; | |
197 | |
198 struct RTPVideoHeaderVP9 { | |
199 void InitRTPVideoHeaderVP9() { | |
200 inter_pic_predicted = false; | |
201 flexible_mode = false; | |
202 beginning_of_frame = false; | |
203 end_of_frame = false; | |
204 ss_data_available = false; | |
205 picture_id = kNoPictureId; | |
206 max_picture_id = kMaxTwoBytePictureId; | |
207 tl0_pic_idx = kNoTl0PicIdx; | |
208 temporal_idx = kNoTemporalIdx; | |
209 spatial_idx = kNoSpatialIdx; | |
210 temporal_up_switch = false; | |
211 inter_layer_predicted = false; | |
212 gof_idx = kNoGofIdx; | |
213 num_ref_pics = 0; | |
214 num_spatial_layers = 1; | |
215 } | |
216 | |
217 bool inter_pic_predicted; // This layer frame is dependent on previously | |
218 // coded frame(s). | |
219 bool flexible_mode; // This frame is in flexible mode. | |
220 bool beginning_of_frame; // True if this packet is the first in a VP9 layer | |
221 // frame. | |
222 bool end_of_frame; // True if this packet is the last in a VP9 layer frame. | |
223 bool ss_data_available; // True if SS data is available in this payload | |
224 // descriptor. | |
225 int16_t picture_id; // PictureID index, 15 bits; | |
226 // kNoPictureId if PictureID does not exist. | |
227 int16_t max_picture_id; // Maximum picture ID index; either 0x7F or 0x7FFF; | |
228 int16_t tl0_pic_idx; // TL0PIC_IDX, 8 bits; | |
229 // kNoTl0PicIdx means no value provided. | |
230 uint8_t temporal_idx; // Temporal layer index, or kNoTemporalIdx. | |
231 uint8_t spatial_idx; // Spatial layer index, or kNoSpatialIdx. | |
232 bool temporal_up_switch; // True if upswitch to higher frame rate is possible | |
233 // starting from this frame. | |
234 bool inter_layer_predicted; // Frame is dependent on directly lower spatial | |
235 // layer frame. | |
236 | |
237 uint8_t gof_idx; // Index to predefined temporal frame info in SS data. | |
238 | |
239 uint8_t num_ref_pics; // Number of reference pictures used by this layer | |
240 // frame. | |
241 uint8_t pid_diff[kMaxVp9RefPics]; // P_DIFF signaled to derive the PictureID | |
242 // of the reference pictures. | |
243 int16_t ref_picture_id[kMaxVp9RefPics]; // PictureID of reference pictures. | |
244 | |
245 // SS data. | |
246 size_t num_spatial_layers; // Always populated. | |
247 bool spatial_layer_resolution_present; | |
248 uint16_t width[kMaxVp9NumberOfSpatialLayers]; | |
249 uint16_t height[kMaxVp9NumberOfSpatialLayers]; | |
250 GofInfoVP9 gof; | |
251 }; | |
252 | |
253 // The packetization types that we support: single, aggregated, and fragmented. | |
254 enum H264PacketizationTypes { | |
255 kH264SingleNalu, // This packet contains a single NAL unit. | |
256 kH264StapA, // This packet contains STAP-A (single time | |
257 // aggregation) packets. If this packet has an | |
258 // associated NAL unit type, it'll be for the | |
259 // first such aggregated packet. | |
260 kH264FuA, // This packet contains a FU-A (fragmentation | |
261 // unit) packet, meaning it is a part of a frame | |
262 // that was too large to fit into a single packet. | |
263 }; | |
264 | |
265 // Packetization modes are defined in RFC 6184 section 6 | |
266 // Due to the structure containing this being initialized with zeroes | |
267 // in some places, and mode 1 being default, mode 1 needs to have the value | |
268 // zero. https://crbug.com/webrtc/6803 | |
269 enum class H264PacketizationMode { | |
270 NonInterleaved = 0, // Mode 1 - STAP-A, FU-A is allowed | |
271 SingleNalUnit // Mode 0 - only single NALU allowed | |
272 }; | |
273 | |
274 // This function is declared inline because it is not clear which | |
275 // .cc file it should belong to. | |
276 // TODO(hta): Refactor. https://bugs.webrtc.org/6842 | |
277 inline std::ostream& operator<<(std::ostream& stream, | |
278 H264PacketizationMode mode) { | |
279 switch (mode) { | |
280 case H264PacketizationMode::NonInterleaved: | |
281 stream << "NonInterleaved"; | |
282 break; | |
283 case H264PacketizationMode::SingleNalUnit: | |
284 stream << "SingleNalUnit"; | |
285 break; | |
286 } | |
287 return stream; | |
288 } | |
289 | |
290 struct NaluInfo { | |
291 uint8_t type; | |
292 int sps_id; | |
293 int pps_id; | |
294 | |
295 // Offset and size are only valid for non-FuA packets. | |
296 size_t offset; | |
297 size_t size; | |
298 }; | |
299 | |
300 const size_t kMaxNalusPerPacket = 10; | |
301 | |
302 struct RTPVideoHeaderH264 { | |
303 // The NAL unit type. If this is a header for a | |
304 // fragmented packet, it's the NAL unit type of | |
305 // the original data. If this is the header for an | |
306 // aggregated packet, it's the NAL unit type of | |
307 // the first NAL unit in the packet. | |
308 uint8_t nalu_type; | |
309 // The packetization type of this buffer - single, aggregated or fragmented. | |
310 H264PacketizationTypes packetization_type; | |
311 NaluInfo nalus[kMaxNalusPerPacket]; | |
312 size_t nalus_length; | |
313 // The packetization mode of this transport. Packetization mode | |
314 // determines which packetization types are allowed when packetizing. | |
315 H264PacketizationMode packetization_mode; | |
316 }; | |
317 | |
318 union RTPVideoTypeHeader { | 39 union RTPVideoTypeHeader { |
319 RTPVideoHeaderVP8 VP8; | 40 RTPVideoHeaderVP8 VP8; |
320 RTPVideoHeaderVP9 VP9; | 41 RTPVideoHeaderVP9 VP9; |
321 RTPVideoHeaderH264 H264; | 42 RTPVideoHeaderH264 H264; |
322 }; | 43 }; |
323 | 44 |
324 enum RtpVideoCodecTypes { | 45 enum RtpVideoCodecTypes { |
325 kRtpVideoNone, | 46 kRtpVideoNone, |
326 kRtpVideoGeneric, | 47 kRtpVideoGeneric, |
327 kRtpVideoVp8, | 48 kRtpVideoVp8, |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 return unwrapped; | 522 return unwrapped; |
802 } | 523 } |
803 | 524 |
804 private: | 525 private: |
805 int64_t last_seq_; | 526 int64_t last_seq_; |
806 }; | 527 }; |
807 | 528 |
808 } // namespace webrtc | 529 } // namespace webrtc |
809 | 530 |
810 #endif // WEBRTC_MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ | 531 #endif // WEBRTC_MODULES_INCLUDE_MODULE_COMMON_TYPES_H_ |
OLD | NEW |