gstvideoencoder.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /* GStreamer
  2. * Copyright (C) 2008 David Schleef <ds@schleef.org>
  3. * Copyright (C) 2011 Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>.
  4. * Copyright (C) 2011 Nokia Corporation. All rights reserved.
  5. * Contact: Stefan Kost <stefan.kost@nokia.com>
  6. * Copyright (C) 2012 Collabora Ltd.
  7. * Author : Edward Hervey <edward@collabora.com>
  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. * Deprecated: since 1.8. use gst_video_encoder_finish_frame with
  79. * a %NULL frame->output_buffer to drop the frame instead.
  80. */
  81. #ifndef GST_DISABLE_DEPRECATED
  82. #define GST_VIDEO_ENCODER_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS_1
  83. #endif
  84. /**
  85. * GST_VIDEO_ENCODER_INPUT_SEGMENT:
  86. * @obj: base parse instance
  87. *
  88. * Gives the segment of the element.
  89. */
  90. #define GST_VIDEO_ENCODER_INPUT_SEGMENT(obj) (GST_VIDEO_ENCODER_CAST (obj)->input_segment)
  91. /**
  92. * GST_VIDEO_ENCODER_OUTPUT_SEGMENT:
  93. * @obj: base parse instance
  94. *
  95. * Gives the segment of the element.
  96. */
  97. #define GST_VIDEO_ENCODER_OUTPUT_SEGMENT(obj) (GST_VIDEO_ENCODER_CAST (obj)->output_segment)
  98. /**
  99. * GST_VIDEO_ENCODER_STREAM_LOCK:
  100. * @encoder: video encoder instance
  101. *
  102. * Obtain a lock to protect the encoder function from concurrent access.
  103. */
  104. #define GST_VIDEO_ENCODER_STREAM_LOCK(encoder) g_rec_mutex_lock (&GST_VIDEO_ENCODER (encoder)->stream_lock)
  105. /**
  106. * GST_VIDEO_ENCODER_STREAM_UNLOCK:
  107. * @encoder: video encoder instance
  108. *
  109. * Release the lock that protects the encoder function from concurrent access.
  110. */
  111. #define GST_VIDEO_ENCODER_STREAM_UNLOCK(encoder) g_rec_mutex_unlock (&GST_VIDEO_ENCODER (encoder)->stream_lock)
  112. typedef struct _GstVideoEncoder GstVideoEncoder;
  113. typedef struct _GstVideoEncoderPrivate GstVideoEncoderPrivate;
  114. typedef struct _GstVideoEncoderClass GstVideoEncoderClass;
  115. /**
  116. * GstVideoEncoder:
  117. *
  118. * The opaque #GstVideoEncoder data structure.
  119. */
  120. struct _GstVideoEncoder
  121. {
  122. /*< private >*/
  123. GstElement element;
  124. /*< protected >*/
  125. GstPad *sinkpad;
  126. GstPad *srcpad;
  127. /* protects all data processing, i.e. is locked
  128. * in the chain function, finish_frame and when
  129. * processing serialized events */
  130. GRecMutex stream_lock;
  131. /* MT-protected (with STREAM_LOCK) */
  132. GstSegment input_segment;
  133. GstSegment output_segment;
  134. /*< private >*/
  135. GstVideoEncoderPrivate *priv;
  136. void *padding[GST_PADDING_LARGE];
  137. };
  138. /**
  139. * GstVideoEncoderClass:
  140. * @open: Optional.
  141. * Called when the element changes to GST_STATE_READY.
  142. * Allows opening external resources.
  143. * @close: Optional.
  144. * Called when the element changes to GST_STATE_NULL.
  145. * Allows closing external resources.
  146. * @start: Optional.
  147. * Called when the element starts processing.
  148. * Allows opening external resources.
  149. * @stop: Optional.
  150. * Called when the element stops processing.
  151. * Allows closing external resources.
  152. * @set_format: Optional.
  153. * Notifies subclass of incoming data format.
  154. * GstVideoCodecState fields have already been
  155. * set according to provided caps.
  156. * @handle_frame: Provides input frame to subclass.
  157. * @reset: Optional.
  158. * Allows subclass (encoder) to perform post-seek semantics reset.
  159. * Deprecated.
  160. * @finish: Optional.
  161. * Called to request subclass to dispatch any pending remaining
  162. * data (e.g. at EOS).
  163. * @pre_push: Optional.
  164. * Allows subclass to push frame downstream in whatever
  165. * shape or form it deems appropriate. If not provided,
  166. * provided encoded frame data is simply pushed downstream.
  167. * @getcaps: Optional.
  168. * Allows for a custom sink getcaps implementation (e.g.
  169. * for multichannel input specification). If not implemented,
  170. * default returns gst_video_encoder_proxy_getcaps
  171. * applied to sink template caps.
  172. * @sink_event: Optional.
  173. * Event handler on the sink pad. This function should return
  174. * TRUE if the event was handled and should be discarded
  175. * (i.e. not unref'ed).
  176. * Subclasses should chain up to the parent implementation to
  177. * invoke the default handler.
  178. * @src_event: Optional.
  179. * Event handler on the source pad. This function should return
  180. * TRUE if the event was handled and should be discarded
  181. * (i.e. not unref'ed).
  182. * Subclasses should chain up to the parent implementation to
  183. * invoke the default handler.
  184. * @negotiate: Optional.
  185. * Negotiate with downstream and configure buffer pools, etc.
  186. * Subclasses should chain up to the parent implementation to
  187. * invoke the default handler.
  188. * @decide_allocation: Optional.
  189. * Setup the allocation parameters for allocating output
  190. * buffers. The passed in query contains the result of the
  191. * downstream allocation query.
  192. * Subclasses should chain up to the parent implementation to
  193. * invoke the default handler.
  194. * @propose_allocation: Optional.
  195. * Propose buffer allocation parameters for upstream elements.
  196. * Subclasses should chain up to the parent implementation to
  197. * invoke the default handler.
  198. * @flush: Optional.
  199. * Flush all remaining data from the encoder without
  200. * pushing it downstream. Since: 1.2
  201. * @sink_query: Optional.
  202. * Query handler on the sink 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. * @src_query: Optional.
  207. * Query handler on the source pad. This function should
  208. * return TRUE if the query could be performed. Subclasses
  209. * should chain up to the parent implementation to invoke the
  210. * default handler. Since 1.4
  211. * @transform_meta: Optional. Transform the metadata on the input buffer to the
  212. * output buffer. By default this method is copies all meta without
  213. * tags and meta with only the "video" tag. subclasses can
  214. * implement this method and return %TRUE if the metadata is to be
  215. * copied. Since 1.6
  216. *
  217. * Subclasses can override any of the available virtual methods or not, as
  218. * needed. At minimum @handle_frame needs to be overridden, and @set_format
  219. * and @get_caps are likely needed as well.
  220. */
  221. struct _GstVideoEncoderClass
  222. {
  223. /*< private >*/
  224. GstElementClass element_class;
  225. /*< public >*/
  226. /* virtual methods for subclasses */
  227. gboolean (*open) (GstVideoEncoder *encoder);
  228. gboolean (*close) (GstVideoEncoder *encoder);
  229. gboolean (*start) (GstVideoEncoder *encoder);
  230. gboolean (*stop) (GstVideoEncoder *encoder);
  231. gboolean (*set_format) (GstVideoEncoder *encoder,
  232. GstVideoCodecState *state);
  233. GstFlowReturn (*handle_frame) (GstVideoEncoder *encoder,
  234. GstVideoCodecFrame *frame);
  235. gboolean (*reset) (GstVideoEncoder *encoder,
  236. gboolean hard);
  237. GstFlowReturn (*finish) (GstVideoEncoder *encoder);
  238. GstFlowReturn (*pre_push) (GstVideoEncoder *encoder,
  239. GstVideoCodecFrame *frame);
  240. GstCaps * (*getcaps) (GstVideoEncoder *enc,
  241. GstCaps *filter);
  242. gboolean (*sink_event) (GstVideoEncoder *encoder,
  243. GstEvent *event);
  244. gboolean (*src_event) (GstVideoEncoder *encoder,
  245. GstEvent *event);
  246. gboolean (*negotiate) (GstVideoEncoder *encoder);
  247. gboolean (*decide_allocation) (GstVideoEncoder *encoder, GstQuery *query);
  248. gboolean (*propose_allocation) (GstVideoEncoder * encoder,
  249. GstQuery * query);
  250. gboolean (*flush) (GstVideoEncoder *encoder);
  251. gboolean (*sink_query) (GstVideoEncoder *encoder,
  252. GstQuery *query);
  253. gboolean (*src_query) (GstVideoEncoder *encoder,
  254. GstQuery *query);
  255. gboolean (*transform_meta) (GstVideoEncoder *encoder,
  256. GstVideoCodecFrame *frame,
  257. GstMeta * meta);
  258. /*< private >*/
  259. gpointer _gst_reserved[GST_PADDING_LARGE-4];
  260. };
  261. GType gst_video_encoder_get_type (void);
  262. GstVideoCodecState* gst_video_encoder_get_output_state (GstVideoEncoder *encoder);
  263. GstVideoCodecState* gst_video_encoder_set_output_state (GstVideoEncoder * encoder,
  264. GstCaps * caps,
  265. GstVideoCodecState * reference);
  266. gboolean gst_video_encoder_negotiate (GstVideoEncoder * encoder);
  267. GstVideoCodecFrame* gst_video_encoder_get_frame (GstVideoEncoder *encoder,
  268. int frame_number);
  269. GstVideoCodecFrame* gst_video_encoder_get_oldest_frame (GstVideoEncoder *encoder);
  270. GList * gst_video_encoder_get_frames (GstVideoEncoder *encoder);
  271. GstBuffer * gst_video_encoder_allocate_output_buffer (GstVideoEncoder * encoder,
  272. gsize size);
  273. GstFlowReturn gst_video_encoder_allocate_output_frame (GstVideoEncoder *encoder,
  274. GstVideoCodecFrame *frame,
  275. gsize size);
  276. GstFlowReturn gst_video_encoder_finish_frame (GstVideoEncoder *encoder,
  277. GstVideoCodecFrame *frame);
  278. GstCaps * gst_video_encoder_proxy_getcaps (GstVideoEncoder * enc,
  279. GstCaps * caps,
  280. GstCaps * filter);
  281. void gst_video_encoder_set_latency (GstVideoEncoder *encoder,
  282. GstClockTime min_latency,
  283. GstClockTime max_latency);
  284. void gst_video_encoder_get_latency (GstVideoEncoder *encoder,
  285. GstClockTime *min_latency,
  286. GstClockTime *max_latency);
  287. void gst_video_encoder_set_headers (GstVideoEncoder *encoder,
  288. GList *headers);
  289. void gst_video_encoder_merge_tags (GstVideoEncoder *encoder,
  290. const GstTagList *tags,
  291. GstTagMergeMode mode);
  292. void gst_video_encoder_get_allocator (GstVideoEncoder *encoder,
  293. GstAllocator **allocator,
  294. GstAllocationParams *params);
  295. void gst_video_encoder_set_min_pts(GstVideoEncoder *encoder, GstClockTime min_pts);
  296. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  297. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoEncoder, gst_object_unref)
  298. #endif
  299. G_END_DECLS
  300. #endif