Debian Codegraph @

gst/isomp4/gstrtpxqtdepay.c

raw symbols SCIP
1 /* GStreamer
2 * Copyright (C) <2006> Wim Taymans <[email protected]>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /*
21 * based on http://developer.apple.com/quicktime/icefloe/dispatch026.html
22 */
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26
27 #include <gst/rtp/gstrtpbuffer.h>
28
29 #include <string.h>
30 #include "gstisomp4elements.h"
31 #include "gstrtpxqtdepay.h"
32
33 #define MAKE_TLV(a,b) (((a)<<8)|(b))
34
35 #define TLV_sd MAKE_TLV ('s','d')
36 #define TLV_qt MAKE_TLV ('q','t')
37 #define TLV_ti MAKE_TLV ('t','i')
38 #define TLV_ly MAKE_TLV ('l','y')
39 #define TLV_vo MAKE_TLV ('v','o')
40 #define TLV_mx MAKE_TLV ('m','x')
41 #define TLV_tr MAKE_TLV ('t','r')
42 #define TLV_tw MAKE_TLV ('t','w')
43 #define TLV_th MAKE_TLV ('t','h')
44 #define TLV_la MAKE_TLV ('l','a')
45 #define TLV_rt MAKE_TLV ('r','t')
46 #define TLV_gm MAKE_TLV ('g','m')
47 #define TLV_oc MAKE_TLV ('o','c')
48 #define TLV_cr MAKE_TLV ('c','r')
49 #define TLV_du MAKE_TLV ('d','u')
50 #define TLV_po MAKE_TLV ('p','o')
51
52 #define QT_UINT32(a) (GST_READ_UINT32_BE(a))
53 #define QT_UINT24(a) (GST_READ_UINT32_BE(a) >> 8)
54 #define QT_UINT16(a) (GST_READ_UINT16_BE(a))
55 #define QT_UINT8(a) (GST_READ_UINT8(a))
56 #define QT_FP32(a) ((GST_READ_UINT32_BE(a))/65536.0)
57 #define QT_FP16(a) ((GST_READ_UINT16_BE(a))/256.0)
58 #define QT_FOURCC(a) (GST_READ_UINT32_LE(a))
59 #define QT_UINT64(a) ((((guint64)QT_UINT32(a))<<32)|QT_UINT32(((guint8 *)a)+4))
60
61 #define FOURCC_avc1 GST_MAKE_FOURCC('a','v','c','1')
62 #define FOURCC_avc3 GST_MAKE_FOURCC('a','v','c','3')
63 #define FOURCC_avcC GST_MAKE_FOURCC('a','v','c','C')
64
65 GST_DEBUG_CATEGORY_STATIC (rtpxqtdepay_debug);
66 #define GST_CAT_DEFAULT (rtpxqtdepay_debug)
67
68 /* RtpXQTDepay signals and args */
69 enum
70 {
71 /* FILL ME */
72 LAST_SIGNAL
73 };
74
75 enum
76 {
77 PROP_0,
78 };
79
80 static GstStaticPadTemplate gst_rtp_xqt_depay_src_template =
81 GST_STATIC_PAD_TEMPLATE ("src",
82 GST_PAD_SRC,
83 GST_PAD_ALWAYS,
84 GST_STATIC_CAPS_ANY);
85
86 static GstStaticPadTemplate gst_rtp_xqt_depay_sink_template =
87 GST_STATIC_PAD_TEMPLATE ("sink",
88 GST_PAD_SINK,
89 GST_PAD_ALWAYS,
90 GST_STATIC_CAPS ("application/x-rtp, "
91 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
92 "media = (string) { \"audio\", \"video\" }, clock-rate = (int) [1, MAX], "
93 "encoding-name = (string) { \"X-QT\", \"X-QUICKTIME\" }")
94 );
95
96 #define gst_rtp_xqt_depay_parent_class parent_class
97 G_DEFINE_TYPE (GstRtpXQTDepay, gst_rtp_xqt_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
98 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtpxqtdepay, "rtpxqtdepay",
99 GST_RANK_MARGINAL, GST_TYPE_RTP_XQT_DEPAY, isomp4_element_init (plugin));
100
101 static void gst_rtp_xqt_depay_finalize (GObject * object);
102
103 static gboolean gst_rtp_xqt_depay_setcaps (GstRTPBaseDepayload * depayload,
104 GstCaps * caps);
105 static GstBuffer *gst_rtp_xqt_depay_process (GstRTPBaseDepayload * depayload,
106 GstBuffer * buf);
107
108 static GstStateChangeReturn gst_rtp_xqt_depay_change_state (GstElement *
109 element, GstStateChange transition);
110
111
112 static void
113 gst_rtp_xqt_depay_class_init (GstRtpXQTDepayClass * klass)
114 {
115 GObjectClass *gobject_class;
116 GstElementClass *gstelement_class;
117 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
118
119 gobject_class = (GObjectClass *) klass;
120 gstelement_class = (GstElementClass *) klass;
121 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
122
123 parent_class = g_type_class_peek_parent (klass);
124
125 gobject_class->finalize = gst_rtp_xqt_depay_finalize;
126
127 gstelement_class->change_state = gst_rtp_xqt_depay_change_state;
128
129 gstrtpbasedepayload_class->set_caps = gst_rtp_xqt_depay_setcaps;
130 gstrtpbasedepayload_class->process = gst_rtp_xqt_depay_process;
131
132 GST_DEBUG_CATEGORY_INIT (rtpxqtdepay_debug, "rtpxqtdepay", 0,
133 "QT Media RTP Depayloader");
134
135 gst_element_class_add_static_pad_template (gstelement_class,
136 &gst_rtp_xqt_depay_src_template);
137 gst_element_class_add_static_pad_template (gstelement_class,
138 &gst_rtp_xqt_depay_sink_template);
139
140 gst_element_class_set_static_metadata (gstelement_class,
141 "RTP packet depayloader", "Codec/Depayloader/Network",
142 "Extracts Quicktime audio/video from RTP packets",
143 "Wim Taymans <[email protected]>");
144 }
145
146 static void
147 gst_rtp_xqt_depay_init (GstRtpXQTDepay * rtpxqtdepay)
148 {
149 gst_rtp_base_depayload_set_aggregate_hdrext_enabled (GST_RTP_BASE_DEPAYLOAD
150 (rtpxqtdepay), TRUE);
151
152 rtpxqtdepay->adapter = gst_adapter_new ();
153 }
154
155 static void
156 gst_rtp_xqt_depay_finalize (GObject * object)
157 {
158 GstRtpXQTDepay *rtpxqtdepay;
159
160 rtpxqtdepay = GST_RTP_XQT_DEPAY (object);
161
162 g_object_unref (rtpxqtdepay->adapter);
163 rtpxqtdepay->adapter = NULL;
164
165 G_OBJECT_CLASS (parent_class)->finalize (object);
166 }
167
168 static gboolean
169 gst_rtp_quicktime_parse_sd (GstRtpXQTDepay * rtpxqtdepay, guint8 * data,
170 guint data_len)
171 {
172 gint len;
173 guint32 fourcc;
174
175 if (data_len < 8)
176 goto too_short;
177
178 len = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
179 if (len > data_len)
180 goto too_short;
181
182 fourcc = QT_FOURCC (data + 4);
183
184 GST_DEBUG_OBJECT (rtpxqtdepay, "parsing %" GST_FOURCC_FORMAT,
185 GST_FOURCC_ARGS (fourcc));
186
187 switch (fourcc) {
188 case FOURCC_avc1:
189 case FOURCC_avc3:
190 {
191 guint32 chlen;
192
193 if (len < 0x56)
194 goto too_short;
195 len -= 0x56;
196 data += 0x56;
197
198 /* find avcC */
199 while (len >= 8) {
200 chlen = QT_UINT32 (data);
201 fourcc = QT_FOURCC (data + 4);
202 if (fourcc == FOURCC_avcC) {
203 GstBuffer *buf;
204 gint size;
205 GstCaps *caps;
206
207 GST_DEBUG_OBJECT (rtpxqtdepay, "found avcC codec_data in sd, %u",
208 chlen);
209
210 /* parse, if found */
211 if (chlen < len)
212 size = chlen - 8;
213 else
214 size = len - 8;
215
216 buf = gst_buffer_new_and_alloc (size);
217 gst_buffer_fill (buf, 0, data + 8, size);
218 caps = gst_caps_new_simple ("video/x-h264",
219 "codec_data", GST_TYPE_BUFFER, buf, NULL);
220 gst_buffer_unref (buf);
221 gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD (rtpxqtdepay)->srcpad, caps);
222 gst_caps_unref (caps);
223 break;
224 }
225 len -= chlen;
226 data += chlen;
227 }
228 break;
229 }
230 default:
231 break;
232 }
233 return TRUE;
234
235 /* ERRORS */
236 too_short:
237 {
238 return FALSE;
239 }
240 }
241
242 static gboolean
243 gst_rtp_xqt_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
244 {
245 GstStructure *structure;
246 gint clock_rate = 90000; /* default */
247
248 structure = gst_caps_get_structure (caps, 0);
249
250 gst_structure_get_int (structure, "clock-rate", &clock_rate);
251 depayload->clock_rate = clock_rate;
252
253 return TRUE;
254 }
255
256 static GstBuffer *
257 gst_rtp_xqt_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
258 {
259 GstRtpXQTDepay *rtpxqtdepay;
260 GstBuffer *outbuf = NULL;
261 gboolean m;
262 GstRTPBuffer rtp = { NULL };
263
264 rtpxqtdepay = GST_RTP_XQT_DEPAY (depayload);
265
266 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
267
268 if (GST_BUFFER_IS_DISCONT (buf)) {
269 /* discont, clear adapter and try to find a new packet start */
270 gst_adapter_clear (rtpxqtdepay->adapter);
271 rtpxqtdepay->need_resync = TRUE;
272 GST_DEBUG_OBJECT (rtpxqtdepay, "we need resync");
273 }
274
275 m = gst_rtp_buffer_get_marker (&rtp);
276 GST_LOG_OBJECT (rtpxqtdepay, "marker: %d", m);
277
278 {
279 gint payload_len;
280 guint avail;
281 guint8 *payload;
282 guint8 ver, pck;
283 gboolean s, q, l, d;
284
285 payload_len = gst_rtp_buffer_get_payload_len (&rtp);
286 payload = gst_rtp_buffer_get_payload (&rtp);
287
288 /* 1 2 3
289 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
290 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
291 * | VER |PCK|S|Q|L| RES |D| QuickTime Payload ID |
292 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
293 */
294 if (payload_len <= 4)
295 goto wrong_length;
296
297 ver = (payload[0] & 0xf0) >> 4;
298 if (ver > 1)
299 goto wrong_version;
300
301 pck = (payload[0] & 0x0c) >> 2;
302 if (pck == 0)
303 goto pck_reserved;
304
305 s = (payload[0] & 0x02) != 0; /* contains sync sample */
306 q = (payload[0] & 0x01) != 0; /* has payload description */
307 l = (payload[1] & 0x80) != 0; /* has packet specific information description */
308 d = (payload[2] & 0x80) != 0; /* don't cache info for payload id */
309 /* id used for caching info */
310 rtpxqtdepay->current_id = ((payload[2] & 0x7f) << 8) | payload[3];
311
312 GST_LOG_OBJECT (rtpxqtdepay,
313 "VER: %d, PCK: %d, S: %d, Q: %d, L: %d, D: %d, ID: %d", ver, pck, s, q,
314 l, d, rtpxqtdepay->current_id);
315
316 if (rtpxqtdepay->need_resync) {
317 /* we need to find the boundary of a new packet after a DISCONT */
318 if (pck != 3 || q) {
319 /* non-fragmented packet or payload description present, packet starts
320 * here. */
321 rtpxqtdepay->need_resync = FALSE;
322 } else {
323 /* fragmented packet without description */
324 if (m) {
325 /* marker bit set, next packet is start of new one */
326 rtpxqtdepay->need_resync = FALSE;
327 }
328 goto need_resync;
329 }
330 }
331
332 payload += 4;
333 payload_len -= 4;
334
335 if (q) {
336 gboolean k, f, a, z;
337 guint pdlen, pdpadded;
338 gint padding;
339 /* media_type only used for printing */
340 guint32 G_GNUC_UNUSED media_type;
341 guint32 timescale;
342
343 /* 1 2 3
344 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
345 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
346 * |K|F|A|Z| RES | QuickTime Payload Desc Length |
347 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
348 * . QuickTime Payload Desc Data ... .
349 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
350 */
351 if (payload_len <= 4)
352 goto wrong_length;
353
354 k = (payload[0] & 0x80) != 0; /* keyframe */
355 f = (payload[0] & 0x40) != 0; /* sparse */
356 a = (payload[0] & 0x20) != 0; /* start of payload */
357 z = (payload[0] & 0x10) != 0; /* end of payload */
358 pdlen = (payload[2] << 8) | payload[3];
359
360 if (pdlen < 12)
361 goto wrong_length;
362
363 /* calc padding */
364 pdpadded = pdlen + 3;
365 pdpadded -= pdpadded % 4;
366 if (payload_len < pdpadded)
367 goto wrong_length;
368
369 padding = pdpadded - pdlen;
370 GST_LOG_OBJECT (rtpxqtdepay,
371 "K: %d, F: %d, A: %d, Z: %d, len: %d, padding %d", k, f, a, z, pdlen,
372 padding);
373
374 payload += 4;
375 payload_len -= 4;
376 /* 1 2 3
377 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
378 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
379 * | QuickTime Media Type |
380 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
381 * | Timescale |
382 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
383 * . QuickTime TLVs ... .
384 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
385 */
386 media_type =
387 (payload[0] << 24) | (payload[1] << 16) | (payload[2] << 8) |
388 payload[3];
389 timescale =
390 (payload[4] << 24) | (payload[5] << 16) | (payload[6] << 8) |
391 payload[7];
392
393 GST_LOG_OBJECT (rtpxqtdepay, "media_type: %c%c%c%c, timescale %u",
394 payload[0], payload[1], payload[2], payload[3], timescale);
395
396 payload += 8;
397 payload_len -= 8;
398 pdlen -= 12;
399
400 /* parse TLV (type-length-value triplets */
401 while (pdlen > 3) {
402 guint16 tlv_len, tlv_type;
403
404 /* 1 2 3
405 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
406 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
407 * | QuickTime TLV Length | QuickTime TLV Type |
408 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
409 * . QuickTime TLV Value ... .
410 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
411 */
412 tlv_len = (payload[0] << 8) | payload[1];
413 tlv_type = (payload[2] << 8) | payload[3];
414 pdlen -= 4;
415 if (tlv_len > pdlen)
416 goto wrong_length;
417
418 GST_LOG_OBJECT (rtpxqtdepay, "TLV '%c%c', len %d", payload[2],
419 payload[3], tlv_len);
420
421 payload += 4;
422 payload_len -= 4;
423
424 switch (tlv_type) {
425 case TLV_sd:
426 /* Session description */
427 if (!gst_rtp_quicktime_parse_sd (rtpxqtdepay, payload, tlv_len))
428 goto unknown_format;
429 rtpxqtdepay->have_sd = TRUE;
430 break;
431 case TLV_qt:
432 case TLV_ti:
433 case TLV_ly:
434 case TLV_vo:
435 case TLV_mx:
436 case TLV_tr:
437 case TLV_tw:
438 case TLV_th:
439 case TLV_la:
440 case TLV_rt:
441 case TLV_gm:
442 case TLV_oc:
443 case TLV_cr:
444 case TLV_du:
445 case TLV_po:
446 default:
447 break;
448 }
449
450 pdlen -= tlv_len;
451 payload += tlv_len;
452 payload_len -= tlv_len;
453 }
454 payload += padding;
455 payload_len -= padding;
456 }
457
458 if (l) {
459 guint ssilen, ssipadded;
460 gint padding;
461
462 /* 1 2 3
463 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
464 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
465 * | RES | Sample-Specific Info Length |
466 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
467 * . QuickTime TLVs ...
468 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
469 */
470 if (payload_len <= 4)
471 goto wrong_length;
472
473 ssilen = (payload[2] << 8) | payload[3];
474 if (ssilen < 4)
475 goto wrong_length;
476
477 /* calc padding */
478 ssipadded = ssilen + 3;
479 ssipadded -= ssipadded % 4;
480 if (payload_len < ssipadded)
481 goto wrong_length;
482
483 padding = ssipadded - ssilen;
484 GST_LOG_OBJECT (rtpxqtdepay, "len: %d, padding %d", ssilen, padding);
485
486 payload += 4;
487 payload_len -= 4;
488 ssilen -= 4;
489
490 /* parse TLV (type-length-value triplets */
491 while (ssilen > 3) {
492 guint16 tlv_len, tlv_type;
493
494 /* 1 2 3
495 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
496 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
497 * | QuickTime TLV Length | QuickTime TLV Type |
498 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
499 * . QuickTime TLV Value ... .
500 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
501 */
502 tlv_len = (payload[0] << 8) | payload[1];
503 tlv_type = (payload[2] << 8) | payload[3];
504 ssilen -= 4;
505 if (tlv_len > ssilen)
506 goto wrong_length;
507
508 GST_LOG_OBJECT (rtpxqtdepay, "TLV '%c%c', len %d", payload[2],
509 payload[3], tlv_len);
510
511 payload += 4;
512 payload_len -= 4;
513
514 switch (tlv_type) {
515 case TLV_sd:
516 case TLV_qt:
517 case TLV_ti:
518 case TLV_ly:
519 case TLV_vo:
520 case TLV_mx:
521 case TLV_tr:
522 case TLV_tw:
523 case TLV_th:
524 case TLV_la:
525 case TLV_rt:
526 case TLV_gm:
527 case TLV_oc:
528 case TLV_cr:
529 case TLV_du:
530 case TLV_po:
531 default:
532 break;
533 }
534
535 ssilen -= tlv_len;
536 payload += tlv_len;
537 payload_len -= tlv_len;
538 }
539 payload += padding;
540 payload_len -= padding;
541 }
542
543 rtpxqtdepay->previous_id = rtpxqtdepay->current_id;
544
545 switch (pck) {
546 case 1:
547 {
548 /* multiple samples per packet. */
549 outbuf = gst_buffer_new_and_alloc (payload_len);
550 gst_buffer_fill (outbuf, 0, payload, payload_len);
551
552 goto done;
553 }
554 case 2:
555 {
556 guint slen;
557 GstBufferList *outbufs = NULL;
558
559 /* multiple samples per packet.
560 * 1 2 3
561 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
562 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
563 * |S| Reserved | Sample Length |
564 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
565 * | Sample Timestamp |
566 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
567 * . Sample Data ... .
568 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
569 * |S| Reserved | Sample Length |
570 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
571 * | Sample Timestamp |
572 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
573 * . Sample Data ... .
574 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
575 * . ...... .
576 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
577 */
578 outbufs = gst_buffer_list_new ();
579 while (payload_len > 8) {
580 s = (payload[0] & 0x80) != 0; /* contains sync sample */
581 slen = (payload[2] << 8) | payload[3];
582 /* timestamp =
583 * (payload[4] << 24) | (payload[5] << 16) | (payload[6] << 8) |
584 * payload[7];
585 */
586
587 payload += 8;
588 payload_len -= 8;
589
590 if (slen > payload_len)
591 slen = payload_len;
592
593 outbuf = gst_buffer_new_and_alloc (slen);
594 gst_buffer_fill (outbuf, 0, payload, slen);
595 if (!s)
596 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
597
598 gst_buffer_list_add (outbufs, outbuf);
599
600 /* aligned on 32 bit boundary */
601 slen = GST_ROUND_UP_4 (slen);
602
603 payload += slen;
604 payload_len -= slen;
605 }
606 gst_rtp_base_depayload_push_list (depayload, outbufs);
607 outbuf = NULL;
608 break;
609 }
610 case 3:
611 {
612 /* one sample per packet, use adapter to combine based on marker bit. */
613 outbuf = gst_buffer_new_and_alloc (payload_len);
614 gst_buffer_fill (outbuf, 0, payload, payload_len);
615
616 gst_adapter_push (rtpxqtdepay->adapter, outbuf);
617 outbuf = NULL;
618
619 if (!m)
620 goto done;
621
622 avail = gst_adapter_available (rtpxqtdepay->adapter);
623 outbuf = gst_adapter_take_buffer (rtpxqtdepay->adapter, avail);
624
625 GST_DEBUG_OBJECT (rtpxqtdepay,
626 "gst_rtp_xqt_depay_chain: pushing buffer of size %u", avail);
627
628 goto done;
629 }
630 }
631 }
632
633 done:
634 gst_rtp_buffer_unmap (&rtp);
635 return outbuf;
636
637 need_resync:
638 {
639 GST_DEBUG_OBJECT (rtpxqtdepay, "waiting for marker");
640 gst_rtp_base_depayload_dropped (depayload);
641 goto done;
642 }
643 wrong_version:
644 {
645 GST_ELEMENT_WARNING (rtpxqtdepay, STREAM, DECODE,
646 ("Unknown payload version."), (NULL));
647 gst_rtp_base_depayload_dropped (depayload);
648 goto done;
649 }
650 pck_reserved:
651 {
652 GST_ELEMENT_WARNING (rtpxqtdepay, STREAM, DECODE,
653 ("PCK reserved 0."), (NULL));
654 gst_rtp_base_depayload_dropped (depayload);
655 goto done;
656 }
657 wrong_length:
658 {
659 GST_ELEMENT_WARNING (rtpxqtdepay, STREAM, DECODE,
660 ("Wrong payload length."), (NULL));
661 gst_rtp_base_depayload_dropped (depayload);
662 goto done;
663 }
664 unknown_format:
665 {
666 GST_ELEMENT_WARNING (rtpxqtdepay, STREAM, DECODE,
667 ("Unknown payload format."), (NULL));
668 gst_rtp_base_depayload_dropped (depayload);
669 goto done;
670 }
671 }
672
673 static GstStateChangeReturn
674 gst_rtp_xqt_depay_change_state (GstElement * element, GstStateChange transition)
675 {
676 GstRtpXQTDepay *rtpxqtdepay;
677 GstStateChangeReturn ret;
678
679 rtpxqtdepay = GST_RTP_XQT_DEPAY (element);
680
681 switch (transition) {
682 case GST_STATE_CHANGE_READY_TO_PAUSED:
683 gst_adapter_clear (rtpxqtdepay->adapter);
684 rtpxqtdepay->previous_id = -1;
685 rtpxqtdepay->current_id = -1;
686 rtpxqtdepay->need_resync = TRUE;
687 rtpxqtdepay->have_sd = FALSE;
688 break;
689 default:
690 break;
691 }
692
693 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
694
695 switch (transition) {
696 case GST_STATE_CHANGE_PAUSED_TO_READY:
697 gst_adapter_clear (rtpxqtdepay->adapter);
698 default:
699 break;
700 }
701 return ret;
702 }