gstbasetransform.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /* GStreamer
  2. * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
  3. * 2005 Wim Taymans <wim@fluendo.com>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public
  16. * License along with this library; if not, write to the
  17. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef __GST_BASE_TRANSFORM_H__
  21. #define __GST_BASE_TRANSFORM_H__
  22. #include <gst/gst.h>
  23. G_BEGIN_DECLS
  24. #define GST_TYPE_BASE_TRANSFORM (gst_base_transform_get_type())
  25. #define GST_BASE_TRANSFORM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_TRANSFORM,GstBaseTransform))
  26. #define GST_BASE_TRANSFORM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_TRANSFORM,GstBaseTransformClass))
  27. #define GST_BASE_TRANSFORM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_BASE_TRANSFORM,GstBaseTransformClass))
  28. #define GST_IS_BASE_TRANSFORM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_TRANSFORM))
  29. #define GST_IS_BASE_TRANSFORM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_TRANSFORM))
  30. #define GST_BASE_TRANSFORM_CAST(obj) ((GstBaseTransform *)(obj))
  31. /**
  32. * GST_BASE_TRANSFORM_SINK_NAME:
  33. *
  34. * The name of the templates for the sink pad.
  35. */
  36. #define GST_BASE_TRANSFORM_SINK_NAME "sink"
  37. /**
  38. * GST_BASE_TRANSFORM_SRC_NAME:
  39. *
  40. * The name of the templates for the source pad.
  41. */
  42. #define GST_BASE_TRANSFORM_SRC_NAME "src"
  43. /**
  44. * GST_BASE_TRANSFORM_SRC_PAD:
  45. * @obj: base transform instance
  46. *
  47. * Gives the pointer to the source #GstPad object of the element.
  48. */
  49. #define GST_BASE_TRANSFORM_SRC_PAD(obj) (GST_BASE_TRANSFORM_CAST (obj)->srcpad)
  50. /**
  51. * GST_BASE_TRANSFORM_SINK_PAD:
  52. * @obj: base transform instance
  53. *
  54. * Gives the pointer to the sink #GstPad object of the element.
  55. */
  56. #define GST_BASE_TRANSFORM_SINK_PAD(obj) (GST_BASE_TRANSFORM_CAST (obj)->sinkpad)
  57. /**
  58. * GST_BASE_TRANSFORM_FLOW_DROPPED:
  59. *
  60. * A #GstFlowReturn that can be returned from transform and transform_ip to
  61. * indicate that no output buffer was generated.
  62. */
  63. #define GST_BASE_TRANSFORM_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS
  64. typedef struct _GstBaseTransform GstBaseTransform;
  65. typedef struct _GstBaseTransformClass GstBaseTransformClass;
  66. typedef struct _GstBaseTransformPrivate GstBaseTransformPrivate;
  67. /**
  68. * GstBaseTransform:
  69. *
  70. * The opaque #GstBaseTransform data structure.
  71. */
  72. struct _GstBaseTransform {
  73. GstElement element;
  74. /*< protected >*/
  75. /* source and sink pads */
  76. GstPad *sinkpad;
  77. GstPad *srcpad;
  78. /* MT-protected (with STREAM_LOCK) */
  79. gboolean have_segment;
  80. GstSegment segment;
  81. /* Default submit_input_buffer places the buffer here,
  82. * for consumption by the generate_output method: */
  83. GstBuffer *queued_buf;
  84. /*< private >*/
  85. GstBaseTransformPrivate *priv;
  86. gpointer _gst_reserved[GST_PADDING_LARGE-1];
  87. };
  88. /**
  89. * GstBaseTransformClass:
  90. * @parent_class: Element parent class
  91. * @passthrough_on_same_caps: If set to %TRUE, passthrough mode will be
  92. * automatically enabled if the caps are the same.
  93. * Set to %FALSE by default.
  94. * @transform_ip_on_passthrough: If set to %TRUE, @transform_ip will be called in
  95. * passthrough mode. The passed buffer might not be
  96. * writable. When %FALSE, neither @transform nor
  97. * @transform_ip will be called in passthrough mode.
  98. * Set to %TRUE by default.
  99. * @transform_caps: Optional. Given the pad in this direction and the given
  100. * caps, what caps are allowed on the other pad in this
  101. * element ?
  102. * @fixate_caps: Optional. Given the pad in this direction and the given
  103. * caps, fixate the caps on the other pad. The function takes
  104. * ownership of @othercaps and returns a fixated version of
  105. * @othercaps. @othercaps is not guaranteed to be writable.
  106. * @accept_caps: Optional.
  107. * Subclasses can override this method to check if @caps can be
  108. * handled by the element. The default implementation might not be
  109. * the most optimal way to check this in all cases.
  110. * @set_caps: allows the subclass to be notified of the actual caps set.
  111. * @query: Optional.
  112. * Handle a requested query. Subclasses that implement this
  113. * should must chain up to the parent if they didn't handle the
  114. * query
  115. * @decide_allocation: Setup the allocation parameters for allocating output
  116. * buffers. The passed in query contains the result of the
  117. * downstream allocation query. This function is only called
  118. * when not operating in passthrough mode. The default
  119. * implementation will remove all memory dependent metadata.
  120. * If there is a @filter_meta method implementation, it will
  121. * be called for all metadata API in the downstream query,
  122. * otherwise the metadata API is removed.
  123. * @filter_meta: Return %TRUE if the metadata API should be proposed in the
  124. * upstream allocation query. The default implementation is %NULL
  125. * and will cause all metadata to be removed.
  126. * @propose_allocation: Propose buffer allocation parameters for upstream elements.
  127. * This function must be implemented if the element reads or
  128. * writes the buffer content. The query that was passed to
  129. * the decide_allocation is passed in this method (or %NULL
  130. * when the element is in passthrough mode). The default
  131. * implementation will pass the query downstream when in
  132. * passthrough mode and will copy all the filtered metadata
  133. * API in non-passthrough mode.
  134. * @transform_size: Optional. Given the size of a buffer in the given direction
  135. * with the given caps, calculate the size in bytes of a buffer
  136. * on the other pad with the given other caps.
  137. * The default implementation uses get_unit_size and keeps
  138. * the number of units the same.
  139. * @get_unit_size: Required if the transform is not in-place.
  140. * get the size in bytes of one unit for the given caps.
  141. * @start: Optional.
  142. * Called when the element starts processing.
  143. * Allows opening external resources.
  144. * @stop: Optional.
  145. * Called when the element stops processing.
  146. * Allows closing external resources.
  147. * @sink_event: Optional.
  148. * Event handler on the sink pad. The default implementation
  149. * handles the event and forwards it downstream.
  150. * @src_event: Optional.
  151. * Event handler on the source pad. The default implementation
  152. * handles the event and forwards it upstream.
  153. * @prepare_output_buffer: Optional.
  154. * Subclasses can override this to do their own
  155. * allocation of output buffers. Elements that only do
  156. * analysis can return a subbuffer or even just
  157. * return a reference to the input buffer (if in
  158. * passthrough mode). The default implementation will
  159. * use the negotiated allocator or bufferpool and
  160. * transform_size to allocate an output buffer or it
  161. * will return the input buffer in passthrough mode.
  162. * @copy_metadata: Optional.
  163. * Copy the metadata from the input buffer to the output buffer.
  164. * The default implementation will copy the flags, timestamps and
  165. * offsets of the buffer.
  166. * @transform_meta: Optional. Transform the metadata on the input buffer to the
  167. * output buffer. By default this method copies all meta without
  168. * tags. subclasses can implement this method and return %TRUE if
  169. * the metadata is to be copied.
  170. * @before_transform: Optional.
  171. * This method is called right before the base class will
  172. * start processing. Dynamic properties or other delayed
  173. * configuration could be performed in this method.
  174. * @transform: Required if the element does not operate in-place.
  175. * Transforms one incoming buffer to one outgoing buffer.
  176. * The function is allowed to change size/timestamp/duration
  177. * of the outgoing buffer.
  178. * @transform_ip: Required if the element operates in-place.
  179. * Transform the incoming buffer in-place.
  180. * @submit_input_buffer: Function which accepts a new input buffer and pre-processes it.
  181. * The default implementation performs caps (re)negotiation, then
  182. * QoS if needed, and places the input buffer into the @queued_buf
  183. * member variable. If the buffer is dropped due to QoS, it returns
  184. * GST_BASE_TRANSFORM_FLOW_DROPPED. If this input buffer is not
  185. * contiguous with any previous input buffer, then @is_discont
  186. * is set to #TRUE. (Since 1.6)
  187. * @generate_output: Called after each new input buffer is submitted repeatedly
  188. * until it either generates an error or fails to generate an output
  189. * buffer. The default implementation takes the contents of the
  190. * @queued_buf variable, generates an output buffer if needed
  191. * by calling the class @prepare_output_buffer, and then
  192. * calls either @transform or @transform_ip. Elements that don't
  193. * do 1-to-1 transformations on input to output buffers can either
  194. * return GST_BASE_TRANSFORM_FLOW_DROPPED or simply not generate
  195. * an output buffer until they are ready to do so. (Since 1.6)
  196. *
  197. * Subclasses can override any of the available virtual methods or not, as
  198. * needed. At minimum either @transform or @transform_ip need to be overridden.
  199. * If the element can overwrite the input data with the results (data is of the
  200. * same type and quantity) it should provide @transform_ip.
  201. */
  202. struct _GstBaseTransformClass {
  203. GstElementClass parent_class;
  204. /*< public >*/
  205. gboolean passthrough_on_same_caps;
  206. gboolean transform_ip_on_passthrough;
  207. /* virtual methods for subclasses */
  208. GstCaps* (*transform_caps) (GstBaseTransform *trans,
  209. GstPadDirection direction,
  210. GstCaps *caps, GstCaps *filter);
  211. GstCaps* (*fixate_caps) (GstBaseTransform *trans,
  212. GstPadDirection direction, GstCaps *caps,
  213. GstCaps *othercaps);
  214. gboolean (*accept_caps) (GstBaseTransform *trans, GstPadDirection direction,
  215. GstCaps *caps);
  216. gboolean (*set_caps) (GstBaseTransform *trans, GstCaps *incaps,
  217. GstCaps *outcaps);
  218. gboolean (*query) (GstBaseTransform *trans, GstPadDirection direction,
  219. GstQuery *query);
  220. /* decide allocation query for output buffers */
  221. gboolean (*decide_allocation) (GstBaseTransform *trans, GstQuery *query);
  222. gboolean (*filter_meta) (GstBaseTransform *trans, GstQuery *query,
  223. GType api, const GstStructure *params);
  224. /* propose allocation query parameters for input buffers */
  225. gboolean (*propose_allocation) (GstBaseTransform *trans, GstQuery *decide_query,
  226. GstQuery *query);
  227. /* transform size */
  228. gboolean (*transform_size) (GstBaseTransform *trans,
  229. GstPadDirection direction,
  230. GstCaps *caps, gsize size,
  231. GstCaps *othercaps, gsize *othersize);
  232. gboolean (*get_unit_size) (GstBaseTransform *trans, GstCaps *caps,
  233. gsize *size);
  234. /* states */
  235. gboolean (*start) (GstBaseTransform *trans);
  236. gboolean (*stop) (GstBaseTransform *trans);
  237. /* sink and src pad event handlers */
  238. gboolean (*sink_event) (GstBaseTransform *trans, GstEvent *event);
  239. gboolean (*src_event) (GstBaseTransform *trans, GstEvent *event);
  240. GstFlowReturn (*prepare_output_buffer) (GstBaseTransform * trans,
  241. GstBuffer *input, GstBuffer **outbuf);
  242. /* metadata */
  243. gboolean (*copy_metadata) (GstBaseTransform *trans, GstBuffer *input,
  244. GstBuffer *outbuf);
  245. gboolean (*transform_meta) (GstBaseTransform *trans, GstBuffer *outbuf,
  246. GstMeta *meta, GstBuffer *inbuf);
  247. void (*before_transform) (GstBaseTransform *trans, GstBuffer *buffer);
  248. /* transform */
  249. GstFlowReturn (*transform) (GstBaseTransform *trans, GstBuffer *inbuf,
  250. GstBuffer *outbuf);
  251. GstFlowReturn (*transform_ip) (GstBaseTransform *trans, GstBuffer *buf);
  252. GstFlowReturn (*submit_input_buffer) (GstBaseTransform *trans, gboolean is_discont, GstBuffer *input);
  253. GstFlowReturn (*generate_output) (GstBaseTransform *trans, GstBuffer **outbuf);
  254. /*< private >*/
  255. gpointer _gst_reserved[GST_PADDING_LARGE - 2];
  256. };
  257. GType gst_base_transform_get_type (void);
  258. void gst_base_transform_set_passthrough (GstBaseTransform *trans,
  259. gboolean passthrough);
  260. gboolean gst_base_transform_is_passthrough (GstBaseTransform *trans);
  261. void gst_base_transform_set_in_place (GstBaseTransform *trans,
  262. gboolean in_place);
  263. gboolean gst_base_transform_is_in_place (GstBaseTransform *trans);
  264. void gst_base_transform_update_qos (GstBaseTransform *trans,
  265. gdouble proportion,
  266. GstClockTimeDiff diff,
  267. GstClockTime timestamp);
  268. void gst_base_transform_set_qos_enabled (GstBaseTransform *trans,
  269. gboolean enabled);
  270. gboolean gst_base_transform_is_qos_enabled (GstBaseTransform *trans);
  271. void gst_base_transform_set_gap_aware (GstBaseTransform *trans,
  272. gboolean gap_aware);
  273. void gst_base_transform_set_prefer_passthrough (GstBaseTransform *trans,
  274. gboolean prefer_passthrough);
  275. GstBufferPool * gst_base_transform_get_buffer_pool (GstBaseTransform *trans);
  276. void gst_base_transform_get_allocator (GstBaseTransform *trans,
  277. GstAllocator **allocator,
  278. GstAllocationParams *params);
  279. void gst_base_transform_reconfigure_sink (GstBaseTransform *trans);
  280. void gst_base_transform_reconfigure_src (GstBaseTransform *trans);
  281. gboolean gst_base_transform_update_src_caps (GstBaseTransform *trans,
  282. GstCaps *updated_caps);
  283. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  284. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstBaseTransform, gst_object_unref)
  285. #endif
  286. G_END_DECLS
  287. #endif /* __GST_BASE_TRANSFORM_H__ */