gstvideoencoder.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /* GStreamer
  2. * Copyright (C) 2008 David Schleef <[email protected]>
  3. * Copyright (C) 2011 Mark Nauwelaerts <[email protected]>.
  4. * Copyright (C) 2011 Nokia Corporation. All rights reserved.
  5. * Contact: Stefan Kost <[email protected]>
  6. * Copyright (C) 2012 Collabora Ltd.
  7. * Author : Edward Hervey <[email protected]>
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Library General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Library General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Library General Public
  20. * License along with this library; if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  22. * Boston, MA 02110-1301, USA.
  23. */
  24. #ifndef _GST_VIDEO_ENCODER_H_
  25. #define _GST_VIDEO_ENCODER_H_
  26. #include <gst/video/gstvideoutils.h>
  27. G_BEGIN_DECLS
  28. #define GST_TYPE_VIDEO_ENCODER \
  29. (gst_video_encoder_get_type())
  30. #define GST_VIDEO_ENCODER(obj) \
  31. (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_ENCODER,GstVideoEncoder))
  32. #define GST_VIDEO_ENCODER_CLASS(klass) \
  33. (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_ENCODER,GstVideoEncoderClass))
  34. #define GST_VIDEO_ENCODER_GET_CLASS(obj) \
  35. (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_VIDEO_ENCODER,GstVideoEncoderClass))
  36. #define GST_IS_VIDEO_ENCODER(obj) \
  37. (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_ENCODER))
  38. #define GST_IS_VIDEO_ENCODER_CLASS(obj) \
  39. (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_ENCODER))
  40. #define GST_VIDEO_ENCODER_CAST(enc) ((GstVideoEncoder*)enc)
  41. /**
  42. * GST_VIDEO_ENCODER_SINK_NAME:
  43. *
  44. * The name of the templates for the sink pad.
  45. */
  46. #define GST_VIDEO_ENCODER_SINK_NAME "sink"
  47. /**
  48. * GST_VIDEO_ENCODER_SRC_NAME:
  49. *
  50. * The name of the templates for the source pad.
  51. */
  52. #define GST_VIDEO_ENCODER_SRC_NAME "src"
  53. /**
  54. * GST_VIDEO_ENCODER_SRC_PAD:
  55. * @obj: a #GstVideoEncoder
  56. *
  57. * Gives the pointer to the source #GstPad object of the element.
  58. */
  59. #define GST_VIDEO_ENCODER_SRC_PAD(obj) (((GstVideoEncoder *) (obj))->srcpad)
  60. /**
  61. * GST_VIDEO_ENCODER_SINK_PAD:
  62. * @obj: a #GstVideoEncoder
  63. *
  64. * Gives the pointer to the sink #GstPad object of the element.
  65. */
  66. #define GST_VIDEO_ENCODER_SINK_PAD(obj) (((GstVideoEncoder *) (obj))->sinkpad)
  67. /**
  68. * GST_VIDEO_ENCODER_FLOW_NEED_DATA:
  69. *
  70. * Returned while parsing to indicate more data is needed.
  71. **/
  72. #define GST_VIDEO_ENCODER_FLOW_NEED_DATA GST_FLOW_CUSTOM_SUCCESS
  73. /**
  74. * GST_VIDEO_ENCODER_FLOW_DROPPED:
  75. *
  76. * Returned when the event/buffer should be dropped.
  77. */
  78. #define GST_VIDEO_ENCODER_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS_1
  79. /**
  80. * GST_VIDEO_ENCODER_INPUT_SEGMENT:
  81. * @obj: base parse instance
  82. *
  83. * Gives the segment of the element.
  84. */
  85. #define GST_VIDEO_ENCODER_INPUT_SEGMENT(obj) (GST_VIDEO_ENCODER_CAST (obj)->input_segment)
  86. /**
  87. * GST_VIDEO_ENCODER_OUTPUT_SEGMENT:
  88. * @obj: base parse instance
  89. *
  90. * Gives the segment of the element.
  91. */
  92. #define GST_VIDEO_ENCODER_OUTPUT_SEGMENT(obj) (GST_VIDEO_ENCODER_CAST (obj)->output_segment)
  93. /**
  94. * GST_VIDEO_ENCODER_STREAM_LOCK:
  95. * @encoder: video encoder instance
  96. *
  97. * Obtain a lock to protect the encoder function from concurrent access.
  98. */
  99. #define GST_VIDEO_ENCODER_STREAM_LOCK(encoder) g_rec_mutex_lock (&GST_VIDEO_ENCODER (encoder)->stream_lock)
  100. /**
  101. * GST_VIDEO_ENCODER_STREAM_UNLOCK:
  102. * @encoder: video encoder instance
  103. *
  104. * Release the lock that protects the encoder function from concurrent access.
  105. */
  106. #define GST_VIDEO_ENCODER_STREAM_UNLOCK(encoder) g_rec_mutex_unlock (&GST_VIDEO_ENCODER (encoder)->stream_lock)
  107. typedef struct _GstVideoEncoder GstVideoEncoder;
  108. typedef struct _GstVideoEncoderPrivate GstVideoEncoderPrivate;
  109. typedef struct _GstVideoEncoderClass GstVideoEncoderClass;
  110. /**
  111. * GstVideoEncoder:
  112. *
  113. * The opaque #GstVideoEncoder data structure.
  114. */
  115. struct _GstVideoEncoder
  116. {
  117. /*< private >*/
  118. GstElement element;
  119. /*< protected >*/
  120. GstPad *sinkpad;
  121. GstPad *srcpad;
  122. /* protects all data processing, i.e. is locked
  123. * in the chain function, finish_frame and when
  124. * processing serialized events */
  125. GRecMutex stream_lock;
  126. /* MT-protected (with STREAM_LOCK) */
  127. GstSegment input_segment;
  128. GstSegment output_segment;
  129. /*< private >*/
  130. GstVideoEncoderPrivate *priv;
  131. void *padding[GST_PADDING_LARGE];
  132. };
  133. /**
  134. * GstVideoEncoderClass:
  135. * @open: Optional.
  136. * Called when the element changes to GST_STATE_READY.
  137. * Allows opening external resources.
  138. * @close: Optional.
  139. * Called when the element changes to GST_STATE_NULL.
  140. * Allows closing external resources.
  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. * @set_format: Optional.
  148. * Notifies subclass of incoming data format.
  149. * GstVideoCodecState fields have already been
  150. * set according to provided caps.
  151. * @handle_frame: Provides input frame to subclass.
  152. * @reset: Optional.
  153. * Allows subclass (encoder) to perform post-seek semantics reset.
  154. * Deprecated.
  155. * @finish: Optional.
  156. * Called to request subclass to dispatch any pending remaining
  157. * data (e.g. at EOS).
  158. * @pre_push: Optional.
  159. * Allows subclass to push frame downstream in whatever
  160. * shape or form it deems appropriate. If not provided,
  161. * provided encoded frame data is simply pushed downstream.
  162. * @getcaps: Optional.
  163. * Allows for a custom sink getcaps implementation (e.g.
  164. * for multichannel input specification). If not implemented,
  165. * default returns gst_video_encoder_proxy_getcaps
  166. * applied to sink template caps.
  167. * @sink_event: Optional.
  168. * Event handler on the sink pad. This function should return
  169. * TRUE if the event was handled and should be discarded
  170. * (i.e. not unref'ed).
  171. * Subclasses should chain up to the parent implementation to
  172. * invoke the default handler.
  173. * @src_event: Optional.
  174. * Event handler on the source pad. This function should return
  175. * TRUE if the event was handled and should be discarded
  176. * (i.e. not unref'ed).
  177. * Subclasses should chain up to the parent implementation to
  178. * invoke the default handler.
  179. * @negotiate: Optional.
  180. * Negotiate with downstream and configure buffer pools, etc.
  181. * Subclasses should chain up to the parent implementation to
  182. * invoke the default handler.
  183. * @decide_allocation: Optional.
  184. * Setup the allocation parameters for allocating output
  185. * buffers. The passed in query contains the result of the
  186. * downstream allocation query.
  187. * Subclasses should chain up to the parent implementation to
  188. * invoke the default handler.
  189. * @propose_allocation: Optional.
  190. * Propose buffer allocation parameters for upstream elements.
  191. * Subclasses should chain up to the parent implementation to
  192. * invoke the default handler.
  193. * @flush: Optional.
  194. * Flush all remaining data from the encoder without
  195. * pushing it downstream. Since: 1.2
  196. * @sink_query: Optional.
  197. * Query handler on the sink pad. This function should
  198. * return TRUE if the query could be performed. Subclasses
  199. * should chain up to the parent implementation to invoke the
  200. * default handler. Since 1.4
  201. * @src_query: Optional.
  202. * Query handler on the source pad. This function should
  203. * return TRUE if the query could be performed. Subclasses
  204. * should chain up to the parent implementation to invoke the
  205. * default handler. Since 1.4
  206. *
  207. * Subclasses can override any of the available virtual methods or not, as
  208. * needed. At minimum @handle_frame needs to be overridden, and @set_format
  209. * and @get_caps are likely needed as well.
  210. */
  211. struct _GstVideoEncoderClass
  212. {
  213. /*< private >*/
  214. GstElementClass element_class;
  215. /*< public >*/
  216. /* virtual methods for subclasses */
  217. gboolean (*open) (GstVideoEncoder *encoder);
  218. gboolean (*close) (GstVideoEncoder *encoder);
  219. gboolean (*start) (GstVideoEncoder *encoder);
  220. gboolean (*stop) (GstVideoEncoder *encoder);
  221. gboolean (*set_format) (GstVideoEncoder *encoder,
  222. GstVideoCodecState *state);
  223. GstFlowReturn (*handle_frame) (GstVideoEncoder *encoder,
  224. GstVideoCodecFrame *frame);
  225. gboolean (*reset) (GstVideoEncoder *encoder,
  226. gboolean hard);
  227. GstFlowReturn (*finish) (GstVideoEncoder *encoder);
  228. GstFlowReturn (*pre_push) (GstVideoEncoder *encoder,
  229. GstVideoCodecFrame *frame);
  230. GstCaps * (*getcaps) (GstVideoEncoder *enc,
  231. GstCaps *filter);
  232. gboolean (*sink_event) (GstVideoEncoder *encoder,
  233. GstEvent *event);
  234. gboolean (*src_event) (GstVideoEncoder *encoder,
  235. GstEvent *event);
  236. gboolean (*negotiate) (GstVideoEncoder *encoder);
  237. gboolean (*decide_allocation) (GstVideoEncoder *encoder, GstQuery *query);
  238. gboolean (*propose_allocation) (GstVideoEncoder * encoder,
  239. GstQuery * query);
  240. gboolean (*flush) (GstVideoEncoder *encoder);
  241. gboolean (*sink_query) (GstVideoEncoder *encoder,
  242. GstQuery *query);
  243. gboolean (*src_query) (GstVideoEncoder *encoder,
  244. GstQuery *query);
  245. /*< private >*/
  246. gpointer _gst_reserved[GST_PADDING_LARGE-3];
  247. };
  248. GType gst_video_encoder_get_type (void);
  249. GstVideoCodecState* gst_video_encoder_get_output_state (GstVideoEncoder *encoder);
  250. GstVideoCodecState* gst_video_encoder_set_output_state (GstVideoEncoder * encoder,
  251. GstCaps * caps,
  252. GstVideoCodecState * reference);
  253. gboolean gst_video_encoder_negotiate (GstVideoEncoder * encoder);
  254. GstVideoCodecFrame* gst_video_encoder_get_frame (GstVideoEncoder *encoder,
  255. int frame_number);
  256. GstVideoCodecFrame* gst_video_encoder_get_oldest_frame (GstVideoEncoder *encoder);
  257. GList * gst_video_encoder_get_frames (GstVideoEncoder *encoder);
  258. GstBuffer * gst_video_encoder_allocate_output_buffer (GstVideoEncoder * encoder,
  259. gsize size);
  260. GstFlowReturn gst_video_encoder_allocate_output_frame (GstVideoEncoder *encoder,
  261. GstVideoCodecFrame *frame,
  262. gsize size);
  263. GstFlowReturn gst_video_encoder_finish_frame (GstVideoEncoder *encoder,
  264. GstVideoCodecFrame *frame);
  265. GstCaps * gst_video_encoder_proxy_getcaps (GstVideoEncoder * enc,
  266. GstCaps * caps,
  267. GstCaps * filter);
  268. void gst_video_encoder_set_latency (GstVideoEncoder *encoder,
  269. GstClockTime min_latency,
  270. GstClockTime max_latency);
  271. void gst_video_encoder_get_latency (GstVideoEncoder *encoder,
  272. GstClockTime *min_latency,
  273. GstClockTime *max_latency);
  274. void gst_video_encoder_set_headers (GstVideoEncoder *encoder,
  275. GList *headers);
  276. void gst_video_encoder_merge_tags (GstVideoEncoder *encoder,
  277. const GstTagList *tags,
  278. GstTagMergeMode mode);
  279. void gst_video_encoder_get_allocator (GstVideoEncoder *encoder,
  280. GstAllocator **allocator,
  281. GstAllocationParams *params);
  282. G_END_DECLS
  283. #endif