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>
|
2004-10-26 17:59:18 +00:00
|
|
|
#include <math.h>
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
/* First, include the header file for the plugin, to bring in the
|
|
|
|
* object definition and other useful things.
|
|
|
|
*/
|
|
|
|
#include "gstdvdec.h"
|
|
|
|
|
2005-01-28 17:35:13 +00:00
|
|
|
/* DV output has two modes, normal and wide. The resolution is the same in both
|
|
|
|
* cases: 720 pixels wide by 576 pixels tall in PAL format, and 720x480 for
|
|
|
|
* NTSC.
|
|
|
|
*
|
|
|
|
* Each of the modes has its own pixel aspect ratio, which is fixed in practice
|
|
|
|
* by ITU-R BT.601 (also known as "CCIR-601" or "Rec.601"). Or so claims a
|
|
|
|
* reference that I culled from the reliable "internet",
|
|
|
|
* http://www.mir.com/DMG/aspect.html. Normal PAL is 59/54 and normal NTSC is
|
|
|
|
* 10/11. Because the pixel resolution is the same for both cases, we can get
|
|
|
|
* the pixel aspect ratio for wide recordings by multiplying by the ratio of
|
|
|
|
* display aspect ratios, 16/9 (for wide) divided by 4/3 (for normal):
|
|
|
|
*
|
|
|
|
* Wide NTSC: 10/11 * (16/9)/(4/3) = 40/33
|
|
|
|
* Wide PAL: 59/54 * (16/9)/(4/3) = 118/81
|
|
|
|
*
|
|
|
|
* However, the pixel resolution coming out of a DV source does not combine with
|
|
|
|
* the standard pixel aspect ratios to give a proper display aspect ratio. An
|
|
|
|
* image 480 pixels tall, with a 4:3 display aspect ratio, will be 768 pixels
|
|
|
|
* wide. But, if we take the normal PAL aspect ratio of 59/54, and multiply it
|
|
|
|
* with the width of the DV image (720 pixels), we get 786.666..., which is
|
|
|
|
* nonintegral and too wide. The camera is not outputting a 4:3 image.
|
|
|
|
*
|
|
|
|
* If the video sink for this stream has fixed dimensions (such as for
|
|
|
|
* fullscreen playback, or for a java applet in a web page), you then have two
|
|
|
|
* choices. Either you show the whole image, but pad the image with black
|
|
|
|
* borders on the top and bottom (like watching a widescreen video on a 4:3
|
|
|
|
* device), or you crop the video to the proper ratio. Apparently the latter is
|
|
|
|
* the standard practice.
|
|
|
|
*
|
|
|
|
* For its part, GStreamer is concerned with accuracy and preservation of
|
|
|
|
* information. This element outputs the 720x576 or 720x480 video that it
|
|
|
|
* recieves, noting the proper aspect ratio. This should not be a problem for
|
|
|
|
* windowed applications, which can change size to fit the video. Applications
|
|
|
|
* with fixed size requirements should decide whether to crop or pad. If you
|
|
|
|
* decide to crop, the videocrop element might be useful to you.
|
|
|
|
*/
|
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
#define NTSC_HEIGHT 480
|
|
|
|
#define NTSC_BUFFER 120000
|
2005-01-14 18:36:42 +00:00
|
|
|
#define NTSC_FRAMERATE 30000/1001.
|
2003-12-22 01:47:09 +00:00
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
#define PAL_HEIGHT 576
|
|
|
|
#define PAL_BUFFER 144000
|
2003-12-22 01:47:09 +00:00
|
|
|
#define PAL_FRAMERATE 25.0
|
2001-12-23 16:42:33 +00:00
|
|
|
|
2005-01-28 17:35:13 +00:00
|
|
|
#define PAL_NORMAL_PAR_X 59
|
|
|
|
#define PAL_NORMAL_PAR_Y 54
|
|
|
|
#define PAL_WIDE_PAR_X 118
|
|
|
|
#define PAL_WIDE_PAR_Y 81
|
2004-10-18 14:02:51 +00:00
|
|
|
|
2005-01-28 17:35:13 +00:00
|
|
|
#define NTSC_NORMAL_PAR_X 10
|
|
|
|
#define NTSC_NORMAL_PAR_Y 11
|
|
|
|
#define NTSC_WIDE_PAR_X 40
|
|
|
|
#define NTSC_WIDE_PAR_Y 33
|
2004-10-18 14:02:51 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2004-03-14 20:54:13 +00:00
|
|
|
static GstElementDetails dvdec_details =
|
|
|
|
GST_ELEMENT_DETAILS ("DV (smpte314) decoder plugin",
|
|
|
|
"Codec/Decoder/Video",
|
|
|
|
"Uses libdv to decode DV video (libdv.sourceforge.net)",
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>\n" "Wim Taymans <wim.taymans@tvd.be>");
|
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.
|
|
|
|
*/
|
2004-03-14 20:54:13 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-23 16:42:33 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-06-27 16:38:41 +00:00
|
|
|
#define DV_DEFAULT_QUALITY DV_QUALITY_BEST
|
|
|
|
#define DV_DEFAULT_DECODE_NTH 1
|
|
|
|
|
2001-12-23 16:42:33 +00:00
|
|
|
/* Arguments are identified the same way, but cannot be zero, so you
|
|
|
|
* must leave the ARG_0 entry in as a placeholder.
|
|
|
|
*/
|
2004-03-14 20:54:13 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-23 16:42:33 +00:00
|
|
|
ARG_0,
|
2002-09-09 22:20:34 +00:00
|
|
|
ARG_CLAMP_LUMA,
|
|
|
|
ARG_CLAMP_CHROMA,
|
2004-06-27 16:38:41 +00:00
|
|
|
ARG_QUALITY,
|
|
|
|
ARG_DECODE_NTH
|
2004-05-21 23:28:57 +00:00
|
|
|
/* FILL ME */
|
2001-12-23 16:42:33 +00:00
|
|
|
};
|
|
|
|
|
2004-05-12 14:53:57 +00:00
|
|
|
const gint qualities[] = {
|
|
|
|
DV_QUALITY_DC,
|
|
|
|
DV_QUALITY_AC_1,
|
|
|
|
DV_QUALITY_AC_2,
|
|
|
|
DV_QUALITY_DC | DV_QUALITY_COLOR,
|
|
|
|
DV_QUALITY_AC_1 | DV_QUALITY_COLOR,
|
2004-05-21 23:28:57 +00:00
|
|
|
DV_QUALITY_AC_2 | DV_QUALITY_COLOR
|
2004-05-12 14:53:57 +00:00
|
|
|
};
|
|
|
|
|
2001-12-23 16:42:33 +00:00
|
|
|
/* 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.
|
|
|
|
*/
|
2004-03-14 20:54:13 +00:00
|
|
|
static GstStaticPadTemplate sink_temp = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/x-dv, systemstream = (boolean) true")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate video_src_temp = GST_STATIC_PAD_TEMPLATE ("video",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/x-raw-yuv, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"format = (fourcc) YUY2, "
|
|
|
|
"width = (int) 720, "
|
|
|
|
"height = (int) { "
|
|
|
|
G_STRINGIFY (NTSC_HEIGHT) ", " G_STRINGIFY (PAL_HEIGHT)
|
2004-10-18 14:02:51 +00:00
|
|
|
" }, "
|
|
|
|
"pixel-aspect-ratio=(fraction) { "
|
|
|
|
G_STRINGIFY (PAL_NORMAL_PAR_X) "/" G_STRINGIFY (PAL_NORMAL_PAR_Y) ","
|
|
|
|
G_STRINGIFY (PAL_WIDE_PAR_X) "/" G_STRINGIFY (PAL_WIDE_PAR_Y) ","
|
|
|
|
G_STRINGIFY (NTSC_NORMAL_PAR_X) "/" G_STRINGIFY (NTSC_NORMAL_PAR_Y) ","
|
|
|
|
G_STRINGIFY (NTSC_WIDE_PAR_X) "/" G_STRINGIFY (NTSC_WIDE_PAR_Y) "},"
|
|
|
|
"framerate = (double) [ 1.0, 60.0 ];"
|
2004-06-27 16:38:41 +00:00
|
|
|
//"framerate = (double) { "
|
|
|
|
//G_STRINGIFY (PAL_FRAMERATE) ", " G_STRINGIFY (NTSC_FRAMERATE)
|
|
|
|
//" }; "
|
2004-03-15 19:32:27 +00:00
|
|
|
"video/x-raw-rgb, "
|
|
|
|
"bpp = (int) 32, "
|
2005-01-07 22:42:32 +00:00
|
|
|
"depth = (int) 24, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"endianness = (int) " G_STRINGIFY (G_BIG_ENDIAN) ", "
|
2005-01-08 15:30:33 +00:00
|
|
|
"red_mask = (int) 0x0000ff00, "
|
|
|
|
"green_mask = (int) 0x00ff0000, "
|
|
|
|
"blue_mask = (int) 0xff000000, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"width = (int) 720, "
|
|
|
|
"height = (int) { "
|
|
|
|
G_STRINGIFY (NTSC_HEIGHT) ", " G_STRINGIFY (PAL_HEIGHT)
|
2004-10-18 14:02:51 +00:00
|
|
|
" }, "
|
|
|
|
"pixel-aspect-ratio=(fraction) { "
|
|
|
|
G_STRINGIFY (PAL_NORMAL_PAR_X) "/" G_STRINGIFY (PAL_NORMAL_PAR_Y) ","
|
|
|
|
G_STRINGIFY (PAL_WIDE_PAR_X) "/" G_STRINGIFY (PAL_WIDE_PAR_Y) ","
|
|
|
|
G_STRINGIFY (NTSC_NORMAL_PAR_X) "/" G_STRINGIFY (NTSC_NORMAL_PAR_Y) ","
|
|
|
|
G_STRINGIFY (NTSC_WIDE_PAR_X) "/" G_STRINGIFY (NTSC_WIDE_PAR_Y) "},"
|
|
|
|
"framerate = (double) [ 1.0, 60.0 ];"
|
2004-06-27 16:38:41 +00:00
|
|
|
//"framerate = (double) { "
|
|
|
|
//G_STRINGIFY (PAL_FRAMERATE) ", " G_STRINGIFY (NTSC_FRAMERATE)
|
|
|
|
//" }; "
|
2004-03-15 19:32:27 +00:00
|
|
|
"video/x-raw-rgb, "
|
|
|
|
"bpp = (int) 24, "
|
|
|
|
"depth = (int) 24, "
|
|
|
|
"endianness = (int) " G_STRINGIFY (G_BIG_ENDIAN) ", "
|
2004-05-07 16:17:25 +00:00
|
|
|
"red_mask = (int) 0x00ff0000, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"green_mask = (int) 0x0000ff00, "
|
2004-05-07 16:17:25 +00:00
|
|
|
"blue_mask = (int) 0x000000ff, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"width = (int) 720, "
|
|
|
|
"height = (int) { "
|
|
|
|
G_STRINGIFY (NTSC_HEIGHT) ", " G_STRINGIFY (PAL_HEIGHT)
|
2004-10-18 14:02:51 +00:00
|
|
|
" }, "
|
|
|
|
"pixel-aspect-ratio=(fraction) { "
|
|
|
|
G_STRINGIFY (PAL_NORMAL_PAR_X) "/" G_STRINGIFY (PAL_NORMAL_PAR_Y) ","
|
|
|
|
G_STRINGIFY (PAL_WIDE_PAR_X) "/" G_STRINGIFY (PAL_WIDE_PAR_Y) ","
|
|
|
|
G_STRINGIFY (NTSC_NORMAL_PAR_X) "/" G_STRINGIFY (NTSC_NORMAL_PAR_Y) ","
|
|
|
|
G_STRINGIFY (NTSC_WIDE_PAR_X) "/" G_STRINGIFY (NTSC_WIDE_PAR_Y) "},"
|
|
|
|
"framerate = (double) [ 1.0, 60.0 ]"
|
2004-06-27 16:38:41 +00:00
|
|
|
//"framerate = (double) { "
|
|
|
|
//G_STRINGIFY (PAL_FRAMERATE) ", " G_STRINGIFY (NTSC_FRAMERATE)
|
|
|
|
//" }"
|
|
|
|
)
|
2004-03-14 20:54:13 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate audio_src_temp = GST_STATIC_PAD_TEMPLATE ("audio",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"depth = (int) 16, "
|
|
|
|
"width = (int) 16, "
|
|
|
|
"signed = (boolean) TRUE, "
|
2005-01-07 23:46:23 +00:00
|
|
|
"channels = (int) {2, 4}, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"endianness = (int) " G_STRINGIFY (G_LITTLE_ENDIAN) ", "
|
2005-01-07 23:46:23 +00:00
|
|
|
"rate = (int) { 32000, 44100, 48000 }")
|
2004-03-14 20:54:13 +00:00
|
|
|
);
|
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;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2002-09-09 22:20:34 +00:00
|
|
|
if (qtype == 0) {
|
2004-05-12 14:53:57 +00:00
|
|
|
static const GEnumValue values[] = {
|
|
|
|
{0, "DV_QUALITY_FASTEST", "Fastest decoding, low-quality mono"},
|
|
|
|
{1, "DV_QUALITY_AC_1", "Mono decoding using the first AC coefficient"},
|
|
|
|
{2, "DV_QUALITY_AC_2", "Highest quality mono decoding"},
|
|
|
|
{3, "DV_QUALITY_DC|DV_QUALITY_COLOUR", "Fastest colour decoding"},
|
|
|
|
{4, "DV_QUALITY_AC_1|DV_QUALITY_COLOUR",
|
2004-05-13 11:32:42 +00:00
|
|
|
"Colour, using only the first AC coefficient"},
|
2004-05-12 14:53:57 +00:00
|
|
|
{5, "DV_QUALITY_BEST", "Highest quality colour decoding"},
|
2004-05-19 09:21:43 +00:00
|
|
|
{0, NULL, NULL},
|
2002-09-09 22:20:34 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-05-12 14:53:57 +00:00
|
|
|
qtype = g_enum_register_static ("GstDVDecQualityEnum", values);
|
2002-09-09 22:20:34 +00:00
|
|
|
}
|
|
|
|
return qtype;
|
|
|
|
}
|
|
|
|
|
2001-12-23 16:42:33 +00:00
|
|
|
/* A number of functon prototypes are given so we can refer to them later. */
|
2004-03-14 20:54:13 +00:00
|
|
|
static void gst_dvdec_base_init (gpointer g_class);
|
|
|
|
static void gst_dvdec_class_init (GstDVDecClass * klass);
|
|
|
|
static void gst_dvdec_init (GstDVDec * dvdec);
|
|
|
|
|
|
|
|
static const GstQueryType *gst_dvdec_get_src_query_types (GstPad * pad);
|
|
|
|
static gboolean gst_dvdec_src_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value);
|
|
|
|
static const GstFormat *gst_dvdec_get_formats (GstPad * pad);
|
|
|
|
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);
|
|
|
|
|
|
|
|
static GstPadLinkReturn gst_dvdec_video_link (GstPad * pad,
|
|
|
|
const GstCaps * caps);
|
|
|
|
static GstCaps *gst_dvdec_video_getcaps (GstPad * pad);
|
|
|
|
|
|
|
|
static const GstEventMask *gst_dvdec_get_event_masks (GstPad * pad);
|
|
|
|
static gboolean gst_dvdec_handle_src_event (GstPad * pad, GstEvent * event);
|
|
|
|
|
|
|
|
static void gst_dvdec_loop (GstElement * element);
|
|
|
|
|
|
|
|
static GstElementStateReturn gst_dvdec_change_state (GstElement * element);
|
|
|
|
|
|
|
|
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 = {
|
2004-03-14 20:54:13 +00:00
|
|
|
sizeof (GstDVDecClass),
|
|
|
|
gst_dvdec_base_init,
|
2002-01-26 02:48:47 +00:00
|
|
|
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
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 20:54:13 +00:00
|
|
|
dvdec_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstDVDec", &dvdec_info, 0);
|
2001-12-23 16:42:33 +00:00
|
|
|
}
|
|
|
|
return dvdec_type;
|
|
|
|
}
|
|
|
|
|
2003-11-02 03:32:31 +00:00
|
|
|
static void
|
|
|
|
gst_dvdec_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sink_temp));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&video_src_temp));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&audio_src_temp));
|
2003-11-02 03:32:31 +00:00
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &dvdec_details);
|
|
|
|
}
|
|
|
|
|
2001-12-23 16:42:33 +00:00
|
|
|
/* 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
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_dvdec_class_init (GstDVDecClass * klass)
|
2001-12-23 16:42:33 +00:00
|
|
|
{
|
|
|
|
/* 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.
|
|
|
|
*/
|
2004-03-14 20:54:13 +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,
|
2004-03-14 20:54:13 +00:00
|
|
|
g_param_spec_boolean ("clamp_luma", "Clamp luma", "Clamp luma",
|
2004-03-15 19:32:27 +00:00
|
|
|
FALSE, G_PARAM_READWRITE));
|
2002-09-09 22:20:34 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CLAMP_CHROMA,
|
2004-03-14 20:54:13 +00:00
|
|
|
g_param_spec_boolean ("clamp_chroma", "Clamp chroma", "Clamp chroma",
|
2004-03-15 19:32:27 +00:00
|
|
|
FALSE, G_PARAM_READWRITE));
|
2002-09-09 22:20:34 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY,
|
2004-05-12 14:53:57 +00:00
|
|
|
g_param_spec_enum ("quality", "Quality", "Decoding quality",
|
2004-06-27 16:38:41 +00:00
|
|
|
GST_TYPE_DVDEC_QUALITY, DV_DEFAULT_QUALITY, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DECODE_NTH,
|
|
|
|
g_param_spec_int ("drop-factor", "Drop Factor", "Only decode Nth frame",
|
|
|
|
1, G_MAXINT, DV_DEFAULT_DECODE_NTH, G_PARAM_READWRITE));
|
2002-09-09 22:20:34 +00:00
|
|
|
|
2001-12-23 16:42:33 +00:00
|
|
|
gobject_class->set_property = gst_dvdec_set_property;
|
|
|
|
gobject_class->get_property = gst_dvdec_get_property;
|
2004-03-14 20:54:13 +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 */
|
2004-03-14 20:54:13 +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
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_dvdec_init (GstDVDec * dvdec)
|
2001-12-23 16:42:33 +00:00
|
|
|
{
|
2002-06-13 22:30:15 +00:00
|
|
|
gint i;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-02-07 13:04:09 +00:00
|
|
|
dvdec->found_header = FALSE;
|
2002-06-13 22:30:15 +00:00
|
|
|
|
2004-03-14 20:54:13 +00:00
|
|
|
dvdec->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get (&sink_temp),
|
|
|
|
"sink");
|
2002-06-15 14:32:35 +00:00
|
|
|
gst_pad_set_query_function (dvdec->sinkpad, NULL);
|
2004-03-14 20:54:13 +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));
|
2004-05-21 13:28:24 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->sinkpad);
|
2004-03-14 20:54:13 +00:00
|
|
|
|
|
|
|
dvdec->videosrcpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get (&video_src_temp),
|
|
|
|
"video");
|
|
|
|
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));
|
|
|
|
gst_pad_set_getcaps_function (dvdec->videosrcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dvdec_video_getcaps));
|
|
|
|
gst_pad_set_link_function (dvdec->videosrcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_dvdec_video_link));
|
2004-02-07 13:04:09 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->videosrcpad);
|
2004-03-14 20:54:13 +00:00
|
|
|
|
|
|
|
dvdec->audiosrcpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get (&audio_src_temp),
|
|
|
|
"audio");
|
|
|
|
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));
|
2004-02-07 13:04:09 +00:00
|
|
|
gst_pad_use_explicit_caps (dvdec->audiosrcpad);
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->audiosrcpad);
|
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
|
|
|
|
2004-06-07 12:01:52 +00:00
|
|
|
dvdec->bs = 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;
|
2004-06-07 12:01:52 +00:00
|
|
|
dvdec->new_media = FALSE;
|
2002-06-16 14:45:46 +00:00
|
|
|
dvdec->framerate = 0;
|
|
|
|
dvdec->height = 0;
|
2004-02-07 13:04:09 +00:00
|
|
|
dvdec->frequency = 0;
|
|
|
|
dvdec->channels = 0;
|
2004-10-18 17:49:09 +00:00
|
|
|
dvdec->wide = FALSE;
|
2004-06-27 16:38:41 +00:00
|
|
|
dvdec->drop_factor = 1;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2002-09-09 22:20:34 +00:00
|
|
|
dvdec->clamp_luma = FALSE;
|
|
|
|
dvdec->clamp_chroma = FALSE;
|
2004-06-27 16:38:41 +00:00
|
|
|
dvdec->quality = DV_DEFAULT_QUALITY;
|
2002-11-02 13:34:42 +00:00
|
|
|
dvdec->loop = FALSE;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
dvdec->audio_buffers[i] =
|
2004-03-15 19:32:27 +00:00
|
|
|
(gint16 *) g_malloc (DV_AUDIO_MAX_SAMPLES * sizeof (gint16));
|
2002-06-13 22:30:15 +00:00
|
|
|
}
|
2002-01-26 02:48:47 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 20:54:13 +00:00
|
|
|
static const GstFormat *
|
|
|
|
gst_dvdec_get_formats (GstPad * pad)
|
2002-09-09 22:35:30 +00:00
|
|
|
{
|
|
|
|
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,
|
2004-05-21 13:28:24 +00:00
|
|
|
GST_FORMAT_DEFAULT,
|
2002-09-09 22:35:30 +00:00
|
|
|
0
|
|
|
|
};
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2002-09-09 22:35:30 +00:00
|
|
|
return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats);
|
2004-03-14 20:54:13 +00:00
|
|
|
}
|
2002-09-09 22:35:30 +00:00
|
|
|
|
2002-06-16 14:45:46 +00:00
|
|
|
static gboolean
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_dvdec_src_convert (GstPad * pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat * dest_format, gint64 * dest_value)
|
2002-06-16 14:45:46 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstDVDec *dvdec;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2002-06-16 14:45:46 +00:00
|
|
|
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) {
|
2004-05-21 13:28:24 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_DEFAULT:
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_TIME:
|
2004-05-21 13:28:24 +00:00
|
|
|
*dest_format = GST_FORMAT_TIME;
|
|
|
|
if (pad == dvdec->videosrcpad)
|
|
|
|
*dest_value = src_value * GST_SECOND /
|
|
|
|
(720 * dvdec->height * dvdec->bpp * dvdec->framerate /
|
|
|
|
GST_SECOND);
|
|
|
|
else if (pad == dvdec->audiosrcpad)
|
|
|
|
*dest_value = src_value * GST_SECOND /
|
2004-06-07 12:01:52 +00:00
|
|
|
(2 * dvdec->frequency * dvdec->channels);
|
2004-05-21 13:28:24 +00:00
|
|
|
break;
|
2004-03-15 19:32:27 +00:00
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-06-16 14:45:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
if (pad == dvdec->videosrcpad)
|
2004-05-21 13:28:24 +00:00
|
|
|
*dest_value = src_value * 720 * dvdec->height * dvdec->bpp *
|
|
|
|
dvdec->framerate / GST_SECOND;
|
2004-03-15 19:32:27 +00:00
|
|
|
else if (pad == dvdec->audiosrcpad)
|
2004-06-07 12:01:52 +00:00
|
|
|
*dest_value = 2 * src_value * dvdec->frequency *
|
|
|
|
dvdec->channels / GST_SECOND;
|
2004-05-21 13:28:24 +00:00
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2004-05-13 11:32:42 +00:00
|
|
|
*dest_format = GST_FORMAT_TIME;
|
2004-05-21 13:28:24 +00:00
|
|
|
*dest_value = src_value;
|
2004-03-15 19:32:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-06-16 14:45:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_dvdec_sink_convert (GstPad * pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat * dest_format, gint64 * dest_value)
|
2002-06-16 14:45:46 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstDVDec *dvdec;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2002-06-16 14:45:46 +00:00
|
|
|
dvdec = GST_DVDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (dvdec->length == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2004-05-21 13:28:24 +00:00
|
|
|
if (*dest_format == GST_FORMAT_DEFAULT)
|
|
|
|
*dest_format = GST_FORMAT_TIME;
|
|
|
|
|
2002-06-16 14:45:46 +00:00
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
|
|
|
guint64 frame;
|
|
|
|
|
|
|
|
/* get frame number */
|
|
|
|
frame = src_value / dvdec->length;
|
|
|
|
|
|
|
|
*dest_value = (frame * GST_SECOND) / dvdec->framerate;
|
|
|
|
break;
|
|
|
|
}
|
2004-05-21 13:28:24 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value;
|
|
|
|
break;
|
2004-03-15 19:32:27 +00:00
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-06-16 14:45:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
{
|
|
|
|
guint64 frame;
|
|
|
|
|
|
|
|
/* calculate the frame */
|
|
|
|
frame = src_value * dvdec->framerate / GST_SECOND;
|
|
|
|
/* calculate the offset */
|
|
|
|
*dest_value = frame * dvdec->length;
|
|
|
|
break;
|
|
|
|
}
|
2004-05-21 13:28:24 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
*dest_value = src_value;
|
|
|
|
break;
|
2004-03-15 19:32:27 +00:00
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-06-16 14:45:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-03-14 20:54:13 +00:00
|
|
|
static const GstQueryType *
|
|
|
|
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
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2002-09-09 22:35:30 +00:00
|
|
|
return src_query_types;
|
|
|
|
}
|
|
|
|
|
2002-06-15 14:32:35 +00:00
|
|
|
static gboolean
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_dvdec_src_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value)
|
2002-06-15 14:32:35 +00:00
|
|
|
{
|
|
|
|
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) {
|
2004-03-15 19:32:27 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
guint64 len;
|
|
|
|
GstFormat tmp_format;
|
|
|
|
|
2004-06-07 12:01:52 +00:00
|
|
|
if (!dvdec->bs)
|
|
|
|
return FALSE;
|
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
len = gst_bytestream_length (dvdec->bs);
|
|
|
|
tmp_format = GST_FORMAT_TIME;
|
|
|
|
if (len == -1 || !gst_pad_convert (dvdec->sinkpad,
|
|
|
|
GST_FORMAT_BYTES, len, &tmp_format, value)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!gst_pad_convert (pad, GST_FORMAT_TIME, *value, format, value)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
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) {
|
2004-03-15 19:32:27 +00:00
|
|
|
default:
|
|
|
|
res =
|
|
|
|
gst_pad_convert (pad, GST_FORMAT_TIME, dvdec->next_ts, format,
|
|
|
|
value);
|
|
|
|
break;
|
2002-06-15 14:32:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
2004-03-14 20:54:13 +00:00
|
|
|
}
|
2002-06-15 14:32:35 +00:00
|
|
|
|
2004-03-14 20:54:13 +00:00
|
|
|
static const GstEventMask *
|
|
|
|
gst_dvdec_get_event_masks (GstPad * pad)
|
|
|
|
{
|
2002-09-09 22:35:30 +00:00
|
|
|
static const GstEventMask src_event_masks[] = {
|
2004-03-14 20:54:13 +00:00
|
|
|
{GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH},
|
|
|
|
{0,}
|
2002-09-09 22:35:30 +00:00
|
|
|
};
|
|
|
|
static const GstEventMask sink_event_masks[] = {
|
2004-03-14 20:54:13 +00:00
|
|
|
{GST_EVENT_EOS, 0},
|
|
|
|
{GST_EVENT_DISCONTINUOUS, 0},
|
|
|
|
{GST_EVENT_FLUSH, 0},
|
|
|
|
{0,}
|
2002-09-09 22:35:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (GST_PAD_IS_SRC (pad) ? src_event_masks : sink_event_masks);
|
2004-03-14 20:54:13 +00:00
|
|
|
}
|
2002-09-09 22:35:30 +00:00
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
static gboolean
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_dvdec_handle_sink_event (GstDVDec * dvdec)
|
2002-01-26 02:48:47 +00:00
|
|
|
{
|
|
|
|
guint32 remaining;
|
|
|
|
GstEvent *event;
|
|
|
|
GstEventType type;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
gst_bytestream_get_status (dvdec->bs, &remaining, &event);
|
2004-03-14 20:54:13 +00:00
|
|
|
|
|
|
|
type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
|
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
switch (type) {
|
|
|
|
case GST_EVENT_FLUSH:
|
2004-06-07 12:01:52 +00:00
|
|
|
case GST_EVENT_EOS:
|
|
|
|
case GST_EVENT_FILLER:
|
2004-06-07 13:25:14 +00:00
|
|
|
{
|
2004-06-07 12:01:52 +00:00
|
|
|
/* Forward the event to output sinks */
|
|
|
|
if (GST_PAD_IS_LINKED (dvdec->videosrcpad)) {
|
|
|
|
gst_event_ref (event);
|
|
|
|
gst_pad_push (dvdec->videosrcpad, GST_DATA (event));
|
|
|
|
}
|
|
|
|
if (GST_PAD_IS_LINKED (dvdec->audiosrcpad)) {
|
|
|
|
gst_event_ref (event);
|
|
|
|
gst_pad_push (dvdec->audiosrcpad, GST_DATA (event));
|
|
|
|
}
|
2004-10-30 06:44:02 +00:00
|
|
|
if (type == GST_EVENT_EOS) {
|
|
|
|
gst_element_set_eos (GST_ELEMENT (dvdec));
|
|
|
|
}
|
2002-01-26 02:48:47 +00:00
|
|
|
break;
|
2004-06-07 13:25:14 +00:00
|
|
|
}
|
2002-01-26 02:48:47 +00:00
|
|
|
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 */
|
2004-03-14 20:54:13 +00:00
|
|
|
for (i = 0; i < GST_EVENT_DISCONT_OFFSET_LEN (event); i++) {
|
2004-03-15 19:32:27 +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)) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2002-06-16 14:45:46 +00:00
|
|
|
}
|
|
|
|
/* assume 0 then */
|
|
|
|
if (!found) {
|
2004-03-15 19:32:27 +00:00
|
|
|
dvdec->next_ts = 0LL;
|
2002-06-16 14:45:46 +00:00
|
|
|
}
|
|
|
|
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:
|
2004-02-07 13:04:09 +00:00
|
|
|
return gst_pad_event_default (dvdec->sinkpad, event);
|
2002-01-26 02:48:47 +00:00
|
|
|
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
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_dvdec_handle_src_event (GstPad * pad, GstEvent * event)
|
2002-06-16 14:45:46 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstDVDec *dvdec;
|
|
|
|
|
|
|
|
dvdec = GST_DVDEC (gst_pad_get_parent (pad));
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2002-06-16 14:45:46 +00:00
|
|
|
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;
|
2004-03-14 20:54:13 +00:00
|
|
|
if (!gst_pad_convert (pad,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_EVENT_SEEK_FORMAT (event),
|
|
|
|
GST_EVENT_SEEK_ENDOFFSET (event), &format, &position)) {
|
|
|
|
/* could not convert seek format to time offset */
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2002-11-02 13:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2004-03-14 20:54:13 +00:00
|
|
|
if (!gst_pad_convert (pad,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_EVENT_SEEK_FORMAT (event),
|
|
|
|
GST_EVENT_SEEK_OFFSET (event), &format, &position)) {
|
|
|
|
/* could not convert seek format to time offset */
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2002-11-02 13:34:42 +00:00
|
|
|
}
|
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,
|
2004-03-15 19:32:27 +00:00
|
|
|
&format, &position)) {
|
|
|
|
/* could not convert seek format to byte offset */
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2002-11-02 13:34:42 +00:00
|
|
|
}
|
|
|
|
/* seek to offset */
|
|
|
|
if (!gst_bytestream_seek (dvdec->bs, position, GST_SEEK_METHOD_SET)) {
|
2004-03-15 19:32:27 +00:00
|
|
|
res = FALSE;
|
2002-11-02 13:34:42 +00:00
|
|
|
}
|
2003-05-24 10:34:34 +00:00
|
|
|
if (GST_EVENT_TYPE (event) != GST_EVENT_SEEK_SEGMENT)
|
2004-03-15 19:32:27 +00:00
|
|
|
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
|
|
|
|
2004-03-14 20:54:13 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_dvdec_video_getcaps (GstPad * pad)
|
2004-02-07 13:04:09 +00:00
|
|
|
{
|
|
|
|
GstDVDec *dvdec;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstPadTemplate *src_pad_template;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-02-07 13:04:09 +00:00
|
|
|
dvdec = GST_DVDEC (gst_pad_get_parent (pad));
|
|
|
|
src_pad_template = gst_static_pad_template_get (&video_src_temp);
|
2004-03-14 20:54:13 +00:00
|
|
|
caps = gst_caps_copy (gst_pad_template_get_caps (src_pad_template));
|
|
|
|
|
|
|
|
if (dvdec->found_header) {
|
2004-02-07 13:04:09 +00:00
|
|
|
int i;
|
2004-10-18 14:02:51 +00:00
|
|
|
gint par_x, par_y;
|
|
|
|
|
|
|
|
if (dvdec->PAL) {
|
2004-10-18 17:49:09 +00:00
|
|
|
if (dvdec->wide) {
|
2004-10-18 14:02:51 +00:00
|
|
|
par_x = PAL_WIDE_PAR_X;
|
|
|
|
par_y = PAL_WIDE_PAR_Y;
|
|
|
|
} else {
|
|
|
|
par_x = PAL_NORMAL_PAR_X;
|
|
|
|
par_y = PAL_NORMAL_PAR_Y;
|
|
|
|
}
|
|
|
|
} else {
|
2004-10-18 17:49:09 +00:00
|
|
|
if (dvdec->wide) {
|
2004-10-18 14:02:51 +00:00
|
|
|
par_x = NTSC_WIDE_PAR_X;
|
|
|
|
par_y = NTSC_WIDE_PAR_Y;
|
|
|
|
} else {
|
|
|
|
par_x = NTSC_NORMAL_PAR_X;
|
|
|
|
par_y = NTSC_NORMAL_PAR_Y;
|
|
|
|
}
|
|
|
|
}
|
2004-02-07 13:04:09 +00:00
|
|
|
/* set the height */
|
2004-03-14 20:54:13 +00:00
|
|
|
for (i = 0; i < gst_caps_get_size (caps); i++) {
|
|
|
|
GstStructure *structure = gst_caps_get_structure (caps, i);
|
|
|
|
|
|
|
|
gst_structure_set (structure,
|
2004-03-15 19:32:27 +00:00
|
|
|
"height", G_TYPE_INT, dvdec->height,
|
2004-06-27 16:38:41 +00:00
|
|
|
"framerate", G_TYPE_DOUBLE, dvdec->framerate / dvdec->drop_factor,
|
2004-10-18 14:02:51 +00:00
|
|
|
"pixel-aspect-ratio", GST_TYPE_FRACTION, par_x, par_y, NULL);
|
2004-02-07 13:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-02-07 13:04:09 +00:00
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2004-03-14 20:54:13 +00:00
|
|
|
static GstPadLinkReturn
|
|
|
|
gst_dvdec_video_link (GstPad * pad, const GstCaps * caps)
|
2004-02-07 13:04:09 +00:00
|
|
|
{
|
|
|
|
GstDVDec *dvdec;
|
|
|
|
GstStructure *structure;
|
|
|
|
guint32 fourcc;
|
|
|
|
gint height;
|
|
|
|
gdouble framerate;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-02-07 13:04:09 +00:00
|
|
|
dvdec = GST_DVDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
/* if we did not find a header yet, return delayed */
|
2004-03-14 20:54:13 +00:00
|
|
|
if (!dvdec->found_header) {
|
2004-02-07 13:04:09 +00:00
|
|
|
return GST_PAD_LINK_DELAYED;
|
|
|
|
}
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-02-07 13:04:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-05-07 16:17:25 +00:00
|
|
|
if (!gst_structure_get_int (structure, "height", &height) ||
|
2004-02-07 13:04:09 +00:00
|
|
|
!gst_structure_get_double (structure, "framerate", &framerate))
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-10-26 17:59:18 +00:00
|
|
|
/* allow a margin of error for the framerate caused by float rounding errors */
|
|
|
|
if ((height != dvdec->height) ||
|
|
|
|
(fabs (framerate - (dvdec->framerate / dvdec->drop_factor)) > 0.00000001))
|
2004-02-07 13:04:09 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-05-07 16:17:25 +00:00
|
|
|
if (strcmp (gst_structure_get_name (structure), "video/x-raw-rgb") == 0) {
|
2004-02-07 13:04:09 +00:00
|
|
|
gint bpp;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-02-07 13:04:09 +00:00
|
|
|
gst_structure_get_int (structure, "bpp", &bpp);
|
|
|
|
if (bpp == 24) {
|
|
|
|
dvdec->space = e_dv_color_rgb;
|
|
|
|
dvdec->bpp = 3;
|
2004-03-14 20:54:13 +00:00
|
|
|
} else {
|
2004-02-07 13:04:09 +00:00
|
|
|
dvdec->space = e_dv_color_bgr0;
|
|
|
|
dvdec->bpp = 4;
|
|
|
|
}
|
2004-03-14 20:54:13 +00:00
|
|
|
} else {
|
2004-05-07 16:17:25 +00:00
|
|
|
if (!gst_structure_get_fourcc (structure, "format", &fourcc))
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
|
2004-02-07 13:04:09 +00:00
|
|
|
dvdec->space = e_dv_color_yuv;
|
|
|
|
dvdec->bpp = 2;
|
|
|
|
}
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-02-07 13:04:09 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
|
|
|
}
|
|
|
|
|
2002-11-02 13:34:42 +00:00
|
|
|
static void
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_dvdec_push (GstDVDec * dvdec, GstBuffer * outbuf, GstPad * pad,
|
|
|
|
GstClockTime ts)
|
|
|
|
{
|
2004-06-07 12:01:52 +00:00
|
|
|
if ((dvdec->need_discont) || (dvdec->new_media)) {
|
2002-11-02 13:34:42 +00:00
|
|
|
GstEvent *discont;
|
|
|
|
|
|
|
|
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, ts, NULL);
|
2004-06-07 12:01:52 +00:00
|
|
|
GST_EVENT_DISCONT_NEW_MEDIA (discont) = dvdec->new_media;
|
|
|
|
|
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
|
|
|
|
2004-03-14 20:54:13 +00:00
|
|
|
if ((dvdec->end_position != -1) && (dvdec->next_ts >= dvdec->end_position)) {
|
|
|
|
if (dvdec->loop)
|
|
|
|
gst_pad_push (pad, GST_DATA (gst_event_new (GST_EVENT_SEGMENT_DONE)));
|
2002-11-02 13:34:42 +00:00
|
|
|
else
|
2004-03-14 20:54:13 +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
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_dvdec_loop (GstElement * element)
|
|
|
|
{
|
2001-12-23 16:42:33 +00:00
|
|
|
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;
|
2004-06-27 14:42:09 +00:00
|
|
|
GstClockTime ts, duration;
|
2004-02-07 13:04:09 +00:00
|
|
|
gdouble fps;
|
2004-10-18 17:49:09 +00:00
|
|
|
gboolean wide;
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
dvdec = GST_DVDEC (element);
|
|
|
|
|
2004-04-01 11:48:27 +00:00
|
|
|
/*
|
|
|
|
* Apparently dv_parse_header can read from the body of the frame
|
|
|
|
* too, so it needs more than header_size bytes. Wacky!
|
|
|
|
*/
|
|
|
|
if (dvdec->found_header)
|
|
|
|
length = (dvdec->PAL ? PAL_BUFFER : NTSC_BUFFER);
|
|
|
|
else
|
|
|
|
length = NTSC_BUFFER;
|
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
/* first read enough bytes to parse the header */
|
2004-04-01 11:48:27 +00:00
|
|
|
got_bytes = gst_bytestream_peek_bytes (dvdec->bs, &inframe, 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;
|
2001-12-23 23:00:59 +00:00
|
|
|
}
|
2004-03-14 20:54:13 +00:00
|
|
|
if (dv_parse_header (dvdec->decoder, inframe) < 0) {
|
2004-02-07 13:04:09 +00:00
|
|
|
GST_ELEMENT_ERROR (dvdec, STREAM, DECODE, (NULL), (NULL));
|
|
|
|
return;
|
|
|
|
}
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-02-07 13:04:09 +00:00
|
|
|
/* after parsing the header we know the length of the data */
|
2002-06-16 14:45:46 +00:00
|
|
|
dvdec->PAL = dv_system_50_fields (dvdec->decoder);
|
2004-02-07 13:04:09 +00:00
|
|
|
dvdec->found_header = TRUE;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-02-05 23:15:00 +00:00
|
|
|
fps = (dvdec->PAL ? PAL_FRAMERATE : NTSC_FRAMERATE);
|
2004-02-07 13:04:09 +00:00
|
|
|
height = (dvdec->PAL ? PAL_HEIGHT : NTSC_HEIGHT);
|
2002-06-16 14:45:46 +00:00
|
|
|
length = (dvdec->PAL ? PAL_BUFFER : NTSC_BUFFER);
|
2004-10-18 17:49:09 +00:00
|
|
|
wide = dv_format_wide (dvdec->decoder);
|
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
|
|
|
|
2004-05-12 14:53:57 +00:00
|
|
|
ts = dvdec->next_ts;
|
2004-06-27 16:38:41 +00:00
|
|
|
dvdec->next_ts += GST_SECOND / fps;
|
2004-06-27 14:42:09 +00:00
|
|
|
duration = dvdec->next_ts - ts;
|
2004-02-07 13:04:09 +00:00
|
|
|
|
|
|
|
dv_parse_packs (dvdec->decoder, GST_BUFFER_DATA (buf));
|
2004-06-07 12:01:52 +00:00
|
|
|
if (dv_is_new_recording (dvdec->decoder, GST_BUFFER_DATA (buf)))
|
|
|
|
dvdec->new_media = TRUE;
|
2003-01-10 10:22:25 +00:00
|
|
|
if (GST_PAD_IS_LINKED (dvdec->audiosrcpad)) {
|
2004-06-27 14:42:09 +00:00
|
|
|
gint num_samples;
|
2002-06-16 14:45:46 +00:00
|
|
|
|
2004-03-14 20:54:13 +00:00
|
|
|
dv_decode_full_audio (dvdec->decoder, GST_BUFFER_DATA (buf),
|
2004-03-15 19:32:27 +00:00
|
|
|
dvdec->audio_buffers);
|
2002-06-16 14:45:46 +00:00
|
|
|
|
2004-06-07 12:01:52 +00:00
|
|
|
if ((dv_get_frequency (dvdec->decoder) != dvdec->frequency) ||
|
|
|
|
(dv_get_num_channels (dvdec->decoder) != dvdec->channels)) {
|
2004-02-07 13:04:09 +00:00
|
|
|
if (!gst_pad_set_explicit_caps (dvdec->audiosrcpad,
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_caps_new_simple ("audio/x-raw-int",
|
2004-06-07 12:01:52 +00:00
|
|
|
"rate", G_TYPE_INT, dv_get_frequency (dvdec->decoder),
|
2004-03-15 19:32:27 +00:00
|
|
|
"depth", G_TYPE_INT, 16,
|
|
|
|
"width", G_TYPE_INT, 16,
|
|
|
|
"signed", G_TYPE_BOOLEAN, TRUE,
|
2004-06-07 12:01:52 +00:00
|
|
|
"channels", G_TYPE_INT, dv_get_num_channels (dvdec->decoder),
|
2004-03-15 19:32:27 +00:00
|
|
|
"endianness", G_TYPE_INT, G_LITTLE_ENDIAN, NULL))) {
|
|
|
|
gst_buffer_unref (buf);
|
2004-06-07 12:01:52 +00:00
|
|
|
GST_ELEMENT_ERROR (dvdec, CORE, NEGOTIATION, (NULL),
|
|
|
|
("Failed to negotiate audio parameters for the DV audio stream"));
|
2004-03-15 19:32:27 +00:00
|
|
|
return;
|
2004-02-07 13:04:09 +00:00
|
|
|
}
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-06-07 12:01:52 +00:00
|
|
|
dvdec->frequency = dv_get_frequency (dvdec->decoder);
|
|
|
|
dvdec->channels = dv_get_num_channels (dvdec->decoder);
|
2002-06-16 14:45:46 +00:00
|
|
|
}
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-06-27 14:42:09 +00:00
|
|
|
num_samples = dv_get_num_samples (dvdec->decoder);
|
|
|
|
|
|
|
|
if (num_samples) {
|
|
|
|
gint16 *a_ptr;
|
|
|
|
gint i, j;
|
|
|
|
|
2004-06-07 12:01:52 +00:00
|
|
|
outbuf = gst_buffer_new ();
|
|
|
|
GST_BUFFER_SIZE (outbuf) = dv_get_num_samples (dvdec->decoder) *
|
|
|
|
sizeof (gint16) * dv_get_num_channels (dvdec->decoder);
|
|
|
|
GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-06-07 12:01:52 +00:00
|
|
|
a_ptr = (gint16 *) GST_BUFFER_DATA (outbuf);
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-06-27 14:42:09 +00:00
|
|
|
for (i = 0; i < num_samples; i++) {
|
2004-06-07 12:01:52 +00:00
|
|
|
for (j = 0; j < dv_get_num_channels (dvdec->decoder); j++) {
|
|
|
|
*(a_ptr++) = dvdec->audio_buffers[j][i];
|
|
|
|
}
|
2002-06-15 14:32:35 +00:00
|
|
|
}
|
2004-06-27 14:42:09 +00:00
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = ts;
|
|
|
|
GST_BUFFER_DURATION (outbuf) = duration;
|
|
|
|
GST_BUFFER_OFFSET (outbuf) = dvdec->audio_offset;
|
|
|
|
dvdec->audio_offset += num_samples;
|
|
|
|
GST_BUFFER_OFFSET_END (outbuf) = dvdec->audio_offset;
|
|
|
|
|
2004-06-07 12:01:52 +00:00
|
|
|
gst_dvdec_push (dvdec, outbuf, dvdec->audiosrcpad, ts);
|
2002-06-13 22:30:15 +00:00
|
|
|
}
|
2004-06-07 12:01:52 +00:00
|
|
|
} else {
|
|
|
|
dvdec->frequency = dv_get_frequency (dvdec->decoder);
|
|
|
|
dvdec->channels = dv_get_num_channels (dvdec->decoder);
|
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];
|
|
|
|
|
2004-06-27 16:38:41 +00:00
|
|
|
dvdec->framecount++;
|
|
|
|
if (dvdec->framecount < dvdec->drop_factor) {
|
|
|
|
/* don't decode */
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
dvdec->framecount = 0;
|
|
|
|
|
2004-10-18 17:49:09 +00:00
|
|
|
if ((dvdec->framerate != fps) || (dvdec->height != height)
|
|
|
|
|| dvdec->wide != wide) {
|
2004-05-12 14:53:57 +00:00
|
|
|
dvdec->height = height;
|
|
|
|
dvdec->framerate = fps;
|
2004-10-18 17:49:09 +00:00
|
|
|
dvdec->wide = wide;
|
2004-05-12 14:53:57 +00:00
|
|
|
|
|
|
|
if (GST_PAD_LINK_FAILED (gst_pad_renegotiate (dvdec->videosrcpad))) {
|
|
|
|
GST_ELEMENT_ERROR (dvdec, CORE, NEGOTIATION, (NULL), (NULL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
outbuf = gst_buffer_new_and_alloc ((720 * height) * dvdec->bpp);
|
2004-03-14 20:54:13 +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;
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2002-06-16 20:49:22 +00:00
|
|
|
outframe_pitches[1] = height / 2;
|
|
|
|
outframe_pitches[2] = outframe_pitches[1];
|
|
|
|
}
|
2002-01-26 02:48:47 +00:00
|
|
|
|
2004-03-14 20:54:13 +00:00
|
|
|
dv_decode_full_frame (dvdec->decoder, GST_BUFFER_DATA (buf),
|
2004-03-15 19:32:27 +00:00
|
|
|
dvdec->space, outframe_ptrs, outframe_pitches);
|
2002-01-26 02:48:47 +00:00
|
|
|
|
2004-06-27 14:42:09 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = ts;
|
2004-06-27 16:38:41 +00:00
|
|
|
GST_BUFFER_DURATION (outbuf) = duration * dvdec->drop_factor;
|
2004-06-27 14:42:09 +00:00
|
|
|
|
2002-11-02 13:34:42 +00:00
|
|
|
gst_dvdec_push (dvdec, outbuf, dvdec->videosrcpad, ts);
|
2004-06-07 12:01:52 +00:00
|
|
|
} else {
|
|
|
|
dvdec->height = height;
|
|
|
|
dvdec->framerate = fps;
|
2004-10-18 17:49:09 +00:00
|
|
|
dvdec->wide = wide;
|
2002-06-15 14:32:35 +00:00
|
|
|
}
|
2002-01-26 02:48:47 +00:00
|
|
|
|
2004-06-27 16:38:41 +00:00
|
|
|
end:
|
2004-03-14 20:54:13 +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
|
|
|
|
2004-06-07 12:01:52 +00:00
|
|
|
dvdec->need_discont = FALSE;
|
|
|
|
dvdec->new_media = FALSE;
|
2002-06-15 14:32:35 +00:00
|
|
|
|
|
|
|
gst_buffer_unref (buf);
|
2002-01-26 02:48:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_dvdec_change_state (GstElement * element)
|
2002-01-26 02:48:47 +00:00
|
|
|
{
|
|
|
|
GstDVDec *dvdec = GST_DVDEC (element);
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2002-01-26 02:48:47 +00:00
|
|
|
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);
|
2004-03-14 20:54:13 +00:00
|
|
|
dvdec->decoder =
|
2004-03-15 19:32:27 +00:00
|
|
|
dv_decoder_new (0, dvdec->clamp_luma, dvdec->clamp_chroma);
|
2004-05-12 14:53:57 +00:00
|
|
|
dvdec->decoder->quality = qualities[dvdec->quality];
|
2004-06-27 14:42:09 +00:00
|
|
|
dvdec->audio_offset = 0;
|
2004-06-27 16:38:41 +00:00
|
|
|
dvdec->framecount = 0;
|
2004-04-01 11:48:27 +00:00
|
|
|
/*
|
|
|
|
* Enable this function call when libdv2 0.100 or higher is more
|
|
|
|
* common
|
|
|
|
*/
|
2004-05-12 14:53:57 +00:00
|
|
|
/* dv_set_quality (dvdec->decoder, qualities [dvdec->quality]); */
|
2002-01-26 02:48:47 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2002-09-09 22:20:34 +00:00
|
|
|
dv_decoder_free (dvdec->decoder);
|
|
|
|
dvdec->decoder = NULL;
|
2004-02-07 13:04:09 +00:00
|
|
|
dvdec->found_header = FALSE;
|
2002-01-26 02:48:47 +00:00
|
|
|
gst_bytestream_destroy (dvdec->bs);
|
2004-06-07 12:01:52 +00:00
|
|
|
dvdec->bs = NULL;
|
2002-01-26 02:48:47 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-03-14 20:54:13 +00:00
|
|
|
|
2004-05-10 12:19:02 +00:00
|
|
|
return parent_class->change_state (element);
|
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
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_dvdec_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-23 16:42:33 +00:00
|
|
|
{
|
|
|
|
GstDVDec *dvdec;
|
|
|
|
|
|
|
|
/* It's not null if we got it, but it might not be ours */
|
2004-03-14 20:54:13 +00:00
|
|
|
g_return_if_fail (GST_IS_DVDEC (object));
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
/* Get a pointer of the right type. */
|
2004-03-14 20:54:13 +00:00
|
|
|
dvdec = GST_DVDEC (object);
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
/* 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:
|
2004-05-12 14:53:57 +00:00
|
|
|
dvdec->quality = g_value_get_enum (value);
|
|
|
|
if ((dvdec->quality < 0) || (dvdec->quality > 5))
|
|
|
|
dvdec->quality = 0;
|
2002-09-09 22:20:34 +00:00
|
|
|
break;
|
2004-06-27 16:38:41 +00:00
|
|
|
case ARG_DECODE_NTH:
|
|
|
|
dvdec->drop_factor = g_value_get_int (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
|
2004-03-14 20:54:13 +00:00
|
|
|
gst_dvdec_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-23 16:42:33 +00:00
|
|
|
{
|
|
|
|
GstDVDec *dvdec;
|
|
|
|
|
|
|
|
/* It's not null if we got it, but it might not be ours */
|
2004-03-14 20:54:13 +00:00
|
|
|
g_return_if_fail (GST_IS_DVDEC (object));
|
|
|
|
dvdec = GST_DVDEC (object);
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
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:
|
2004-05-12 14:53:57 +00:00
|
|
|
g_value_set_enum (value, dvdec->quality);
|
2002-09-09 22:20:34 +00:00
|
|
|
break;
|
2004-06-27 16:38:41 +00:00
|
|
|
case ARG_DECODE_NTH:
|
|
|
|
g_value_set_int (value, dvdec->drop_factor);
|
|
|
|
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
|
2004-03-14 20:54:13 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-23 16:42:33 +00:00
|
|
|
{
|
2003-10-28 20:52:41 +00:00
|
|
|
if (!gst_library_load ("gstbytestream"))
|
|
|
|
return FALSE;
|
|
|
|
|
2004-03-14 20:54:13 +00:00
|
|
|
if (!gst_element_register (plugin, "dvdec", GST_RANK_PRIMARY,
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_dvdec_get_type ()))
|
2003-11-02 03:32:31 +00:00
|
|
|
return FALSE;
|
2001-12-23 16:42:33 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 20:54:13 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"dvdec",
|
|
|
|
"Uses libdv to decode DV video (libdv.sourceforge.net)",
|
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN);
|