gstaudioencoder.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /* GStreamer
  2. * Copyright (C) 2011 Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>.
  3. * Copyright (C) 2011 Nokia Corporation. All rights reserved.
  4. * Contact: Stefan Kost <stefan.kost@nokia.com>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this library; if not, write to the
  18. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. */
  21. #ifndef __GST_AUDIO_AUDIO_H__
  22. #include <gst/audio/audio.h>
  23. #endif
  24. #ifndef __GST_AUDIO_ENCODER_H__
  25. #define __GST_AUDIO_ENCODER_H__
  26. #include <gst/gst.h>
  27. G_BEGIN_DECLS
  28. #define GST_TYPE_AUDIO_ENCODER (gst_audio_encoder_get_type())
  29. #define GST_AUDIO_ENCODER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_ENCODER,GstAudioEncoder))
  30. #define GST_AUDIO_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_ENCODER,GstAudioEncoderClass))
  31. #define GST_AUDIO_ENCODER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_AUDIO_ENCODER,GstAudioEncoderClass))
  32. #define GST_IS_AUDIO_ENCODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_ENCODER))
  33. #define GST_IS_AUDIO_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_ENCODER))
  34. #define GST_AUDIO_ENCODER_CAST(obj) ((GstAudioEncoder *)(obj))
  35. /**
  36. * GST_AUDIO_ENCODER_SINK_NAME:
  37. *
  38. * the name of the templates for the sink pad
  39. */
  40. #define GST_AUDIO_ENCODER_SINK_NAME "sink"
  41. /**
  42. * GST_AUDIO_ENCODER_SRC_NAME:
  43. *
  44. * the name of the templates for the source pad
  45. */
  46. #define GST_AUDIO_ENCODER_SRC_NAME "src"
  47. /**
  48. * GST_AUDIO_ENCODER_SRC_PAD:
  49. * @obj: audio encoder instance
  50. *
  51. * Gives the pointer to the source #GstPad object of the element.
  52. */
  53. #define GST_AUDIO_ENCODER_SRC_PAD(obj) (GST_AUDIO_ENCODER_CAST (obj)->srcpad)
  54. /**
  55. * GST_AUDIO_ENCODER_SINK_PAD:
  56. * @obj: audio encoder instance
  57. *
  58. * Gives the pointer to the sink #GstPad object of the element.
  59. */
  60. #define GST_AUDIO_ENCODER_SINK_PAD(obj) (GST_AUDIO_ENCODER_CAST (obj)->sinkpad)
  61. /**
  62. * GST_AUDIO_ENCODER_INPUT_SEGMENT:
  63. * @obj: base parse instance
  64. *
  65. * Gives the input segment of the element.
  66. */
  67. #define GST_AUDIO_ENCODER_INPUT_SEGMENT(obj) (GST_AUDIO_ENCODER_CAST (obj)->input_segment)
  68. /**
  69. * GST_AUDIO_ENCODER_OUTPUT_SEGMENT:
  70. * @obj: base parse instance
  71. *
  72. * Gives the output segment of the element.
  73. */
  74. #define GST_AUDIO_ENCODER_OUTPUT_SEGMENT(obj) (GST_AUDIO_ENCODER_CAST (obj)->output_segment)
  75. #define GST_AUDIO_ENCODER_STREAM_LOCK(enc) g_rec_mutex_lock (&GST_AUDIO_ENCODER (enc)->stream_lock)
  76. #define GST_AUDIO_ENCODER_STREAM_UNLOCK(enc) g_rec_mutex_unlock (&GST_AUDIO_ENCODER (enc)->stream_lock)
  77. typedef struct _GstAudioEncoder GstAudioEncoder;
  78. typedef struct _GstAudioEncoderClass GstAudioEncoderClass;
  79. typedef struct _GstAudioEncoderPrivate GstAudioEncoderPrivate;
  80. /**
  81. * GstAudioEncoder:
  82. *
  83. * The opaque #GstAudioEncoder data structure.
  84. */
  85. struct _GstAudioEncoder {
  86. GstElement element;
  87. /*< protected >*/
  88. /* source and sink pads */
  89. GstPad *sinkpad;
  90. GstPad *srcpad;
  91. /* protects all data processing, i.e. is locked
  92. * in the chain function, finish_frame and when
  93. * processing serialized events */
  94. GRecMutex stream_lock;
  95. /* MT-protected (with STREAM_LOCK) */
  96. GstSegment input_segment;
  97. GstSegment output_segment;
  98. /*< private >*/
  99. GstAudioEncoderPrivate *priv;
  100. gpointer _gst_reserved[GST_PADDING_LARGE];
  101. };
  102. /**
  103. * GstAudioEncoderClass:
  104. * @element_class: The parent class structure
  105. * @start: Optional.
  106. * Called when the element starts processing.
  107. * Allows opening external resources.
  108. * @stop: Optional.
  109. * Called when the element stops processing.
  110. * Allows closing external resources.
  111. * @set_format: Notifies subclass of incoming data format.
  112. * GstAudioInfo contains the format according to provided caps.
  113. * @handle_frame: Provides input samples (or NULL to clear any remaining data)
  114. * according to directions as configured by the subclass
  115. * using the API. Input data ref management is performed
  116. * by base class, subclass should not care or intervene,
  117. * and input data is only valid until next call to base class,
  118. * most notably a call to gst_audio_encoder_finish_frame().
  119. * @flush: Optional.
  120. * Instructs subclass to clear any codec caches and discard
  121. * any pending samples and not yet returned encoded data.
  122. * @sink_event: Optional.
  123. * Event handler on the sink pad. Subclasses should chain up to
  124. * the parent implementation to invoke the default handler.
  125. * @src_event: Optional.
  126. * Event handler on the src pad. Subclasses should chain up to
  127. * the parent implementation to invoke the default handler.
  128. * @pre_push: Optional.
  129. * Called just prior to pushing (encoded data) buffer downstream.
  130. * Subclass has full discretionary access to buffer,
  131. * and a not OK flow return will abort downstream pushing.
  132. * @getcaps: Optional.
  133. * Allows for a custom sink getcaps implementation (e.g.
  134. * for multichannel input specification). If not implemented,
  135. * default returns gst_audio_encoder_proxy_getcaps
  136. * applied to sink template caps.
  137. * @open: Optional.
  138. * Called when the element changes to GST_STATE_READY.
  139. * Allows opening external resources.
  140. * @close: Optional.
  141. * Called when the element changes to GST_STATE_NULL.
  142. * Allows closing external resources.
  143. * @negotiate: Optional.
  144. * Negotiate with downstream and configure buffer pools, etc.
  145. * Subclasses should chain up to the parent implementation to
  146. * invoke the default handler.
  147. * @decide_allocation: Optional.
  148. * Setup the allocation parameters for allocating output
  149. * buffers. The passed in query contains the result of the
  150. * downstream allocation query.
  151. * Subclasses should chain up to the parent implementation to
  152. * invoke the default handler.
  153. * @propose_allocation: Optional.
  154. * Propose buffer allocation parameters for upstream elements.
  155. * Subclasses should chain up to the parent implementation to
  156. * invoke the default handler.
  157. * @transform_meta: Optional. Transform the metadata on the input buffer to the
  158. * output buffer. By default this method copies all meta without
  159. * tags and meta with only the "audio" tag. subclasses can
  160. * implement this method and return %TRUE if the metadata is to be
  161. * copied. Since 1.6
  162. * @sink_query: Optional.
  163. * Query handler on the sink pad. This function should
  164. * return TRUE if the query could be performed. Subclasses
  165. * should chain up to the parent implementation to invoke the
  166. * default handler. Since 1.6
  167. * @src_query: Optional.
  168. * Query handler on the source pad. This function should
  169. * return TRUE if the query could be performed. Subclasses
  170. * should chain up to the parent implementation to invoke the
  171. * default handler. Since 1.6
  172. *
  173. * Subclasses can override any of the available virtual methods or not, as
  174. * needed. At minimum @set_format and @handle_frame needs to be overridden.
  175. */
  176. struct _GstAudioEncoderClass {
  177. GstElementClass element_class;
  178. /*< public >*/
  179. /* virtual methods for subclasses */
  180. gboolean (*start) (GstAudioEncoder *enc);
  181. gboolean (*stop) (GstAudioEncoder *enc);
  182. gboolean (*set_format) (GstAudioEncoder *enc,
  183. GstAudioInfo *info);
  184. GstFlowReturn (*handle_frame) (GstAudioEncoder *enc,
  185. GstBuffer *buffer);
  186. void (*flush) (GstAudioEncoder *enc);
  187. GstFlowReturn (*pre_push) (GstAudioEncoder *enc,
  188. GstBuffer **buffer);
  189. gboolean (*sink_event) (GstAudioEncoder *enc,
  190. GstEvent *event);
  191. gboolean (*src_event) (GstAudioEncoder *enc,
  192. GstEvent *event);
  193. GstCaps * (*getcaps) (GstAudioEncoder *enc, GstCaps *filter);
  194. gboolean (*open) (GstAudioEncoder *enc);
  195. gboolean (*close) (GstAudioEncoder *enc);
  196. gboolean (*negotiate) (GstAudioEncoder *enc);
  197. gboolean (*decide_allocation) (GstAudioEncoder *enc, GstQuery *query);
  198. gboolean (*propose_allocation) (GstAudioEncoder * enc,
  199. GstQuery * query);
  200. gboolean (*transform_meta) (GstAudioEncoder *enc, GstBuffer *outbuf,
  201. GstMeta *meta, GstBuffer *inbuf);
  202. gboolean (*sink_query) (GstAudioEncoder *encoder,
  203. GstQuery *query);
  204. gboolean (*src_query) (GstAudioEncoder *encoder,
  205. GstQuery *query);
  206. /*< private >*/
  207. gpointer _gst_reserved[GST_PADDING_LARGE-3];
  208. };
  209. GType gst_audio_encoder_get_type (void);
  210. GstFlowReturn gst_audio_encoder_finish_frame (GstAudioEncoder * enc,
  211. GstBuffer * buffer,
  212. gint samples);
  213. GstCaps * gst_audio_encoder_proxy_getcaps (GstAudioEncoder * enc,
  214. GstCaps * caps,
  215. GstCaps * filter);
  216. gboolean gst_audio_encoder_set_output_format (GstAudioEncoder * enc,
  217. GstCaps * caps);
  218. gboolean gst_audio_encoder_negotiate (GstAudioEncoder * enc);
  219. GstBuffer * gst_audio_encoder_allocate_output_buffer (GstAudioEncoder * enc,
  220. gsize size);
  221. /* context parameters */
  222. GstAudioInfo * gst_audio_encoder_get_audio_info (GstAudioEncoder * enc);
  223. gint gst_audio_encoder_get_frame_samples_min (GstAudioEncoder * enc);
  224. void gst_audio_encoder_set_frame_samples_min (GstAudioEncoder * enc, gint num);
  225. gint gst_audio_encoder_get_frame_samples_max (GstAudioEncoder * enc);
  226. void gst_audio_encoder_set_frame_samples_max (GstAudioEncoder * enc, gint num);
  227. gint gst_audio_encoder_get_frame_max (GstAudioEncoder * enc);
  228. void gst_audio_encoder_set_frame_max (GstAudioEncoder * enc, gint num);
  229. gint gst_audio_encoder_get_lookahead (GstAudioEncoder * enc);
  230. void gst_audio_encoder_set_lookahead (GstAudioEncoder * enc, gint num);
  231. void gst_audio_encoder_get_latency (GstAudioEncoder * enc,
  232. GstClockTime * min,
  233. GstClockTime * max);
  234. void gst_audio_encoder_set_latency (GstAudioEncoder * enc,
  235. GstClockTime min,
  236. GstClockTime max);
  237. void gst_audio_encoder_set_headers (GstAudioEncoder * enc,
  238. GList * headers);
  239. /* object properties */
  240. void gst_audio_encoder_set_mark_granule (GstAudioEncoder * enc,
  241. gboolean enabled);
  242. gboolean gst_audio_encoder_get_mark_granule (GstAudioEncoder * enc);
  243. void gst_audio_encoder_set_perfect_timestamp (GstAudioEncoder * enc,
  244. gboolean enabled);
  245. gboolean gst_audio_encoder_get_perfect_timestamp (GstAudioEncoder * enc);
  246. void gst_audio_encoder_set_hard_resync (GstAudioEncoder * enc,
  247. gboolean enabled);
  248. gboolean gst_audio_encoder_get_hard_resync (GstAudioEncoder * enc);
  249. void gst_audio_encoder_set_tolerance (GstAudioEncoder * enc,
  250. GstClockTime tolerance);
  251. GstClockTime gst_audio_encoder_get_tolerance (GstAudioEncoder * enc);
  252. void gst_audio_encoder_set_hard_min (GstAudioEncoder * enc,
  253. gboolean enabled);
  254. gboolean gst_audio_encoder_get_hard_min (GstAudioEncoder * enc);
  255. void gst_audio_encoder_set_drainable (GstAudioEncoder * enc,
  256. gboolean enabled);
  257. gboolean gst_audio_encoder_get_drainable (GstAudioEncoder * enc);
  258. void gst_audio_encoder_get_allocator (GstAudioEncoder * enc,
  259. GstAllocator ** allocator,
  260. GstAllocationParams * params);
  261. void gst_audio_encoder_merge_tags (GstAudioEncoder * enc,
  262. const GstTagList * tags, GstTagMergeMode mode);
  263. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  264. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstAudioEncoder, gst_object_unref)
  265. #endif
  266. G_END_DECLS
  267. #endif /* __GST_AUDIO_ENCODER_H__ */