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
29
36
39 unsigned int pgroup;
/* size of the pixel group in bytes */
41
43 };
44
46 {
50
51 if (!strncmp(
data->sampling,
"YCbCr-4:2:2", 11)) {
54
55 if (
data->depth == 8) {
59 }
else if (
data->depth == 10) {
63 } else {
65 }
66 }
else if (!strncmp(
data->sampling,
"YCbCr-4:2:0", 11)) {
69
70 if (
data->depth == 8) {
74 } else {
76 }
77 }
else if (!strncmp(
data->sampling,
"RGB", 3)) {
79 if (
data->depth == 8) {
84 } else {
86 }
87 }
else if (!strncmp(
data->sampling,
"BGR", 3)) {
89 if (
data->depth == 8) {
94 } else {
96 }
97 } else {
99 }
100
106
107 if (
data->framerate.den > 0) {
110 }
111
112 return 0;
113 }
114
118 {
119 if (!strncmp(attr, "width", 5))
121 else if (!strncmp(attr, "height", 6))
123 else if (!strncmp(attr, "sampling", 8))
125 else if (!strncmp(attr, "depth", 5))
127 else if (!strncmp(attr, "exactframerate", 14)) {
130 } else if (!strncmp(attr, "TCS", 3)) {
131 if (!strncmp(
value,
"SDR", 3))
133 else if (!strncmp(
value,
"PQ", 2))
135 else if (!strncmp(
value,
"HLG", 3))
137 else if (!strncmp(
value,
"LINEAR", 6))
139 else if (!strncmp(
value,
"ST428-1", 7))
141 else
143 } else if (!strncmp(attr, "colorimetry", 11)) {
144 if (!strncmp(
value,
"BT601", 5)) {
147 }
else if (!strncmp(
value,
"BT709", 5)) {
150 }
else if (!strncmp(
value,
"BT2020", 6)) {
153 }
154 } else if (!strncmp(attr, "RANGE", 5)) {
155 if (!strncmp(
value,
"NARROW", 6))
157 else if (!strncmp(
value,
"FULL", 4))
159 }
160
161 return 0;
162 }
163
166 {
167 const char *p;
168
169 if (st_index < 0)
170 return 0;
171
175
178
179
182
185
188
190 }
191
192 return 0;
193 }
194
196 int stream_index)
197 {
199
204 }
205
207
209 }
210
213 const uint8_t * buf,
int len,
214 uint16_t seq,
int flags)
215 {
217 const uint8_t *
headers = buf + 2;
/* skip extended seqnum */
218 const uint8_t *payload = buf + 2;
219 int payload_len =
len - 2;
220 int missed_last_packet = 0;
221
222 uint8_t *dest;
223
224 if (*timestamp !=
data->timestamp) {
226 /*
227 * if we're here, it means that two RTP packets didn't have the
228 * same timestamp, which is a sign that they were packets from two
229 * different frames, but we didn't get the flag RTP_FLAG_MARKER on
230 * the first one of these frames (last packet of a frame).
231 * Finalize the previous frame anyway by filling the AVPacket.
232 */
234 missed_last_packet = 1;
236 }
237
239
240 data->timestamp = *timestamp;
241
245 }
246 }
247
248 /*
249 * looks for the 'Continuation bit' in scan lines' headers
250 * to find where data start
251 */
252 do {
253 if (payload_len < 6)
255
256 cont = payload[4] & 0x80;
257 payload += 6;
258 payload_len -= 6;
259 } while (cont);
260
261 /* and now iterate over every scan lines */
262 do {
263 int copy_offset;
264
265 if (payload_len < data->pgroup)
267
273
274 if (!
data->pgroup || length %
data->pgroup)
276
277 if (length > payload_len)
278 length = payload_len;
279
280 /* prevent ill-formed packets to write after buffer's end */
282 if (copy_offset + length >
data->frame_size)
284
285 dest =
data->frame + copy_offset;
286 memcpy(dest, payload, length);
287
288 payload += length;
289 payload_len -= length;
290 } while (cont);
291
294 } else if (missed_last_packet) {
295 return 0;
296 }
297
299 }
300
308 };