2 * Copyright (C) 2008 David Schleef <ds@schleef.org>
3 * Copyright (C) 2012 Collabora Ltd.
4 * Author : Edward Hervey <edward@collabora.com>
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.
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.
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.
22 #ifndef __GST_VIDEO_H__
23 #include <gst/video/video.h>
26 #ifndef _GST_VIDEO_UTILS_H_
27 #define _GST_VIDEO_UTILS_H_
32 #define GST_TYPE_VIDEO_CODEC_STATE \
33 (gst_video_codec_state_get_type())
35 #define GST_TYPE_VIDEO_CODEC_FRAME \
36 (gst_video_codec_frame_get_type())
38 typedef struct _GstVideoCodecState GstVideoCodecState;
39 typedef struct _GstVideoCodecFrame GstVideoCodecFrame;
43 * @info: The #GstVideoInfo describing the stream
44 * @caps: The #GstCaps used in the caps negotiation of the pad.
45 * @codec_data: a #GstBuffer corresponding to the
46 * 'codec_data' field of a stream, or NULL.
47 * @allocation_caps: The #GstCaps for allocation query and pool
48 * negotiation. Since: 1.10
50 * Structure representing the state of an incoming or outgoing video
51 * stream for encoders and decoders.
53 * Decoders and encoders will receive such a state through their
54 * respective @set_format vmethods.
56 * Decoders and encoders can set the downstream state, by using the
57 * @gst_video_decoder_set_output_state() or
58 * @gst_video_encoder_set_output_state() methods.
60 struct _GstVideoCodecState
70 GstBuffer *codec_data;
72 GstCaps *allocation_caps;
75 gpointer padding[GST_PADDING_LARGE - 1];
79 * GstVideoCodecFrameFlags:
80 * @GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY: is the frame only meant to be decoded
81 * @GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT: is the frame a synchronization point (keyframe)
82 * @GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME: should the output frame be made a keyframe
83 * @GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS: should the encoder output stream headers
85 * Flags for #GstVideoCodecFrame
89 GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY = (1<<0),
90 GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT = (1<<1),
91 GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME = (1<<2),
92 GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS = (1<<3)
93 } GstVideoCodecFrameFlags;
96 * GST_VIDEO_CODEC_FRAME_FLAGS:
97 * @frame: a #GstVideoCodecFrame
99 * The entire set of flags for the @frame
101 #define GST_VIDEO_CODEC_FRAME_FLAGS(frame) ((frame)->flags)
104 * GST_VIDEO_CODEC_FRAME_FLAG_IS_SET:
105 * @frame: a #GstVideoCodecFrame
106 * @flag: a flag to check for
108 * Checks whether the given @flag is set
110 #define GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame,flag) !!(GST_VIDEO_CODEC_FRAME_FLAGS(frame) & (flag))
113 * GST_VIDEO_CODEC_FRAME_FLAG_SET:
114 * @frame: a #GstVideoCodecFrame
115 * @flag: Flag to set, can be any number of bits in guint32.
117 * This macro sets the given bits
119 #define GST_VIDEO_CODEC_FRAME_FLAG_SET(frame,flag) (GST_VIDEO_CODEC_FRAME_FLAGS(frame) |= (flag))
122 * GST_VIDEO_CODEC_FRAME_FLAG_UNSET:
123 * @frame: a #GstVideoCodecFrame
124 * @flag: Flag to unset
126 * This macro usets the given bits.
128 #define GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame,flag) (GST_VIDEO_CODEC_FRAME_FLAGS(frame) &= ~(flag))
131 * GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY:
132 * @frame: a #GstVideoCodecFrame
134 * Tests if the buffer should only be decoded but not sent downstream.
136 #define GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY(frame) (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY))
139 * GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY:
140 * @frame: a #GstVideoCodecFrame
142 * Sets the buffer to not be sent downstream.
144 * Decoder implementation can use this if they have frames that
145 * are not meant to be displayed.
147 * Encoder implementation can safely ignore this field.
149 #define GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY(frame) (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY))
152 * GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT:
153 * @frame: a #GstVideoCodecFrame
155 * Tests if the frame is a synchronization point (like a keyframe).
157 * Decoder implementations can use this to detect keyframes.
159 #define GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT(frame) (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT))
162 * GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT:
163 * @frame: a #GstVideoCodecFrame
165 * Sets the frame to be a synchronization point (like a keyframe).
167 * Encoder implementations should set this accordingly.
169 * Decoder implementing parsing features should set this when they
170 * detect such a synchronization point.
172 #define GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT(frame) (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT))
173 #define GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT(frame) (GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame, GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT))
177 * GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME:
178 * @frame: a #GstVideoCodecFrame
180 * Tests if the frame must be encoded as a keyframe. Applies only to
181 * frames provided to encoders. Decoders can safely ignore this field.
183 #define GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME(frame) (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME))
184 #define GST_VIDEO_CODEC_FRAME_SET_FORCE_KEYFRAME(frame) (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME))
185 #define GST_VIDEO_CODEC_FRAME_UNSET_FORCE_KEYFRAME(frame) (GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME))
188 * GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME_HEADERS:
189 * @frame: a #GstVideoCodecFrame
191 * Tests if encoder should output stream headers before outputting the
192 * resulting encoded buffer for the given frame.
194 * Applies only to frames provided to encoders. Decoders can safely
197 #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))
198 #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))
199 #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))
202 * GstVideoCodecFrame:
203 * @pts: Presentation timestamp
204 * @dts: Decoding timestamp
205 * @duration: Duration of the frame
206 * @system_frame_number: Unique identifier for the frame. Use this if you need
207 * to get hold of the frame later (like when data is being decoded).
208 * Typical usage in decoders is to set this on the opaque value provided
209 * to the library and get back the frame using gst_video_decoder_get_frame()
210 * @distance_from_sync: Distance in frames from the last synchronization point.
211 * @input_buffer: the input #GstBuffer that created this frame. The buffer is owned
212 * by the frame and references to the frame instead of the buffer should
214 * @output_buffer: the output #GstBuffer. Implementations should set this either
215 * directly, or by using the
216 * @gst_video_decoder_allocate_output_frame() or
217 * @gst_video_decoder_allocate_output_buffer() methods. The buffer is
218 * owned by the frame and references to the frame instead of the
219 * buffer should be kept.
220 * @deadline: Running time when the frame will be used.
222 * A #GstVideoCodecFrame represents a video frame both in raw and
225 struct _GstVideoCodecFrame
233 guint32 system_frame_number; /* ED */
234 guint32 decode_frame_number; /* ED */
235 guint32 presentation_frame_number; /* ED */
237 GstClockTime dts; /* ED */
238 GstClockTime pts; /* ED */
239 GstClockTime duration; /* ED */
241 int distance_from_sync; /* ED */
243 GstBuffer *input_buffer; /* ED */
244 GstBuffer *output_buffer; /* ED */
246 GstClockTime deadline; /* D */
250 /* Events that should be pushed downstream *before*
251 * the next output_buffer */
252 GList *events; /* ED */
255 GDestroyNotify user_data_destroy_notify;
262 gpointer padding[GST_PADDING_LARGE];
266 /* GstVideoCodecState */
269 GType gst_video_codec_state_get_type (void);
272 GstVideoCodecState *gst_video_codec_state_ref (GstVideoCodecState * state);
275 void gst_video_codec_state_unref (GstVideoCodecState * state);
278 /* GstVideoCodecFrame */
281 GType gst_video_codec_frame_get_type (void);
284 GstVideoCodecFrame *gst_video_codec_frame_ref (GstVideoCodecFrame * frame);
287 void gst_video_codec_frame_unref (GstVideoCodecFrame * frame);
290 void gst_video_codec_frame_set_user_data (GstVideoCodecFrame *frame,
292 GDestroyNotify notify);
295 gpointer gst_video_codec_frame_get_user_data (GstVideoCodecFrame *frame);
297 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
298 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoCodecFrame, gst_video_codec_frame_unref)
301 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
302 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoCodecState, gst_video_codec_state_unref)