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