1 /*
2 * RTP parser for HEVC/H.265 payload format (draft version 6)
3 * Copyright (c) 2014 Thomas Volkert <thomas@homer-conferencing.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22
27
31
32 #define RTP_HEVC_PAYLOAD_HEADER_SIZE 2
33 #define RTP_HEVC_FU_HEADER_SIZE 1
34 #define RTP_HEVC_DONL_FIELD_SIZE 2
35 #define RTP_HEVC_DOND_FIELD_SIZE 1
36 #define RTP_HEVC_AP_NALU_LENGTH_FIELD_SIZE 2
37 #define HEVC_SPECIFIED_NAL_UNIT_TYPES 48
38
39 /* SDP out-of-band signaling data */
45 };
46
48
52 const char *attr,
const char *
value)
53 {
54 /* profile-space: 0-3 */
55 /* profile-id: 0-31 */
56 if (!strcmp(attr, "profile-id")) {
59 }
60
61 /* tier-flag: 0-1 */
62 /* level-id: 0-255 */
63 /* interop-constraints: [base16] */
64 /* profile-compatibility-indicator: [base16] */
65 /* sprop-sub-layer-id: 0-6, defines highest possible value for TID, default: 6 */
66 /* recv-sub-layer-id: 0-6 */
67 /* max-recv-level-id: 0-255 */
68 /* tx-mode: MSM,SSM */
69 /* sprop-vps: [base64] */
70 /* sprop-sps: [base64] */
71 /* sprop-pps: [base64] */
72 /* sprop-sei: [base64] */
73 if (!strcmp(attr, "sprop-vps") || !strcmp(attr, "sprop-sps") ||
74 !strcmp(attr, "sprop-pps") || !strcmp(attr, "sprop-sei")) {
77 if (!strcmp(attr, "sprop-vps")) {
78 data_ptr = &hevc_data->
vps;
80 } else if (!strcmp(attr, "sprop-sps")) {
81 data_ptr = &hevc_data->
sps;
83 } else if (!strcmp(attr, "sprop-pps")) {
84 data_ptr = &hevc_data->
pps;
86 } else if (!strcmp(attr, "sprop-sei")) {
87 data_ptr = &hevc_data->
sei;
89 } else
91
93 size_ptr, value);
94 }
95
96 /* max-lsr, max-lps, max-cpb, max-dpb, max-br, max-tr, max-tc */
97 /* max-fps */
98
99 /* sprop-max-don-diff: 0-32767
100
101 When the RTP stream depends on one or more other RTP
102 streams (in this case tx-mode MUST be equal to "MSM" and
103 MSM is in use), this parameter MUST be present and the
104 value MUST be greater than 0.
105 */
106 if (!strcmp(attr, "sprop-max-don-diff")) {
107 if (atoi(value) > 0)
109 av_dlog(s,
"Found sprop-max-don-diff in SDP, DON field usage is: %d\n",
111 }
112
113 /* sprop-depack-buf-nalus: 0-32767 */
114 if (!strcmp(attr, "sprop-depack-buf-nalus")) {
115 if (atoi(value) > 0)
117 av_dlog(s,
"Found sprop-depack-buf-nalus in SDP, DON field usage is: %d\n",
119 }
120
121 /* sprop-depack-buf-bytes: 0-4294967295 */
122 /* depack-buf-cap */
123 /* sprop-segmentation-id: 0-3 */
124 /* sprop-spatial-segmentation-idc: [base16] */
125 /* dec-parallel-ca: */
126 /* include-dph */
127
128 return 0;
129 }
130
133 {
136 const char *sdp_line_ptr = line;
137
138 if (st_index < 0)
139 return 0;
140
141 current_stream = ctx->
streams[st_index];
142 codec = current_stream->
codec;
143
144 if (
av_strstart(sdp_line_ptr,
"framesize:", &sdp_line_ptr)) {
146 }
else if (
av_strstart(sdp_line_ptr,
"fmtp:", &sdp_line_ptr)) {
159 } else {
160 int pos = 0;
170 }
171
180 }
182 }
183
184 return 0;
185 }
186
191 {
193 int tid, lid, nal_type;
194 int first_fragment, last_fragment, fu_type;
196 int res = 0;
197
198 /* sanity check for size of input packet: 1 byte payload at least */
202 }
203
204 /*
205 * decode the HEVC payload header according to section 4 of draft version 6:
206 *
207 * 0 1
208 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
209 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
210 * |F| Type | LayerId | TID |
211 * +-------------+-----------------+
212 *
213 * Forbidden zero (F): 1 bit
214 * NAL unit type (Type): 6 bits
215 * NUH layer ID (LayerId): 6 bits
216 * NUH temporal ID plus 1 (TID): 3 bits
217 */
218 nal_type = (buf[0] >> 1) & 0x3f;
219 lid = ((buf[0] << 5) & 0x20) | ((buf[1] >> 3) & 0x1f);
220 tid = buf[1] & 0x07;
221
222 /* sanity check for correct layer ID */
223 if (lid) {
224 /* future scalable or 3D video coding extensions */
227 }
228
229 /* sanity check for correct temporal ID */
230 if (!tid) {
233 }
234
235 /* sanity check for correct NAL unit type */
236 if (nal_type > 50) {
239 }
240
241 switch (nal_type) {
242 /* video parameter set (VPS) */
243 case 32:
244 /* sequence parameter set (SPS) */
245 case 33:
246 /* picture parameter set (PPS) */
247 case 34:
248 /* supplemental enhancement information (SEI) */
249 case 39:
250 /* single NAL unit packet */
251 default:
252 /* sanity check for size of input packet: 1 byte payload at least */
253 if (len < 1) {
255 "Too short RTP/HEVC packet, got %d bytes of NAL unit type %d\n",
256 len, nal_type);
258 }
259
260 /* create A/V packet */
262 return res;
263 /* A/V packet: copy start sequence */
265 /* A/V packet: copy NAL unit data */
267
268 break;
269 /* aggregated packet (AP) - with two or more NAL units */
270 case 48:
271 /* pass the HEVC payload header */
274
275 /* pass the HEVC DONL field */
279 }
280
285 if (res < 0)
286 return res;
287 break;
288 /* fragmentation unit (FU) */
289 case 49:
290 /* pass the HEVC payload header */
293
294 /*
295 * decode the FU header
296 *
297 * 0 1 2 3 4 5 6 7
298 * +-+-+-+-+-+-+-+-+
299 * |S|E| FuType |
300 * +---------------+
301 *
302 * Start fragment (S): 1 bit
303 * End fragment (E): 1 bit
304 * FuType: 6 bits
305 */
306 first_fragment = buf[0] & 0x80;
307 last_fragment = buf[0] & 0x40;
308 fu_type = buf[0] & 0x3f;
309
310 /* pass the HEVC FU header */
313
314 /* pass the HEVC DONL field */
318 }
319
320 av_dlog(ctx,
" FU type %d with %d bytes\n", fu_type, len);
321
322 /* sanity check for size of input packet: 1 byte payload at least */
323 if (len <= 0) {
324 if (len < 0) {
326 "Too short RTP/HEVC packet, got %d bytes of NAL unit type %d\n",
327 len, nal_type);
329 } else {
331 }
332 }
333
334 if (first_fragment && last_fragment) {
337 }
338
339 new_nal_header[0] = (rtp_pl[0] & 0x81) | (fu_type << 1);
340 new_nal_header[1] = rtp_pl[1];
341
343 new_nal_header, sizeof(new_nal_header));
344
345 break;
346 /* PACI packet */
347 case 50:
348 /* Temporal scalability control information (TSCI) */
351 break;
352 }
353
355
356 return res;
357 }
358
367 };