2009-07-01 17:55:12 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 David Schleef <ds@schleef.org>
|
|
|
|
*
|
|
|
|
* 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_BASE_VIDEO_CODEC_H_
|
|
|
|
#define _GST_BASE_VIDEO_CODEC_H_
|
|
|
|
|
2009-07-03 15:08:38 +00:00
|
|
|
#ifndef GST_USE_UNSTABLE_API
|
|
|
|
#warning "GstBaseVideoCodec is unstable API and may change in future."
|
|
|
|
#warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
|
|
|
|
#endif
|
|
|
|
|
2009-07-01 17:55:12 +00:00
|
|
|
#include <gst/gst.h>
|
2011-02-20 22:16:18 +00:00
|
|
|
#include <gst/base/gstadapter.h>
|
|
|
|
#include <gst/video/video.h>
|
2011-11-03 12:56:49 +00:00
|
|
|
#include <gst/video/gstvideopool.h>
|
2011-11-03 15:57:17 +00:00
|
|
|
#include <gst/video/gstvideometa.h>
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
#define GST_TYPE_BASE_VIDEO_CODEC \
|
|
|
|
(gst_base_video_codec_get_type())
|
|
|
|
#define GST_BASE_VIDEO_CODEC(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_VIDEO_CODEC,GstBaseVideoCodec))
|
|
|
|
#define GST_BASE_VIDEO_CODEC_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_VIDEO_CODEC,GstBaseVideoCodecClass))
|
|
|
|
#define GST_BASE_VIDEO_CODEC_GET_CLASS(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_BASE_VIDEO_CODEC,GstBaseVideoCodecClass))
|
|
|
|
#define GST_IS_BASE_VIDEO_CODEC(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_VIDEO_CODEC))
|
|
|
|
#define GST_IS_BASE_VIDEO_CODEC_CLASS(obj) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_VIDEO_CODEC))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GST_BASE_VIDEO_CODEC_SINK_NAME:
|
|
|
|
*
|
|
|
|
* The name of the templates for the sink pad.
|
|
|
|
*/
|
|
|
|
#define GST_BASE_VIDEO_CODEC_SINK_NAME "sink"
|
|
|
|
/**
|
|
|
|
* GST_BASE_VIDEO_CODEC_SRC_NAME:
|
|
|
|
*
|
|
|
|
* The name of the templates for the source pad.
|
|
|
|
*/
|
|
|
|
#define GST_BASE_VIDEO_CODEC_SRC_NAME "src"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GST_BASE_VIDEO_CODEC_SRC_PAD:
|
|
|
|
* @obj: base video codec instance
|
|
|
|
*
|
|
|
|
* Gives the pointer to the source #GstPad object of the element.
|
|
|
|
*/
|
|
|
|
#define GST_BASE_VIDEO_CODEC_SRC_PAD(obj) (((GstBaseVideoCodec *) (obj))->srcpad)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GST_BASE_VIDEO_CODEC_SINK_PAD:
|
|
|
|
* @obj: base video codec instance
|
|
|
|
*
|
|
|
|
* Gives the pointer to the sink #GstPad object of the element.
|
|
|
|
*/
|
|
|
|
#define GST_BASE_VIDEO_CODEC_SINK_PAD(obj) (((GstBaseVideoCodec *) (obj))->sinkpad)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GST_BASE_VIDEO_CODEC_FLOW_NEED_DATA:
|
|
|
|
*
|
2012-03-06 17:49:11 +00:00
|
|
|
* Returned while parsing to indicate more data is needed.
|
2009-07-01 17:55:12 +00:00
|
|
|
*/
|
|
|
|
#define GST_BASE_VIDEO_CODEC_FLOW_NEED_DATA GST_FLOW_CUSTOM_SUCCESS
|
|
|
|
|
2012-03-06 17:49:11 +00:00
|
|
|
/**
|
|
|
|
* GST_BASE_VIDEO_CODEC_STREAM_LOCK:
|
|
|
|
* @codec: video codec instance
|
|
|
|
*
|
|
|
|
* Obtain a lock to protect the codec function from concurrent access.
|
|
|
|
*
|
|
|
|
* Since: 0.10.22
|
|
|
|
*/
|
2012-01-19 10:34:26 +00:00
|
|
|
#define GST_BASE_VIDEO_CODEC_STREAM_LOCK(codec) g_rec_mutex_lock (&GST_BASE_VIDEO_CODEC (codec)->stream_lock)
|
2012-03-06 17:49:11 +00:00
|
|
|
/**
|
|
|
|
* GST_BASE_VIDEO_CODEC_STREAM_UNLOCK:
|
|
|
|
* @codec: video codec instance
|
|
|
|
*
|
|
|
|
* Release the lock that protects the codec function from concurrent access.
|
|
|
|
*
|
|
|
|
* Since: 0.10.22
|
|
|
|
*/
|
2012-01-19 10:34:26 +00:00
|
|
|
#define GST_BASE_VIDEO_CODEC_STREAM_UNLOCK(codec) g_rec_mutex_unlock (&GST_BASE_VIDEO_CODEC (codec)->stream_lock)
|
2011-08-18 08:02:50 +00:00
|
|
|
|
2011-02-20 22:16:18 +00:00
|
|
|
typedef struct _GstVideoState GstVideoState;
|
2011-10-04 12:27:32 +00:00
|
|
|
typedef struct _GstVideoFrameState GstVideoFrameState;
|
2009-07-01 17:55:12 +00:00
|
|
|
typedef struct _GstBaseVideoCodec GstBaseVideoCodec;
|
|
|
|
typedef struct _GstBaseVideoCodecClass GstBaseVideoCodecClass;
|
|
|
|
|
2012-02-21 15:52:49 +00:00
|
|
|
/* GstVideoState is only used on the compressed video pad */
|
|
|
|
/**
|
|
|
|
* GstVideoState:
|
|
|
|
* @width: Width in pixels (including borders)
|
|
|
|
* @height: Height in pixels (including borders)
|
|
|
|
* @fps_n: Numerator of framerate
|
|
|
|
* @fps_d: Denominator of framerate
|
|
|
|
* @par_n: Numerator of Pixel Aspect Ratio
|
|
|
|
* @par_d: Denominator of Pixel Aspect Ratio
|
|
|
|
* @have_interlaced: The content of the @interlaced field is present and valid
|
|
|
|
* @interlaced: %TRUE if the stream is interlaced
|
|
|
|
* @top_field_first: %TRUE if the interlaced frame is top-field-first
|
|
|
|
* @clean_width: Useful width of video in pixels (i.e. without borders)
|
|
|
|
* @clean_height: Useful height of video in pixels (i.e. without borders)
|
|
|
|
* @clean_offset_left: Horizontal offset (from the left) of useful region in pixels
|
|
|
|
* @clean_offset_top: Vertical offset (from the top) of useful region in pixels
|
|
|
|
* @bytes_per_picture: Size in bytes of each picture
|
|
|
|
* @codec_data: Optional Codec Data for the stream
|
|
|
|
*
|
|
|
|
* Information about compressed video stream.
|
|
|
|
* FIXME: Re-use GstVideoInfo for more fields.
|
|
|
|
*/
|
2011-02-20 22:16:18 +00:00
|
|
|
struct _GstVideoState
|
|
|
|
{
|
2011-06-27 07:41:40 +00:00
|
|
|
GstCaps *caps;
|
2011-02-20 22:16:18 +00:00
|
|
|
GstVideoFormat format;
|
|
|
|
int width, height;
|
|
|
|
int fps_n, fps_d;
|
|
|
|
int par_n, par_d;
|
|
|
|
|
|
|
|
gboolean have_interlaced;
|
|
|
|
gboolean interlaced;
|
|
|
|
gboolean top_field_first;
|
|
|
|
|
|
|
|
int clean_width, clean_height;
|
|
|
|
int clean_offset_left, clean_offset_top;
|
|
|
|
|
|
|
|
int bytes_per_picture;
|
|
|
|
|
|
|
|
GstBuffer *codec_data;
|
|
|
|
};
|
|
|
|
|
2012-02-21 15:52:49 +00:00
|
|
|
/**
|
|
|
|
* GstVideoFrameState:
|
|
|
|
* @decode_timestamp: Decoding timestamp (aka DTS)
|
|
|
|
* @presentation_timestamp: Presentation timestamp (aka PTS)
|
|
|
|
* @presentation_duration: Duration of frame
|
|
|
|
* @system_frame_number: unique ID attributed when #GstVideoFrameState is
|
|
|
|
* created
|
|
|
|
* @decode_frame_number: Decoded frame number, increases in decoding order
|
|
|
|
* @presentation_frame_number: Presentation frame number, increases in
|
|
|
|
* presentation order.
|
|
|
|
* @distance_from_sync: Distance of the frame from a sync point, in number
|
|
|
|
* of frames.
|
|
|
|
* @is_sync_point: #TRUE if the frame is a synchronization point (like a
|
|
|
|
* keyframe)
|
|
|
|
* @is_eos: #TRUE if the frame is the last one of a segment.
|
|
|
|
* @decode_only: If #TRUE, the frame is only meant to be decoded but not
|
|
|
|
* pushed downstream
|
|
|
|
* @sink_buffer: input buffer
|
|
|
|
* @src_buffer: output buffer
|
|
|
|
* @field_index: Number of fields since beginning of stream
|
|
|
|
* @n_fields: Number of fields present in frame (default 2)
|
|
|
|
* @coder_hook: Private data called with @coder_hook_destroy_notify
|
|
|
|
* @coder_hook_destroy_notify: Called when frame is destroyed
|
|
|
|
* @deadline: Target clock time for display (running time)
|
|
|
|
* @force_keyframe: For encoders, if #TRUE a keyframe must be generated
|
|
|
|
* @force_keyframe_headers: For encoders, if #TRUE new headers must be generated
|
|
|
|
* @events: List of #GstEvent that must be pushed before the next @src_buffer
|
|
|
|
*
|
|
|
|
* State of a video frame going through the codec
|
|
|
|
**/
|
|
|
|
|
2011-10-04 12:27:32 +00:00
|
|
|
struct _GstVideoFrameState
|
2011-02-20 22:16:18 +00:00
|
|
|
{
|
2012-02-21 15:52:49 +00:00
|
|
|
/*< private >*/
|
2011-12-05 17:57:01 +00:00
|
|
|
gint ref_count;
|
|
|
|
|
2012-02-21 15:52:49 +00:00
|
|
|
/*< public >*/
|
2011-02-20 22:16:18 +00:00
|
|
|
GstClockTime decode_timestamp;
|
|
|
|
GstClockTime presentation_timestamp;
|
|
|
|
GstClockTime presentation_duration;
|
|
|
|
|
|
|
|
gint system_frame_number;
|
|
|
|
gint decode_frame_number;
|
|
|
|
gint presentation_frame_number;
|
|
|
|
|
|
|
|
int distance_from_sync;
|
|
|
|
gboolean is_sync_point;
|
|
|
|
gboolean is_eos;
|
|
|
|
|
2012-01-04 10:09:23 +00:00
|
|
|
/* Frames that should not be pushed downstream and are
|
|
|
|
* not meant for display */
|
|
|
|
gboolean decode_only;
|
|
|
|
|
2011-02-20 22:16:18 +00:00
|
|
|
GstBuffer *sink_buffer;
|
|
|
|
GstBuffer *src_buffer;
|
|
|
|
|
|
|
|
int field_index;
|
|
|
|
int n_fields;
|
|
|
|
|
|
|
|
void *coder_hook;
|
2011-07-09 08:57:52 +00:00
|
|
|
GDestroyNotify coder_hook_destroy_notify;
|
|
|
|
|
2011-02-20 22:16:18 +00:00
|
|
|
GstClockTime deadline;
|
|
|
|
|
|
|
|
gboolean force_keyframe;
|
2011-11-29 11:12:33 +00:00
|
|
|
gboolean force_keyframe_headers;
|
2011-06-28 09:47:25 +00:00
|
|
|
|
|
|
|
/* Events that should be pushed downstream *before*
|
|
|
|
* the next src_buffer */
|
|
|
|
GList *events;
|
2011-02-20 22:16:18 +00:00
|
|
|
};
|
|
|
|
|
2012-03-06 17:49:11 +00:00
|
|
|
/**
|
|
|
|
* GstBaseVideoCodec:
|
|
|
|
*
|
|
|
|
* The opaque #GstBaseVideoCodec data structure.
|
|
|
|
*/
|
2009-07-01 17:55:12 +00:00
|
|
|
struct _GstBaseVideoCodec
|
|
|
|
{
|
|
|
|
/*< private >*/
|
2012-03-06 17:49:11 +00:00
|
|
|
GstElement element;
|
|
|
|
|
|
|
|
/*< protected >*/
|
|
|
|
GstPad *sinkpad;
|
|
|
|
GstPad *srcpad;
|
2009-07-01 17:55:12 +00:00
|
|
|
|
2011-08-18 08:02:50 +00:00
|
|
|
/* protects all data processing, i.e. is locked
|
|
|
|
* in the chain function, finish_frame and when
|
|
|
|
* processing serialized events */
|
2012-01-19 10:34:26 +00:00
|
|
|
GRecMutex stream_lock;
|
2011-08-18 08:02:50 +00:00
|
|
|
|
2012-03-06 17:49:11 +00:00
|
|
|
guint64 system_frame_number;
|
2010-10-10 00:36:07 +00:00
|
|
|
|
2011-07-11 09:28:40 +00:00
|
|
|
GList *frames; /* Protected with OBJECT_LOCK */
|
2011-11-03 12:56:49 +00:00
|
|
|
GstVideoState state; /* Compressed video pad */
|
|
|
|
GstVideoInfo info; /* Raw video pad */
|
2010-10-10 00:36:07 +00:00
|
|
|
GstSegment segment;
|
|
|
|
|
2012-03-06 17:49:11 +00:00
|
|
|
/* QoS properties */
|
|
|
|
gdouble proportion;
|
|
|
|
GstClockTime earliest_time;
|
|
|
|
gboolean discont;
|
2010-10-10 00:36:07 +00:00
|
|
|
|
2012-03-06 17:49:11 +00:00
|
|
|
gint64 bytes;
|
|
|
|
gint64 time;
|
2011-03-28 09:15:49 +00:00
|
|
|
|
2010-10-10 00:36:07 +00:00
|
|
|
/* FIXME before moving to base */
|
2012-03-06 17:49:11 +00:00
|
|
|
void *padding[GST_PADDING_LARGE];
|
2009-07-01 17:55:12 +00:00
|
|
|
};
|
|
|
|
|
2012-03-06 17:49:11 +00:00
|
|
|
/**
|
|
|
|
* GstBaseVideoCodecClass:
|
|
|
|
*
|
|
|
|
* The opaque #GstBaseVideoCodecClass data structure.
|
|
|
|
*/
|
2009-07-01 17:55:12 +00:00
|
|
|
struct _GstBaseVideoCodecClass
|
|
|
|
{
|
2012-03-06 17:49:11 +00:00
|
|
|
/*< private >*/
|
2009-07-01 17:55:12 +00:00
|
|
|
GstElementClass element_class;
|
|
|
|
|
2010-10-10 00:36:07 +00:00
|
|
|
/* FIXME before moving to base */
|
|
|
|
void *padding[GST_PADDING_LARGE];
|
2009-07-01 17:55:12 +00:00
|
|
|
};
|
|
|
|
|
2011-12-05 17:57:01 +00:00
|
|
|
GType gst_video_frame_state_get_type (void);
|
2009-07-01 17:55:12 +00:00
|
|
|
GType gst_base_video_codec_get_type (void);
|
|
|
|
|
2011-12-05 17:57:01 +00:00
|
|
|
void gst_base_video_codec_append_frame (GstBaseVideoCodec *codec, GstVideoFrameState *frame);
|
|
|
|
void gst_base_video_codec_remove_frame (GstBaseVideoCodec *codec, GstVideoFrameState *frame);
|
|
|
|
|
2011-10-04 12:27:32 +00:00
|
|
|
GstVideoFrameState * gst_base_video_codec_new_frame (GstBaseVideoCodec *base_video_codec);
|
2011-12-05 17:57:01 +00:00
|
|
|
|
|
|
|
GstVideoFrameState * gst_video_frame_state_ref (GstVideoFrameState * frame);
|
|
|
|
void gst_video_frame_state_unref (GstVideoFrameState * frame);
|
2009-07-01 17:55:12 +00:00
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|