2 * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org>
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.
21 * SECTION:element-gdppay
24 * This element payloads GStreamer buffers and events using the
25 * GStreamer Data Protocol.
29 * gst-launch -v -m videotestsrc num-buffers=50 ! gdppay ! filesink location=test.gdp
30 * ]| This pipeline creates a serialized video stream that can be played back
31 * with the example shown in gdpdepay.
39 #include <gst/dataprotocol/dataprotocol.h>
41 #include "gstgdppay.h"
43 static GstStaticPadTemplate gdp_pay_sink_template =
44 GST_STATIC_PAD_TEMPLATE ("sink",
49 static GstStaticPadTemplate gdp_pay_src_template =
50 GST_STATIC_PAD_TEMPLATE ("src",
53 GST_STATIC_CAPS ("application/x-gdp"));
55 GST_DEBUG_CATEGORY_STATIC (gst_gdp_pay_debug);
56 #define GST_CAT_DEFAULT gst_gdp_pay_debug
58 #define DEFAULT_CRC_HEADER TRUE
59 #define DEFAULT_CRC_PAYLOAD FALSE
60 #define DEFAULT_VERSION GST_DP_VERSION_1_0
71 GST_DEBUG_CATEGORY_INIT (gst_gdp_pay_debug, "gdppay", 0, \
74 GST_BOILERPLATE_FULL (GstGDPPay, gst_gdp_pay, GstElement,
75 GST_TYPE_ELEMENT, _do_init);
77 static void gst_gdp_pay_reset (GstGDPPay * this);
79 static GstFlowReturn gst_gdp_pay_chain (GstPad * pad, GstBuffer * buffer);
80 static gboolean gst_gdp_pay_src_event (GstPad * pad, GstEvent * event);
81 static gboolean gst_gdp_pay_sink_event (GstPad * pad, GstEvent * event);
83 static GstStateChangeReturn gst_gdp_pay_change_state (GstElement *
84 element, GstStateChange transition);
86 static void gst_gdp_pay_set_property (GObject * object, guint prop_id,
87 const GValue * value, GParamSpec * pspec);
88 static void gst_gdp_pay_get_property (GObject * object, guint prop_id,
89 GValue * value, GParamSpec * pspec);
91 static void gst_gdp_pay_finalize (GObject * gobject);
94 gst_gdp_pay_base_init (gpointer g_class)
96 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
98 gst_element_class_set_details_simple (element_class,
99 "GDP Payloader", "GDP/Payloader",
100 "Payloads GStreamer Data Protocol buffers",
101 "Thomas Vander Stichele <thomas at apestaart dot org>");
103 gst_element_class_add_pad_template (element_class,
104 gst_static_pad_template_get (&gdp_pay_sink_template));
105 gst_element_class_add_pad_template (element_class,
106 gst_static_pad_template_get (&gdp_pay_src_template));
110 gst_gdp_pay_class_init (GstGDPPayClass * klass)
112 GObjectClass *gobject_class;
113 GstElementClass *gstelement_class;
115 gobject_class = (GObjectClass *) klass;
116 gstelement_class = (GstElementClass *) klass;
118 gobject_class->set_property = gst_gdp_pay_set_property;
119 gobject_class->get_property = gst_gdp_pay_get_property;
120 gobject_class->finalize = gst_gdp_pay_finalize;
122 g_object_class_install_property (gobject_class, PROP_CRC_HEADER,
123 g_param_spec_boolean ("crc-header", "CRC Header",
124 "Calculate and store a CRC checksum on the header",
125 DEFAULT_CRC_HEADER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
126 g_object_class_install_property (gobject_class, PROP_CRC_PAYLOAD,
127 g_param_spec_boolean ("crc-payload", "CRC Payload",
128 "Calculate and store a CRC checksum on the payload",
129 DEFAULT_CRC_PAYLOAD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
130 g_object_class_install_property (gobject_class, PROP_VERSION,
131 g_param_spec_enum ("version", "Version",
132 "Version of the GStreamer Data Protocol",
133 GST_TYPE_DP_VERSION, DEFAULT_VERSION,
134 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
136 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_gdp_pay_change_state);
140 gst_gdp_pay_init (GstGDPPay * gdppay, GstGDPPayClass * g_class)
143 gst_pad_new_from_static_template (&gdp_pay_sink_template, "sink");
144 gst_pad_set_chain_function (gdppay->sinkpad,
145 GST_DEBUG_FUNCPTR (gst_gdp_pay_chain));
146 gst_pad_set_event_function (gdppay->sinkpad,
147 GST_DEBUG_FUNCPTR (gst_gdp_pay_sink_event));
148 gst_element_add_pad (GST_ELEMENT (gdppay), gdppay->sinkpad);
151 gst_pad_new_from_static_template (&gdp_pay_src_template, "src");
152 gst_pad_set_event_function (gdppay->srcpad,
153 GST_DEBUG_FUNCPTR (gst_gdp_pay_src_event));
154 gst_element_add_pad (GST_ELEMENT (gdppay), gdppay->srcpad);
156 gdppay->crc_header = DEFAULT_CRC_HEADER;
157 gdppay->crc_payload = DEFAULT_CRC_PAYLOAD;
158 gdppay->header_flag = gdppay->crc_header | gdppay->crc_payload;
159 gdppay->version = DEFAULT_VERSION;
162 gdppay->packetizer = gst_dp_packetizer_new (gdppay->version);
166 gst_gdp_pay_finalize (GObject * gobject)
168 GstGDPPay *this = GST_GDP_PAY (gobject);
170 gst_gdp_pay_reset (this);
171 gst_dp_packetizer_free (this->packetizer);
173 GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (gobject));
177 gst_gdp_pay_reset (GstGDPPay * this)
179 GST_DEBUG_OBJECT (this, "Resetting GDP object");
180 /* clear the queued buffers */
181 while (this->queue) {
184 buffer = GST_BUFFER_CAST (this->queue->data);
186 /* delete buffer from queue now */
187 this->queue = g_list_delete_link (this->queue, this->queue);
189 gst_buffer_unref (buffer);
192 gst_caps_unref (this->caps);
195 if (this->caps_buf) {
196 gst_buffer_unref (this->caps_buf);
197 this->caps_buf = NULL;
200 gst_buffer_unref (this->tag_buf);
201 this->tag_buf = NULL;
203 if (this->new_segment_buf) {
204 gst_buffer_unref (this->new_segment_buf);
205 this->new_segment_buf = NULL;
207 this->sent_streamheader = FALSE;
211 /* set OFFSET and OFFSET_END with running count */
213 gst_gdp_stamp_buffer (GstGDPPay * this, GstBuffer * buffer)
215 GST_BUFFER_OFFSET (buffer) = this->offset;
216 GST_BUFFER_OFFSET_END (buffer) = this->offset + gst_buffer_get_size (buffer);
217 this->offset = GST_BUFFER_OFFSET_END (buffer);
221 gst_gdp_buffer_from_caps (GstGDPPay * this, GstCaps * caps)
223 GstBuffer *headerbuf;
224 GstBuffer *payloadbuf;
225 guint8 *header, *payload;
228 if (!this->packetizer->packet_from_caps (caps, this->header_flag, &len,
232 GST_LOG_OBJECT (this, "creating GDP header and payload buffer from caps");
233 headerbuf = gst_buffer_new ();
234 gst_buffer_take_memory (headerbuf,
235 gst_memory_new_wrapped (0, header, g_free, len, 0, len));
237 payloadbuf = gst_buffer_new ();
238 plen = gst_dp_header_payload_length (header);
239 gst_buffer_take_memory (payloadbuf,
240 gst_memory_new_wrapped (0, payload, g_free, plen, 0, plen));
242 return gst_buffer_join (headerbuf, payloadbuf);
247 GST_WARNING_OBJECT (this, "could not create GDP header from caps");
253 gst_gdp_pay_buffer_from_buffer (GstGDPPay * this, GstBuffer * buffer)
255 GstBuffer *headerbuf;
259 if (!this->packetizer->header_from_buffer (buffer, this->header_flag, &len,
263 GST_LOG_OBJECT (this, "creating GDP header and payload buffer from buffer");
264 headerbuf = gst_buffer_new ();
265 gst_buffer_take_memory (headerbuf,
266 gst_memory_new_wrapped (0, header, g_free, len, 0, len));
268 /* we do not want to lose the ref on the incoming buffer */
269 gst_buffer_ref (buffer);
271 return gst_buffer_join (headerbuf, buffer);
276 GST_WARNING_OBJECT (this, "could not create GDP header from buffer");
282 gst_gdp_buffer_from_event (GstGDPPay * this, GstEvent * event)
284 GstBuffer *headerbuf;
285 GstBuffer *payloadbuf;
286 guint8 *header, *payload;
291 this->packetizer->packet_from_event (event, this->header_flag, &len,
296 GST_LOG_OBJECT (this, "creating GDP header and payload buffer from event");
297 headerbuf = gst_buffer_new ();
298 gst_buffer_take_memory (headerbuf,
299 gst_memory_new_wrapped (0, header, g_free, len, 0, len));
301 payloadbuf = gst_buffer_new ();
302 plen = gst_dp_header_payload_length (header);
303 gst_buffer_take_memory (payloadbuf,
304 gst_memory_new_wrapped (0, payload, g_free, plen, 0, plen));
306 return gst_buffer_join (headerbuf, payloadbuf);
311 GST_WARNING_OBJECT (this, "could not create GDP header from event %s (%d)",
312 gst_event_type_get_name (event->type), event->type);
318 /* set our caps with streamheader, based on the latest newsegment and caps,
319 * and (possibly) GDP-serialized buffers of the streamheaders on the src pad */
321 gst_gdp_pay_reset_streamheader (GstGDPPay * this)
324 /* We use copies of these to avoid circular refcounts */
325 GstBuffer *new_segment_buf, *caps_buf, *tag_buf;
326 GstStructure *structure;
327 GstFlowReturn r = GST_FLOW_OK;
328 gboolean version_one_zero = TRUE;
330 GValue array = { 0 };
331 GValue value = { 0 };
333 GST_DEBUG_OBJECT (this, "start");
334 /* In version 0.2, we didn't need or send new segment or tags */
335 if (this->version == GST_DP_VERSION_0_2)
336 version_one_zero = FALSE;
338 if (version_one_zero) {
339 if (!this->new_segment_buf || !this->caps_buf) {
340 GST_DEBUG_OBJECT (this, "1.0, missing new_segment or caps, returning");
344 if (!this->caps_buf) {
345 GST_DEBUG_OBJECT (this, "0.2, missing caps, returning");
350 /* put copies of the buffers in a fixed list
351 * Stamp the buffers with offset and offset_end as well.
352 * We do this here so the offsets match the order the buffers go out in */
353 g_value_init (&array, GST_TYPE_ARRAY);
355 if (version_one_zero) {
356 gst_gdp_stamp_buffer (this, this->new_segment_buf);
357 GST_DEBUG_OBJECT (this, "1.0, appending copy of new segment buffer %p",
358 this->new_segment_buf);
359 new_segment_buf = gst_buffer_copy (this->new_segment_buf);
360 gst_buffer_set_caps (new_segment_buf, NULL);
361 g_value_init (&value, GST_TYPE_BUFFER);
362 gst_value_set_buffer (&value, new_segment_buf);
363 gst_value_array_append_value (&array, &value);
364 g_value_unset (&value);
365 gst_buffer_unref (new_segment_buf);
368 gst_gdp_stamp_buffer (this, this->tag_buf);
369 GST_DEBUG_OBJECT (this, "1.0, appending current tags buffer %p",
371 tag_buf = this->tag_buf;
372 this->tag_buf = NULL;
374 gst_buffer_set_caps (tag_buf, NULL);
375 g_value_init (&value, GST_TYPE_BUFFER);
376 gst_value_set_buffer (&value, tag_buf);
377 gst_value_array_append_value (&array, &value);
378 g_value_unset (&value);
379 gst_buffer_unref (tag_buf);
383 gst_gdp_stamp_buffer (this, this->caps_buf);
384 GST_DEBUG_OBJECT (this, "appending copy of caps buffer %p", this->caps_buf);
385 caps_buf = gst_buffer_copy (this->caps_buf);
386 gst_buffer_set_caps (caps_buf, NULL);
387 g_value_init (&value, GST_TYPE_BUFFER);
388 gst_value_set_buffer (&value, caps_buf);
389 gst_value_array_append_value (&array, &value);
390 g_value_unset (&value);
391 gst_buffer_unref (caps_buf);
393 /* we also need to add GDP serializations of the streamheaders of the
395 structure = gst_caps_get_structure (this->caps, 0);
396 if (gst_structure_has_field (structure, "streamheader")) {
405 sh = gst_structure_get_value (structure, "streamheader");
406 buffers = g_value_peek_pointer (sh);
407 GST_DEBUG_OBJECT (this,
408 "Need to serialize %d incoming streamheader buffers on ours",
410 for (i = 0; i < buffers->len; ++i) {
413 GstBuffer *outbuffer;
415 bufval = &g_array_index (buffers, GValue, i);
416 buffer = g_value_peek_pointer (bufval);
417 /* this buffer is deserialized by gdpdepay as a regular buffer,
418 it needs IN_CAPS, because it's a streamheader - otherwise it
419 is mixed with regular data buffers */
420 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS);
421 GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE;
422 GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE;
423 GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE;
425 outbuffer = gst_gdp_pay_buffer_from_buffer (this, buffer);
427 g_value_unset (&array);
431 /* Setting IN_CAPS as other GDP event buffers */
432 GST_DEBUG_OBJECT (this,
433 "Setting IN_CAPS flag on outgoing buffer %" GST_PTR_FORMAT,
435 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
436 GST_BUFFER_OFFSET (outbuffer) = GST_BUFFER_OFFSET_NONE;
437 GST_BUFFER_OFFSET_END (outbuffer) = GST_BUFFER_OFFSET_NONE;
438 GST_BUFFER_TIMESTAMP (outbuffer) = GST_CLOCK_TIME_NONE;
440 g_value_init (&value, GST_TYPE_BUFFER);
441 gst_value_set_buffer (&value, outbuffer);
442 gst_value_array_append_value (&array, &value);
443 g_value_unset (&value);
445 gst_buffer_unref (outbuffer);
448 GST_DEBUG_OBJECT (this, "no streamheader to serialize");
451 GST_DEBUG_OBJECT (this, "%d serialized buffers on streamheaders",
452 gst_value_array_get_size (&array));
453 caps = gst_caps_from_string ("application/x-gdp");
454 structure = gst_caps_get_structure (caps, 0);
456 gst_structure_set_value (structure, "streamheader", &array);
457 g_value_unset (&array);
459 GST_DEBUG_OBJECT (this, "Setting caps on src pad %" GST_PTR_FORMAT, caps);
460 gst_pad_set_caps (this->srcpad, caps);
461 this->caps_buf = gst_buffer_make_writable (this->caps_buf);
462 gst_buffer_set_caps (this->caps_buf, caps);
463 this->new_segment_buf = gst_buffer_make_writable (this->new_segment_buf);
464 gst_buffer_set_caps (this->new_segment_buf, caps);
466 /* if these are our first ever buffers, send out new_segment first */
467 if (!this->sent_streamheader) {
469 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
470 GST_DEBUG_OBJECT (this, "Sending out new_segment event %p", event);
471 if (!gst_pad_push_event (this->srcpad, event)) {
472 GST_WARNING_OBJECT (this, "pushing new segment failed");
478 /* push out these streamheader buffers, then flush our internal queue */
479 GST_DEBUG_OBJECT (this, "Pushing GDP new_segment buffer %p with offset %"
480 G_GINT64_FORMAT ", offset_end %" G_GINT64_FORMAT, this->new_segment_buf,
481 GST_BUFFER_OFFSET (this->new_segment_buf),
482 GST_BUFFER_OFFSET_END (this->new_segment_buf));
483 /* we stored these bufs with refcount 1, so make sure we keep a ref */
484 r = gst_pad_push (this->srcpad, gst_buffer_ref (this->new_segment_buf));
485 if (r != GST_FLOW_OK) {
486 GST_WARNING_OBJECT (this, "pushing GDP newsegment buffer returned %d", r);
490 gst_buffer_set_caps (this->tag_buf, caps);
491 GST_DEBUG_OBJECT (this, "Pushing GDP tag buffer %p", this->tag_buf);
492 /* we stored these bufs with refcount 1, so make sure we keep a ref */
493 r = gst_pad_push (this->srcpad, gst_buffer_ref (this->tag_buf));
494 if (r != GST_FLOW_OK) {
495 GST_WARNING_OBJECT (this, "pushing GDP tag buffer returned %d", r);
499 GST_DEBUG_OBJECT (this, "Pushing GDP caps buffer %p", this->caps_buf);
500 r = gst_pad_push (this->srcpad, gst_buffer_ref (this->caps_buf));
501 if (r != GST_FLOW_OK) {
502 GST_WARNING_OBJECT (this, "pushing GDP caps buffer returned %d", r);
505 this->sent_streamheader = TRUE;
506 GST_DEBUG_OBJECT (this, "need to push %d queued buffers",
507 g_list_length (this->queue));
508 while (this->queue) {
511 buffer = GST_BUFFER_CAST (this->queue->data);
512 GST_DEBUG_OBJECT (this, "Pushing queued GDP buffer %p", buffer);
514 /* delete buffer from queue now */
515 this->queue = g_list_delete_link (this->queue, this->queue);
517 /* set caps and push */
518 gst_buffer_set_caps (buffer, caps);
519 r = gst_pad_push (this->srcpad, buffer);
520 if (r != GST_FLOW_OK) {
521 GST_WARNING_OBJECT (this, "pushing queued GDP buffer returned %d", r);
527 gst_caps_unref (caps);
528 GST_DEBUG_OBJECT (this, "stop");
534 GST_ELEMENT_ERROR (this, STREAM, FORMAT, (NULL),
535 ("failed to create GDP buffer from streamheader"));
536 return GST_FLOW_ERROR;
540 /* queue a buffer internally if we haven't sent streamheader buffers yet;
541 * otherwise, just push on, this takes ownership of the buffer. */
543 gst_gdp_queue_buffer (GstGDPPay * this, GstBuffer * buffer)
545 if (this->sent_streamheader) {
546 GST_LOG_OBJECT (this, "Pushing GDP buffer %p, caps %" GST_PTR_FORMAT,
548 gst_buffer_set_caps (buffer, GST_PAD_CAPS (this->srcpad));
549 return gst_pad_push (this->srcpad, buffer);
552 /* store it on an internal queue. buffer remains reffed. */
553 this->queue = g_list_append (this->queue, buffer);
554 GST_DEBUG_OBJECT (this, "streamheader not sent yet, "
555 "queued buffer %p, now %d buffers queued",
556 buffer, g_list_length (this->queue));
562 gst_gdp_pay_chain (GstPad * pad, GstBuffer * buffer)
566 GstBuffer *outbuffer;
569 this = GST_GDP_PAY (gst_pad_get_parent (pad));
571 /* we should have received a new_segment before, otherwise it's a bug.
572 * fake one in that case */
573 if (!this->new_segment_buf) {
576 GST_WARNING_OBJECT (this,
577 "did not receive new-segment before first buffer");
578 event = gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
579 outbuffer = gst_gdp_buffer_from_event (this, event);
580 gst_event_unref (event);
582 /* GDP 0.2 doesn't know about new-segment, so this is not fatal */
584 GST_ELEMENT_WARNING (this, STREAM, ENCODE, (NULL),
585 ("Could not create GDP buffer from new segment event"));
587 GST_BUFFER_TIMESTAMP (outbuffer) = GST_BUFFER_TIMESTAMP (buffer);
588 GST_BUFFER_DURATION (outbuffer) = 0;
589 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
590 GST_DEBUG_OBJECT (this, "Storing buffer %p as new_segment_buf",
592 this->new_segment_buf = outbuffer;
596 /* make sure we've received caps before */
597 caps = gst_buffer_get_caps (buffer);
598 if (!this->caps && !caps)
601 /* if the caps have changed, process caps first */
602 if (caps && !gst_caps_is_equal (this->caps, caps)) {
603 GST_LOG_OBJECT (this, "caps changed to %p, %" GST_PTR_FORMAT, caps, caps);
604 gst_caps_replace (&(this->caps), caps);
605 outbuffer = gst_gdp_buffer_from_caps (this, caps);
609 GST_BUFFER_TIMESTAMP (outbuffer) = GST_BUFFER_TIMESTAMP (buffer);
610 GST_BUFFER_DURATION (outbuffer) = 0;
611 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
614 gst_buffer_unref (this->caps_buf);
615 this->caps_buf = outbuffer;
616 gst_gdp_pay_reset_streamheader (this);
620 gst_caps_unref (caps);
622 /* create a GDP header packet,
623 * then create a GST buffer of the header packet and the buffer contents */
624 outbuffer = gst_gdp_pay_buffer_from_buffer (this, buffer);
628 /* If the incoming buffer is IN_CAPS, that means we have it on the caps
629 * as streamheader, and we have serialized a GDP version of it and put it
631 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_IN_CAPS)) {
632 GST_DEBUG_OBJECT (this, "Setting IN_CAPS flag on outgoing buffer %p",
634 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
637 gst_gdp_stamp_buffer (this, outbuffer);
638 GST_BUFFER_TIMESTAMP (outbuffer) = GST_BUFFER_TIMESTAMP (buffer);
639 GST_BUFFER_DURATION (outbuffer) = GST_BUFFER_DURATION (buffer);
641 ret = gst_gdp_queue_buffer (this, outbuffer);
644 gst_buffer_unref (buffer);
645 gst_object_unref (this);
651 /* when returning a fatal error as a GstFlowReturn we must post an error
653 GST_ELEMENT_ERROR (this, STREAM, FORMAT, (NULL),
654 ("first received buffer does not have caps set"));
656 gst_caps_unref (caps);
657 ret = GST_FLOW_NOT_NEGOTIATED;
662 GST_ELEMENT_ERROR (this, STREAM, ENCODE, (NULL),
663 ("Could not create GDP buffer from caps %" GST_PTR_FORMAT, caps));
664 gst_caps_unref (caps);
665 ret = GST_FLOW_ERROR;
670 GST_ELEMENT_ERROR (this, STREAM, ENCODE, (NULL),
671 ("Could not create GDP buffer from buffer"));
672 ret = GST_FLOW_ERROR;
678 gst_gdp_pay_sink_event (GstPad * pad, GstEvent * event)
680 GstBuffer *outbuffer;
681 GstGDPPay *this = GST_GDP_PAY (gst_pad_get_parent (pad));
682 GstFlowReturn flowret;
685 GST_DEBUG_OBJECT (this, "received event %p of type %s (%d)",
686 event, gst_event_type_get_name (event->type), event->type);
688 /* now turn the event into a buffer */
689 outbuffer = gst_gdp_buffer_from_event (this, event);
693 GST_BUFFER_TIMESTAMP (outbuffer) = GST_EVENT_TIMESTAMP (event);
694 GST_BUFFER_DURATION (outbuffer) = 0;
696 /* if we got a new segment or tag event, we should put it on our streamheader,
697 * and not send it on */
698 switch (GST_EVENT_TYPE (event)) {
699 case GST_EVENT_NEWSEGMENT:
700 GST_DEBUG_OBJECT (this, "Storing in caps buffer %p as new_segment_buf",
703 if (this->new_segment_buf)
704 gst_buffer_unref (this->new_segment_buf);
705 this->new_segment_buf = outbuffer;
707 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
708 gst_gdp_pay_reset_streamheader (this);
711 GST_DEBUG_OBJECT (this, "Storing in caps buffer %p as tag_buf",
715 gst_buffer_unref (this->tag_buf);
716 this->tag_buf = outbuffer;
718 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
719 gst_gdp_pay_reset_streamheader (this);
722 GST_DEBUG_OBJECT (this, "queuing GDP buffer %p of event %p", outbuffer,
724 flowret = gst_gdp_queue_buffer (this, outbuffer);
725 if (flowret != GST_FLOW_OK)
730 /* if we have EOS, we should send on EOS ourselves */
731 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
732 GST_DEBUG_OBJECT (this, "Sending on EOS event %p", event);
733 /* ref, we unref later again */
734 ret = gst_pad_push_event (this->srcpad, gst_event_ref (event));
738 gst_event_unref (event);
739 gst_object_unref (this);
746 GST_ELEMENT_WARNING (this, STREAM, ENCODE, (NULL),
747 ("Could not create GDP buffer from received event (type %s)",
748 gst_event_type_get_name (event->type)));
754 GST_WARNING_OBJECT (this, "queueing GDP event buffer returned %d", flowret);
761 gst_gdp_pay_src_event (GstPad * pad, GstEvent * event)
766 this = GST_GDP_PAY (gst_pad_get_parent (pad));
768 switch (GST_EVENT_TYPE (event)) {
770 /* we refuse seek for now. */
771 gst_event_unref (event);
775 case GST_EVENT_NAVIGATION:
777 /* everything else is passed */
778 res = gst_pad_push_event (this->sinkpad, event);
781 gst_object_unref (this);
787 gst_gdp_pay_set_property (GObject * object, guint prop_id,
788 const GValue * value, GParamSpec * pspec)
792 g_return_if_fail (GST_IS_GDP_PAY (object));
793 this = GST_GDP_PAY (object);
796 case PROP_CRC_HEADER:
798 g_value_get_boolean (value) ? GST_DP_HEADER_FLAG_CRC_HEADER : 0;
799 this->header_flag = this->crc_header | this->crc_payload;
801 case PROP_CRC_PAYLOAD:
803 g_value_get_boolean (value) ? GST_DP_HEADER_FLAG_CRC_PAYLOAD : 0;
804 this->header_flag = this->crc_header | this->crc_payload;
807 this->version = g_value_get_enum (value);
810 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
816 gst_gdp_pay_get_property (GObject * object, guint prop_id,
817 GValue * value, GParamSpec * pspec)
821 g_return_if_fail (GST_IS_GDP_PAY (object));
822 this = GST_GDP_PAY (object);
825 case PROP_CRC_HEADER:
826 g_value_set_boolean (value, this->crc_header);
828 case PROP_CRC_PAYLOAD:
829 g_value_set_boolean (value, this->crc_payload);
832 g_value_set_enum (value, this->version);
835 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
840 static GstStateChangeReturn
841 gst_gdp_pay_change_state (GstElement * element, GstStateChange transition)
843 GstStateChangeReturn ret;
844 GstGDPPay *this = GST_GDP_PAY (element);
846 switch (transition) {
847 case GST_STATE_CHANGE_READY_TO_PAUSED:
853 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
855 switch (transition) {
856 case GST_STATE_CHANGE_PAUSED_TO_READY:
857 gst_gdp_pay_reset (this);
867 gst_gdp_pay_plugin_init (GstPlugin * plugin)
869 if (!gst_element_register (plugin, "gdppay", GST_RANK_NONE, GST_TYPE_GDP_PAY))