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.
32 * <listitem><para>one sinkpad</para></listitem>
33 * <listitem><para>handles state changes</para></listitem>
34 * <listitem><para>does flushing</para></listitem>
35 * <listitem><para>preroll with optional preview</para></listitem>
36 * <listitem><para>pull/push mode</para></listitem>
37 * <listitem><para>EOS handling</para></listitem>
48 #include "gstbasesrc.h"
49 #include "gsttypefindhelper.h"
50 #include <gst/gstmarshal.h>
52 #define DEFAULT_BLOCKSIZE 4096
53 #define DEFAULT_NUM_BUFFERS -1
55 GST_DEBUG_CATEGORY_STATIC (gst_base_src_debug);
56 #define GST_CAT_DEFAULT gst_base_src_debug
58 /* BaseSrc signals and args */
74 static GstElementClass *parent_class = NULL;
76 static void gst_base_src_base_init (gpointer g_class);
77 static void gst_base_src_class_init (GstBaseSrcClass * klass);
78 static void gst_base_src_init (GstBaseSrc * src, gpointer g_class);
79 static void gst_base_src_finalize (GObject * object);
83 gst_base_src_get_type (void)
85 static GType base_src_type = 0;
88 static const GTypeInfo base_src_info = {
89 sizeof (GstBaseSrcClass),
90 (GBaseInitFunc) gst_base_src_base_init,
92 (GClassInitFunc) gst_base_src_class_init,
97 (GInstanceInitFunc) gst_base_src_init,
100 base_src_type = g_type_register_static (GST_TYPE_ELEMENT,
101 "GstBaseSrc", &base_src_info, G_TYPE_FLAG_ABSTRACT);
103 return base_src_type;
105 static GstCaps *gst_base_src_getcaps (GstPad * pad);
106 static gboolean gst_base_src_setcaps (GstPad * pad, GstCaps * caps);
108 static gboolean gst_base_src_activate_push (GstPad * pad, gboolean active);
109 static gboolean gst_base_src_activate_pull (GstPad * pad, gboolean active);
110 static void gst_base_src_set_property (GObject * object, guint prop_id,
111 const GValue * value, GParamSpec * pspec);
112 static void gst_base_src_get_property (GObject * object, guint prop_id,
113 GValue * value, GParamSpec * pspec);
114 static gboolean gst_base_src_event_handler (GstPad * pad, GstEvent * event);
116 static gboolean gst_base_src_query (GstPad * pad, GstQuery * query);
119 static const GstEventMask *gst_base_src_get_event_mask (GstPad * pad);
121 static gboolean gst_base_src_default_negotiate (GstBaseSrc * basesrc);
123 static gboolean gst_base_src_unlock (GstBaseSrc * basesrc);
124 static gboolean gst_base_src_get_size (GstBaseSrc * basesrc, guint64 * size);
125 static gboolean gst_base_src_start (GstBaseSrc * basesrc);
126 static gboolean gst_base_src_stop (GstBaseSrc * basesrc);
128 static GstElementStateReturn gst_base_src_change_state (GstElement * element);
130 static void gst_base_src_set_dataflow_funcs (GstBaseSrc * this);
131 static void gst_base_src_loop (GstPad * pad);
132 static gboolean gst_base_src_check_get_range (GstPad * pad);
133 static GstFlowReturn gst_base_src_get_range (GstPad * pad, guint64 offset,
134 guint length, GstBuffer ** buf);
137 gst_base_src_base_init (gpointer g_class)
139 GST_DEBUG_CATEGORY_INIT (gst_base_src_debug, "basesrc", 0, "basesrc element");
143 gst_base_src_class_init (GstBaseSrcClass * klass)
145 GObjectClass *gobject_class;
146 GstElementClass *gstelement_class;
148 gobject_class = (GObjectClass *) klass;
149 gstelement_class = (GstElementClass *) klass;
151 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
153 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_base_src_finalize);
154 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_base_src_set_property);
155 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_base_src_get_property);
157 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BLOCKSIZE,
158 g_param_spec_ulong ("blocksize", "Block size",
159 "Size in bytes to read per buffer", 1, G_MAXULONG, DEFAULT_BLOCKSIZE,
162 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HAS_LOOP,
163 g_param_spec_boolean ("has-loop", "Has loop function",
164 "True if the element should expose a loop function", TRUE,
165 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
167 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HAS_GETRANGE,
168 g_param_spec_boolean ("has-getrange", "Has getrange function",
169 "True if the element should expose a getrange function", TRUE,
170 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
172 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_NUM_BUFFERS,
173 g_param_spec_int ("num-buffers", "num-buffers",
174 "Number of buffers to output before sending EOS", -1, G_MAXINT,
175 DEFAULT_NUM_BUFFERS, G_PARAM_READWRITE));
177 gstelement_class->change_state =
178 GST_DEBUG_FUNCPTR (gst_base_src_change_state);
180 klass->negotiate = gst_base_src_default_negotiate;
184 gst_base_src_init (GstBaseSrc * basesrc, gpointer g_class)
187 GstPadTemplate *pad_template;
189 basesrc->is_live = FALSE;
190 basesrc->live_lock = g_mutex_new ();
191 basesrc->live_cond = g_cond_new ();
192 basesrc->num_buffers = DEFAULT_NUM_BUFFERS;
193 basesrc->num_buffers_left = -1;
196 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "src");
197 g_return_if_fail (pad_template != NULL);
199 pad = gst_pad_new_from_template (pad_template, "src");
201 gst_pad_set_activatepush_function (pad, gst_base_src_activate_push);
202 gst_pad_set_activatepull_function (pad, gst_base_src_activate_pull);
203 gst_pad_set_event_function (pad, gst_base_src_event_handler);
204 gst_pad_set_query_function (pad, gst_base_src_query);
205 gst_pad_set_checkgetrange_function (pad, gst_base_src_check_get_range);
206 gst_pad_set_getcaps_function (pad, gst_base_src_getcaps);
207 gst_pad_set_setcaps_function (pad, gst_base_src_setcaps);
209 /* hold ref to pad */
210 basesrc->srcpad = pad;
211 gst_element_add_pad (GST_ELEMENT (basesrc), pad);
213 basesrc->segment_start = -1;
214 basesrc->segment_end = -1;
215 basesrc->need_discont = TRUE;
216 basesrc->blocksize = DEFAULT_BLOCKSIZE;
217 basesrc->clock_id = NULL;
219 GST_FLAG_UNSET (basesrc, GST_BASE_SRC_STARTED);
223 gst_base_src_finalize (GObject * object)
227 basesrc = GST_BASE_SRC (object);
229 g_mutex_free (basesrc->live_lock);
230 g_cond_free (basesrc->live_cond);
232 G_OBJECT_CLASS (parent_class)->finalize (object);
236 gst_base_src_set_live (GstBaseSrc * src, gboolean live)
240 GST_LIVE_UNLOCK (src);
244 gst_base_src_is_live (GstBaseSrc * src)
249 result = src->is_live;
250 GST_LIVE_UNLOCK (src);
256 gst_base_src_set_dataflow_funcs (GstBaseSrc * this)
258 GST_DEBUG ("updating dataflow functions");
260 if (this->has_getrange)
261 gst_pad_set_getrange_function (this->srcpad, gst_base_src_get_range);
263 gst_pad_set_getrange_function (this->srcpad, NULL);
267 gst_base_src_setcaps (GstPad * pad, GstCaps * caps)
269 GstBaseSrcClass *bclass;
273 bsrc = GST_BASE_SRC (GST_PAD_PARENT (pad));
274 bclass = GST_BASE_SRC_GET_CLASS (bsrc);
276 if (bclass->set_caps)
277 res = bclass->set_caps (bsrc, caps);
283 gst_base_src_getcaps (GstPad * pad)
285 GstBaseSrcClass *bclass;
287 GstCaps *caps = NULL;
289 bsrc = GST_BASE_SRC (GST_PAD_PARENT (pad));
290 bclass = GST_BASE_SRC_GET_CLASS (bsrc);
291 if (bclass->get_caps)
292 caps = bclass->get_caps (bsrc);
295 GstPadTemplate *pad_template;
298 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
299 if (pad_template != NULL) {
300 caps = gst_caps_ref (gst_pad_template_get_caps (pad_template));
307 gst_base_src_query (GstPad * pad, GstQuery * query)
314 src = GST_BASE_SRC (GST_PAD_PARENT (pad));
316 switch (GST_QUERY_TYPE (query)) {
317 case GST_QUERY_POSITION:
321 gst_query_parse_position (query, &format, NULL, NULL);
323 case GST_FORMAT_DEFAULT:
324 case GST_FORMAT_BYTES:
325 b = gst_base_src_get_size (src, &ui64);
326 /* better to make get_size take an int64 */
327 i64 = b ? (gint64) ui64 : -1;
328 gst_query_set_position (query, GST_FORMAT_BYTES, src->offset, i64);
330 case GST_FORMAT_PERCENT:
331 b = gst_base_src_get_size (src, &ui64);
332 i64 = GST_FORMAT_PERCENT_MAX;
333 i64 *= b ? (src->offset / (gdouble) ui64) : 1.0;
334 gst_query_set_position (query, GST_FORMAT_PERCENT,
335 i64, GST_FORMAT_PERCENT_MAX);
342 case GST_QUERY_SEEKING:
343 gst_query_set_seeking (query, GST_FORMAT_BYTES,
344 src->seekable, src->segment_start, src->segment_end);
347 case GST_QUERY_FORMATS:
348 gst_query_set_formats (query, 3, GST_FORMAT_DEFAULT,
349 GST_FORMAT_BYTES, GST_FORMAT_PERCENT);
352 case GST_QUERY_LATENCY:
353 case GST_QUERY_JITTER:
355 case GST_QUERY_CONVERT:
357 return gst_pad_query_default (pad, query);
362 static const GstEventMask *
363 gst_base_src_get_event_mask (GstPad * pad)
365 static const GstEventMask masks[] = {
366 {GST_EVENT_SEEK, GST_SEEK_METHOD_CUR | GST_SEEK_METHOD_SET |
367 GST_SEEK_METHOD_END | GST_SEEK_FLAG_FLUSH |
368 GST_SEEK_FLAG_SEGMENT_LOOP},
369 {GST_EVENT_FLUSH, 0},
378 gst_base_src_send_discont (GstBaseSrc * src)
382 event = gst_event_new_newsegment (1.0,
384 (gint64) src->segment_start, (gint64) src->segment_end, (gint64) 0);
386 return gst_pad_push_event (src->srcpad, event);
390 gst_base_src_do_seek (GstBaseSrc * src, GstEvent * event)
395 GstSeekType cur_type, stop_type;
398 gst_event_parse_seek (event, &rate, &format, &flags,
399 &cur_type, &cur, &stop_type, &stop);
401 /* get seek format */
402 if (format == GST_FORMAT_DEFAULT)
403 format = GST_FORMAT_BYTES;
404 /* we can only seek bytes */
405 if (format != GST_FORMAT_BYTES)
408 /* get seek positions */
409 src->segment_loop = flags & GST_SEEK_FLAG_SEGMENT;
411 /* send flush start */
412 gst_pad_push_event (src->srcpad, gst_event_new_flush_start ());
414 /* unblock streaming thread */
415 gst_base_src_unlock (src);
417 /* grab streaming lock */
418 GST_STREAM_LOCK (src->srcpad);
420 /* send flush stop */
421 gst_pad_push_event (src->srcpad, gst_event_new_flush_stop ());
423 /* perform the seek */
425 case GST_SEEK_TYPE_SET:
428 src->offset = MIN (cur, src->size);
429 src->segment_start = src->offset;
430 src->segment_end = MIN (stop, src->size);
431 GST_DEBUG_OBJECT (src, "seek set pending to %" G_GINT64_FORMAT,
434 case GST_SEEK_TYPE_CUR:
436 src->offset = CLAMP (cur, 0, src->size);
437 src->segment_start = src->offset;
438 src->segment_end = stop;
439 GST_DEBUG_OBJECT (src, "seek cur pending to %" G_GINT64_FORMAT,
442 case GST_SEEK_TYPE_END:
445 cur = src->size + cur;
446 src->offset = MAX (0, cur);
447 src->segment_start = src->offset;
448 src->segment_end = stop;
449 GST_DEBUG_OBJECT (src, "seek end pending to %" G_GINT64_FORMAT,
456 /* now make sure the discont will be send */
457 src->need_discont = TRUE;
459 /* and restart the task */
460 gst_pad_start_task (src->srcpad, (GstTaskFunction) gst_base_src_loop,
462 GST_STREAM_UNLOCK (src->srcpad);
464 gst_event_unref (event);
471 GST_DEBUG_OBJECT (src, "seek error");
472 GST_STREAM_UNLOCK (src->srcpad);
473 gst_event_unref (event);
479 gst_base_src_event_handler (GstPad * pad, GstEvent * event)
482 GstBaseSrcClass *bclass;
485 src = GST_BASE_SRC (GST_PAD_PARENT (pad));
486 bclass = GST_BASE_SRC_GET_CLASS (src);
489 result = bclass->event (src, event);
491 switch (GST_EVENT_TYPE (event)) {
493 return gst_base_src_do_seek (src, event);
494 case GST_EVENT_FLUSH_START:
495 /* cancel any blocking getrange */
496 gst_base_src_unlock (src);
498 case GST_EVENT_FLUSH_STOP:
503 gst_event_unref (event);
509 gst_base_src_set_property (GObject * object, guint prop_id,
510 const GValue * value, GParamSpec * pspec)
514 src = GST_BASE_SRC (object);
518 src->blocksize = g_value_get_ulong (value);
521 src->has_loop = g_value_get_boolean (value);
522 gst_base_src_set_dataflow_funcs (src);
524 case PROP_HAS_GETRANGE:
525 src->has_getrange = g_value_get_boolean (value);
526 gst_base_src_set_dataflow_funcs (src);
528 case PROP_NUM_BUFFERS:
529 src->num_buffers = g_value_get_int (value);
532 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
538 gst_base_src_get_property (GObject * object, guint prop_id, GValue * value,
543 src = GST_BASE_SRC (object);
547 g_value_set_ulong (value, src->blocksize);
550 g_value_set_boolean (value, src->has_loop);
552 case PROP_HAS_GETRANGE:
553 g_value_set_boolean (value, src->has_getrange);
555 case PROP_NUM_BUFFERS:
556 g_value_set_int (value, src->num_buffers);
559 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
565 gst_base_src_get_range (GstPad * pad, guint64 offset, guint length,
570 GstBaseSrcClass *bclass;
572 src = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
573 bclass = GST_BASE_SRC_GET_CLASS (src);
577 while (!src->live_running) {
578 GST_DEBUG ("live source signal waiting");
579 GST_LIVE_SIGNAL (src);
580 GST_DEBUG ("live source waiting for running state");
582 GST_DEBUG ("live source unlocked");
585 GST_LIVE_UNLOCK (src);
588 if (GST_PAD_IS_FLUSHING (pad))
592 if (!GST_FLAG_IS_SET (src, GST_BASE_SRC_STARTED))
599 if (src->size != -1) {
600 if (offset > src->size)
601 goto unexpected_length;
603 if (offset + length > src->size) {
604 if (bclass->get_size)
605 bclass->get_size (src, &src->size);
607 if (offset + length > src->size) {
608 length = src->size - offset;
613 goto unexpected_length;
615 if (src->num_buffers_left == 0) {
616 goto reached_num_buffers;
618 if (src->num_buffers_left > 0)
619 src->num_buffers_left--;
622 ret = bclass->create (src, offset, length, buf);
629 GST_DEBUG_OBJECT (src, "pad is flushing");
631 return GST_FLOW_WRONG_STATE;
635 GST_DEBUG_OBJECT (src, "getrange but not started");
636 return GST_FLOW_WRONG_STATE;
640 GST_DEBUG_OBJECT (src, "no create function");
641 return GST_FLOW_ERROR;
645 GST_DEBUG_OBJECT (src, "unexpected length %u", length);
646 return GST_FLOW_UNEXPECTED;
650 GST_DEBUG_OBJECT (src, "sent all buffers");
651 return GST_FLOW_UNEXPECTED;
656 gst_base_src_check_get_range (GstPad * pad)
660 src = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
662 if (!GST_FLAG_IS_SET (src, GST_BASE_SRC_STARTED)) {
663 gst_base_src_start (src);
664 gst_base_src_stop (src);
667 return src->seekable;
671 gst_base_src_loop (GstPad * pad)
674 GstBuffer *buf = NULL;
677 src = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
679 if (src->need_discont) {
680 /* now send discont */
681 gst_base_src_send_discont (src);
682 src->need_discont = FALSE;
685 ret = gst_base_src_get_range (pad, src->offset, src->blocksize, &buf);
686 if (ret != GST_FLOW_OK)
692 src->offset += GST_BUFFER_SIZE (buf);
694 ret = gst_pad_push (pad, buf);
695 if (ret != GST_FLOW_OK)
702 GST_DEBUG_OBJECT (src, "going to EOS");
703 gst_pad_pause_task (pad);
704 gst_pad_push_event (pad, gst_event_new_eos ());
709 GST_DEBUG_OBJECT (src, "pausing task");
710 gst_pad_pause_task (pad);
711 if (GST_FLOW_IS_FATAL (ret) || ret == GST_FLOW_NOT_LINKED) {
712 /* for fatal errors we post an error message */
713 GST_ELEMENT_ERROR (src, STREAM, STOPPED,
714 ("streaming stopped, reason %s", gst_flow_get_name (ret)),
715 ("streaming stopped, reason %s", gst_flow_get_name (ret)));
716 gst_pad_push_event (pad, gst_event_new_eos ());
722 GST_ELEMENT_ERROR (src, STREAM, STOPPED,
723 ("internal: element returned NULL buffer"),
724 ("internal: element returned NULL buffer"));
725 gst_pad_pause_task (pad);
726 gst_pad_push_event (pad, gst_event_new_eos ());
732 gst_base_src_unlock (GstBaseSrc * basesrc)
734 GstBaseSrcClass *bclass;
735 gboolean result = FALSE;
737 GST_DEBUG ("unlock");
738 /* unblock whatever the subclass is doing */
739 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
741 result = bclass->unlock (basesrc);
743 GST_DEBUG ("unschedule clock");
744 /* and unblock the clock as well, if any */
746 if (basesrc->clock_id) {
747 gst_clock_id_unschedule (basesrc->clock_id);
749 GST_UNLOCK (basesrc);
751 GST_DEBUG ("unlock done");
757 gst_base_src_get_size (GstBaseSrc * basesrc, guint64 * size)
759 GstBaseSrcClass *bclass;
760 gboolean result = FALSE;
762 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
763 if (bclass->get_size)
764 result = bclass->get_size (basesrc, size);
767 basesrc->size = *size;
773 gst_base_src_is_seekable (GstBaseSrc * basesrc)
775 GstBaseSrcClass *bclass;
777 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
779 /* check if we can seek */
780 if (bclass->is_seekable)
781 basesrc->seekable = bclass->is_seekable (basesrc);
783 basesrc->seekable = FALSE;
785 return basesrc->seekable;
789 gst_base_src_default_negotiate (GstBaseSrc * basesrc)
792 GstCaps *caps = NULL;
793 GstCaps *peercaps = NULL;
794 gboolean result = FALSE;
796 thiscaps = gst_pad_get_caps (GST_BASE_SRC_PAD (basesrc));
797 GST_DEBUG ("caps of src: %" GST_PTR_FORMAT, thiscaps);
798 if (thiscaps == NULL || gst_caps_is_any (thiscaps))
801 peercaps = gst_pad_peer_get_caps (GST_BASE_SRC_PAD (basesrc));
802 GST_DEBUG ("caps of peer: %" GST_PTR_FORMAT, peercaps);
806 icaps = gst_caps_intersect (thiscaps, peercaps);
807 GST_DEBUG ("intersect: %" GST_PTR_FORMAT, icaps);
808 gst_caps_unref (thiscaps);
809 gst_caps_unref (peercaps);
811 caps = gst_caps_copy_nth (icaps, 0);
812 gst_caps_unref (icaps);
818 caps = gst_caps_make_writable (caps);
819 gst_caps_truncate (caps);
821 gst_pad_fixate_caps (GST_BASE_SRC_PAD (basesrc), caps);
822 GST_DEBUG ("fixated to: %" GST_PTR_FORMAT, caps);
824 if (gst_caps_is_any (caps)) {
825 gst_caps_unref (caps);
827 } else if (gst_caps_is_fixed (caps)) {
828 gst_pad_set_caps (GST_BASE_SRC_PAD (basesrc), caps);
829 gst_caps_unref (caps);
837 GST_DEBUG ("no negotiation needed");
839 gst_caps_unref (thiscaps);
845 gst_base_src_negotiate (GstBaseSrc * basesrc)
847 GstBaseSrcClass *bclass;
848 gboolean result = TRUE;
850 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
852 if (bclass->negotiate)
853 result = bclass->negotiate (basesrc);
859 gst_base_src_start (GstBaseSrc * basesrc)
861 GstBaseSrcClass *bclass;
864 if (GST_FLAG_IS_SET (basesrc, GST_BASE_SRC_STARTED))
867 basesrc->num_buffers_left = basesrc->num_buffers;
869 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
871 result = bclass->start (basesrc);
876 goto could_not_start;
878 GST_FLAG_SET (basesrc, GST_BASE_SRC_STARTED);
880 /* start in the beginning */
883 /* figure out the size */
884 if (bclass->get_size) {
885 result = bclass->get_size (basesrc, &basesrc->size);
893 GST_DEBUG ("size %d %lld", result, basesrc->size);
895 /* we always run to the end */
896 basesrc->segment_start = 0;
897 basesrc->segment_end = basesrc->size;
898 basesrc->need_discont = TRUE;
900 /* check if we can seek, updates ->seekable */
901 gst_base_src_is_seekable (basesrc);
905 if (basesrc->seekable) {
908 caps = gst_type_find_helper (basesrc->srcpad, basesrc->size);
909 gst_pad_set_caps (basesrc->srcpad, caps);
910 gst_caps_unref (caps);
914 if (!gst_base_src_negotiate (basesrc))
915 goto could_not_negotiate;
922 GST_DEBUG_OBJECT (basesrc, "could not start");
927 GST_DEBUG_OBJECT (basesrc, "could not negotiate, stopping");
928 GST_ELEMENT_ERROR (basesrc, STREAM, FORMAT,
929 ("Could not connect source to pipeline"),
930 ("Check your filtered caps, if any"));
931 gst_base_src_stop (basesrc);
937 gst_base_src_stop (GstBaseSrc * basesrc)
939 GstBaseSrcClass *bclass;
940 gboolean result = TRUE;
942 if (!GST_FLAG_IS_SET (basesrc, GST_BASE_SRC_STARTED))
945 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
947 result = bclass->stop (basesrc);
950 GST_FLAG_UNSET (basesrc, GST_BASE_SRC_STARTED);
956 gst_base_src_deactivate (GstBaseSrc * basesrc, GstPad * pad)
960 GST_LIVE_LOCK (basesrc);
961 basesrc->live_running = TRUE;
962 GST_LIVE_SIGNAL (basesrc);
963 GST_LIVE_UNLOCK (basesrc);
965 /* step 1, unblock clock sync (if any) */
966 gst_base_src_unlock (basesrc);
968 /* step 2, make sure streaming finishes */
969 result = gst_pad_stop_task (pad);
975 gst_base_src_activate_push (GstPad * pad, gboolean active)
979 basesrc = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
981 /* prepare subclass first */
983 if (!gst_base_src_start (basesrc))
986 return gst_pad_start_task (pad, (GstTaskFunction) gst_base_src_loop, pad);
988 return gst_base_src_deactivate (basesrc, pad);
993 GST_DEBUG_OBJECT (basesrc, "failed to start");
999 gst_base_src_activate_pull (GstPad * pad, gboolean active)
1001 GstBaseSrc *basesrc;
1003 basesrc = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
1005 /* prepare subclass first */
1007 if (!gst_base_src_start (basesrc))
1010 if (!basesrc->seekable) {
1011 gst_base_src_stop (basesrc);
1017 return gst_base_src_deactivate (basesrc, pad);
1022 GST_DEBUG_OBJECT (basesrc, "failed to start");
1027 static GstElementStateReturn
1028 gst_base_src_change_state (GstElement * element)
1030 GstBaseSrc *basesrc;
1031 GstElementStateReturn result = GST_STATE_SUCCESS;
1032 GstElementStateReturn presult;
1033 GstElementState transition;
1035 basesrc = GST_BASE_SRC (element);
1037 transition = GST_STATE_TRANSITION (element);
1039 switch (transition) {
1040 case GST_STATE_NULL_TO_READY:
1042 case GST_STATE_READY_TO_PAUSED:
1043 GST_LIVE_LOCK (element);
1044 if (basesrc->is_live) {
1045 result = GST_STATE_NO_PREROLL;
1046 basesrc->live_running = FALSE;
1048 GST_LIVE_UNLOCK (element);
1050 case GST_STATE_PAUSED_TO_PLAYING:
1051 GST_LIVE_LOCK (element);
1052 if (basesrc->is_live) {
1053 basesrc->live_running = TRUE;
1054 GST_LIVE_SIGNAL (element);
1056 GST_LIVE_UNLOCK (element);
1062 if ((presult = GST_ELEMENT_CLASS (parent_class)->change_state (element)) !=
1066 switch (transition) {
1067 case GST_STATE_PLAYING_TO_PAUSED:
1068 GST_LIVE_LOCK (element);
1069 if (basesrc->is_live) {
1070 result = GST_STATE_NO_PREROLL;
1071 basesrc->live_running = FALSE;
1073 GST_LIVE_UNLOCK (element);
1075 case GST_STATE_PAUSED_TO_READY:
1076 if (!gst_base_src_stop (basesrc))
1077 result = GST_STATE_FAILURE;
1079 case GST_STATE_READY_TO_NULL: