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);
81 static gboolean gst_gdp_pay_src_event (GstPad * pad, GstEvent * event);
83 static gboolean gst_gdp_pay_sink_event (GstPad * pad, GstEvent * event);
85 static GstStateChangeReturn gst_gdp_pay_change_state (GstElement *
86 element, GstStateChange transition);
88 static void gst_gdp_pay_set_property (GObject * object, guint prop_id,
89 const GValue * value, GParamSpec * pspec);
90 static void gst_gdp_pay_get_property (GObject * object, guint prop_id,
91 GValue * value, GParamSpec * pspec);
93 static void gst_gdp_pay_finalize (GObject * gobject);
96 gst_gdp_pay_base_init (gpointer g_class)
98 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
100 gst_element_class_set_details_simple (element_class,
101 "GDP Payloader", "GDP/Payloader",
102 "Payloads GStreamer Data Protocol buffers",
103 "Thomas Vander Stichele <thomas at apestaart dot org>");
105 gst_element_class_add_pad_template (element_class,
106 gst_static_pad_template_get (&gdp_pay_sink_template));
107 gst_element_class_add_pad_template (element_class,
108 gst_static_pad_template_get (&gdp_pay_src_template));
112 gst_gdp_pay_class_init (GstGDPPayClass * klass)
114 GObjectClass *gobject_class;
116 GstElementClass *gstelement_class;
118 gobject_class = (GObjectClass *) klass;
119 gstelement_class = (GstElementClass *) klass;
121 gobject_class->set_property = gst_gdp_pay_set_property;
122 gobject_class->get_property = gst_gdp_pay_get_property;
123 gobject_class->finalize = gst_gdp_pay_finalize;
125 g_object_class_install_property (gobject_class, PROP_CRC_HEADER,
126 g_param_spec_boolean ("crc-header", "CRC Header",
127 "Calculate and store a CRC checksum on the header",
128 DEFAULT_CRC_HEADER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
129 g_object_class_install_property (gobject_class, PROP_CRC_PAYLOAD,
130 g_param_spec_boolean ("crc-payload", "CRC Payload",
131 "Calculate and store a CRC checksum on the payload",
132 DEFAULT_CRC_PAYLOAD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
133 g_object_class_install_property (gobject_class, PROP_VERSION,
134 g_param_spec_enum ("version", "Version",
135 "Version of the GStreamer Data Protocol",
136 GST_TYPE_DP_VERSION, DEFAULT_VERSION,
137 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
139 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_gdp_pay_change_state);
143 gst_gdp_pay_init (GstGDPPay * gdppay, GstGDPPayClass * g_class)
146 gst_pad_new_from_static_template (&gdp_pay_sink_template, "sink");
147 gst_pad_set_chain_function (gdppay->sinkpad,
148 GST_DEBUG_FUNCPTR (gst_gdp_pay_chain));
149 gst_pad_set_event_function (gdppay->sinkpad,
150 GST_DEBUG_FUNCPTR (gst_gdp_pay_sink_event));
151 gst_element_add_pad (GST_ELEMENT (gdppay), gdppay->sinkpad);
154 gst_pad_new_from_static_template (&gdp_pay_src_template, "src");
155 gst_pad_set_event_function (gdppay->srcpad,
156 GST_DEBUG_FUNCPTR (gst_gdp_pay_src_event));
157 gst_element_add_pad (GST_ELEMENT (gdppay), gdppay->srcpad);
159 gdppay->crc_header = DEFAULT_CRC_HEADER;
160 gdppay->crc_payload = DEFAULT_CRC_PAYLOAD;
161 gdppay->header_flag = gdppay->crc_header | gdppay->crc_payload;
162 gdppay->version = DEFAULT_VERSION;
165 gdppay->packetizer = gst_dp_packetizer_new (gdppay->version);
169 gst_gdp_pay_finalize (GObject * gobject)
171 GstGDPPay *this = GST_GDP_PAY (gobject);
173 gst_gdp_pay_reset (this);
174 gst_dp_packetizer_free (this->packetizer);
176 GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (gobject));
180 gst_gdp_pay_reset (GstGDPPay * this)
182 GST_DEBUG_OBJECT (this, "Resetting GDP object");
183 /* clear the queued buffers */
184 while (this->queue) {
187 buffer = GST_BUFFER_CAST (this->queue->data);
189 /* delete buffer from queue now */
190 this->queue = g_list_delete_link (this->queue, this->queue);
192 gst_buffer_unref (buffer);
195 gst_caps_unref (this->caps);
198 if (this->caps_buf) {
199 gst_buffer_unref (this->caps_buf);
200 this->caps_buf = NULL;
203 gst_buffer_unref (this->tag_buf);
204 this->tag_buf = NULL;
206 if (this->new_segment_buf) {
207 gst_buffer_unref (this->new_segment_buf);
208 this->new_segment_buf = NULL;
210 this->sent_streamheader = FALSE;
214 /* set OFFSET and OFFSET_END with running count */
216 gst_gdp_stamp_buffer (GstGDPPay * this, GstBuffer * buffer)
218 GST_BUFFER_OFFSET (buffer) = this->offset;
219 GST_BUFFER_OFFSET_END (buffer) = this->offset + GST_BUFFER_SIZE (buffer);
220 this->offset = GST_BUFFER_OFFSET_END (buffer);
224 gst_gdp_buffer_from_caps (GstGDPPay * this, GstCaps * caps)
226 GstBuffer *headerbuf;
228 GstBuffer *payloadbuf;
230 guint8 *header, *payload;
234 if (!this->packetizer->packet_from_caps (caps, this->header_flag, &len,
238 GST_LOG_OBJECT (this, "creating GDP header and payload buffer from caps");
239 headerbuf = gst_buffer_new ();
240 gst_buffer_set_data (headerbuf, header, len);
241 GST_BUFFER_MALLOCDATA (headerbuf) = header;
243 payloadbuf = gst_buffer_new ();
244 gst_buffer_set_data (payloadbuf, payload,
245 gst_dp_header_payload_length (header));
246 GST_BUFFER_MALLOCDATA (payloadbuf) = payload;
248 return gst_buffer_join (headerbuf, payloadbuf);
253 GST_WARNING_OBJECT (this, "could not create GDP header from caps");
259 gst_gdp_pay_buffer_from_buffer (GstGDPPay * this, GstBuffer * buffer)
261 GstBuffer *headerbuf;
267 if (!this->packetizer->header_from_buffer (buffer, this->header_flag, &len,
271 GST_LOG_OBJECT (this, "creating GDP header and payload buffer from buffer");
272 headerbuf = gst_buffer_new ();
273 gst_buffer_set_data (headerbuf, header, len);
274 GST_BUFFER_MALLOCDATA (headerbuf) = header;
276 /* we do not want to lose the ref on the incoming buffer */
277 gst_buffer_ref (buffer);
279 return gst_buffer_join (headerbuf, buffer);
284 GST_WARNING_OBJECT (this, "could not create GDP header from buffer");
290 gst_gdp_buffer_from_event (GstGDPPay * this, GstEvent * event)
292 GstBuffer *headerbuf;
294 GstBuffer *payloadbuf;
296 guint8 *header, *payload;
303 this->packetizer->packet_from_event (event, this->header_flag, &len,
308 GST_LOG_OBJECT (this, "creating GDP header and payload buffer from event");
309 headerbuf = gst_buffer_new ();
310 gst_buffer_set_data (headerbuf, header, len);
311 GST_BUFFER_MALLOCDATA (headerbuf) = header;
313 payloadbuf = gst_buffer_new ();
314 gst_buffer_set_data (payloadbuf, payload,
315 gst_dp_header_payload_length (header));
316 GST_BUFFER_MALLOCDATA (payloadbuf) = payload;
318 return gst_buffer_join (headerbuf, payloadbuf);
323 GST_WARNING_OBJECT (this, "could not create GDP header from event %s (%d)",
324 gst_event_type_get_name (event->type), event->type);
330 /* set our caps with streamheader, based on the latest newsegment and caps,
331 * and (possibly) GDP-serialized buffers of the streamheaders on the src pad */
333 gst_gdp_pay_reset_streamheader (GstGDPPay * this)
337 /* We use copies of these to avoid circular refcounts */
338 GstBuffer *new_segment_buf, *caps_buf, *tag_buf;
340 GstStructure *structure;
342 GstFlowReturn r = GST_FLOW_OK;
344 gboolean version_one_zero = TRUE;
346 GValue array = { 0 };
347 GValue value = { 0 };
349 GST_DEBUG_OBJECT (this, "start");
350 /* In version 0.2, we didn't need or send new segment or tags */
351 if (this->version == GST_DP_VERSION_0_2)
352 version_one_zero = FALSE;
354 if (version_one_zero) {
355 if (!this->new_segment_buf || !this->caps_buf) {
356 GST_DEBUG_OBJECT (this, "1.0, missing new_segment or caps, returning");
360 if (!this->caps_buf) {
361 GST_DEBUG_OBJECT (this, "0.2, missing caps, returning");
366 /* put copies of the buffers in a fixed list
367 * Stamp the buffers with offset and offset_end as well.
368 * We do this here so the offsets match the order the buffers go out in */
369 g_value_init (&array, GST_TYPE_ARRAY);
371 if (version_one_zero) {
372 gst_gdp_stamp_buffer (this, this->new_segment_buf);
373 GST_DEBUG_OBJECT (this, "1.0, appending copy of new segment buffer %p",
374 this->new_segment_buf);
375 new_segment_buf = gst_buffer_copy (this->new_segment_buf);
376 gst_buffer_set_caps (new_segment_buf, NULL);
377 g_value_init (&value, GST_TYPE_BUFFER);
378 gst_value_set_buffer (&value, new_segment_buf);
379 gst_value_array_append_value (&array, &value);
380 g_value_unset (&value);
381 gst_buffer_unref (new_segment_buf);
384 gst_gdp_stamp_buffer (this, this->tag_buf);
385 GST_DEBUG_OBJECT (this, "1.0, appending current tags buffer %p",
387 tag_buf = this->tag_buf;
388 this->tag_buf = NULL;
390 gst_buffer_set_caps (tag_buf, NULL);
391 g_value_init (&value, GST_TYPE_BUFFER);
392 gst_value_set_buffer (&value, tag_buf);
393 gst_value_array_append_value (&array, &value);
394 g_value_unset (&value);
395 gst_buffer_unref (tag_buf);
399 gst_gdp_stamp_buffer (this, this->caps_buf);
400 GST_DEBUG_OBJECT (this, "appending copy of caps buffer %p", this->caps_buf);
401 caps_buf = gst_buffer_copy (this->caps_buf);
402 gst_buffer_set_caps (caps_buf, NULL);
403 g_value_init (&value, GST_TYPE_BUFFER);
404 gst_value_set_buffer (&value, caps_buf);
405 gst_value_array_append_value (&array, &value);
406 g_value_unset (&value);
407 gst_buffer_unref (caps_buf);
409 /* we also need to add GDP serializations of the streamheaders of the
411 structure = gst_caps_get_structure (this->caps, 0);
412 if (gst_structure_has_field (structure, "streamheader")) {
421 sh = gst_structure_get_value (structure, "streamheader");
422 buffers = g_value_peek_pointer (sh);
423 GST_DEBUG_OBJECT (this,
424 "Need to serialize %d incoming streamheader buffers on ours",
426 for (i = 0; i < buffers->len; ++i) {
429 GstBuffer *outbuffer;
431 bufval = &g_array_index (buffers, GValue, i);
432 buffer = g_value_peek_pointer (bufval);
433 /* this buffer is deserialized by gdpdepay as a regular buffer,
434 it needs IN_CAPS, because it's a streamheader - otherwise it
435 is mixed with regular data buffers */
436 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS);
437 GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE;
438 GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE;
439 GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE;
441 outbuffer = gst_gdp_pay_buffer_from_buffer (this, buffer);
443 g_value_unset (&array);
447 /* Setting IN_CAPS as other GDP event buffers */
448 GST_DEBUG_OBJECT (this,
449 "Setting IN_CAPS flag on outgoing buffer %" GST_PTR_FORMAT,
451 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
452 GST_BUFFER_OFFSET (outbuffer) = GST_BUFFER_OFFSET_NONE;
453 GST_BUFFER_OFFSET_END (outbuffer) = GST_BUFFER_OFFSET_NONE;
454 GST_BUFFER_TIMESTAMP (outbuffer) = GST_CLOCK_TIME_NONE;
456 g_value_init (&value, GST_TYPE_BUFFER);
457 gst_value_set_buffer (&value, outbuffer);
458 gst_value_array_append_value (&array, &value);
459 g_value_unset (&value);
461 gst_buffer_unref (outbuffer);
464 GST_DEBUG_OBJECT (this, "no streamheader to serialize");
467 GST_DEBUG_OBJECT (this, "%d serialized buffers on streamheaders",
468 gst_value_array_get_size (&array));
469 caps = gst_caps_from_string ("application/x-gdp");
470 structure = gst_caps_get_structure (caps, 0);
472 gst_structure_set_value (structure, "streamheader", &array);
473 g_value_unset (&array);
475 GST_DEBUG_OBJECT (this, "Setting caps on src pad %" GST_PTR_FORMAT, caps);
476 gst_pad_set_caps (this->srcpad, caps);
477 this->caps_buf = gst_buffer_make_metadata_writable (this->caps_buf);
478 gst_buffer_set_caps (this->caps_buf, caps);
479 this->new_segment_buf =
480 gst_buffer_make_metadata_writable (this->new_segment_buf);
481 gst_buffer_set_caps (this->new_segment_buf, caps);
483 /* if these are our first ever buffers, send out new_segment first */
484 if (!this->sent_streamheader) {
486 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
487 GST_DEBUG_OBJECT (this, "Sending out new_segment event %p", event);
488 if (!gst_pad_push_event (this->srcpad, event)) {
489 GST_WARNING_OBJECT (this, "pushing new segment failed");
495 /* push out these streamheader buffers, then flush our internal queue */
496 GST_DEBUG_OBJECT (this, "Pushing GDP new_segment buffer %p with offset %"
497 G_GINT64_FORMAT ", offset_end %" G_GINT64_FORMAT, this->new_segment_buf,
498 GST_BUFFER_OFFSET (this->new_segment_buf),
499 GST_BUFFER_OFFSET_END (this->new_segment_buf));
500 /* we stored these bufs with refcount 1, so make sure we keep a ref */
501 r = gst_pad_push (this->srcpad, gst_buffer_ref (this->new_segment_buf));
502 if (r != GST_FLOW_OK) {
503 GST_WARNING_OBJECT (this, "pushing GDP newsegment buffer returned %d", r);
507 gst_buffer_set_caps (this->tag_buf, caps);
508 GST_DEBUG_OBJECT (this, "Pushing GDP tag buffer %p", this->tag_buf);
509 /* we stored these bufs with refcount 1, so make sure we keep a ref */
510 r = gst_pad_push (this->srcpad, gst_buffer_ref (this->tag_buf));
511 if (r != GST_FLOW_OK) {
512 GST_WARNING_OBJECT (this, "pushing GDP tag buffer returned %d", r);
516 GST_DEBUG_OBJECT (this, "Pushing GDP caps buffer %p", this->caps_buf);
517 r = gst_pad_push (this->srcpad, gst_buffer_ref (this->caps_buf));
518 if (r != GST_FLOW_OK) {
519 GST_WARNING_OBJECT (this, "pushing GDP caps buffer returned %d", r);
522 this->sent_streamheader = TRUE;
523 GST_DEBUG_OBJECT (this, "need to push %d queued buffers",
524 g_list_length (this->queue));
525 while (this->queue) {
528 buffer = GST_BUFFER_CAST (this->queue->data);
529 GST_DEBUG_OBJECT (this, "Pushing queued GDP buffer %p", buffer);
531 /* delete buffer from queue now */
532 this->queue = g_list_delete_link (this->queue, this->queue);
534 /* set caps and push */
535 gst_buffer_set_caps (buffer, caps);
536 r = gst_pad_push (this->srcpad, buffer);
537 if (r != GST_FLOW_OK) {
538 GST_WARNING_OBJECT (this, "pushing queued GDP buffer returned %d", r);
544 gst_caps_unref (caps);
545 GST_DEBUG_OBJECT (this, "stop");
551 GST_ELEMENT_ERROR (this, STREAM, FORMAT, (NULL),
552 ("failed to create GDP buffer from streamheader"));
553 return GST_FLOW_ERROR;
557 /* queue a buffer internally if we haven't sent streamheader buffers yet;
558 * otherwise, just push on, this takes ownership of the buffer. */
560 gst_gdp_queue_buffer (GstGDPPay * this, GstBuffer * buffer)
562 if (this->sent_streamheader) {
563 GST_LOG_OBJECT (this, "Pushing GDP buffer %p, caps %" GST_PTR_FORMAT,
565 gst_buffer_set_caps (buffer, GST_PAD_CAPS (this->srcpad));
566 return gst_pad_push (this->srcpad, buffer);
569 /* store it on an internal queue. buffer remains reffed. */
570 this->queue = g_list_append (this->queue, buffer);
571 GST_DEBUG_OBJECT (this, "streamheader not sent yet, "
572 "queued buffer %p, now %d buffers queued",
573 buffer, g_list_length (this->queue));
579 gst_gdp_pay_chain (GstPad * pad, GstBuffer * buffer)
585 GstBuffer *outbuffer;
589 this = GST_GDP_PAY (gst_pad_get_parent (pad));
591 /* we should have received a new_segment before, otherwise it's a bug.
592 * fake one in that case */
593 if (!this->new_segment_buf) {
596 GST_WARNING_OBJECT (this,
597 "did not receive new-segment before first buffer");
598 event = gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
599 outbuffer = gst_gdp_buffer_from_event (this, event);
600 gst_event_unref (event);
602 /* GDP 0.2 doesn't know about new-segment, so this is not fatal */
604 GST_ELEMENT_WARNING (this, STREAM, ENCODE, (NULL),
605 ("Could not create GDP buffer from new segment event"));
607 GST_BUFFER_TIMESTAMP (outbuffer) = GST_BUFFER_TIMESTAMP (buffer);
608 GST_BUFFER_DURATION (outbuffer) = 0;
609 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
610 GST_DEBUG_OBJECT (this, "Storing buffer %p as new_segment_buf",
612 this->new_segment_buf = outbuffer;
616 /* make sure we've received caps before */
617 caps = gst_buffer_get_caps (buffer);
618 if (!this->caps && !caps)
621 /* if the caps have changed, process caps first */
622 if (caps && !gst_caps_is_equal (this->caps, caps)) {
623 GST_LOG_OBJECT (this, "caps changed to %p, %" GST_PTR_FORMAT, caps, caps);
624 gst_caps_replace (&(this->caps), caps);
625 outbuffer = gst_gdp_buffer_from_caps (this, caps);
629 GST_BUFFER_TIMESTAMP (outbuffer) = GST_BUFFER_TIMESTAMP (buffer);
630 GST_BUFFER_DURATION (outbuffer) = 0;
631 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
634 gst_buffer_unref (this->caps_buf);
635 this->caps_buf = outbuffer;
636 gst_gdp_pay_reset_streamheader (this);
640 gst_caps_unref (caps);
642 /* create a GDP header packet,
643 * then create a GST buffer of the header packet and the buffer contents */
644 outbuffer = gst_gdp_pay_buffer_from_buffer (this, buffer);
648 /* If the incoming buffer is IN_CAPS, that means we have it on the caps
649 * as streamheader, and we have serialized a GDP version of it and put it
651 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_IN_CAPS)) {
652 GST_DEBUG_OBJECT (this, "Setting IN_CAPS flag on outgoing buffer %p",
654 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
657 gst_gdp_stamp_buffer (this, outbuffer);
658 GST_BUFFER_TIMESTAMP (outbuffer) = GST_BUFFER_TIMESTAMP (buffer);
659 GST_BUFFER_DURATION (outbuffer) = GST_BUFFER_DURATION (buffer);
661 ret = gst_gdp_queue_buffer (this, outbuffer);
664 gst_buffer_unref (buffer);
665 gst_object_unref (this);
671 /* when returning a fatal error as a GstFlowReturn we must post an error
673 GST_ELEMENT_ERROR (this, STREAM, FORMAT, (NULL),
674 ("first received buffer does not have caps set"));
676 gst_caps_unref (caps);
677 ret = GST_FLOW_NOT_NEGOTIATED;
682 GST_ELEMENT_ERROR (this, STREAM, ENCODE, (NULL),
683 ("Could not create GDP buffer from caps %" GST_PTR_FORMAT, caps));
684 gst_caps_unref (caps);
685 ret = GST_FLOW_ERROR;
690 GST_ELEMENT_ERROR (this, STREAM, ENCODE, (NULL),
691 ("Could not create GDP buffer from buffer"));
692 ret = GST_FLOW_ERROR;
698 gst_gdp_pay_sink_event (GstPad * pad, GstEvent * event)
700 GstBuffer *outbuffer;
702 GstGDPPay *this = GST_GDP_PAY (gst_pad_get_parent (pad));
704 GstFlowReturn flowret;
708 GST_DEBUG_OBJECT (this, "received event %p of type %s (%d)",
709 event, gst_event_type_get_name (event->type), event->type);
711 /* now turn the event into a buffer */
712 outbuffer = gst_gdp_buffer_from_event (this, event);
716 GST_BUFFER_TIMESTAMP (outbuffer) = GST_EVENT_TIMESTAMP (event);
717 GST_BUFFER_DURATION (outbuffer) = 0;
719 /* if we got a new segment or tag event, we should put it on our streamheader,
720 * and not send it on */
721 switch (GST_EVENT_TYPE (event)) {
722 case GST_EVENT_NEWSEGMENT:
723 GST_DEBUG_OBJECT (this, "Storing in caps buffer %p as new_segment_buf",
726 if (this->new_segment_buf)
727 gst_buffer_unref (this->new_segment_buf);
728 this->new_segment_buf = outbuffer;
730 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
731 gst_gdp_pay_reset_streamheader (this);
734 GST_DEBUG_OBJECT (this, "Storing in caps buffer %p as tag_buf",
738 gst_buffer_unref (this->tag_buf);
739 this->tag_buf = outbuffer;
741 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
742 gst_gdp_pay_reset_streamheader (this);
745 GST_DEBUG_OBJECT (this, "queuing GDP buffer %p of event %p", outbuffer,
747 flowret = gst_gdp_queue_buffer (this, outbuffer);
748 if (flowret != GST_FLOW_OK)
753 /* if we have EOS, we should send on EOS ourselves */
754 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
755 GST_DEBUG_OBJECT (this, "Sending on EOS event %p", event);
756 /* ref, we unref later again */
757 ret = gst_pad_push_event (this->srcpad, gst_event_ref (event));
761 gst_event_unref (event);
762 gst_object_unref (this);
769 GST_ELEMENT_WARNING (this, STREAM, ENCODE, (NULL),
770 ("Could not create GDP buffer from received event (type %s)",
771 gst_event_type_get_name (event->type)));
777 GST_WARNING_OBJECT (this, "queueing GDP event buffer returned %d", flowret);
784 gst_gdp_pay_src_event (GstPad * pad, GstEvent * event)
790 this = GST_GDP_PAY (gst_pad_get_parent (pad));
792 switch (GST_EVENT_TYPE (event)) {
794 /* we refuse seek for now. */
795 gst_event_unref (event);
799 case GST_EVENT_NAVIGATION:
801 /* everything else is passed */
802 res = gst_pad_push_event (this->sinkpad, event);
805 gst_object_unref (this);
811 gst_gdp_pay_set_property (GObject * object, guint prop_id,
812 const GValue * value, GParamSpec * pspec)
816 g_return_if_fail (GST_IS_GDP_PAY (object));
817 this = GST_GDP_PAY (object);
820 case PROP_CRC_HEADER:
822 g_value_get_boolean (value) ? GST_DP_HEADER_FLAG_CRC_HEADER : 0;
823 this->header_flag = this->crc_header | this->crc_payload;
825 case PROP_CRC_PAYLOAD:
827 g_value_get_boolean (value) ? GST_DP_HEADER_FLAG_CRC_PAYLOAD : 0;
828 this->header_flag = this->crc_header | this->crc_payload;
831 this->version = g_value_get_enum (value);
834 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
840 gst_gdp_pay_get_property (GObject * object, guint prop_id,
841 GValue * value, GParamSpec * pspec)
845 g_return_if_fail (GST_IS_GDP_PAY (object));
846 this = GST_GDP_PAY (object);
849 case PROP_CRC_HEADER:
850 g_value_set_boolean (value, this->crc_header);
852 case PROP_CRC_PAYLOAD:
853 g_value_set_boolean (value, this->crc_payload);
856 g_value_set_enum (value, this->version);
859 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
864 static GstStateChangeReturn
865 gst_gdp_pay_change_state (GstElement * element, GstStateChange transition)
867 GstStateChangeReturn ret;
869 GstGDPPay *this = GST_GDP_PAY (element);
871 switch (transition) {
872 case GST_STATE_CHANGE_READY_TO_PAUSED:
878 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
880 switch (transition) {
881 case GST_STATE_CHANGE_PAUSED_TO_READY:
882 gst_gdp_pay_reset (this);
892 gst_gdp_pay_plugin_init (GstPlugin * plugin)
894 if (!gst_element_register (plugin, "gdppay", GST_RANK_NONE, GST_TYPE_GDP_PAY))