2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2005 Wim Taymans <wim@fluendo.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 #ifndef __GST_BASE_SRC_H__
25 #define __GST_BASE_SRC_H__
31 #define GST_TYPE_BASE_SRC (gst_base_src_get_type())
32 #define GST_BASE_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_SRC,GstBaseSrc))
33 #define GST_BASE_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_SRC,GstBaseSrcClass))
34 #define GST_BASE_SRC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BASE_SRC, GstBaseSrcClass))
35 #define GST_IS_BASE_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_SRC))
36 #define GST_IS_BASE_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_SRC))
39 GST_BASE_SRC_STARTED = GST_ELEMENT_FLAG_LAST,
41 GST_BASE_SRC_FLAG_LAST = GST_ELEMENT_FLAG_LAST + 2
44 typedef struct _GstBaseSrc GstBaseSrc;
45 typedef struct _GstBaseSrcClass GstBaseSrcClass;
47 #define GST_BASE_SRC_PAD(obj) (GST_BASE_SRC (obj)->srcpad)
49 #define GST_LIVE_GET_LOCK(elem) (GST_BASE_SRC(elem)->live_lock)
50 #define GST_LIVE_LOCK(elem) g_mutex_lock(GST_LIVE_GET_LOCK(elem))
51 #define GST_LIVE_TRYLOCK(elem) g_mutex_trylock(GST_LIVE_GET_LOCK(elem))
52 #define GST_LIVE_UNLOCK(elem) g_mutex_unlock(GST_LIVE_GET_LOCK(elem))
53 #define GST_LIVE_GET_COND(elem) (GST_BASE_SRC(elem)->live_cond)
54 #define GST_LIVE_WAIT(elem) g_cond_wait (GST_LIVE_GET_COND (elem), GST_LIVE_GET_LOCK (elem))
55 #define GST_LIVE_TIMED_WAIT(elem, timeval) g_cond_timed_wait (GST_LIVE_GET_COND (elem), GST_LIVE_GET_LOCK (elem),\
57 #define GST_LIVE_SIGNAL(elem) g_cond_signal (GST_LIVE_GET_COND (elem));
58 #define GST_LIVE_BROADCAST(elem) g_cond_broadcast (GST_LIVE_GET_COND (elem));
66 /* available to subclass implementations */
67 /* MT-protected (with LIVE_LOCK) */
71 gboolean live_running;
73 /* MT-protected (with LOCK) */
74 gint blocksize; /* size of buffers when operating push based */
75 gboolean has_loop; /* some scheduling properties */
76 gboolean has_getrange;
78 gboolean random_access;
80 GstClockID clock_id; /* for syncing */
81 GstClockTime end_time;
83 /* MT-protected (with STREAM_LOCK) */
84 gint64 segment_start; /* start and end positions for seeking */
86 gboolean segment_loop;
87 gboolean need_discont;
89 guint64 offset; /* current offset in the resource */
90 guint64 size; /* total size of the resource */
93 gint num_buffers_left;
96 gpointer _gst_reserved[GST_PADDING];
101 * @create: ask the subclass to create a buffer with offset and size
102 * @start: start processing
104 struct _GstBaseSrcClass {
105 GstElementClass parent_class;
108 /* virtual methods for subclasses */
110 /* get caps from subclass */
111 GstCaps* (*get_caps) (GstBaseSrc *src);
112 /* notify the subclass of new caps */
113 gboolean (*set_caps) (GstBaseSrc *src, GstCaps *caps);
116 gboolean (*negotiate) (GstBaseSrc *src);
118 /* start and stop processing, ideal for opening/closing the resource */
119 gboolean (*start) (GstBaseSrc *src);
120 gboolean (*stop) (GstBaseSrc *src);
122 /* given a buffer, return start and stop time when it should be pushed
123 * out. The base class will sync on the clock using these times. */
124 void (*get_times) (GstBaseSrc *src, GstBuffer *buffer,
125 GstClockTime *start, GstClockTime *end);
127 /* get the total size of the resource in bytes */
128 gboolean (*get_size) (GstBaseSrc *src, guint64 *size);
130 /* check if the resource is seekable */
131 gboolean (*is_seekable) (GstBaseSrc *src);
132 /* unlock any pending access to the resource. subclasses should unlock
133 * any function ASAP. */
134 gboolean (*unlock) (GstBaseSrc *src);
136 /* notify subclasses of an event */
137 gboolean (*event) (GstBaseSrc *src, GstEvent *event);
139 /* ask the subclass to create a buffer with offset and size */
140 GstFlowReturn (*create) (GstBaseSrc *src, guint64 offset, guint size,
144 gpointer _gst_reserved[GST_PADDING];
147 GType gst_base_src_get_type(void);
149 void gst_base_src_set_live (GstBaseSrc *src, gboolean live);
150 gboolean gst_base_src_is_live (GstBaseSrc *src);
154 #endif /* __GST_BASE_SRC_H__ */