gstbasesink.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. #ifndef __GST_BASE_SINK_H__
  23. #define __GST_BASE_SINK_H__
  24. #include <gst/gst.h>
  25. G_BEGIN_DECLS
  26. #define GST_TYPE_BASE_SINK (gst_base_sink_get_type())
  27. #define GST_BASE_SINK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_SINK,GstBaseSink))
  28. #define GST_BASE_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_SINK,GstBaseSinkClass))
  29. #define GST_BASE_SINK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BASE_SINK, GstBaseSinkClass))
  30. #define GST_IS_BASE_SINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_SINK))
  31. #define GST_IS_BASE_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_SINK))
  32. #define GST_BASE_SINK_CAST(obj) ((GstBaseSink *) (obj))
  33. /**
  34. * GST_BASE_SINK_PAD:
  35. * @obj: base sink instance
  36. *
  37. * Gives the pointer to the #GstPad object of the element.
  38. */
  39. #define GST_BASE_SINK_PAD(obj) (GST_BASE_SINK_CAST (obj)->sinkpad)
  40. #define GST_BASE_SINK_GET_PREROLL_LOCK(obj) (&GST_BASE_SINK_CAST(obj)->preroll_lock)
  41. #define GST_BASE_SINK_PREROLL_LOCK(obj) (g_mutex_lock(GST_BASE_SINK_GET_PREROLL_LOCK(obj)))
  42. #define GST_BASE_SINK_PREROLL_TRYLOCK(obj) (g_mutex_trylock(GST_BASE_SINK_GET_PREROLL_LOCK(obj)))
  43. #define GST_BASE_SINK_PREROLL_UNLOCK(obj) (g_mutex_unlock(GST_BASE_SINK_GET_PREROLL_LOCK(obj)))
  44. #define GST_BASE_SINK_GET_PREROLL_COND(obj) (&GST_BASE_SINK_CAST(obj)->preroll_cond)
  45. #define GST_BASE_SINK_PREROLL_WAIT(obj) \
  46. g_cond_wait (GST_BASE_SINK_GET_PREROLL_COND (obj), GST_BASE_SINK_GET_PREROLL_LOCK (obj))
  47. #define GST_BASE_SINK_PREROLL_WAIT_UNTIL(obj, end_time) \
  48. g_cond_wait_until (GST_BASE_SINK_GET_PREROLL_COND (obj), GST_BASE_SINK_GET_PREROLL_LOCK (obj), end_time)
  49. #define GST_BASE_SINK_PREROLL_SIGNAL(obj) g_cond_signal (GST_BASE_SINK_GET_PREROLL_COND (obj));
  50. #define GST_BASE_SINK_PREROLL_BROADCAST(obj) g_cond_broadcast (GST_BASE_SINK_GET_PREROLL_COND (obj));
  51. typedef struct _GstBaseSink GstBaseSink;
  52. typedef struct _GstBaseSinkClass GstBaseSinkClass;
  53. typedef struct _GstBaseSinkPrivate GstBaseSinkPrivate;
  54. /**
  55. * GstBaseSink:
  56. *
  57. * The opaque #GstBaseSink data structure.
  58. */
  59. struct _GstBaseSink {
  60. GstElement element;
  61. /*< protected >*/
  62. GstPad *sinkpad;
  63. GstPadMode pad_mode;
  64. /*< protected >*/ /* with LOCK */
  65. guint64 offset;
  66. gboolean can_activate_pull;
  67. gboolean can_activate_push;
  68. /*< protected >*/ /* with PREROLL_LOCK */
  69. GMutex preroll_lock;
  70. GCond preroll_cond;
  71. gboolean eos;
  72. gboolean need_preroll;
  73. gboolean have_preroll;
  74. gboolean playing_async;
  75. /*< protected >*/ /* with STREAM_LOCK */
  76. gboolean have_newsegment;
  77. GstSegment segment;
  78. /*< private >*/ /* with LOCK */
  79. GstClockID clock_id;
  80. gboolean sync;
  81. gboolean flushing;
  82. gboolean running;
  83. gint64 max_lateness;
  84. /*< private >*/
  85. GstBaseSinkPrivate *priv;
  86. gpointer _gst_reserved[GST_PADDING_LARGE];
  87. };
  88. /**
  89. * GstBaseSinkClass:
  90. * @parent_class: Element parent class
  91. * @get_caps: Called to get sink pad caps from the subclass
  92. * @set_caps: Notify subclass of changed caps
  93. * @fixate: Only useful in pull mode. Implement if you have
  94. * ideas about what should be the default values for the caps you support.
  95. * @activate_pull: Subclasses should override this when they can provide an
  96. * alternate method of spawning a thread to drive the pipeline in pull mode.
  97. * Should start or stop the pulling thread, depending on the value of the
  98. * "active" argument. Called after actually activating the sink pad in pull
  99. * mode. The default implementation starts a task on the sink pad.
  100. * @get_times: Called to get the start and end times for synchronising
  101. * the passed buffer to the clock
  102. * @propose_allocation: configure the allocation query
  103. * @start: Start processing. Ideal for opening resources in the subclass
  104. * @stop: Stop processing. Subclasses should use this to close resources.
  105. * @unlock: Unlock any pending access to the resource. Subclasses should
  106. * unblock any blocked function ASAP
  107. * @unlock_stop: Clear the previous unlock request. Subclasses should clear
  108. * any state they set during unlock(), such as clearing command queues.
  109. * @query: perform a #GstQuery on the element.
  110. * @event: Override this to handle events arriving on the sink pad
  111. * @wait_event: Override this to implement custom logic to wait for the event
  112. * time (for events like EOS and GAP). Subclasses should always first
  113. * chain up to the default implementation.
  114. * @prepare: Called to prepare the buffer for @render and @preroll. This
  115. * function is called before synchronisation is performed.
  116. * @prepare_list: Called to prepare the buffer list for @render_list. This
  117. * function is called before synchronisation is performed.
  118. * @preroll: Called to present the preroll buffer if desired.
  119. * @render: Called when a buffer should be presented or output, at the
  120. * correct moment if the #GstBaseSink has been set to sync to the clock.
  121. * @render_list: Same as @render but used with buffer lists instead of
  122. * buffers.
  123. *
  124. * Subclasses can override any of the available virtual methods or not, as
  125. * needed. At the minimum, the @render method should be overridden to
  126. * output/present buffers.
  127. */
  128. struct _GstBaseSinkClass {
  129. GstElementClass parent_class;
  130. /* get caps from subclass */
  131. GstCaps* (*get_caps) (GstBaseSink *sink, GstCaps *filter);
  132. /* notify subclass of new caps */
  133. gboolean (*set_caps) (GstBaseSink *sink, GstCaps *caps);
  134. /* fixate sink caps during pull-mode negotiation */
  135. GstCaps * (*fixate) (GstBaseSink *sink, GstCaps *caps);
  136. /* start or stop a pulling thread */
  137. gboolean (*activate_pull)(GstBaseSink *sink, gboolean active);
  138. /* get the start and end times for syncing on this buffer */
  139. void (*get_times) (GstBaseSink *sink, GstBuffer *buffer,
  140. GstClockTime *start, GstClockTime *end);
  141. /* propose allocation parameters for upstream */
  142. gboolean (*propose_allocation) (GstBaseSink *sink, GstQuery *query);
  143. /* start and stop processing, ideal for opening/closing the resource */
  144. gboolean (*start) (GstBaseSink *sink);
  145. gboolean (*stop) (GstBaseSink *sink);
  146. /* unlock any pending access to the resource. subclasses should unlock
  147. * any function ASAP. */
  148. gboolean (*unlock) (GstBaseSink *sink);
  149. /* Clear a previously indicated unlock request not that unlocking is
  150. * complete. Sub-classes should clear any command queue or indicator they
  151. * set during unlock */
  152. gboolean (*unlock_stop) (GstBaseSink *sink);
  153. /* notify subclass of query */
  154. gboolean (*query) (GstBaseSink *sink, GstQuery *query);
  155. /* notify subclass of event */
  156. gboolean (*event) (GstBaseSink *sink, GstEvent *event);
  157. /* wait for eos or gap, subclasses should chain up to parent first */
  158. GstFlowReturn (*wait_event) (GstBaseSink *sink, GstEvent *event);
  159. /* notify subclass of buffer or list before doing sync */
  160. GstFlowReturn (*prepare) (GstBaseSink *sink, GstBuffer *buffer);
  161. GstFlowReturn (*prepare_list) (GstBaseSink *sink, GstBufferList *buffer_list);
  162. /* notify subclass of preroll buffer or real buffer */
  163. GstFlowReturn (*preroll) (GstBaseSink *sink, GstBuffer *buffer);
  164. GstFlowReturn (*render) (GstBaseSink *sink, GstBuffer *buffer);
  165. /* Render a BufferList */
  166. GstFlowReturn (*render_list) (GstBaseSink *sink, GstBufferList *buffer_list);
  167. /*< private >*/
  168. gpointer _gst_reserved[GST_PADDING_LARGE];
  169. };
  170. GType gst_base_sink_get_type(void);
  171. GstFlowReturn gst_base_sink_do_preroll (GstBaseSink *sink, GstMiniObject *obj);
  172. GstFlowReturn gst_base_sink_wait_preroll (GstBaseSink *sink);
  173. /* synchronizing against the clock */
  174. void gst_base_sink_set_sync (GstBaseSink *sink, gboolean sync);
  175. gboolean gst_base_sink_get_sync (GstBaseSink *sink);
  176. /* dropping late buffers */
  177. void gst_base_sink_set_max_lateness (GstBaseSink *sink, gint64 max_lateness);
  178. gint64 gst_base_sink_get_max_lateness (GstBaseSink *sink);
  179. /* performing QoS */
  180. void gst_base_sink_set_qos_enabled (GstBaseSink *sink, gboolean enabled);
  181. gboolean gst_base_sink_is_qos_enabled (GstBaseSink *sink);
  182. /* doing async state changes */
  183. void gst_base_sink_set_async_enabled (GstBaseSink *sink, gboolean enabled);
  184. gboolean gst_base_sink_is_async_enabled (GstBaseSink *sink);
  185. /* tuning synchronisation */
  186. void gst_base_sink_set_ts_offset (GstBaseSink *sink, GstClockTimeDiff offset);
  187. GstClockTimeDiff gst_base_sink_get_ts_offset (GstBaseSink *sink);
  188. /* last sample */
  189. GstSample * gst_base_sink_get_last_sample (GstBaseSink *sink);
  190. void gst_base_sink_set_last_sample_enabled (GstBaseSink *sink, gboolean enabled);
  191. gboolean gst_base_sink_is_last_sample_enabled (GstBaseSink *sink);
  192. /* latency */
  193. gboolean gst_base_sink_query_latency (GstBaseSink *sink, gboolean *live, gboolean *upstream_live,
  194. GstClockTime *min_latency, GstClockTime *max_latency);
  195. GstClockTime gst_base_sink_get_latency (GstBaseSink *sink);
  196. /* render delay */
  197. void gst_base_sink_set_render_delay (GstBaseSink *sink, GstClockTime delay);
  198. GstClockTime gst_base_sink_get_render_delay (GstBaseSink *sink);
  199. /* blocksize */
  200. void gst_base_sink_set_blocksize (GstBaseSink *sink, guint blocksize);
  201. guint gst_base_sink_get_blocksize (GstBaseSink *sink);
  202. /* throttle-time */
  203. void gst_base_sink_set_throttle_time (GstBaseSink *sink, guint64 throttle);
  204. guint64 gst_base_sink_get_throttle_time (GstBaseSink *sink);
  205. /* max-bitrate */
  206. void gst_base_sink_set_max_bitrate (GstBaseSink *sink, guint64 max_bitrate);
  207. guint64 gst_base_sink_get_max_bitrate (GstBaseSink *sink);
  208. GstClockReturn gst_base_sink_wait_clock (GstBaseSink *sink, GstClockTime time,
  209. GstClockTimeDiff * jitter);
  210. GstFlowReturn gst_base_sink_wait (GstBaseSink *sink, GstClockTime time,
  211. GstClockTimeDiff *jitter);
  212. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  213. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstBaseSink, gst_object_unref)
  214. #endif
  215. G_END_DECLS
  216. #endif /* __GST_BASE_SINK_H__ */