2
* Copyright (C) 2008 David Schleef <ds@schleef.org>
3
* Copyright (C) 2011 Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>.
4
* Copyright (C) 2011 Nokia Corporation. All rights reserved.
5
* Contact: Stefan Kost <stefan.kost@nokia.com>
6
* Copyright (C) 2012 Collabora Ltd.
7
* Author : Edward Hervey <edward@collabora.com>
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Library General Public
11
* License as published by the Free Software Foundation; either
12
* version 2 of the License, or (at your option) any later version.
14
* This library is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* Library General Public License for more details.
19
* You should have received a copy of the GNU Library General Public
20
* License along with this library; if not, write to the
21
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22
* Boston, MA 02111-1307, USA.
25
#ifndef _GST_VIDEO_ENCODER_H_
26
#define _GST_VIDEO_ENCODER_H_
28
#include <gst/video/gstvideoutils.h>
32
#define GST_TYPE_VIDEO_ENCODER \
33
(gst_video_encoder_get_type())
34
#define GST_VIDEO_ENCODER(obj) \
35
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_ENCODER,GstVideoEncoder))
36
#define GST_VIDEO_ENCODER_CLASS(klass) \
37
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_ENCODER,GstVideoEncoderClass))
38
#define GST_VIDEO_ENCODER_GET_CLASS(obj) \
39
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_VIDEO_ENCODER,GstVideoEncoderClass))
40
#define GST_IS_VIDEO_ENCODER(obj) \
41
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_ENCODER))
42
#define GST_IS_VIDEO_ENCODER_CLASS(obj) \
43
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_ENCODER))
44
#define GST_VIDEO_ENCODER_CAST(enc) ((GstVideoEncoder*)enc)
47
* GST_VIDEO_ENCODER_SINK_NAME:
49
* The name of the templates for the sink pad.
53
#define GST_VIDEO_ENCODER_SINK_NAME "sink"
55
* GST_VIDEO_ENCODER_SRC_NAME:
57
* The name of the templates for the source pad.
61
#define GST_VIDEO_ENCODER_SRC_NAME "src"
64
* GST_VIDEO_ENCODER_FLOW_DROPPED:
66
* Returned when the event/buffer should be dropped.
70
#define GST_VIDEO_ENCODER_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS_1
73
* GST_VIDEO_ENCODER_SRC_PAD:
74
* @obj: a #GstVideoEncoder
76
* Gives the pointer to the source #GstPad object of the element.
80
#define GST_VIDEO_ENCODER_SRC_PAD(obj) (((GstVideoEncoder *) (obj))->srcpad)
83
* GST_VIDEO_ENCODER_SINK_PAD:
84
* @obj: a #GstVideoEncoder
86
* Gives the pointer to the sink #GstPad object of the element.
90
#define GST_VIDEO_ENCODER_SINK_PAD(obj) (((GstVideoEncoder *) (obj))->sinkpad)
93
* GST_VIDEO_ENCODER_FLOW_NEED_DATA:
95
* Returned while parsing to indicate more data is needed.
99
#define GST_VIDEO_ENCODER_FLOW_NEED_DATA GST_FLOW_CUSTOM_SUCCESS
102
* GST_VIDEO_ENCODER_FLOW_DROPPED:
104
* Returned when the event/buffer should be dropped.
108
#define GST_VIDEO_ENCODER_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS_1
111
* GST_VIDEO_ENCODER_INPUT_SEGMENT:
112
* @obj: base parse instance
114
* Gives the segment of the element.
118
#define GST_VIDEO_ENCODER_INPUT_SEGMENT(obj) (GST_VIDEO_ENCODER_CAST (obj)->input_segment)
121
* GST_VIDEO_ENCODER_OUTPUT_SEGMENT:
122
* @obj: base parse instance
124
* Gives the segment of the element.
128
#define GST_VIDEO_ENCODER_OUTPUT_SEGMENT(obj) (GST_VIDEO_ENCODER_CAST (obj)->output_segment)
131
* GST_VIDEO_ENCODER_STREAM_LOCK:
132
* @encoder: video encoder instance
134
* Obtain a lock to protect the encoder function from concurrent access.
138
#define GST_VIDEO_ENCODER_STREAM_LOCK(encoder) g_static_rec_mutex_lock (&GST_VIDEO_ENCODER (encoder)->stream_lock)
141
* GST_VIDEO_ENCODER_STREAM_UNLOCK:
142
* @encoder: video encoder instance
144
* Release the lock that protects the encoder function from concurrent access.
148
#define GST_VIDEO_ENCODER_STREAM_UNLOCK(encoder) g_static_rec_mutex_unlock (&GST_VIDEO_ENCODER (encoder)->stream_lock)
150
typedef struct _GstVideoEncoder GstVideoEncoder;
151
typedef struct _GstVideoEncoderPrivate GstVideoEncoderPrivate;
152
typedef struct _GstVideoEncoderClass GstVideoEncoderClass;
157
* The opaque #GstVideoEncoder data structure.
161
struct _GstVideoEncoder
170
/* protects all data processing, i.e. is locked
171
* in the chain function, finish_frame and when
172
* processing serialized events */
173
GStaticRecMutex stream_lock;
175
/* MT-protected (with STREAM_LOCK) */
176
GstSegment input_segment;
177
GstSegment output_segment;
179
GstVideoEncoderPrivate *priv;
182
gpointer _gst_reserved[GST_PADDING_LARGE];
186
* GstVideoEncoderClass:
188
* Called when the element changes to GST_STATE_READY.
189
* Allows opening external resources. Since: 0.10.37.
191
* Called when the element changes to GST_STATE_NULL.
192
* Allows closing external resources. Since: 0.10.37.
194
* Called when the element starts processing.
195
* Allows opening external resources.
197
* Called when the element stops processing.
198
* Allows closing external resources.
199
* @set_format: Optional.
200
* Notifies subclass of incoming data format.
201
* GstVideoCodecState fields have already been
202
* set according to provided caps.
203
* @handle_frame: Provides input frame to subclass.
205
* Allows subclass (encoder) to perform post-seek semantics reset.
207
* Called to request subclass to dispatch any pending remaining
208
* data (e.g. at EOS).
209
* @pre_push: Optional.
210
* Allows subclass to push frame downstream in whatever
211
* shape or form it deems appropriate. If not provided,
212
* provided encoded frame data is simply pushed downstream.
213
* @getcaps: Optional.
214
* Allows for a custom sink getcaps implementation (e.g.
215
* for multichannel input specification). If not implemented,
216
* default returns gst_video_encoder_proxy_getcaps
217
* applied to sink template caps.
218
* @sink_event: Optional.
219
* Event handler on the sink pad. This function should return
220
* TRUE if the event was handled and should be discarded
221
* (i.e. not unref'ed).
222
* @src_event: Optional.
223
* Event handler on the source pad. This function should return
224
* TRUE if the event was handled and should be discarded
225
* (i.e. not unref'ed).
227
* Subclasses can override any of the available virtual methods or not, as
228
* needed. At minimum @handle_frame needs to be overridden, and @set_format
229
* and @get_caps are likely needed as well.
233
struct _GstVideoEncoderClass
236
GstElementClass element_class;
239
/* virtual methods for subclasses */
240
gboolean (*open) (GstVideoEncoder *encoder);
242
gboolean (*close) (GstVideoEncoder *encoder);
244
gboolean (*start) (GstVideoEncoder *encoder);
246
gboolean (*stop) (GstVideoEncoder *encoder);
248
gboolean (*set_format) (GstVideoEncoder *encoder,
249
GstVideoCodecState *state);
251
GstFlowReturn (*handle_frame) (GstVideoEncoder *encoder,
252
GstVideoCodecFrame *frame);
254
gboolean (*reset) (GstVideoEncoder *encoder,
257
GstFlowReturn (*finish) (GstVideoEncoder *encoder);
259
GstFlowReturn (*pre_push) (GstVideoEncoder *encoder,
260
GstVideoCodecFrame *frame);
262
GstCaps * (*getcaps) (GstVideoEncoder *enc);
264
gboolean (*sink_event) (GstVideoEncoder *encoder,
267
gboolean (*src_event) (GstVideoEncoder *encoder,
271
gpointer _gst_reserved[GST_PADDING_LARGE];
274
GType gst_video_encoder_get_type (void);
276
GstVideoCodecState* gst_video_encoder_get_output_state (GstVideoEncoder *encoder);
278
GstVideoCodecState* gst_video_encoder_set_output_state (GstVideoEncoder * encoder,
280
GstVideoCodecState * reference);
282
GstVideoCodecFrame* gst_video_encoder_get_frame (GstVideoEncoder *encoder,
284
GstVideoCodecFrame* gst_video_encoder_get_oldest_frame (GstVideoEncoder *encoder);
286
GList * gst_video_encoder_get_frames (GstVideoEncoder *encoder);
288
GstFlowReturn gst_video_encoder_finish_frame (GstVideoEncoder *encoder,
289
GstVideoCodecFrame *frame);
291
GstCaps * gst_video_encoder_proxy_getcaps (GstVideoEncoder * enc,
293
void gst_video_encoder_set_discont (GstVideoEncoder *encoder);
294
gboolean gst_video_encoder_get_discont (GstVideoEncoder *encoder);
296
void gst_video_encoder_set_latency (GstVideoEncoder *encoder,
297
GstClockTime min_latency,
298
GstClockTime max_latency);
299
void gst_video_encoder_get_latency (GstVideoEncoder *encoder,
300
GstClockTime *min_latency,
301
GstClockTime *max_latency);
303
void gst_video_encoder_set_headers (GstVideoEncoder *encoder,