video-info.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /* GStreamer
  2. * Copyright (C) <2011> Wim Taymans <wim.taymans@gmail.com>
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef __GST_VIDEO_INFO_H__
  20. #define __GST_VIDEO_INFO_H__
  21. #include <gst/gst.h>
  22. #include <gst/video/video-format.h>
  23. #include <gst/video/video-color.h>
  24. G_BEGIN_DECLS
  25. #include <gst/video/video-enumtypes.h>
  26. typedef struct _GstVideoInfo GstVideoInfo;
  27. /**
  28. * GstVideoInterlaceMode:
  29. * @GST_VIDEO_INTERLACE_MODE_PROGRESSIVE: all frames are progressive
  30. * @GST_VIDEO_INTERLACE_MODE_INTERLEAVED: 2 fields are interleaved in one video
  31. * frame. Extra buffer flags describe the field order.
  32. * @GST_VIDEO_INTERLACE_MODE_MIXED: frames contains both interlaced and
  33. * progressive video, the buffer flags describe the frame and fields.
  34. * @GST_VIDEO_INTERLACE_MODE_FIELDS: 2 fields are stored in one buffer, use the
  35. * frame ID to get access to the required field. For multiview (the
  36. * 'views' property > 1) the fields of view N can be found at frame ID
  37. * (N * 2) and (N * 2) + 1.
  38. * Each field has only half the amount of lines as noted in the
  39. * height property. This mode requires multiple GstVideoMeta metadata
  40. * to describe the fields.
  41. *
  42. * The possible values of the #GstVideoInterlaceMode describing the interlace
  43. * mode of the stream.
  44. */
  45. typedef enum {
  46. GST_VIDEO_INTERLACE_MODE_PROGRESSIVE = 0,
  47. GST_VIDEO_INTERLACE_MODE_INTERLEAVED,
  48. GST_VIDEO_INTERLACE_MODE_MIXED,
  49. GST_VIDEO_INTERLACE_MODE_FIELDS
  50. } GstVideoInterlaceMode;
  51. const gchar * gst_video_interlace_mode_to_string (GstVideoInterlaceMode mode);
  52. GstVideoInterlaceMode gst_video_interlace_mode_from_string (const gchar * mode);
  53. /**
  54. * GstVideoMultiviewMode:
  55. * @GST_VIDEO_MULTIVIEW_MODE_NONE: A special value indicating
  56. * no multiview information. Used in GstVideoInfo and other places to
  57. * indicate that no specific multiview handling has been requested or
  58. * provided. This value is never carried on caps.
  59. * @GST_VIDEO_MULTIVIEW_MODE_MONO: All frames are monoscopic.
  60. * @GST_VIDEO_MULTIVIEW_MODE_LEFT: All frames represent a left-eye view.
  61. * @GST_VIDEO_MULTIVIEW_MODE_RIGHT: All frames represent a right-eye view.
  62. * @GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE: Left and right eye views are
  63. * provided in the left and right half of the frame respectively.
  64. * @GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE_QUINCUNX: Left and right eye
  65. * views are provided in the left and right half of the frame, but
  66. * have been sampled using quincunx method, with half-pixel offset
  67. * between the 2 views.
  68. * @GST_VIDEO_MULTIVIEW_MODE_COLUMN_INTERLEAVED: Alternating vertical
  69. * columns of pixels represent the left and right eye view respectively.
  70. * @GST_VIDEO_MULTIVIEW_MODE_ROW_INTERLEAVED: Alternating horizontal
  71. * rows of pixels represent the left and right eye view respectively.
  72. * @GST_VIDEO_MULTIVIEW_MODE_TOP_BOTTOM: The top half of the frame
  73. * contains the left eye, and the bottom half the right eye.
  74. * @GST_VIDEO_MULTIVIEW_MODE_CHECKERBOARD: Pixels are arranged with
  75. * alternating pixels representing left and right eye views in a
  76. * checkerboard fashion.
  77. * @GST_VIDEO_MULTIVIEW_MODE_FRAME_BY_FRAME: Left and right eye views
  78. * are provided in separate frames alternately.
  79. * @GST_VIDEO_MULTIVIEW_MODE_MULTIVIEW_FRAME_BY_FRAME: Multiple
  80. * independent views are provided in separate frames in sequence.
  81. * This method only applies to raw video buffers at the moment.
  82. * Specific view identification is via the #GstVideoMultiviewMeta
  83. * and #GstVideoMeta(s) on raw video buffers.
  84. * @GST_VIDEO_MULTIVIEW_MODE_SEPARATED: Multiple views are
  85. * provided as separate #GstMemory framebuffers attached to each
  86. * #GstBuffer, described by the #GstVideoMultiviewMeta
  87. * and #GstVideoMeta(s)
  88. *
  89. * All possible stereoscopic 3D and multiview representations.
  90. * In conjunction with #GstVideoMultiviewFlags, describes how
  91. * multiview content is being transported in the stream.
  92. */
  93. typedef enum {
  94. GST_VIDEO_MULTIVIEW_MODE_NONE = -1,
  95. GST_VIDEO_MULTIVIEW_MODE_MONO = 0,
  96. /* Single view modes */
  97. GST_VIDEO_MULTIVIEW_MODE_LEFT,
  98. GST_VIDEO_MULTIVIEW_MODE_RIGHT,
  99. /* Stereo view modes */
  100. GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE,
  101. GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE_QUINCUNX,
  102. GST_VIDEO_MULTIVIEW_MODE_COLUMN_INTERLEAVED,
  103. GST_VIDEO_MULTIVIEW_MODE_ROW_INTERLEAVED,
  104. GST_VIDEO_MULTIVIEW_MODE_TOP_BOTTOM,
  105. GST_VIDEO_MULTIVIEW_MODE_CHECKERBOARD,
  106. /* Padding for new frame packing modes */
  107. GST_VIDEO_MULTIVIEW_MODE_FRAME_BY_FRAME = 32,
  108. /* Multivew mode(s) */
  109. GST_VIDEO_MULTIVIEW_MODE_MULTIVIEW_FRAME_BY_FRAME,
  110. GST_VIDEO_MULTIVIEW_MODE_SEPARATED
  111. /* future expansion for annotated modes */
  112. } GstVideoMultiviewMode;
  113. /**
  114. * GstVideoMultiviewFramePacking:
  115. * @GST_VIDEO_MULTIVIEW_FRAME_PACKING_NONE: A special value indicating
  116. * no frame packing info.
  117. * @GST_VIDEO_MULTIVIEW_FRAME_PACKING_MONO: All frames are monoscopic.
  118. * @GST_VIDEO_MULTIVIEW_FRAME_PACKING_LEFT: All frames represent a left-eye view.
  119. * @GST_VIDEO_MULTIVIEW_FRAME_PACKING_RIGHT: All frames represent a right-eye view.
  120. * @GST_VIDEO_MULTIVIEW_FRAME_PACKING_SIDE_BY_SIDE: Left and right eye views are
  121. * provided in the left and right half of the frame respectively.
  122. * @GST_VIDEO_MULTIVIEW_FRAME_PACKING_SIDE_BY_SIDE_QUINCUNX: Left and right eye
  123. * views are provided in the left and right half of the frame, but
  124. * have been sampled using quincunx method, with half-pixel offset
  125. * between the 2 views.
  126. * @GST_VIDEO_MULTIVIEW_FRAME_PACKING_COLUMN_INTERLEAVED: Alternating vertical
  127. * columns of pixels represent the left and right eye view respectively.
  128. * @GST_VIDEO_MULTIVIEW_FRAME_PACKING_ROW_INTERLEAVED: Alternating horizontal
  129. * rows of pixels represent the left and right eye view respectively.
  130. * @GST_VIDEO_MULTIVIEW_FRAME_PACKING_TOP_BOTTOM: The top half of the frame
  131. * contains the left eye, and the bottom half the right eye.
  132. * @GST_VIDEO_MULTIVIEW_FRAME_PACKING_CHECKERBOARD: Pixels are arranged with
  133. * alternating pixels representing left and right eye views in a
  134. * checkerboard fashion.
  135. *
  136. * #GstVideoMultiviewFramePacking represents the subset of #GstVideoMultiviewMode
  137. * values that can be applied to any video frame without needing extra metadata.
  138. * It can be used by elements that provide a property to override the
  139. * multiview interpretation of a video stream when the video doesn't contain
  140. * any markers.
  141. *
  142. * This enum is used (for example) on playbin, to re-interpret a played
  143. * video stream as a stereoscopic video. The individual enum values are
  144. * equivalent to and have the same value as the matching #GstVideoMultiviewMode.
  145. *
  146. */
  147. typedef enum {
  148. GST_VIDEO_MULTIVIEW_FRAME_PACKING_NONE = GST_VIDEO_MULTIVIEW_MODE_NONE,
  149. GST_VIDEO_MULTIVIEW_FRAME_PACKING_MONO = GST_VIDEO_MULTIVIEW_MODE_MONO,
  150. GST_VIDEO_MULTIVIEW_FRAME_PACKING_LEFT = GST_VIDEO_MULTIVIEW_MODE_LEFT,
  151. GST_VIDEO_MULTIVIEW_FRAME_PACKING_RIGHT = GST_VIDEO_MULTIVIEW_MODE_RIGHT,
  152. GST_VIDEO_MULTIVIEW_FRAME_PACKING_SIDE_BY_SIDE = GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE,
  153. GST_VIDEO_MULTIVIEW_FRAME_PACKING_SIDE_BY_SIDE_QUINCUNX = GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE_QUINCUNX,
  154. GST_VIDEO_MULTIVIEW_FRAME_PACKING_COLUMN_INTERLEAVED = GST_VIDEO_MULTIVIEW_MODE_COLUMN_INTERLEAVED,
  155. GST_VIDEO_MULTIVIEW_FRAME_PACKING_ROW_INTERLEAVED = GST_VIDEO_MULTIVIEW_MODE_ROW_INTERLEAVED,
  156. GST_VIDEO_MULTIVIEW_FRAME_PACKING_TOP_BOTTOM = GST_VIDEO_MULTIVIEW_MODE_TOP_BOTTOM,
  157. GST_VIDEO_MULTIVIEW_FRAME_PACKING_CHECKERBOARD = GST_VIDEO_MULTIVIEW_MODE_CHECKERBOARD
  158. } GstVideoMultiviewFramePacking;
  159. #define GST_VIDEO_MULTIVIEW_MAX_FRAME_PACKING GST_VIDEO_MULTIVIEW_FRAME_PACKING_CHECKERBOARD
  160. /**
  161. * GstVideoMultiviewFlags:
  162. * @GST_VIDEO_MULTIVIEW_FLAGS_NONE: No flags
  163. * @GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_VIEW_FIRST: For stereo streams, the
  164. * normal arrangement of left and right views is reversed.
  165. * @GST_VIDEO_MULTIVIEW_FLAGS_LEFT_FLIPPED: The left view is vertically
  166. * mirrored.
  167. * @GST_VIDEO_MULTIVIEW_FLAGS_LEFT_FLOPPED: The left view is horizontally
  168. * mirrored.
  169. * @GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_FLIPPED: The right view is
  170. * vertically mirrored.
  171. * @GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_FLOPPED: The right view is
  172. * horizontally mirrored.
  173. * @GST_VIDEO_MULTIVIEW_FLAGS_HALF_ASPECT: For frame-packed
  174. * multiview modes, indicates that the individual
  175. * views have been encoded with half the true width or height
  176. * and should be scaled back up for display. This flag
  177. * is used for overriding input layout interpretation
  178. * by adjusting pixel-aspect-ratio.
  179. * For side-by-side, column interleaved or checkerboard packings, the
  180. * pixel width will be doubled. For row interleaved and top-bottom
  181. * encodings, pixel height will be doubled.
  182. * @GST_VIDEO_MULTIVIEW_FLAGS_MIXED_MONO: The video stream contains both
  183. * mono and multiview portions, signalled on each buffer by the
  184. * absence or presence of the @GST_VIDEO_BUFFER_FLAG_MULTIPLE_VIEW
  185. * buffer flag.
  186. *
  187. * GstVideoMultiviewFlags are used to indicate extra properties of a
  188. * stereo/multiview stream beyond the frame layout and buffer mapping
  189. * that is conveyed in the #GstMultiviewMode.
  190. */
  191. typedef enum {
  192. GST_VIDEO_MULTIVIEW_FLAGS_NONE = 0,
  193. GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_VIEW_FIRST = (1 << 0),
  194. GST_VIDEO_MULTIVIEW_FLAGS_LEFT_FLIPPED = (1 << 1),
  195. GST_VIDEO_MULTIVIEW_FLAGS_LEFT_FLOPPED = (1 << 2),
  196. GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_FLIPPED = (1 << 3),
  197. GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_FLOPPED = (1 << 4),
  198. GST_VIDEO_MULTIVIEW_FLAGS_HALF_ASPECT = (1 << 14),
  199. GST_VIDEO_MULTIVIEW_FLAGS_MIXED_MONO = (1 << 15)
  200. } GstVideoMultiviewFlags;
  201. /**
  202. * GstVideoFlags:
  203. * @GST_VIDEO_FLAG_NONE: no flags
  204. * @GST_VIDEO_FLAG_VARIABLE_FPS: a variable fps is selected, fps_n and fps_d
  205. * denote the maximum fps of the video
  206. * @GST_VIDEO_FLAG_PREMULTIPLIED_ALPHA: Each color has been scaled by the alpha
  207. * value.
  208. *
  209. * Extra video flags
  210. */
  211. typedef enum {
  212. GST_VIDEO_FLAG_NONE = 0,
  213. GST_VIDEO_FLAG_VARIABLE_FPS = (1 << 0),
  214. GST_VIDEO_FLAG_PREMULTIPLIED_ALPHA = (1 << 1)
  215. } GstVideoFlags;
  216. /**
  217. * GstVideoInfo:
  218. * @finfo: the format info of the video
  219. * @interlace_mode: the interlace mode
  220. * @flags: additional video flags
  221. * @width: the width of the video
  222. * @height: the height of the video
  223. * @views: the number of views for multiview video
  224. * @size: the default size of one frame
  225. * @chroma_site: a #GstVideoChromaSite.
  226. * @colorimetry: the colorimetry info
  227. * @par_n: the pixel-aspect-ratio numerator
  228. * @par_d: the pixel-aspect-ratio demnominator
  229. * @fps_n: the framerate numerator
  230. * @fps_d: the framerate demnominator
  231. * @offset: offsets of the planes
  232. * @stride: strides of the planes
  233. * @multiview_mode: delivery mode for multiple views. (Since 1.6)
  234. * @multiview_flags: flags for multiple views configuration (Since 1.6)
  235. *
  236. * Information describing image properties. This information can be filled
  237. * in from GstCaps with gst_video_info_from_caps(). The information is also used
  238. * to store the specific video info when mapping a video frame with
  239. * gst_video_frame_map().
  240. *
  241. * Use the provided macros to access the info in this structure.
  242. */
  243. struct _GstVideoInfo {
  244. const GstVideoFormatInfo *finfo;
  245. GstVideoInterlaceMode interlace_mode;
  246. GstVideoFlags flags;
  247. gint width;
  248. gint height;
  249. gsize size;
  250. gint views;
  251. GstVideoChromaSite chroma_site;
  252. GstVideoColorimetry colorimetry;
  253. gint par_n;
  254. gint par_d;
  255. gint fps_n;
  256. gint fps_d;
  257. gsize offset[GST_VIDEO_MAX_PLANES];
  258. gint stride[GST_VIDEO_MAX_PLANES];
  259. /* Union preserves padded struct size for backwards compat
  260. * Consumer code should use the accessor macros for fields */
  261. union {
  262. struct {
  263. GstVideoMultiviewMode multiview_mode;
  264. GstVideoMultiviewFlags multiview_flags;
  265. } abi;
  266. /*< private >*/
  267. gpointer _gst_reserved[GST_PADDING];
  268. } ABI;
  269. };
  270. #define GST_TYPE_VIDEO_INFO (gst_video_info_get_type ())
  271. GType gst_video_info_get_type (void);
  272. /* general info */
  273. #define GST_VIDEO_INFO_FORMAT(i) (GST_VIDEO_FORMAT_INFO_FORMAT((i)->finfo))
  274. #define GST_VIDEO_INFO_NAME(i) (GST_VIDEO_FORMAT_INFO_NAME((i)->finfo))
  275. #define GST_VIDEO_INFO_IS_YUV(i) (GST_VIDEO_FORMAT_INFO_IS_YUV((i)->finfo))
  276. #define GST_VIDEO_INFO_IS_RGB(i) (GST_VIDEO_FORMAT_INFO_IS_RGB((i)->finfo))
  277. #define GST_VIDEO_INFO_IS_GRAY(i) (GST_VIDEO_FORMAT_INFO_IS_GRAY((i)->finfo))
  278. #define GST_VIDEO_INFO_HAS_ALPHA(i) (GST_VIDEO_FORMAT_INFO_HAS_ALPHA((i)->finfo))
  279. #define GST_VIDEO_INFO_INTERLACE_MODE(i) ((i)->interlace_mode)
  280. #define GST_VIDEO_INFO_IS_INTERLACED(i) ((i)->interlace_mode != GST_VIDEO_INTERLACE_MODE_PROGRESSIVE)
  281. #define GST_VIDEO_INFO_FLAGS(i) ((i)->flags)
  282. #define GST_VIDEO_INFO_WIDTH(i) ((i)->width)
  283. #define GST_VIDEO_INFO_HEIGHT(i) ((i)->height)
  284. #define GST_VIDEO_INFO_SIZE(i) ((i)->size)
  285. #define GST_VIDEO_INFO_VIEWS(i) ((i)->views)
  286. #define GST_VIDEO_INFO_PAR_N(i) ((i)->par_n)
  287. #define GST_VIDEO_INFO_PAR_D(i) ((i)->par_d)
  288. #define GST_VIDEO_INFO_FPS_N(i) ((i)->fps_n)
  289. #define GST_VIDEO_INFO_FPS_D(i) ((i)->fps_d)
  290. #define GST_VIDEO_INFO_COLORIMETRY(i) ((i)->colorimetry)
  291. #define GST_VIDEO_INFO_CHROMA_SITE(i) ((i)->chroma_site)
  292. #define GST_VIDEO_INFO_MULTIVIEW_MODE(i) ((i)->ABI.abi.multiview_mode)
  293. #define GST_VIDEO_INFO_MULTIVIEW_FLAGS(i) ((i)->ABI.abi.multiview_flags)
  294. /* dealing with GstVideoInfo flags */
  295. #define GST_VIDEO_INFO_FLAG_IS_SET(i,flag) ((GST_VIDEO_INFO_FLAGS(i) & (flag)) == (flag))
  296. #define GST_VIDEO_INFO_FLAG_SET(i,flag) (GST_VIDEO_INFO_FLAGS(i) |= (flag))
  297. #define GST_VIDEO_INFO_FLAG_UNSET(i,flag) (GST_VIDEO_INFO_FLAGS(i) &= ~(flag))
  298. /* dealing with planes */
  299. #define GST_VIDEO_INFO_N_PLANES(i) (GST_VIDEO_FORMAT_INFO_N_PLANES((i)->finfo))
  300. #define GST_VIDEO_INFO_PLANE_OFFSET(i,p) ((i)->offset[p])
  301. #define GST_VIDEO_INFO_PLANE_STRIDE(i,p) ((i)->stride[p])
  302. /* dealing with components */
  303. #define GST_VIDEO_INFO_N_COMPONENTS(i) GST_VIDEO_FORMAT_INFO_N_COMPONENTS((i)->finfo)
  304. #define GST_VIDEO_INFO_COMP_DEPTH(i,c) GST_VIDEO_FORMAT_INFO_DEPTH((i)->finfo,(c))
  305. #define GST_VIDEO_INFO_COMP_DATA(i,d,c) GST_VIDEO_FORMAT_INFO_DATA((i)->finfo,d,(c))
  306. #define GST_VIDEO_INFO_COMP_OFFSET(i,c) GST_VIDEO_FORMAT_INFO_OFFSET((i)->finfo,(i)->offset,(c))
  307. #define GST_VIDEO_INFO_COMP_STRIDE(i,c) GST_VIDEO_FORMAT_INFO_STRIDE((i)->finfo,(i)->stride,(c))
  308. #define GST_VIDEO_INFO_COMP_WIDTH(i,c) GST_VIDEO_FORMAT_INFO_SCALE_WIDTH((i)->finfo,(c),(i)->width)
  309. #define GST_VIDEO_INFO_COMP_HEIGHT(i,c) GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT((i)->finfo,(c),(i)->height)
  310. #define GST_VIDEO_INFO_COMP_PLANE(i,c) GST_VIDEO_FORMAT_INFO_PLANE((i)->finfo,(c))
  311. #define GST_VIDEO_INFO_COMP_PSTRIDE(i,c) GST_VIDEO_FORMAT_INFO_PSTRIDE((i)->finfo,(c))
  312. #define GST_VIDEO_INFO_COMP_POFFSET(i,c) GST_VIDEO_FORMAT_INFO_POFFSET((i)->finfo,(c))
  313. GstVideoInfo * gst_video_info_new (void);
  314. void gst_video_info_init (GstVideoInfo *info);
  315. GstVideoInfo * gst_video_info_copy (const GstVideoInfo *info);
  316. void gst_video_info_free (GstVideoInfo *info);
  317. void gst_video_info_set_format (GstVideoInfo *info, GstVideoFormat format,
  318. guint width, guint height);
  319. gboolean gst_video_info_from_caps (GstVideoInfo *info, const GstCaps * caps);
  320. GstCaps * gst_video_info_to_caps (GstVideoInfo *info);
  321. gboolean gst_video_info_convert (GstVideoInfo *info,
  322. GstFormat src_format,
  323. gint64 src_value,
  324. GstFormat dest_format,
  325. gint64 *dest_value);
  326. gboolean gst_video_info_is_equal (const GstVideoInfo *info,
  327. const GstVideoInfo *other);
  328. #include <gst/video/video.h>
  329. void gst_video_info_align (GstVideoInfo * info, GstVideoAlignment * align);
  330. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  331. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoInfo, gst_video_info_free)
  332. #endif
  333. G_END_DECLS
  334. #endif /* __GST_VIDEO_INFO_H__ */