2 * Copyright (C) <2006> Wim Taymans <wim.taymans@gmail.com>
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.
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.
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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 #include <gst/rtp/gstrtpbuffer.h>
29 #include "gstrtptheorapay.h"
31 #define THEORA_ID_LEN 42
33 GST_DEBUG_CATEGORY_STATIC (rtptheorapay_debug);
34 #define GST_CAT_DEFAULT (rtptheorapay_debug)
37 * http://svn.xiph.org/trunk/theora/doc/draft-ietf-avt-rtp-theora-01.txt
40 static GstStaticPadTemplate gst_rtp_theora_pay_src_template =
41 GST_STATIC_PAD_TEMPLATE ("src",
44 GST_STATIC_CAPS ("application/x-rtp, "
45 "media = (string) \"video\", "
46 "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
47 "clock-rate = (int) 90000, " "encoding-name = (string) \"THEORA\""
48 /* All required parameters
50 * "sampling = (string) { "YCbCr-4:2:0", "YCbCr-4:2:2", "YCbCr-4:4:4" } "
51 * "width = (string) [1, 1048561] (multiples of 16) "
52 * "height = (string) [1, 1048561] (multiples of 16) "
53 * "configuration = (string) ANY"
55 /* All optional parameters
57 * "configuration-uri ="
58 * "delivery-method = (string) { inline, in_band, out_band/<specific_name> } "
63 static GstStaticPadTemplate gst_rtp_theora_pay_sink_template =
64 GST_STATIC_PAD_TEMPLATE ("sink",
67 GST_STATIC_CAPS ("video/x-theora")
70 #define DEFAULT_CONFIG_INTERVAL 0
78 GST_BOILERPLATE (GstRtpTheoraPay, gst_rtp_theora_pay, GstBaseRTPPayload,
79 GST_TYPE_BASE_RTP_PAYLOAD);
81 static gboolean gst_rtp_theora_pay_setcaps (GstBaseRTPPayload * basepayload,
83 static GstStateChangeReturn gst_rtp_theora_pay_change_state (GstElement *
84 element, GstStateChange transition);
85 static GstFlowReturn gst_rtp_theora_pay_handle_buffer (GstBaseRTPPayload * pad,
87 static gboolean gst_rtp_theora_pay_handle_event (GstPad * pad,
91 static void gst_rtp_theora_pay_set_property (GObject * object, guint prop_id,
92 const GValue * value, GParamSpec * pspec);
93 static void gst_rtp_theora_pay_get_property (GObject * object, guint prop_id,
94 GValue * value, GParamSpec * pspec);
97 gst_rtp_theora_pay_base_init (gpointer klass)
99 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
101 gst_element_class_add_static_pad_template (element_class,
102 &gst_rtp_theora_pay_src_template);
103 gst_element_class_add_static_pad_template (element_class,
104 &gst_rtp_theora_pay_sink_template);
106 gst_element_class_set_details_simple (element_class, "RTP Theora payloader",
107 "Codec/Payloader/Network/RTP",
108 "Payload-encode Theora video into RTP packets (draft-01 RFC XXXX)",
109 "Wim Taymans <wim.taymans@gmail.com>");
113 gst_rtp_theora_pay_class_init (GstRtpTheoraPayClass * klass)
115 GObjectClass *gobject_class;
116 GstElementClass *gstelement_class;
117 GstBaseRTPPayloadClass *gstbasertppayload_class;
119 gobject_class = (GObjectClass *) klass;
120 gstelement_class = (GstElementClass *) klass;
121 gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
123 gstelement_class->change_state = gst_rtp_theora_pay_change_state;
125 gstbasertppayload_class->set_caps = gst_rtp_theora_pay_setcaps;
126 gstbasertppayload_class->handle_buffer = gst_rtp_theora_pay_handle_buffer;
127 gstbasertppayload_class->handle_event = gst_rtp_theora_pay_handle_event;
129 gobject_class->set_property = gst_rtp_theora_pay_set_property;
130 gobject_class->get_property = gst_rtp_theora_pay_get_property;
132 GST_DEBUG_CATEGORY_INIT (rtptheorapay_debug, "rtptheorapay", 0,
133 "Theora RTP Payloader");
135 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CONFIG_INTERVAL,
136 g_param_spec_uint ("config-interval", "Config Send Interval",
137 "Send Config Insertion Interval in seconds (configuration headers "
138 "will be multiplexed in the data stream when detected.) (0 = disabled)",
139 0, 3600, DEFAULT_CONFIG_INTERVAL,
140 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
145 gst_rtp_theora_pay_init (GstRtpTheoraPay * rtptheorapay,
146 GstRtpTheoraPayClass * klass)
148 rtptheorapay->last_config = GST_CLOCK_TIME_NONE;
152 gst_rtp_theora_pay_clear_packet (GstRtpTheoraPay * rtptheorapay)
154 if (rtptheorapay->packet)
155 gst_buffer_unref (rtptheorapay->packet);
156 rtptheorapay->packet = NULL;
160 gst_rtp_theora_pay_cleanup (GstRtpTheoraPay * rtptheorapay)
162 g_list_foreach (rtptheorapay->headers, (GFunc) gst_mini_object_unref, NULL);
163 g_list_free (rtptheorapay->headers);
164 rtptheorapay->headers = NULL;
166 gst_rtp_theora_pay_clear_packet (rtptheorapay);
168 if (rtptheorapay->config_data)
169 g_free (rtptheorapay->config_data);
170 rtptheorapay->config_data = NULL;
171 rtptheorapay->last_config = GST_CLOCK_TIME_NONE;
175 gst_rtp_theora_pay_setcaps (GstBaseRTPPayload * basepayload, GstCaps * caps)
177 GstRtpTheoraPay *rtptheorapay;
179 rtptheorapay = GST_RTP_THEORA_PAY (basepayload);
181 rtptheorapay->need_headers = TRUE;
187 gst_rtp_theora_pay_reset_packet (GstRtpTheoraPay * rtptheorapay, guint8 TDT)
191 GST_DEBUG_OBJECT (rtptheorapay, "reset packet");
193 rtptheorapay->payload_pos = 4;
194 payload_len = gst_rtp_buffer_get_payload_len (rtptheorapay->packet);
195 rtptheorapay->payload_left = payload_len - 4;
196 rtptheorapay->payload_duration = 0;
197 rtptheorapay->payload_F = 0;
198 rtptheorapay->payload_TDT = TDT;
199 rtptheorapay->payload_pkts = 0;
203 gst_rtp_theora_pay_init_packet (GstRtpTheoraPay * rtptheorapay, guint8 TDT,
204 GstClockTime timestamp)
206 GST_DEBUG_OBJECT (rtptheorapay, "starting new packet, TDT: %d", TDT);
208 if (rtptheorapay->packet)
209 gst_buffer_unref (rtptheorapay->packet);
211 /* new packet allocate max packet size */
212 rtptheorapay->packet =
213 gst_rtp_buffer_new_allocate_len (GST_BASE_RTP_PAYLOAD_MTU
214 (rtptheorapay), 0, 0);
215 gst_rtp_theora_pay_reset_packet (rtptheorapay, TDT);
217 GST_BUFFER_TIMESTAMP (rtptheorapay->packet) = timestamp;
221 gst_rtp_theora_pay_flush_packet (GstRtpTheoraPay * rtptheorapay)
227 /* check for empty packet */
228 if (!rtptheorapay->packet || rtptheorapay->payload_pos <= 4)
231 GST_DEBUG_OBJECT (rtptheorapay, "flushing packet");
234 payload = gst_rtp_buffer_get_payload (rtptheorapay->packet);
237 * 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
238 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
239 * | Ident | F |TDT|# pkts.|
240 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
242 * F: Fragment type (0=none, 1=start, 2=cont, 3=end)
243 * TDT: Theora data type (0=theora, 1=config, 2=comment, 3=reserved)
244 * pkts: number of packets.
246 payload[0] = (rtptheorapay->payload_ident >> 16) & 0xff;
247 payload[1] = (rtptheorapay->payload_ident >> 8) & 0xff;
248 payload[2] = (rtptheorapay->payload_ident) & 0xff;
249 payload[3] = (rtptheorapay->payload_F & 0x3) << 6 |
250 (rtptheorapay->payload_TDT & 0x3) << 4 |
251 (rtptheorapay->payload_pkts & 0xf);
253 /* shrink the buffer size to the last written byte */
254 hlen = gst_rtp_buffer_calc_header_len (0);
255 GST_BUFFER_SIZE (rtptheorapay->packet) = hlen + rtptheorapay->payload_pos;
257 GST_BUFFER_DURATION (rtptheorapay->packet) = rtptheorapay->payload_duration;
259 /* push, this gives away our ref to the packet, so clear it. */
261 gst_basertppayload_push (GST_BASE_RTP_PAYLOAD (rtptheorapay),
262 rtptheorapay->packet);
263 rtptheorapay->packet = NULL;
269 gst_rtp_theora_pay_finish_headers (GstBaseRTPPayload * basepayload)
271 GstRtpTheoraPay *rtptheorapay = GST_RTP_THEORA_PAY (basepayload);
273 guint length, size, n_headers, configlen, extralen;
274 gchar *wstr, *hstr, *configuration;
275 guint8 *data, *config;
279 GST_DEBUG_OBJECT (rtptheorapay, "finish headers");
281 if (!rtptheorapay->headers) {
282 GST_DEBUG_OBJECT (rtptheorapay, "We need 2 headers but have none");
286 /* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
287 * | Number of packed headers |
288 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
289 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
291 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
292 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
294 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
295 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
297 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
299 * We only construct a config containing 1 packed header like this:
302 * 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
303 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
304 * | Ident | length ..
305 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
306 * .. | n. of headers | length1 | length2 ..
307 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
308 * .. | Identification Header ..
309 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
310 * .................................................................
311 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
312 * .. | Comment Header ..
313 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
314 * .................................................................
315 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
316 * .. Comment Header |
317 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
319 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
320 * .................................................................
321 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
323 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
326 /* we need 4 bytes for the number of headers (which is always 1), 3 bytes for
327 * the ident, 2 bytes for length, 1 byte for n. of headers. */
328 size = 4 + 3 + 2 + 1;
330 /* count the size of the headers first and update the hash */
333 ident = fnv1_hash_32_new ();
335 for (walk = rtptheorapay->headers; walk; walk = g_list_next (walk)) {
336 GstBuffer *buf = GST_BUFFER_CAST (walk->data);
340 bsize = GST_BUFFER_SIZE (buf);
344 /* count number of bytes needed for length fields, we don't need this for
345 * the last header. */
346 if (g_list_next (walk)) {
354 ident = fnv1_hash_32_update (ident, GST_BUFFER_DATA (buf),
355 GST_BUFFER_SIZE (buf));
358 /* packet length is header size + packet length */
359 configlen = size + length;
360 config = data = g_malloc (configlen);
362 /* number of packed headers, we only pack 1 header */
368 ident = fnv1_hash_32_to_24 (ident);
369 rtptheorapay->payload_ident = ident;
370 GST_DEBUG_OBJECT (rtptheorapay, "ident 0x%08x", ident);
372 /* take lower 3 bytes */
373 data[4] = (ident >> 16) & 0xff;
374 data[5] = (ident >> 8) & 0xff;
375 data[6] = ident & 0xff;
377 /* store length of all theora headers */
378 data[7] = ((length) >> 8) & 0xff;
379 data[8] = (length) & 0xff;
381 /* store number of headers minus one. */
382 data[9] = n_headers - 1;
385 /* store length for each header */
386 for (walk = rtptheorapay->headers; walk; walk = g_list_next (walk)) {
387 GstBuffer *buf = GST_BUFFER_CAST (walk->data);
389 guint bsize, size, temp;
392 /* only need to store the length when it's not the last header */
393 if (!g_list_next (walk))
396 bsize = GST_BUFFER_SIZE (buf);
406 bsize = GST_BUFFER_SIZE (buf);
407 /* write the size backwards */
411 data[size] = (bsize & 0x7f) | flag;
418 /* copy header data */
419 for (walk = rtptheorapay->headers; walk; walk = g_list_next (walk)) {
420 GstBuffer *buf = GST_BUFFER_CAST (walk->data);
422 memcpy (data, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
423 data += GST_BUFFER_SIZE (buf);
426 /* serialize to base64 */
427 configuration = g_base64_encode (config, configlen);
429 /* store for later re-sending */
430 rtptheorapay->config_size = configlen - 4 - 3 - 2;
431 rtptheorapay->config_data = g_malloc (rtptheorapay->config_size);
432 rtptheorapay->config_extra_len = extralen;
433 memcpy (rtptheorapay->config_data, config + 4 + 3 + 2,
434 rtptheorapay->config_size);
438 /* configure payloader settings */
439 wstr = g_strdup_printf ("%d", rtptheorapay->width);
440 hstr = g_strdup_printf ("%d", rtptheorapay->height);
441 gst_basertppayload_set_options (basepayload, "video", TRUE, "THEORA", 90000);
442 res = gst_basertppayload_set_outcaps (basepayload,
443 "sampling", G_TYPE_STRING, "YCbCr-4:2:0",
444 "width", G_TYPE_STRING, wstr,
445 "height", G_TYPE_STRING, hstr,
446 "configuration", G_TYPE_STRING, configuration,
447 "delivery-method", G_TYPE_STRING, "inline",
448 /* don't set the other defaults
453 g_free (configuration);
460 GST_DEBUG_OBJECT (rtptheorapay, "finish headers");
466 gst_rtp_theora_pay_parse_id (GstBaseRTPPayload * basepayload, guint8 * data,
469 GstRtpTheoraPay *rtptheorapay;
472 rtptheorapay = GST_RTP_THEORA_PAY (basepayload);
474 if (G_UNLIKELY (size < 42))
477 if (G_UNLIKELY (memcmp (data, "\200theora", 7)))
481 if (G_UNLIKELY (data[0] != 3))
482 goto invalid_version;
483 if (G_UNLIKELY (data[1] != 2))
484 goto invalid_version;
487 width = GST_READ_UINT16_BE (data) << 4;
489 height = GST_READ_UINT16_BE (data) << 4;
492 /* FIXME, parse pixel format */
495 rtptheorapay->width = width;
496 rtptheorapay->height = height;
503 GST_ELEMENT_ERROR (basepayload, STREAM, DECODE,
505 ("Identification packet is too short, need at least 42, got %d", size));
510 GST_ELEMENT_ERROR (basepayload, STREAM, DECODE,
511 (NULL), ("Invalid header start in identification packet"));
516 GST_ELEMENT_ERROR (basepayload, STREAM, DECODE,
517 (NULL), ("Invalid version"));
523 gst_rtp_theora_pay_payload_buffer (GstRtpTheoraPay * rtptheorapay, guint8 TDT,
524 guint8 * data, guint size, GstClockTime timestamp, GstClockTime duration,
527 GstFlowReturn ret = GST_FLOW_OK;
530 GstClockTime newduration;
533 guint8 *ppos, *payload;
536 /* size increases with packet length and 2 bytes size eader. */
537 newduration = rtptheorapay->payload_duration;
538 if (duration != GST_CLOCK_TIME_NONE)
539 newduration += duration;
541 newsize = rtptheorapay->payload_pos + 2 + size;
542 packet_len = gst_rtp_buffer_calc_packet_len (newsize, 0, 0);
544 /* check buffer filled against length and max latency */
545 flush = gst_basertppayload_is_filled (GST_BASE_RTP_PAYLOAD (rtptheorapay),
546 packet_len, newduration);
547 /* we can store up to 15 theora packets in one RTP packet. */
548 flush |= (rtptheorapay->payload_pkts == 15);
549 /* flush if we have a new TDT */
550 if (rtptheorapay->packet)
551 flush |= (rtptheorapay->payload_TDT != TDT);
553 ret = gst_rtp_theora_pay_flush_packet (rtptheorapay);
555 /* create new packet if we must */
556 if (!rtptheorapay->packet) {
557 gst_rtp_theora_pay_init_packet (rtptheorapay, TDT, timestamp);
560 payload = gst_rtp_buffer_get_payload (rtptheorapay->packet);
561 ppos = payload + rtptheorapay->payload_pos;
564 /* put buffer in packet, it either fits completely or needs to be fragmented
565 * over multiple RTP packets. */
567 plen = MIN (rtptheorapay->payload_left - 2, size);
569 GST_DEBUG_OBJECT (rtptheorapay, "append %u bytes", plen);
571 /* data is copied in the payload with a 2 byte length header */
572 ppos[0] = ((plen - not_in_length) >> 8) & 0xff;
573 ppos[1] = ((plen - not_in_length) & 0xff);
575 memcpy (&ppos[2], data, plen);
577 /* only first (only) configuration cuts length field */
578 /* NOTE: spec (if any) is not clear on this ... */
584 rtptheorapay->payload_pos += plen + 2;
585 rtptheorapay->payload_left -= plen + 2;
589 /* last fragment, set F to 0x3. */
590 rtptheorapay->payload_F = 0x3;
592 /* fragment continues, set F to 0x2. */
593 rtptheorapay->payload_F = 0x2;
596 /* fragmented packet starts, set F to 0x1, mark ourselves as
598 rtptheorapay->payload_F = 0x1;
603 /* fragmented packets are always flushed and have ptks of 0 */
604 rtptheorapay->payload_pkts = 0;
605 ret = gst_rtp_theora_pay_flush_packet (rtptheorapay);
608 /* start new packet and get pointers. TDT stays the same. */
609 gst_rtp_theora_pay_init_packet (rtptheorapay,
610 rtptheorapay->payload_TDT, timestamp);
611 payload = gst_rtp_buffer_get_payload (rtptheorapay->packet);
612 ppos = payload + rtptheorapay->payload_pos;
615 /* unfragmented packet, update stats for next packet, size == 0 and we
616 * exit the while loop */
617 rtptheorapay->payload_pkts++;
618 if (duration != GST_CLOCK_TIME_NONE)
619 rtptheorapay->payload_duration += duration;
627 gst_rtp_theora_pay_handle_buffer (GstBaseRTPPayload * basepayload,
630 GstRtpTheoraPay *rtptheorapay;
634 GstClockTime duration, timestamp;
636 gboolean keyframe = FALSE;
638 rtptheorapay = GST_RTP_THEORA_PAY (basepayload);
640 size = GST_BUFFER_SIZE (buffer);
641 data = GST_BUFFER_DATA (buffer);
642 duration = GST_BUFFER_DURATION (buffer);
643 timestamp = GST_BUFFER_TIMESTAMP (buffer);
645 GST_DEBUG_OBJECT (rtptheorapay, "size %u, duration %" GST_TIME_FORMAT,
646 size, GST_TIME_ARGS (duration));
648 if (G_UNLIKELY (size > 0xffff))
651 /* find packet type */
655 } else if (data[0] & 0x80) {
657 if (data[0] == 0x80) {
658 /* identification, we need to parse this in order to get the clock rate.
660 if (G_UNLIKELY (!gst_rtp_theora_pay_parse_id (basepayload, data, size)))
661 goto parse_id_failed;
663 } else if (data[0] == 0x81) {
666 } else if (data[0] == 0x82) {
674 keyframe = ((data[0] & 0x40) == 0);
677 if (rtptheorapay->need_headers) {
678 /* we need to collect the headers and construct a config string from them */
680 GST_DEBUG_OBJECT (rtptheorapay, "collecting header, buffer %p", buffer);
681 /* append header to the list of headers */
682 rtptheorapay->headers = g_list_append (rtptheorapay->headers, buffer);
686 if (!gst_rtp_theora_pay_finish_headers (basepayload))
688 rtptheorapay->need_headers = FALSE;
692 /* there is a config request, see if we need to insert it */
693 if (keyframe && (rtptheorapay->config_interval > 0) &&
694 rtptheorapay->config_data) {
695 gboolean send_config = FALSE;
697 if (rtptheorapay->last_config != -1) {
700 GST_LOG_OBJECT (rtptheorapay,
701 "now %" GST_TIME_FORMAT ", last VOP-I %" GST_TIME_FORMAT,
702 GST_TIME_ARGS (timestamp), GST_TIME_ARGS (rtptheorapay->last_config));
704 /* calculate diff between last config in milliseconds */
705 if (timestamp > rtptheorapay->last_config) {
706 diff = timestamp - rtptheorapay->last_config;
711 GST_DEBUG_OBJECT (rtptheorapay,
712 "interval since last config %" GST_TIME_FORMAT, GST_TIME_ARGS (diff));
714 /* bigger than interval, queue config */
715 /* FIXME should convert timestamps to running time */
716 if (GST_TIME_AS_SECONDS (diff) >= rtptheorapay->config_interval) {
717 GST_DEBUG_OBJECT (rtptheorapay, "time to send config");
721 /* no known previous config time, send now */
722 GST_DEBUG_OBJECT (rtptheorapay, "no previous config time, send now");
727 /* we need to send config now first */
728 /* different TDT type forces flush */
729 gst_rtp_theora_pay_payload_buffer (rtptheorapay, 1,
730 rtptheorapay->config_data, rtptheorapay->config_size,
731 timestamp, GST_CLOCK_TIME_NONE, rtptheorapay->config_extra_len);
733 if (timestamp != -1) {
734 rtptheorapay->last_config = timestamp;
739 ret = gst_rtp_theora_pay_payload_buffer (rtptheorapay, TDT, data, size,
740 timestamp, duration, 0);
741 gst_buffer_unref (buffer);
749 GST_ELEMENT_WARNING (rtptheorapay, STREAM, DECODE,
750 ("Invalid packet size (%d <= 0xffff)", size), (NULL));
751 gst_buffer_unref (buffer);
756 gst_buffer_unref (buffer);
757 return GST_FLOW_ERROR;
761 GST_ELEMENT_WARNING (rtptheorapay, STREAM, DECODE,
762 (NULL), ("Ignoring unknown header received"));
763 gst_buffer_unref (buffer);
768 GST_ELEMENT_WARNING (rtptheorapay, STREAM, DECODE,
769 (NULL), ("Error initializing header config"));
770 gst_buffer_unref (buffer);
776 gst_rtp_theora_pay_handle_event (GstPad * pad, GstEvent * event)
778 GstRtpTheoraPay *rtptheorapay = GST_RTP_THEORA_PAY (GST_PAD_PARENT (pad));
780 switch (GST_EVENT_TYPE (event)) {
781 case GST_EVENT_FLUSH_STOP:
782 gst_rtp_theora_pay_clear_packet (rtptheorapay);
787 /* false to let parent handle event as well */
791 static GstStateChangeReturn
792 gst_rtp_theora_pay_change_state (GstElement * element,
793 GstStateChange transition)
795 GstRtpTheoraPay *rtptheorapay;
797 GstStateChangeReturn ret;
799 rtptheorapay = GST_RTP_THEORA_PAY (element);
801 switch (transition) {
806 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
808 switch (transition) {
809 case GST_STATE_CHANGE_PAUSED_TO_READY:
810 gst_rtp_theora_pay_cleanup (rtptheorapay);
819 gst_rtp_theora_pay_set_property (GObject * object, guint prop_id,
820 const GValue * value, GParamSpec * pspec)
822 GstRtpTheoraPay *rtptheorapay;
824 rtptheorapay = GST_RTP_THEORA_PAY (object);
827 case PROP_CONFIG_INTERVAL:
828 rtptheorapay->config_interval = g_value_get_uint (value);
836 gst_rtp_theora_pay_get_property (GObject * object, guint prop_id,
837 GValue * value, GParamSpec * pspec)
839 GstRtpTheoraPay *rtptheorapay;
841 rtptheorapay = GST_RTP_THEORA_PAY (object);
844 case PROP_CONFIG_INTERVAL:
845 g_value_set_uint (value, rtptheorapay->config_interval);
853 gst_rtp_theora_pay_plugin_init (GstPlugin * plugin)
855 return gst_element_register (plugin, "rtptheorapay",
856 GST_RANK_SECONDARY, GST_TYPE_RTP_THEORA_PAY);