basevideocodec: remove parser in favor of baseparse

This commit is contained in:
David Schleef 2011-02-19 13:07:39 -08:00
parent 493082abd7
commit 5b90c31ca2
6 changed files with 2 additions and 1598 deletions

View file

@ -8,7 +8,6 @@ libgstschro_la_SOURCES = \
gstschro.c \
gstschrodec.c \
gstschroenc.c \
gstschroparse.c \
gstschroutils.c
libgstschro_la_CFLAGS = \
$(GST_PLUGINS_BAD_CFLAGS) \

View file

@ -26,7 +26,6 @@
GType gst_schro_enc_get_type (void);
GType gst_schro_dec_get_type (void);
GType gst_schro_parse_get_type (void);
GST_DEBUG_CATEGORY (schro_debug);
#define GST_CAT_DEFAULT schro_debug
@ -39,8 +38,6 @@ plugin_init (GstPlugin * plugin)
GST_DEBUG_CATEGORY_INIT (schro_debug, "schro", 0, "Schroedinger");
gst_element_register (plugin, "schrodec", GST_RANK_PRIMARY,
gst_schro_dec_get_type ());
gst_element_register (plugin, "schroparse", GST_RANK_NONE,
gst_schro_parse_get_type ());
gst_element_register (plugin, "schroenc", GST_RANK_PRIMARY,
gst_schro_enc_get_type ());

View file

@ -1,586 +0,0 @@
/* Schrodinger
* Copyright (C) 2006 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <gst/base/gstadapter.h>
#include <gst/video/video.h>
#include <gst/video/gstbasevideoparse.h>
#include <string.h>
#include <schroedinger/schro.h>
#include <math.h>
#include <schroedinger/schroparse.h>
GST_DEBUG_CATEGORY_EXTERN (schro_debug);
#define GST_CAT_DEFAULT schro_debug
#define GST_TYPE_SCHRO_PARSE \
(gst_schro_parse_get_type())
#define GST_SCHRO_PARSE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SCHRO_PARSE,GstSchroParse))
#define GST_SCHRO_PARSE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SCHRO_PARSE,GstSchroParseClass))
#define GST_IS_SCHRO_PARSE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SCHRO_PARSE))
#define GST_IS_SCHRO_PARSE_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SCHRO_PARSE))
typedef struct _GstSchroParse GstSchroParse;
typedef struct _GstSchroParseClass GstSchroParseClass;
typedef enum
{
GST_SCHRO_PARSE_OUTPUT_OGG,
GST_SCHRO_PARSE_OUTPUT_QUICKTIME,
GST_SCHRO_PARSE_OUTPUT_AVI,
GST_SCHRO_PARSE_OUTPUT_MPEG_TS,
GST_SCHRO_PARSE_OUTPUT_MP4
} GstSchroParseOutputType;
struct _GstSchroParse
{
GstBaseVideoParse base_video_parse;
GstPad *sinkpad, *srcpad;
GstSchroParseOutputType output_format;
GstBuffer *seq_header_buffer;
/* state */
gboolean have_picture;
int buf_picture_number;
int seq_hdr_picture_number;
int picture_number;
guint64 last_granulepos;
int bytes_per_picture;
};
struct _GstSchroParseClass
{
GstBaseVideoParseClass base_video_parse_class;
};
GType gst_schro_parse_get_type (void);
/* GstSchroParse signals and args */
enum
{
LAST_SIGNAL
};
enum
{
ARG_0
};
static gboolean gst_schro_parse_start (GstBaseVideoParse * base_video_parse);
static gboolean gst_schro_parse_stop (GstBaseVideoParse * base_video_parse);
static gboolean gst_schro_parse_reset (GstBaseVideoParse * base_video_parse);
static int gst_schro_parse_scan_for_sync (GstAdapter * adapter,
gboolean at_eos, int offset, int n);
static gboolean gst_schro_parse_parse_data (GstBaseVideoParse *
base_video_parse, gboolean at_eos);
static gboolean gst_schro_parse_shape_output (GstBaseVideoParse *
base_video_parse, GstVideoFrame * frame);
static GstCaps *gst_schro_parse_get_caps (GstBaseVideoParse * base_video_parse);
static GstStaticPadTemplate gst_schro_parse_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-dirac")
);
static GstStaticPadTemplate gst_schro_parse_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS
("video/x-dirac;video/x-qt-part;video/x-avi-part;video/x-mp4-part")
);
GST_BOILERPLATE (GstSchroParse, gst_schro_parse, GstBaseVideoParse,
GST_TYPE_BASE_VIDEO_PARSE);
static void
gst_schro_parse_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_schro_parse_src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_schro_parse_sink_template));
gst_element_class_set_details_simple (element_class, "Dirac Parser",
"Codec/Parser/Video",
"Parse Dirac streams", "David Schleef <ds@schleef.org>");
}
static void
gst_schro_parse_class_init (GstSchroParseClass * klass)
{
GstBaseVideoParseClass *base_video_parse_class;
base_video_parse_class = GST_BASE_VIDEO_PARSE_CLASS (klass);
base_video_parse_class->start = GST_DEBUG_FUNCPTR (gst_schro_parse_start);
base_video_parse_class->stop = GST_DEBUG_FUNCPTR (gst_schro_parse_stop);
base_video_parse_class->reset = GST_DEBUG_FUNCPTR (gst_schro_parse_reset);
base_video_parse_class->parse_data =
GST_DEBUG_FUNCPTR (gst_schro_parse_parse_data);
base_video_parse_class->shape_output =
GST_DEBUG_FUNCPTR (gst_schro_parse_shape_output);
base_video_parse_class->scan_for_sync =
GST_DEBUG_FUNCPTR (gst_schro_parse_scan_for_sync);
base_video_parse_class->get_caps =
GST_DEBUG_FUNCPTR (gst_schro_parse_get_caps);
}
static void
gst_schro_parse_init (GstSchroParse * schro_parse, GstSchroParseClass * klass)
{
GstBaseVideoParse *base_video_parse = GST_BASE_VIDEO_PARSE (schro_parse);
GST_DEBUG ("gst_schro_parse_init");
schro_parse->output_format = GST_SCHRO_PARSE_OUTPUT_OGG;
base_video_parse->reorder_depth = 2;
}
static gboolean
gst_schro_parse_reset (GstBaseVideoParse * base_video_parse)
{
GST_DEBUG ("reset");
return TRUE;
}
static gboolean
gst_schro_parse_start (GstBaseVideoParse * base_video_parse)
{
GstSchroParse *schro_parse = GST_SCHRO_PARSE (base_video_parse);
GstCaps *caps;
GstStructure *structure;
GST_DEBUG ("start");
caps =
gst_pad_get_allowed_caps (GST_BASE_VIDEO_CODEC_SRC_PAD
(base_video_parse));
if (gst_caps_is_empty (caps)) {
gst_caps_unref (caps);
return FALSE;
}
structure = gst_caps_get_structure (caps, 0);
if (gst_structure_has_name (structure, "video/x-dirac")) {
schro_parse->output_format = GST_SCHRO_PARSE_OUTPUT_OGG;
} else if (gst_structure_has_name (structure, "video/x-qt-part")) {
schro_parse->output_format = GST_SCHRO_PARSE_OUTPUT_QUICKTIME;
} else if (gst_structure_has_name (structure, "video/x-avi-part")) {
schro_parse->output_format = GST_SCHRO_PARSE_OUTPUT_AVI;
} else if (gst_structure_has_name (structure, "video/x-mpegts-part")) {
schro_parse->output_format = GST_SCHRO_PARSE_OUTPUT_MPEG_TS;
} else if (gst_structure_has_name (structure, "video/x-mp4-part")) {
schro_parse->output_format = GST_SCHRO_PARSE_OUTPUT_MP4;
} else {
return FALSE;
}
gst_caps_unref (caps);
return TRUE;
}
static gboolean
gst_schro_parse_stop (GstBaseVideoParse * base_video_parse)
{
return TRUE;
}
static void
parse_sequence_header (GstSchroParse * schro_parse, guint8 * data, int size)
{
SchroVideoFormat video_format;
int ret;
GstVideoState *state;
GST_DEBUG ("parse_sequence_header size=%d", size);
state = gst_base_video_parse_get_state (GST_BASE_VIDEO_PARSE (schro_parse));
schro_parse->seq_header_buffer = gst_buffer_new_and_alloc (size);
memcpy (GST_BUFFER_DATA (schro_parse->seq_header_buffer), data, size);
ret = schro_parse_decode_sequence_header (data + 13, size - 13,
&video_format);
if (ret) {
state->fps_n = video_format.frame_rate_numerator;
state->fps_d = video_format.frame_rate_denominator;
GST_DEBUG ("Frame rate is %d/%d", state->fps_n, state->fps_d);
state->width = video_format.width;
state->height = video_format.height;
GST_DEBUG ("Frame dimensions are %d x %d\n", state->width, state->height);
state->clean_width = video_format.clean_width;
state->clean_height = video_format.clean_height;
state->clean_offset_left = video_format.left_offset;
state->clean_offset_top = video_format.top_offset;
state->par_n = video_format.aspect_ratio_numerator;
state->par_d = video_format.aspect_ratio_denominator;
GST_DEBUG ("Pixel aspect ratio is %d/%d", state->par_n, state->par_d);
gst_base_video_parse_set_state (GST_BASE_VIDEO_PARSE (schro_parse), state);
} else {
GST_WARNING ("Failed to get frame rate from sequence header");
}
}
static int
gst_schro_parse_scan_for_sync (GstAdapter * adapter, gboolean at_eos,
int offset, int n)
{
int n_available = gst_adapter_available (adapter) - offset;
if (n_available < 4) {
if (at_eos) {
return n_available;
} else {
return 0;
}
}
n_available -= 3;
return gst_adapter_masked_scan_uint32 (adapter, 0xffffffff, 0x42424344,
offset, MIN (n, n_available - 3));
}
static GstFlowReturn
gst_schro_parse_parse_data (GstBaseVideoParse * base_video_parse,
gboolean at_eos)
{
GstSchroParse *schro_parse;
unsigned char header[SCHRO_PARSE_HEADER_SIZE];
int next;
int prev;
int parse_code;
GST_DEBUG ("parse_data");
schro_parse = GST_SCHRO_PARSE (base_video_parse);
if (gst_adapter_available (base_video_parse->input_adapter) <
SCHRO_PARSE_HEADER_SIZE) {
return GST_BASE_VIDEO_PARSE_FLOW_NEED_DATA;
}
GST_DEBUG ("available %d",
gst_adapter_available (base_video_parse->input_adapter));
gst_adapter_copy (base_video_parse->input_adapter, header, 0,
SCHRO_PARSE_HEADER_SIZE);
parse_code = header[4];
next = GST_READ_UINT32_BE (header + 5);
prev = GST_READ_UINT32_BE (header + 9);
GST_DEBUG ("%08x %02x %08x %08x",
GST_READ_UINT32_BE (header), parse_code, next, prev);
if (memcmp (header, "BBCD", 4) != 0 ||
(next & 0xf0000000) || (prev & 0xf0000000)) {
gst_base_video_parse_lost_sync (base_video_parse);
return GST_BASE_VIDEO_PARSE_FLOW_NEED_DATA;
}
if (SCHRO_PARSE_CODE_IS_END_OF_SEQUENCE (parse_code)) {
GstVideoFrame *frame;
if (next != 0 && next != SCHRO_PARSE_HEADER_SIZE) {
GST_WARNING ("next is not 0 or 13 in EOS packet (%d)", next);
}
gst_base_video_parse_add_to_frame (base_video_parse,
SCHRO_PARSE_HEADER_SIZE);
frame = gst_base_video_parse_get_frame (base_video_parse);
frame->is_eos = TRUE;
SCHRO_DEBUG ("eos");
return gst_base_video_parse_finish_frame (base_video_parse);
}
if (gst_adapter_available (base_video_parse->input_adapter) < next) {
return GST_BASE_VIDEO_PARSE_FLOW_NEED_DATA;
}
if (SCHRO_PARSE_CODE_IS_SEQ_HEADER (parse_code)) {
guint8 *data;
data = g_malloc (next);
gst_adapter_copy (base_video_parse->input_adapter, data, 0, next);
parse_sequence_header (schro_parse, data, next);
base_video_parse->current_frame->is_sync_point = TRUE;
g_free (data);
}
if (schro_parse->seq_header_buffer == NULL) {
gst_adapter_flush (base_video_parse->input_adapter, next);
return GST_FLOW_OK;
}
if (SCHRO_PARSE_CODE_IS_PICTURE (parse_code)) {
GstVideoFrame *frame;
guint8 tmp[4];
frame = gst_base_video_parse_get_frame (base_video_parse);
#if 0
if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buf))) {
frame->presentation_timestamp = GST_BUFFER_TIMESTAMP (buf);
}
#endif
gst_adapter_copy (base_video_parse->input_adapter, tmp,
SCHRO_PARSE_HEADER_SIZE, 4);
frame->presentation_frame_number = GST_READ_UINT32_BE (tmp);
gst_base_video_parse_add_to_frame (base_video_parse, next);
return gst_base_video_parse_finish_frame (base_video_parse);
} else {
gst_base_video_parse_add_to_frame (base_video_parse, next);
}
return GST_FLOW_OK;
}
static GstFlowReturn
gst_schro_parse_shape_output_ogg (GstBaseVideoParse * base_video_parse,
GstVideoFrame * frame)
{
GstSchroParse *schro_parse;
int dpn;
int delay;
int dist;
int pt;
int dt;
guint64 granulepos_hi;
guint64 granulepos_low;
GstBuffer *buf = frame->src_buffer;
schro_parse = GST_SCHRO_PARSE (base_video_parse);
dpn = frame->decode_frame_number;
pt = frame->presentation_frame_number * 2;
dt = frame->decode_frame_number * 2;
delay = pt - dt;
dist = frame->distance_from_sync;
GST_DEBUG ("sys %d dpn %d pt %d dt %d delay %d dist %d",
(int) frame->system_frame_number,
(int) frame->decode_frame_number, pt, dt, delay, dist);
granulepos_hi = (((guint64) pt - delay) << 9) | ((dist >> 8));
granulepos_low = (delay << 9) | (dist & 0xff);
GST_DEBUG ("granulepos %" G_GINT64_FORMAT ":%" G_GINT64_FORMAT, granulepos_hi,
granulepos_low);
if (frame->is_eos) {
GST_BUFFER_OFFSET_END (buf) = schro_parse->last_granulepos;
} else {
schro_parse->last_granulepos = (granulepos_hi << 22) | (granulepos_low);
GST_BUFFER_OFFSET_END (buf) = schro_parse->last_granulepos;
}
return gst_base_video_parse_push (base_video_parse, buf);
}
static GstFlowReturn
gst_schro_parse_shape_output_quicktime (GstBaseVideoParse * base_video_parse,
GstVideoFrame * frame)
{
GstBuffer *buf = frame->src_buffer;
const GstVideoState *state;
state = gst_base_video_parse_get_state (base_video_parse);
GST_BUFFER_OFFSET_END (buf) = gst_video_state_get_timestamp (state,
&base_video_parse->segment, frame->system_frame_number);
if (frame->is_sync_point &&
frame->presentation_frame_number == frame->system_frame_number) {
GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
GST_DEBUG ("sync point");
} else {
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
}
return gst_base_video_parse_push (base_video_parse, buf);
}
static GstFlowReturn
gst_schro_parse_shape_output_mpeg_ts (GstBaseVideoParse * base_video_parse,
GstVideoFrame * frame)
{
GstBuffer *buf = frame->src_buffer;
return gst_base_video_parse_push (base_video_parse, buf);
}
static GstFlowReturn
gst_schro_parse_shape_output (GstBaseVideoParse * base_video_parse,
GstVideoFrame * frame)
{
GstSchroParse *schro_parse;
schro_parse = GST_SCHRO_PARSE (base_video_parse);
switch (schro_parse->output_format) {
case GST_SCHRO_PARSE_OUTPUT_OGG:
return gst_schro_parse_shape_output_ogg (base_video_parse, frame);
case GST_SCHRO_PARSE_OUTPUT_QUICKTIME:
return gst_schro_parse_shape_output_quicktime (base_video_parse, frame);
case GST_SCHRO_PARSE_OUTPUT_MPEG_TS:
return gst_schro_parse_shape_output_mpeg_ts (base_video_parse, frame);
default:
break;
}
return GST_FLOW_ERROR;
}
static GstCaps *
gst_schro_parse_get_caps (GstBaseVideoParse * base_video_parse)
{
GstCaps *caps;
GstVideoState *state;
GstSchroParse *schro_parse;
schro_parse = GST_SCHRO_PARSE (base_video_parse);
state = gst_base_video_parse_get_state (base_video_parse);
if (schro_parse->output_format == GST_SCHRO_PARSE_OUTPUT_OGG) {
caps = gst_caps_new_simple ("video/x-dirac",
"width", G_TYPE_INT, state->width,
"height", G_TYPE_INT, state->height,
"framerate", GST_TYPE_FRACTION, state->fps_n,
state->fps_d,
"pixel-aspect-ratio", GST_TYPE_FRACTION, state->par_n,
state->par_d, NULL);
GST_BUFFER_FLAG_SET (schro_parse->seq_header_buffer,
GST_BUFFER_FLAG_IN_CAPS);
{
GValue array = { 0 };
GValue value = { 0 };
GstBuffer *buf;
int size;
g_value_init (&array, GST_TYPE_ARRAY);
g_value_init (&value, GST_TYPE_BUFFER);
size = GST_BUFFER_SIZE (schro_parse->seq_header_buffer);
buf = gst_buffer_new_and_alloc (size + SCHRO_PARSE_HEADER_SIZE);
memcpy (GST_BUFFER_DATA (buf),
GST_BUFFER_DATA (schro_parse->seq_header_buffer), size);
GST_WRITE_UINT32_BE (GST_BUFFER_DATA (buf) + size + 0, 0x42424344);
GST_WRITE_UINT8 (GST_BUFFER_DATA (buf) + size + 4,
SCHRO_PARSE_CODE_END_OF_SEQUENCE);
GST_WRITE_UINT32_BE (GST_BUFFER_DATA (buf) + size + 5, 0);
GST_WRITE_UINT32_BE (GST_BUFFER_DATA (buf) + size + 9, size);
gst_value_set_buffer (&value, buf);
gst_buffer_unref (buf);
gst_value_array_append_value (&array, &value);
gst_structure_set_value (gst_caps_get_structure (caps, 0),
"streamheader", &array);
g_value_unset (&value);
g_value_unset (&array);
}
} else if (schro_parse->output_format == GST_SCHRO_PARSE_OUTPUT_QUICKTIME) {
caps = gst_caps_new_simple ("video/x-qt-part",
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('d', 'r', 'a', 'c'),
"width", G_TYPE_INT, state->width,
"height", G_TYPE_INT, state->height,
"framerate", GST_TYPE_FRACTION, state->fps_n,
state->fps_d,
"pixel-aspect-ratio", GST_TYPE_FRACTION, state->par_n,
state->par_d, NULL);
} else if (schro_parse->output_format == GST_SCHRO_PARSE_OUTPUT_AVI) {
caps = gst_caps_new_simple ("video/x-avi-part",
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('d', 'r', 'a', 'c'),
"width", G_TYPE_INT, state->width,
"height", G_TYPE_INT, state->height,
"framerate", GST_TYPE_FRACTION, state->fps_n,
state->fps_d,
"pixel-aspect-ratio", GST_TYPE_FRACTION, state->par_n,
state->par_d, NULL);
} else if (schro_parse->output_format == GST_SCHRO_PARSE_OUTPUT_MPEG_TS) {
caps = gst_caps_new_simple ("video/x-mpegts-part",
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('d', 'r', 'a', 'c'),
"width", G_TYPE_INT, state->width,
"height", G_TYPE_INT, state->height,
"framerate", GST_TYPE_FRACTION, state->fps_n,
state->fps_d,
"pixel-aspect-ratio", GST_TYPE_FRACTION, state->par_n,
state->par_d, NULL);
} else if (schro_parse->output_format == GST_SCHRO_PARSE_OUTPUT_MP4) {
caps = gst_caps_new_simple ("video/x-mp4-part",
"format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('d', 'r', 'a', 'c'),
"width", G_TYPE_INT, state->width,
"height", G_TYPE_INT, state->height,
"framerate", GST_TYPE_FRACTION, state->fps_n,
state->fps_d,
"pixel-aspect-ratio", GST_TYPE_FRACTION, state->par_n,
state->par_d, NULL);
} else {
g_assert_not_reached ();
caps = NULL;
}
return caps;
}

View file

@ -7,16 +7,14 @@ libgstbasevideo_@GST_MAJORMINOR@_la_SOURCES = \
gstbasevideoutils.c \
gstbasevideocodec.c \
gstbasevideodecoder.c \
gstbasevideoencoder.c \
gstbasevideoparse.c
gstbasevideoencoder.c
libgstbasevideo_@GST_MAJORMINOR@includedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/video
libgstbasevideo_@GST_MAJORMINOR@include_HEADERS = \
gstbasevideoutils.h \
gstbasevideocodec.h \
gstbasevideodecoder.h \
gstbasevideoencoder.h \
gstbasevideoparse.h
gstbasevideoencoder.h
libgstbasevideo_@GST_MAJORMINOR@_la_CFLAGS = \
$(GST_PLUGINS_BAD_CFLAGS) \

View file

@ -1,862 +0,0 @@
/* Schrodinger
* Copyright (C) 2006 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstbasevideoparse.h"
#include <string.h>
#include <math.h>
GST_DEBUG_CATEGORY (basevideoparse_debug);
#define GST_CAT_DEFAULT basevideoparse_debug
/* GstBaseVideoParse signals and args */
enum
{
LAST_SIGNAL
};
enum
{
ARG_0
};
static void gst_base_video_parse_finalize (GObject * object);
static const GstQueryType *gst_base_video_parse_get_query_types (GstPad * pad);
static gboolean gst_base_video_parse_src_query (GstPad * pad, GstQuery * query);
static gboolean gst_base_video_parse_sink_query (GstPad * pad,
GstQuery * query);
static gboolean gst_base_video_parse_src_event (GstPad * pad, GstEvent * event);
static gboolean gst_base_video_parse_sink_event (GstPad * pad,
GstEvent * event);
static GstStateChangeReturn gst_base_video_parse_change_state (GstElement *
element, GstStateChange transition);
static GstFlowReturn gst_base_video_parse_push_all (GstBaseVideoParse *
base_video_parse, gboolean at_eos);
static GstFlowReturn gst_base_video_parse_chain (GstPad * pad, GstBuffer * buf);
static void gst_base_video_parse_free_frame (GstVideoFrame * frame);
static GstVideoFrame *gst_base_video_parse_new_frame (GstBaseVideoParse *
base_video_parse);
GST_BOILERPLATE (GstBaseVideoParse, gst_base_video_parse,
GstBaseVideoCodec, GST_TYPE_BASE_VIDEO_CODEC);
static void
gst_base_video_parse_base_init (gpointer g_class)
{
GST_DEBUG_CATEGORY_INIT (basevideoparse_debug, "basevideoparse", 0,
"Base Video Parse");
}
static void
gst_base_video_parse_class_init (GstBaseVideoParseClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *element_class;
gobject_class = G_OBJECT_CLASS (klass);
element_class = GST_ELEMENT_CLASS (klass);
gobject_class->finalize = gst_base_video_parse_finalize;
element_class->change_state = gst_base_video_parse_change_state;
}
static void
gst_base_video_parse_init (GstBaseVideoParse * base_video_parse,
GstBaseVideoParseClass * klass)
{
GstPad *pad;
GST_DEBUG ("gst_base_video_parse_init");
pad = GST_BASE_VIDEO_CODEC_SINK_PAD (base_video_parse);
gst_pad_set_chain_function (pad, gst_base_video_parse_chain);
gst_pad_set_query_function (pad, gst_base_video_parse_sink_query);
gst_pad_set_event_function (pad, gst_base_video_parse_sink_event);
pad = GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_parse);
gst_pad_set_query_type_function (pad, gst_base_video_parse_get_query_types);
gst_pad_set_query_function (pad, gst_base_video_parse_src_query);
gst_pad_set_event_function (pad, gst_base_video_parse_src_event);
base_video_parse->input_adapter = gst_adapter_new ();
base_video_parse->output_adapter = gst_adapter_new ();
base_video_parse->reorder_depth = 1;
base_video_parse->current_frame =
gst_base_video_parse_new_frame (base_video_parse);
}
static void
gst_base_video_parse_reset (GstBaseVideoParse * base_video_parse)
{
GST_DEBUG ("reset");
base_video_parse->discont = TRUE;
base_video_parse->have_sync = FALSE;
base_video_parse->system_frame_number = 0;
base_video_parse->presentation_frame_number = 0;
if (base_video_parse->caps) {
gst_caps_unref (base_video_parse->caps);
base_video_parse->caps = NULL;
}
gst_segment_init (&base_video_parse->segment, GST_FORMAT_TIME);
gst_adapter_clear (base_video_parse->input_adapter);
gst_adapter_clear (base_video_parse->output_adapter);
if (base_video_parse->current_frame) {
gst_base_video_parse_free_frame (base_video_parse->current_frame);
}
base_video_parse->current_frame =
gst_base_video_parse_new_frame (base_video_parse);
}
static void
gst_base_video_parse_finalize (GObject * object)
{
GstBaseVideoParse *base_video_parse;
g_return_if_fail (GST_IS_BASE_VIDEO_PARSE (object));
base_video_parse = GST_BASE_VIDEO_PARSE (object);
if (base_video_parse->input_adapter) {
g_object_unref (base_video_parse->input_adapter);
}
if (base_video_parse->output_adapter) {
g_object_unref (base_video_parse->output_adapter);
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static const GstQueryType *
gst_base_video_parse_get_query_types (GstPad * pad)
{
static const GstQueryType query_types[] = {
GST_QUERY_POSITION,
GST_QUERY_DURATION,
GST_QUERY_CONVERT,
0
};
return query_types;
}
#if 0
static gboolean
gst_base_video_parse_src_convert (GstPad * pad,
GstFormat src_format, gint64 src_value,
GstFormat * dest_format, gint64 * dest_value)
{
gboolean res;
GstBaseVideoParse *dec;
if (src_format == *dest_format) {
*dest_value = src_value;
return TRUE;
}
dec = GST_BASE_VIDEO_PARSE (gst_pad_get_parent (pad));
if (src_format == GST_FORMAT_DEFAULT && *dest_format == GST_FORMAT_TIME) {
if (dec->fps_d != 0) {
*dest_value = gst_util_uint64_scale (granulepos_to_frame (src_value),
dec->fps_d * GST_SECOND, dec->fps_n);
res = TRUE;
} else {
res = FALSE;
}
} else {
GST_WARNING ("unhandled conversion from %d to %d", src_format,
*dest_format);
res = FALSE;
}
gst_object_unref (dec);
return res;
}
static gboolean
gst_base_video_parse_sink_convert (GstPad * pad,
GstFormat src_format, gint64 src_value,
GstFormat * dest_format, gint64 * dest_value)
{
gboolean res = TRUE;
GstBaseVideoParse *dec;
if (src_format == *dest_format) {
*dest_value = src_value;
return TRUE;
}
dec = GST_BASE_VIDEO_PARSE (gst_pad_get_parent (pad));
/* FIXME: check if we are in a decoding state */
switch (src_format) {
case GST_FORMAT_DEFAULT:
switch (*dest_format) {
case GST_FORMAT_TIME:
*dest_value = gst_util_uint64_scale (src_value,
dec->fps_d * GST_SECOND, dec->fps_n);
break;
default:
res = FALSE;
}
break;
case GST_FORMAT_TIME:
switch (*dest_format) {
case GST_FORMAT_DEFAULT:
{
*dest_value = gst_util_uint64_scale (src_value,
dec->fps_n, dec->fps_d * GST_SECOND);
break;
}
default:
res = FALSE;
break;
}
break;
default:
res = FALSE;
break;
}
gst_object_unref (dec);
return res;
}
#endif
static gboolean
gst_base_video_parse_src_query (GstPad * pad, GstQuery * query)
{
GstBaseVideoParse *base_parse;
gboolean res = FALSE;
base_parse = GST_BASE_VIDEO_PARSE (gst_pad_get_parent (pad));
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION:
{
GstFormat format;
gint64 time;
gint64 value;
gst_query_parse_position (query, &format, NULL);
time = gst_util_uint64_scale (base_parse->presentation_frame_number,
base_parse->state.fps_n, base_parse->state.fps_d);
time += base_parse->segment.time;
GST_DEBUG ("query position %" GST_TIME_FORMAT, GST_TIME_ARGS (time));
res = gst_base_video_encoded_video_convert (&base_parse->state,
GST_FORMAT_TIME, time, &format, &value);
if (!res)
goto error;
gst_query_set_position (query, format, value);
break;
}
case GST_QUERY_DURATION:
res =
gst_pad_query (GST_PAD_PEER (GST_BASE_VIDEO_CODEC_SINK_PAD
(base_parse)), query);
if (!res)
goto error;
break;
case GST_QUERY_CONVERT:
{
GstFormat src_fmt, dest_fmt;
gint64 src_val, dest_val;
GST_WARNING ("query convert");
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
res = gst_base_video_encoded_video_convert (&base_parse->state,
src_fmt, src_val, &dest_fmt, &dest_val);
if (!res)
goto error;
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
break;
}
default:
res = gst_pad_query_default (pad, query);
break;
}
done:
gst_object_unref (base_parse);
return res;
error:
GST_DEBUG_OBJECT (base_parse, "query failed");
goto done;
}
static gboolean
gst_base_video_parse_sink_query (GstPad * pad, GstQuery * query)
{
GstBaseVideoParse *base_video_parse;
gboolean res = FALSE;
base_video_parse = GST_BASE_VIDEO_PARSE (gst_pad_get_parent (pad));
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_CONVERT:
{
GstFormat src_fmt, dest_fmt;
gint64 src_val, dest_val;
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
res = gst_base_video_encoded_video_convert (&base_video_parse->state,
src_fmt, src_val, &dest_fmt, &dest_val);
if (!res)
goto error;
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
break;
}
default:
res = gst_pad_query_default (pad, query);
break;
}
done:
gst_object_unref (base_video_parse);
return res;
error:
GST_DEBUG_OBJECT (base_video_parse, "query failed");
goto done;
}
static gboolean
gst_base_video_parse_src_event (GstPad * pad, GstEvent * event)
{
GstBaseVideoParse *base_video_parse;
gboolean res = FALSE;
base_video_parse = GST_BASE_VIDEO_PARSE (gst_pad_get_parent (pad));
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_SEEK:
{
GstFormat format, tformat;
gdouble rate;
GstEvent *real_seek;
GstSeekFlags flags;
GstSeekType cur_type, stop_type;
gint64 cur, stop;
gint64 tcur, tstop;
gst_event_parse_seek (event, &rate, &format, &flags, &cur_type,
&cur, &stop_type, &stop);
gst_event_unref (event);
tformat = GST_FORMAT_TIME;
res = gst_base_video_encoded_video_convert (&base_video_parse->state,
format, cur, &tformat, &tcur);
if (!res)
goto convert_error;
res = gst_base_video_encoded_video_convert (&base_video_parse->state,
format, stop, &tformat, &tstop);
if (!res)
goto convert_error;
real_seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
flags, cur_type, tcur, stop_type, tstop);
res =
gst_pad_push_event (GST_BASE_VIDEO_CODEC_SINK_PAD (base_video_parse),
real_seek);
break;
}
#if 0
case GST_EVENT_QOS:
{
gdouble proportion;
GstClockTimeDiff diff;
GstClockTime timestamp;
gst_event_parse_qos (event, &proportion, &diff, &timestamp);
GST_OBJECT_LOCK (base_video_parse);
base_video_parse->proportion = proportion;
base_video_parse->earliest_time = timestamp + diff;
GST_OBJECT_UNLOCK (base_video_parse);
GST_DEBUG_OBJECT (base_video_parse,
"got QoS %" GST_TIME_FORMAT ", %" G_GINT64_FORMAT,
GST_TIME_ARGS (timestamp), diff);
res = gst_pad_push_event (base_video_parse->sinkpad, event);
break;
}
#endif
default:
res =
gst_pad_push_event (GST_BASE_VIDEO_CODEC_SINK_PAD (base_video_parse),
event);
break;
}
done:
gst_object_unref (base_video_parse);
return res;
convert_error:
GST_DEBUG_OBJECT (base_video_parse, "could not convert format");
goto done;
}
static gboolean
gst_base_video_parse_sink_event (GstPad * pad, GstEvent * event)
{
GstBaseVideoParse *base_video_parse;
gboolean ret = FALSE;
base_video_parse = GST_BASE_VIDEO_PARSE (gst_pad_get_parent (pad));
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_START:
ret =
gst_pad_push_event (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_parse),
event);
break;
case GST_EVENT_FLUSH_STOP:
gst_base_video_parse_reset (base_video_parse);
ret =
gst_pad_push_event (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_parse),
event);
break;
case GST_EVENT_EOS:
if (gst_base_video_parse_push_all (base_video_parse,
FALSE) == GST_FLOW_ERROR) {
gst_event_unref (event);
return FALSE;
}
ret =
gst_pad_push_event (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_parse),
event);
break;
case GST_EVENT_NEWSEGMENT:
{
gboolean update;
GstFormat format;
gdouble rate;
gint64 start, stop, time;
gst_event_parse_new_segment (event, &update, &rate, &format, &start,
&stop, &time);
if (format != GST_FORMAT_TIME)
goto newseg_wrong_format;
if (rate <= 0.0)
goto newseg_wrong_rate;
GST_DEBUG ("newsegment %" GST_TIME_FORMAT " %" GST_TIME_FORMAT,
GST_TIME_ARGS (start), GST_TIME_ARGS (time));
gst_segment_set_newsegment (&base_video_parse->segment, update,
rate, format, start, stop, time);
ret =
gst_pad_push_event (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_parse),
event);
break;
}
default:
ret =
gst_pad_push_event (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_parse),
event);
break;
}
done:
gst_object_unref (base_video_parse);
return ret;
newseg_wrong_format:
GST_DEBUG_OBJECT (base_video_parse, "received non TIME newsegment");
gst_event_unref (event);
goto done;
newseg_wrong_rate:
GST_DEBUG_OBJECT (base_video_parse, "negative rates not supported");
gst_event_unref (event);
goto done;
}
static GstStateChangeReturn
gst_base_video_parse_change_state (GstElement * element,
GstStateChange transition)
{
GstBaseVideoParse *base_parse = GST_BASE_VIDEO_PARSE (element);
GstStateChangeReturn ret;
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
gst_base_video_parse_reset (base_parse);
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
break;
default:
break;
}
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
switch (transition) {
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
gst_base_video_parse_reset (base_parse);
break;
case GST_STATE_CHANGE_READY_TO_NULL:
break;
default:
break;
}
return ret;
}
static guint64
gst_base_video_parse_get_timestamp (GstBaseVideoParse * base_video_parse,
int picture_number)
{
if (picture_number < 0) {
return base_video_parse->timestamp_offset -
(gint64) gst_util_uint64_scale (-picture_number,
base_video_parse->state.fps_d * GST_SECOND,
base_video_parse->state.fps_n);
} else {
return base_video_parse->timestamp_offset +
gst_util_uint64_scale (picture_number,
base_video_parse->state.fps_d * GST_SECOND,
base_video_parse->state.fps_n);
}
}
static GstFlowReturn
gst_base_video_parse_push_all (GstBaseVideoParse * base_video_parse,
gboolean at_eos)
{
GstFlowReturn ret = GST_FLOW_OK;
/* FIXME do stuff */
return ret;
}
static GstFlowReturn
gst_base_video_parse_chain (GstPad * pad, GstBuffer * buf)
{
GstBaseVideoParse *base_video_parse;
GstBaseVideoParseClass *klass;
GstFlowReturn ret;
GST_DEBUG ("chain with %d bytes", GST_BUFFER_SIZE (buf));
base_video_parse = GST_BASE_VIDEO_PARSE (GST_PAD_PARENT (pad));
klass = GST_BASE_VIDEO_PARSE_GET_CLASS (base_video_parse);
if (!base_video_parse->started) {
klass->start (base_video_parse);
base_video_parse->started = TRUE;
}
if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT))) {
GST_DEBUG_OBJECT (base_video_parse, "received DISCONT buffer");
gst_base_video_parse_reset (base_video_parse);
base_video_parse->discont = TRUE;
base_video_parse->have_sync = FALSE;
}
if (GST_BUFFER_TIMESTAMP (buf) != GST_CLOCK_TIME_NONE) {
base_video_parse->last_timestamp = GST_BUFFER_TIMESTAMP (buf);
}
gst_adapter_push (base_video_parse->input_adapter, buf);
if (!base_video_parse->have_sync) {
int n, m;
GST_DEBUG ("no sync, scanning");
n = gst_adapter_available (base_video_parse->input_adapter);
m = klass->scan_for_sync (base_video_parse->input_adapter, FALSE, 0, n);
gst_adapter_flush (base_video_parse->input_adapter, m);
if (m < n) {
GST_DEBUG ("found possible sync after %d bytes (of %d)", m, n);
/* this is only "maybe" sync */
base_video_parse->have_sync = TRUE;
}
if (!base_video_parse->have_sync) {
return GST_FLOW_OK;
}
}
/* FIXME check klass->parse_data */
do {
ret = klass->parse_data (base_video_parse, FALSE);
} while (ret == GST_FLOW_OK);
if (ret == GST_BASE_VIDEO_PARSE_FLOW_NEED_DATA) {
return GST_FLOW_OK;
}
return ret;
}
GstVideoState *
gst_base_video_parse_get_state (GstBaseVideoParse * base_video_parse)
{
return &base_video_parse->state;
}
void
gst_base_video_parse_set_state (GstBaseVideoParse * base_video_parse,
GstVideoState * state)
{
GST_DEBUG ("set_state");
memcpy (&base_video_parse->state, state, sizeof (GstVideoState));
/* FIXME set caps */
}
gboolean
gst_base_video_parse_set_src_caps (GstBaseVideoParse * base_video_parse,
GstCaps * caps)
{
g_return_val_if_fail (GST_IS_BASE_VIDEO_PARSE (base_video_parse), FALSE);
GST_DEBUG ("set_src_caps");
return gst_pad_set_caps (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_parse),
caps);
}
void
gst_base_video_parse_lost_sync (GstBaseVideoParse * base_video_parse)
{
g_return_if_fail (GST_IS_BASE_VIDEO_PARSE (base_video_parse));
GST_DEBUG ("lost_sync");
if (gst_adapter_available (base_video_parse->input_adapter) >= 1) {
gst_adapter_flush (base_video_parse->input_adapter, 1);
}
base_video_parse->have_sync = FALSE;
}
GstVideoFrame *
gst_base_video_parse_get_frame (GstBaseVideoParse * base_video_parse)
{
g_return_val_if_fail (GST_IS_BASE_VIDEO_PARSE (base_video_parse), NULL);
return base_video_parse->current_frame;
}
void
gst_base_video_parse_add_to_frame (GstBaseVideoParse * base_video_parse,
int n_bytes)
{
GstBuffer *buf;
GST_DEBUG ("add_to_frame");
buf = gst_adapter_take_buffer (base_video_parse->input_adapter, n_bytes);
gst_adapter_push (base_video_parse->output_adapter, buf);
}
GstFlowReturn
gst_base_video_parse_finish_frame (GstBaseVideoParse * base_video_parse)
{
GstVideoFrame *frame = base_video_parse->current_frame;
GstBuffer *buffer;
GstBaseVideoParseClass *base_video_parse_class;
GstFlowReturn ret;
GST_DEBUG ("finish_frame");
base_video_parse_class = GST_BASE_VIDEO_PARSE_GET_CLASS (base_video_parse);
buffer = gst_adapter_take_buffer (base_video_parse->output_adapter,
gst_adapter_available (base_video_parse->output_adapter));
if (frame->is_sync_point) {
base_video_parse->timestamp_offset = base_video_parse->last_timestamp -
gst_util_uint64_scale (frame->presentation_frame_number,
base_video_parse->state.fps_d * GST_SECOND,
base_video_parse->state.fps_n);
base_video_parse->distance_from_sync = 0;
}
frame->distance_from_sync = base_video_parse->distance_from_sync;
base_video_parse->distance_from_sync++;
frame->presentation_timestamp =
gst_base_video_parse_get_timestamp (base_video_parse,
frame->presentation_frame_number);
frame->presentation_duration =
gst_base_video_parse_get_timestamp (base_video_parse,
frame->presentation_frame_number + 1) - frame->presentation_timestamp;
frame->decode_timestamp =
gst_base_video_parse_get_timestamp (base_video_parse,
frame->decode_frame_number);
GST_BUFFER_TIMESTAMP (buffer) = frame->presentation_timestamp;
GST_BUFFER_DURATION (buffer) = frame->presentation_duration;
if (frame->decode_frame_number < 0) {
GST_BUFFER_OFFSET (buffer) = 0;
} else {
GST_BUFFER_OFFSET (buffer) = frame->decode_timestamp;
}
GST_BUFFER_OFFSET_END (buffer) = GST_CLOCK_TIME_NONE;
GST_DEBUG ("pts %" GST_TIME_FORMAT,
GST_TIME_ARGS (frame->presentation_timestamp));
GST_DEBUG ("dts %" GST_TIME_FORMAT, GST_TIME_ARGS (frame->decode_timestamp));
GST_DEBUG ("dist %d", frame->distance_from_sync);
if (frame->is_sync_point) {
GST_BUFFER_FLAG_UNSET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
} else {
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
}
frame->src_buffer = buffer;
ret = base_video_parse_class->shape_output (base_video_parse, frame);
gst_base_video_parse_free_frame (base_video_parse->current_frame);
/* create new frame */
base_video_parse->current_frame =
gst_base_video_parse_new_frame (base_video_parse);
return ret;
}
static void
gst_base_video_parse_free_frame (GstVideoFrame * frame)
{
if (frame->sink_buffer) {
gst_buffer_unref (frame->sink_buffer);
}
#if 0
if (frame->src_buffer) {
gst_buffer_unref (frame->src_buffer);
}
#endif
g_free (frame);
}
static GstVideoFrame *
gst_base_video_parse_new_frame (GstBaseVideoParse * base_video_parse)
{
GstVideoFrame *frame;
frame = g_malloc0 (sizeof (GstVideoFrame));
frame->system_frame_number = base_video_parse->system_frame_number;
base_video_parse->system_frame_number++;
frame->decode_frame_number = frame->system_frame_number -
base_video_parse->reorder_depth;
return frame;
}
void
gst_base_video_parse_set_sync_point (GstBaseVideoParse * base_video_parse)
{
GST_DEBUG ("set_sync_point");
base_video_parse->current_frame->is_sync_point = TRUE;
base_video_parse->distance_from_sync = 0;
}
GstFlowReturn
gst_base_video_parse_push (GstBaseVideoParse * base_video_parse,
GstBuffer * buffer)
{
GstBaseVideoParseClass *base_video_parse_class;
base_video_parse_class = GST_BASE_VIDEO_PARSE_GET_CLASS (base_video_parse);
if (base_video_parse->caps == NULL) {
gboolean ret;
base_video_parse->caps =
base_video_parse_class->get_caps (base_video_parse);
ret = gst_pad_set_caps (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_parse),
base_video_parse->caps);
if (!ret) {
GST_WARNING ("pad didn't accept caps");
return GST_FLOW_ERROR;
}
}
gst_buffer_set_caps (buffer, base_video_parse->caps);
GST_DEBUG ("pushing ts=%" GST_TIME_FORMAT " dur=%" GST_TIME_FORMAT
" off=%" G_GUINT64_FORMAT " off_end=%" G_GUINT64_FORMAT,
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)),
GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)),
GST_BUFFER_OFFSET (buffer), GST_BUFFER_OFFSET_END (buffer));
if (base_video_parse->discont) {
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
base_video_parse->discont = FALSE;
} else {
GST_BUFFER_FLAG_UNSET (buffer, GST_BUFFER_FLAG_DISCONT);
}
return gst_pad_push (GST_BASE_VIDEO_CODEC_SRC_PAD (base_video_parse), buffer);
}

View file

@ -1,142 +0,0 @@
/* 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_PARSE_H_
#define _GST_BASE_VIDEO_PARSE_H_
#ifndef GST_USE_UNSTABLE_API
#warning "GstBaseVideoParse is unstable API and may change in future."
#warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
#endif
#include <gst/video/gstbasevideocodec.h>
#include <gst/video/gstbasevideoutils.h>
G_BEGIN_DECLS
#define GST_TYPE_BASE_VIDEO_PARSE \
(gst_base_video_parse_get_type())
#define GST_BASE_VIDEO_PARSE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_VIDEO_PARSE,GstBaseVideoParse))
#define GST_BASE_VIDEO_PARSE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_VIDEO_PARSE,GstBaseVideoParseClass))
#define GST_BASE_VIDEO_PARSE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_BASE_VIDEO_PARSE,GstBaseVideoParseClass))
#define GST_IS_BASE_VIDEO_PARSE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_VIDEO_PARSE))
#define GST_IS_BASE_VIDEO_PARSE_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_VIDEO_PARSE))
/**
* GST_BASE_VIDEO_PARSE_SINK_NAME:
*
* The name of the templates for the sink pad.
*/
#define GST_BASE_VIDEO_PARSE_SINK_NAME "sink"
/**
* GST_BASE_VIDEO_PARSE_SRC_NAME:
*
* The name of the templates for the source pad.
*/
#define GST_BASE_VIDEO_PARSE_SRC_NAME "src"
/**
* GST_BASE_VIDEO_PARSE_FLOW_NEED_DATA:
*
*/
#define GST_BASE_VIDEO_PARSE_FLOW_NEED_DATA GST_FLOW_CUSTOM_SUCCESS
typedef struct _GstBaseVideoParse GstBaseVideoParse;
typedef struct _GstBaseVideoParseClass GstBaseVideoParseClass;
struct _GstBaseVideoParse
{
GstBaseVideoCodec base_video_codec;
/*< private >*/
GstAdapter *input_adapter;
GstAdapter *output_adapter;
int reorder_depth;
gboolean have_sync;
gboolean discont;
gboolean started;
GstVideoFrame *current_frame;
GstVideoState state;
GstSegment segment;
int distance_from_sync;
gboolean sink_clipping;
guint64 presentation_frame_number;
guint64 system_frame_number;
GstCaps *caps;
gboolean set_output_caps;
GstClockTime last_timestamp;
gint64 timestamp_offset;
};
struct _GstBaseVideoParseClass
{
GstBaseVideoCodecClass base_video_codec_class;
gboolean (*start) (GstBaseVideoParse *parse);
gboolean (*stop) (GstBaseVideoParse *parse);
gboolean (*reset) (GstBaseVideoParse *parse);
GstFlowReturn (*parse_data) (GstBaseVideoParse *parse, gboolean at_eos);
int (*scan_for_sync) (GstAdapter *adapter, gboolean at_eos,
int offset, int n);
GstFlowReturn (*shape_output) (GstBaseVideoParse *parse, GstVideoFrame *frame);
GstCaps *(*get_caps) (GstBaseVideoParse *parse);
};
GType gst_base_video_parse_get_type (void);
int gst_base_video_parse_get_width (GstBaseVideoParse *parse);
int gst_base_video_parse_get_height (GstBaseVideoParse *parse);
GstVideoState *gst_base_video_parse_get_state (GstBaseVideoParse *parse);
void gst_base_video_parse_set_state (GstBaseVideoParse *parse,
GstVideoState *state);
guint64 gst_base_video_parse_get_timestamp_offset (GstBaseVideoParse *parse);
gboolean gst_base_video_parse_set_src_caps (GstBaseVideoParse *base_video_parse, GstCaps *caps);
GstFlowReturn gst_base_video_parse_end_of_stream (GstBaseVideoParse *base_video_parse,
GstBuffer *buffer);
void gst_base_video_parse_lost_sync (GstBaseVideoParse *base_video_parse);
GstVideoFrame * gst_base_video_parse_get_frame (GstBaseVideoParse *base_video_parse);
void gst_base_video_parse_add_to_frame (GstBaseVideoParse *base_video_parse, int n_bytes);
GstFlowReturn gst_base_video_parse_finish_frame (GstBaseVideoParse *base_video_parse);
void gst_base_video_parse_set_sync_point (GstBaseVideoParse *base_video_parse);
GstFlowReturn gst_base_video_parse_push (GstBaseVideoParse *base_video_parse,
GstBuffer *buffer);
G_END_DECLS
#endif