Top |
Functions
Types and Values
#define | GST_VIDEO_ENCODER_FLOW_DROPPED |
#define | GST_VIDEO_ENCODER_FLOW_NEED_DATA |
#define | GST_VIDEO_ENCODER_SINK_NAME |
#define | GST_VIDEO_ENCODER_SRC_NAME |
struct | GstVideoEncoder |
struct | GstVideoEncoderClass |
Description
This base class is for video encoders turning raw video into encoded video data.
GstVideoEncoder and subclass should cooperate as follows.
Configuration
Initially, GstVideoEncoder calls
start
when the encoder element is activated, which allows subclass to perform any global setup.GstVideoEncoder calls
set_format
to inform subclass of the format of input video data that it is about to receive. Subclass should setup for encoding and configure base class as appropriate (e.g. latency). While unlikely, it might be called more than once, if changing input parameters require reconfiguration. Baseclass will ensure that processing of current configuration is finished.GstVideoEncoder calls
stop
at end of all processing.
Data processing
-
Base class collects input data and metadata into a frame and hands this to subclass'
handle_frame
.If codec processing results in encoded data, subclass should call
gst_video_encoder_finish_frame
to have encoded data pushed downstream.If implemented, baseclass calls subclass
pre_push
just prior to pushing to allow subclasses to modify some metadata on the buffer. If it returns GST_FLOW_OK, the buffer is pushed downstream.GstVideoEncoderClass will handle both srcpad and sinkpad events. Sink events will be passed to subclass if
event
callback has been provided.
Shutdown phase
GstVideoEncoder class calls
stop
to inform the subclass that data parsing will be stopped.
Subclass is responsible for providing pad template caps for
source and sink pads. The pads need to be named "sink" and "src". It should
also be able to provide fixed src pad caps in getcaps
by the time it calls
gst_video_encoder_finish_frame
.
Things that subclass need to take care of:
Provide pad templates
Provide source pad caps before pushing the first buffer
Accept data in
handle_frame
and provide encoded results togst_video_encoder_finish_frame
.
The “qos” property will enable the Quality-of-Service
features of the encoder which gather statistics about the real-time
performance of the downstream elements. If enabled, subclasses can
use gst_video_encoder_get_max_encode_time()
to check if input frames
are already late and drop them right away to give a chance to the
pipeline to catch up.
Functions
GST_VIDEO_ENCODER_SINK_PAD()
#define GST_VIDEO_ENCODER_SINK_PAD(obj) (((GstVideoEncoder *) (obj))->sinkpad)
Gives the pointer to the sink GstPad object of the element.
GST_VIDEO_ENCODER_SRC_PAD()
#define GST_VIDEO_ENCODER_SRC_PAD(obj) (((GstVideoEncoder *) (obj))->srcpad)
Gives the pointer to the source GstPad object of the element.
GST_VIDEO_ENCODER_INPUT_SEGMENT()
#define GST_VIDEO_ENCODER_INPUT_SEGMENT(obj) (GST_VIDEO_ENCODER_CAST (obj)->input_segment)
Gives the segment of the element.
GST_VIDEO_ENCODER_OUTPUT_SEGMENT()
#define GST_VIDEO_ENCODER_OUTPUT_SEGMENT(obj) (GST_VIDEO_ENCODER_CAST (obj)->output_segment)
Gives the segment of the element.
GST_VIDEO_ENCODER_STREAM_LOCK()
#define GST_VIDEO_ENCODER_STREAM_LOCK(encoder) g_rec_mutex_lock (&GST_VIDEO_ENCODER (encoder)->stream_lock)
Obtain a lock to protect the encoder function from concurrent access.
GST_VIDEO_ENCODER_STREAM_UNLOCK()
#define GST_VIDEO_ENCODER_STREAM_UNLOCK(encoder) g_rec_mutex_unlock (&GST_VIDEO_ENCODER (encoder)->stream_lock)
Release the lock that protects the encoder function from concurrent access.
gst_video_encoder_allocate_output_buffer ()
GstBuffer * gst_video_encoder_allocate_output_buffer (GstVideoEncoder *encoder
,gsize size
);
Helper function that allocates a buffer to hold an encoded video frame
for encoder
's current GstVideoCodecState.
gst_video_encoder_allocate_output_frame ()
GstFlowReturn gst_video_encoder_allocate_output_frame (GstVideoEncoder *encoder
,GstVideoCodecFrame *frame
,gsize size
);
Helper function that allocates a buffer to hold an encoded video frame for encoder
's
current GstVideoCodecState. Subclass should already have configured video
state and set src pad caps.
The buffer allocated here is owned by the frame and you should only keep references to the frame, not the buffer.
gst_video_encoder_get_allocator ()
void gst_video_encoder_get_allocator (GstVideoEncoder *encoder
,GstAllocator **allocator
,GstAllocationParams *params
);
Lets GstVideoEncoder sub-classes to know the memory allocator
used by the base class and its params
.
Unref the allocator
after use it.
Parameters
encoder |
||
allocator |
the GstAllocator used. |
[out][allow-none][transfer full] |
params |
the
GstAllocatorParams of |
[out][allow-none][transfer full] |
gst_video_encoder_finish_frame ()
GstFlowReturn gst_video_encoder_finish_frame (GstVideoEncoder *encoder
,GstVideoCodecFrame *frame
);
frame
must have a valid encoded data buffer, whose metadata fields
are then appropriately set according to frame data or no buffer at
all if the frame should be dropped.
It is subsequently pushed downstream or provided to pre_push
.
In any case, the frame is considered finished and released.
After calling this function the output buffer of the frame is to be considered read-only. This function will also change the metadata of the buffer.
gst_video_encoder_negotiate ()
gboolean
gst_video_encoder_negotiate (GstVideoEncoder *encoder
);
Negotiate with downstream elements to currently configured GstVideoCodecState. Unmark GST_PAD_FLAG_NEED_RECONFIGURE in any case. But mark it again if negotiate fails.
gst_video_encoder_get_frame ()
GstVideoCodecFrame * gst_video_encoder_get_frame (GstVideoEncoder *encoder
,int frame_number
);
Get a pending unfinished GstVideoCodecFrame
gst_video_encoder_get_frames ()
GList *
gst_video_encoder_get_frames (GstVideoEncoder *encoder
);
Get all pending unfinished GstVideoCodecFrame
gst_video_encoder_get_oldest_frame ()
GstVideoCodecFrame *
gst_video_encoder_get_oldest_frame (GstVideoEncoder *encoder
);
Get the oldest unfinished pending GstVideoCodecFrame
gst_video_encoder_set_headers ()
void gst_video_encoder_set_headers (GstVideoEncoder *encoder
,GList *headers
);
Set the codec headers to be sent downstream whenever requested.
Parameters
encoder |
||
headers |
a list of GstBuffer containing the codec header. |
[transfer full][element-type GstBuffer] |
gst_video_encoder_get_latency ()
void gst_video_encoder_get_latency (GstVideoEncoder *encoder
,GstClockTime *min_latency
,GstClockTime *max_latency
);
Query the configured encoding latency. Results will be returned via
min_latency
and max_latency
.
gst_video_encoder_set_latency ()
void gst_video_encoder_set_latency (GstVideoEncoder *encoder
,GstClockTime min_latency
,GstClockTime max_latency
);
Informs baseclass of encoding latency.
gst_video_encoder_set_output_state ()
GstVideoCodecState * gst_video_encoder_set_output_state (GstVideoEncoder *encoder
,GstCaps *caps
,GstVideoCodecState *reference
);
Creates a new GstVideoCodecState with the specified caps as the output state
for the encoder.
Any previously set output state on encoder
will be replaced by the newly
created one.
The specified caps
should not contain any resolution, pixel-aspect-ratio,
framerate, codec-data, .... Those should be specified instead in the returned
GstVideoCodecState.
If the subclass wishes to copy over existing fields (like pixel aspect ratio,
or framerate) from an existing GstVideoCodecState, it can be provided as a
reference
.
If the subclass wishes to override some fields from the output state (like pixel-aspect-ratio or framerate) it can do so on the returned GstVideoCodecState.
The new output state will only take effect (set on pads and buffers) starting
from the next call to gst_video_encoder_finish_frame()
.
Parameters
encoder |
||
caps |
the GstCaps to use for the output. |
[transfer full] |
reference |
An optional reference |
[allow-none][transfer none] |
gst_video_encoder_get_output_state ()
GstVideoCodecState *
gst_video_encoder_get_output_state (GstVideoEncoder *encoder
);
Get the current GstVideoCodecState
gst_video_encoder_set_min_pts ()
void gst_video_encoder_set_min_pts (GstVideoEncoder *encoder
,GstClockTime min_pts
);
Request minimal value for PTS passed to handle_frame.
For streams with reordered frames this can be used to ensure that there is enough time to accomodate first DTS, which may be less than first PTS
Since 1.6
gst_video_encoder_proxy_getcaps ()
GstCaps * gst_video_encoder_proxy_getcaps (GstVideoEncoder *enc
,GstCaps *caps
,GstCaps *filter
);
Returns caps that express caps
(or sink template caps if caps
== NULL)
restricted to resolution/format/... combinations supported by downstream
elements (e.g. muxers).
gst_video_encoder_merge_tags ()
void gst_video_encoder_merge_tags (GstVideoEncoder *encoder
,const GstTagList *tags
,GstTagMergeMode mode
);
Sets the video encoder tags and how they should be merged with any
upstream stream tags. This will override any tags previously-set
with gst_video_encoder_merge_tags()
.
Note that this is provided for convenience, and the subclass is not required to use this and can still do tag handling on its own.
MT safe.
Parameters
encoder |
||
tags |
a GstTagList to merge, or NULL to unset previously-set tags. |
[allow-none] |
mode |
the GstTagMergeMode to use, usually GST_TAG_MERGE_REPLACE |
gst_video_encoder_get_max_encode_time ()
GstClockTimeDiff gst_video_encoder_get_max_encode_time (GstVideoEncoder *encoder
,GstVideoCodecFrame *frame
);
Determines maximum possible encoding time for frame
that will
allow it to encode and arrive in time (as determined by QoS events).
In particular, a negative result means encoding in time is no longer possible
and should therefore occur as soon/skippy as possible.
If no QoS events have been received from downstream, or if “qos” is disabled this function returns G_MAXINT64.
Since: 1.14
Types and Values
GST_VIDEO_ENCODER_FLOW_DROPPED
#define GST_VIDEO_ENCODER_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS_1
GST_VIDEO_ENCODER_FLOW_DROPPED
is deprecated and should not be used in newly-written code.
since 1.8. use gst_video_encoder_finish_frame with
a NULL
frame->output_buffer to drop the frame instead.
Returned when the event/buffer should be dropped.
GST_VIDEO_ENCODER_FLOW_NEED_DATA
#define GST_VIDEO_ENCODER_FLOW_NEED_DATA GST_FLOW_CUSTOM_SUCCESS
Returned while parsing to indicate more data is needed.
GST_VIDEO_ENCODER_SINK_NAME
#define GST_VIDEO_ENCODER_SINK_NAME "sink"
The name of the templates for the sink pad.
GST_VIDEO_ENCODER_SRC_NAME
#define GST_VIDEO_ENCODER_SRC_NAME "src"
The name of the templates for the source pad.
struct GstVideoEncoderClass
struct GstVideoEncoderClass { /* 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); };
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.
Members
Optional. Called when the element changes to GST_STATE_READY. Allows opening external resources. |
||
Optional. Called when the element changes to GST_STATE_NULL. Allows closing external resources. |
||
Optional. Called when the element starts processing. Allows opening external resources. |
||
Optional. Called when the element stops processing. Allows closing external resources. |
||
Optional. Notifies subclass of incoming data format. GstVideoCodecState fields have already been set according to provided caps. |
||
Provides input frame to subclass. |
||
Optional. Allows subclass (encoder) to perform post-seek semantics reset. Deprecated. |
||
Optional. Called to request subclass to dispatch any pending remaining data (e.g. at EOS). |
||
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. |
||
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. |
||
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. |
||
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. |
||
Optional. Negotiate with downstream and configure buffer pools, etc. Subclasses should chain up to the parent implementation to invoke the default handler. |
||
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. |
||
Optional. Propose buffer allocation parameters for upstream elements. Subclasses should chain up to the parent implementation to invoke the default handler. |
||
Optional. Flush all remaining data from the encoder without pushing it downstream. Since: 1.2 |
||
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 |
||
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 |
||
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 |