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 to gst_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
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.
- public Buffer allocate_output_buffer (size_t size)
Helper function that allocates a buffer to hold an encoded video frame
for this's current CodecState.
- public FlowReturn allocate_output_frame (CodecFrame frame, size_t size)
Helper function that allocates a buffer to hold an encoded video frame
for this's current CodecState.
- public virtual bool close ()
Optional.
- public virtual bool decide_allocation (Query query)
Optional.
- public virtual FlowReturn finish ()
Optional.
- public FlowReturn finish_frame (owned CodecFrame 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.
- public FlowReturn finish_subframe (CodecFrame frame)
If multiple subframes are produced for one input frame then use this
method for each subframe, except for the last one.
- public virtual bool flush ()
Optional.
- public void get_allocator (out Allocator allocator, out AllocationParams @params)
Lets Encoder sub-classes to know
the memory allocator used by the base class and its params.
- public CodecFrame get_frame (int frame_number)
- public List<CodecFrame> get_frames ()
- public void get_latency (out ClockTime min_latency, out ClockTime max_latency)
Query the configured encoding latency.
- public ClockTimeDiff get_max_encode_time (CodecFrame frame)
Determines maximum possible encoding time for frame that
will allow it to encode and arrive in time (as determined by QoS events).
- public ClockTime get_min_force_key_unit_interval ()
- public CodecFrame get_oldest_frame ()
- public CodecState get_output_state ()
- public virtual Caps getcaps (Caps filter)
Optional.
- public virtual FlowReturn handle_frame (CodecFrame frame)
Provides input frame to subclass.
- public bool is_qos_enabled ()
Checks if this is currently
configured to handle Quality-of-Service events from downstream.
- public void merge_tags (TagList? tags, TagMergeMode mode)
Sets the video encoder tags and how they should be merged with any
upstream stream tags.
- public virtual bool negotiate ()
Negotiate with downstream elements to currently configured
CodecState.
- public virtual bool open ()
Optional.
- public virtual FlowReturn pre_push (CodecFrame frame)
Optional.
- public virtual bool propose_allocation (Query query)
Optional.
- public Caps proxy_getcaps (Caps? caps, Caps? filter)
Returns caps that express caps (or sink template caps if
caps == NULL) restricted to resolution/format/... combinations supported by downstream elements (e.
- public virtual bool reset (bool hard)
Optional.
- public virtual bool set_format (CodecState state)
Optional.
- public void set_headers (owned List<Buffer> headers)
Set the codec headers to be sent downstream whenever requested.
- public void set_latency (ClockTime min_latency, ClockTime max_latency)
Informs baseclass of encoding latency.
- public void set_min_force_key_unit_interval (ClockTime interval)
Sets the minimum interval for requesting keyframes based on
force-keyunit events.
- public void set_min_pts (ClockTime min_pts)
Request minimal value for PTS passed to handle_frame.
- public CodecState set_output_state (owned Caps caps, CodecState? reference)
Creates a new
CodecState with the specified caps as the output state for the encoder.
- public void set_qos_enabled (bool enabled)
Configures this to handle
Quality-of-Service events from downstream.
- public virtual bool sink_event (Event event)
Optional.
- public virtual bool sink_query (Query query)
Optional.
- public virtual bool src_event (Event event)
Optional.
- public virtual bool src_query (Query query)
Optional.
- public virtual bool start ()
Optional.
- public virtual bool stop ()
Optional.
- public virtual bool transform_meta (CodecFrame frame, Meta meta)
Optional.