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_
30 #include <gst/video/video-prelude.h>
33 #define GST_TYPE_VIDEO_CODEC_STATE \
34 (gst_video_codec_state_get_type())
36 #define GST_TYPE_VIDEO_CODEC_FRAME \
37 (gst_video_codec_frame_get_type())
39 typedef struct _GstVideoCodecState GstVideoCodecState;
40 typedef struct _GstVideoCodecFrame GstVideoCodecFrame;
44 * @info: The #GstVideoInfo describing the stream
45 * @caps: The #GstCaps used in the caps negotiation of the pad.
46 * @codec_data: a #GstBuffer corresponding to the
47 * 'codec_data' field of a stream, or NULL.
48 * @allocation_caps: The #GstCaps for allocation query and pool
49 * negotiation. Since: 1.10
51 * Structure representing the state of an incoming or outgoing video
52 * stream for encoders and decoders.
54 * Decoders and encoders will receive such a state through their
55 * respective @set_format vmethods.
57 * Decoders and encoders can set the downstream state, by using the
58 * @gst_video_decoder_set_output_state() or
59 * @gst_video_encoder_set_output_state() methods.
61 struct _GstVideoCodecState
71 GstBuffer *codec_data;
73 GstCaps *allocation_caps;
76 gpointer padding[GST_PADDING_LARGE - 1];
80 * GstVideoCodecFrameFlags:
81 * @GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY: is the frame only meant to be decoded
82 * @GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT: is the frame a synchronization point (keyframe)
83 * @GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME: should the output frame be made a keyframe
84 * @GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS: should the encoder output stream headers
86 * Flags for #GstVideoCodecFrame
90 GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY = (1<<0),
91 GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT = (1<<1),
92 GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME = (1<<2),
93 GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS = (1<<3)
94 } GstVideoCodecFrameFlags;
97 * GST_VIDEO_CODEC_FRAME_FLAGS:
98 * @frame: a #GstVideoCodecFrame
100 * The entire set of flags for the @frame
102 #define GST_VIDEO_CODEC_FRAME_FLAGS(frame) ((frame)->flags)
105 * GST_VIDEO_CODEC_FRAME_FLAG_IS_SET:
106 * @frame: a #GstVideoCodecFrame
107 * @flag: a flag to check for
109 * Checks whether the given @flag is set
111 #define GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame,flag) !!(GST_VIDEO_CODEC_FRAME_FLAGS(frame) & (flag))
114 * GST_VIDEO_CODEC_FRAME_FLAG_SET:
115 * @frame: a #GstVideoCodecFrame
116 * @flag: Flag to set, can be any number of bits in guint32.
118 * This macro sets the given bits
120 #define GST_VIDEO_CODEC_FRAME_FLAG_SET(frame,flag) (GST_VIDEO_CODEC_FRAME_FLAGS(frame) |= (flag))
123 * GST_VIDEO_CODEC_FRAME_FLAG_UNSET:
124 * @frame: a #GstVideoCodecFrame
125 * @flag: Flag to unset
127 * This macro usets the given bits.
129 #define GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame,flag) (GST_VIDEO_CODEC_FRAME_FLAGS(frame) &= ~(flag))
132 * GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY:
133 * @frame: a #GstVideoCodecFrame
135 * Tests if the buffer should only be decoded but not sent downstream.
137 #define GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY(frame) (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY))
140 * GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY:
141 * @frame: a #GstVideoCodecFrame
143 * Sets the buffer to not be sent downstream.
145 * Decoder implementation can use this if they have frames that
146 * are not meant to be displayed.
148 * Encoder implementation can safely ignore this field.
150 #define GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY(frame) (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY))
153 * GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT:
154 * @frame: a #GstVideoCodecFrame
156 * Tests if the frame is a synchronization point (like a keyframe).
158 * Decoder implementations can use this to detect keyframes.
160 #define GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT(frame) (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT))
163 * GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT:
164 * @frame: a #GstVideoCodecFrame
166 * Sets the frame to be a synchronization point (like a keyframe).
168 * Encoder implementations should set this accordingly.
170 * Decoder implementing parsing features should set this when they
171 * detect such a synchronization point.
173 #define GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT(frame) (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT))
174 #define GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT(frame) (GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame, GST_VIDEO_CODEC_FRAME_FLAG_SYNC_POINT))
178 * GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME:
179 * @frame: a #GstVideoCodecFrame
181 * Tests if the frame must be encoded as a keyframe. Applies only to
182 * frames provided to encoders. Decoders can safely ignore this field.
184 #define GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME(frame) (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME))
185 #define GST_VIDEO_CODEC_FRAME_SET_FORCE_KEYFRAME(frame) (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME))
186 #define GST_VIDEO_CODEC_FRAME_UNSET_FORCE_KEYFRAME(frame) (GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME))
189 * GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME_HEADERS:
190 * @frame: a #GstVideoCodecFrame
192 * Tests if encoder should output stream headers before outputting the
193 * resulting encoded buffer for the given frame.
195 * Applies only to frames provided to encoders. Decoders can safely
198 #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))
199 #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))
200 #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))
203 * GstVideoCodecFrame:
204 * @pts: Presentation timestamp
205 * @dts: Decoding timestamp
206 * @duration: Duration of the frame
207 * @system_frame_number: Unique identifier for the frame. Use this if you need
208 * to get hold of the frame later (like when data is being decoded).
209 * Typical usage in decoders is to set this on the opaque value provided
210 * to the library and get back the frame using gst_video_decoder_get_frame()
211 * @distance_from_sync: Distance in frames from the last synchronization point.
212 * @input_buffer: the input #GstBuffer that created this frame. The buffer is owned
213 * by the frame and references to the frame instead of the buffer should
215 * @output_buffer: the output #GstBuffer. Implementations should set this either
216 * directly, or by using the
217 * @gst_video_decoder_allocate_output_frame() or
218 * @gst_video_decoder_allocate_output_buffer() methods. The buffer is
219 * owned by the frame and references to the frame instead of the
220 * buffer should be kept.
221 * @deadline: Running time when the frame will be used.
223 * A #GstVideoCodecFrame represents a video frame both in raw and
226 struct _GstVideoCodecFrame
234 guint32 system_frame_number; /* ED */
235 guint32 decode_frame_number; /* ED */
236 guint32 presentation_frame_number; /* ED */
238 GstClockTime dts; /* ED */
239 GstClockTime pts; /* ED */
240 GstClockTime duration; /* ED */
242 int distance_from_sync; /* ED */
244 GstBuffer *input_buffer; /* ED */
245 GstBuffer *output_buffer; /* ED */
247 GstClockTime deadline; /* D */
251 /* Events that should be pushed downstream *before*
252 * the next output_buffer */
253 GList *events; /* ED */
256 GDestroyNotify user_data_destroy_notify;
263 gpointer padding[GST_PADDING_LARGE];
267 /* GstVideoCodecState */
270 GType gst_video_codec_state_get_type (void);
273 GstVideoCodecState *gst_video_codec_state_ref (GstVideoCodecState * state);
276 void gst_video_codec_state_unref (GstVideoCodecState * state);
279 /* GstVideoCodecFrame */
282 GType gst_video_codec_frame_get_type (void);
285 GstVideoCodecFrame *gst_video_codec_frame_ref (GstVideoCodecFrame * frame);
288 void gst_video_codec_frame_unref (GstVideoCodecFrame * frame);
291 void gst_video_codec_frame_set_user_data (GstVideoCodecFrame *frame,
293 GDestroyNotify notify);
296 gpointer gst_video_codec_frame_get_user_data (GstVideoCodecFrame *frame);
298 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
299 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoCodecFrame, gst_video_codec_frame_unref)
302 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
303 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoCodecState, gst_video_codec_state_unref)