caps: avoid using in-place oprations
[platform/upstream/gstreamer.git] / libs / gst / base / gstbasesrc.h
1 /* GStreamer
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>
5  *
6  * gstbasesrc.h:
7  *
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.
12  *
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.
17  *
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.
22  */
23
24 #ifndef __GST_BASE_SRC_H__
25 #define __GST_BASE_SRC_H__
26
27 #include <gst/gst.h>
28
29 G_BEGIN_DECLS
30
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))
38
39 /**
40  * GstBaseSrcFlags:
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
44  *
45  * The #GstElement flags that a basesrc element may have.
46  */
47 typedef enum {
48   GST_BASE_SRC_FLAG_STARTING     = (GST_ELEMENT_FLAG_LAST << 0),
49   GST_BASE_SRC_FLAG_STARTED      = (GST_ELEMENT_FLAG_LAST << 1),
50   /* padding */
51   GST_BASE_SRC_FLAG_LAST         = (GST_ELEMENT_FLAG_LAST << 16)
52 } GstBaseSrcFlags;
53
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)
56
57 typedef struct _GstBaseSrc GstBaseSrc;
58 typedef struct _GstBaseSrcClass GstBaseSrcClass;
59 typedef struct _GstBaseSrcPrivate GstBaseSrcPrivate;
60
61 /**
62  * GST_BASE_SRC_PAD:
63  * @obj: base source instance
64  *
65  * Gives the pointer to the #GstPad object of the element.
66  */
67 #define GST_BASE_SRC_PAD(obj)                 (GST_BASE_SRC_CAST (obj)->srcpad)
68
69
70 /**
71  * GstBaseSrc:
72  *
73  * The opaque #GstBaseSrc data structure.
74  */
75 struct _GstBaseSrc {
76   GstElement     element;
77
78   /*< protected >*/
79   GstPad        *srcpad;
80
81   /* available to subclass implementations */
82   /* MT-protected (with LIVE_LOCK) */
83   GMutex         live_lock;
84   GCond          live_cond;
85   gboolean       is_live;
86   gboolean       live_running;
87
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;
92
93   GstClockID     clock_id;      /* for syncing */
94
95   /* MT-protected (with STREAM_LOCK *and* OBJECT_LOCK) */
96   GstSegment     segment;
97   /* MT-protected (with STREAM_LOCK) */
98   gboolean       need_newsegment;
99
100   gint           num_buffers;
101   gint           num_buffers_left;
102
103   gboolean       typefind;
104   gboolean       running;
105   GstEvent      *pending_seek;
106
107   GstBaseSrcPrivate *priv;
108
109   /*< private >*/
110   gpointer       _gst_reserved[GST_PADDING_LARGE];
111 };
112
113 /**
114  * GstBaseSrcClass:
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
129  *    these times.
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  *   do_seek vmethod for executing a seek request. Sub-classes should override
134  *   this if they support seeking in formats other than the configured native
135  *   format. By default, it tries to convert the seek arguments to the
136  *   configured native format and prepare a segment in that format.
137  *   Since: 0.10.13
138  * @do_seek: Perform seeking on the resource to the indicated segment.
139  * @unlock: Unlock any pending access to the resource. Subclasses should
140  *    unblock any blocked function ASAP. In particular, any create() function in
141  *    progress should be unblocked and should return GST_FLOW_FLUSHING. Any
142  *    future @create<!-- -->() function call should also return GST_FLOW_FLUSHING
143  *    until the @unlock_stop<!-- -->() function has been called.
144  * @unlock_stop: Clear the previous unlock request. Subclasses should clear
145  *    any state they set during unlock(), such as clearing command queues.
146  * @query: Handle a requested query.
147  * @event: Override this to implement custom event handling.
148  * @create: Ask the subclass to create a buffer with offset and size.
149  *   When the subclass returns GST_FLOW_OK, it MUST return a buffer of the
150  *   requested size unless fewer bytes are available because an EOS condition
151  *   is near. No buffer should be returned when the return value is different
152  *   from GST_FLOW_OK. A return value of GST_FLOW_UNEXPECTED signifies that the
153  *   end of stream is reached. The default implementation will call @alloc and
154  *   then call @fill.
155  * @alloc: Ask the subclass to allocate a buffer with for offset and size. The
156  *   default implementation will create a new buffer from the negotiated allocator.
157  * @fill: Ask the subclass to fill the buffer with data for offset and size. The
158  *   passed buffer is guaranteed to hold the requested amount of bytes.
159  *
160  * Subclasses can override any of the available virtual methods or not, as
161  * needed. At the minimum, the @create method should be overridden to produce
162  * buffers.
163  */
164 struct _GstBaseSrcClass {
165   GstElementClass parent_class;
166
167   /*< public >*/
168   /* virtual methods for subclasses */
169
170   /* get caps from subclass */
171   GstCaps*      (*get_caps)     (GstBaseSrc *src, GstCaps *filter);
172   /* decide on caps */
173   gboolean      (*negotiate)    (GstBaseSrc *src);
174   /* called if, in negotiation, caps need fixating */
175   GstCaps *     (*fixate)       (GstBaseSrc *src, GstCaps *caps);
176   /* notify the subclass of new caps */
177   gboolean      (*set_caps)     (GstBaseSrc *src, GstCaps *caps);
178
179   /* setup allocation query */
180   gboolean      (*decide_allocation)   (GstBaseSrc *src, GstQuery *query);
181
182   /* start and stop processing, ideal for opening/closing the resource */
183   gboolean      (*start)        (GstBaseSrc *src);
184   gboolean      (*stop)         (GstBaseSrc *src);
185
186   /* given a buffer, return start and stop time when it should be pushed
187    * out. The base class will sync on the clock using these times. */
188   void          (*get_times)    (GstBaseSrc *src, GstBuffer *buffer,
189                                  GstClockTime *start, GstClockTime *end);
190
191   /* get the total size of the resource in bytes */
192   gboolean      (*get_size)     (GstBaseSrc *src, guint64 *size);
193
194   /* check if the resource is seekable */
195   gboolean      (*is_seekable)  (GstBaseSrc *src);
196
197   /* Prepare the segment on which to perform do_seek(), converting to the
198    * current basesrc format. */
199   gboolean      (*prepare_seek_segment) (GstBaseSrc *src, GstEvent *seek,
200                                          GstSegment *segment);
201   /* notify subclasses of a seek */
202   gboolean      (*do_seek)      (GstBaseSrc *src, GstSegment *segment);
203
204   /* unlock any pending access to the resource. subclasses should unlock
205    * any function ASAP. */
206   gboolean      (*unlock)       (GstBaseSrc *src);
207   /* Clear any pending unlock request, as we succeeded in unlocking */
208   gboolean      (*unlock_stop)  (GstBaseSrc *src);
209
210   /* notify subclasses of a query */
211   gboolean      (*query)        (GstBaseSrc *src, GstQuery *query);
212
213   /* notify subclasses of an event */
214   gboolean      (*event)        (GstBaseSrc *src, GstEvent *event);
215
216   /* ask the subclass to create a buffer with offset and size, the default
217    * implementation will call alloc and fill. */
218   GstFlowReturn (*create)       (GstBaseSrc *src, guint64 offset, guint size,
219                                  GstBuffer **buf);
220   /* ask the subclass to allocate an output buffer. The default implementation
221    * will use the negotiated allocator. */
222   GstFlowReturn (*alloc)        (GstBaseSrc *src, guint64 offset, guint size,
223                                  GstBuffer **buf);
224   /* ask the subclass to fill the buffer with data from offset and size */
225   GstFlowReturn (*fill)         (GstBaseSrc *src, guint64 offset, guint size,
226                                  GstBuffer *buf);
227
228   /*< private >*/
229   gpointer       _gst_reserved[GST_PADDING_LARGE];
230 };
231
232 GType gst_base_src_get_type (void);
233
234 GstFlowReturn   gst_base_src_wait_playing     (GstBaseSrc *src);
235
236 void            gst_base_src_set_live         (GstBaseSrc *src, gboolean live);
237 gboolean        gst_base_src_is_live          (GstBaseSrc *src);
238
239 void            gst_base_src_set_format       (GstBaseSrc *src, GstFormat format);
240
241 void            gst_base_src_set_dynamic_size (GstBaseSrc * src, gboolean dynamic);
242
243 void            gst_base_src_set_async        (GstBaseSrc *src, gboolean async);
244 gboolean        gst_base_src_is_async         (GstBaseSrc *src);
245
246 void            gst_base_src_start_complete   (GstBaseSrc * basesrc, GstFlowReturn ret);
247 GstFlowReturn   gst_base_src_start_wait       (GstBaseSrc * basesrc);
248
249 gboolean        gst_base_src_query_latency    (GstBaseSrc *src, gboolean * live,
250                                                GstClockTime * min_latency,
251                                                GstClockTime * max_latency);
252
253 void            gst_base_src_set_blocksize    (GstBaseSrc *src, guint blocksize);
254 guint           gst_base_src_get_blocksize    (GstBaseSrc *src);
255
256 void            gst_base_src_set_do_timestamp (GstBaseSrc *src, gboolean timestamp);
257 gboolean        gst_base_src_get_do_timestamp (GstBaseSrc *src);
258
259 gboolean        gst_base_src_new_seamless_segment (GstBaseSrc *src, gint64 start, gint64 stop, gint64 position);
260
261 gboolean        gst_base_src_set_caps         (GstBaseSrc *src, GstCaps *caps);
262
263 G_END_DECLS
264
265 #endif /* __GST_BASE_SRC_H__ */