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 */
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_loop (GstPad * pad);
131 static gboolean gst_base_src_check_get_range (GstPad * pad);
132 static GstFlowReturn gst_base_src_get_range (GstPad * pad, guint64 offset,
133 guint length, GstBuffer ** buf);
136 gst_base_src_base_init (gpointer g_class)
138 GST_DEBUG_CATEGORY_INIT (gst_base_src_debug, "basesrc", 0, "basesrc element");
142 gst_base_src_class_init (GstBaseSrcClass * klass)
144 GObjectClass *gobject_class;
145 GstElementClass *gstelement_class;
147 gobject_class = (GObjectClass *) klass;
148 gstelement_class = (GstElementClass *) klass;
150 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
152 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_base_src_finalize);
153 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_base_src_set_property);
154 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_base_src_get_property);
156 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BLOCKSIZE,
157 g_param_spec_ulong ("blocksize", "Block size",
158 "Size in bytes to read per buffer", 1, G_MAXULONG, DEFAULT_BLOCKSIZE,
161 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_NUM_BUFFERS,
162 g_param_spec_int ("num-buffers", "num-buffers",
163 "Number of buffers to output before sending EOS", -1, G_MAXINT,
164 DEFAULT_NUM_BUFFERS, G_PARAM_READWRITE));
166 gstelement_class->change_state =
167 GST_DEBUG_FUNCPTR (gst_base_src_change_state);
169 klass->negotiate = gst_base_src_default_negotiate;
173 gst_base_src_init (GstBaseSrc * basesrc, gpointer g_class)
176 GstPadTemplate *pad_template;
178 basesrc->is_live = FALSE;
179 basesrc->live_lock = g_mutex_new ();
180 basesrc->live_cond = g_cond_new ();
181 basesrc->num_buffers = DEFAULT_NUM_BUFFERS;
182 basesrc->num_buffers_left = -1;
184 basesrc->can_activate_push = TRUE;
185 basesrc->pad_mode = GST_ACTIVATE_NONE;
188 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "src");
189 g_return_if_fail (pad_template != NULL);
191 pad = gst_pad_new_from_template (pad_template, "src");
193 gst_pad_set_activatepush_function (pad, gst_base_src_activate_push);
194 gst_pad_set_activatepull_function (pad, gst_base_src_activate_pull);
195 gst_pad_set_event_function (pad, gst_base_src_event_handler);
196 gst_pad_set_query_function (pad, gst_base_src_query);
197 gst_pad_set_checkgetrange_function (pad, gst_base_src_check_get_range);
198 gst_pad_set_getrange_function (pad, gst_base_src_get_range);
199 gst_pad_set_getcaps_function (pad, gst_base_src_getcaps);
200 gst_pad_set_setcaps_function (pad, gst_base_src_setcaps);
202 /* hold ref to pad */
203 basesrc->srcpad = pad;
204 gst_element_add_pad (GST_ELEMENT (basesrc), pad);
206 basesrc->segment_start = -1;
207 basesrc->segment_end = -1;
208 basesrc->need_discont = TRUE;
209 basesrc->blocksize = DEFAULT_BLOCKSIZE;
210 basesrc->clock_id = NULL;
212 GST_FLAG_UNSET (basesrc, GST_BASE_SRC_STARTED);
216 gst_base_src_finalize (GObject * object)
220 basesrc = GST_BASE_SRC (object);
222 g_mutex_free (basesrc->live_lock);
223 g_cond_free (basesrc->live_cond);
225 G_OBJECT_CLASS (parent_class)->finalize (object);
229 * gst_base_src_set_live:
230 * @src: base source instance
231 * @live: new live-mode
233 * If the element listens to a live source, the @livemode should
234 * be set to %TRUE. This declares that this source can't seek.
237 gst_base_src_set_live (GstBaseSrc * src, gboolean live)
241 GST_LIVE_UNLOCK (src);
245 * gst_base_src_is_live:
246 * @src: base source instance
248 * Check if an element is in live mode.
250 * Returns: %TRUE if element is in live mode.
253 gst_base_src_is_live (GstBaseSrc * src)
258 result = src->is_live;
259 GST_LIVE_UNLOCK (src);
265 gst_base_src_setcaps (GstPad * pad, GstCaps * caps)
267 GstBaseSrcClass *bclass;
271 bsrc = GST_BASE_SRC (GST_PAD_PARENT (pad));
272 bclass = GST_BASE_SRC_GET_CLASS (bsrc);
274 if (bclass->set_caps)
275 res = bclass->set_caps (bsrc, caps);
281 gst_base_src_getcaps (GstPad * pad)
283 GstBaseSrcClass *bclass;
285 GstCaps *caps = NULL;
287 bsrc = GST_BASE_SRC (GST_PAD_PARENT (pad));
288 bclass = GST_BASE_SRC_GET_CLASS (bsrc);
289 if (bclass->get_caps)
290 caps = bclass->get_caps (bsrc);
293 GstPadTemplate *pad_template;
296 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (bclass), "src");
297 if (pad_template != NULL) {
298 caps = gst_caps_ref (gst_pad_template_get_caps (pad_template));
305 gst_base_src_query (GstPad * pad, GstQuery * query)
312 src = GST_BASE_SRC (GST_PAD_PARENT (pad));
314 switch (GST_QUERY_TYPE (query)) {
315 case GST_QUERY_POSITION:
319 gst_query_parse_position (query, &format, NULL, NULL);
321 case GST_FORMAT_DEFAULT:
322 case GST_FORMAT_BYTES:
323 b = gst_base_src_get_size (src, &ui64);
324 /* better to make get_size take an int64 */
325 i64 = b ? (gint64) ui64 : -1;
326 gst_query_set_position (query, GST_FORMAT_BYTES, src->offset, i64);
328 case GST_FORMAT_PERCENT:
329 b = gst_base_src_get_size (src, &ui64);
330 i64 = GST_FORMAT_PERCENT_MAX;
331 i64 *= b ? (src->offset / (gdouble) ui64) : 1.0;
332 gst_query_set_position (query, GST_FORMAT_PERCENT,
333 i64, GST_FORMAT_PERCENT_MAX);
340 case GST_QUERY_SEEKING:
341 gst_query_set_seeking (query, GST_FORMAT_BYTES,
342 src->seekable, src->segment_start, src->segment_end);
345 case GST_QUERY_FORMATS:
346 gst_query_set_formats (query, 3, GST_FORMAT_DEFAULT,
347 GST_FORMAT_BYTES, GST_FORMAT_PERCENT);
350 case GST_QUERY_LATENCY:
351 case GST_QUERY_JITTER:
353 case GST_QUERY_CONVERT:
355 return gst_pad_query_default (pad, query);
360 gst_base_src_send_discont (GstBaseSrc * src)
364 GST_DEBUG_OBJECT (src, "Sending newsegment from %" G_GINT64_FORMAT
365 " to %" G_GINT64_FORMAT, (gint64) src->segment_start,
366 (gint64) src->segment_end);
367 event = gst_event_new_newsegment (1.0,
369 (gint64) src->segment_start, (gint64) src->segment_end, (gint64) 0);
371 return gst_pad_push_event (src->srcpad, event);
375 gst_base_src_do_seek (GstBaseSrc * src, GstEvent * event)
380 GstSeekType cur_type, stop_type;
383 gst_event_parse_seek (event, &rate, &format, &flags,
384 &cur_type, &cur, &stop_type, &stop);
386 /* get seek format */
387 if (format == GST_FORMAT_DEFAULT)
388 format = GST_FORMAT_BYTES;
389 /* we can only seek bytes */
390 if (format != GST_FORMAT_BYTES)
393 /* get seek positions */
394 src->segment_loop = flags & GST_SEEK_FLAG_SEGMENT;
396 /* send flush start */
397 gst_pad_push_event (src->srcpad, gst_event_new_flush_start ());
399 /* unblock streaming thread */
400 gst_base_src_unlock (src);
402 /* grab streaming lock */
403 GST_STREAM_LOCK (src->srcpad);
405 /* send flush stop */
406 gst_pad_push_event (src->srcpad, gst_event_new_flush_stop ());
408 /* perform the seek */
410 case GST_SEEK_TYPE_NONE:
412 case GST_SEEK_TYPE_SET:
415 src->offset = MIN (cur, src->size);
416 src->segment_start = src->offset;
418 case GST_SEEK_TYPE_CUR:
419 src->offset = CLAMP (src->offset + cur, 0, src->size);
420 src->segment_start = src->offset;
422 case GST_SEEK_TYPE_END:
425 src->offset = MAX (0, src->size + cur);
426 src->segment_start = src->offset;
433 case GST_SEEK_TYPE_NONE:
435 case GST_SEEK_TYPE_SET:
438 src->segment_end = MIN (stop, src->size);
440 case GST_SEEK_TYPE_CUR:
441 src->segment_end = CLAMP (src->segment_end + stop, 0, src->size);
443 case GST_SEEK_TYPE_END:
446 src->segment_end = src->size + stop;
452 GST_DEBUG_OBJECT (src, "seek pending for segment from %" G_GINT64_FORMAT
453 " to %" G_GINT64_FORMAT, src->segment_start, src->segment_end);
455 /* now make sure the discont will be send */
456 src->need_discont = TRUE;
458 /* and restart the task */
459 gst_pad_start_task (src->srcpad, (GstTaskFunction) gst_base_src_loop,
461 GST_STREAM_UNLOCK (src->srcpad);
463 gst_event_unref (event);
470 GST_DEBUG_OBJECT (src, "seek error");
471 GST_STREAM_UNLOCK (src->srcpad);
472 gst_event_unref (event);
478 gst_base_src_event_handler (GstPad * pad, GstEvent * event)
481 GstBaseSrcClass *bclass;
484 src = GST_BASE_SRC (GST_PAD_PARENT (pad));
485 bclass = GST_BASE_SRC_GET_CLASS (src);
488 result = bclass->event (src, event);
490 switch (GST_EVENT_TYPE (event)) {
492 if (!src->seekable) {
493 gst_event_unref (event);
496 return gst_base_src_do_seek (src, event);
497 case GST_EVENT_FLUSH_START:
498 /* cancel any blocking getrange */
499 gst_base_src_unlock (src);
501 case GST_EVENT_FLUSH_STOP:
506 gst_event_unref (event);
512 gst_base_src_set_property (GObject * object, guint prop_id,
513 const GValue * value, GParamSpec * pspec)
517 src = GST_BASE_SRC (object);
521 src->blocksize = g_value_get_ulong (value);
523 case PROP_NUM_BUFFERS:
524 src->num_buffers = g_value_get_int (value);
527 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
533 gst_base_src_get_property (GObject * object, guint prop_id, GValue * value,
538 src = GST_BASE_SRC (object);
542 g_value_set_ulong (value, src->blocksize);
544 case PROP_NUM_BUFFERS:
545 g_value_set_int (value, src->num_buffers);
548 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
554 gst_base_src_get_range (GstPad * pad, guint64 offset, guint length,
559 GstBaseSrcClass *bclass;
561 src = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
562 bclass = GST_BASE_SRC_GET_CLASS (src);
566 while (!src->live_running) {
567 GST_DEBUG ("live source signal waiting");
568 GST_LIVE_SIGNAL (src);
569 GST_DEBUG ("live source waiting for running state");
571 GST_DEBUG ("live source unlocked");
574 GST_LIVE_UNLOCK (src);
577 if (GST_PAD_IS_FLUSHING (pad))
581 if (!GST_FLAG_IS_SET (src, GST_BASE_SRC_STARTED))
588 if (src->size != -1) {
589 if (offset > src->size)
590 goto unexpected_length;
592 if (offset + length > src->size) {
593 if (bclass->get_size)
594 bclass->get_size (src, &src->size);
596 if (offset + length > src->size) {
597 length = src->size - offset;
602 goto unexpected_length;
604 if (src->num_buffers_left == 0) {
605 goto reached_num_buffers;
607 if (src->num_buffers_left > 0)
608 src->num_buffers_left--;
611 ret = bclass->create (src, offset, length, buf);
618 GST_DEBUG_OBJECT (src, "pad is flushing");
620 return GST_FLOW_WRONG_STATE;
624 GST_DEBUG_OBJECT (src, "getrange but not started");
625 return GST_FLOW_WRONG_STATE;
629 GST_DEBUG_OBJECT (src, "no create function");
630 return GST_FLOW_ERROR;
634 GST_DEBUG_OBJECT (src, "unexpected length %u", length);
635 return GST_FLOW_UNEXPECTED;
639 GST_DEBUG_OBJECT (src, "sent all buffers");
640 return GST_FLOW_UNEXPECTED;
645 gst_base_src_check_get_range (GstPad * pad)
649 src = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
651 if (!GST_FLAG_IS_SET (src, GST_BASE_SRC_STARTED)) {
652 gst_base_src_start (src);
653 gst_base_src_stop (src);
656 return src->seekable;
660 gst_base_src_loop (GstPad * pad)
663 GstBuffer *buf = NULL;
666 src = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
668 if (src->need_discont) {
669 /* now send discont */
670 gst_base_src_send_discont (src);
671 src->need_discont = FALSE;
674 ret = gst_base_src_get_range (pad, src->offset, src->blocksize, &buf);
675 if (ret != GST_FLOW_OK)
681 src->offset += GST_BUFFER_SIZE (buf);
683 ret = gst_pad_push (pad, buf);
684 if (ret != GST_FLOW_OK)
691 GST_DEBUG_OBJECT (src, "going to EOS");
692 gst_pad_pause_task (pad);
693 gst_pad_push_event (pad, gst_event_new_eos ());
698 GST_DEBUG_OBJECT (src, "pausing task");
699 gst_pad_pause_task (pad);
700 if (GST_FLOW_IS_FATAL (ret) || ret == GST_FLOW_NOT_LINKED) {
701 /* for fatal errors we post an error message */
702 GST_ELEMENT_ERROR (src, STREAM, STOPPED,
703 ("streaming stopped, reason %s", gst_flow_get_name (ret)),
704 ("streaming stopped, reason %s", gst_flow_get_name (ret)));
705 gst_pad_push_event (pad, gst_event_new_eos ());
711 GST_ELEMENT_ERROR (src, STREAM, STOPPED,
712 ("internal: element returned NULL buffer"),
713 ("internal: element returned NULL buffer"));
714 gst_pad_pause_task (pad);
715 gst_pad_push_event (pad, gst_event_new_eos ());
721 gst_base_src_unlock (GstBaseSrc * basesrc)
723 GstBaseSrcClass *bclass;
724 gboolean result = FALSE;
726 GST_DEBUG ("unlock");
727 /* unblock whatever the subclass is doing */
728 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
730 result = bclass->unlock (basesrc);
732 GST_DEBUG ("unschedule clock");
733 /* and unblock the clock as well, if any */
735 if (basesrc->clock_id) {
736 gst_clock_id_unschedule (basesrc->clock_id);
738 GST_UNLOCK (basesrc);
740 GST_DEBUG ("unlock done");
746 gst_base_src_get_size (GstBaseSrc * basesrc, guint64 * size)
748 GstBaseSrcClass *bclass;
749 gboolean result = FALSE;
751 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
752 if (bclass->get_size)
753 result = bclass->get_size (basesrc, size);
756 basesrc->size = *size;
762 gst_base_src_is_seekable (GstBaseSrc * basesrc)
764 GstBaseSrcClass *bclass;
766 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
768 /* check if we can seek */
769 if (bclass->is_seekable)
770 basesrc->seekable = bclass->is_seekable (basesrc);
772 basesrc->seekable = FALSE;
774 return basesrc->seekable;
778 gst_base_src_default_negotiate (GstBaseSrc * basesrc)
781 GstCaps *caps = NULL;
782 GstCaps *peercaps = NULL;
783 gboolean result = FALSE;
785 thiscaps = gst_pad_get_caps (GST_BASE_SRC_PAD (basesrc));
786 GST_DEBUG ("caps of src: %" GST_PTR_FORMAT, thiscaps);
787 if (thiscaps == NULL || gst_caps_is_any (thiscaps))
790 peercaps = gst_pad_peer_get_caps (GST_BASE_SRC_PAD (basesrc));
791 GST_DEBUG ("caps of peer: %" GST_PTR_FORMAT, peercaps);
795 icaps = gst_caps_intersect (thiscaps, peercaps);
796 GST_DEBUG ("intersect: %" GST_PTR_FORMAT, icaps);
797 gst_caps_unref (thiscaps);
798 gst_caps_unref (peercaps);
800 caps = gst_caps_copy_nth (icaps, 0);
801 gst_caps_unref (icaps);
807 caps = gst_caps_make_writable (caps);
808 gst_caps_truncate (caps);
810 gst_pad_fixate_caps (GST_BASE_SRC_PAD (basesrc), caps);
811 GST_DEBUG ("fixated to: %" GST_PTR_FORMAT, caps);
813 if (gst_caps_is_any (caps)) {
814 gst_caps_unref (caps);
816 } else if (gst_caps_is_fixed (caps)) {
817 gst_pad_set_caps (GST_BASE_SRC_PAD (basesrc), caps);
818 gst_caps_unref (caps);
826 GST_DEBUG ("no negotiation needed");
828 gst_caps_unref (thiscaps);
834 gst_base_src_negotiate (GstBaseSrc * basesrc)
836 GstBaseSrcClass *bclass;
837 gboolean result = TRUE;
839 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
841 if (bclass->negotiate)
842 result = bclass->negotiate (basesrc);
848 gst_base_src_start (GstBaseSrc * basesrc)
850 GstBaseSrcClass *bclass;
853 if (GST_FLAG_IS_SET (basesrc, GST_BASE_SRC_STARTED))
856 GST_DEBUG_OBJECT (basesrc, "starting source");
858 basesrc->num_buffers_left = basesrc->num_buffers;
860 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
862 result = bclass->start (basesrc);
867 goto could_not_start;
869 GST_FLAG_SET (basesrc, GST_BASE_SRC_STARTED);
871 /* start in the beginning */
874 /* figure out the size */
875 if (bclass->get_size) {
876 result = bclass->get_size (basesrc, &basesrc->size);
884 GST_DEBUG ("size %d %lld", result, basesrc->size);
886 /* we always run to the end */
887 basesrc->segment_start = 0;
888 basesrc->segment_end = basesrc->size;
889 basesrc->need_discont = TRUE;
891 /* check if we can seek, updates ->seekable */
892 gst_base_src_is_seekable (basesrc);
896 if (basesrc->seekable) {
899 caps = gst_type_find_helper (basesrc->srcpad, basesrc->size);
900 gst_pad_set_caps (basesrc->srcpad, caps);
901 gst_caps_unref (caps);
905 if (!gst_base_src_negotiate (basesrc))
906 goto could_not_negotiate;
913 GST_DEBUG_OBJECT (basesrc, "could not start");
918 GST_DEBUG_OBJECT (basesrc, "could not negotiate, stopping");
919 GST_ELEMENT_ERROR (basesrc, STREAM, FORMAT,
920 ("Could not connect source to pipeline"),
921 ("Check your filtered caps, if any"));
922 gst_base_src_stop (basesrc);
928 gst_base_src_stop (GstBaseSrc * basesrc)
930 GstBaseSrcClass *bclass;
931 gboolean result = TRUE;
933 if (!GST_FLAG_IS_SET (basesrc, GST_BASE_SRC_STARTED))
936 GST_DEBUG_OBJECT (basesrc, "stopping source");
938 bclass = GST_BASE_SRC_GET_CLASS (basesrc);
940 result = bclass->stop (basesrc);
943 GST_FLAG_UNSET (basesrc, GST_BASE_SRC_STARTED);
949 gst_base_src_deactivate (GstBaseSrc * basesrc, GstPad * pad)
953 GST_LIVE_LOCK (basesrc);
954 basesrc->live_running = TRUE;
955 GST_LIVE_SIGNAL (basesrc);
956 GST_LIVE_UNLOCK (basesrc);
958 /* step 1, unblock clock sync (if any) */
959 gst_base_src_unlock (basesrc);
961 /* step 2, make sure streaming finishes */
962 result = gst_pad_stop_task (pad);
968 gst_base_src_activate_push (GstPad * pad, gboolean active)
972 basesrc = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
974 /* prepare subclass first */
976 GST_DEBUG_OBJECT (basesrc, "Activating in push mode");
978 if (!basesrc->can_activate_push)
979 goto no_push_activation;
981 if (!gst_base_src_start (basesrc))
984 return gst_pad_start_task (pad, (GstTaskFunction) gst_base_src_loop, pad);
986 GST_DEBUG_OBJECT (basesrc, "Deactivating in push mode");
987 return gst_base_src_deactivate (basesrc, pad);
992 GST_DEBUG_OBJECT (basesrc, "Subclass disabled push-mode activation");
997 gst_base_src_stop (basesrc);
998 GST_DEBUG_OBJECT (basesrc, "Failed to start in push mode");
1004 gst_base_src_activate_pull (GstPad * pad, gboolean active)
1006 GstBaseSrc *basesrc;
1008 basesrc = GST_BASE_SRC (GST_OBJECT_PARENT (pad));
1010 /* prepare subclass first */
1012 GST_DEBUG_OBJECT (basesrc, "Activating in pull mode");
1013 if (!gst_base_src_start (basesrc))
1016 if (!basesrc->seekable) {
1017 gst_base_src_stop (basesrc);
1023 GST_DEBUG_OBJECT (basesrc, "Deactivating in pull mode");
1025 if (!gst_base_src_stop (basesrc))
1028 return gst_base_src_deactivate (basesrc, pad);
1033 gst_base_src_stop (basesrc);
1034 GST_DEBUG_OBJECT (basesrc, "Failed to start in pull mode");
1039 GST_DEBUG_OBJECT (basesrc, "Failed to stop in pull mode");
1044 static GstElementStateReturn
1045 gst_base_src_change_state (GstElement * element)
1047 GstBaseSrc *basesrc;
1048 GstElementStateReturn result = GST_STATE_SUCCESS;
1049 GstElementStateReturn presult;
1050 GstElementState transition;
1052 basesrc = GST_BASE_SRC (element);
1054 transition = GST_STATE_TRANSITION (element);
1056 switch (transition) {
1057 case GST_STATE_NULL_TO_READY:
1059 case GST_STATE_READY_TO_PAUSED:
1060 GST_LIVE_LOCK (element);
1061 if (basesrc->is_live) {
1062 result = GST_STATE_NO_PREROLL;
1063 basesrc->live_running = FALSE;
1065 GST_LIVE_UNLOCK (element);
1067 case GST_STATE_PAUSED_TO_PLAYING:
1068 GST_LIVE_LOCK (element);
1069 if (basesrc->is_live) {
1070 basesrc->live_running = TRUE;
1071 GST_LIVE_SIGNAL (element);
1073 GST_LIVE_UNLOCK (element);
1079 if ((presult = GST_ELEMENT_CLASS (parent_class)->change_state (element)) !=
1080 GST_STATE_SUCCESS) {
1081 gst_base_src_stop (basesrc);
1085 switch (transition) {
1086 case GST_STATE_PLAYING_TO_PAUSED:
1087 GST_LIVE_LOCK (element);
1088 if (basesrc->is_live) {
1089 result = GST_STATE_NO_PREROLL;
1090 basesrc->live_running = FALSE;
1092 GST_LIVE_UNLOCK (element);
1094 case GST_STATE_PAUSED_TO_READY:
1095 if (!gst_base_src_stop (basesrc))
1096 result = GST_STATE_FAILURE;
1098 case GST_STATE_READY_TO_NULL: