2002-01-26 02:48:47 +00:00
|
|
|
/* GStreamer
|
2001-12-23 16:42:33 +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:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-23 16:42:33 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/* First, include the header file for the plugin, to bring in the
|
|
|
|
* object definition and other useful things.
|
|
|
|
*/
|
|
|
|
#include "gstdvdec.h"
|
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
#define NTSC_HEIGHT 480
|
|
|
|
#define NTSC_BUFFER 120000
|
|
|
|
#define PAL_HEIGHT 576
|
|
|
|
#define PAL_BUFFER 144000
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
/* The ElementDetails structure gives a human-readable description
|
|
|
|
* of the plugin, as well as author and version data.
|
|
|
|
*/
|
|
|
|
static GstElementDetails dvdec_details = {
|
|
|
|
"DV (smpte314) decoder plugin",
|
2003-07-06 20:49:52 +00:00
|
|
|
"Codec/Video/Decoder",
|
2002-09-18 19:02:51 +00:00
|
|
|
"LGPL",
|
2001-12-23 16:42:33 +00:00
|
|
|
"Uses libdv to decode DV video (libdv.sourceforge.net)",
|
|
|
|
VERSION,
|
2002-01-26 02:48:47 +00:00
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>\n"
|
|
|
|
"Wim Taymans <wim.taymans@tvd.be>",
|
|
|
|
"(C) 2001-2002",
|
2001-12-23 16:42:33 +00:00
|
|
|
};
|
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
|
2001-12-23 16:42:33 +00:00
|
|
|
/* These are the signals that this element can fire. They are zero-
|
|
|
|
* based because the numbers themselves are private to the object.
|
|
|
|
* LAST_SIGNAL is used for initialization of the signal array.
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Arguments are identified the same way, but cannot be zero, so you
|
|
|
|
* must leave the ARG_0 entry in as a placeholder.
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
2002-09-09 22:20:34 +00:00
|
|
|
ARG_CLAMP_LUMA,
|
|
|
|
ARG_CLAMP_CHROMA,
|
|
|
|
ARG_QUALITY,
|
2001-12-23 16:42:33 +00:00
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The PadFactory structures describe what pads the element has or
|
|
|
|
* can have. They can be quite complex, but for this dvdec plugin
|
|
|
|
* they are rather simple.
|
|
|
|
*/
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (sink_temp,
|
2001-12-23 16:42:33 +00:00
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"dv_dec_sink",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-dv",
|
|
|
|
"systemstream", GST_PROPS_BOOLEAN (TRUE)
|
2001-12-23 16:42:33 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (video_src_temp,
|
2001-12-23 16:42:33 +00:00
|
|
|
"video",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2002-01-26 02:48:47 +00:00
|
|
|
GST_CAPS_NEW (
|
|
|
|
"dv_dec_src",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-raw-yuv",
|
2002-01-26 02:48:47 +00:00
|
|
|
"format", GST_PROPS_FOURCC (GST_MAKE_FOURCC ('Y','U','Y','2')),
|
|
|
|
"width", GST_PROPS_INT (720),
|
2003-07-06 20:49:52 +00:00
|
|
|
"height", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_INT (NTSC_HEIGHT),
|
|
|
|
GST_PROPS_INT (PAL_HEIGHT)
|
|
|
|
),
|
|
|
|
"framerate", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_FLOAT (25.),
|
|
|
|
GST_PROPS_FLOAT (30/1.001)
|
|
|
|
)
|
2002-01-26 02:48:47 +00:00
|
|
|
),
|
2001-12-23 16:42:33 +00:00
|
|
|
GST_CAPS_NEW (
|
|
|
|
"dv_dec_src",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-raw-rgb",
|
2002-06-21 18:32:46 +00:00
|
|
|
"bpp", GST_PROPS_INT(32),
|
|
|
|
"depth", GST_PROPS_INT(32),
|
2003-07-06 20:49:52 +00:00
|
|
|
"endianness", GST_PROPS_INT (G_BIG_ENDIAN),
|
|
|
|
"red_mask", GST_PROPS_INT(0x000000ff),
|
2002-06-21 18:32:46 +00:00
|
|
|
"green_mask", GST_PROPS_INT(0x0000ff00),
|
2003-07-23 21:44:47 +00:00
|
|
|
"blue_mask", GST_PROPS_INT(0x00ff0000),
|
2001-12-23 16:42:33 +00:00
|
|
|
"width", GST_PROPS_INT (720),
|
2003-07-06 20:49:52 +00:00
|
|
|
"height", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_INT (NTSC_HEIGHT),
|
|
|
|
GST_PROPS_INT (PAL_HEIGHT)
|
|
|
|
),
|
|
|
|
"framerate", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_FLOAT (25.),
|
|
|
|
GST_PROPS_FLOAT (30/1.001)
|
|
|
|
)
|
2002-06-16 20:49:22 +00:00
|
|
|
),
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"dv_dec_src",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-raw-rgb",
|
2002-06-21 18:32:46 +00:00
|
|
|
"bpp", GST_PROPS_INT(24),
|
|
|
|
"depth", GST_PROPS_INT(24),
|
2003-07-06 20:49:52 +00:00
|
|
|
"endianness", GST_PROPS_INT (G_BIG_ENDIAN),
|
2002-06-21 18:32:46 +00:00
|
|
|
"red_mask", GST_PROPS_INT(0x0000ff),
|
|
|
|
"green_mask", GST_PROPS_INT(0x00ff00),
|
|
|
|
"blue_mask", GST_PROPS_INT(0xff0000),
|
2002-06-16 20:49:22 +00:00
|
|
|
"width", GST_PROPS_INT (720),
|
2003-07-06 20:49:52 +00:00
|
|
|
"height", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_INT (NTSC_HEIGHT),
|
|
|
|
GST_PROPS_INT (PAL_HEIGHT)
|
|
|
|
),
|
|
|
|
"framerate", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_FLOAT (25.),
|
|
|
|
GST_PROPS_FLOAT (30/1.001)
|
|
|
|
)
|
2001-12-23 16:42:33 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY ( audio_src_temp,
|
2001-12-23 16:42:33 +00:00
|
|
|
"audio",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"arts_sample",
|
2003-07-06 20:49:52 +00:00
|
|
|
"audio/x-raw-int",
|
2001-12-23 16:42:33 +00:00
|
|
|
"depth", GST_PROPS_INT (16),
|
|
|
|
"width", GST_PROPS_INT (16),
|
|
|
|
"signed", GST_PROPS_BOOLEAN (TRUE),
|
|
|
|
"channels", GST_PROPS_INT (2),
|
2002-11-02 13:34:42 +00:00
|
|
|
"endianness", GST_PROPS_INT (G_LITTLE_ENDIAN),
|
|
|
|
"rate", GST_PROPS_INT_RANGE (4000, 48000)
|
2001-12-23 16:42:33 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2002-09-09 22:20:34 +00:00
|
|
|
#define GST_TYPE_DVDEC_QUALITY (gst_dvdec_quality_get_type())
|
|
|
|
GType
|
|
|
|
gst_dvdec_quality_get_type (void)
|
|
|
|
{
|
|
|
|
static GType qtype = 0;
|
|
|
|
if (qtype == 0) {
|
|
|
|
static const GFlagsValue values[] = {
|
|
|
|
{ DV_QUALITY_COLOR, "DV_QUALITY_COLOR", "Color or monochrome decoding" },
|
|
|
|
{ DV_QUALITY_AC_1, "DV_QUALITY_AC_1", "AC 1 something" },
|
|
|
|
{ DV_QUALITY_AC_2, "DV_QUALITY_AC_2", "AC 2 something" },
|
|
|
|
{ 0, NULL, NULL }
|
|
|
|
};
|
|
|
|
qtype = g_flags_register_static ("GstDVDecQualityFlags", values);
|
|
|
|
}
|
|
|
|
return qtype;
|
|
|
|
}
|
|
|
|
|
2001-12-23 16:42:33 +00:00
|
|
|
/* A number of functon prototypes are given so we can refer to them later. */
|
2002-06-16 14:45:46 +00:00
|
|
|
static void gst_dvdec_class_init (GstDVDecClass *klass);
|
|
|
|
static void gst_dvdec_init (GstDVDec *dvdec);
|
2001-12-23 16:42:33 +00:00
|
|
|
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType*
|
2002-09-09 22:35:30 +00:00
|
|
|
gst_dvdec_get_src_query_types (GstPad *pad);
|
2002-12-30 17:53:18 +00:00
|
|
|
static gboolean gst_dvdec_src_query (GstPad *pad, GstQueryType type,
|
2002-06-16 14:45:46 +00:00
|
|
|
GstFormat *format, gint64 *value);
|
2002-09-09 22:35:30 +00:00
|
|
|
static const GstFormat* gst_dvdec_get_formats (GstPad *pad);
|
2002-06-16 14:45:46 +00:00
|
|
|
static gboolean gst_dvdec_sink_convert (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value);
|
|
|
|
static gboolean gst_dvdec_src_convert (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value);
|
2002-06-15 14:32:35 +00:00
|
|
|
|
2002-09-09 22:35:30 +00:00
|
|
|
static const GstEventMask*
|
|
|
|
gst_dvdec_get_event_masks (GstPad *pad);
|
2002-06-16 14:45:46 +00:00
|
|
|
static gboolean gst_dvdec_handle_src_event (GstPad *pad, GstEvent *event);
|
|
|
|
|
|
|
|
static void gst_dvdec_loop (GstElement *element);
|
2001-12-23 16:42:33 +00:00
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
static GstElementStateReturn
|
2002-06-16 14:45:46 +00:00
|
|
|
gst_dvdec_change_state (GstElement *element);
|
2002-01-26 02:48:47 +00:00
|
|
|
|
2002-06-16 14:45:46 +00:00
|
|
|
static void gst_dvdec_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_dvdec_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec);
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
/* The parent class pointer needs to be kept around for some object
|
|
|
|
* operations.
|
|
|
|
*/
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
|
|
|
/* This array holds the ids of the signals registered for this object.
|
|
|
|
* The array indexes are based on the enum up above.
|
|
|
|
*/
|
2002-03-19 04:10:05 +00:00
|
|
|
/*static guint gst_dvdec_signals[LAST_SIGNAL] = { 0 }; */
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
/* This function is used to register and subsequently return the type
|
|
|
|
* identifier for this object class. On first invocation, it will
|
|
|
|
* register the type, providing the name of the class, struct sizes,
|
|
|
|
* and pointers to the various functions that define the class.
|
|
|
|
*/
|
|
|
|
GType
|
2002-01-26 02:48:47 +00:00
|
|
|
gst_dvdec_get_type (void)
|
2001-12-23 16:42:33 +00:00
|
|
|
{
|
|
|
|
static GType dvdec_type = 0;
|
|
|
|
|
|
|
|
if (!dvdec_type) {
|
|
|
|
static const GTypeInfo dvdec_info = {
|
2002-01-26 02:48:47 +00:00
|
|
|
sizeof (GstDVDecClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_dvdec_class_init,
|
2001-12-23 16:42:33 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-01-26 02:48:47 +00:00
|
|
|
sizeof (GstDVDec),
|
2001-12-23 16:42:33 +00:00
|
|
|
0,
|
2002-01-26 02:48:47 +00:00
|
|
|
(GInstanceInitFunc) gst_dvdec_init,
|
2001-12-23 16:42:33 +00:00
|
|
|
};
|
2002-01-26 02:48:47 +00:00
|
|
|
dvdec_type = g_type_register_static (GST_TYPE_ELEMENT, "GstDVDec", &dvdec_info, 0);
|
2001-12-23 16:42:33 +00:00
|
|
|
}
|
|
|
|
return dvdec_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In order to create an instance of an object, the class must be
|
|
|
|
* initialized by this function. GObject will take care of running
|
|
|
|
* it, based on the pointer to the function provided above.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_dvdec_class_init (GstDVDecClass *klass)
|
|
|
|
{
|
|
|
|
/* Class pointers are needed to supply pointers to the private
|
|
|
|
* implementations of parent class methods.
|
|
|
|
*/
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
/* Since the dvdec class contains the parent classes, you can simply
|
|
|
|
* cast the pointer to get access to the parent classes.
|
|
|
|
*/
|
2002-01-26 02:48:47 +00:00
|
|
|
gobject_class = (GObjectClass*) klass;
|
|
|
|
gstelement_class = (GstElementClass*) klass;
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
/* The parent class is needed for class method overrides. */
|
2002-01-26 02:48:47 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2001-12-23 16:42:33 +00:00
|
|
|
|
2002-09-09 22:20:34 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CLAMP_LUMA,
|
|
|
|
g_param_spec_boolean ("clamp_luma", "Clamp luma", "Clamp luma",
|
|
|
|
FALSE, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CLAMP_CHROMA,
|
|
|
|
g_param_spec_boolean ("clamp_chroma", "Clamp chroma", "Clamp chroma",
|
|
|
|
FALSE, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY,
|
|
|
|
g_param_spec_flags ("quality", "Quality", "Decoding quality",
|
|
|
|
GST_TYPE_DVDEC_QUALITY, DV_QUALITY_BEST, G_PARAM_READWRITE));
|
|
|
|
|
2001-12-23 16:42:33 +00:00
|
|
|
gobject_class->set_property = gst_dvdec_set_property;
|
|
|
|
gobject_class->get_property = gst_dvdec_get_property;
|
2002-09-09 19:32:19 +00:00
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
gstelement_class->change_state = gst_dvdec_change_state;
|
2001-12-23 16:42:33 +00:00
|
|
|
|
2002-03-19 04:10:05 +00:00
|
|
|
/* table initialization, only do once */
|
2002-04-26 13:25:51 +00:00
|
|
|
dv_init(0, 0);
|
2001-12-23 16:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function is responsible for initializing a specific instance of
|
|
|
|
* the plugin.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_dvdec_init(GstDVDec *dvdec)
|
|
|
|
{
|
2002-06-13 22:30:15 +00:00
|
|
|
gint i;
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
dvdec->sinkpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (sink_temp), "sink");
|
2002-01-26 02:48:47 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->sinkpad);
|
2002-06-15 14:32:35 +00:00
|
|
|
gst_pad_set_query_function (dvdec->sinkpad, NULL);
|
2002-09-09 22:35:30 +00:00
|
|
|
gst_pad_set_convert_function (dvdec->sinkpad, GST_DEBUG_FUNCPTR (gst_dvdec_sink_convert));
|
|
|
|
gst_pad_set_formats_function (dvdec->sinkpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_formats));
|
2001-12-23 16:42:33 +00:00
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
dvdec->videosrcpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (video_src_temp), "video");
|
2002-01-26 02:48:47 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->videosrcpad);
|
2002-09-09 22:35:30 +00:00
|
|
|
gst_pad_set_query_function (dvdec->videosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_src_query));
|
|
|
|
gst_pad_set_query_type_function (dvdec->videosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_src_query_types));
|
|
|
|
gst_pad_set_event_function (dvdec->videosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_handle_src_event));
|
|
|
|
gst_pad_set_event_mask_function (dvdec->videosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_event_masks));
|
|
|
|
gst_pad_set_convert_function (dvdec->videosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_src_convert));
|
|
|
|
gst_pad_set_formats_function (dvdec->videosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_formats));
|
2001-12-23 16:42:33 +00:00
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
dvdec->audiosrcpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET(audio_src_temp), "audio");
|
2002-01-26 02:48:47 +00:00
|
|
|
gst_element_add_pad(GST_ELEMENT(dvdec),dvdec->audiosrcpad);
|
2002-09-09 22:35:30 +00:00
|
|
|
gst_pad_set_query_function (dvdec->audiosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_src_query));
|
|
|
|
gst_pad_set_query_type_function (dvdec->audiosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_src_query_types));
|
|
|
|
gst_pad_set_event_function (dvdec->audiosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_handle_src_event));
|
|
|
|
gst_pad_set_event_mask_function (dvdec->audiosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_event_masks));
|
|
|
|
gst_pad_set_convert_function (dvdec->audiosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_src_convert));
|
|
|
|
gst_pad_set_formats_function (dvdec->audiosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_formats));
|
2001-12-23 16:42:33 +00:00
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
gst_element_set_loop_function (GST_ELEMENT (dvdec), gst_dvdec_loop);
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
dvdec->pool = NULL;
|
2002-06-13 22:30:15 +00:00
|
|
|
dvdec->length = 0;
|
2002-06-15 14:32:35 +00:00
|
|
|
dvdec->next_ts = 0LL;
|
2003-01-04 04:10:30 +00:00
|
|
|
dvdec->end_position = -1LL;
|
2002-06-16 14:45:46 +00:00
|
|
|
dvdec->need_discont = FALSE;
|
|
|
|
dvdec->framerate = 0;
|
|
|
|
dvdec->height = 0;
|
2002-09-09 22:20:34 +00:00
|
|
|
dvdec->clamp_luma = FALSE;
|
|
|
|
dvdec->clamp_chroma = FALSE;
|
|
|
|
dvdec->quality = DV_QUALITY_BEST;
|
2002-11-02 13:34:42 +00:00
|
|
|
dvdec->loop = FALSE;
|
2002-06-13 22:30:15 +00:00
|
|
|
|
|
|
|
for (i = 0; i <4; i++) {
|
|
|
|
dvdec->audio_buffers[i] = (gint16 *)g_malloc (DV_AUDIO_MAX_SAMPLES * sizeof (gint16));
|
|
|
|
}
|
2002-01-26 02:48:47 +00:00
|
|
|
}
|
|
|
|
|
2002-09-09 22:35:30 +00:00
|
|
|
static const GstFormat*
|
|
|
|
gst_dvdec_get_formats (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstFormat src_formats[] = {
|
|
|
|
GST_FORMAT_BYTES,
|
2003-05-24 10:34:34 +00:00
|
|
|
GST_FORMAT_DEFAULT,
|
2002-09-09 22:35:30 +00:00
|
|
|
GST_FORMAT_TIME,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
static const GstFormat sink_formats[] = {
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats);
|
|
|
|
}
|
|
|
|
|
2002-06-16 14:45:46 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dvdec_src_convert (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstDVDec *dvdec;
|
|
|
|
gint scale = 1;
|
|
|
|
|
|
|
|
dvdec = GST_DVDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (dvdec->length == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2002-09-09 22:20:34 +00:00
|
|
|
if (dvdec->decoder == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2002-06-16 14:45:46 +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:
|
|
|
|
if (pad == dvdec->videosrcpad)
|
|
|
|
scale = 720 * dvdec->height * dvdec->bpp;
|
|
|
|
else if (pad == dvdec->audiosrcpad)
|
|
|
|
scale = dvdec->decoder->audio->num_channels * 2;
|
|
|
|
/* fallthrough */
|
2003-05-24 10:34:34 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-06-16 14:45:46 +00:00
|
|
|
if (pad == dvdec->videosrcpad)
|
2003-01-04 04:10:30 +00:00
|
|
|
*dest_value = src_value * dvdec->framerate * scale / (GST_SECOND*100);
|
2002-06-16 14:45:46 +00:00
|
|
|
else if (pad == dvdec->audiosrcpad)
|
|
|
|
*dest_value = src_value * dvdec->decoder->audio->frequency * scale / GST_SECOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_dvdec_sink_convert (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstDVDec *dvdec;
|
|
|
|
|
|
|
|
dvdec = GST_DVDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (dvdec->length == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
2003-05-24 10:34:34 +00:00
|
|
|
{
|
|
|
|
guint64 frame;
|
|
|
|
/* get frame number */
|
|
|
|
frame = src_value / dvdec->length;
|
|
|
|
|
|
|
|
*dest_value = (frame * GST_SECOND * 100) / dvdec->framerate;
|
2002-06-16 14:45:46 +00:00
|
|
|
break;
|
2003-05-24 10:34:34 +00:00
|
|
|
}
|
2002-06-16 14:45:46 +00:00
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
{
|
|
|
|
guint64 frame;
|
|
|
|
/* calculate the frame */
|
2003-01-04 04:10:30 +00:00
|
|
|
frame = src_value * dvdec->framerate / (GST_SECOND*100);
|
2002-06-16 14:45:46 +00:00
|
|
|
/* calculate the offset */
|
|
|
|
*dest_value = frame * dvdec->length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType*
|
2002-09-09 22:35:30 +00:00
|
|
|
gst_dvdec_get_src_query_types (GstPad *pad)
|
|
|
|
{
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType src_query_types[] = {
|
|
|
|
GST_QUERY_TOTAL,
|
|
|
|
GST_QUERY_POSITION,
|
2002-09-09 22:35:30 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
return src_query_types;
|
|
|
|
}
|
|
|
|
|
2002-06-15 14:32:35 +00:00
|
|
|
static gboolean
|
2002-12-30 17:53:18 +00:00
|
|
|
gst_dvdec_src_query (GstPad *pad, GstQueryType type,
|
2002-06-15 14:32:35 +00:00
|
|
|
GstFormat *format, gint64 *value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstDVDec *dvdec;
|
|
|
|
|
|
|
|
dvdec = GST_DVDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (type) {
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_TOTAL:
|
2002-06-15 14:32:35 +00:00
|
|
|
switch (*format) {
|
2002-06-16 14:45:46 +00:00
|
|
|
default:
|
2002-06-15 22:30:58 +00:00
|
|
|
{
|
|
|
|
guint64 len;
|
2002-06-16 14:45:46 +00:00
|
|
|
GstFormat tmp_format;
|
2002-06-15 22:30:58 +00:00
|
|
|
|
|
|
|
len = gst_bytestream_length (dvdec->bs);
|
2002-06-16 14:45:46 +00:00
|
|
|
tmp_format = GST_FORMAT_TIME;
|
2002-09-09 22:20:34 +00:00
|
|
|
if (len == -1 || !gst_pad_convert (dvdec->sinkpad,
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
len,
|
|
|
|
&tmp_format, value))
|
|
|
|
{
|
2002-06-16 14:45:46 +00:00
|
|
|
return FALSE;
|
2002-06-15 22:30:58 +00:00
|
|
|
}
|
2002-06-16 14:45:46 +00:00
|
|
|
if (!gst_pad_convert (pad, GST_FORMAT_TIME, *value, format, value)) {
|
2002-06-15 22:30:58 +00:00
|
|
|
return FALSE;
|
2002-06-16 14:45:46 +00:00
|
|
|
}
|
2002-06-15 14:32:35 +00:00
|
|
|
break;
|
2002-06-15 22:30:58 +00:00
|
|
|
}
|
2002-06-15 14:32:35 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2002-06-15 14:32:35 +00:00
|
|
|
switch (*format) {
|
|
|
|
default:
|
2002-06-16 14:45:46 +00:00
|
|
|
res = gst_pad_convert (pad, GST_FORMAT_TIME, dvdec->next_ts, format, value);
|
2002-06-15 14:32:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-09-09 22:35:30 +00:00
|
|
|
static const GstEventMask*
|
|
|
|
gst_dvdec_get_event_masks (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstEventMask src_event_masks[] = {
|
|
|
|
{ GST_EVENT_SEEK, GST_SEEK_METHOD_SET |
|
|
|
|
GST_SEEK_FLAG_FLUSH },
|
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
static const GstEventMask sink_event_masks[] = {
|
|
|
|
{ GST_EVENT_EOS, 0 },
|
|
|
|
{ GST_EVENT_DISCONTINUOUS, 0 },
|
|
|
|
{ GST_EVENT_FLUSH, 0 },
|
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
|
|
|
|
return (GST_PAD_IS_SRC (pad) ? src_event_masks : sink_event_masks);
|
|
|
|
}
|
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
static gboolean
|
2002-06-16 14:45:46 +00:00
|
|
|
gst_dvdec_handle_sink_event (GstDVDec *dvdec)
|
2002-01-26 02:48:47 +00:00
|
|
|
{
|
|
|
|
guint32 remaining;
|
|
|
|
GstEvent *event;
|
|
|
|
GstEventType type;
|
|
|
|
|
|
|
|
gst_bytestream_get_status (dvdec->bs, &remaining, &event);
|
|
|
|
|
|
|
|
type = event? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
gst_pad_event_default (dvdec->sinkpad, event);
|
2002-07-08 19:31:05 +00:00
|
|
|
return TRUE;
|
2002-01-26 02:48:47 +00:00
|
|
|
case GST_EVENT_FLUSH:
|
|
|
|
break;
|
|
|
|
case GST_EVENT_DISCONTINUOUS:
|
2002-06-16 14:45:46 +00:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gboolean found = FALSE;
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
format = GST_FORMAT_TIME;
|
|
|
|
/* try to get a timestamp from the discont formats */
|
|
|
|
for (i = 0; i < GST_EVENT_DISCONT_OFFSET_LEN(event); i++) {
|
2002-09-09 22:20:34 +00:00
|
|
|
if (gst_pad_convert (dvdec->sinkpad,
|
|
|
|
GST_EVENT_DISCONT_OFFSET(event,i).format,
|
|
|
|
GST_EVENT_DISCONT_OFFSET(event,i).value,
|
|
|
|
&format, &dvdec->next_ts))
|
2002-06-16 14:45:46 +00:00
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* assume 0 then */
|
|
|
|
if (!found) {
|
|
|
|
dvdec->next_ts = 0LL;
|
|
|
|
}
|
|
|
|
dvdec->need_discont = TRUE;
|
2002-01-26 02:48:47 +00:00
|
|
|
break;
|
2002-06-16 14:45:46 +00:00
|
|
|
}
|
2002-01-26 02:48:47 +00:00
|
|
|
default:
|
|
|
|
g_warning ("unhandled event %d\n", type);
|
|
|
|
break;
|
|
|
|
}
|
2002-07-08 19:31:05 +00:00
|
|
|
gst_event_unref (event);
|
2002-01-26 02:48:47 +00:00
|
|
|
return TRUE;
|
2001-12-23 16:42:33 +00:00
|
|
|
}
|
|
|
|
|
2002-06-16 14:45:46 +00:00
|
|
|
static gboolean
|
|
|
|
gst_dvdec_handle_src_event (GstPad *pad, GstEvent *event)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstDVDec *dvdec;
|
|
|
|
|
|
|
|
dvdec = GST_DVDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2002-11-02 13:34:42 +00:00
|
|
|
case GST_EVENT_SEEK_SEGMENT:
|
|
|
|
{
|
|
|
|
gint64 position;
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
/* first bring the format to time */
|
|
|
|
format = GST_FORMAT_TIME;
|
|
|
|
if (!gst_pad_convert (pad,
|
|
|
|
GST_EVENT_SEEK_FORMAT (event),
|
|
|
|
GST_EVENT_SEEK_ENDOFFSET (event),
|
|
|
|
&format, &position))
|
|
|
|
{
|
2003-01-04 04:10:30 +00:00
|
|
|
/* could not convert seek format to time offset */
|
2002-11-02 13:34:42 +00:00
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dvdec->end_position = position;
|
|
|
|
dvdec->loop = GST_EVENT_SEEK_TYPE (event) & GST_SEEK_FLAG_SEGMENT_LOOP;
|
|
|
|
}
|
2002-06-16 14:45:46 +00:00
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
2002-11-02 13:34:42 +00:00
|
|
|
gint64 position;
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
/* first bring the format to time */
|
|
|
|
format = GST_FORMAT_TIME;
|
|
|
|
if (!gst_pad_convert (pad,
|
|
|
|
GST_EVENT_SEEK_FORMAT (event),
|
|
|
|
GST_EVENT_SEEK_OFFSET (event),
|
|
|
|
&format, &position))
|
|
|
|
{
|
2003-01-04 04:10:30 +00:00
|
|
|
/* could not convert seek format to time offset */
|
2002-11-02 13:34:42 +00:00
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2003-05-24 10:34:34 +00:00
|
|
|
dvdec->next_ts = position;
|
2002-11-02 13:34:42 +00:00
|
|
|
/* then try to figure out the byteoffset for this time */
|
|
|
|
format = GST_FORMAT_BYTES;
|
|
|
|
if (!gst_pad_convert (dvdec->sinkpad, GST_FORMAT_TIME, position,
|
2002-09-09 22:20:34 +00:00
|
|
|
&format, &position))
|
2002-11-02 13:34:42 +00:00
|
|
|
{
|
|
|
|
/* could not convert seek format to byte offset */
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* seek to offset */
|
|
|
|
if (!gst_bytestream_seek (dvdec->bs, position, GST_SEEK_METHOD_SET)) {
|
|
|
|
res = FALSE;
|
|
|
|
}
|
2003-05-24 10:34:34 +00:00
|
|
|
if (GST_EVENT_TYPE (event) != GST_EVENT_SEEK_SEGMENT)
|
|
|
|
dvdec->end_position = -1;
|
2002-11-02 13:34:42 +00:00
|
|
|
break;
|
2002-06-16 14:45:46 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2002-07-08 19:31:05 +00:00
|
|
|
gst_event_unref (event);
|
2002-06-16 14:45:46 +00:00
|
|
|
return res;
|
|
|
|
}
|
2001-12-23 16:42:33 +00:00
|
|
|
|
2002-11-02 13:34:42 +00:00
|
|
|
static void
|
|
|
|
gst_dvdec_push (GstDVDec *dvdec, GstBuffer *outbuf, GstPad *pad, GstClockTime ts)
|
|
|
|
{
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = ts;
|
|
|
|
|
|
|
|
if (dvdec->need_discont) {
|
|
|
|
GstEvent *discont;
|
|
|
|
|
|
|
|
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, ts, NULL);
|
2003-10-08 16:08:18 +00:00
|
|
|
gst_pad_push (pad, GST_DATA (discont));
|
2002-11-02 13:34:42 +00:00
|
|
|
}
|
|
|
|
|
2003-10-08 16:08:18 +00:00
|
|
|
gst_pad_push (pad, GST_DATA (outbuf));
|
2002-11-02 13:34:42 +00:00
|
|
|
|
2003-01-04 04:10:30 +00:00
|
|
|
if ((dvdec->end_position != -1) &&
|
|
|
|
(dvdec->next_ts >= dvdec->end_position)) {
|
2002-11-02 13:34:42 +00:00
|
|
|
if (dvdec->loop)
|
2003-10-09 02:23:01 +00:00
|
|
|
gst_pad_push (pad, GST_DATA(gst_event_new (GST_EVENT_SEGMENT_DONE)));
|
2002-11-02 13:34:42 +00:00
|
|
|
else
|
2003-10-09 02:23:01 +00:00
|
|
|
gst_pad_push (pad, GST_DATA(gst_event_new (GST_EVENT_EOS)));
|
2002-11-02 13:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-23 16:42:33 +00:00
|
|
|
static void
|
|
|
|
gst_dvdec_loop (GstElement *element)
|
|
|
|
{
|
|
|
|
GstDVDec *dvdec;
|
2002-01-26 02:48:47 +00:00
|
|
|
GstBuffer *buf, *outbuf;
|
|
|
|
guint8 *inframe;
|
|
|
|
gint height;
|
2002-05-15 19:05:41 +00:00
|
|
|
guint32 length, got_bytes;
|
2002-06-15 14:32:35 +00:00
|
|
|
GstFormat format;
|
|
|
|
guint64 ts;
|
2003-07-06 20:49:52 +00:00
|
|
|
gfloat fps;
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
dvdec = GST_DVDEC (element);
|
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
/* first read enough bytes to parse the header */
|
2002-05-15 19:05:41 +00:00
|
|
|
got_bytes = gst_bytestream_peek_bytes (dvdec->bs, &inframe, header_size);
|
|
|
|
if (got_bytes < header_size) {
|
2002-06-16 14:45:46 +00:00
|
|
|
gst_dvdec_handle_sink_event (dvdec);
|
2002-01-26 02:48:47 +00:00
|
|
|
return;
|
2001-12-23 23:00:59 +00:00
|
|
|
}
|
2002-01-26 02:48:47 +00:00
|
|
|
dv_parse_header (dvdec->decoder, inframe);
|
|
|
|
/* after parsing the header we know the size of the data */
|
2002-06-16 14:45:46 +00:00
|
|
|
dvdec->PAL = dv_system_50_fields (dvdec->decoder);
|
2002-01-26 02:48:47 +00:00
|
|
|
|
2003-01-04 04:10:30 +00:00
|
|
|
dvdec->framerate = (dvdec->PAL ? 2500 : 2997);
|
2003-07-06 20:49:52 +00:00
|
|
|
fps = (dvdec->PAL ? 25. : 30/1.001);
|
2002-06-16 14:45:46 +00:00
|
|
|
dvdec->height = height = (dvdec->PAL ? PAL_HEIGHT : NTSC_HEIGHT);
|
|
|
|
length = (dvdec->PAL ? PAL_BUFFER : NTSC_BUFFER);
|
2001-12-23 16:42:33 +00:00
|
|
|
|
2002-06-13 22:30:15 +00:00
|
|
|
if (length != dvdec->length) {
|
|
|
|
dvdec->length = length;
|
|
|
|
gst_bytestream_size_hint (dvdec->bs, length);
|
|
|
|
}
|
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
/* then read the read data */
|
2002-05-15 19:05:41 +00:00
|
|
|
got_bytes = gst_bytestream_read (dvdec->bs, &buf, length);
|
|
|
|
if (got_bytes < length) {
|
2002-06-16 14:45:46 +00:00
|
|
|
gst_dvdec_handle_sink_event (dvdec);
|
2002-01-26 02:48:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-06-16 14:45:46 +00:00
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
/* if we did not negotiate yet, do it now */
|
2003-05-24 10:34:34 +00:00
|
|
|
if (!GST_PAD_CAPS (dvdec->videosrcpad)) {
|
2002-01-26 02:48:47 +00:00
|
|
|
GstCaps *allowed;
|
|
|
|
GstCaps *trylist;
|
|
|
|
|
|
|
|
/* we what we are allowed to do */
|
|
|
|
allowed = gst_pad_get_allowed_caps (dvdec->videosrcpad);
|
|
|
|
|
|
|
|
/* try to fix our height */
|
2003-07-06 20:49:52 +00:00
|
|
|
trylist = gst_caps_intersect (allowed, gst_caps_append (
|
|
|
|
GST_CAPS_NEW (
|
2002-09-09 22:20:34 +00:00
|
|
|
"dvdec_negotiate",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-raw-yuv",
|
|
|
|
"height", GST_PROPS_INT (height),
|
|
|
|
"framerate", GST_PROPS_FLOAT (fps)
|
|
|
|
), GST_CAPS_NEW (
|
|
|
|
"dvdec_negotiate",
|
|
|
|
"video/x-raw-rgb",
|
|
|
|
"height", GST_PROPS_INT (height),
|
|
|
|
"framerate", GST_PROPS_FLOAT (fps)
|
|
|
|
)));
|
2002-01-26 02:48:47 +00:00
|
|
|
|
|
|
|
/* prepare for looping */
|
|
|
|
trylist = gst_caps_normalize (trylist);
|
|
|
|
|
|
|
|
while (trylist) {
|
2002-06-13 12:17:26 +00:00
|
|
|
GstCaps *to_try = gst_caps_copy_1 (trylist);
|
2002-01-26 02:48:47 +00:00
|
|
|
|
|
|
|
/* try each format */
|
2002-09-10 09:31:40 +00:00
|
|
|
if (gst_pad_try_set_caps (dvdec->videosrcpad, to_try) > 0) {
|
2002-03-30 17:06:26 +00:00
|
|
|
guint32 fourcc;
|
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
/* it worked, try to find what it was again */
|
2002-03-30 17:06:26 +00:00
|
|
|
gst_caps_get_fourcc_int (to_try, "format", &fourcc);
|
|
|
|
|
|
|
|
if (fourcc == GST_STR_FOURCC ("RGB ")) {
|
2002-06-16 20:49:22 +00:00
|
|
|
gint bpp;
|
|
|
|
|
|
|
|
gst_caps_get_int (to_try, "bpp", &bpp);
|
|
|
|
if (bpp == 24) {
|
|
|
|
dvdec->space = e_dv_color_rgb;
|
|
|
|
dvdec->bpp = 3;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dvdec->space = e_dv_color_bgr0;
|
|
|
|
dvdec->bpp = 4;
|
|
|
|
}
|
2002-01-26 02:48:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
dvdec->space = e_dv_color_yuv;
|
|
|
|
dvdec->bpp = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
trylist = trylist->next;
|
|
|
|
}
|
|
|
|
/* oops list exhausted an nothing was found... */
|
|
|
|
if (!trylist) {
|
2003-09-16 10:00:02 +00:00
|
|
|
gst_element_error (element, "could not negotiate");
|
2002-01-26 02:48:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-12-23 23:00:59 +00:00
|
|
|
}
|
2002-06-13 22:30:15 +00:00
|
|
|
|
2002-06-16 14:45:46 +00:00
|
|
|
format = GST_FORMAT_TIME;
|
2002-12-30 17:53:18 +00:00
|
|
|
gst_pad_query (dvdec->videosrcpad, GST_QUERY_POSITION, &format, &ts);
|
2002-06-16 14:45:46 +00:00
|
|
|
|
2003-01-04 04:10:30 +00:00
|
|
|
dvdec->next_ts += (GST_SECOND*100) / dvdec->framerate;
|
2002-11-02 13:34:42 +00:00
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
if (GST_PAD_IS_LINKED (dvdec->audiosrcpad)) {
|
2002-06-16 14:45:46 +00:00
|
|
|
gint16 *a_ptr;
|
|
|
|
gint i, j;
|
|
|
|
|
|
|
|
dv_decode_full_audio (dvdec->decoder, GST_BUFFER_DATA (buf), dvdec->audio_buffers);
|
|
|
|
|
|
|
|
/* if we did not negotiate yet, do it now */
|
|
|
|
if (!GST_PAD_CAPS (dvdec->audiosrcpad)) {
|
|
|
|
gst_pad_try_set_caps (dvdec->audiosrcpad,
|
2002-09-09 22:20:34 +00:00
|
|
|
GST_CAPS_NEW (
|
|
|
|
"dvdec_audio_caps",
|
2003-07-06 20:49:52 +00:00
|
|
|
"audio/x-raw-int",
|
2002-09-09 22:20:34 +00:00
|
|
|
"rate", GST_PROPS_INT (dvdec->decoder->audio->frequency),
|
|
|
|
"depth", GST_PROPS_INT (16),
|
|
|
|
"width", GST_PROPS_INT (16),
|
|
|
|
"signed", GST_PROPS_BOOLEAN (TRUE),
|
|
|
|
"channels", GST_PROPS_INT (dvdec->decoder->audio->num_channels),
|
|
|
|
"endianness", GST_PROPS_INT (G_LITTLE_ENDIAN)
|
|
|
|
));
|
2002-06-16 14:45:46 +00:00
|
|
|
}
|
2002-06-13 22:30:15 +00:00
|
|
|
|
2002-06-15 14:32:35 +00:00
|
|
|
outbuf = gst_buffer_new ();
|
2002-09-09 22:20:34 +00:00
|
|
|
GST_BUFFER_SIZE (outbuf) = dvdec->decoder->audio->samples_this_frame *
|
|
|
|
sizeof (gint16) * dvdec->decoder->audio->num_channels;
|
2002-06-15 14:32:35 +00:00
|
|
|
GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
|
|
|
|
|
|
|
|
a_ptr = (gint16 *) GST_BUFFER_DATA (outbuf);
|
|
|
|
|
|
|
|
for (i = 0; i < dvdec->decoder->audio->samples_this_frame; i++) {
|
|
|
|
for (j = 0; j < dvdec->decoder->audio->num_channels; j++) {
|
|
|
|
*(a_ptr++) = dvdec->audio_buffers[j][i];
|
|
|
|
}
|
2002-06-13 22:30:15 +00:00
|
|
|
}
|
2002-11-02 13:34:42 +00:00
|
|
|
gst_dvdec_push (dvdec, outbuf, dvdec->audiosrcpad, ts);
|
2001-12-23 23:00:59 +00:00
|
|
|
}
|
2001-12-23 16:42:33 +00:00
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
if (GST_PAD_IS_LINKED (dvdec->videosrcpad)) {
|
2002-06-15 14:32:35 +00:00
|
|
|
guint8 *outframe;
|
|
|
|
guint8 *outframe_ptrs[3];
|
|
|
|
gint outframe_pitches[3];
|
|
|
|
|
|
|
|
/* try to grab a pool */
|
|
|
|
if (!dvdec->pool) {
|
|
|
|
dvdec->pool = gst_pad_get_bufferpool (dvdec->videosrcpad);
|
|
|
|
}
|
2002-06-13 22:30:15 +00:00
|
|
|
|
2002-06-15 14:32:35 +00:00
|
|
|
outbuf = NULL;
|
|
|
|
/* try to get a buffer from the pool if we have one */
|
|
|
|
if (dvdec->pool) {
|
|
|
|
outbuf = gst_buffer_new_from_pool (dvdec->pool, 0, 0);
|
|
|
|
}
|
|
|
|
/* no buffer from pool, allocate one ourselves */
|
|
|
|
if (!outbuf) {
|
|
|
|
outbuf = gst_buffer_new ();
|
|
|
|
|
|
|
|
GST_BUFFER_SIZE (outbuf) = (720 * height) * dvdec->bpp;
|
|
|
|
GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
|
|
|
|
}
|
2002-01-26 02:48:47 +00:00
|
|
|
|
2002-06-15 14:32:35 +00:00
|
|
|
outframe = GST_BUFFER_DATA (outbuf);
|
2001-12-23 16:42:33 +00:00
|
|
|
|
2002-06-15 14:32:35 +00:00
|
|
|
outframe_ptrs[0] = outframe;
|
|
|
|
outframe_pitches[0] = 720 * dvdec->bpp;
|
2002-06-16 20:49:22 +00:00
|
|
|
|
|
|
|
/* the rest only matters for YUY2 */
|
|
|
|
if (dvdec->bpp < 3) {
|
|
|
|
outframe_ptrs[1] = outframe_ptrs[0] + 720 * height;
|
|
|
|
outframe_ptrs[2] = outframe_ptrs[1] + 360 * height;
|
|
|
|
|
|
|
|
outframe_pitches[1] = height / 2;
|
|
|
|
outframe_pitches[2] = outframe_pitches[1];
|
|
|
|
}
|
2002-01-26 02:48:47 +00:00
|
|
|
|
2002-06-15 14:32:35 +00:00
|
|
|
dv_decode_full_frame (dvdec->decoder, GST_BUFFER_DATA (buf),
|
|
|
|
dvdec->space, outframe_ptrs, outframe_pitches);
|
2002-01-26 02:48:47 +00:00
|
|
|
|
2002-11-02 13:34:42 +00:00
|
|
|
gst_dvdec_push (dvdec, outbuf, dvdec->videosrcpad, ts);
|
2002-06-15 14:32:35 +00:00
|
|
|
}
|
2002-01-26 02:48:47 +00:00
|
|
|
|
2003-01-04 04:10:30 +00:00
|
|
|
if ((dvdec->end_position != -1) &&
|
|
|
|
(dvdec->next_ts >= dvdec->end_position) &&
|
|
|
|
!dvdec->loop) {
|
2002-11-02 13:34:42 +00:00
|
|
|
gst_element_set_eos (GST_ELEMENT (dvdec));
|
|
|
|
}
|
2002-06-16 14:45:46 +00:00
|
|
|
|
|
|
|
if (dvdec->need_discont) {
|
|
|
|
dvdec->need_discont = FALSE;
|
|
|
|
}
|
2002-06-15 14:32:35 +00:00
|
|
|
|
|
|
|
gst_buffer_unref (buf);
|
2002-01-26 02:48:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_dvdec_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstDVDec *dvdec = GST_DVDEC (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
dvdec->bs = gst_bytestream_new (dvdec->sinkpad);
|
2002-09-09 22:20:34 +00:00
|
|
|
dvdec->decoder = dv_decoder_new (0, dvdec->clamp_luma, dvdec->clamp_chroma);
|
|
|
|
dvdec->decoder->quality = dvdec->quality;
|
2002-01-26 02:48:47 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
2002-07-08 19:31:05 +00:00
|
|
|
if (dvdec->pool)
|
|
|
|
gst_buffer_pool_unref (dvdec->pool);
|
2002-01-26 02:48:47 +00:00
|
|
|
dvdec->pool = NULL;
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2002-09-09 22:20:34 +00:00
|
|
|
dv_decoder_free (dvdec->decoder);
|
|
|
|
dvdec->decoder = NULL;
|
2002-01-26 02:48:47 +00:00
|
|
|
gst_bytestream_destroy (dvdec->bs);
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent_class->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
2001-12-23 16:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Arguments are part of the Gtk+ object system, and these functions
|
|
|
|
* enable the element to respond to various arguments.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_dvdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstDVDec *dvdec;
|
|
|
|
|
|
|
|
/* It's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail(GST_IS_DVDEC(object));
|
|
|
|
|
|
|
|
/* Get a pointer of the right type. */
|
|
|
|
dvdec = GST_DVDEC(object);
|
|
|
|
|
|
|
|
/* Check the argument id to see which argument we're setting. */
|
|
|
|
switch (prop_id) {
|
2002-09-09 22:20:34 +00:00
|
|
|
case ARG_CLAMP_LUMA:
|
|
|
|
dvdec->clamp_luma = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case ARG_CLAMP_CHROMA:
|
|
|
|
dvdec->clamp_chroma = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case ARG_QUALITY:
|
|
|
|
dvdec->quality = g_value_get_flags (value);
|
|
|
|
break;
|
2001-12-23 16:42:33 +00:00
|
|
|
default:
|
2002-09-12 20:55:10 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-12-23 16:42:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The set function is simply the inverse of the get fuction. */
|
|
|
|
static void
|
|
|
|
gst_dvdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstDVDec *dvdec;
|
|
|
|
|
|
|
|
/* It's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail(GST_IS_DVDEC(object));
|
|
|
|
dvdec = GST_DVDEC(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2002-09-09 22:20:34 +00:00
|
|
|
case ARG_CLAMP_LUMA:
|
|
|
|
g_value_set_boolean (value, dvdec->clamp_luma);
|
|
|
|
break;
|
|
|
|
case ARG_CLAMP_CHROMA:
|
|
|
|
g_value_set_boolean (value, dvdec->clamp_chroma);
|
|
|
|
break;
|
|
|
|
case ARG_QUALITY:
|
|
|
|
g_value_set_flags (value, dvdec->quality);
|
|
|
|
break;
|
2001-12-23 16:42:33 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the entry into the plugin itself. When the plugin loads,
|
|
|
|
* this function is called to register everything that the plugin provides.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GModule *module, GstPlugin *plugin)
|
|
|
|
{
|
|
|
|
GstElementFactory *factory;
|
|
|
|
|
2003-10-28 20:52:41 +00:00
|
|
|
if (!gst_library_load ("gstbytestream"))
|
|
|
|
return FALSE;
|
|
|
|
|
2001-12-23 16:42:33 +00:00
|
|
|
/* We need to create an ElementFactory for each element we provide.
|
|
|
|
* This consists of the name of the element, the GType identifier,
|
|
|
|
* and a pointer to the details structure at the top of the file.
|
|
|
|
*/
|
2002-04-11 20:42:25 +00:00
|
|
|
factory = gst_element_factory_new("dvdec", GST_TYPE_DVDEC, &dvdec_details);
|
2001-12-23 16:42:33 +00:00
|
|
|
g_return_val_if_fail(factory != NULL, FALSE);
|
|
|
|
|
2002-06-13 18:46:36 +00:00
|
|
|
gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_PRIMARY);
|
2001-12-23 16:42:33 +00:00
|
|
|
/* The pad templates can be easily generated from the factories above,
|
|
|
|
* and then added to the list of padtemplates for the elementfactory.
|
|
|
|
* Note that the generated padtemplates are stored in static global
|
|
|
|
* variables, for the gst_dvdec_init function to use later on.
|
|
|
|
*/
|
2002-04-11 20:42:25 +00:00
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET(sink_temp));
|
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET(video_src_temp));
|
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET(audio_src_temp));
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
/* The very last thing is to register the elementfactory with the plugin. */
|
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstPluginDesc plugin_desc = {
|
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"dvdec",
|
|
|
|
plugin_init
|
|
|
|
};
|