| 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., 51 Franklin St, Fifth Floor, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | */ |
| 22 | |
| 23 | #ifndef __GST_BASE_SINK_H__ |
| 24 | #define __GST_BASE_SINK_H__ |
| 25 | |
| 26 | #include <gst/gst.h> |
| 27 | #include <gst/base/base-prelude.h> |
| 28 | |
| 29 | G_BEGIN_DECLS |
| 30 | |
| 31 | |
| 32 | #define GST_TYPE_BASE_SINK (gst_base_sink_get_type()) |
| 33 | #define GST_BASE_SINK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_SINK,GstBaseSink)) |
| 34 | #define GST_BASE_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_SINK,GstBaseSinkClass)) |
| 35 | #define GST_BASE_SINK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BASE_SINK, GstBaseSinkClass)) |
| 36 | #define GST_IS_BASE_SINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_SINK)) |
| 37 | #define GST_IS_BASE_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_SINK)) |
| 38 | #define GST_BASE_SINK_CAST(obj) ((GstBaseSink *) (obj)) |
| 39 | |
| 40 | /** |
| 41 | * GST_BASE_SINK_PAD: |
| 42 | * @obj: base sink instance |
| 43 | * |
| 44 | * Gives the pointer to the #GstPad object of the element. |
| 45 | */ |
| 46 | #define GST_BASE_SINK_PAD(obj) (GST_BASE_SINK_CAST (obj)->sinkpad) |
| 47 | |
| 48 | #define GST_BASE_SINK_GET_PREROLL_LOCK(obj) (&GST_BASE_SINK_CAST(obj)->preroll_lock) |
| 49 | #define GST_BASE_SINK_PREROLL_LOCK(obj) (g_mutex_lock(GST_BASE_SINK_GET_PREROLL_LOCK(obj))) |
| 50 | #define GST_BASE_SINK_PREROLL_TRYLOCK(obj) (g_mutex_trylock(GST_BASE_SINK_GET_PREROLL_LOCK(obj))) |
| 51 | #define GST_BASE_SINK_PREROLL_UNLOCK(obj) (g_mutex_unlock(GST_BASE_SINK_GET_PREROLL_LOCK(obj))) |
| 52 | |
| 53 | #define GST_BASE_SINK_GET_PREROLL_COND(obj) (&GST_BASE_SINK_CAST(obj)->preroll_cond) |
| 54 | #define GST_BASE_SINK_PREROLL_WAIT(obj) \ |
| 55 | g_cond_wait (GST_BASE_SINK_GET_PREROLL_COND (obj), GST_BASE_SINK_GET_PREROLL_LOCK (obj)) |
| 56 | #define GST_BASE_SINK_PREROLL_WAIT_UNTIL(obj, end_time) \ |
| 57 | g_cond_wait_until (GST_BASE_SINK_GET_PREROLL_COND (obj), GST_BASE_SINK_GET_PREROLL_LOCK (obj), end_time) |
| 58 | #define GST_BASE_SINK_PREROLL_SIGNAL(obj) g_cond_signal (GST_BASE_SINK_GET_PREROLL_COND (obj)); |
| 59 | #define GST_BASE_SINK_PREROLL_BROADCAST(obj) g_cond_broadcast (GST_BASE_SINK_GET_PREROLL_COND (obj)); |
| 60 | |
| 61 | /** |
| 62 | * GST_BASE_SINK_FLOW_DROPPED: |
| 63 | * |
| 64 | * A #GstFlowReturn that can be returned from |
| 65 | * #GstBaseSinkClass::render to indicate that the output buffer was not |
| 66 | * rendered. |
| 67 | * |
| 68 | * Note that this is currently not support for #GstBaseSinkClass::render_list |
| 69 | * virtual method. |
| 70 | * |
| 71 | * Since: 1.24 |
| 72 | */ |
| 73 | #define GST_BASE_SINK_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS |
| 74 | |
| 75 | typedef struct _GstBaseSink GstBaseSink; |
| 76 | typedef struct _GstBaseSinkClass GstBaseSinkClass; |
| 77 | typedef struct _GstBaseSinkPrivate GstBaseSinkPrivate; |
| 78 | |
| 79 | /** |
| 80 | * GstBaseSink: |
| 81 | * |
| 82 | * The opaque #GstBaseSink data structure. |
| 83 | */ |
| 84 | struct _GstBaseSink { |
| 85 | GstElement element; |
| 86 | |
| 87 | /*< protected >*/ |
| 88 | GstPad *sinkpad; |
| 89 | GstPadMode pad_mode; |
| 90 | |
| 91 | /*< protected >*/ /* with LOCK */ |
| 92 | guint64 offset; |
| 93 | gboolean can_activate_pull; |
| 94 | gboolean can_activate_push; |
| 95 | |
| 96 | /*< protected >*/ /* with PREROLL_LOCK */ |
| 97 | GMutex preroll_lock; |
| 98 | GCond preroll_cond; |
| 99 | gboolean eos; |
| 100 | gboolean need_preroll; |
| 101 | gboolean have_preroll; |
| 102 | gboolean playing_async; |
| 103 | |
| 104 | /*< protected >*/ /* with STREAM_LOCK */ |
| 105 | gboolean have_newsegment; |
| 106 | GstSegment segment; |
| 107 | |
| 108 | /*< private >*/ /* with LOCK */ |
| 109 | GstClockID clock_id; |
| 110 | gboolean sync; |
| 111 | gboolean flushing; |
| 112 | gboolean running; |
| 113 | |
| 114 | gint64 max_lateness; |
| 115 | |
| 116 | /*< private >*/ |
| 117 | GstBaseSinkPrivate *priv; |
| 118 | |
| 119 | gpointer _gst_reserved[GST_PADDING_LARGE]; |
| 120 | }; |
| 121 | |
| 122 | /** |
| 123 | * GstBaseSinkClass: |
| 124 | * @parent_class: Element parent class |
| 125 | * @get_caps: Called to get sink pad caps from the subclass |
| 126 | * @set_caps: Notify subclass of changed caps |
| 127 | * @fixate: Only useful in pull mode. Implement if you have |
| 128 | * ideas about what should be the default values for the caps you support. |
| 129 | * @activate_pull: Subclasses should override this when they can provide an |
| 130 | * alternate method of spawning a thread to drive the pipeline in pull mode. |
| 131 | * Should start or stop the pulling thread, depending on the value of the |
| 132 | * "active" argument. Called after actually activating the sink pad in pull |
| 133 | * mode. The default implementation starts a task on the sink pad. |
| 134 | * @get_times: Called to get the start and end times for synchronising |
| 135 | * the passed buffer to the clock |
| 136 | * @propose_allocation: configure the allocation query |
| 137 | * @start: Start processing. Ideal for opening resources in the subclass |
| 138 | * @stop: Stop processing. Subclasses should use this to close resources. |
| 139 | * @unlock: Unlock any pending access to the resource. Subclasses should |
| 140 | * unblock any blocked function ASAP and call gst_base_sink_wait_preroll() |
| 141 | * @unlock_stop: Clear the previous unlock request. Subclasses should clear |
| 142 | * any state they set during #GstBaseSinkClass::unlock, and be ready to |
| 143 | * continue where they left off after gst_base_sink_wait_preroll(), |
| 144 | * gst_base_sink_wait() or gst_wait_sink_wait_clock() return or |
| 145 | * #GstBaseSinkClass::render is called again. |
| 146 | * @query: perform a #GstQuery on the element. |
| 147 | * @event: Override this to handle events arriving on the sink pad |
| 148 | * @wait_event: Override this to implement custom logic to wait for the event |
| 149 | * time (for events like EOS and GAP). Subclasses should always first |
| 150 | * chain up to the default implementation. |
| 151 | * @prepare: Called to prepare the buffer for @render and @preroll. This |
| 152 | * function is called before synchronisation is performed. |
| 153 | * @prepare_list: Called to prepare the buffer list for @render_list. This |
| 154 | * function is called before synchronisation is performed. |
| 155 | * @preroll: Called to present the preroll buffer if desired. |
| 156 | * @render: Called when a buffer should be presented or output, at the |
| 157 | * correct moment if the #GstBaseSink has been set to sync to the clock. |
| 158 | * @render_list: Same as @render but used with buffer lists instead of |
| 159 | * buffers. |
| 160 | * |
| 161 | * Subclasses can override any of the available virtual methods or not, as |
| 162 | * needed. At the minimum, the @render method should be overridden to |
| 163 | * output/present buffers. |
| 164 | */ |
| 165 | struct _GstBaseSinkClass { |
| 166 | GstElementClass parent_class; |
| 167 | |
| 168 | /** |
| 169 | * GstBaseSinkClass::get_caps: |
| 170 | * @filter: (in) (nullable): |
| 171 | * |
| 172 | * Called to get sink pad caps from the subclass. |
| 173 | */ |
| 174 | GstCaps* (*get_caps) (GstBaseSink *sink, GstCaps *filter); |
| 175 | /* notify subclass of new caps */ |
| 176 | gboolean (*set_caps) (GstBaseSink *sink, GstCaps *caps); |
| 177 | |
| 178 | /* fixate sink caps during pull-mode negotiation */ |
| 179 | GstCaps * (*fixate) (GstBaseSink *sink, GstCaps *caps); |
| 180 | /* start or stop a pulling thread */ |
| 181 | gboolean (*activate_pull)(GstBaseSink *sink, gboolean active); |
| 182 | |
| 183 | /** |
| 184 | * GstBaseSinkClass::get_times: |
| 185 | * @start: (out): the start #GstClockTime |
| 186 | * @end: (out): the end #GstClockTime |
| 187 | * |
| 188 | * Get the start and end times for syncing on this buffer. |
| 189 | */ |
| 190 | void (*get_times) (GstBaseSink *sink, GstBuffer *buffer, |
| 191 | GstClockTime *start, GstClockTime *end); |
| 192 | |
| 193 | /* propose allocation parameters for upstream */ |
| 194 | gboolean (*propose_allocation) (GstBaseSink *sink, GstQuery *query); |
| 195 | |
| 196 | /* start and stop processing, ideal for opening/closing the resource */ |
| 197 | gboolean (*start) (GstBaseSink *sink); |
| 198 | gboolean (*stop) (GstBaseSink *sink); |
| 199 | |
| 200 | /* unlock any pending access to the resource. subclasses should unlock |
| 201 | * any function ASAP. */ |
| 202 | gboolean (*unlock) (GstBaseSink *sink); |
| 203 | /* Clear a previously indicated unlock request not that unlocking is |
| 204 | * complete. Sub-classes should clear any command queue or indicator they |
| 205 | * set during unlock */ |
| 206 | gboolean (*unlock_stop) (GstBaseSink *sink); |
| 207 | |
| 208 | /* notify subclass of query */ |
| 209 | gboolean (*query) (GstBaseSink *sink, GstQuery *query); |
| 210 | |
| 211 | /* notify subclass of event */ |
| 212 | gboolean (*event) (GstBaseSink *sink, GstEvent *event); |
| 213 | /* wait for eos or gap, subclasses should chain up to parent first */ |
| 214 | GstFlowReturn (*wait_event) (GstBaseSink *sink, GstEvent *event); |
| 215 | |
| 216 | /* notify subclass of buffer or list before doing sync */ |
| 217 | GstFlowReturn (*prepare) (GstBaseSink *sink, GstBuffer *buffer); |
| 218 | GstFlowReturn (*prepare_list) (GstBaseSink *sink, GstBufferList *buffer_list); |
| 219 | |
| 220 | /* notify subclass of preroll buffer or real buffer */ |
| 221 | GstFlowReturn (*preroll) (GstBaseSink *sink, GstBuffer *buffer); |
| 222 | GstFlowReturn (*render) (GstBaseSink *sink, GstBuffer *buffer); |
| 223 | /* Render a BufferList */ |
| 224 | GstFlowReturn (*render_list) (GstBaseSink *sink, GstBufferList *buffer_list); |
| 225 | |
| 226 | /*< private >*/ |
| 227 | gpointer _gst_reserved[GST_PADDING_LARGE]; |
| 228 | }; |
| 229 | |
| 230 | GST_BASE_API |
| 231 | GType gst_base_sink_get_type (void); |
| 232 | |
| 233 | GST_BASE_API |
| 234 | GstFlowReturn gst_base_sink_do_preroll (GstBaseSink *sink, GstMiniObject *obj); |
| 235 | |
| 236 | GST_BASE_API |
| 237 | GstFlowReturn gst_base_sink_wait_preroll (GstBaseSink *sink); |
| 238 | |
| 239 | /* synchronizing against the clock */ |
| 240 | |
| 241 | GST_BASE_API |
| 242 | void gst_base_sink_set_sync (GstBaseSink *sink, gboolean sync); |
| 243 | |
| 244 | GST_BASE_API |
| 245 | gboolean gst_base_sink_get_sync (GstBaseSink *sink); |
| 246 | |
| 247 | /* Drop buffers which are out of segment */ |
| 248 | |
| 249 | GST_BASE_API |
| 250 | void gst_base_sink_set_drop_out_of_segment (GstBaseSink *sink, gboolean drop_out_of_segment); |
| 251 | |
| 252 | GST_BASE_API |
| 253 | gboolean gst_base_sink_get_drop_out_of_segment (GstBaseSink *sink); |
| 254 | |
| 255 | /* dropping late buffers */ |
| 256 | |
| 257 | GST_BASE_API |
| 258 | void gst_base_sink_set_max_lateness (GstBaseSink *sink, gint64 max_lateness); |
| 259 | |
| 260 | GST_BASE_API |
| 261 | gint64 gst_base_sink_get_max_lateness (GstBaseSink *sink); |
| 262 | |
| 263 | /* performing QoS */ |
| 264 | |
| 265 | GST_BASE_API |
| 266 | void gst_base_sink_set_qos_enabled (GstBaseSink *sink, gboolean enabled); |
| 267 | |
| 268 | GST_BASE_API |
| 269 | gboolean gst_base_sink_is_qos_enabled (GstBaseSink *sink); |
| 270 | |
| 271 | /* doing async state changes */ |
| 272 | |
| 273 | GST_BASE_API |
| 274 | void gst_base_sink_set_async_enabled (GstBaseSink *sink, gboolean enabled); |
| 275 | |
| 276 | GST_BASE_API |
| 277 | gboolean gst_base_sink_is_async_enabled (GstBaseSink *sink); |
| 278 | |
| 279 | /* tuning synchronisation */ |
| 280 | |
| 281 | GST_BASE_API |
| 282 | void gst_base_sink_set_ts_offset (GstBaseSink *sink, GstClockTimeDiff offset); |
| 283 | |
| 284 | GST_BASE_API |
| 285 | GstClockTimeDiff gst_base_sink_get_ts_offset (GstBaseSink *sink); |
| 286 | |
| 287 | /* last sample */ |
| 288 | |
| 289 | GST_BASE_API |
| 290 | GstSample * gst_base_sink_get_last_sample (GstBaseSink *sink); |
| 291 | |
| 292 | GST_BASE_API |
| 293 | void gst_base_sink_set_last_sample_enabled (GstBaseSink *sink, gboolean enabled); |
| 294 | |
| 295 | GST_BASE_API |
| 296 | gboolean gst_base_sink_is_last_sample_enabled (GstBaseSink *sink); |
| 297 | |
| 298 | /* latency */ |
| 299 | |
| 300 | GST_BASE_API |
| 301 | gboolean gst_base_sink_query_latency (GstBaseSink *sink, gboolean *live, gboolean *upstream_live, |
| 302 | GstClockTime *min_latency, GstClockTime *max_latency); |
| 303 | GST_BASE_API |
| 304 | GstClockTime gst_base_sink_get_latency (GstBaseSink *sink); |
| 305 | |
| 306 | /* render delay */ |
| 307 | |
| 308 | GST_BASE_API |
| 309 | void gst_base_sink_set_render_delay (GstBaseSink *sink, GstClockTime delay); |
| 310 | |
| 311 | GST_BASE_API |
| 312 | GstClockTime gst_base_sink_get_render_delay (GstBaseSink *sink); |
| 313 | |
| 314 | /* blocksize */ |
| 315 | |
| 316 | GST_BASE_API |
| 317 | void gst_base_sink_set_blocksize (GstBaseSink *sink, guint blocksize); |
| 318 | |
| 319 | GST_BASE_API |
| 320 | guint gst_base_sink_get_blocksize (GstBaseSink *sink); |
| 321 | |
| 322 | /* throttle-time */ |
| 323 | |
| 324 | GST_BASE_API |
| 325 | void gst_base_sink_set_throttle_time (GstBaseSink *sink, guint64 throttle); |
| 326 | |
| 327 | GST_BASE_API |
| 328 | guint64 gst_base_sink_get_throttle_time (GstBaseSink *sink); |
| 329 | |
| 330 | /* max-bitrate */ |
| 331 | |
| 332 | GST_BASE_API |
| 333 | void gst_base_sink_set_max_bitrate (GstBaseSink *sink, guint64 max_bitrate); |
| 334 | |
| 335 | GST_BASE_API |
| 336 | guint64 gst_base_sink_get_max_bitrate (GstBaseSink *sink); |
| 337 | |
| 338 | /* processing deadline */ |
| 339 | GST_BASE_API |
| 340 | void gst_base_sink_set_processing_deadline (GstBaseSink *sink, GstClockTime processing_deadline); |
| 341 | |
| 342 | GST_BASE_API |
| 343 | GstClockTime gst_base_sink_get_processing_deadline (GstBaseSink *sink); |
| 344 | |
| 345 | GST_BASE_API |
| 346 | GstClockReturn gst_base_sink_wait_clock (GstBaseSink *sink, GstClockTime time, |
| 347 | GstClockTimeDiff * jitter); |
| 348 | GST_BASE_API |
| 349 | GstFlowReturn gst_base_sink_wait (GstBaseSink *sink, GstClockTime time, |
| 350 | GstClockTimeDiff *jitter); |
| 351 | |
| 352 | GST_BASE_API |
| 353 | GstStructure *gst_base_sink_get_stats (GstBaseSink * sink); |
| 354 | |
| 355 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstBaseSink, gst_object_unref) |
| 356 | |
| 357 | G_END_DECLS |
| 358 | |
| 359 | #endif /* __GST_BASE_SINK_H__ */ |
| 360 | |