Commit f6cfd763 authored by Edward Hervey's avatar Edward Hervey
Browse files

video: Base classes for video decoders and encoders

parent a2254513
......@@ -228,6 +228,9 @@
<xi:include href="xml/gstvideooverlaycomposition.xml" />
<xi:include href="xml/gstvideofilter.xml" />
<xi:include href="xml/gstvideosink.xml" />
<xi:include href="xml/gstvideodecoder.xml" />
<xi:include href="xml/gstvideoencoder.xml" />
<xi:include href="xml/gstvideoutils.xml" />
</chapter>
</part>
......
......@@ -2302,6 +2302,7 @@ GST_VIDEO_FORMAT_INFO_IS_GRAY
GST_VIDEO_FORMAT_INFO_IS_LE
GST_VIDEO_FORMAT_INFO_IS_RGB
GST_VIDEO_FORMAT_INFO_IS_YUV
GST_VIDEO_FORMAT_INFO_IS_COMPLEX
GST_VIDEO_FORMAT_INFO_NAME
GST_VIDEO_FORMAT_INFO_N_COMPONENTS
GST_VIDEO_FORMAT_INFO_N_PLANES
......@@ -2509,6 +2510,123 @@ GST_IS_VIDEO_SINK_CLASS
gst_video_sink_get_type
</SECTION>
<SECTION>
<FILE>gstvideodecoder</FILE>
<TITLE>GstVideoDecoder</TITLE>
GST_VIDEO_DECODER_ERROR
GST_VIDEO_DECODER_FLOW_DROPPED
GST_VIDEO_DECODER_FLOW_NEED_DATA
GST_VIDEO_DECODER_MAX_ERRORS
GST_VIDEO_DECODER_SINK_NAME
GST_VIDEO_DECODER_SINK_PAD
GST_VIDEO_DECODER_SRC_NAME
GST_VIDEO_DECODER_SRC_PAD
GST_VIDEO_DECODER_STREAM_LOCK
GST_VIDEO_DECODER_STREAM_UNLOCK
GST_VIDEO_DECODER_INPUT_SEGMENT
GST_VIDEO_DECODER_OUTPUT_SEGMENT
GstVideoDecoder
GstVideoDecoderClass
gst_video_decoder_add_to_frame
gst_video_decoder_alloc_output_buffer
gst_video_decoder_alloc_output_frame
gst_video_decoder_drop_frame
gst_video_decoder_finish_frame
gst_video_decoder_get_frame
gst_video_decoder_get_max_decode_time
gst_video_decoder_get_max_errors
gst_video_decoder_get_oldest_frame
gst_video_decoder_get_packetized
gst_video_decoder_have_frame
gst_video_decoder_get_latency
gst_video_decoder_set_latency
gst_video_decoder_get_estimate_rate
gst_video_decoder_get_output_state
gst_video_decoder_set_estimate_rate
gst_video_decoder_set_output_state
gst_video_decoder_set_max_errors
gst_video_decoder_set_packetized
<SUBSECTION Standard>
GST_IS_VIDEO_DECODER
GST_IS_VIDEO_DECODER_CLASS
GST_TYPE_VIDEO_DECODER
GST_VIDEO_DECODER
GST_VIDEO_DECODER_CLASS
GST_VIDEO_DECODER_GET_CLASS
GstVideoDecoderPrivate
gst_video_decoder_get_type
</SECTION>
<SECTION>
<FILE>gstvideoencoder</FILE>
<TITLE>GstVideoEncoder</TITLE>
GST_VIDEO_ENCODER_CAST
GST_VIDEO_ENCODER_FLOW_DROPPED
GST_VIDEO_ENCODER_FLOW_NEED_DATA
GST_VIDEO_ENCODER_SINK_NAME
GST_VIDEO_ENCODER_SINK_PAD
GST_VIDEO_ENCODER_SRC_NAME
GST_VIDEO_ENCODER_SRC_PAD
GST_VIDEO_ENCODER_INPUT_SEGMENT
GST_VIDEO_ENCODER_OUTPUT_SEGMENT
GST_VIDEO_ENCODER_STREAM_LOCK
GST_VIDEO_ENCODER_STREAM_UNLOCK
GstVideoEncoder
GstVideoEncoderClass
gst_video_encoder_finish_frame
gst_video_encoder_get_frame
gst_video_encoder_get_oldest_frame
gst_video_encoder_set_headers
gst_video_encoder_get_latency
gst_video_encoder_set_latency
gst_video_encoder_get_discont
gst_video_encoder_set_discont
gst_video_encoder_set_output_state
gst_video_encoder_get_output_state
gst_video_encoder_proxy_getcaps
<SUBSECTION Standard>
GST_IS_VIDEO_ENCODER
GST_IS_VIDEO_ENCODER_CLASS
GST_TYPE_VIDEO_ENCODER
GST_VIDEO_ENCODER
GST_VIDEO_ENCODER_CLASS
GST_VIDEO_ENCODER_GET_CLASS
GstVideoEncoderPrivate
gst_video_encoder_get_type
</SECTION>
<SECTION>
<FILE>gstvideoutils</FILE>
GstVideoCodecFrame
GstVideoCodecFrameFlags
GST_VIDEO_CODEC_FRAME_FLAGS
GST_VIDEO_CODEC_FRAME_FLAG_IS_SET
GST_VIDEO_CODEC_FRAME_FLAG_SET
GST_VIDEO_CODEC_FRAME_FLAG_UNSET
GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY
GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME
GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME_HEADERS
GST_VIDEO_CODEC_FRAME_IS_SYNC_POINT
GST_VIDEO_CODEC_FRAME_SET_DECODE_ONLY
GST_VIDEO_CODEC_FRAME_SET_FORCE_KEYFRAME
GST_VIDEO_CODEC_FRAME_SET_FORCE_KEYFRAME_HEADERS
GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT
GST_VIDEO_CODEC_FRAME_UNSET_FORCE_KEYFRAME
GST_VIDEO_CODEC_FRAME_UNSET_FORCE_KEYFRAME_HEADERS
GST_VIDEO_CODEC_FRAME_UNSET_SYNC_POINT
gst_video_codec_frame_ref
gst_video_codec_frame_unref
gst_video_codec_frame_set_hook
GstVideoCodecState
gst_video_codec_state_ref
gst_video_codec_state_unref
<SUBSECTION Standard>
GST_TYPE_VIDEO_CODEC_FRAME
GST_TYPE_VIDEO_CODEC_STATE
gst_video_codec_frame_get_type
gst_video_codec_state_get_type
</SECTION>
<SECTION>
<FILE>gstdiscoverer</FILE>
<INCLUDE>gst/pbutils/pbutils.h</INCLUDE>
......
......@@ -63,6 +63,13 @@ gst_video_sink_get_type
#include <gst/video/video-overlay-composition.h>
gst_video_overlay_rectangle_get_type
gst_video_overlay_composition_get_type
#include <gst/video/gstvideodecoder.h>
gst_video_decoder_get_type
#include <gst/video/gstvideoencoder.h>
gst_video_encoder_get_type
#include <gst/video/gstvideoutils.h>
gst_video_codec_frame_get_type
gst_video_codec_state_get_type
#include <gst/pbutils/pbutils.h>
gst_discoverer_get_type
......
......@@ -20,13 +20,17 @@ CLEANFILES = $(BUILT_SOURCES)
# video-blend.h should be disted but not installed into the includedir
libgstvideo_@GST_MAJORMINOR@_la_SOURCES = \
video.c gstvideosink.c gstvideofilter.c convertframe.c \
video-blend.c video-blend.h video-overlay-composition.c
video-blend.c video-blend.h video-overlay-composition.c \
gstvideodecoder.c gstvideoencoder.c \
gstvideoutils.c
nodist_libgstvideo_@GST_MAJORMINOR@_la_SOURCES = \
$(built_sources) $(built_headers) \
$(ORC_NODIST_SOURCES)
libgstvideo_@GST_MAJORMINOR@includedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/video
libgstvideo_@GST_MAJORMINOR@include_HEADERS = \
video.h gstvideosink.h gstvideofilter.h video-overlay-composition.h
video.h gstvideosink.h gstvideofilter.h video-overlay-composition.h \
gstvideodecoder.h gstvideoencoder.h \
gstvideoutils.h
nodist_libgstvideo_@GST_MAJORMINOR@include_HEADERS = $(built_headers)
libgstvideo_@GST_MAJORMINOR@_la_CFLAGS = \
......@@ -63,6 +67,7 @@ GstVideo-@GST_MAJORMINOR@.gir: $(INTROSPECTION_SCANNER) libgstvideo-@GST_MAJORMI
$(INTROSPECTION_SCANNER) -v --namespace GstVideo \
--nsversion=@GST_MAJORMINOR@ \
--strip-prefix=Gst \
--warn-all \
$(gir_cincludes) \
-I$(top_srcdir)/gst-libs \
-I$(top_builddir)/gst-libs \
......
Base Video Classes TODO
Main goal:
Make the video encoder/decoder base classes more consistent with the
other GStreamer API, especially with the audio encoder/decoder base
classes.
API:
The API should be named similar, the base classes should be used
similar by the sub-classes, the behaviour of the base classes should
be similar.
Currently there are many, mostly small, differences between the audio
and video base classes API. Things like GstVideoState should be merged
with the stuff we have in 0.11 to make the API the same in 0.11 and
0.10 as far as possible, things like GstVideoInfo might make sense to
be backported (at least partially).
Specifics:
* Use a GInstancePrivate for extensability.
* Try to move more common video objects to video.[ch]
Known bugs:
https://bugzilla.gnome.org/show_bug.cgi?id=664127
[basevideodecoder] Add separate drain vfunc and differentiate
between hard/soft reset in reset vfunc
https://bugzilla.gnome.org/show_bug.cgi?id=660770
Doesn't support handling of "partial" frames
https://bugzilla.gnome.org/show_bug.cgi?id=654294
Impossible to flush pending frames in ::set_format
https://bugzilla.gnome.org/show_bug.cgi?id=658241
add API to handle QoS events and dropping logic
https://bugzilla.gnome.org/show_bug.cgi?id=667653
Autodetect multicore/multithread processors
https://bugzilla.gnome.org/show_bug.cgi?id=617021
Add support for QoS messages to -bad decoders and other elements
Peripheral issues
https://bugzilla.gnome.org/show_bug.cgi?id=663262
theoraenc: spurious encoder resets due to unstable upstream
timestamps cause quality issues
=> Investigate how to specify/handle variable framerates.
This diff is collapsed.
/* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef _GST_VIDEO_DECODER_H_
#define _GST_VIDEO_DECODER_H_
#include <gst/base/gstadapter.h>
#include <gst/video/gstvideoutils.h>
G_BEGIN_DECLS
#define GST_TYPE_VIDEO_DECODER \
(gst_video_decoder_get_type())
#define GST_VIDEO_DECODER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_DECODER,GstVideoDecoder))
#define GST_VIDEO_DECODER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_DECODER,GstVideoDecoderClass))
#define GST_VIDEO_DECODER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_VIDEO_DECODER,GstVideoDecoderClass))
#define GST_IS_VIDEO_DECODER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_DECODER))
#define GST_IS_VIDEO_DECODER_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_DECODER))
/**
* GST_VIDEO_DECODER_SINK_NAME:
*
* The name of the templates for the sink pad.
*
* Since: 0.10.36
*/
#define GST_VIDEO_DECODER_SINK_NAME "sink"
/**
* GST_VIDEO_DECODER_SRC_NAME:
*
* The name of the templates for the source pad.
*
* Since: 0.10.36
*/
#define GST_VIDEO_DECODER_SRC_NAME "src"
/**
* GST_VIDEO_DECODER_SRC_PAD:
* @obj: a #GstVideoDecoder
*
* Gives the pointer to the source #GstPad object of the element.
*
* Since: 0.10.36
*/
#define GST_VIDEO_DECODER_SRC_PAD(obj) (((GstVideoDecoder *) (obj))->srcpad)
/**
* GST_VIDEO_DECODER_SINK_PAD:
* @obj: a #GstVideoDecoder
*
* Gives the pointer to the sink #GstPad object of the element.
*
* Since: 0.10.36
*/
#define GST_VIDEO_DECODER_SINK_PAD(obj) (((GstVideoDecoder *) (obj))->sinkpad)
/**
* GST_VIDEO_DECODER_FLOW_NEED_DATA:
*
* Returned while parsing to indicate more data is needed.
*
* Since: 0.10.36
**/
#define GST_VIDEO_DECODER_FLOW_NEED_DATA GST_FLOW_CUSTOM_SUCCESS
/**
* GST_VIDEO_DECODER_FLOW_DROPPED:
*
* Returned when the event/buffer should be dropped.
*
* Since: 0.10.36
*/
#define GST_VIDEO_DECODER_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS_1
/**
* GST_VIDEO_DECODER_INPUT_SEGMENT:
* @obj: base decoder instance
*
* Gives the segment of the element.
*
* Since: 0.10.36
*/
#define GST_VIDEO_DECODER_INPUT_SEGMENT(obj) (GST_VIDEO_DECODER_CAST (obj)->input_segment)
/**
* GST_VIDEO_DECODER_OUTPUT_SEGMENT:
* @obj: base decoder instance
*
* Gives the segment of the element.
*
* Since: 0.10.36
*/
#define GST_VIDEO_DECODER_OUTPUT_SEGMENT(obj) (GST_VIDEO_DECODER_CAST (obj)->output_segment)
/**
* GST_VIDEO_DECODER_STREAM_LOCK:
* @decoder: video decoder instance
*
* Obtain a lock to protect the decoder function from concurrent access.
*
* Since: 0.10.36
*/
#define GST_VIDEO_DECODER_STREAM_LOCK(decoder) g_static_rec_mutex_lock (&GST_VIDEO_DECODER (decoder)->stream_lock)
/**
* GST_VIDEO_DECODER_STREAM_UNLOCK:
* @decoder: video decoder instance
*
* Release the lock that protects the decoder function from concurrent access.
*
* Since: 0.10.36
*/
#define GST_VIDEO_DECODER_STREAM_UNLOCK(decoder) g_static_rec_mutex_unlock (&GST_VIDEO_DECODER (decoder)->stream_lock)
typedef struct _GstVideoDecoder GstVideoDecoder;
typedef struct _GstVideoDecoderClass GstVideoDecoderClass;
typedef struct _GstVideoDecoderPrivate GstVideoDecoderPrivate;
/* do not use this one, use macro below */
GstFlowReturn _gst_video_decoder_error (GstVideoDecoder *dec, gint weight,
GQuark domain, gint code,
gchar *txt, gchar *debug,
const gchar *file, const gchar *function,
gint line);
/**
* GST_VIDEO_DECODER_ERROR:
* @el: the base video decoder element that generates the error
* @weight: element defined weight of the error, added to error count
* @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
* @code: error code defined for that domain (see #gstreamer-GstGError)
* @text: the message to display (format string and args enclosed in
* parentheses)
* @debug: debugging information for the message (format string and args
* enclosed in parentheses)
* @ret: variable to receive return value
*
* Utility function that video decoder elements can use in case they encountered
* a data processing error that may be fatal for the current "data unit" but
* need not prevent subsequent decoding. Such errors are counted and if there
* are too many, as configured in the context's max_errors, the pipeline will
* post an error message and the application will be requested to stop further
* media processing. Otherwise, it is considered a "glitch" and only a warning
* is logged. In either case, @ret is set to the proper value to
* return to upstream/caller (indicating either GST_FLOW_ERROR or GST_FLOW_OK).
*
* Since: 0.10.36
*/
#define GST_VIDEO_DECODER_ERROR(el, w, domain, code, text, debug, ret) \
G_STMT_START { \
gchar *__txt = _gst_element_error_printf text; \
gchar *__dbg = _gst_element_error_printf debug; \
GstVideoDecoder *dec = GST_VIDEO_DECODER (el); \
ret = _gst_video_decoder_error (dec, w, GST_ ## domain ## _ERROR, \
GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__, \
GST_FUNCTION, __LINE__); \
} G_STMT_END
/**
* GST_VIDEO_DECODER_MAX_ERRORS:
*
* Default maximum number of errors tolerated before signaling error.
*
* Since: 0.10.36
*/
#define GST_VIDEO_DECODER_MAX_ERRORS 10
/**
* GstVideoDecoder:
*
* The opaque #GstVideoDecoder data structure.
*
* Since: 0.10.36
*/
struct _GstVideoDecoder
{
/*< 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 */
GStaticRecMutex stream_lock;
/* MT-protected (with STREAM_LOCK) */
GstSegment input_segment;
GstSegment output_segment;
GstVideoDecoderPrivate *priv;
/* FIXME before moving to base */
void *padding[GST_PADDING_LARGE];
};
/**
* GstVideoDecoderClass:
* @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: Notifies subclass of incoming data format (caps).
* @parse: Required for non-packetized input.
* Allows chopping incoming data into manageable units (frames)
* for subsequent decoding.
* @reset: Optional.
* Allows subclass (decoder) to perform post-seek semantics reset.
* @handle_frame: Provides input data frame to subclass.
* @finish: Optional.
* Called to request subclass to dispatch any pending remaining
* data (e.g. at EOS).
* @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).
* @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 can override any of the available virtual methods or not, as
* needed. At minimum @handle_frame needs to be overridden, and @set_format
* and likely as well. If non-packetized input is supported or expected,
* @parse needs to be overridden as well.
*
* Since: 0.10.36
*/
struct _GstVideoDecoderClass
{
/*< private >*/
GstElementClass element_class;
/*< public >*/
gboolean (*open) (GstVideoDecoder *decoder);
gboolean (*close) (GstVideoDecoder *decoder);
gboolean (*start) (GstVideoDecoder *decoder);
gboolean (*stop) (GstVideoDecoder *decoder);
GstFlowReturn (*parse) (GstVideoDecoder *decoder,
GstVideoCodecFrame *frame,
GstAdapter *adapter,
gboolean at_eos);
gboolean (*set_format) (GstVideoDecoder *decoder,
GstVideoCodecState * state);
gboolean (*reset) (GstVideoDecoder *decoder,
gboolean hard);
GstFlowReturn (*finish) (GstVideoDecoder *decoder);
GstFlowReturn (*handle_frame) (GstVideoDecoder *decoder,
GstVideoCodecFrame *frame);
gboolean (*sink_event) (GstVideoDecoder *decoder,
GstEvent *event);
gboolean (*src_event) (GstVideoDecoder *decoder,
GstEvent *event);
/*< private >*/
/* FIXME before moving to base */
void *padding[GST_PADDING_LARGE];
};
GType gst_video_decoder_get_type (void);
/* Context parameters */
void gst_video_decoder_set_packetized (GstVideoDecoder * decoder,
gboolean packetized);
gboolean gst_video_decoder_get_packetized (GstVideoDecoder * decoder);
void gst_video_decoder_set_estimate_rate (GstVideoDecoder * dec,
gboolean enabled);
gint gst_video_decoder_get_estimate_rate (GstVideoDecoder * dec);
void gst_video_decoder_set_max_errors (GstVideoDecoder * dec,
gint num);
gint gst_video_decoder_get_max_errors (GstVideoDecoder * dec);
void gst_video_decoder_set_latency (GstVideoDecoder *decoder,
GstClockTime min_latency,
GstClockTime max_latency);
void gst_video_decoder_get_latency (GstVideoDecoder *decoder,
GstClockTime *min_latency,
GstClockTime *max_latency);
/* Object methods */
GstVideoCodecFrame *gst_video_decoder_get_frame (GstVideoDecoder *decoder,
int frame_number);
GstVideoCodecFrame *gst_video_decoder_get_oldest_frame (GstVideoDecoder *decoder);
/* Parsing related methods */
void gst_video_decoder_add_to_frame (GstVideoDecoder *decoder,
int n_bytes);
GstFlowReturn gst_video_decoder_have_frame (GstVideoDecoder *decoder);
GstBuffer *gst_video_decoder_alloc_output_buffer (GstVideoDecoder * decoder);
GstFlowReturn gst_video_decoder_alloc_output_frame (GstVideoDecoder *decoder,
GstVideoCodecFrame *frame);
GstVideoCodecState *gst_video_decoder_set_output_state (GstVideoDecoder *decoder,
GstVideoFormat fmt, guint width, guint height,
GstVideoCodecState *reference);
GstVideoCodecState *gst_video_decoder_get_output_state (GstVideoDecoder *decoder);
GstClockTimeDiff gst_video_decoder_get_max_decode_time (GstVideoDecoder *decoder,
GstVideoCodecFrame *frame);
GstFlowReturn gst_video_decoder_finish_frame (GstVideoDecoder *decoder,
GstVideoCodecFrame *frame);
GstFlowReturn gst_video_decoder_drop_frame (GstVideoDecoder *dec,
GstVideoCodecFrame *frame);
G_END_DECLS
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
EXPORTS
_gst_video_decoder_error
gst_video_buffer_get_overlay_composition
gst_video_buffer_set_overlay_composition
gst_video_calculate_display_ratio
gst_video_codec_frame_get_type
gst_video_codec_frame_ref
gst_video_codec_frame_set_hook
gst_video_codec_frame_unref
gst_video_codec_state_get_type
gst_video_codec_state_ref