gstvideoutils.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /* GStreamer
  2. * Copyright (C) 2008 David Schleef <[email protected]>
  3. * Copyright (C) 2012 Collabora Ltd.
  4. * Author : Edward Hervey <[email protected]>
  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_VIDEO_H__
  22. #include <gst/video/video.h>
  23. #endif
  24. #ifndef _GST_VIDEO_UTILS_H_
  25. #define _GST_VIDEO_UTILS_H_
  26. #include <gst/gst.h>
  27. G_BEGIN_DECLS
  28. #define GST_TYPE_VIDEO_CODEC_STATE \
  29. (gst_video_codec_state_get_type())
  30. #define GST_TYPE_VIDEO_CODEC_FRAME \
  31. (gst_video_codec_frame_get_type())
  32. typedef struct _GstVideoCodecState GstVideoCodecState;
  33. typedef struct _GstVideoCodecFrame GstVideoCodecFrame;
  34. /**
  35. * GstVideoCodecState:
  36. * @info: The #GstVideoInfo describing the stream
  37. * @caps: The #GstCaps
  38. * @codec_data: a #GstBuffer corresponding to the
  39. * 'codec_data' field of a stream, or NULL.
  40. *
  41. * Structure representing the state of an incoming or outgoing video
  42. * stream for encoders and decoders.
  43. *
  44. * Decoders and encoders will receive such a state through their
  45. * respective @set_format vmethods.
  46. *
  47. * Decoders and encoders can set the downstream state, by using the
  48. * @gst_video_decoder_set_output_state() or
  49. * @gst_video_encoder_set_output_state() methods.
  50. */
  51. struct _GstVideoCodecState
  52. {
  53. /*< private >*/
  54. gint ref_count;
  55. /*< public >*/
  56. GstVideoInfo info;
  57. GstCaps *caps;
  58. GstBuffer *codec_data;
  59. /*< private >*/
  60. void *padding[GST_PADDING_LARGE];
  61. };
  62. /**
  63. * GstVideoCodecFrameFlags:
  64. * @GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY: is the frame only meant to be decoded
  65. * @GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT: is the frame a synchronization point (keyframe)
  66. * @GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME: should the output frame be made a keyframe
  67. * @GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS: should the encoder output stream headers
  68. *
  69. * Flags for #GstVideoCodecFrame
  70. */
  71. typedef enum
  72. {
  73. GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY = (1<<0),
  74. GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT = (1<<1),
  75. GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME = (1<<2),
  76. GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS = (1<<3)
  77. } GstVideoCodecFrameFlags;
  78. /**
  79. * GST_VIDEO_CODEC_FRAME_FLAGS:
  80. * @frame: a #GstVideoCodecFrame
  81. *
  82. * The entire set of flags for the @frame
  83. */
  84. #define GST_VIDEO_CODEC_FRAME_FLAGS(frame) ((frame)->flags)
  85. /**
  86. * GST_VIDEO_CODEC_FRAME_FLAG_IS_SET:
  87. * @frame: a #GstVideoCodecFrame
  88. * @flag: a flag to check for
  89. *
  90. * Checks whether the given @flag is set
  91. */
  92. #define GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame,flag) !!(GST_VIDEO_CODEC_FRAME_FLAGS(frame) & (flag))
  93. /**
  94. * GST_VIDEO_CODEC_FRAME_FLAG_SET:
  95. * @frame: a #GstVideoCodecFrame
  96. * @flag: Flag to set, can be any number of bits in guint32.
  97. *
  98. * This macro sets the given bits
  99. */
  100. #define GST_VIDEO_CODEC_FRAME_FLAG_SET(frame,flag) (GST_VIDEO_CODEC_FRAME_FLAGS(frame) |= (flag))
  101. /**
  102. * GST_VIDEO_CODEC_FRAME_FLAG_UNSET:
  103. * @frame: a #GstVideoCodecFrame
  104. * @flag: Flag to unset
  105. *
  106. * This macro usets the given bits.
  107. */
  108. #define GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame,flag) (GST_VIDEO_CODEC_FRAME_FLAGS(frame) &= ~(flag))
  109. /**
  110. * GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY:
  111. * @frame: a #GstVideoCodecFrame
  112. *
  113. * Tests if the buffer should only be decoded but not sent downstream.
  114. */
  115. #define GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY(frame) (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY))
  116. /**
  117. * GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY:
  118. * @frame: a #GstVideoCodecFrame
  119. *
  120. * Sets the buffer to not be sent downstream.
  121. *
  122. * Decoder implementation can use this if they have frames that
  123. * are not meant to be displayed.
  124. *
  125. * Encoder implementation can safely ignore this field.
  126. */
  127. #define GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY(frame) (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY))
  128. /**
  129. * GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT:
  130. * @frame: a #GstVideoCodecFrame
  131. *
  132. * Tests if the frame is a synchronization point (like a keyframe).
  133. *
  134. * Decoder implementations can use this to detect keyframes.
  135. */
  136. #define GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT(frame) (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT))
  137. /**
  138. * GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT:
  139. * @frame: a #GstVideoCodecFrame
  140. *
  141. * Sets the frame to be a synchronization point (like a keyframe).
  142. *
  143. * Encoder implementations should set this accordingly.
  144. *
  145. * Decoder implementing parsing features should set this when they
  146. * detect such a synchronization point.
  147. */
  148. #define GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT(frame) (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT))
  149. #define GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT(frame) (GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame, GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT))
  150. /**
  151. * GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME:
  152. * @frame: a #GstVideoCodecFrame
  153. *
  154. * Tests if the frame must be encoded as a keyframe. Applies only to
  155. * frames provided to encoders. Decoders can safely ignore this field.
  156. */
  157. #define GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME(frame) (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME))
  158. #define GST_VIDEO_CODEC_FRAME_SET_FORCE_KEYFRAME(frame) (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME))
  159. #define GST_VIDEO_CODEC_FRAME_UNSET_FORCE_KEYFRAME(frame) (GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME))
  160. /**
  161. * GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME_HEADERS:
  162. * @frame: a #GstVideoCodecFrame
  163. *
  164. * Tests if encoder should output stream headers before outputting the
  165. * resulting encoded buffer for the given frame.
  166. *
  167. * Applies only to frames provided to encoders. Decoders can safely
  168. * ignore this field.
  169. */
  170. #define GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME_HEADERS(frame) (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS))
  171. #define GST_VIDEO_CODEC_FRAME_SET_FORCE_KEYFRAME_HEADERS(frame) (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS))
  172. #define GST_VIDEO_CODEC_FRAME_UNSET_FORCE_KEYFRAME_HEADERS(frame) (GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS))
  173. /**
  174. * GstVideoCodecFrame:
  175. * @pts: Presentation timestamp
  176. * @dts: Decoding timestamp
  177. * @duration: Duration of the frame
  178. * @system_frame_number: Unique identifier for the frame. Use this if you need
  179. * to get hold of the frame later (like when data is being decoded).
  180. * Typical usage in decoders is to set this on the opaque value provided
  181. * to the library and get back the frame using gst_video_decoder_get_frame()
  182. * @distance_from_sync: Distance in frames from the last synchronization point.
  183. * @input_buffer: the input #GstBuffer that created this frame. The buffer is owned
  184. * by the frame and references to the frame instead of the buffer should
  185. * @output_buffer: the output #GstBuffer. Implementations should set this either
  186. * directly, or by using the
  187. * @gst_video_decoder_allocate_output_frame() or
  188. * @gst_video_decoder_allocate_output_buffer() methods. The buffer is
  189. * owned by the frame and references to the frame instead of the
  190. * buffer should be kept.
  191. * @deadline: Running time when the frame will be used.
  192. * @events: Events that will be pushed downstream before this frame is pushed.
  193. *
  194. * A #GstVideoCodecFrame represents a video frame both in raw and
  195. * encoded form.
  196. */
  197. struct _GstVideoCodecFrame
  198. {
  199. /*< private >*/
  200. gint ref_count;
  201. guint32 flags;
  202. /*< public >*/
  203. guint32 system_frame_number; /* ED */
  204. guint32 decode_frame_number; /* ED */
  205. guint32 presentation_frame_number; /* ED */
  206. GstClockTime dts; /* ED */
  207. GstClockTime pts; /* ED */
  208. GstClockTime duration; /* ED */
  209. int distance_from_sync; /* ED */
  210. GstBuffer *input_buffer; /* ED */
  211. GstBuffer *output_buffer; /* ED */
  212. GstClockTime deadline; /* D */
  213. /*< private >*/
  214. /* Events that should be pushed downstream *before*
  215. * the next output_buffer */
  216. GList *events; /* ED */
  217. gpointer user_data;
  218. GDestroyNotify user_data_destroy_notify;
  219. union {
  220. struct {
  221. GstClockTime ts;
  222. GstClockTime ts2;
  223. } ABI;
  224. void *padding[GST_PADDING_LARGE];
  225. } abidata;
  226. };
  227. /* GstVideoCodecState */
  228. GType gst_video_codec_state_get_type (void);
  229. GstVideoCodecState *gst_video_codec_state_ref (GstVideoCodecState * state);
  230. void gst_video_codec_state_unref (GstVideoCodecState * state);
  231. /* GstVideoCodecFrame */
  232. GType gst_video_codec_frame_get_type (void);
  233. GstVideoCodecFrame *gst_video_codec_frame_ref (GstVideoCodecFrame * frame);
  234. void gst_video_codec_frame_unref (GstVideoCodecFrame * frame);
  235. void gst_video_codec_frame_set_user_data (GstVideoCodecFrame *frame,
  236. gpointer user_data,
  237. GDestroyNotify notify);
  238. gpointer gst_video_codec_frame_get_user_data (GstVideoCodecFrame *frame);
  239. G_END_DECLS
  240. #endif