2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-23 06:03:21 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-23 06:03:21 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
#include "gstmpeg2dec.h"
|
|
|
|
|
2003-09-11 17:13:24 +00:00
|
|
|
/* mpeg2dec changed a struct name after 0.3.1, here's a workaround */
|
|
|
|
/* mpeg2dec also only defined MPEG2_RELEASE after 0.3.1
|
|
|
|
#if MPEG2_RELEASE < MPEG2_VERSION(0,3,2)
|
|
|
|
*/
|
|
|
|
#ifndef MPEG2_RELEASE
|
|
|
|
typedef picture_t mpeg2_picture_t;
|
2003-10-06 12:16:21 +00:00
|
|
|
typedef gint mpeg2_state_t;
|
2003-10-07 10:08:30 +00:00
|
|
|
#define STATE_BUFFER 0
|
2003-09-11 17:13:24 +00:00
|
|
|
#endif
|
|
|
|
|
2003-07-25 02:04:01 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (GST_CAT_SEEK);
|
|
|
|
|
2001-12-23 06:03:21 +00:00
|
|
|
/* elementfactory information */
|
|
|
|
static GstElementDetails gst_mpeg2dec_details = {
|
|
|
|
"mpeg1 and mpeg2 video decoder",
|
2003-11-16 22:02:04 +00:00
|
|
|
"Codec/Decoder/Video",
|
2001-12-23 06:03:21 +00:00
|
|
|
"Uses libmpeg2 to decode MPEG video streams",
|
2002-12-19 07:45:11 +00:00
|
|
|
"Wim Taymans <wim.taymans@chello.be>",
|
2001-12-23 06:03:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Mpeg2dec signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
2002-12-19 20:05:10 +00:00
|
|
|
ARG_STREAMINFO,
|
2001-12-23 06:03:21 +00:00
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (src_template_factory,
|
2001-12-23 06:03:21 +00:00
|
|
|
"src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"mpeg2dec_src",
|
2003-07-06 20:49:50 +00:00
|
|
|
"video/x-raw-yuv",
|
|
|
|
"format", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_FOURCC (GST_MAKE_FOURCC ('Y','V','1','2')),
|
|
|
|
GST_PROPS_FOURCC (GST_MAKE_FOURCC ('I','4','2','0'))
|
|
|
|
),
|
2002-12-05 00:29:11 +00:00
|
|
|
"width", GST_PROPS_INT_RANGE (16, 4096),
|
|
|
|
"height", GST_PROPS_INT_RANGE (16, 4096),
|
|
|
|
"pixel_width", GST_PROPS_INT_RANGE (1, 255),
|
2003-07-06 20:49:50 +00:00
|
|
|
"pixel_height", GST_PROPS_INT_RANGE (1, 255),
|
2003-07-08 17:40:09 +00:00
|
|
|
"framerate", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_FLOAT (24/1.001),
|
|
|
|
GST_PROPS_FLOAT (24.),
|
|
|
|
GST_PROPS_FLOAT (25.),
|
|
|
|
GST_PROPS_FLOAT (30/1.001),
|
|
|
|
GST_PROPS_FLOAT (30.),
|
|
|
|
GST_PROPS_FLOAT (50.),
|
|
|
|
GST_PROPS_FLOAT (60/1.001),
|
|
|
|
GST_PROPS_FLOAT (60.)
|
|
|
|
)
|
2001-12-23 06:03:21 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2002-12-19 07:45:11 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (user_data_template_factory,
|
|
|
|
"user_data",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"mpeg2dec_user_data",
|
|
|
|
"application/octet-stream",
|
|
|
|
NULL
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (sink_template_factory,
|
2001-12-23 06:03:21 +00:00
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"mpeg2dec_sink",
|
|
|
|
"video/mpeg",
|
2003-07-06 20:49:50 +00:00
|
|
|
/* width/height/framerate not needed */
|
2001-12-23 06:03:21 +00:00
|
|
|
"mpegversion", GST_PROPS_INT_RANGE (1, 2),
|
|
|
|
"systemstream", GST_PROPS_BOOLEAN (FALSE)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2003-11-02 00:33:31 +00:00
|
|
|
static void gst_mpeg2dec_base_init (gpointer g_class);
|
2002-12-05 00:29:11 +00:00
|
|
|
static void gst_mpeg2dec_class_init (GstMpeg2decClass *klass);
|
|
|
|
static void gst_mpeg2dec_init (GstMpeg2dec *mpeg2dec);
|
|
|
|
|
|
|
|
static void gst_mpeg2dec_dispose (GObject *object);
|
|
|
|
|
|
|
|
static void gst_mpeg2dec_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_mpeg2dec_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec);
|
2002-12-12 22:15:39 +00:00
|
|
|
static void gst_mpeg2dec_set_index (GstElement *element, GstIndex *index);
|
|
|
|
static GstIndex* gst_mpeg2dec_get_index (GstElement *element);
|
2002-12-05 00:29:11 +00:00
|
|
|
|
|
|
|
static const GstFormat*
|
|
|
|
gst_mpeg2dec_get_src_formats (GstPad *pad);
|
|
|
|
static const GstEventMask*
|
|
|
|
gst_mpeg2dec_get_src_event_masks (GstPad *pad);
|
|
|
|
static gboolean gst_mpeg2dec_src_event (GstPad *pad, GstEvent *event);
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType*
|
2002-12-05 00:29:11 +00:00
|
|
|
gst_mpeg2dec_get_src_query_types (GstPad *pad);
|
2002-12-30 17:53:18 +00:00
|
|
|
static gboolean gst_mpeg2dec_src_query (GstPad *pad, GstQueryType type,
|
2002-12-05 00:29:11 +00:00
|
|
|
GstFormat *format, gint64 *value);
|
|
|
|
|
|
|
|
static const GstFormat*
|
|
|
|
gst_mpeg2dec_get_sink_formats (GstPad *pad);
|
|
|
|
static gboolean gst_mpeg2dec_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value);
|
|
|
|
static gboolean gst_mpeg2dec_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value);
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2001-12-23 06:03:21 +00:00
|
|
|
static GstElementStateReturn
|
2002-12-05 00:29:11 +00:00
|
|
|
gst_mpeg2dec_change_state (GstElement *element);
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2003-10-08 16:08:10 +00:00
|
|
|
static void gst_mpeg2dec_chain (GstPad *pad, GstData *_data);
|
2001-12-23 06:03:21 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
/*static guint gst_mpeg2dec_signals[LAST_SIGNAL] = { 0 };*/
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_mpeg2dec_get_type (void)
|
|
|
|
{
|
|
|
|
static GType mpeg2dec_type = 0;
|
2003-11-02 00:33:31 +00:00
|
|
|
|
2001-12-23 06:03:21 +00:00
|
|
|
if (!mpeg2dec_type) {
|
|
|
|
static const GTypeInfo mpeg2dec_info = {
|
|
|
|
sizeof(GstMpeg2decClass),
|
2003-11-02 00:33:31 +00:00
|
|
|
gst_mpeg2dec_base_init,
|
2001-12-23 06:03:21 +00:00
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_mpeg2dec_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstMpeg2dec),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_mpeg2dec_init,
|
|
|
|
};
|
|
|
|
mpeg2dec_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMpeg2dec", &mpeg2dec_info, 0);
|
|
|
|
}
|
|
|
|
return mpeg2dec_type;
|
|
|
|
}
|
|
|
|
|
2003-11-02 00:33:31 +00:00
|
|
|
static void
|
|
|
|
gst_mpeg2dec_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class, GST_PAD_TEMPLATE_GET (src_template_factory));
|
|
|
|
gst_element_class_add_pad_template (element_class, GST_PAD_TEMPLATE_GET (sink_template_factory));
|
|
|
|
gst_element_class_add_pad_template (element_class, GST_PAD_TEMPLATE_GET (user_data_template_factory));
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_mpeg2dec_details);
|
|
|
|
}
|
|
|
|
|
2001-12-23 06:03:21 +00:00
|
|
|
static void
|
|
|
|
gst_mpeg2dec_class_init(GstMpeg2decClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
|
|
|
|
2002-12-19 20:05:10 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_STREAMINFO,
|
|
|
|
g_param_spec_boxed ("streaminfo", "Streaminfo", "Streaminfo",
|
|
|
|
GST_TYPE_CAPS, G_PARAM_READABLE));
|
2002-02-06 23:05:22 +00:00
|
|
|
|
2001-12-23 06:03:21 +00:00
|
|
|
gobject_class->set_property = gst_mpeg2dec_set_property;
|
|
|
|
gobject_class->get_property = gst_mpeg2dec_get_property;
|
|
|
|
gobject_class->dispose = gst_mpeg2dec_dispose;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_mpeg2dec_change_state;
|
2002-12-12 22:15:39 +00:00
|
|
|
gstelement_class->set_index = gst_mpeg2dec_set_index;
|
|
|
|
gstelement_class->get_index = gst_mpeg2dec_get_index;
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-12-05 00:29:11 +00:00
|
|
|
gst_mpeg2dec_init (GstMpeg2dec *mpeg2dec)
|
2001-12-23 06:03:21 +00:00
|
|
|
{
|
2002-12-05 00:29:11 +00:00
|
|
|
/* create the sink and src pads */
|
|
|
|
mpeg2dec->sinkpad = gst_pad_new_from_template (
|
|
|
|
GST_PAD_TEMPLATE_GET (sink_template_factory), "sink");
|
|
|
|
gst_element_add_pad (GST_ELEMENT (mpeg2dec), mpeg2dec->sinkpad);
|
|
|
|
gst_pad_set_chain_function (mpeg2dec->sinkpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_chain));
|
|
|
|
gst_pad_set_formats_function (mpeg2dec->sinkpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_sink_formats));
|
|
|
|
gst_pad_set_convert_function (mpeg2dec->sinkpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_convert_sink));
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
mpeg2dec->srcpad = gst_pad_new_from_template (
|
|
|
|
GST_PAD_TEMPLATE_GET (src_template_factory), "src");
|
|
|
|
gst_element_add_pad (GST_ELEMENT (mpeg2dec), mpeg2dec->srcpad);
|
|
|
|
gst_pad_set_formats_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_formats));
|
|
|
|
gst_pad_set_event_mask_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_event_masks));
|
|
|
|
gst_pad_set_event_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_src_event));
|
|
|
|
gst_pad_set_query_type_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_query_types));
|
|
|
|
gst_pad_set_query_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_src_query));
|
|
|
|
gst_pad_set_convert_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_convert_src));
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-12-19 07:45:11 +00:00
|
|
|
mpeg2dec->userdatapad = gst_pad_new_from_template (
|
|
|
|
GST_PAD_TEMPLATE_GET (user_data_template_factory), "user_data");
|
|
|
|
gst_element_add_pad (GST_ELEMENT (mpeg2dec), mpeg2dec->userdatapad);
|
|
|
|
|
2002-12-23 00:32:36 +00:00
|
|
|
/* initialize the mpeg2dec acceleration */
|
2002-12-19 20:05:10 +00:00
|
|
|
mpeg2_accel (MPEG2_ACCEL_DETECT);
|
2002-12-26 22:46:26 +00:00
|
|
|
mpeg2dec->closed = TRUE;
|
2002-12-27 04:04:04 +00:00
|
|
|
mpeg2dec->have_fbuf = FALSE;
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
GST_FLAG_SET (GST_ELEMENT (mpeg2dec), GST_ELEMENT_EVENT_AWARE);
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
static void
|
2002-12-26 22:46:26 +00:00
|
|
|
gst_mpeg2dec_close_decoder (GstMpeg2dec *mpeg2dec)
|
2001-12-23 06:03:21 +00:00
|
|
|
{
|
2002-12-23 00:32:36 +00:00
|
|
|
if (!mpeg2dec->closed) {
|
2002-12-05 00:29:11 +00:00
|
|
|
mpeg2_close (mpeg2dec->decoder);
|
2002-12-23 00:32:36 +00:00
|
|
|
mpeg2dec->closed = TRUE;
|
2002-12-26 22:46:26 +00:00
|
|
|
mpeg2dec->decoder = NULL;
|
2002-12-23 00:32:36 +00:00
|
|
|
}
|
2002-12-26 22:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mpeg2dec_open_decoder (GstMpeg2dec *mpeg2dec)
|
|
|
|
{
|
|
|
|
gst_mpeg2dec_close_decoder (mpeg2dec);
|
|
|
|
mpeg2dec->decoder = mpeg2_init ();
|
|
|
|
mpeg2dec->closed = FALSE;
|
2002-12-27 04:04:04 +00:00
|
|
|
mpeg2dec->have_fbuf = FALSE;
|
2002-12-26 22:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mpeg2dec_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (object);
|
|
|
|
|
|
|
|
gst_mpeg2dec_close_decoder (mpeg2dec);
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-12-12 22:15:39 +00:00
|
|
|
gst_mpeg2dec_set_index (GstElement *element, GstIndex *index)
|
2001-12-23 06:03:21 +00:00
|
|
|
{
|
2002-12-05 00:29:11 +00:00
|
|
|
GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (element);
|
|
|
|
|
2002-12-12 22:15:39 +00:00
|
|
|
mpeg2dec->index = index;
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-12-12 22:15:39 +00:00
|
|
|
gst_index_get_writer_id (index, GST_OBJECT (element), &mpeg2dec->index_id);
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
2002-12-12 22:15:39 +00:00
|
|
|
static GstIndex*
|
|
|
|
gst_mpeg2dec_get_index (GstElement *element)
|
2001-12-23 06:03:21 +00:00
|
|
|
{
|
2002-12-05 00:29:11 +00:00
|
|
|
GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (element);
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-12-12 22:15:39 +00:00
|
|
|
return mpeg2dec->index;
|
2002-12-05 00:29:11 +00:00
|
|
|
}
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
static GstBuffer*
|
2002-12-23 00:32:36 +00:00
|
|
|
gst_mpeg2dec_alloc_buffer (GstMpeg2dec *mpeg2dec, const mpeg2_info_t *info, gint64 offset)
|
2002-12-05 00:29:11 +00:00
|
|
|
{
|
|
|
|
GstBuffer *outbuf = NULL;
|
|
|
|
gint size = mpeg2dec->width * mpeg2dec->height;
|
|
|
|
guint8 *buf[3], *out;
|
2003-09-11 17:13:24 +00:00
|
|
|
const mpeg2_picture_t *picture;
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
if (mpeg2dec->peerpool) {
|
|
|
|
outbuf = gst_buffer_new_from_pool (mpeg2dec->peerpool, 0, 0);
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
2002-12-05 00:29:11 +00:00
|
|
|
if (!outbuf) {
|
|
|
|
outbuf = gst_buffer_new_and_alloc ((size * 3) / 2);
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
out = GST_BUFFER_DATA (outbuf);
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
buf[0] = out;
|
|
|
|
if (mpeg2dec->format == MPEG2DEC_FORMAT_I420) {
|
|
|
|
buf[1] = buf[0] + size;
|
|
|
|
buf[2] = buf[1] + size/4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buf[2] = buf[0] + size;
|
|
|
|
buf[1] = buf[2] + size/4;
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
gst_buffer_ref (outbuf);
|
|
|
|
mpeg2_set_buf (mpeg2dec->decoder, buf, outbuf);
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
picture = info->current_picture;
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-12-23 00:32:36 +00:00
|
|
|
if (picture && (picture->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I) {
|
2002-12-05 00:29:11 +00:00
|
|
|
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_KEY_UNIT);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_KEY_UNIT);
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
2002-12-23 00:32:36 +00:00
|
|
|
/* we store the original byteoffset of this picture in the stream here
|
|
|
|
* because we need it for indexing */
|
|
|
|
GST_BUFFER_OFFSET (outbuf) = offset;
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
return outbuf;
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mpeg2dec_negotiate_format (GstMpeg2dec *mpeg2dec)
|
2001-12-23 06:03:21 +00:00
|
|
|
{
|
2002-12-05 00:29:11 +00:00
|
|
|
GstCaps *allowed;
|
2003-02-02 20:03:10 +00:00
|
|
|
GstCaps *intersect, *trylist, *head, *to_intersect;
|
2002-12-05 00:29:11 +00:00
|
|
|
|
2003-07-24 03:02:06 +00:00
|
|
|
if (!GST_PAD_IS_LINKED (mpeg2dec->srcpad)) {
|
|
|
|
mpeg2dec->format = MPEG2DEC_FORMAT_I420;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
/* we what we are allowed to do */
|
|
|
|
allowed = gst_pad_get_allowed_caps (mpeg2dec->srcpad);
|
|
|
|
/* we could not get allowed caps */
|
|
|
|
if (!allowed) {
|
|
|
|
allowed = GST_CAPS_NEW (
|
|
|
|
"mpeg2dec_negotiate",
|
2003-07-06 20:49:50 +00:00
|
|
|
"video/x-raw-yuv",
|
2002-12-05 00:29:11 +00:00
|
|
|
"format", GST_PROPS_FOURCC (GST_STR_FOURCC ("I420"))
|
|
|
|
);
|
|
|
|
}
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2003-02-02 20:03:10 +00:00
|
|
|
to_intersect = GST_CAPS_NEW (
|
|
|
|
"mpeg2dec_negotiate",
|
2003-07-06 20:49:50 +00:00
|
|
|
"video/x-raw-yuv",
|
2003-02-02 20:03:10 +00:00
|
|
|
"width", GST_PROPS_INT (mpeg2dec->width),
|
|
|
|
"height", GST_PROPS_INT (mpeg2dec->height),
|
|
|
|
"pixel_width", GST_PROPS_INT (mpeg2dec->pixel_width),
|
2003-07-06 20:49:50 +00:00
|
|
|
"pixel_height", GST_PROPS_INT (mpeg2dec->pixel_height),
|
|
|
|
"framerate", GST_PROPS_FLOAT (1. * GST_SECOND / mpeg2dec->frame_period)
|
2003-02-02 20:03:10 +00:00
|
|
|
);
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
/* try to fix our height */
|
2003-02-02 20:03:10 +00:00
|
|
|
intersect = gst_caps_intersect (allowed, to_intersect);
|
|
|
|
gst_caps_unref (allowed);
|
|
|
|
gst_caps_unref (to_intersect);
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
/* prepare for looping */
|
2003-02-02 20:03:10 +00:00
|
|
|
head = trylist = gst_caps_normalize (intersect);
|
|
|
|
gst_caps_unref (intersect);
|
2002-12-05 00:29:11 +00:00
|
|
|
|
|
|
|
while (trylist) {
|
|
|
|
GstCaps *to_try = gst_caps_copy_1 (trylist);
|
|
|
|
|
|
|
|
/* try each format */
|
|
|
|
if (gst_pad_try_set_caps (mpeg2dec->srcpad, to_try) > 0) {
|
|
|
|
guint32 fourcc;
|
|
|
|
|
|
|
|
/* it worked, try to find what it was again */
|
|
|
|
gst_caps_get_fourcc_int (to_try, "format", &fourcc);
|
|
|
|
|
|
|
|
if (fourcc == GST_STR_FOURCC ("I420")) {
|
|
|
|
mpeg2dec->format = MPEG2DEC_FORMAT_I420;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mpeg2dec->format = MPEG2DEC_FORMAT_YV12;
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
2002-12-05 00:29:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-02-02 20:03:10 +00:00
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
trylist = trylist->next;
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
2003-02-02 20:03:10 +00:00
|
|
|
gst_caps_unref (head);
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
/* oops list exhausted and nothing was found... */
|
|
|
|
if (!trylist) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
2002-12-19 20:05:10 +00:00
|
|
|
static void
|
|
|
|
update_streaminfo (GstMpeg2dec *mpeg2dec)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
GstProps *props;
|
|
|
|
GstPropsEntry *entry;
|
|
|
|
const mpeg2_info_t *info;
|
|
|
|
|
|
|
|
info = mpeg2_info (mpeg2dec->decoder);
|
|
|
|
|
|
|
|
props = gst_props_empty_new ();
|
|
|
|
|
|
|
|
entry = gst_props_entry_new ("framerate", GST_PROPS_FLOAT (GST_SECOND/(float)mpeg2dec->frame_period));
|
|
|
|
gst_props_add_entry (props, entry);
|
|
|
|
entry = gst_props_entry_new ("bitrate", GST_PROPS_INT (info->sequence->byte_rate * 8));
|
|
|
|
gst_props_add_entry (props, entry);
|
|
|
|
|
|
|
|
caps = gst_caps_new ("mpeg2dec_streaminfo",
|
|
|
|
"application/x-gst-streaminfo",
|
|
|
|
props);
|
|
|
|
|
2003-02-02 20:03:10 +00:00
|
|
|
gst_caps_replace_sink (&mpeg2dec->streaminfo, caps);
|
2002-12-19 20:05:10 +00:00
|
|
|
g_object_notify (G_OBJECT (mpeg2dec), "streaminfo");
|
|
|
|
}
|
|
|
|
|
2002-12-27 04:04:04 +00:00
|
|
|
static void
|
|
|
|
gst_mpeg2dec_flush_decoder (GstMpeg2dec *mpeg2dec)
|
|
|
|
{
|
2003-10-06 12:16:21 +00:00
|
|
|
mpeg2_state_t state;
|
2002-12-27 04:04:04 +00:00
|
|
|
|
|
|
|
if (mpeg2dec->decoder) {
|
|
|
|
const mpeg2_info_t *info = mpeg2_info (mpeg2dec->decoder);
|
|
|
|
|
|
|
|
do {
|
|
|
|
state = mpeg2_parse (mpeg2dec->decoder);
|
|
|
|
if (state == STATE_END) {
|
|
|
|
if (info->discard_fbuf && info->discard_fbuf->id) {
|
|
|
|
gst_buffer_unref ((GstBuffer *)info->discard_fbuf->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-07 10:08:30 +00:00
|
|
|
while (state != STATE_BUFFER && state != -1);
|
2002-12-27 04:04:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-23 06:03:21 +00:00
|
|
|
static void
|
2003-10-08 16:08:10 +00:00
|
|
|
gst_mpeg2dec_chain (GstPad *pad, GstData *_data)
|
2001-12-23 06:03:21 +00:00
|
|
|
{
|
2003-10-08 16:08:10 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-23 06:03:21 +00:00
|
|
|
GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad));
|
|
|
|
guint32 size;
|
2002-12-05 00:29:11 +00:00
|
|
|
guint8 *data, *end;
|
2001-12-23 06:03:21 +00:00
|
|
|
gint64 pts;
|
2002-12-05 00:29:11 +00:00
|
|
|
const mpeg2_info_t *info;
|
2003-10-06 12:16:21 +00:00
|
|
|
mpeg2_state_t state;
|
2002-12-05 00:29:11 +00:00
|
|
|
gboolean done = FALSE;
|
2001-12-23 06:03:21 +00:00
|
|
|
|
|
|
|
if (GST_IS_EVENT (buf)) {
|
2002-05-26 21:59:22 +00:00
|
|
|
GstEvent *event = GST_EVENT (buf);
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2002-06-02 11:57:12 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2001-12-23 06:03:21 +00:00
|
|
|
case GST_EVENT_DISCONTINUOUS:
|
2002-05-26 21:59:22 +00:00
|
|
|
{
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("discont");
|
2002-05-26 21:59:22 +00:00
|
|
|
mpeg2dec->next_time = 0;
|
2002-12-26 22:46:26 +00:00
|
|
|
mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE;
|
2002-12-27 04:04:04 +00:00
|
|
|
gst_mpeg2dec_flush_decoder (mpeg2dec);
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_pad_event_default (pad, event);
|
2001-12-23 06:03:21 +00:00
|
|
|
return;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
2001-12-23 06:03:21 +00:00
|
|
|
case GST_EVENT_EOS:
|
2002-12-26 22:46:26 +00:00
|
|
|
if (mpeg2dec->index && mpeg2dec->closed) {
|
|
|
|
gst_index_commit (mpeg2dec->index, mpeg2dec->index_id);
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
|
|
|
default:
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_pad_event_default (pad, event);
|
2001-12-23 06:03:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size = GST_BUFFER_SIZE (buf);
|
|
|
|
data = GST_BUFFER_DATA (buf);
|
|
|
|
pts = GST_BUFFER_TIMESTAMP (buf);
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
info = mpeg2_info (mpeg2dec->decoder);
|
|
|
|
end = data + size;
|
|
|
|
|
|
|
|
if (pts != -1) {
|
|
|
|
gint64 mpeg_pts = GSTTIME_TO_MPEGTIME (pts);
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("have pts: %" G_GINT64_FORMAT " (%" G_GINT64_FORMAT ")",
|
2002-12-05 00:29:11 +00:00
|
|
|
mpeg_pts, MPEGTIME_TO_GSTTIME (mpeg_pts));
|
|
|
|
|
|
|
|
mpeg2_pts (mpeg2dec->decoder, mpeg_pts);
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
2002-12-05 00:29:11 +00:00
|
|
|
else {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("no pts");
|
2002-06-02 11:57:12 +00:00
|
|
|
}
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("calling _buffer");
|
2002-12-05 00:29:11 +00:00
|
|
|
mpeg2_buffer (mpeg2dec->decoder, data, end);
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("calling _buffer done");
|
2002-12-05 00:29:11 +00:00
|
|
|
|
|
|
|
while (!done) {
|
2002-12-26 22:46:26 +00:00
|
|
|
gboolean slice = FALSE;
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("calling parse");
|
2002-12-05 00:29:11 +00:00
|
|
|
state = mpeg2_parse (mpeg2dec->decoder);
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("parse state %d", state);
|
2002-12-05 00:29:11 +00:00
|
|
|
switch (state) {
|
|
|
|
case STATE_SEQUENCE:
|
|
|
|
{
|
|
|
|
mpeg2dec->width = info->sequence->width;
|
|
|
|
mpeg2dec->height = info->sequence->height;
|
|
|
|
mpeg2dec->pixel_width = info->sequence->pixel_width;
|
|
|
|
mpeg2dec->pixel_height = info->sequence->pixel_height;
|
|
|
|
mpeg2dec->total_frames = 0;
|
|
|
|
mpeg2dec->frame_period = info->sequence->frame_period * GST_USECOND / 27;
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("sequence flags: %d, frame period: %d",
|
2002-12-05 00:29:11 +00:00
|
|
|
info->sequence->flags, info->sequence->frame_period);
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("profile: %02x, colour_primaries: %d",
|
2003-05-24 10:15:28 +00:00
|
|
|
info->sequence->profile_level_id, info->sequence->colour_primaries);
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("transfer chars: %d, matrix coef: %d",
|
2003-05-24 10:15:28 +00:00
|
|
|
info->sequence->transfer_characteristics, info->sequence->matrix_coefficients);
|
2002-12-05 00:29:11 +00:00
|
|
|
|
|
|
|
if (!gst_mpeg2dec_negotiate_format (mpeg2dec)) {
|
2003-09-16 10:00:00 +00:00
|
|
|
gst_element_error (GST_ELEMENT (mpeg2dec), "could not negotiate format");
|
2002-12-27 04:04:04 +00:00
|
|
|
goto exit;
|
2002-12-05 00:29:11 +00:00
|
|
|
}
|
|
|
|
|
2003-07-23 04:53:59 +00:00
|
|
|
/* now that we've negotiated, try to get a bufferpool */
|
|
|
|
mpeg2dec->peerpool = gst_pad_get_bufferpool (mpeg2dec->srcpad);
|
|
|
|
if (mpeg2dec->peerpool)
|
|
|
|
GST_INFO ( "got pool %p", mpeg2dec->peerpool);
|
|
|
|
|
2002-12-19 20:05:10 +00:00
|
|
|
update_streaminfo (mpeg2dec);
|
|
|
|
|
2002-12-27 04:04:04 +00:00
|
|
|
if (!mpeg2dec->have_fbuf) {
|
|
|
|
/* alloc 3 buffers */
|
|
|
|
gst_mpeg2dec_alloc_buffer (mpeg2dec, info, GST_BUFFER_OFFSET (buf));
|
|
|
|
gst_mpeg2dec_alloc_buffer (mpeg2dec, info, GST_BUFFER_OFFSET (buf));
|
|
|
|
gst_mpeg2dec_alloc_buffer (mpeg2dec, info, GST_BUFFER_OFFSET (buf));
|
|
|
|
mpeg2dec->have_fbuf = TRUE;
|
|
|
|
}
|
2002-12-26 22:46:26 +00:00
|
|
|
|
|
|
|
mpeg2dec->need_sequence = FALSE;
|
|
|
|
if (mpeg2dec->pending_event) {
|
|
|
|
done = GST_EVENT_SEEK_FLAGS (mpeg2dec->pending_event) & GST_SEEK_FLAG_FLUSH;
|
|
|
|
|
|
|
|
gst_mpeg2dec_src_event (mpeg2dec->srcpad, mpeg2dec->pending_event);
|
|
|
|
mpeg2dec->pending_event = NULL;
|
|
|
|
}
|
2002-12-05 00:29:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STATE_SEQUENCE_REPEATED:
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("sequence repeated");
|
2002-12-05 00:29:11 +00:00
|
|
|
case STATE_GOP:
|
|
|
|
break;
|
|
|
|
case STATE_PICTURE:
|
|
|
|
{
|
|
|
|
gboolean key_frame = FALSE;
|
2002-12-26 22:46:26 +00:00
|
|
|
GstBuffer *outbuf;
|
2002-12-05 00:29:11 +00:00
|
|
|
|
2002-12-23 00:32:36 +00:00
|
|
|
if (info->current_picture) {
|
2002-12-05 00:29:11 +00:00
|
|
|
key_frame = (info->current_picture->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I;
|
2002-12-23 00:32:36 +00:00
|
|
|
}
|
2002-12-26 22:46:26 +00:00
|
|
|
outbuf = gst_mpeg2dec_alloc_buffer (mpeg2dec, info, GST_BUFFER_OFFSET (buf));
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("picture %d, %p, %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT,
|
2002-12-26 22:46:26 +00:00
|
|
|
key_frame, outbuf, GST_BUFFER_OFFSET (outbuf), pts);
|
|
|
|
|
|
|
|
if (mpeg2dec->discont_state == MPEG2DEC_DISC_NEW_PICTURE && key_frame)
|
|
|
|
mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_KEYFRAME;
|
2002-12-05 00:29:11 +00:00
|
|
|
|
2002-12-19 20:05:10 +00:00
|
|
|
if (!GST_PAD_IS_USABLE (mpeg2dec->srcpad))
|
|
|
|
mpeg2_skip (mpeg2dec->decoder, 1);
|
2002-12-23 00:32:36 +00:00
|
|
|
else
|
|
|
|
mpeg2_skip (mpeg2dec->decoder, 0);
|
2002-12-05 00:29:11 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STATE_SLICE_1ST:
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("slice 1st");
|
2002-12-05 00:29:11 +00:00
|
|
|
break;
|
|
|
|
case STATE_PICTURE_2ND:
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("picture second");
|
2002-12-05 00:29:11 +00:00
|
|
|
break;
|
|
|
|
case STATE_SLICE:
|
2002-12-26 22:46:26 +00:00
|
|
|
slice = TRUE;
|
2002-12-05 00:29:11 +00:00
|
|
|
case STATE_END:
|
|
|
|
{
|
|
|
|
GstBuffer *outbuf = NULL;
|
2002-12-27 04:04:04 +00:00
|
|
|
gboolean skip = FALSE;
|
2002-12-05 00:29:11 +00:00
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
if (!slice) {
|
|
|
|
mpeg2dec->need_sequence = TRUE;
|
|
|
|
}
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("picture end %p %p %p %p", info->display_fbuf, info->display_picture, info->current_picture,
|
2002-12-26 22:46:26 +00:00
|
|
|
(info->display_fbuf ? info->display_fbuf->id : NULL));
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
if (info->display_fbuf && info->display_fbuf->id) {
|
2003-09-11 17:13:24 +00:00
|
|
|
const mpeg2_picture_t *picture;
|
2002-12-23 00:32:36 +00:00
|
|
|
gboolean key_frame = FALSE;
|
2003-09-11 17:13:24 +00:00
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
outbuf = (GstBuffer *) info->display_fbuf->id;
|
|
|
|
picture = info->display_picture;
|
|
|
|
|
2002-12-23 00:32:36 +00:00
|
|
|
key_frame = (picture->flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I;
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("picture keyfame %d", key_frame);
|
2002-12-26 22:46:26 +00:00
|
|
|
|
|
|
|
if (key_frame) {
|
|
|
|
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_KEY_UNIT);
|
|
|
|
}
|
|
|
|
if (mpeg2dec->discont_state == MPEG2DEC_DISC_NEW_KEYFRAME && key_frame)
|
|
|
|
mpeg2dec->discont_state = MPEG2DEC_DISC_NONE;
|
2002-12-23 00:32:36 +00:00
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
if (picture->flags & PIC_FLAG_PTS) {
|
|
|
|
GstClockTime time = MPEGTIME_TO_GSTTIME (picture->pts);
|
2001-12-23 06:03:21 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("picture had pts %" G_GINT64_FORMAT, time);
|
2002-12-05 00:29:11 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = time;
|
|
|
|
|
|
|
|
mpeg2dec->next_time = time;
|
|
|
|
}
|
|
|
|
else {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("picture didn't have pts using %" G_GINT64_FORMAT, mpeg2dec->next_time);
|
2002-12-05 00:29:11 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = mpeg2dec->next_time;
|
|
|
|
}
|
|
|
|
mpeg2dec->next_time += (mpeg2dec->frame_period * picture->nb_fields) >> 1;
|
2002-12-23 00:32:36 +00:00
|
|
|
|
2002-12-27 04:04:04 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("picture: %s %s fields:%d off:%" G_GINT64_FORMAT " ts:%" G_GINT64_FORMAT,
|
2002-12-05 00:29:11 +00:00
|
|
|
(picture->flags & PIC_FLAG_TOP_FIELD_FIRST ? "tff " : " "),
|
|
|
|
(picture->flags & PIC_FLAG_PROGRESSIVE_FRAME ? "prog" : " "),
|
|
|
|
picture->nb_fields,
|
2002-12-23 00:32:36 +00:00
|
|
|
GST_BUFFER_OFFSET (outbuf),
|
2002-12-05 00:29:11 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf));
|
|
|
|
|
2002-12-23 00:32:36 +00:00
|
|
|
if (mpeg2dec->index) {
|
|
|
|
gst_index_add_association (mpeg2dec->index, mpeg2dec->index_id,
|
2002-12-31 14:53:04 +00:00
|
|
|
(key_frame ? GST_ASSOCIATION_FLAG_KEY_UNIT : 0),
|
2002-12-23 00:32:36 +00:00
|
|
|
GST_FORMAT_BYTES, GST_BUFFER_OFFSET (outbuf),
|
|
|
|
GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (outbuf), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
if (picture->flags & PIC_FLAG_SKIP ||
|
2002-12-26 22:46:26 +00:00
|
|
|
!GST_PAD_IS_USABLE (mpeg2dec->srcpad) ||
|
|
|
|
mpeg2dec->discont_state != MPEG2DEC_DISC_NONE ||
|
2002-12-27 04:04:04 +00:00
|
|
|
mpeg2dec->next_time < mpeg2dec->segment_start ||
|
|
|
|
skip)
|
2002-12-26 22:46:26 +00:00
|
|
|
{
|
2002-12-05 00:29:11 +00:00
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
}
|
|
|
|
else {
|
2003-05-24 10:15:28 +00:00
|
|
|
/* TODO set correct offset here based on frame number */
|
|
|
|
GST_BUFFER_DURATION (outbuf) = mpeg2dec->frame_period;
|
2003-10-08 16:08:10 +00:00
|
|
|
gst_pad_push (mpeg2dec->srcpad, GST_DATA (outbuf));
|
2002-12-05 00:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (info->discard_fbuf && info->discard_fbuf->id) {
|
|
|
|
gst_buffer_unref ((GstBuffer *)info->discard_fbuf->id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* need more data */
|
2003-10-06 12:16:21 +00:00
|
|
|
case STATE_BUFFER:
|
2003-10-07 10:08:30 +00:00
|
|
|
case -1:
|
2002-12-05 00:29:11 +00:00
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
/* error */
|
|
|
|
case STATE_INVALID:
|
2003-04-13 15:01:27 +00:00
|
|
|
g_warning ("mpeg2dec: decoding error");
|
|
|
|
/* it looks like setting a new frame in libmpeg2 avoids a crash */
|
|
|
|
/* FIXME figure out how this screws up sync and buffer leakage */
|
|
|
|
gst_mpeg2dec_alloc_buffer (mpeg2dec, info, GST_BUFFER_OFFSET (buf));
|
2002-12-05 00:29:11 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_warning ("%s: unhandled state %d, FIXME",
|
|
|
|
gst_element_get_name (GST_ELEMENT (mpeg2dec)),
|
|
|
|
state);
|
|
|
|
break;
|
|
|
|
}
|
2002-12-19 07:45:11 +00:00
|
|
|
|
2002-12-19 21:05:57 +00:00
|
|
|
/*
|
2002-12-19 07:45:11 +00:00
|
|
|
* FIXME: should pass more information such as state the user data is from
|
|
|
|
*/
|
2002-12-19 21:05:57 +00:00
|
|
|
if (info->user_data_len > 0) {
|
|
|
|
if (GST_PAD_IS_USABLE (mpeg2dec->userdatapad)) {
|
|
|
|
GstBuffer *udbuf = gst_buffer_new_and_alloc (info->user_data_len);
|
|
|
|
|
|
|
|
memcpy (GST_BUFFER_DATA (udbuf), info->user_data, info->user_data_len);
|
|
|
|
|
2003-10-08 16:08:10 +00:00
|
|
|
gst_pad_push (mpeg2dec->userdatapad, GST_DATA (udbuf));
|
2002-12-19 21:05:57 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-05 00:29:11 +00:00
|
|
|
}
|
2002-12-27 04:04:04 +00:00
|
|
|
exit:
|
2001-12-23 06:03:21 +00:00
|
|
|
gst_buffer_unref(buf);
|
|
|
|
}
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
static const GstFormat*
|
|
|
|
gst_mpeg2dec_get_sink_formats (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstFormat formats[] = {
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
return formats;
|
|
|
|
}
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mpeg2dec_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstMpeg2dec *mpeg2dec;
|
2002-12-05 00:29:11 +00:00
|
|
|
const mpeg2_info_t *info;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
|
|
|
mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad));
|
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
if (mpeg2dec->decoder == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
info = mpeg2_info (mpeg2dec->decoder);
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
2002-12-05 00:29:11 +00:00
|
|
|
if (info->sequence && info->sequence->byte_rate) {
|
|
|
|
*dest_value = GST_SECOND * src_value / info->sequence->byte_rate;
|
|
|
|
break;
|
|
|
|
}
|
2002-05-26 21:59:22 +00:00
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
2002-12-05 00:29:11 +00:00
|
|
|
if (info->sequence && info->sequence->byte_rate) {
|
|
|
|
*dest_value = src_value * info->sequence->byte_rate / GST_SECOND;
|
|
|
|
break;
|
|
|
|
}
|
2002-05-26 21:59:22 +00:00
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
static const GstFormat*
|
|
|
|
gst_mpeg2dec_get_src_formats (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstFormat formats[] = {
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
GST_FORMAT_TIME,
|
2003-05-24 10:15:28 +00:00
|
|
|
GST_FORMAT_DEFAULT,
|
2002-12-05 00:29:11 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
return formats;
|
|
|
|
}
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mpeg2dec_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstMpeg2dec *mpeg2dec;
|
2002-12-05 00:29:11 +00:00
|
|
|
const mpeg2_info_t *info;
|
|
|
|
guint64 scale = 1;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
|
|
|
mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad));
|
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
if (mpeg2dec->decoder == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
info = mpeg2_info (mpeg2dec->decoder);
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
2002-12-05 00:29:11 +00:00
|
|
|
scale = 6 * (mpeg2dec->width * mpeg2dec->height >> 2);
|
2003-05-24 10:15:28 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-12-05 00:29:11 +00:00
|
|
|
if (info->sequence && mpeg2dec->frame_period) {
|
|
|
|
*dest_value = src_value * scale / mpeg2dec->frame_period;
|
|
|
|
break;
|
|
|
|
}
|
2002-05-26 21:59:22 +00:00
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2003-05-24 10:15:28 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-05-26 21:59:22 +00:00
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
2002-12-05 00:29:11 +00:00
|
|
|
*dest_value = src_value * mpeg2dec->frame_period;
|
2002-05-26 21:59:22 +00:00
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
2002-12-05 00:29:11 +00:00
|
|
|
*dest_value = src_value * 6 * ((mpeg2dec->width * mpeg2dec->height) >> 2);
|
2002-05-26 21:59:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType*
|
2002-12-05 00:29:11 +00:00
|
|
|
gst_mpeg2dec_get_src_query_types (GstPad *pad)
|
|
|
|
{
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType types[] = {
|
|
|
|
GST_QUERY_TOTAL,
|
|
|
|
GST_QUERY_POSITION,
|
2002-12-05 00:29:11 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
return types;
|
|
|
|
}
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
static gboolean
|
2002-12-30 17:53:18 +00:00
|
|
|
gst_mpeg2dec_src_query (GstPad *pad, GstQueryType type,
|
2002-05-26 21:59:22 +00:00
|
|
|
GstFormat *format, gint64 *value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstMpeg2dec *mpeg2dec;
|
2002-12-05 00:29:11 +00:00
|
|
|
static const GstFormat *formats;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
|
|
|
mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (type) {
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_TOTAL:
|
2002-05-26 21:59:22 +00:00
|
|
|
{
|
|
|
|
switch (*format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
case GST_FORMAT_BYTES:
|
2003-05-24 10:15:28 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-05-26 21:59:22 +00:00
|
|
|
{
|
|
|
|
res = FALSE;
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
/* get our peer formats */
|
|
|
|
formats = gst_pad_get_formats (GST_PAD_PEER (mpeg2dec->sinkpad));
|
|
|
|
|
|
|
|
/* while we did not exhaust our seek formats without result */
|
|
|
|
while (formats && *formats) {
|
2002-05-26 21:59:22 +00:00
|
|
|
GstFormat peer_format;
|
|
|
|
gint64 peer_value;
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
peer_format = *formats;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
|
|
|
/* do the probe */
|
2002-12-30 17:53:18 +00:00
|
|
|
if (gst_pad_query (GST_PAD_PEER (mpeg2dec->sinkpad), GST_QUERY_TOTAL,
|
2002-05-26 21:59:22 +00:00
|
|
|
&peer_format, &peer_value))
|
|
|
|
{
|
|
|
|
GstFormat conv_format;
|
|
|
|
|
|
|
|
/* convert to TIME */
|
|
|
|
conv_format = GST_FORMAT_TIME;
|
2002-06-02 20:17:58 +00:00
|
|
|
res = gst_pad_convert (mpeg2dec->sinkpad,
|
2002-05-26 21:59:22 +00:00
|
|
|
peer_format, peer_value,
|
|
|
|
&conv_format, value);
|
|
|
|
/* and to final format */
|
2002-06-02 20:17:58 +00:00
|
|
|
res &= gst_pad_convert (pad,
|
2002-05-26 21:59:22 +00:00
|
|
|
GST_FORMAT_TIME, *value,
|
|
|
|
format, value);
|
|
|
|
}
|
2002-12-05 00:29:11 +00:00
|
|
|
formats++;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2002-05-26 21:59:22 +00:00
|
|
|
{
|
|
|
|
switch (*format) {
|
|
|
|
default:
|
2002-06-02 20:17:58 +00:00
|
|
|
res = gst_pad_convert (pad,
|
2002-05-26 21:59:22 +00:00
|
|
|
GST_FORMAT_TIME, mpeg2dec->next_time,
|
|
|
|
format, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-12-05 00:29:11 +00:00
|
|
|
|
|
|
|
static const GstEventMask*
|
|
|
|
gst_mpeg2dec_get_src_event_masks (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstEventMask masks[] = {
|
|
|
|
{ GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH },
|
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
return masks;
|
|
|
|
}
|
|
|
|
|
2002-12-23 00:32:36 +00:00
|
|
|
static gboolean
|
2002-12-26 22:46:26 +00:00
|
|
|
index_seek (GstPad *pad, GstEvent *event)
|
2002-12-23 00:32:36 +00:00
|
|
|
{
|
|
|
|
GstIndexEntry *entry;
|
2002-12-26 22:46:26 +00:00
|
|
|
GstMpeg2dec *mpeg2dec;
|
|
|
|
|
|
|
|
mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad));
|
2002-12-23 00:32:36 +00:00
|
|
|
|
|
|
|
entry = gst_index_get_assoc_entry (mpeg2dec->index, mpeg2dec->index_id,
|
2002-12-31 14:53:04 +00:00
|
|
|
GST_INDEX_LOOKUP_BEFORE, GST_ASSOCIATION_FLAG_KEY_UNIT,
|
2002-12-23 00:32:36 +00:00
|
|
|
GST_EVENT_SEEK_FORMAT (event),
|
|
|
|
GST_EVENT_SEEK_OFFSET (event));
|
|
|
|
|
|
|
|
if (entry) {
|
2002-12-27 22:26:15 +00:00
|
|
|
const GstFormat *peer_formats, *try_formats;
|
|
|
|
/* since we know the exaxt byteoffset of the frame, make sure to seek on bytes first */
|
|
|
|
const GstFormat try_all_formats[] =
|
|
|
|
{
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
0
|
|
|
|
};
|
2002-12-23 00:32:36 +00:00
|
|
|
|
2002-12-27 22:26:15 +00:00
|
|
|
try_formats = try_all_formats;
|
2002-12-23 00:32:36 +00:00
|
|
|
peer_formats = gst_pad_get_formats (GST_PAD_PEER (mpeg2dec->sinkpad));
|
|
|
|
|
2002-12-27 22:26:15 +00:00
|
|
|
while (gst_formats_contains (peer_formats, *try_formats)) {
|
2002-12-23 00:32:36 +00:00
|
|
|
gint64 value;
|
|
|
|
|
2002-12-27 22:26:15 +00:00
|
|
|
if (gst_index_entry_assoc_map (entry, *try_formats, &value)) {
|
2002-12-23 00:32:36 +00:00
|
|
|
GstEvent *seek_event;
|
|
|
|
|
2003-07-25 02:04:01 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_SEEK, "index %s %" G_GINT64_FORMAT
|
|
|
|
" -> %s %" G_GINT64_FORMAT,
|
|
|
|
gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick,
|
|
|
|
GST_EVENT_SEEK_OFFSET (event),
|
|
|
|
gst_format_get_details (*try_formats)->nick,
|
|
|
|
value);
|
|
|
|
|
2002-12-23 00:32:36 +00:00
|
|
|
/* lookup succeeded, create the seek */
|
2002-12-27 22:26:15 +00:00
|
|
|
seek_event = gst_event_new_seek (*try_formats | GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, value);
|
2002-12-23 00:32:36 +00:00
|
|
|
/* do the seekk */
|
|
|
|
if (gst_pad_send_event (GST_PAD_PEER (mpeg2dec->sinkpad), seek_event)) {
|
|
|
|
/* seek worked, we're done, loop will exit */
|
2002-12-27 04:04:04 +00:00
|
|
|
gst_mpeg2dec_flush_decoder (mpeg2dec);
|
2002-12-26 22:46:26 +00:00
|
|
|
mpeg2dec->segment_start = GST_EVENT_SEEK_OFFSET (event);
|
2002-12-23 00:32:36 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2002-12-27 22:26:15 +00:00
|
|
|
try_formats++;
|
2002-12-23 00:32:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
static gboolean
|
2002-12-26 22:46:26 +00:00
|
|
|
normal_seek (GstPad *pad, GstEvent *event)
|
2002-05-26 21:59:22 +00:00
|
|
|
{
|
2002-12-26 22:46:26 +00:00
|
|
|
gint64 src_offset;
|
|
|
|
gboolean flush;
|
|
|
|
GstFormat format;
|
|
|
|
const GstFormat *peer_formats;
|
|
|
|
gboolean res = FALSE;
|
2002-05-26 21:59:22 +00:00
|
|
|
GstMpeg2dec *mpeg2dec;
|
|
|
|
|
|
|
|
mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad));
|
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
format = GST_FORMAT_TIME;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
/* first bring the src_format to TIME */
|
|
|
|
if (!gst_pad_convert (pad,
|
|
|
|
GST_EVENT_SEEK_FORMAT (event), GST_EVENT_SEEK_OFFSET (event),
|
|
|
|
&format, &src_offset))
|
|
|
|
{
|
|
|
|
/* didn't work, probably unsupported seek format then */
|
|
|
|
return res;
|
|
|
|
}
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
/* shave off the flush flag, we'll need it later */
|
|
|
|
flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
/* get our peer formats */
|
|
|
|
peer_formats = gst_pad_get_formats (GST_PAD_PEER (mpeg2dec->sinkpad));
|
2002-12-05 00:29:11 +00:00
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
/* while we did not exhaust our seek formats without result */
|
|
|
|
while (peer_formats && *peer_formats) {
|
|
|
|
gint64 desired_offset;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
format = *peer_formats;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
/* try to convert requested format to one we can seek with on the sinkpad */
|
|
|
|
if (gst_pad_convert (mpeg2dec->sinkpad, GST_FORMAT_TIME, src_offset, &format, &desired_offset))
|
|
|
|
{
|
|
|
|
GstEvent *seek_event;
|
|
|
|
|
|
|
|
/* conversion succeeded, create the seek */
|
|
|
|
seek_event = gst_event_new_seek (format | GST_SEEK_METHOD_SET | flush, desired_offset);
|
|
|
|
/* do the seekk */
|
|
|
|
if (gst_pad_send_event (GST_PAD_PEER (mpeg2dec->sinkpad), seek_event)) {
|
|
|
|
/* seek worked, we're done, loop will exit */
|
|
|
|
mpeg2dec->segment_start = GST_EVENT_SEEK_OFFSET (event);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
peer_formats++;
|
|
|
|
}
|
|
|
|
/* at this point, either the seek worked and res = TRUE or res == FALSE and the seek
|
|
|
|
* failed */
|
|
|
|
if (res && flush) {
|
|
|
|
/* if we need to flush, iterate until the buffer is empty */
|
2002-12-27 04:04:04 +00:00
|
|
|
gst_mpeg2dec_flush_decoder (mpeg2dec);
|
2002-12-26 22:46:26 +00:00
|
|
|
}
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
static gboolean
|
|
|
|
gst_mpeg2dec_src_event (GstPad *pad, GstEvent *event)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstMpeg2dec *mpeg2dec;
|
|
|
|
|
|
|
|
mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (mpeg2dec->decoder == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
/* the all-formats seek logic */
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
if (mpeg2dec->need_sequence) {
|
|
|
|
mpeg2dec->pending_event = event;
|
|
|
|
return TRUE;
|
2002-12-05 00:29:11 +00:00
|
|
|
}
|
2002-12-26 22:46:26 +00:00
|
|
|
else {
|
|
|
|
if (mpeg2dec->index)
|
|
|
|
res = index_seek (pad, event);
|
|
|
|
else
|
|
|
|
res = normal_seek (pad, event);
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2002-07-09 17:39:18 +00:00
|
|
|
gst_event_unref (event);
|
2002-05-26 21:59:22 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2001-12-23 06:03:21 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_mpeg2dec_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
{
|
|
|
|
mpeg2dec->next_time = 0;
|
|
|
|
mpeg2dec->peerpool = NULL;
|
|
|
|
|
|
|
|
/* reset the initial video state */
|
2002-12-05 00:29:11 +00:00
|
|
|
mpeg2dec->format = MPEG2DEC_FORMAT_NONE;
|
2001-12-23 06:03:21 +00:00
|
|
|
mpeg2dec->width = -1;
|
|
|
|
mpeg2dec->height = -1;
|
2002-12-26 22:46:26 +00:00
|
|
|
mpeg2dec->segment_start = 0;
|
|
|
|
mpeg2dec->segment_end = -1;
|
|
|
|
mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE;
|
2002-12-05 00:29:11 +00:00
|
|
|
mpeg2dec->frame_period = 0;
|
2002-12-19 20:05:10 +00:00
|
|
|
mpeg2dec->streaminfo = NULL;
|
2002-12-26 22:46:26 +00:00
|
|
|
gst_mpeg2dec_open_decoder (mpeg2dec);
|
|
|
|
mpeg2dec->need_sequence = TRUE;
|
2001-12-23 06:03:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
2003-07-23 05:02:25 +00:00
|
|
|
/* if we've negotiated caps, try to get a bufferpool */
|
|
|
|
if (mpeg2dec->peerpool == NULL && mpeg2dec->width > 0) {
|
|
|
|
mpeg2dec->peerpool = gst_pad_get_bufferpool (mpeg2dec->srcpad);
|
|
|
|
if (mpeg2dec->peerpool)
|
|
|
|
GST_INFO ( "got pool %p", mpeg2dec->peerpool);
|
|
|
|
}
|
2001-12-23 06:03:21 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
/* need to clear things we get from other plugins, since we could be reconnected */
|
|
|
|
if (mpeg2dec->peerpool) {
|
2002-07-08 19:35:51 +00:00
|
|
|
gst_buffer_pool_unref (mpeg2dec->peerpool);
|
2001-12-23 06:03:21 +00:00
|
|
|
mpeg2dec->peerpool = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2002-12-26 22:46:26 +00:00
|
|
|
gst_mpeg2dec_close_decoder (mpeg2dec);
|
2003-02-02 20:03:10 +00:00
|
|
|
gst_caps_replace (&mpeg2dec->streaminfo, NULL);
|
2001-12-23 06:03:21 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-12-26 22:46:26 +00:00
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
2001-12-23 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mpeg2dec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstMpeg2dec *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_MPEG2DEC (object));
|
|
|
|
src = GST_MPEG2DEC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mpeg2dec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
2002-02-06 23:05:22 +00:00
|
|
|
GstMpeg2dec *mpeg2dec;
|
2001-12-23 06:03:21 +00:00
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_MPEG2DEC (object));
|
2002-02-06 23:05:22 +00:00
|
|
|
mpeg2dec = GST_MPEG2DEC (object);
|
2001-12-23 06:03:21 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2002-12-19 20:05:10 +00:00
|
|
|
case ARG_STREAMINFO:
|
|
|
|
g_value_set_boxed (value, mpeg2dec->streaminfo);
|
2002-02-06 23:05:22 +00:00
|
|
|
break;
|
2001-12-23 06:03:21 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-11-02 00:33:31 +00:00
|
|
|
plugin_init (GstPlugin *plugin)
|
2001-12-23 06:03:21 +00:00
|
|
|
{
|
2003-11-02 00:33:31 +00:00
|
|
|
if (!gst_element_register (plugin, "mpeg2dec", GST_RANK_PRIMARY, GST_TYPE_MPEG2DEC))
|
|
|
|
return FALSE;
|
2001-12-23 06:03:21 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-02 00:33:31 +00:00
|
|
|
GST_PLUGIN_DEFINE (
|
2001-12-23 06:03:21 +00:00
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"mpeg2dec",
|
2003-11-02 00:33:31 +00:00
|
|
|
"LibMpeg2 decoder",
|
|
|
|
plugin_init,
|
|
|
|
VERSION,
|
|
|
|
"GPL",
|
|
|
|
GST_COPYRIGHT,
|
|
|
|
GST_PACKAGE,
|
|
|
|
GST_ORIGIN)
|