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., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, 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(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_SRC))
37 #define GST_BASE_SRC_CAST(obj) ((GstBaseSrc *)(obj))
41 * @GST_BASE_SRC_FLAG_STARTING: has source is starting
42 * @GST_BASE_SRC_FLAG_STARTED: has source been started
43 * @GST_BASE_SRC_FLAG_LAST: offset to define more flags
45 * The #GstElement flags that a basesrc element may have.
48 GST_BASE_SRC_FLAG_STARTING = (GST_ELEMENT_FLAG_LAST << 0),
49 GST_BASE_SRC_FLAG_STARTED = (GST_ELEMENT_FLAG_LAST << 1),
51 GST_BASE_SRC_FLAG_LAST = (GST_ELEMENT_FLAG_LAST << 6)
54 #define GST_BASE_SRC_IS_STARTING(obj) GST_OBJECT_FLAG_IS_SET ((obj), GST_BASE_SRC_FLAG_STARTING)
55 #define GST_BASE_SRC_IS_STARTED(obj) GST_OBJECT_FLAG_IS_SET ((obj), GST_BASE_SRC_FLAG_STARTED)
57 typedef struct _GstBaseSrc GstBaseSrc;
58 typedef struct _GstBaseSrcClass GstBaseSrcClass;
59 typedef struct _GstBaseSrcPrivate GstBaseSrcPrivate;
63 * @obj: base source instance
65 * Gives the pointer to the #GstPad object of the element.
67 #define GST_BASE_SRC_PAD(obj) (GST_BASE_SRC_CAST (obj)->srcpad)
73 * The opaque #GstBaseSrc data structure.
81 /* available to subclass implementations */
82 /* MT-protected (with LIVE_LOCK) */
86 gboolean live_running;
88 /* MT-protected (with LOCK) */
89 guint blocksize; /* size of buffers when operating push based */
90 gboolean can_activate_push; /* some scheduling properties */
91 gboolean random_access;
93 GstClockID clock_id; /* for syncing */
95 /* MT-protected (with STREAM_LOCK *and* OBJECT_LOCK) */
97 /* MT-protected (with STREAM_LOCK) */
98 gboolean need_newsegment;
101 gint num_buffers_left;
105 GstEvent *pending_seek;
107 GstBaseSrcPrivate *priv;
110 gpointer _gst_reserved[GST_PADDING_LARGE];
115 * @parent_class: Element parent class
116 * @get_caps: Called to get the caps to report
117 * @negotiate: Negotiated the caps with the peer.
118 * @fixate: Called during negotiation if caps need fixating. Implement instead of
119 * setting a fixate function on the source pad.
120 * @set_caps: Notify subclass of changed output caps
121 * @decide_allocation: configure the allocation query
122 * @start: Start processing. Subclasses should open resources and prepare
123 * to produce data. Implementation should call gst_base_src_start_complete()
124 * when the operation completes, either from the current thread or any other
125 * thread that finishes the start operation asynchronously.
126 * @stop: Stop processing. Subclasses should use this to close resources.
127 * @get_times: Given a buffer, return the start and stop time when it
128 * should be pushed out. The base class will sync on the clock using
130 * @get_size: Return the total size of the resource, in the configured format.
131 * @is_seekable: Check if the source can seek
132 * @prepare_seek_segment: Prepare the #GstSegment that will be passed to the
133 * #GstBaseSrcClass.do_seek() vmethod for executing a seek
134 * request. Sub-classes should override this if they support seeking in
135 * formats other than the configured native format. By default, it tries to
136 * convert the seek arguments to the configured native format and prepare a
137 * segment in that format.
138 * @do_seek: Perform seeking on the resource to the indicated segment.
139 * @unlock: Unlock any pending access to the resource. Subclasses should unblock
140 * any blocked function ASAP. In particular, any create() function in
141 * progress should be unblocked and should return GST_FLOW_FLUSHING. Any
142 * future #GstBaseSrcClass.create() function call should also return
143 * GST_FLOW_FLUSHING until the #GstBaseSrcClass.unlock_stop() function has
145 * @unlock_stop: Clear the previous unlock request. Subclasses should clear any
146 * state they set during #GstBaseSrcClass.unlock(), such as clearing command
148 * @query: Handle a requested query.
149 * @event: Override this to implement custom event handling.
150 * @create: Ask the subclass to create a buffer with offset and size. When the
151 * subclass returns GST_FLOW_OK, it MUST return a buffer of the requested size
152 * unless fewer bytes are available because an EOS condition is near. No
153 * buffer should be returned when the return value is different from
154 * GST_FLOW_OK. A return value of GST_FLOW_EOS signifies that the end of
155 * stream is reached. The default implementation will call
156 * #GstBaseSrcClass.alloc() and then call #GstBaseSrcClass.fill().
157 * @alloc: Ask the subclass to allocate a buffer with for offset and size. The
158 * default implementation will create a new buffer from the negotiated allocator.
159 * @fill: Ask the subclass to fill the buffer with data for offset and size. The
160 * passed buffer is guaranteed to hold the requested amount of bytes.
162 * Subclasses can override any of the available virtual methods or not, as
163 * needed. At the minimum, the @create method should be overridden to produce
166 struct _GstBaseSrcClass {
167 GstElementClass parent_class;
170 /* virtual methods for subclasses */
172 /* get caps from subclass */
173 GstCaps* (*get_caps) (GstBaseSrc *src, GstCaps *filter);
175 gboolean (*negotiate) (GstBaseSrc *src);
176 /* called if, in negotiation, caps need fixating */
177 GstCaps * (*fixate) (GstBaseSrc *src, GstCaps *caps);
178 /* notify the subclass of new caps */
179 gboolean (*set_caps) (GstBaseSrc *src, GstCaps *caps);
181 /* setup allocation query */
182 gboolean (*decide_allocation) (GstBaseSrc *src, GstQuery *query);
184 /* start and stop processing, ideal for opening/closing the resource */
185 gboolean (*start) (GstBaseSrc *src);
186 gboolean (*stop) (GstBaseSrc *src);
188 /* given a buffer, return start and stop time when it should be pushed
189 * out. The base class will sync on the clock using these times. */
190 void (*get_times) (GstBaseSrc *src, GstBuffer *buffer,
191 GstClockTime *start, GstClockTime *end);
193 /* get the total size of the resource in bytes */
194 gboolean (*get_size) (GstBaseSrc *src, guint64 *size);
196 /* check if the resource is seekable */
197 gboolean (*is_seekable) (GstBaseSrc *src);
199 /* Prepare the segment on which to perform do_seek(), converting to the
200 * current basesrc format. */
201 gboolean (*prepare_seek_segment) (GstBaseSrc *src, GstEvent *seek,
202 GstSegment *segment);
203 /* notify subclasses of a seek */
204 gboolean (*do_seek) (GstBaseSrc *src, GstSegment *segment);
206 /* unlock any pending access to the resource. subclasses should unlock
207 * any function ASAP. */
208 gboolean (*unlock) (GstBaseSrc *src);
209 /* Clear any pending unlock request, as we succeeded in unlocking */
210 gboolean (*unlock_stop) (GstBaseSrc *src);
212 /* notify subclasses of a query */
213 gboolean (*query) (GstBaseSrc *src, GstQuery *query);
215 /* notify subclasses of an event */
216 gboolean (*event) (GstBaseSrc *src, GstEvent *event);
218 /* ask the subclass to create a buffer with offset and size, the default
219 * implementation will call alloc and fill. */
220 GstFlowReturn (*create) (GstBaseSrc *src, guint64 offset, guint size,
222 /* ask the subclass to allocate an output buffer. The default implementation
223 * will use the negotiated allocator. */
224 GstFlowReturn (*alloc) (GstBaseSrc *src, guint64 offset, guint size,
226 /* ask the subclass to fill the buffer with data from offset and size */
227 GstFlowReturn (*fill) (GstBaseSrc *src, guint64 offset, guint size,
231 gpointer _gst_reserved[GST_PADDING_LARGE];
234 GType gst_base_src_get_type (void);
236 GstFlowReturn gst_base_src_wait_playing (GstBaseSrc *src);
238 void gst_base_src_set_live (GstBaseSrc *src, gboolean live);
239 gboolean gst_base_src_is_live (GstBaseSrc *src);
241 void gst_base_src_set_format (GstBaseSrc *src, GstFormat format);
243 void gst_base_src_set_dynamic_size (GstBaseSrc * src, gboolean dynamic);
245 void gst_base_src_set_automatic_eos (GstBaseSrc * src, gboolean automatic_eos);
247 void gst_base_src_set_async (GstBaseSrc *src, gboolean async);
248 gboolean gst_base_src_is_async (GstBaseSrc *src);
250 void gst_base_src_start_complete (GstBaseSrc * basesrc, GstFlowReturn ret);
251 GstFlowReturn gst_base_src_start_wait (GstBaseSrc * basesrc);
253 gboolean gst_base_src_query_latency (GstBaseSrc *src, gboolean * live,
254 GstClockTime * min_latency,
255 GstClockTime * max_latency);
257 void gst_base_src_set_blocksize (GstBaseSrc *src, guint blocksize);
258 guint gst_base_src_get_blocksize (GstBaseSrc *src);
260 void gst_base_src_set_do_timestamp (GstBaseSrc *src, gboolean timestamp);
261 gboolean gst_base_src_get_do_timestamp (GstBaseSrc *src);
263 gboolean gst_base_src_new_seamless_segment (GstBaseSrc *src, gint64 start, gint64 stop, gint64 time);
265 gboolean gst_base_src_set_caps (GstBaseSrc *src, GstCaps *caps);
267 GstBufferPool * gst_base_src_get_buffer_pool (GstBaseSrc *src);
268 void gst_base_src_get_allocator (GstBaseSrc *src,
269 GstAllocator **allocator,
270 GstAllocationParams *params);
275 #endif /* __GST_BASE_SRC_H__ */