1 | /* GStreamer |
2 | * Copyright (C) 2008 David Schleef <ds@schleef.org> |
3 | * Copyright (C) 2012 Collabora Ltd. |
4 | * Author : Edward Hervey <edward@collabora.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 | |
22 | #ifndef __GST_VIDEO_H__ |
23 | #include <gst/video/video.h> |
24 | #endif |
25 | |
26 | #ifndef _GST_VIDEO_UTILS_H_ |
27 | #define _GST_VIDEO_UTILS_H_ |
28 | |
29 | #include <gst/gst.h> |
30 | #include <gst/video/video-prelude.h> |
31 | |
32 | G_BEGIN_DECLS |
33 | #define GST_TYPE_VIDEO_CODEC_STATE \ |
34 | (gst_video_codec_state_get_type()) |
35 | |
36 | #define GST_TYPE_VIDEO_CODEC_FRAME \ |
37 | (gst_video_codec_frame_get_type()) |
38 | |
39 | typedef struct _GstVideoCodecState GstVideoCodecState; |
40 | typedef struct _GstVideoCodecFrame GstVideoCodecFrame; |
41 | |
42 | /** |
43 | * GstVideoCodecState: |
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 |
50 | * |
51 | * Structure representing the state of an incoming or outgoing video |
52 | * stream for encoders and decoders. |
53 | * |
54 | * Decoders and encoders will receive such a state through their |
55 | * respective @set_format vmethods. |
56 | * |
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. |
60 | */ |
61 | struct _GstVideoCodecState |
62 | { |
63 | /*< private >*/ |
64 | gint ref_count; |
65 | |
66 | /*< public >*/ |
67 | GstVideoInfo info; |
68 | |
69 | GstCaps *caps; |
70 | |
71 | GstBuffer *codec_data; |
72 | |
73 | GstCaps *allocation_caps; |
74 | |
75 | /*< private >*/ |
76 | gpointer padding[GST_PADDING_LARGE - 1]; |
77 | }; |
78 | |
79 | /** |
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 |
85 | * |
86 | * Flags for #GstVideoCodecFrame |
87 | */ |
88 | typedef enum |
89 | { |
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 | = (1<<3) |
94 | } GstVideoCodecFrameFlags; |
95 | |
96 | /** |
97 | * GST_VIDEO_CODEC_FRAME_FLAGS: |
98 | * @frame: a #GstVideoCodecFrame |
99 | * |
100 | * The entire set of flags for the @frame |
101 | */ |
102 | #define GST_VIDEO_CODEC_FRAME_FLAGS(frame) ((frame)->flags) |
103 | |
104 | /** |
105 | * GST_VIDEO_CODEC_FRAME_FLAG_IS_SET: |
106 | * @frame: a #GstVideoCodecFrame |
107 | * @flag: a flag to check for |
108 | * |
109 | * Checks whether the given @flag is set |
110 | */ |
111 | #define GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame,flag) !!(GST_VIDEO_CODEC_FRAME_FLAGS(frame) & (flag)) |
112 | |
113 | /** |
114 | * GST_VIDEO_CODEC_FRAME_FLAG_SET: |
115 | * @frame: a #GstVideoCodecFrame |
116 | * @flag: Flag to set, can be any number of bits in guint32. |
117 | * |
118 | * This macro sets the given bits |
119 | */ |
120 | #define GST_VIDEO_CODEC_FRAME_FLAG_SET(frame,flag) (GST_VIDEO_CODEC_FRAME_FLAGS(frame) |= (flag)) |
121 | |
122 | /** |
123 | * GST_VIDEO_CODEC_FRAME_FLAG_UNSET: |
124 | * @frame: a #GstVideoCodecFrame |
125 | * @flag: Flag to unset |
126 | * |
127 | * This macro usets the given bits. |
128 | */ |
129 | #define GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame,flag) (GST_VIDEO_CODEC_FRAME_FLAGS(frame) &= ~(flag)) |
130 | |
131 | /** |
132 | * GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY: |
133 | * @frame: a #GstVideoCodecFrame |
134 | * |
135 | * Tests if the buffer should only be decoded but not sent downstream. |
136 | */ |
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)) |
138 | |
139 | /** |
140 | * GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY: |
141 | * @frame: a #GstVideoCodecFrame |
142 | * |
143 | * Sets the buffer to not be sent downstream. |
144 | * |
145 | * Decoder implementation can use this if they have frames that |
146 | * are not meant to be displayed. |
147 | * |
148 | * Encoder implementation can safely ignore this field. |
149 | */ |
150 | #define GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY(frame) (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY)) |
151 | |
152 | /** |
153 | * GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT: |
154 | * @frame: a #GstVideoCodecFrame |
155 | * |
156 | * Tests if the frame is a synchronization point (like a keyframe). |
157 | * |
158 | * Decoder implementations can use this to detect keyframes. |
159 | */ |
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)) |
161 | |
162 | /** |
163 | * GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT: |
164 | * @frame: a #GstVideoCodecFrame |
165 | * |
166 | * Sets the frame to be a synchronization point (like a keyframe). |
167 | * |
168 | * Encoder implementations should set this accordingly. |
169 | * |
170 | * Decoder implementing parsing features should set this when they |
171 | * detect such a synchronization point. |
172 | */ |
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)) |
175 | |
176 | |
177 | /** |
178 | * GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME: |
179 | * @frame: a #GstVideoCodecFrame |
180 | * |
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. |
183 | */ |
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)) |
187 | |
188 | /** |
189 | * GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME_HEADERS: |
190 | * @frame: a #GstVideoCodecFrame |
191 | * |
192 | * Tests if encoder should output stream headers before outputting the |
193 | * resulting encoded buffer for the given frame. |
194 | * |
195 | * Applies only to frames provided to encoders. Decoders can safely |
196 | * ignore this field. |
197 | */ |
198 | #define (frame) (GST_VIDEO_CODEC_FRAME_FLAG_IS_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS)) |
199 | #define (frame) (GST_VIDEO_CODEC_FRAME_FLAG_SET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS)) |
200 | #define (frame) (GST_VIDEO_CODEC_FRAME_FLAG_UNSET(frame, GST_VIDEO_CODEC_FRAME_FLAG_FORCE_KEYFRAME_HEADERS)) |
201 | |
202 | /** |
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 |
214 | * be kept. |
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. |
222 | * |
223 | * A #GstVideoCodecFrame represents a video frame both in raw and |
224 | * encoded form. |
225 | */ |
226 | struct _GstVideoCodecFrame |
227 | { |
228 | /*< private >*/ |
229 | gint ref_count; |
230 | guint32 flags; |
231 | |
232 | /*< public >*/ |
233 | guint32 system_frame_number; /* ED */ |
234 | |
235 | /*< private >*/ |
236 | guint32 decode_frame_number; /* ED */ |
237 | guint32 presentation_frame_number; /* ED */ |
238 | |
239 | /*< public >*/ |
240 | GstClockTime dts; /* ED */ |
241 | GstClockTime pts; /* ED */ |
242 | GstClockTime duration; /* ED */ |
243 | |
244 | int distance_from_sync; /* ED */ |
245 | |
246 | GstBuffer *input_buffer; /* ED */ |
247 | GstBuffer *output_buffer; /* ED */ |
248 | |
249 | GstClockTime deadline; /* D */ |
250 | |
251 | /*< private >*/ |
252 | |
253 | /* Events that should be pushed downstream *before* |
254 | * the next output_buffer */ |
255 | GList *events; /* ED */ |
256 | |
257 | gpointer user_data; |
258 | GDestroyNotify user_data_destroy_notify; |
259 | |
260 | union { |
261 | struct { |
262 | GstClockTime ts; |
263 | GstClockTime ts2; |
264 | } ABI; |
265 | gpointer padding[GST_PADDING_LARGE]; |
266 | } abidata; |
267 | }; |
268 | |
269 | /* GstVideoCodecState */ |
270 | |
271 | GST_VIDEO_API |
272 | GType gst_video_codec_state_get_type (void); |
273 | |
274 | GST_VIDEO_API |
275 | GstVideoCodecState *gst_video_codec_state_ref (GstVideoCodecState * state); |
276 | |
277 | GST_VIDEO_API |
278 | void gst_video_codec_state_unref (GstVideoCodecState * state); |
279 | |
280 | |
281 | /* GstVideoCodecFrame */ |
282 | |
283 | GST_VIDEO_API |
284 | GType gst_video_codec_frame_get_type (void); |
285 | |
286 | GST_VIDEO_API |
287 | GstVideoCodecFrame *gst_video_codec_frame_ref (GstVideoCodecFrame * frame); |
288 | |
289 | GST_VIDEO_API |
290 | void gst_video_codec_frame_unref (GstVideoCodecFrame * frame); |
291 | |
292 | GST_VIDEO_API |
293 | void gst_video_codec_frame_set_user_data (GstVideoCodecFrame *frame, |
294 | gpointer user_data, |
295 | GDestroyNotify notify); |
296 | |
297 | GST_VIDEO_API |
298 | gpointer gst_video_codec_frame_get_user_data (GstVideoCodecFrame *frame); |
299 | |
300 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC |
301 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoCodecFrame, gst_video_codec_frame_unref) |
302 | #endif |
303 | |
304 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC |
305 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoCodecState, gst_video_codec_state_unref) |
306 | #endif |
307 | |
308 | G_END_DECLS |
309 | |
310 | #endif |
311 | |