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,
88 static void gst_rtp_theora_pay_set_property (GObject * object, guint prop_id,
89 const GValue * value, GParamSpec * pspec);
90 static void gst_rtp_theora_pay_get_property (GObject * object, guint prop_id,
91 GValue * value, GParamSpec * pspec);
94 gst_rtp_theora_pay_base_init (gpointer klass)
96 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
98 gst_element_class_add_pad_template (element_class,
99 gst_static_pad_template_get (&gst_rtp_theora_pay_src_template));
100 gst_element_class_add_pad_template (element_class,
101 gst_static_pad_template_get (&gst_rtp_theora_pay_sink_template));
103 gst_element_class_set_details_simple (element_class, "RTP Theora payloader",
104 "Codec/Payloader/Network",
105 "Payload-encode Theora video into RTP packets (draft-01 RFC XXXX)",
106 "Wim Taymans <wim.taymans@gmail.com>");
110 gst_rtp_theora_pay_class_init (GstRtpTheoraPayClass * klass)
112 GObjectClass *gobject_class;
113 GstElementClass *gstelement_class;
114 GstBaseRTPPayloadClass *gstbasertppayload_class;
116 gobject_class = (GObjectClass *) klass;
117 gstelement_class = (GstElementClass *) klass;
118 gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
120 gstelement_class->change_state = gst_rtp_theora_pay_change_state;
122 gstbasertppayload_class->set_caps = gst_rtp_theora_pay_setcaps;
123 gstbasertppayload_class->handle_buffer = gst_rtp_theora_pay_handle_buffer;
125 gobject_class->set_property = gst_rtp_theora_pay_set_property;
126 gobject_class->get_property = gst_rtp_theora_pay_get_property;
128 GST_DEBUG_CATEGORY_INIT (rtptheorapay_debug, "rtptheorapay", 0,
129 "Theora RTP Payloader");
131 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CONFIG_INTERVAL,
132 g_param_spec_uint ("config-interval", "Config Send Interval",
133 "Send Config Insertion Interval in seconds (configuration headers "
134 "will be multiplexed in the data stream when detected.) (0 = disabled)",
135 0, 3600, DEFAULT_CONFIG_INTERVAL,
136 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
141 gst_rtp_theora_pay_init (GstRtpTheoraPay * rtptheorapay,
142 GstRtpTheoraPayClass * klass)
144 rtptheorapay->last_config = GST_CLOCK_TIME_NONE;
148 gst_rtp_theora_pay_cleanup (GstRtpTheoraPay * rtptheorapay)
150 g_list_foreach (rtptheorapay->headers, (GFunc) gst_mini_object_unref, NULL);
151 g_list_free (rtptheorapay->headers);
152 rtptheorapay->headers = NULL;
154 if (rtptheorapay->packet)
155 gst_buffer_unref (rtptheorapay->packet);
156 rtptheorapay->packet = NULL;
158 if (rtptheorapay->config_data)
159 g_free (rtptheorapay->config_data);
160 rtptheorapay->config_data = NULL;
161 rtptheorapay->last_config = GST_CLOCK_TIME_NONE;
165 gst_rtp_theora_pay_setcaps (GstBaseRTPPayload * basepayload, GstCaps * caps)
167 GstRtpTheoraPay *rtptheorapay;
169 rtptheorapay = GST_RTP_THEORA_PAY (basepayload);
171 rtptheorapay->need_headers = TRUE;
177 gst_rtp_theora_pay_reset_packet (GstRtpTheoraPay * rtptheorapay, guint8 TDT)
181 GST_DEBUG_OBJECT (rtptheorapay, "reset packet");
183 rtptheorapay->payload_pos = 4;
184 payload_len = gst_rtp_buffer_get_payload_len (rtptheorapay->packet);
185 rtptheorapay->payload_left = payload_len - 4;
186 rtptheorapay->payload_duration = 0;
187 rtptheorapay->payload_F = 0;
188 rtptheorapay->payload_TDT = TDT;
189 rtptheorapay->payload_pkts = 0;
193 gst_rtp_theora_pay_init_packet (GstRtpTheoraPay * rtptheorapay, guint8 TDT,
194 GstClockTime timestamp)
196 GST_DEBUG_OBJECT (rtptheorapay, "starting new packet, TDT: %d", TDT);
198 if (rtptheorapay->packet)
199 gst_buffer_unref (rtptheorapay->packet);
201 /* new packet allocate max packet size */
202 rtptheorapay->packet =
203 gst_rtp_buffer_new_allocate_len (GST_BASE_RTP_PAYLOAD_MTU
204 (rtptheorapay), 0, 0);
205 gst_rtp_theora_pay_reset_packet (rtptheorapay, TDT);
207 GST_BUFFER_TIMESTAMP (rtptheorapay->packet) = timestamp;
211 gst_rtp_theora_pay_flush_packet (GstRtpTheoraPay * rtptheorapay)
217 /* check for empty packet */
218 if (!rtptheorapay->packet || rtptheorapay->payload_pos <= 4)
221 GST_DEBUG_OBJECT (rtptheorapay, "flushing packet");
224 payload = gst_rtp_buffer_get_payload (rtptheorapay->packet);
227 * 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
228 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
229 * | Ident | F |TDT|# pkts.|
230 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
232 * F: Fragment type (0=none, 1=start, 2=cont, 3=end)
233 * TDT: Theora data type (0=theora, 1=config, 2=comment, 3=reserved)
234 * pkts: number of packets.
236 payload[0] = (rtptheorapay->payload_ident >> 16) & 0xff;
237 payload[1] = (rtptheorapay->payload_ident >> 8) & 0xff;
238 payload[2] = (rtptheorapay->payload_ident) & 0xff;
239 payload[3] = (rtptheorapay->payload_F & 0x3) << 6 |
240 (rtptheorapay->payload_TDT & 0x3) << 4 |
241 (rtptheorapay->payload_pkts & 0xf);
243 /* shrink the buffer size to the last written byte */
244 hlen = gst_rtp_buffer_calc_header_len (0);
245 GST_BUFFER_SIZE (rtptheorapay->packet) = hlen + rtptheorapay->payload_pos;
247 GST_BUFFER_DURATION (rtptheorapay->packet) = rtptheorapay->payload_duration;
249 /* push, this gives away our ref to the packet, so clear it. */
251 gst_basertppayload_push (GST_BASE_RTP_PAYLOAD (rtptheorapay),
252 rtptheorapay->packet);
253 rtptheorapay->packet = NULL;
259 gst_rtp_theora_pay_finish_headers (GstBaseRTPPayload * basepayload)
261 GstRtpTheoraPay *rtptheorapay = GST_RTP_THEORA_PAY (basepayload);
263 guint length, size, n_headers, configlen, extralen;
264 gchar *wstr, *hstr, *configuration;
265 guint8 *data, *config;
269 GST_DEBUG_OBJECT (rtptheorapay, "finish headers");
271 if (!rtptheorapay->headers) {
272 GST_DEBUG_OBJECT (rtptheorapay, "We need 2 headers but have none");
276 /* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
277 * | Number of packed headers |
278 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
279 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
281 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
282 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
284 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
285 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
287 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
289 * We only construct a config containing 1 packed header like this:
292 * 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
293 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
294 * | Ident | length ..
295 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
296 * .. | n. of headers | length1 | length2 ..
297 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
298 * .. | Identification Header ..
299 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
300 * .................................................................
301 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
302 * .. | Comment Header ..
303 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
304 * .................................................................
305 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
306 * .. Comment Header |
307 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
309 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
310 * .................................................................
311 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
313 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
316 /* we need 4 bytes for the number of headers (which is always 1), 3 bytes for
317 * the ident, 2 bytes for length, 1 byte for n. of headers. */
318 size = 4 + 3 + 2 + 1;
320 /* count the size of the headers first and update the hash */
323 ident = fnv1_hash_32_new ();
325 for (walk = rtptheorapay->headers; walk; walk = g_list_next (walk)) {
326 GstBuffer *buf = GST_BUFFER_CAST (walk->data);
330 bsize = GST_BUFFER_SIZE (buf);
334 /* count number of bytes needed for length fields, we don't need this for
335 * the last header. */
336 if (g_list_next (walk)) {
344 ident = fnv1_hash_32_update (ident, GST_BUFFER_DATA (buf),
345 GST_BUFFER_SIZE (buf));
348 /* packet length is header size + packet length */
349 configlen = size + length;
350 config = data = g_malloc (configlen);
352 /* number of packed headers, we only pack 1 header */
358 ident = fnv1_hash_32_to_24 (ident);
359 rtptheorapay->payload_ident = ident;
360 GST_DEBUG_OBJECT (rtptheorapay, "ident 0x%08x", ident);
362 /* take lower 3 bytes */
363 data[4] = (ident >> 16) & 0xff;
364 data[5] = (ident >> 8) & 0xff;
365 data[6] = ident & 0xff;
367 /* store length of all theora headers */
368 data[7] = ((length) >> 8) & 0xff;
369 data[8] = (length) & 0xff;
371 /* store number of headers minus one. */
372 data[9] = n_headers - 1;
375 /* store length for each header */
376 for (walk = rtptheorapay->headers; walk; walk = g_list_next (walk)) {
377 GstBuffer *buf = GST_BUFFER_CAST (walk->data);
379 guint bsize, size, temp;
382 /* only need to store the length when it's not the last header */
383 if (!g_list_next (walk))
386 bsize = GST_BUFFER_SIZE (buf);
396 bsize = GST_BUFFER_SIZE (buf);
397 /* write the size backwards */
401 data[size] = (bsize & 0x7f) | flag;
408 /* copy header data */
409 for (walk = rtptheorapay->headers; walk; walk = g_list_next (walk)) {
410 GstBuffer *buf = GST_BUFFER_CAST (walk->data);
412 memcpy (data, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
413 data += GST_BUFFER_SIZE (buf);
416 /* serialize to base64 */
417 configuration = g_base64_encode (config, configlen);
419 /* store for later re-sending */
420 rtptheorapay->config_size = configlen - 4 - 3 - 2;
421 rtptheorapay->config_data = g_malloc (rtptheorapay->config_size);
422 rtptheorapay->config_extra_len = extralen;
423 memcpy (rtptheorapay->config_data, config + 4 + 3 + 2,
424 rtptheorapay->config_size);
428 /* configure payloader settings */
429 wstr = g_strdup_printf ("%d", rtptheorapay->width);
430 hstr = g_strdup_printf ("%d", rtptheorapay->height);
431 gst_basertppayload_set_options (basepayload, "video", TRUE, "THEORA", 90000);
432 res = gst_basertppayload_set_outcaps (basepayload,
433 "sampling", G_TYPE_STRING, "YCbCr-4:2:0",
434 "width", G_TYPE_STRING, wstr,
435 "height", G_TYPE_STRING, hstr,
436 "configuration", G_TYPE_STRING, configuration,
437 /* don't set the other defaults
442 g_free (configuration);
449 GST_DEBUG_OBJECT (rtptheorapay, "finish headers");
455 gst_rtp_theora_pay_parse_id (GstBaseRTPPayload * basepayload, guint8 * data,
458 GstRtpTheoraPay *rtptheorapay;
461 rtptheorapay = GST_RTP_THEORA_PAY (basepayload);
463 if (G_UNLIKELY (size < 42))
466 if (G_UNLIKELY (memcmp (data, "\200theora", 7)))
470 if (G_UNLIKELY (data[0] != 3))
471 goto invalid_version;
472 if (G_UNLIKELY (data[1] != 2))
473 goto invalid_version;
476 width = GST_READ_UINT16_BE (data) << 4;
478 height = GST_READ_UINT16_BE (data) << 4;
481 /* FIXME, parse pixel format */
484 rtptheorapay->width = width;
485 rtptheorapay->height = height;
492 GST_ELEMENT_ERROR (basepayload, STREAM, DECODE,
494 ("Identification packet is too short, need at least 42, got %d", size));
499 GST_ELEMENT_ERROR (basepayload, STREAM, DECODE,
500 (NULL), ("Invalid header start in identification packet"));
505 GST_ELEMENT_ERROR (basepayload, STREAM, DECODE,
506 (NULL), ("Invalid version"));
512 gst_rtp_theora_pay_payload_buffer (GstRtpTheoraPay * rtptheorapay, guint8 TDT,
513 guint8 * data, guint size, GstClockTime timestamp, GstClockTime duration,
516 GstFlowReturn ret = GST_FLOW_OK;
519 GstClockTime newduration;
522 guint8 *ppos, *payload;
525 /* size increases with packet length and 2 bytes size eader. */
526 newduration = rtptheorapay->payload_duration;
527 if (duration != GST_CLOCK_TIME_NONE)
528 newduration += duration;
530 newsize = rtptheorapay->payload_pos + 2 + size;
531 packet_len = gst_rtp_buffer_calc_packet_len (newsize, 0, 0);
533 /* check buffer filled against length and max latency */
534 flush = gst_basertppayload_is_filled (GST_BASE_RTP_PAYLOAD (rtptheorapay),
535 packet_len, newduration);
536 /* we can store up to 15 theora packets in one RTP packet. */
537 flush |= (rtptheorapay->payload_pkts == 15);
538 /* flush if we have a new TDT */
539 if (rtptheorapay->packet)
540 flush |= (rtptheorapay->payload_TDT != TDT);
542 ret = gst_rtp_theora_pay_flush_packet (rtptheorapay);
544 /* create new packet if we must */
545 if (!rtptheorapay->packet) {
546 gst_rtp_theora_pay_init_packet (rtptheorapay, TDT, timestamp);
549 payload = gst_rtp_buffer_get_payload (rtptheorapay->packet);
550 ppos = payload + rtptheorapay->payload_pos;
553 /* put buffer in packet, it either fits completely or needs to be fragmented
554 * over multiple RTP packets. */
556 plen = MIN (rtptheorapay->payload_left - 2, size);
558 GST_DEBUG_OBJECT (rtptheorapay, "append %u bytes", plen);
560 /* data is copied in the payload with a 2 byte length header */
561 ppos[0] = ((plen - not_in_length) >> 8) & 0xff;
562 ppos[1] = ((plen - not_in_length) & 0xff);
563 memcpy (&ppos[2], data, plen);
565 /* only first (only) configuration cuts length field */
566 /* NOTE: spec (if any) is not clear on this ... */
572 rtptheorapay->payload_pos += plen + 2;
573 rtptheorapay->payload_left -= plen + 2;
577 /* last fragment, set F to 0x3. */
578 rtptheorapay->payload_F = 0x3;
580 /* fragment continues, set F to 0x2. */
581 rtptheorapay->payload_F = 0x2;
584 /* fragmented packet starts, set F to 0x1, mark ourselves as
586 rtptheorapay->payload_F = 0x1;
591 /* fragmented packets are always flushed and have ptks of 0 */
592 rtptheorapay->payload_pkts = 0;
593 ret = gst_rtp_theora_pay_flush_packet (rtptheorapay);
596 /* start new packet and get pointers. TDT stays the same. */
597 gst_rtp_theora_pay_init_packet (rtptheorapay,
598 rtptheorapay->payload_TDT, timestamp);
599 payload = gst_rtp_buffer_get_payload (rtptheorapay->packet);
600 ppos = payload + rtptheorapay->payload_pos;
603 /* unfragmented packet, update stats for next packet, size == 0 and we
604 * exit the while loop */
605 rtptheorapay->payload_pkts++;
606 if (duration != GST_CLOCK_TIME_NONE)
607 rtptheorapay->payload_duration += duration;
615 gst_rtp_theora_pay_handle_buffer (GstBaseRTPPayload * basepayload,
618 GstRtpTheoraPay *rtptheorapay;
622 GstClockTime duration, timestamp;
624 gboolean keyframe = FALSE;
626 rtptheorapay = GST_RTP_THEORA_PAY (basepayload);
628 size = GST_BUFFER_SIZE (buffer);
629 data = GST_BUFFER_DATA (buffer);
630 duration = GST_BUFFER_DURATION (buffer);
631 timestamp = GST_BUFFER_TIMESTAMP (buffer);
633 GST_DEBUG_OBJECT (rtptheorapay, "size %u, duration %" GST_TIME_FORMAT,
634 size, GST_TIME_ARGS (duration));
636 if (G_UNLIKELY (size < 1 || size > 0xffff))
639 /* find packet type */
640 if (data[0] & 0x80) {
642 if (data[0] == 0x80) {
643 /* identification, we need to parse this in order to get the clock rate.
645 if (G_UNLIKELY (!gst_rtp_theora_pay_parse_id (basepayload, data, size)))
646 goto parse_id_failed;
648 } else if (data[0] == 0x81) {
651 } else if (data[0] == 0x82) {
659 keyframe = ((data[0] & 0x40) == 0);
662 if (rtptheorapay->need_headers) {
663 /* we need to collect the headers and construct a config string from them */
665 GST_DEBUG_OBJECT (rtptheorapay, "collecting header, buffer %p", buffer);
666 /* append header to the list of headers */
667 rtptheorapay->headers = g_list_append (rtptheorapay->headers, buffer);
671 if (!gst_rtp_theora_pay_finish_headers (basepayload))
673 rtptheorapay->need_headers = FALSE;
677 /* there is a config request, see if we need to insert it */
678 if (keyframe && (rtptheorapay->config_interval > 0) &&
679 rtptheorapay->config_data) {
680 gboolean send_config = FALSE;
682 if (rtptheorapay->last_config != -1) {
685 GST_LOG_OBJECT (rtptheorapay,
686 "now %" GST_TIME_FORMAT ", last VOP-I %" GST_TIME_FORMAT,
687 GST_TIME_ARGS (timestamp), GST_TIME_ARGS (rtptheorapay->last_config));
689 /* calculate diff between last config in milliseconds */
690 if (timestamp > rtptheorapay->last_config) {
691 diff = timestamp - rtptheorapay->last_config;
696 GST_DEBUG_OBJECT (rtptheorapay,
697 "interval since last config %" GST_TIME_FORMAT, GST_TIME_ARGS (diff));
699 /* bigger than interval, queue config */
700 /* FIXME should convert timestamps to running time */
701 if (GST_TIME_AS_SECONDS (diff) >= rtptheorapay->config_interval) {
702 GST_DEBUG_OBJECT (rtptheorapay, "time to send config");
706 /* no known previous config time, send now */
707 GST_DEBUG_OBJECT (rtptheorapay, "no previous config time, send now");
712 /* we need to send config now first */
713 /* different TDT type forces flush */
714 gst_rtp_theora_pay_payload_buffer (rtptheorapay, 1,
715 rtptheorapay->config_data, rtptheorapay->config_size,
716 timestamp, GST_CLOCK_TIME_NONE, rtptheorapay->config_extra_len);
718 if (timestamp != -1) {
719 rtptheorapay->last_config = timestamp;
724 ret = gst_rtp_theora_pay_payload_buffer (rtptheorapay, TDT, data, size,
725 timestamp, duration, 0);
726 gst_buffer_unref (buffer);
734 GST_ELEMENT_WARNING (rtptheorapay, STREAM, DECODE,
735 ("Invalid packet size (1 < %d <= 0xffff)", size), (NULL));
736 gst_buffer_unref (buffer);
741 gst_buffer_unref (buffer);
742 return GST_FLOW_ERROR;
746 GST_ELEMENT_WARNING (rtptheorapay, STREAM, DECODE,
747 (NULL), ("Ignoring unknown header received"));
748 gst_buffer_unref (buffer);
753 GST_ELEMENT_WARNING (rtptheorapay, STREAM, DECODE,
754 (NULL), ("Error initializing header config"));
755 gst_buffer_unref (buffer);
760 static GstStateChangeReturn
761 gst_rtp_theora_pay_change_state (GstElement * element,
762 GstStateChange transition)
764 GstRtpTheoraPay *rtptheorapay;
766 GstStateChangeReturn ret;
768 rtptheorapay = GST_RTP_THEORA_PAY (element);
770 switch (transition) {
775 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
777 switch (transition) {
778 case GST_STATE_CHANGE_PAUSED_TO_READY:
779 gst_rtp_theora_pay_cleanup (rtptheorapay);
788 gst_rtp_theora_pay_set_property (GObject * object, guint prop_id,
789 const GValue * value, GParamSpec * pspec)
791 GstRtpTheoraPay *rtptheorapay;
793 rtptheorapay = GST_RTP_THEORA_PAY (object);
796 case PROP_CONFIG_INTERVAL:
797 rtptheorapay->config_interval = g_value_get_uint (value);
805 gst_rtp_theora_pay_get_property (GObject * object, guint prop_id,
806 GValue * value, GParamSpec * pspec)
808 GstRtpTheoraPay *rtptheorapay;
810 rtptheorapay = GST_RTP_THEORA_PAY (object);
813 case PROP_CONFIG_INTERVAL:
814 g_value_set_uint (value, rtptheorapay->config_interval);
822 gst_rtp_theora_pay_plugin_init (GstPlugin * plugin)
824 return gst_element_register (plugin, "rtptheorapay",
825 GST_RANK_NONE, GST_TYPE_RTP_THEORA_PAY);