basesrc: add fill vmethod to basesrc
[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   GstActivateMode pad_mode;
87   gboolean       seekable; /* not used anymore */
88   gboolean       random_access;
89
90   GstClockID     clock_id;      /* for syncing */
91   GstClockTime   end_time;
92
93   /* MT-protected (with STREAM_LOCK *and* OBJECT_LOCK) */
94   GstSegment     segment;
95   /* MT-protected (with STREAM_LOCK) */
96   gboolean       need_newsegment;
97
98   guint64        offset;        /* current offset in the resource, unused */
99   guint64        size;          /* total size of the resource, unused */
100
101   gint           num_buffers;
102   gint           num_buffers_left;
103
104   gboolean       typefind;
105   gboolean       running;
106   GstEvent      *pending_seek;
107
108   GstBaseSrcPrivate *priv;
109
110   /*< private >*/
111   gpointer       _gst_reserved[GST_PADDING_LARGE];
112 };
113
114 /**
115  * GstBaseSrcClass:
116  * @parent_class: Element parent class
117  * @get_caps: Called to get the caps to report
118  * @set_caps: Notify subclass of changed output caps
119  * @negotiate: Negotiated the caps with the peer.
120  * @fixate: Called during negotiation if caps need fixating. Implement instead of
121  *   setting a fixate function on the source pad.
122  * @start: Start processing. Subclasses should open resources and prepare
123  *    to produce data.
124  * @stop: Stop processing. Subclasses should use this to close resources.
125  * @get_times: Given a buffer, return the start and stop time when it
126  *    should be pushed out. The base class will sync on the clock using
127  *    these times.
128  * @get_size: Return the total size of the resource, in the configured format.
129  * @is_seekable: Check if the source can seek
130  * @prepare_seek_segment: Prepare the GstSegment that will be passed to the
131  *   do_seek vmethod for executing a seek request. Sub-classes should override
132  *   this if they support seeking in formats other than the configured native
133  *   format. By default, it tries to convert the seek arguments to the
134  *   configured native format and prepare a segment in that format.
135  *   Since: 0.10.13
136  * @do_seek: Perform seeking on the resource to the indicated segment.
137  * @unlock: Unlock any pending access to the resource. Subclasses should
138  *    unblock any blocked function ASAP. In particular, any create() function in
139  *    progress should be unblocked and should return GST_FLOW_WRONG_STATE. Any
140  *    future @create<!-- -->() function call should also return GST_FLOW_WRONG_STATE
141  *    until the @unlock_stop<!-- -->() function has been called.
142  * @unlock_stop: Clear the previous unlock request. Subclasses should clear
143  *    any state they set during unlock(), such as clearing command queues.
144  * @query: Handle a requested query.
145  * @event: Override this to implement custom event handling.
146  * @create: Ask the subclass to create a buffer with offset and size.
147  *   When the subclass returns GST_FLOW_OK, it MUST return a buffer of the
148  *   requested size unless fewer bytes are available because an EOS condition
149  *   is near. No buffer should be returned when the return value is different
150  *   from GST_FLOW_OK. A return value of GST_FLOW_UNEXPECTED signifies that the
151  *   end of stream is reached. The default implementation will create a new
152  *   buffer from the negotiated allocator and will call @fill.
153  * @fill: Ask the subclass to fill the buffer with data for offset and size. The
154  *   passed buffer is guaranteed to hold the requested amount of bytes.
155  *
156  * Subclasses can override any of the available virtual methods or not, as
157  * needed. At the minimum, the @create method should be overridden to produce
158  * buffers.
159  */
160 struct _GstBaseSrcClass {
161   GstElementClass parent_class;
162
163   /*< public >*/
164   /* virtual methods for subclasses */
165
166   /* get caps from subclass */
167   GstCaps*      (*get_caps)     (GstBaseSrc *src, GstCaps *filter);
168   /* notify the subclass of new caps */
169   gboolean      (*set_caps)     (GstBaseSrc *src, GstCaps *caps);
170
171   /* decide on caps */
172   gboolean      (*negotiate)    (GstBaseSrc *src);
173   /* called if, in negotiation, caps need fixating */
174   void          (*fixate)       (GstBaseSrc *src, GstCaps *caps);
175
176   /* start and stop processing, ideal for opening/closing the resource */
177   gboolean      (*start)        (GstBaseSrc *src);
178   gboolean      (*stop)         (GstBaseSrc *src);
179
180   /* given a buffer, return start and stop time when it should be pushed
181    * out. The base class will sync on the clock using these times. */
182   void          (*get_times)    (GstBaseSrc *src, GstBuffer *buffer,
183                                  GstClockTime *start, GstClockTime *end);
184
185   /* get the total size of the resource in bytes */
186   gboolean      (*get_size)     (GstBaseSrc *src, guint64 *size);
187
188   /* check if the resource is seekable */
189   gboolean      (*is_seekable)  (GstBaseSrc *src);
190
191   /* Prepare the segment on which to perform do_seek(), converting to the
192    * current basesrc format. */
193   gboolean      (*prepare_seek_segment) (GstBaseSrc *src, GstEvent *seek,
194                                          GstSegment *segment);
195   /* notify subclasses of a seek */
196   gboolean      (*do_seek)      (GstBaseSrc *src, GstSegment *segment);
197
198   /* unlock any pending access to the resource. subclasses should unlock
199    * any function ASAP. */
200   gboolean      (*unlock)       (GstBaseSrc *src);
201   /* Clear any pending unlock request, as we succeeded in unlocking */
202   gboolean      (*unlock_stop)  (GstBaseSrc *src);
203
204   /* notify subclasses of a query */
205   gboolean      (*query)        (GstBaseSrc *src, GstQuery *query);
206
207   /* notify subclasses of an event */
208   gboolean      (*event)        (GstBaseSrc *src, GstEvent *event);
209
210   /* ask the subclass to create a buffer with offset and size, the default
211    * implementation will use the negotiated allocator and call fill. */
212   GstFlowReturn (*create)       (GstBaseSrc *src, guint64 offset, guint size,
213                                  GstBuffer **buf);
214   /* ask the subclass to fill the buffer with data from offset and size */
215   GstFlowReturn (*fill)         (GstBaseSrc *src, guint64 offset, guint size,
216                                  GstBuffer *buf);
217
218   /*< private >*/
219   gpointer       _gst_reserved[GST_PADDING_LARGE];
220 };
221
222 GType gst_base_src_get_type (void);
223
224 GstFlowReturn   gst_base_src_wait_playing     (GstBaseSrc *src);
225
226 void            gst_base_src_set_live         (GstBaseSrc *src, gboolean live);
227 gboolean        gst_base_src_is_live          (GstBaseSrc *src);
228
229 void            gst_base_src_set_format       (GstBaseSrc *src, GstFormat format);
230
231 void            gst_base_src_set_dynamic_size (GstBaseSrc * src, gboolean dynamic);
232
233 gboolean        gst_base_src_query_latency    (GstBaseSrc *src, gboolean * live,
234                                                GstClockTime * min_latency,
235                                                GstClockTime * max_latency);
236
237 void            gst_base_src_set_blocksize    (GstBaseSrc *src, guint blocksize);
238 guint           gst_base_src_get_blocksize    (GstBaseSrc *src);
239
240 void            gst_base_src_set_do_timestamp (GstBaseSrc *src, gboolean timestamp);
241 gboolean        gst_base_src_get_do_timestamp (GstBaseSrc *src);
242
243 gboolean        gst_base_src_new_seamless_segment (GstBaseSrc *src, gint64 start, gint64 stop, gint64 position);
244 G_END_DECLS
245
246 #endif /* __GST_BASE_SRC_H__ */