2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000,2005 Wim Taymans <wim@fluendo.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 * @short_description: Base class for getrange based source elements
26 * @see_also: #GstBaseTransformc, #GstBaseSink
28 * This class is mostly useful for elements that do byte based
29 * access to a random access resource, like files.
30 * If random access is not possible, the live-mode should be set
34 * <listitem><para>one sinkpad</para></listitem>
35 * <listitem><para>handles state changes</para></listitem>
36 * <listitem><para>does flushing</para></listitem>
37 * <listitem><para>preroll with optional preview</para></listitem>
38 * <listitem><para>pull/push mode</para></listitem>
39 * <listitem><para>EOS handling</para></listitem>
50 #include "gstbasesrc.h"
51 #include "gsttypefindhelper.h"
52 #include <gst/gstmarshal.h>
54 #define DEFAULT_BLOCKSIZE 4096
55 #define DEFAULT_NUM_BUFFERS -1
57 GST_DEBUG_CATEGORY_STATIC (gst_base_src_debug);
58 #define GST_CAT_DEFAULT gst_base_src_debug
60 /* BaseSrc signals and args */
76 static GstElementClass *parent_class = NULL;
78 static void gst_base_src_base_init (gpointer g_class);
79 static void gst_base_src_class_init (GstBaseSrcClass * klass);
80 static void gst_base_src_init (GstBaseSrc * src, gpointer g_class);
81 static void gst_base_src_finalize (GObject * object);
85 gst_base_src_get_type (void)
87 static GType base_src_type = 0;
90 static const GTypeInfo base_src_info = {
91 sizeof (GstBaseSrcClass),
92 (GBaseInitFunc) gst_base_src_base_init,
94 (GClassInitFunc) gst_base_src_class_init,
99 (GInstanceInitFunc) gst_base_src_init,
102 base_src_type = g_type_register_static (GST_TYPE_ELEMENT,
103 "GstBaseSrc", &base_src_info, G_TYPE_FLAG_ABSTRACT);
105 return base_src_type;
107 static GstCaps *gst_base_src_getcaps (GstPad * pad);
108 static gboolean gst_base_src_setcaps (GstPad * pad, GstCaps * caps);
110 static gboolean gst_base_src_activate_push (GstPad * pad, gboolean active);
111 static gboolean gst_base_src_activate_pull (GstPad * pad, gboolean active);
112 static void gst_base_src_set_property (GObject * object, guint prop_id,
113 const GValue * value, GParamSpec * pspec);
114 static void gst_base_src_get_property (GObject * object, guint prop_id,
115 GValue * value, GParamSpec * pspec);
116 static gboolean gst_base_src_event_handler (GstPad * pad, GstEvent * event);
118 static gboolean gst_base_src_query (GstPad * pad, GstQuery * query);
121 static const GstEventMask *gst_base_src_get_event_mask (GstPad * pad);
123 static gboolean gst_base_src_default_negotiate (GstBaseSrc * basesrc);
125 static gboolean gst_base_src_unlock (GstBaseSrc * basesrc);
126 static gboolean gst_base_src_get_size (GstBaseSrc * basesrc, guint64 * size);
127 static gboolean gst_base_src_start (GstBaseSrc * basesrc);
128 static gboolean gst_base_src_stop (GstBaseSrc * basesrc);
130 static GstElementStateReturn gst_base_src_change_state (GstElement * element);
132 static void gst_base_src_set_dataflow_funcs (GstBaseSrc * this);
133 static void gst_base_src_loop (GstPad * pad);
134 static gboolean gst_base_src_check_get_range (GstPad * pad);
135 static GstFlowReturn gst_base_src_get_range (GstPad * pad, guint64 offset,
136 guint length, GstBuffer ** buf);
139 gst_base_src_base_init (gpointer g_class)
141 GST_DEBUG_CATEGORY_INIT (gst_base_src_debug, "basesrc", 0, "basesrc element");
145 gst_base_src_class_init (GstBaseSrcClass * klass)
147 GObjectClass *gobject_class;
148 GstElementClass *gstelement_class;
150 gobject_class = (GObjectClass *) klass;
151 gstelement_class = (GstElementClass *) klass;
153 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
155 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_base_src_finalize);
156 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_base_src_set_property);
157 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_base_src_get_property);
159 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BLOCKSIZE,
160 g_param_spec_ulong ("blocksize", "Block size",
161 "Size in bytes to read per buffer", 1, G_MAXULONG, DEFAULT_BLOCKSIZE,
164 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HAS_LOOP,
165 g_param_spec_boolean ("has-loop", "Has loop function",
166 "True if the element should expose a loop function", TRUE,
167 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
169 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HAS_GETRANGE,
170 g_param_spec_boolean ("has-getrange", "Has getrange function",
171 "True if the element should expose a getrange function", TRUE,
172 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
174 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_NUM_BUFFERS,
175 g_param_spec_int ("num-buffers", "num-buffers",
176 "Number of buffers to output before sending EOS", -1, G_MAXINT,
177 DEFAULT_NUM_BUFFERS, G_PARAM_READWRITE));
179 gstelement_class->change_state =
180 GST_DEBUG_FUNCPTR (gst_base_src_change_state);
182 klass->negotiate = gst_base_src_default_negotiate;
186 gst_base_src_init (GstBaseSrc * basesrc, gpointer g_class)
189 GstPadTemplate *pad_template;
191 basesrc->is_live = FALSE;
192 basesrc->live_lock = g_mutex_new ();
193 basesrc->live_cond = g_cond_new ();
194 basesrc->num_buffers = DEFAULT_NUM_BUFFERS;
195 basesrc->num_buffers_left = -1;
198 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "src");
199 g_return_if_fail (pad_template != NULL);
201 pad = gst_pad_new_from_template (pad_template, "src");
203 gst_pad_set_activatepush_function (pad, gst_base_src_activate_push);
204 gst_pad_set_activatepull_function (pad, gst_base_src_activate_pull);
205 gst_pad_set_event_function (pad, gst_base_src_event_handler);
206 gst_pad_set_query_function (pad, gst_base_src_query);
207 gst_pad_set_checkgetrange_function (pad, gst_base_src_check_get_range);
208 gst_pad_set_getcaps_function (pad, gst_base_src_getcaps);
209 gst_pad_set_setcaps_function (pad, gst_base_src_setcaps);
211 /* hold ref to pad */
212 basesrc->srcpad = pad;
213 gst_element_add_pad (GST_ELEMENT (basesrc), pad);
215 basesrc->segment_start = -1;
216 basesrc->segment_end = -1;
217 basesrc->need_discont = TRUE;
218 basesrc->blocksize = DEFAULT_BLOCKSIZE;
219 basesrc->clock_id = NULL;
221 GST_FLAG_UNSET (basesrc, GST_BASE_SRC_STARTED);
225 gst_base_src_finalize (GObject * object)
229 basesrc = GST_BASE_SRC (object);
231 g_mutex_free (basesrc->live_lock);
232 g_cond_free (basesrc->live_cond);
234 G_OBJECT_CLASS (parent_class)->finalize (object);
238 * gst_base_src_set_live:
239 * @src: base source instance
240 * @live: new live-mode
242 * If the element listens to a live source, the @livemode should
243 * be set to %TRUE. This declares that this source can't seek.
246 gst_base_src_set_live (GstBaseSrc * src, gboolean live)
250 GST_LIVE_UNLOCK (src);
254 * gst_base_src_get_live:
255 * @src: base source instance
257 * Check if an element is in live mode.
259 * Returns: %TRUE if element is in live mode.
262 gst_base_src_is_live (GstBaseSrc * src)
267 result = src->is_live;
268 GST_LIVE_UNLOCK (src);
274 gst_base_src_set_dataflow_funcs (GstBaseSrc * this)
276 GST_DEBUG ("updating dataflow functions");
278 if (this->has_getrange)
279 gst_pad_set_getrange_function (this->srcpad, gst_base_src_get_range);
281 gst_pad_set_getrange_function (this->srcpad, NULL);
285 gst_base_src_setcaps (GstPad * pad, GstCaps * caps)
287 GstBaseSrcClass *bclass;
291 bsrc = GST_BASE_SRC (GST_PAD_PARENT (pad));
292 bclass = GST_BASE_SRC_GET_CLASS (bsrc);
294 if (bclass->set_caps)
295 res = bclass->set_caps (bsrc, caps);
301 gst_base_src_getcaps (GstPad * pad)
303 GstBaseSrcClass *bclass;
305 GstCaps *caps = NULL;
307 bsrc = GST_BASE_SRC (GST_PAD_PARENT (pad));
308 bclass = GST_BASE_SRC_GET_CLASS (bsrc);
309 if (bclass->get_caps)
310 caps = bclass->get_caps (bsrc);
313 GstPadTemplate *pad_template;
316 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
317 if (pad_template != NULL) {
318 caps = gst_caps_ref (gst_pad_template_get_caps (pad_template));
325 gst_base_src_query (GstPad * pad, GstQuery * query)
332 src = GST_BASE_SRC (GST_PAD_PARENT (pad));
334 switch (GST_QUERY_TYPE (query)) {
335 case GST_QUERY_POSITION:
339 gst_query_parse_position (query, &format, NULL, NULL);
341 case GST_FORMAT_DEFAULT:
342 case GST_FORMAT_BYTES:
343 b = gst_base_src_get_size (src, &ui64);
344 /* better to make get_size take an int64 */
345 i64 = b ? (gint64) ui64 : -1;
346 gst_query_set_position (query, GST_FORMAT_BYTES, src->offset, i64);
348 case GST_FORMAT_PERCENT:
349 b = gst_base_src_get_size (src, &ui64);
350 i64 = GST_FORMAT_PERCENT_MAX;
351 i64 *= b ? (src->offset / (gdouble) ui64) : 1.0;
352 gst_query_set_position (query, GST_FORMAT_PERCENT,
353 i64, GST_FORMAT_PERCENT_MAX);
360 case GST_QUERY_SEEKING:
361 gst_query_set_seeking (query, GST_FORMAT_BYTES,
362 src->seekable, src->segment_start, src->segment_end);
365 case GST_QUERY_FORMATS:
366 gst_query_set_formats (query, 3, GST_FORMAT_DEFAULT,
367 GST_FORMAT_BYTES, GST_FORMAT_PERCENT);
370 case GST_QUERY_LATENCY:
371 case GST_QUERY_JITTER:
373 case GST_QUERY_CONVERT:
375 return gst_pad_query_default (pad, query);
380 static const GstEventMask *
381 gst_base_src_get_event_mask (GstPad * pad)
383 static const GstEventMask masks[] = {
384 {GST_EVENT_SEEK, GST_SEEK_METHOD_CUR | GST_SEEK_METHOD_SET |
385 GST_SEEK_METHOD_END | GST_SEEK_FLAG_FLUSH |
386 GST_SEEK_FLAG_SEGMENT_LOOP},
387 {GST_EVENT_FLUSH, 0},
396 gst_base_src_send_discont (GstBaseSrc * src)
400 event = gst_event_new_newsegment (1.0,
402 (gint64) src->segment_start, (gint64) src->segment_end, (gint64) 0);
404 return gst_pad_push_event (src->srcpad, event);
408 gst_base_src_do_seek (GstBaseSrc * src, GstEvent * event)
413 GstSeekType cur_type, stop_type;
416 gst_event_parse_seek (event, &rate, &format, &flags,
417 &cur_type, &cur, &stop_type, &stop);
419 /* get seek format */
420 if (format == GST_FORMAT_DEFAULT)
421 format = GST_FORMAT_BYTES;
422 /* we can only seek bytes */
423 if (format != GST_FORMAT_BYTES)
426 /* get seek positions */
427 src->segment_loop = flags & GST_SEEK_FLAG_SEGMENT;
429 /* send flush start */
430 gst_pad_push_event (src->srcpad, gst_event_new_flush_start ());
432 /* unblock streaming thread */
433 gst_base_src_unlock (src);
435 /* grab streaming lock */
436 GST_STREAM_LOCK (src->srcpad);
438 /* send flush stop */
439 gst_pad_push_event (src->srcpad, gst_event_new_flush_stop ());
441 /* perform the seek */
443 case GST_SEEK_TYPE_SET:
446 src->offset = MIN (cur, src->size);
447 src->segment_start = src->offset;
448 src->segment_end = MIN (stop, src->size);
449 GST_DEBUG_OBJECT (src, "seek set pending to %" G_GINT64_FORMAT,
452 case GST_SEEK_TYPE_CUR:
454 src->offset = CLAMP (cur, 0, src->size);
455 src->segment_start = src->offset;
456 src->segment_end = stop;
457 GST_DEBUG_OBJECT (src, "seek cur pending to %" G_GINT64_FORMAT,
460 case GST_SEEK_TYPE_END:
463 cur = src->size + cur;
464 src->offset = MAX (0, cur);
465 src->segment_start = src->offset;
466 src->segment_end = stop;
467 GST_DEBUG_OBJECT (src, "seek end pending to %" G_GINT64_FORMAT,
474 /* now make sure the discont will be send */
475 src->need_discont = TRUE;
477 /* and restart the task */
478 gst_pad_start_task (src->srcpad, (GstTaskFunction) gst_base_src_loop,
480 GST_STREAM_UNLOCK (src->srcpad);
482 gst_event_unref (event);
489 GST_DEBUG_OBJECT (src, "seek error");
490 GST_STREAM_UNLOCK (src->srcpad);
491 gst_event_unref (event);
497 gst_base_src_event_handler (GstPad * pad, GstEvent * event)
500 GstBaseSrcClass *bclass;
503 src = GST_BASE_SRC (GST_PAD_PARENT (pad));
504 bclass = GST_BASE_SRC_GET_CLASS (src);
507 result = bclass->event (src, event);
509 switch (GST_EVENT_TYPE (event)) {
511 return gst_base_src_do_seek (src, event);
512 case GST_EVENT_FLUSH_START:
513 /* cancel any blocking getrange */
514 gst_base_src_unlock (src);
516 case GST_EVENT_FLUSH_STOP:
521 gst_event_unref (event);
527 gst_base_src_set_property (GObject * object, guint prop_id,
528 const GValue * value, GParamSpec * pspec)
532 src = GST_BASE_SRC (object);
536 src->blocksize = g_value_get_ulong (value);
539 src->has_loop = g_value_get_boolean (value);
540 gst_base_src_set_dataflow_funcs (src);
542 case PROP_HAS_GETRANGE:
543 src->has_getrange = g_value_get_boolean (value);
544 gst_base_src_set_dataflow_funcs (src);
546 case PROP_NUM_BUFFERS:
547 src->num_buffers = g_value_get_int (value);
550 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
556 gst_base_src_get_property (GObject * object, guint prop_id, GValue * value,
561 src = GST_BASE_SRC (object);
565 g_value_set_ulong (value, src->blocksize);
568 g_value_set_boolean (value, src->has_loop);
570 case PROP_HAS_GETRANGE:
571 g_value_set_boolean (value, src->has_getrange);
573 case PROP_NUM_BUFFERS:
574 g_value_set_int (value, src->num_buffers);
577 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
583 gst_base_src_get_range (GstPad * pad, guint64 offset, guint length,
588 GstBaseSrcClass *bclass;
590 src = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
591 bclass = GST_BASE_SRC_GET_CLASS (src);
595 while (!src->live_running) {
596 GST_DEBUG ("live source signal waiting");
597 GST_LIVE_SIGNAL (src);
598 GST_DEBUG ("live source waiting for running state");
600 GST_DEBUG ("live source unlocked");
603 GST_LIVE_UNLOCK (src);
606 if (GST_PAD_IS_FLUSHING (pad))
610 if (!GST_FLAG_IS_SET (src, GST_BASE_SRC_STARTED))
617 if (src->size != -1) {
618 if (offset > src->size)
619 goto unexpected_length;
621 if (offset + length > src->size) {
622 if (bclass->get_size)
623 bclass->get_size (src, &src->size);
625 if (offset + length > src->size) {
626 length = src->size - offset;
631 goto unexpected_length;
633 if (src->num_buffers_left == 0) {
634 goto reached_num_buffers;
636 if (src->num_buffers_left > 0)
637 src->num_buffers_left--;
640 ret = bclass->create (src, offset, length, buf);
647 GST_DEBUG_OBJECT (src, "pad is flushing");
649 return GST_FLOW_WRONG_STATE;
653 GST_DEBUG_OBJECT (src, "getrange but not started");
654 return GST_FLOW_WRONG_STATE;
658 GST_DEBUG_OBJECT (src, "no create function");
659 return GST_FLOW_ERROR;
663 GST_DEBUG_OBJECT (src, "unexpected length %u", length);
664 return GST_FLOW_UNEXPECTED;
668 GST_DEBUG_OBJECT (src, "sent all buffers");
669 return GST_FLOW_UNEXPECTED;
674 gst_base_src_check_get_range (GstPad * pad)
678 src = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
680 if (!GST_FLAG_IS_SET (src, GST_BASE_SRC_STARTED)) {
681 gst_base_src_start (src);
682 gst_base_src_stop (src);
685 return src->seekable;
689 gst_base_src_loop (GstPad * pad)
692 GstBuffer *buf = NULL;
695 src = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
697 if (src->need_discont) {
698 /* now send discont */
699 gst_base_src_send_discont (src);
700 src->need_discont = FALSE;
703 ret = gst_base_src_get_range (pad, src->offset, src->blocksize, &buf);
704 if (ret != GST_FLOW_OK)
710 src->offset += GST_BUFFER_SIZE (buf);
712 ret = gst_pad_push (pad, buf);
713 if (ret != GST_FLOW_OK)
720 GST_DEBUG_OBJECT (src, "going to EOS");
721 gst_pad_pause_task (pad);
722 gst_pad_push_event (pad, gst_event_new_eos ());
727 GST_DEBUG_OBJECT (src, "pausing task");
728 gst_pad_pause_task (pad);
729 if (GST_FLOW_IS_FATAL (ret) || ret == GST_FLOW_NOT_LINKED) {
730 /* for fatal errors we post an error message */
731 GST_ELEMENT_ERROR (src, STREAM, STOPPED,
732 ("streaming stopped, reason %s", gst_flow_get_name (ret)),
733 ("streaming stopped, reason %s", gst_flow_get_name (ret)));
734 gst_pad_push_event (pad, gst_event_new_eos ());
740 GST_ELEMENT_ERROR (src, STREAM, STOPPED,
741 ("internal: element returned NULL buffer"),
742 ("internal: element returned NULL buffer"));
743 gst_pad_pause_task (pad);
744 gst_pad_push_event (pad, gst_event_new_eos ());
750 gst_base_src_unlock (GstBaseSrc * basesrc)
752 GstBaseSrcClass *bclass;
753 gboolean result = FALSE;
755 GST_DEBUG ("unlock");
756 /* unblock whatever the subclass is doing */
757 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
759 result = bclass->unlock (basesrc);
761 GST_DEBUG ("unschedule clock");
762 /* and unblock the clock as well, if any */
764 if (basesrc->clock_id) {
765 gst_clock_id_unschedule (basesrc->clock_id);
767 GST_UNLOCK (basesrc);
769 GST_DEBUG ("unlock done");
775 gst_base_src_get_size (GstBaseSrc * basesrc, guint64 * size)
777 GstBaseSrcClass *bclass;
778 gboolean result = FALSE;
780 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
781 if (bclass->get_size)
782 result = bclass->get_size (basesrc, size);
785 basesrc->size = *size;
791 gst_base_src_is_seekable (GstBaseSrc * basesrc)
793 GstBaseSrcClass *bclass;
795 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
797 /* check if we can seek */
798 if (bclass->is_seekable)
799 basesrc->seekable = bclass->is_seekable (basesrc);
801 basesrc->seekable = FALSE;
803 return basesrc->seekable;
807 gst_base_src_default_negotiate (GstBaseSrc * basesrc)
810 GstCaps *caps = NULL;
811 GstCaps *peercaps = NULL;
812 gboolean result = FALSE;
814 thiscaps = gst_pad_get_caps (GST_BASE_SRC_PAD (basesrc));
815 GST_DEBUG ("caps of src: %" GST_PTR_FORMAT, thiscaps);
816 if (thiscaps == NULL || gst_caps_is_any (thiscaps))
819 peercaps = gst_pad_peer_get_caps (GST_BASE_SRC_PAD (basesrc));
820 GST_DEBUG ("caps of peer: %" GST_PTR_FORMAT, peercaps);
824 icaps = gst_caps_intersect (thiscaps, peercaps);
825 GST_DEBUG ("intersect: %" GST_PTR_FORMAT, icaps);
826 gst_caps_unref (thiscaps);
827 gst_caps_unref (peercaps);
829 caps = gst_caps_copy_nth (icaps, 0);
830 gst_caps_unref (icaps);
836 caps = gst_caps_make_writable (caps);
837 gst_caps_truncate (caps);
839 gst_pad_fixate_caps (GST_BASE_SRC_PAD (basesrc), caps);
840 GST_DEBUG ("fixated to: %" GST_PTR_FORMAT, caps);
842 if (gst_caps_is_any (caps)) {
843 gst_caps_unref (caps);
845 } else if (gst_caps_is_fixed (caps)) {
846 gst_pad_set_caps (GST_BASE_SRC_PAD (basesrc), caps);
847 gst_caps_unref (caps);
855 GST_DEBUG ("no negotiation needed");
857 gst_caps_unref (thiscaps);
863 gst_base_src_negotiate (GstBaseSrc * basesrc)
865 GstBaseSrcClass *bclass;
866 gboolean result = TRUE;
868 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
870 if (bclass->negotiate)
871 result = bclass->negotiate (basesrc);
877 gst_base_src_start (GstBaseSrc * basesrc)
879 GstBaseSrcClass *bclass;
882 if (GST_FLAG_IS_SET (basesrc, GST_BASE_SRC_STARTED))
885 basesrc->num_buffers_left = basesrc->num_buffers;
887 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
889 result = bclass->start (basesrc);
894 goto could_not_start;
896 GST_FLAG_SET (basesrc, GST_BASE_SRC_STARTED);
898 /* start in the beginning */
901 /* figure out the size */
902 if (bclass->get_size) {
903 result = bclass->get_size (basesrc, &basesrc->size);
911 GST_DEBUG ("size %d %lld", result, basesrc->size);
913 /* we always run to the end */
914 basesrc->segment_start = 0;
915 basesrc->segment_end = basesrc->size;
916 basesrc->need_discont = TRUE;
918 /* check if we can seek, updates ->seekable */
919 gst_base_src_is_seekable (basesrc);
923 if (basesrc->seekable) {
926 caps = gst_type_find_helper (basesrc->srcpad, basesrc->size);
927 gst_pad_set_caps (basesrc->srcpad, caps);
928 gst_caps_unref (caps);
932 if (!gst_base_src_negotiate (basesrc))
933 goto could_not_negotiate;
940 GST_DEBUG_OBJECT (basesrc, "could not start");
945 GST_DEBUG_OBJECT (basesrc, "could not negotiate, stopping");
946 GST_ELEMENT_ERROR (basesrc, STREAM, FORMAT,
947 ("Could not connect source to pipeline"),
948 ("Check your filtered caps, if any"));
949 gst_base_src_stop (basesrc);
955 gst_base_src_stop (GstBaseSrc * basesrc)
957 GstBaseSrcClass *bclass;
958 gboolean result = TRUE;
960 if (!GST_FLAG_IS_SET (basesrc, GST_BASE_SRC_STARTED))
963 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
965 result = bclass->stop (basesrc);
968 GST_FLAG_UNSET (basesrc, GST_BASE_SRC_STARTED);
974 gst_base_src_deactivate (GstBaseSrc * basesrc, GstPad * pad)
978 GST_LIVE_LOCK (basesrc);
979 basesrc->live_running = TRUE;
980 GST_LIVE_SIGNAL (basesrc);
981 GST_LIVE_UNLOCK (basesrc);
983 /* step 1, unblock clock sync (if any) */
984 gst_base_src_unlock (basesrc);
986 /* step 2, make sure streaming finishes */
987 result = gst_pad_stop_task (pad);
993 gst_base_src_activate_push (GstPad * pad, gboolean active)
997 basesrc = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
999 /* prepare subclass first */
1001 if (!gst_base_src_start (basesrc))
1004 return gst_pad_start_task (pad, (GstTaskFunction) gst_base_src_loop, pad);
1006 return gst_base_src_deactivate (basesrc, pad);
1011 GST_DEBUG_OBJECT (basesrc, "failed to start");
1017 gst_base_src_activate_pull (GstPad * pad, gboolean active)
1019 GstBaseSrc *basesrc;
1021 basesrc = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
1023 /* prepare subclass first */
1025 if (!gst_base_src_start (basesrc))
1028 if (!basesrc->seekable) {
1029 gst_base_src_stop (basesrc);
1035 return gst_base_src_deactivate (basesrc, pad);
1040 GST_DEBUG_OBJECT (basesrc, "failed to start");
1045 static GstElementStateReturn
1046 gst_base_src_change_state (GstElement * element)
1048 GstBaseSrc *basesrc;
1049 GstElementStateReturn result = GST_STATE_SUCCESS;
1050 GstElementStateReturn presult;
1051 GstElementState transition;
1053 basesrc = GST_BASE_SRC (element);
1055 transition = GST_STATE_TRANSITION (element);
1057 switch (transition) {
1058 case GST_STATE_NULL_TO_READY:
1060 case GST_STATE_READY_TO_PAUSED:
1061 GST_LIVE_LOCK (element);
1062 if (basesrc->is_live) {
1063 result = GST_STATE_NO_PREROLL;
1064 basesrc->live_running = FALSE;
1066 GST_LIVE_UNLOCK (element);
1068 case GST_STATE_PAUSED_TO_PLAYING:
1069 GST_LIVE_LOCK (element);
1070 if (basesrc->is_live) {
1071 basesrc->live_running = TRUE;
1072 GST_LIVE_SIGNAL (element);
1074 GST_LIVE_UNLOCK (element);
1080 if ((presult = GST_ELEMENT_CLASS (parent_class)->change_state (element)) !=
1084 switch (transition) {
1085 case GST_STATE_PLAYING_TO_PAUSED:
1086 GST_LIVE_LOCK (element);
1087 if (basesrc->is_live) {
1088 result = GST_STATE_NO_PREROLL;
1089 basesrc->live_running = FALSE;
1091 GST_LIVE_UNLOCK (element);
1093 case GST_STATE_PAUSED_TO_READY:
1094 if (!gst_base_src_stop (basesrc))
1095 result = GST_STATE_FAILURE;
1097 case GST_STATE_READY_TO_NULL: