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, \
73 #define gst_gdp_pay_parent_class parent_class
74 G_DEFINE_TYPE_WITH_CODE (GstGDPPay, gst_gdp_pay, GST_TYPE_ELEMENT, _do_init);
76 static void gst_gdp_pay_reset (GstGDPPay * this);
78 static GstFlowReturn gst_gdp_pay_chain (GstPad * pad, GstBuffer * buffer);
79 static gboolean gst_gdp_pay_src_event (GstPad * pad, GstEvent * event);
80 static gboolean gst_gdp_pay_sink_event (GstPad * pad, GstEvent * event);
82 static GstStateChangeReturn gst_gdp_pay_change_state (GstElement *
83 element, GstStateChange transition);
85 static void gst_gdp_pay_set_property (GObject * object, guint prop_id,
86 const GValue * value, GParamSpec * pspec);
87 static void gst_gdp_pay_get_property (GObject * object, guint prop_id,
88 GValue * value, GParamSpec * pspec);
90 static void gst_gdp_pay_finalize (GObject * gobject);
93 gst_gdp_pay_class_init (GstGDPPayClass * klass)
95 GObjectClass *gobject_class;
96 GstElementClass *gstelement_class;
98 gobject_class = (GObjectClass *) klass;
99 gstelement_class = (GstElementClass *) klass;
101 gobject_class->set_property = gst_gdp_pay_set_property;
102 gobject_class->get_property = gst_gdp_pay_get_property;
103 gobject_class->finalize = gst_gdp_pay_finalize;
105 g_object_class_install_property (gobject_class, PROP_CRC_HEADER,
106 g_param_spec_boolean ("crc-header", "CRC Header",
107 "Calculate and store a CRC checksum on the header",
108 DEFAULT_CRC_HEADER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
109 g_object_class_install_property (gobject_class, PROP_CRC_PAYLOAD,
110 g_param_spec_boolean ("crc-payload", "CRC Payload",
111 "Calculate and store a CRC checksum on the payload",
112 DEFAULT_CRC_PAYLOAD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
113 g_object_class_install_property (gobject_class, PROP_VERSION,
114 g_param_spec_enum ("version", "Version",
115 "Version of the GStreamer Data Protocol",
116 GST_TYPE_DP_VERSION, DEFAULT_VERSION,
117 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
119 gst_element_class_set_details_simple (gstelement_class,
120 "GDP Payloader", "GDP/Payloader",
121 "Payloads GStreamer Data Protocol buffers",
122 "Thomas Vander Stichele <thomas at apestaart dot org>");
124 gst_element_class_add_pad_template (gstelement_class,
125 gst_static_pad_template_get (&gdp_pay_sink_template));
126 gst_element_class_add_pad_template (gstelement_class,
127 gst_static_pad_template_get (&gdp_pay_src_template));
129 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_gdp_pay_change_state);
133 gst_gdp_pay_init (GstGDPPay * gdppay)
136 gst_pad_new_from_static_template (&gdp_pay_sink_template, "sink");
137 gst_pad_set_chain_function (gdppay->sinkpad,
138 GST_DEBUG_FUNCPTR (gst_gdp_pay_chain));
139 gst_pad_set_event_function (gdppay->sinkpad,
140 GST_DEBUG_FUNCPTR (gst_gdp_pay_sink_event));
141 gst_element_add_pad (GST_ELEMENT (gdppay), gdppay->sinkpad);
144 gst_pad_new_from_static_template (&gdp_pay_src_template, "src");
145 gst_pad_set_event_function (gdppay->srcpad,
146 GST_DEBUG_FUNCPTR (gst_gdp_pay_src_event));
147 gst_element_add_pad (GST_ELEMENT (gdppay), gdppay->srcpad);
149 gdppay->crc_header = DEFAULT_CRC_HEADER;
150 gdppay->crc_payload = DEFAULT_CRC_PAYLOAD;
151 gdppay->header_flag = gdppay->crc_header | gdppay->crc_payload;
152 gdppay->version = DEFAULT_VERSION;
155 gdppay->packetizer = gst_dp_packetizer_new (gdppay->version);
159 gst_gdp_pay_finalize (GObject * gobject)
161 GstGDPPay *this = GST_GDP_PAY (gobject);
163 gst_gdp_pay_reset (this);
164 gst_dp_packetizer_free (this->packetizer);
166 GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (gobject));
170 gst_gdp_pay_reset (GstGDPPay * this)
172 GST_DEBUG_OBJECT (this, "Resetting GDP object");
173 /* clear the queued buffers */
174 while (this->queue) {
177 buffer = GST_BUFFER_CAST (this->queue->data);
179 /* delete buffer from queue now */
180 this->queue = g_list_delete_link (this->queue, this->queue);
182 gst_buffer_unref (buffer);
185 gst_caps_unref (this->caps);
188 if (this->caps_buf) {
189 gst_buffer_unref (this->caps_buf);
190 this->caps_buf = NULL;
193 gst_buffer_unref (this->tag_buf);
194 this->tag_buf = NULL;
196 if (this->new_segment_buf) {
197 gst_buffer_unref (this->new_segment_buf);
198 this->new_segment_buf = NULL;
200 this->sent_streamheader = FALSE;
204 /* set OFFSET and OFFSET_END with running count */
206 gst_gdp_stamp_buffer (GstGDPPay * this, GstBuffer * buffer)
208 GST_BUFFER_OFFSET (buffer) = this->offset;
209 GST_BUFFER_OFFSET_END (buffer) = this->offset + gst_buffer_get_size (buffer);
210 this->offset = GST_BUFFER_OFFSET_END (buffer);
214 gst_gdp_buffer_from_caps (GstGDPPay * this, GstCaps * caps)
216 GstBuffer *headerbuf;
217 GstBuffer *payloadbuf;
218 guint8 *header, *payload;
221 if (!this->packetizer->packet_from_caps (caps, this->header_flag, &len,
225 GST_LOG_OBJECT (this, "creating GDP header and payload buffer from caps");
226 headerbuf = gst_buffer_new ();
227 gst_buffer_take_memory (headerbuf,
228 gst_memory_new_wrapped (0, header, g_free, len, 0, len));
230 payloadbuf = gst_buffer_new ();
231 plen = gst_dp_header_payload_length (header);
232 gst_buffer_take_memory (payloadbuf,
233 gst_memory_new_wrapped (0, payload, g_free, plen, 0, plen));
235 return gst_buffer_join (headerbuf, payloadbuf);
240 GST_WARNING_OBJECT (this, "could not create GDP header from caps");
246 gst_gdp_pay_buffer_from_buffer (GstGDPPay * this, GstBuffer * buffer)
248 GstBuffer *headerbuf;
252 if (!this->packetizer->header_from_buffer (buffer, this->header_flag, &len,
256 GST_LOG_OBJECT (this, "creating GDP header and payload buffer from buffer");
257 headerbuf = gst_buffer_new ();
258 gst_buffer_take_memory (headerbuf,
259 gst_memory_new_wrapped (0, header, g_free, len, 0, len));
261 /* we do not want to lose the ref on the incoming buffer */
262 gst_buffer_ref (buffer);
264 return gst_buffer_join (headerbuf, buffer);
269 GST_WARNING_OBJECT (this, "could not create GDP header from buffer");
275 gst_gdp_buffer_from_event (GstGDPPay * this, GstEvent * event)
277 GstBuffer *headerbuf;
278 GstBuffer *payloadbuf;
279 guint8 *header, *payload;
284 this->packetizer->packet_from_event (event, this->header_flag, &len,
289 GST_LOG_OBJECT (this, "creating GDP header and payload buffer from event");
290 headerbuf = gst_buffer_new ();
291 gst_buffer_take_memory (headerbuf,
292 gst_memory_new_wrapped (0, header, g_free, len, 0, len));
294 payloadbuf = gst_buffer_new ();
295 plen = gst_dp_header_payload_length (header);
296 if (plen && payload != NULL) {
297 gst_buffer_take_memory (payloadbuf,
298 gst_memory_new_wrapped (0, payload, g_free, plen, 0, plen));
301 return gst_buffer_join (headerbuf, payloadbuf);
306 GST_WARNING_OBJECT (this, "could not create GDP header from event %s (%d)",
307 gst_event_type_get_name (event->type), event->type);
313 /* set our caps with streamheader, based on the latest newsegment and caps,
314 * and (possibly) GDP-serialized buffers of the streamheaders on the src pad */
316 gst_gdp_pay_reset_streamheader (GstGDPPay * this)
319 /* We use copies of these to avoid circular refcounts */
320 GstBuffer *new_segment_buf, *caps_buf, *tag_buf;
321 GstStructure *structure;
322 GstFlowReturn r = GST_FLOW_OK;
323 gboolean version_one_zero = TRUE;
325 GValue array = { 0 };
326 GValue value = { 0 };
328 GST_DEBUG_OBJECT (this, "start");
329 /* In version 0.2, we didn't need or send new segment or tags */
330 if (this->version == GST_DP_VERSION_0_2)
331 version_one_zero = FALSE;
333 if (version_one_zero) {
334 if (!this->new_segment_buf || !this->caps_buf) {
335 GST_DEBUG_OBJECT (this, "1.0, missing new_segment or caps, returning");
339 if (!this->caps_buf) {
340 GST_DEBUG_OBJECT (this, "0.2, missing caps, returning");
345 /* put copies of the buffers in a fixed list
346 * Stamp the buffers with offset and offset_end as well.
347 * We do this here so the offsets match the order the buffers go out in */
348 g_value_init (&array, GST_TYPE_ARRAY);
350 if (version_one_zero) {
351 gst_gdp_stamp_buffer (this, this->new_segment_buf);
352 GST_DEBUG_OBJECT (this, "1.0, appending copy of new segment buffer %p",
353 this->new_segment_buf);
354 new_segment_buf = gst_buffer_copy (this->new_segment_buf);
355 gst_buffer_set_caps (new_segment_buf, NULL);
356 g_value_init (&value, GST_TYPE_BUFFER);
357 gst_value_set_buffer (&value, new_segment_buf);
358 gst_value_array_append_value (&array, &value);
359 g_value_unset (&value);
360 gst_buffer_unref (new_segment_buf);
363 gst_gdp_stamp_buffer (this, this->tag_buf);
364 GST_DEBUG_OBJECT (this, "1.0, appending current tags buffer %p",
366 tag_buf = this->tag_buf;
367 this->tag_buf = NULL;
369 gst_buffer_set_caps (tag_buf, NULL);
370 g_value_init (&value, GST_TYPE_BUFFER);
371 gst_value_set_buffer (&value, tag_buf);
372 gst_value_array_append_value (&array, &value);
373 g_value_unset (&value);
374 gst_buffer_unref (tag_buf);
378 gst_gdp_stamp_buffer (this, this->caps_buf);
379 GST_DEBUG_OBJECT (this, "appending copy of caps buffer %p", this->caps_buf);
380 caps_buf = gst_buffer_copy (this->caps_buf);
381 gst_buffer_set_caps (caps_buf, NULL);
382 g_value_init (&value, GST_TYPE_BUFFER);
383 gst_value_set_buffer (&value, caps_buf);
384 gst_value_array_append_value (&array, &value);
385 g_value_unset (&value);
386 gst_buffer_unref (caps_buf);
388 /* we also need to add GDP serializations of the streamheaders of the
390 structure = gst_caps_get_structure (this->caps, 0);
391 if (gst_structure_has_field (structure, "streamheader")) {
400 sh = gst_structure_get_value (structure, "streamheader");
401 buffers = g_value_peek_pointer (sh);
402 GST_DEBUG_OBJECT (this,
403 "Need to serialize %d incoming streamheader buffers on ours",
405 for (i = 0; i < buffers->len; ++i) {
408 GstBuffer *outbuffer;
410 bufval = &g_array_index (buffers, GValue, i);
411 buffer = g_value_peek_pointer (bufval);
412 /* this buffer is deserialized by gdpdepay as a regular buffer,
413 it needs IN_CAPS, because it's a streamheader - otherwise it
414 is mixed with regular data buffers */
415 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS);
416 GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE;
417 GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE;
418 GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE;
420 outbuffer = gst_gdp_pay_buffer_from_buffer (this, buffer);
422 g_value_unset (&array);
426 /* Setting IN_CAPS as other GDP event buffers */
427 GST_DEBUG_OBJECT (this,
428 "Setting IN_CAPS flag on outgoing buffer %" GST_PTR_FORMAT,
430 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
431 GST_BUFFER_OFFSET (outbuffer) = GST_BUFFER_OFFSET_NONE;
432 GST_BUFFER_OFFSET_END (outbuffer) = GST_BUFFER_OFFSET_NONE;
433 GST_BUFFER_TIMESTAMP (outbuffer) = GST_CLOCK_TIME_NONE;
435 g_value_init (&value, GST_TYPE_BUFFER);
436 gst_value_set_buffer (&value, outbuffer);
437 gst_value_array_append_value (&array, &value);
438 g_value_unset (&value);
440 gst_buffer_unref (outbuffer);
443 GST_DEBUG_OBJECT (this, "no streamheader to serialize");
446 GST_DEBUG_OBJECT (this, "%d serialized buffers on streamheaders",
447 gst_value_array_get_size (&array));
448 caps = gst_caps_from_string ("application/x-gdp");
449 structure = gst_caps_get_structure (caps, 0);
451 gst_structure_set_value (structure, "streamheader", &array);
452 g_value_unset (&array);
454 GST_DEBUG_OBJECT (this, "Setting caps on src pad %" GST_PTR_FORMAT, caps);
455 gst_pad_set_caps (this->srcpad, caps);
456 this->caps_buf = gst_buffer_make_writable (this->caps_buf);
457 gst_buffer_set_caps (this->caps_buf, caps);
458 this->new_segment_buf = gst_buffer_make_writable (this->new_segment_buf);
459 gst_buffer_set_caps (this->new_segment_buf, caps);
461 /* if these are our first ever buffers, send out new_segment first */
462 if (!this->sent_streamheader) {
464 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
465 GST_DEBUG_OBJECT (this, "Sending out new_segment event %p", event);
466 if (!gst_pad_push_event (this->srcpad, event)) {
467 GST_WARNING_OBJECT (this, "pushing new segment failed");
473 /* push out these streamheader buffers, then flush our internal queue */
474 GST_DEBUG_OBJECT (this, "Pushing GDP new_segment buffer %p with offset %"
475 G_GINT64_FORMAT ", offset_end %" G_GINT64_FORMAT, this->new_segment_buf,
476 GST_BUFFER_OFFSET (this->new_segment_buf),
477 GST_BUFFER_OFFSET_END (this->new_segment_buf));
478 /* we stored these bufs with refcount 1, so make sure we keep a ref */
479 r = gst_pad_push (this->srcpad, gst_buffer_ref (this->new_segment_buf));
480 if (r != GST_FLOW_OK) {
481 GST_WARNING_OBJECT (this, "pushing GDP newsegment buffer returned %d", r);
485 gst_buffer_set_caps (this->tag_buf, caps);
486 GST_DEBUG_OBJECT (this, "Pushing GDP tag buffer %p", this->tag_buf);
487 /* we stored these bufs with refcount 1, so make sure we keep a ref */
488 r = gst_pad_push (this->srcpad, gst_buffer_ref (this->tag_buf));
489 if (r != GST_FLOW_OK) {
490 GST_WARNING_OBJECT (this, "pushing GDP tag buffer returned %d", r);
494 GST_DEBUG_OBJECT (this, "Pushing GDP caps buffer %p", this->caps_buf);
495 r = gst_pad_push (this->srcpad, gst_buffer_ref (this->caps_buf));
496 if (r != GST_FLOW_OK) {
497 GST_WARNING_OBJECT (this, "pushing GDP caps buffer returned %d", r);
500 this->sent_streamheader = TRUE;
501 GST_DEBUG_OBJECT (this, "need to push %d queued buffers",
502 g_list_length (this->queue));
503 while (this->queue) {
506 buffer = GST_BUFFER_CAST (this->queue->data);
507 GST_DEBUG_OBJECT (this, "Pushing queued GDP buffer %p", buffer);
509 /* delete buffer from queue now */
510 this->queue = g_list_delete_link (this->queue, this->queue);
512 /* set caps and push */
513 gst_buffer_set_caps (buffer, caps);
514 r = gst_pad_push (this->srcpad, buffer);
515 if (r != GST_FLOW_OK) {
516 GST_WARNING_OBJECT (this, "pushing queued GDP buffer returned %d", r);
522 gst_caps_unref (caps);
523 GST_DEBUG_OBJECT (this, "stop");
529 GST_ELEMENT_ERROR (this, STREAM, FORMAT, (NULL),
530 ("failed to create GDP buffer from streamheader"));
531 return GST_FLOW_ERROR;
535 /* queue a buffer internally if we haven't sent streamheader buffers yet;
536 * otherwise, just push on, this takes ownership of the buffer. */
538 gst_gdp_queue_buffer (GstGDPPay * this, GstBuffer * buffer)
540 if (this->sent_streamheader) {
541 GST_LOG_OBJECT (this, "Pushing GDP buffer %p, caps %" GST_PTR_FORMAT,
543 gst_buffer_set_caps (buffer, GST_PAD_CAPS (this->srcpad));
544 return gst_pad_push (this->srcpad, buffer);
547 /* store it on an internal queue. buffer remains reffed. */
548 this->queue = g_list_append (this->queue, buffer);
549 GST_DEBUG_OBJECT (this, "streamheader not sent yet, "
550 "queued buffer %p, now %d buffers queued",
551 buffer, g_list_length (this->queue));
557 gst_gdp_pay_chain (GstPad * pad, GstBuffer * buffer)
561 GstBuffer *outbuffer;
564 this = GST_GDP_PAY (gst_pad_get_parent (pad));
566 /* we should have received a new_segment before, otherwise it's a bug.
567 * fake one in that case */
568 if (!this->new_segment_buf) {
571 GST_WARNING_OBJECT (this,
572 "did not receive new-segment before first buffer");
573 event = gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
574 outbuffer = gst_gdp_buffer_from_event (this, event);
575 gst_event_unref (event);
577 /* GDP 0.2 doesn't know about new-segment, so this is not fatal */
579 GST_ELEMENT_WARNING (this, STREAM, ENCODE, (NULL),
580 ("Could not create GDP buffer from new segment event"));
582 GST_BUFFER_TIMESTAMP (outbuffer) = GST_BUFFER_TIMESTAMP (buffer);
583 GST_BUFFER_DURATION (outbuffer) = 0;
584 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
585 GST_DEBUG_OBJECT (this, "Storing buffer %p as new_segment_buf",
587 this->new_segment_buf = outbuffer;
591 /* make sure we've received caps before */
592 caps = gst_buffer_get_caps (buffer);
593 if (!this->caps && !caps)
596 /* if the caps have changed, process caps first */
597 if (caps && !gst_caps_is_equal (this->caps, caps)) {
598 GST_LOG_OBJECT (this, "caps changed to %p, %" GST_PTR_FORMAT, caps, caps);
599 gst_caps_replace (&(this->caps), caps);
600 outbuffer = gst_gdp_buffer_from_caps (this, caps);
604 GST_BUFFER_TIMESTAMP (outbuffer) = GST_BUFFER_TIMESTAMP (buffer);
605 GST_BUFFER_DURATION (outbuffer) = 0;
606 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
609 gst_buffer_unref (this->caps_buf);
610 this->caps_buf = outbuffer;
611 gst_gdp_pay_reset_streamheader (this);
615 gst_caps_unref (caps);
617 /* create a GDP header packet,
618 * then create a GST buffer of the header packet and the buffer contents */
619 outbuffer = gst_gdp_pay_buffer_from_buffer (this, buffer);
623 /* If the incoming buffer is IN_CAPS, that means we have it on the caps
624 * as streamheader, and we have serialized a GDP version of it and put it
626 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_IN_CAPS)) {
627 GST_DEBUG_OBJECT (this, "Setting IN_CAPS flag on outgoing buffer %p",
629 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
632 gst_gdp_stamp_buffer (this, outbuffer);
633 GST_BUFFER_TIMESTAMP (outbuffer) = GST_BUFFER_TIMESTAMP (buffer);
634 GST_BUFFER_DURATION (outbuffer) = GST_BUFFER_DURATION (buffer);
636 ret = gst_gdp_queue_buffer (this, outbuffer);
639 gst_buffer_unref (buffer);
640 gst_object_unref (this);
646 /* when returning a fatal error as a GstFlowReturn we must post an error
648 GST_ELEMENT_ERROR (this, STREAM, FORMAT, (NULL),
649 ("first received buffer does not have caps set"));
651 gst_caps_unref (caps);
652 ret = GST_FLOW_NOT_NEGOTIATED;
657 GST_ELEMENT_ERROR (this, STREAM, ENCODE, (NULL),
658 ("Could not create GDP buffer from caps %" GST_PTR_FORMAT, caps));
659 gst_caps_unref (caps);
660 ret = GST_FLOW_ERROR;
665 GST_ELEMENT_ERROR (this, STREAM, ENCODE, (NULL),
666 ("Could not create GDP buffer from buffer"));
667 ret = GST_FLOW_ERROR;
673 gst_gdp_pay_sink_event (GstPad * pad, GstEvent * event)
675 GstBuffer *outbuffer;
676 GstGDPPay *this = GST_GDP_PAY (gst_pad_get_parent (pad));
677 GstFlowReturn flowret;
680 GST_DEBUG_OBJECT (this, "received event %p of type %s (%d)",
681 event, gst_event_type_get_name (event->type), event->type);
683 /* now turn the event into a buffer */
684 outbuffer = gst_gdp_buffer_from_event (this, event);
688 GST_BUFFER_TIMESTAMP (outbuffer) = GST_EVENT_TIMESTAMP (event);
689 GST_BUFFER_DURATION (outbuffer) = 0;
691 /* if we got a new segment or tag event, we should put it on our streamheader,
692 * and not send it on */
693 switch (GST_EVENT_TYPE (event)) {
694 case GST_EVENT_NEWSEGMENT:
695 GST_DEBUG_OBJECT (this, "Storing in caps buffer %p as new_segment_buf",
698 if (this->new_segment_buf)
699 gst_buffer_unref (this->new_segment_buf);
700 this->new_segment_buf = outbuffer;
702 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
703 gst_gdp_pay_reset_streamheader (this);
706 GST_DEBUG_OBJECT (this, "Storing in caps buffer %p as tag_buf",
710 gst_buffer_unref (this->tag_buf);
711 this->tag_buf = outbuffer;
713 GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS);
714 gst_gdp_pay_reset_streamheader (this);
717 GST_DEBUG_OBJECT (this, "queuing GDP buffer %p of event %p", outbuffer,
719 flowret = gst_gdp_queue_buffer (this, outbuffer);
720 if (flowret != GST_FLOW_OK)
725 /* if we have EOS, we should send on EOS ourselves */
726 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
727 GST_DEBUG_OBJECT (this, "Sending on EOS event %p", event);
728 /* ref, we unref later again */
729 ret = gst_pad_push_event (this->srcpad, gst_event_ref (event));
733 gst_event_unref (event);
734 gst_object_unref (this);
741 GST_ELEMENT_WARNING (this, STREAM, ENCODE, (NULL),
742 ("Could not create GDP buffer from received event (type %s)",
743 gst_event_type_get_name (event->type)));
749 GST_WARNING_OBJECT (this, "queueing GDP event buffer returned %d", flowret);
756 gst_gdp_pay_src_event (GstPad * pad, GstEvent * event)
761 this = GST_GDP_PAY (gst_pad_get_parent (pad));
763 switch (GST_EVENT_TYPE (event)) {
765 /* we refuse seek for now. */
766 gst_event_unref (event);
770 case GST_EVENT_NAVIGATION:
772 /* everything else is passed */
773 res = gst_pad_push_event (this->sinkpad, event);
776 gst_object_unref (this);
782 gst_gdp_pay_set_property (GObject * object, guint prop_id,
783 const GValue * value, GParamSpec * pspec)
787 g_return_if_fail (GST_IS_GDP_PAY (object));
788 this = GST_GDP_PAY (object);
791 case PROP_CRC_HEADER:
793 g_value_get_boolean (value) ? GST_DP_HEADER_FLAG_CRC_HEADER : 0;
794 this->header_flag = this->crc_header | this->crc_payload;
796 case PROP_CRC_PAYLOAD:
798 g_value_get_boolean (value) ? GST_DP_HEADER_FLAG_CRC_PAYLOAD : 0;
799 this->header_flag = this->crc_header | this->crc_payload;
802 this->version = g_value_get_enum (value);
805 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
811 gst_gdp_pay_get_property (GObject * object, guint prop_id,
812 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:
821 g_value_set_boolean (value, this->crc_header);
823 case PROP_CRC_PAYLOAD:
824 g_value_set_boolean (value, this->crc_payload);
827 g_value_set_enum (value, this->version);
830 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
835 static GstStateChangeReturn
836 gst_gdp_pay_change_state (GstElement * element, GstStateChange transition)
838 GstStateChangeReturn ret;
839 GstGDPPay *this = GST_GDP_PAY (element);
841 switch (transition) {
842 case GST_STATE_CHANGE_READY_TO_PAUSED:
848 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
850 switch (transition) {
851 case GST_STATE_CHANGE_PAUSED_TO_READY:
852 gst_gdp_pay_reset (this);
862 gst_gdp_pay_plugin_init (GstPlugin * plugin)
864 if (!gst_element_register (plugin, "gdppay", GST_RANK_NONE, GST_TYPE_GDP_PAY))