1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
/* GStreamer
* Copyright (C) 2008 David Schleef <ds@schleef.org>
* Copyright (C) 2011 Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>.
* Copyright (C) 2011 Nokia Corporation. All rights reserved.
* Contact: Stefan Kost <stefan.kost@nokia.com>
* Copyright (C) 2012 Collabora Ltd.
* Author : Edward Hervey <edward@collabora.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _GST_VIDEO_ENCODER_H_
#define _GST_VIDEO_ENCODER_H_
#include <gst/video/gstvideoutils.h>
G_BEGIN_DECLS
#define GST_TYPE_VIDEO_ENCODER \
(gst_video_encoder_get_type())
#define GST_VIDEO_ENCODER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_ENCODER,GstVideoEncoder))
#define GST_VIDEO_ENCODER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_ENCODER,GstVideoEncoderClass))
#define GST_VIDEO_ENCODER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_VIDEO_ENCODER,GstVideoEncoderClass))
#define GST_IS_VIDEO_ENCODER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_ENCODER))
#define GST_IS_VIDEO_ENCODER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_ENCODER))
#define GST_VIDEO_ENCODER_CAST(enc) ((GstVideoEncoder*)enc)
/**
* GST_VIDEO_ENCODER_SINK_NAME:
*
* The name of the templates for the sink pad.
*/
#define GST_VIDEO_ENCODER_SINK_NAME "sink"
/**
* GST_VIDEO_ENCODER_SRC_NAME:
*
* The name of the templates for the source pad.
*/
#define GST_VIDEO_ENCODER_SRC_NAME "src"
/**
* GST_VIDEO_ENCODER_SRC_PAD:
* @obj: a #GstVideoEncoder
*
* Gives the pointer to the source #GstPad object of the element.
*/
#define GST_VIDEO_ENCODER_SRC_PAD(obj) (((GstVideoEncoder *) (obj))->srcpad)
/**
* GST_VIDEO_ENCODER_SINK_PAD:
* @obj: a #GstVideoEncoder
*
* Gives the pointer to the sink #GstPad object of the element.
*/
#define GST_VIDEO_ENCODER_SINK_PAD(obj) (((GstVideoEncoder *) (obj))->sinkpad)
/**
* GST_VIDEO_ENCODER_FLOW_NEED_DATA:
*
* Returned while parsing to indicate more data is needed.
**/
#define GST_VIDEO_ENCODER_FLOW_NEED_DATA GST_FLOW_CUSTOM_SUCCESS
/**
* GST_VIDEO_ENCODER_FLOW_DROPPED:
*
* Returned when the event/buffer should be dropped.
*
* Deprecated: since 1.8. use gst_video_encoder_finish_frame with
* a %NULL frame->output_buffer to drop the frame instead.
*/
#ifndef GST_DISABLE_DEPRECATED
#define GST_VIDEO_ENCODER_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS_1
#endif
/**
* GST_VIDEO_ENCODER_INPUT_SEGMENT:
* @obj: base parse instance
*
* Gives the segment of the element.
*/
#define GST_VIDEO_ENCODER_INPUT_SEGMENT(obj) (GST_VIDEO_ENCODER_CAST (obj)->input_segment)
/**
* GST_VIDEO_ENCODER_OUTPUT_SEGMENT:
* @obj: base parse instance
*
* Gives the segment of the element.
*/
#define GST_VIDEO_ENCODER_OUTPUT_SEGMENT(obj) (GST_VIDEO_ENCODER_CAST (obj)->output_segment)
/**
* GST_VIDEO_ENCODER_STREAM_LOCK:
* @encoder: video encoder instance
*
* Obtain a lock to protect the encoder function from concurrent access.
*/
#define GST_VIDEO_ENCODER_STREAM_LOCK(encoder) g_rec_mutex_lock (&GST_VIDEO_ENCODER (encoder)->stream_lock)
/**
* GST_VIDEO_ENCODER_STREAM_UNLOCK:
* @encoder: video encoder instance
*
* Release the lock that protects the encoder function from concurrent access.
*/
#define GST_VIDEO_ENCODER_STREAM_UNLOCK(encoder) g_rec_mutex_unlock (&GST_VIDEO_ENCODER (encoder)->stream_lock)
typedef struct _GstVideoEncoder GstVideoEncoder;
typedef struct _GstVideoEncoderPrivate GstVideoEncoderPrivate;
typedef struct _GstVideoEncoderClass GstVideoEncoderClass;
/**
* GstVideoEncoder:
*
* The opaque #GstVideoEncoder data structure.
*/
struct _GstVideoEncoder
{
/*< private >*/
GstElement element;
/*< protected >*/
GstPad *sinkpad;
GstPad *srcpad;
/* protects all data processing, i.e. is locked
* in the chain function, finish_frame and when
* processing serialized events */
GRecMutex stream_lock;
/* MT-protected (with STREAM_LOCK) */
GstSegment input_segment;
GstSegment output_segment;
/*< private >*/
GstVideoEncoderPrivate *priv;
gpointer padding[GST_PADDING_LARGE];
};
/**
* GstVideoEncoderClass:
* @open: Optional.
* Called when the element changes to GST_STATE_READY.
* Allows opening external resources.
* @close: Optional.
* Called when the element changes to GST_STATE_NULL.
* Allows closing external resources.
* @start: Optional.
* Called when the element starts processing.
* Allows opening external resources.
* @stop: Optional.
* Called when the element stops processing.
* Allows closing external resources.
* @set_format: Optional.
* Notifies subclass of incoming data format.
* GstVideoCodecState fields have already been
* set according to provided caps.
* @handle_frame: Provides input frame to subclass.
* @reset: Optional.
* Allows subclass (encoder) to perform post-seek semantics reset.
* Deprecated.
* @finish: Optional.
* Called to request subclass to dispatch any pending remaining
* data (e.g. at EOS).
* @pre_push: Optional.
* Allows subclass to push frame downstream in whatever
* shape or form it deems appropriate. If not provided,
* provided encoded frame data is simply pushed downstream.
* @getcaps: Optional.
* Allows for a custom sink getcaps implementation (e.g.
* for multichannel input specification). If not implemented,
* default returns gst_video_encoder_proxy_getcaps
* applied to sink template caps.
* @sink_event: Optional.
* Event handler on the sink pad. This function should return
* TRUE if the event was handled and should be discarded
* (i.e. not unref'ed).
* Subclasses should chain up to the parent implementation to
* invoke the default handler.
* @src_event: Optional.
* Event handler on the source pad. This function should return
* TRUE if the event was handled and should be discarded
* (i.e. not unref'ed).
* Subclasses should chain up to the parent implementation to
* invoke the default handler.
* @negotiate: Optional.
* Negotiate with downstream and configure buffer pools, etc.
* Subclasses should chain up to the parent implementation to
* invoke the default handler.
* @decide_allocation: Optional.
* Setup the allocation parameters for allocating output
* buffers. The passed in query contains the result of the
* downstream allocation query.
* Subclasses should chain up to the parent implementation to
* invoke the default handler.
* @propose_allocation: Optional.
* Propose buffer allocation parameters for upstream elements.
* Subclasses should chain up to the parent implementation to
* invoke the default handler.
* @flush: Optional.
* Flush all remaining data from the encoder without
* pushing it downstream. Since: 1.2
* @sink_query: Optional.
* Query handler on the sink pad. This function should
* return TRUE if the query could be performed. Subclasses
* should chain up to the parent implementation to invoke the
* default handler. Since: 1.4
* @src_query: Optional.
* Query handler on the source pad. This function should
* return TRUE if the query could be performed. Subclasses
* should chain up to the parent implementation to invoke the
* default handler. Since: 1.4
* @transform_meta: Optional. Transform the metadata on the input buffer to the
* output buffer. By default this method is copies all meta without
* tags and meta with only the "video" tag. subclasses can
* implement this method and return %TRUE if the metadata is to be
* copied. Since: 1.6
*
* Subclasses can override any of the available virtual methods or not, as
* needed. At minimum @handle_frame needs to be overridden, and @set_format
* and @get_caps are likely needed as well.
*/
struct _GstVideoEncoderClass
{
/*< private >*/
GstElementClass element_class;
/*< public >*/
/* virtual methods for subclasses */
gboolean (*open) (GstVideoEncoder *encoder);
gboolean (*close) (GstVideoEncoder *encoder);
gboolean (*start) (GstVideoEncoder *encoder);
gboolean (*stop) (GstVideoEncoder *encoder);
gboolean (*set_format) (GstVideoEncoder *encoder,
GstVideoCodecState *state);
GstFlowReturn (*handle_frame) (GstVideoEncoder *encoder,
GstVideoCodecFrame *frame);
gboolean (*reset) (GstVideoEncoder *encoder,
gboolean hard);
GstFlowReturn (*finish) (GstVideoEncoder *encoder);
GstFlowReturn (*pre_push) (GstVideoEncoder *encoder,
GstVideoCodecFrame *frame);
GstCaps * (*getcaps) (GstVideoEncoder *enc,
GstCaps *filter);
gboolean (*sink_event) (GstVideoEncoder *encoder,
GstEvent *event);
gboolean (*src_event) (GstVideoEncoder *encoder,
GstEvent *event);
gboolean (*negotiate) (GstVideoEncoder *encoder);
gboolean (*decide_allocation) (GstVideoEncoder *encoder, GstQuery *query);
gboolean (*propose_allocation) (GstVideoEncoder * encoder,
GstQuery * query);
gboolean (*flush) (GstVideoEncoder *encoder);
gboolean (*sink_query) (GstVideoEncoder *encoder,
GstQuery *query);
gboolean (*src_query) (GstVideoEncoder *encoder,
GstQuery *query);
gboolean (*transform_meta) (GstVideoEncoder *encoder,
GstVideoCodecFrame *frame,
GstMeta * meta);
/*< private >*/
gpointer _gst_reserved[GST_PADDING_LARGE-4];
};
GST_VIDEO_API
GType gst_video_encoder_get_type (void);
GST_VIDEO_API
GstVideoCodecState* gst_video_encoder_get_output_state (GstVideoEncoder *encoder);
GST_VIDEO_API
GstVideoCodecState* gst_video_encoder_set_output_state (GstVideoEncoder * encoder,
GstCaps * caps,
GstVideoCodecState * reference);
GST_VIDEO_API
gboolean gst_video_encoder_negotiate (GstVideoEncoder * encoder);
GST_VIDEO_API
GstVideoCodecFrame* gst_video_encoder_get_frame (GstVideoEncoder *encoder,
int frame_number);
GST_VIDEO_API
GstVideoCodecFrame* gst_video_encoder_get_oldest_frame (GstVideoEncoder *encoder);
GST_VIDEO_API
GList * gst_video_encoder_get_frames (GstVideoEncoder *encoder);
GST_VIDEO_API
GstBuffer * gst_video_encoder_allocate_output_buffer (GstVideoEncoder * encoder,
gsize size);
GST_VIDEO_API
GstFlowReturn gst_video_encoder_allocate_output_frame (GstVideoEncoder *encoder,
GstVideoCodecFrame *frame,
gsize size);
GST_VIDEO_API
GstFlowReturn gst_video_encoder_finish_frame (GstVideoEncoder *encoder,
GstVideoCodecFrame *frame);
GST_VIDEO_API
GstFlowReturn gst_video_encoder_finish_subframe (GstVideoEncoder * encoder,
GstVideoCodecFrame * frame);
GST_VIDEO_API
GstCaps * gst_video_encoder_proxy_getcaps (GstVideoEncoder * enc,
GstCaps * caps,
GstCaps * filter);
GST_VIDEO_API
void gst_video_encoder_set_latency (GstVideoEncoder *encoder,
GstClockTime min_latency,
GstClockTime max_latency);
GST_VIDEO_API
void gst_video_encoder_get_latency (GstVideoEncoder *encoder,
GstClockTime *min_latency,
GstClockTime *max_latency);
GST_VIDEO_API
void gst_video_encoder_set_headers (GstVideoEncoder *encoder,
GList *headers);
GST_VIDEO_API
void gst_video_encoder_merge_tags (GstVideoEncoder *encoder,
const GstTagList *tags,
GstTagMergeMode mode);
GST_VIDEO_API
void gst_video_encoder_get_allocator (GstVideoEncoder *encoder,
GstAllocator **allocator,
GstAllocationParams *params);
GST_VIDEO_API
void gst_video_encoder_set_min_pts(GstVideoEncoder *encoder, GstClockTime min_pts);
GST_VIDEO_API
void gst_video_encoder_set_qos_enabled (GstVideoEncoder * encoder, gboolean enabled);
GST_VIDEO_API
gboolean gst_video_encoder_is_qos_enabled (GstVideoEncoder * encoder);
GST_VIDEO_API
GstClockTimeDiff gst_video_encoder_get_max_encode_time (GstVideoEncoder *encoder, GstVideoCodecFrame * frame);
GST_VIDEO_API
void gst_video_encoder_set_min_force_key_unit_interval (GstVideoEncoder * encoder,
GstClockTime interval);
GST_VIDEO_API
GstClockTime gst_video_encoder_get_min_force_key_unit_interval (GstVideoEncoder * encoder);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVideoEncoder, gst_object_unref)
G_END_DECLS
#endif
|