Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / libs / gst / base / gstbasesink.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstbasesink.h:
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #ifndef __GST_BASE_SINK_H__
24 #define __GST_BASE_SINK_H__
25
26 #include <gst/gst.h>
27
28 G_BEGIN_DECLS
29
30
31 #define GST_TYPE_BASE_SINK              (gst_base_sink_get_type())
32 #define GST_BASE_SINK(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_SINK,GstBaseSink))
33 #define GST_BASE_SINK_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_SINK,GstBaseSinkClass))
34 #define GST_BASE_SINK_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BASE_SINK, GstBaseSinkClass))
35 #define GST_IS_BASE_SINK(obj)           (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_SINK))
36 #define GST_IS_BASE_SINK_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_SINK))
37 #define GST_BASE_SINK_CAST(obj)         ((GstBaseSink *) (obj))
38
39 /**
40  * GST_BASE_SINK_PAD:
41  * @obj: base sink instance
42  *
43  * Gives the pointer to the #GstPad object of the element.
44  */
45 #define GST_BASE_SINK_PAD(obj)          (GST_BASE_SINK_CAST (obj)->sinkpad)
46
47 #define GST_BASE_SINK_GET_PREROLL_LOCK(pad)   (GST_BASE_SINK_CAST(pad)->preroll_lock)
48 #define GST_BASE_SINK_PREROLL_LOCK(pad)       (g_mutex_lock(GST_BASE_SINK_GET_PREROLL_LOCK(pad)))
49 #define GST_BASE_SINK_PREROLL_TRYLOCK(pad)    (g_mutex_trylock(GST_BASE_SINK_GET_PREROLL_LOCK(pad)))
50 #define GST_BASE_SINK_PREROLL_UNLOCK(pad)     (g_mutex_unlock(GST_BASE_SINK_GET_PREROLL_LOCK(pad)))
51
52 #define GST_BASE_SINK_GET_PREROLL_COND(pad)   (GST_BASE_SINK_CAST(pad)->preroll_cond)
53 #define GST_BASE_SINK_PREROLL_WAIT(pad)       \
54       g_cond_wait (GST_BASE_SINK_GET_PREROLL_COND (pad), GST_BASE_SINK_GET_PREROLL_LOCK (pad))
55 #define GST_BASE_SINK_PREROLL_TIMED_WAIT(pad, timeval) \
56       g_cond_timed_wait (GST_BASE_SINK_GET_PREROLL_COND (pad), GST_BASE_SINK_GET_PREROLL_LOCK (pad), timeval)
57 #define GST_BASE_SINK_PREROLL_SIGNAL(pad)     g_cond_signal (GST_BASE_SINK_GET_PREROLL_COND (pad));
58 #define GST_BASE_SINK_PREROLL_BROADCAST(pad)  g_cond_broadcast (GST_BASE_SINK_GET_PREROLL_COND (pad));
59
60 typedef struct _GstBaseSink GstBaseSink;
61 typedef struct _GstBaseSinkClass GstBaseSinkClass;
62 typedef struct _GstBaseSinkPrivate GstBaseSinkPrivate;
63
64 /**
65  * GstBaseSink:
66  *
67  * The opaque #GstBaseSink data structure.
68  */
69 struct _GstBaseSink {
70   GstElement     element;
71
72   /*< protected >*/
73   GstPad        *sinkpad;
74   GstActivateMode       pad_mode;
75
76   /*< protected >*/ /* with LOCK */
77   guint64        offset;
78   gboolean       can_activate_pull;
79   gboolean       can_activate_push;
80
81   /*< protected >*/ /* with PREROLL_LOCK */
82   GMutex        *preroll_lock;
83   GCond         *preroll_cond;
84   GQueue        *preroll_queue;
85   gint           preroll_queue_max_len; /* FIXME-0.11: the property is guint */
86   gint           preroll_queued;
87   gint           buffers_queued;
88   gint           events_queued;
89   gboolean       eos;
90   gboolean       eos_queued;
91   gboolean       need_preroll;
92   gboolean       have_preroll;
93   gboolean       playing_async;
94
95   /*< protected >*/ /* with STREAM_LOCK */
96   gboolean       have_newsegment;
97   GstSegment     segment;
98   GstSegment     clip_segment;
99
100   /*< private >*/ /* with LOCK */
101   GstClockID     clock_id;
102   GstClockTime   end_time;
103   gboolean       sync;
104   gboolean       flushing;
105   gboolean       running;
106
107   gint64         max_lateness;
108
109   /*< private >*/
110   GstBaseSinkPrivate *priv;
111
112   gpointer _gst_reserved[GST_PADDING_LARGE];
113 };
114
115 /**
116  * GstBaseSinkClass:
117  * @parent_class: Element parent class
118  * @get_caps: Called to get sink pad caps from the subclass
119  * @set_caps: Notify subclass of changed caps
120  * @get_times: Called to get the start and end times for synchronising
121  *     the passed buffer to the clock
122  * @start: Start processing. Ideal for opening resources in the subclass
123  * @stop: Stop processing. Subclasses should use this to close resources.
124  * @unlock: Unlock any pending access to the resource. Subclasses should
125  *     unblock any blocked function ASAP
126  * @unlock_stop: Clear the previous unlock request. Subclasses should clear
127  *     any state they set during unlock(), such as clearing command queues.
128  * @event: Override this to handle events arriving on the sink pad
129  * @preroll: Called to present the preroll buffer if desired
130  * @render: Called when a buffer should be presented or output, at the
131  *     correct moment if the #GstBaseSink has been set to sync to the clock.
132  * @render_list: Same as @render but used whith buffer lists instead of
133  *     buffers. Since: 0.10.24
134  * @activate_pull: Subclasses should override this when they can provide an
135  *     alternate method of spawning a thread to drive the pipeline in pull mode.
136  *     Should start or stop the pulling thread, depending on the value of the
137  *     "active" argument. Called after actually activating the sink pad in pull
138  *     mode. The default implementation starts a task on the sink pad.
139  * @fixate: Only useful in pull mode, this vmethod will be called in response to
140  *     gst_pad_fixate_caps() being called on the sink pad. Implement if you have
141  *     ideas about what should be the default values for the caps you support.
142  *
143  * Subclasses can override any of the available virtual methods or not, as
144  * needed. At the minimum, the @render method should be overridden to
145  * output/present buffers.
146  */
147 struct _GstBaseSinkClass {
148   GstElementClass parent_class;
149
150   /* get caps from subclass */
151   GstCaps*      (*get_caps)     (GstBaseSink *sink, GstCaps *filter);
152   /* notify subclass of new caps */
153   gboolean      (*set_caps)     (GstBaseSink *sink, GstCaps *caps);
154
155   /* fixate sink caps during pull-mode negotiation */
156   void          (*fixate)       (GstBaseSink *sink, GstCaps *caps);
157   /* start or stop a pulling thread */
158   gboolean      (*activate_pull)(GstBaseSink *sink, gboolean active);
159
160   /* get the start and end times for syncing on this buffer */
161   void          (*get_times)    (GstBaseSink *sink, GstBuffer *buffer,
162                                  GstClockTime *start, GstClockTime *end);
163
164   /* start and stop processing, ideal for opening/closing the resource */
165   gboolean      (*start)        (GstBaseSink *sink);
166   gboolean      (*stop)         (GstBaseSink *sink);
167
168   /* unlock any pending access to the resource. subclasses should unlock
169    * any function ASAP. */
170   gboolean      (*unlock)       (GstBaseSink *sink);
171   /* Clear a previously indicated unlock request not that unlocking is
172    * complete. Sub-classes should clear any command queue or indicator they
173    * set during unlock */
174   gboolean      (*unlock_stop)  (GstBaseSink *sink);
175
176   /* notify subclass of event, preroll buffer or real buffer */
177   gboolean      (*event)        (GstBaseSink *sink, GstEvent *event);
178
179   GstFlowReturn (*preroll)      (GstBaseSink *sink, GstBuffer *buffer);
180   GstFlowReturn (*render)       (GstBaseSink *sink, GstBuffer *buffer);
181   /* Render a BufferList */
182   GstFlowReturn (*render_list)  (GstBaseSink *sink, GstBufferList *buffer_list);
183
184   /*< private >*/
185   gpointer       _gst_reserved[GST_PADDING_LARGE];
186 };
187
188 GType gst_base_sink_get_type(void);
189
190 GstFlowReturn   gst_base_sink_do_preroll        (GstBaseSink *sink, GstMiniObject *obj);
191 GstFlowReturn   gst_base_sink_wait_preroll      (GstBaseSink *sink);
192
193 /* synchronizing against the clock */
194 void            gst_base_sink_set_sync          (GstBaseSink *sink, gboolean sync);
195 gboolean        gst_base_sink_get_sync          (GstBaseSink *sink);
196
197 /* dropping late buffers */
198 void            gst_base_sink_set_max_lateness  (GstBaseSink *sink, gint64 max_lateness);
199 gint64          gst_base_sink_get_max_lateness  (GstBaseSink *sink);
200
201 /* performing QoS */
202 void            gst_base_sink_set_qos_enabled   (GstBaseSink *sink, gboolean enabled);
203 gboolean        gst_base_sink_is_qos_enabled    (GstBaseSink *sink);
204
205 /* doing async state changes */
206 void            gst_base_sink_set_async_enabled (GstBaseSink *sink, gboolean enabled);
207 gboolean        gst_base_sink_is_async_enabled  (GstBaseSink *sink);
208
209 /* tuning synchronisation */
210 void            gst_base_sink_set_ts_offset     (GstBaseSink *sink, GstClockTimeDiff offset);
211 GstClockTimeDiff gst_base_sink_get_ts_offset    (GstBaseSink *sink);
212
213 /* last buffer */
214 GstBuffer *     gst_base_sink_get_last_buffer   (GstBaseSink *sink);
215 void            gst_base_sink_set_last_buffer_enabled (GstBaseSink *sink, gboolean enabled);
216 gboolean        gst_base_sink_is_last_buffer_enabled (GstBaseSink *sink);
217
218 /* latency */
219 gboolean        gst_base_sink_query_latency     (GstBaseSink *sink, gboolean *live, gboolean *upstream_live,
220                                                  GstClockTime *min_latency, GstClockTime *max_latency);
221 GstClockTime    gst_base_sink_get_latency       (GstBaseSink *sink);
222
223 /* render delay */
224 void            gst_base_sink_set_render_delay  (GstBaseSink *sink, GstClockTime delay);
225 GstClockTime    gst_base_sink_get_render_delay  (GstBaseSink *sink);
226
227 /* blocksize */
228 void            gst_base_sink_set_blocksize     (GstBaseSink *sink, guint blocksize);
229 guint           gst_base_sink_get_blocksize     (GstBaseSink *sink);
230
231 /* throttle-time */
232 void            gst_base_sink_set_throttle_time (GstBaseSink *sink, guint64 throttle);
233 guint64         gst_base_sink_get_throttle_time (GstBaseSink *sink);
234
235 GstClockReturn  gst_base_sink_wait_clock        (GstBaseSink *sink, GstClockTime time,
236                                                  GstClockTimeDiff * jitter);
237 GstFlowReturn   gst_base_sink_wait_eos          (GstBaseSink *sink, GstClockTime time,
238                                                  GstClockTimeDiff *jitter);
239
240 G_END_DECLS
241
242 #endif /* __GST_BASE_SINK_H__ */