1 /*
2 * RTP Depacketization of RAW video (TR-03)
3 * Copyright (c) 2016 Savoir-faire Linux, Inc
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 /* Development sponsored by CBC/Radio-Canada */
23
30
39
42 unsigned int pgroup;
/* size of the pixel group in bytes */
44
46 };
47
49 {
53
54 if (!strncmp(
data->sampling,
"YCbCr-4:2:2", 11)) {
57
58 if (
data->depth == 8) {
62 }
else if (
data->depth == 10) {
66 } else {
68 }
69 }
else if (!strncmp(
data->sampling,
"YCbCr-4:2:0", 11)) {
72
73 if (
data->depth == 8) {
77 } else {
79 }
80 }
else if (!strncmp(
data->sampling,
"RGB", 3)) {
82 if (
data->depth == 8) {
87 } else {
89 }
90 }
else if (!strncmp(
data->sampling,
"BGR", 3)) {
92 if (
data->depth == 8) {
97 } else {
99 }
100 } else {
102 }
103
109
110 if (
data->interlaced)
112 else
114
115 if (
data->framerate.den > 0) {
118 }
119
120 return 0;
121 }
122
126 {
127 if (!strncmp(attr, "width", 5))
129 else if (!strncmp(attr, "height", 6))
131 else if (!strncmp(attr, "sampling", 8))
133 else if (!strncmp(attr, "depth", 5))
135 else if (!strncmp(attr, "interlace", 9))
136 data->interlaced = 1;
137 else if (!strncmp(attr, "exactframerate", 14)) {
140 } else if (!strncmp(attr, "TCS", 3)) {
141 if (!strncmp(
value,
"SDR", 3))
143 else if (!strncmp(
value,
"PQ", 2))
145 else if (!strncmp(
value,
"HLG", 3))
147 else if (!strncmp(
value,
"LINEAR", 6))
149 else if (!strncmp(
value,
"ST428-1", 7))
151 else
153 } else if (!strncmp(attr, "colorimetry", 11)) {
154 if (!strncmp(
value,
"BT601", 5)) {
157 }
else if (!strncmp(
value,
"BT709", 5)) {
160 }
else if (!strncmp(
value,
"BT2020", 6)) {
163 }
164 } else if (!strncmp(attr, "RANGE", 5)) {
165 if (!strncmp(
value,
"NARROW", 6))
167 else if (!strncmp(
value,
"FULL", 4))
169 }
170
171 return 0;
172 }
173
176 {
178
179 if (st_index < 0)
180 return 0;
181
185
188
189
192
195
198
200 }
201
202 return 0;
203 }
204
206 int stream_index)
207 {
209
211 if (!
data->interlaced ||
data->field) {
215 }
217 }
218
220
222 }
223
226 const uint8_t * buf,
int len,
227 uint16_t seq,
int flags)
228 {
230 const uint8_t *
headers = buf + 2;
/* skip extended seqnum */
231 const uint8_t *payload = buf + 2;
232 int payload_len =
len - 2;
233 int missed_last_packet = 0;
234
235 uint8_t *dest;
236
237 if (*timestamp !=
data->timestamp) {
238 if (
data->frame && (!
data->interlaced ||
data->field)) {
239 /*
240 * if we're here, it means that we missed the cue to return
241 * the previous AVPacket, that cue being the RTP_FLAG_MARKER
242 * in the last packet of either the previous frame (progressive)
243 * or the previous second field (interlace). Let's finalize the
244 * previous frame (or pair of fields) anyway by filling the AVPacket.
245 */
247 missed_last_packet = 1;
249 }
250
253
254 data->timestamp = *timestamp;
255
259 }
260 }
261
262 /*
263 * looks for the 'Continuation bit' in scan lines' headers
264 * to find where data start
265 */
266 do {
267 if (payload_len < 6)
269
270 cont = payload[4] & 0x80;
271 payload += 6;
272 payload_len -= 6;
273 } while (cont);
274
275 /* and now iterate over every scan lines */
276 do {
277 int copy_offset;
278
279 if (payload_len < data->pgroup)
281
289
290 if (!
data->pgroup || length %
data->pgroup)
292
293 if (length > payload_len)
294 length = payload_len;
295
296 if (
data->interlaced)
298
299 /* prevent ill-formed packets to write after buffer's end */
301 if (copy_offset + length >
data->frame_size || !
data->frame)
303
304 dest =
data->frame + copy_offset;
305 memcpy(dest, payload, length);
306
307 payload += length;
308 payload_len -= length;
309 } while (cont);
310
313 } else if (missed_last_packet) {
314 return 0;
315 }
316
318 }
319
327 };