2002-04-20 21:42:51 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* <2002> Wim Taymans <wim.taymans@chello.be>
|
|
|
|
*
|
|
|
|
* 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:13 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2002-04-20 21:42:51 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gstcdxaparse.h"
|
2004-05-13 21:27:14 +00:00
|
|
|
#include "gst/riff/riff-ids.h"
|
|
|
|
#include "gst/riff/riff-media.h"
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
static void gst_cdxaparse_base_init (gpointer g_class);
|
|
|
|
static void gst_cdxaparse_class_init (GstCDXAParseClass * klass);
|
|
|
|
static void gst_cdxaparse_init (GstCDXAParse * cdxaparse);
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
static GstElementStateReturn gst_cdxaparse_change_state (GstElement * element);
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
static void gst_cdxaparse_loop (GstElement * element);
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-13 21:27:14 +00:00
|
|
|
static GstStaticPadTemplate sink_template_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/x-cdxa")
|
|
|
|
);
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-13 21:27:14 +00:00
|
|
|
static GstStaticPadTemplate src_template_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/mpeg, " "systemstream = (boolean) TRUE")
|
|
|
|
);
|
2002-04-20 21:42:51 +00:00
|
|
|
|
|
|
|
/* CDXAParse signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2002-04-20 21:42:51 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2002-04-20 21:42:51 +00:00
|
|
|
ARG_0,
|
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-04-20 21:42:51 +00:00
|
|
|
GType
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_cdxaparse_get_type (void)
|
2002-04-20 21:42:51 +00:00
|
|
|
{
|
2004-05-21 14:09:51 +00:00
|
|
|
static GType cdxaparse_type = 0;
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
if (!cdxaparse_type) {
|
|
|
|
static const GTypeInfo cdxaparse_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstCDXAParseClass),
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_cdxaparse_base_init,
|
2002-04-20 21:42:51 +00:00
|
|
|
NULL,
|
2004-05-21 14:09:51 +00:00
|
|
|
(GClassInitFunc) gst_cdxaparse_class_init,
|
2002-04-20 21:42:51 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstCDXAParse),
|
2002-04-20 21:42:51 +00:00
|
|
|
0,
|
2004-05-21 14:09:51 +00:00
|
|
|
(GInstanceInitFunc) gst_cdxaparse_init,
|
2002-04-20 21:42:51 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxaparse_type =
|
2004-05-13 21:27:14 +00:00
|
|
|
g_type_register_static (GST_TYPE_RIFF_READ, "GstCDXAParse",
|
2004-05-21 14:09:51 +00:00
|
|
|
&cdxaparse_info, 0);
|
2002-04-20 21:42:51 +00:00
|
|
|
}
|
2004-05-21 14:09:51 +00:00
|
|
|
return cdxaparse_type;
|
2002-04-20 21:42:51 +00:00
|
|
|
}
|
|
|
|
|
2004-05-13 21:27:14 +00:00
|
|
|
|
2003-11-01 11:56:28 +00:00
|
|
|
static void
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_cdxaparse_base_init (gpointer g_class)
|
2003-11-01 11:56:28 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
2004-05-21 14:09:51 +00:00
|
|
|
static GstElementDetails gst_cdxaparse_details =
|
|
|
|
GST_ELEMENT_DETAILS (".dat parser",
|
|
|
|
"Codec/Parser",
|
|
|
|
"Parse a .dat file (VCD) into raw mpeg1",
|
|
|
|
"Wim Taymans <wim.taymans@tvd.be>");
|
2003-11-01 11:56:28 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_element_class_set_details (element_class, &gst_cdxaparse_details);
|
2004-05-13 21:27:14 +00:00
|
|
|
|
|
|
|
/* register src pads */
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-05-13 21:27:14 +00:00
|
|
|
gst_static_pad_template_get (&sink_template_factory));
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-05-13 21:27:14 +00:00
|
|
|
gst_static_pad_template_get (&src_template_factory));
|
2003-11-01 11:56:28 +00:00
|
|
|
}
|
|
|
|
|
2002-04-20 21:42:51 +00:00
|
|
|
static void
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_cdxaparse_class_init (GstCDXAParseClass * klass)
|
2002-04-20 21:42:51 +00:00
|
|
|
{
|
|
|
|
GstElementClass *gstelement_class;
|
2004-05-13 21:27:14 +00:00
|
|
|
GObjectClass *object_class;
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2004-05-13 21:27:14 +00:00
|
|
|
object_class = (GObjectClass *) klass;
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-13 21:27:14 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_RIFF_READ);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
gstelement_class->change_state = gst_cdxaparse_change_state;
|
2002-04-20 21:42:51 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_cdxaparse_init (GstCDXAParse * cdxaparse)
|
2002-04-20 21:42:51 +00:00
|
|
|
{
|
2004-05-13 21:27:14 +00:00
|
|
|
/* sink */
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxaparse->sinkpad =
|
2004-05-13 21:27:14 +00:00
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&sink_template_factory), "sink");
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (cdxaparse), cdxaparse->sinkpad);
|
|
|
|
GST_RIFF_READ (cdxaparse)->sinkpad = cdxaparse->sinkpad;
|
2004-05-13 21:27:14 +00:00
|
|
|
|
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_element_set_loop_function (GST_ELEMENT (cdxaparse), gst_cdxaparse_loop);
|
2004-05-13 21:27:14 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxaparse->state = GST_CDXAPARSE_START;
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxaparse->srcpad =
|
2004-05-13 21:27:14 +00:00
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&src_template_factory), "src");
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (cdxaparse), cdxaparse->srcpad);
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxaparse->seek_pending = FALSE;
|
|
|
|
cdxaparse->seek_offset = 0;
|
2002-04-20 21:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_cdxaparse_stream_init (GstCDXAParse * cdxa)
|
2002-04-20 21:42:51 +00:00
|
|
|
{
|
2004-05-21 14:09:51 +00:00
|
|
|
GstRiffRead *riff = GST_RIFF_READ (cdxa);
|
2004-05-13 21:27:14 +00:00
|
|
|
guint32 doctype;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-05-13 21:27:14 +00:00
|
|
|
if (!gst_riff_read_header (riff, &doctype))
|
|
|
|
return FALSE;
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-13 21:27:14 +00:00
|
|
|
if (doctype != GST_RIFF_RIFF_CDXA) {
|
2004-05-21 14:09:51 +00:00
|
|
|
GST_ELEMENT_ERROR (cdxa, STREAM, WRONG_TYPE, (NULL), (NULL));
|
2004-05-13 21:27:14 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-13 21:27:14 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read 'fmt ' header */
|
|
|
|
static gboolean
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_cdxaparse_fmt (GstCDXAParse * cdxa)
|
2004-05-13 21:27:14 +00:00
|
|
|
{
|
2004-05-21 14:09:51 +00:00
|
|
|
GstRiffRead *riff = GST_RIFF_READ (cdxa);
|
2004-05-13 21:27:14 +00:00
|
|
|
gst_riff_strf_auds *header;
|
|
|
|
|
|
|
|
if (!gst_riff_read_strf_auds (riff, &header)) {
|
|
|
|
g_warning ("Not fmt");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* As we don't know what is in this fmt field, we do nothing */
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_cdxaparse_other (GstCDXAParse * cdxa)
|
2004-05-13 21:27:14 +00:00
|
|
|
{
|
2004-05-21 14:09:51 +00:00
|
|
|
GstRiffRead *riff = GST_RIFF_READ (cdxa);
|
2004-05-13 21:27:14 +00:00
|
|
|
guint32 tag, length;
|
|
|
|
|
|
|
|
if (!gst_riff_peek_head (riff, &tag, &length, NULL)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (tag) {
|
|
|
|
case GST_RIFF_TAG_data:
|
2004-05-21 14:09:51 +00:00
|
|
|
if (!gst_bytestream_flush (riff->bs, 8))
|
|
|
|
return FALSE;
|
2004-05-13 21:27:14 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxa->state = GST_CDXAPARSE_DATA;
|
|
|
|
cdxa->dataleft = cdxa->datasize = (guint64) length;
|
|
|
|
cdxa->datastart = gst_bytestream_tell (riff->bs);
|
2002-04-20 21:42:51 +00:00
|
|
|
break;
|
2004-05-13 21:27:14 +00:00
|
|
|
|
2002-04-20 21:42:51 +00:00
|
|
|
default:
|
2004-05-21 14:09:51 +00:00
|
|
|
if (!gst_riff_read_skip (riff))
|
|
|
|
return FALSE;
|
2002-04-20 21:42:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-05-13 21:27:14 +00:00
|
|
|
|
|
|
|
A sector is 2352 bytes long and is composed of:
|
2002-04-20 21:42:51 +00:00
|
|
|
|
|
|
|
! sync ! header ! subheader ! data ... ! edc !
|
|
|
|
! 12 bytes ! 4 bytes ! 8 bytes ! 2324 bytes ! 4 bytes !
|
|
|
|
!-------------------------------------------------------!
|
|
|
|
|
|
|
|
We parse the data out of it and send it to the srcpad.
|
2004-05-13 21:27:14 +00:00
|
|
|
|
|
|
|
sync : 00 FF FF FF FF FF FF FF FF FF FF 00
|
|
|
|
header : hour minute second mode
|
|
|
|
sub-header : track channel sub_mode coding repeat (4 bytes)
|
|
|
|
edc : checksum
|
|
|
|
|
2002-04-20 21:42:51 +00:00
|
|
|
*/
|
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
static void
|
|
|
|
gst_cdxaparse_loop (GstElement * element)
|
|
|
|
{
|
|
|
|
GstCDXAParse *cdxa = GST_CDXAPARSE (element);
|
|
|
|
GstRiffRead *riff = GST_RIFF_READ (cdxa);
|
|
|
|
|
|
|
|
if (cdxa->state == GST_CDXAPARSE_DATA) {
|
|
|
|
|
|
|
|
if (cdxa->dataleft > 0) {
|
|
|
|
guint32 got_bytes, desired;
|
|
|
|
GstBuffer *buf = NULL;
|
|
|
|
GstBuffer *outbuf = NULL;
|
|
|
|
|
|
|
|
desired = GST_CDXA_SECTOR_SIZE;
|
|
|
|
|
|
|
|
if (!(buf = gst_riff_read_element_data (riff, desired, &got_bytes)))
|
2004-05-13 21:27:14 +00:00
|
|
|
return;
|
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
/* Skip CDXA headers, only keep data */
|
|
|
|
outbuf =
|
|
|
|
gst_buffer_create_sub (buf, GST_CDXA_HEADER_SIZE, GST_CDXA_DATA_SIZE);
|
2004-05-13 21:27:14 +00:00
|
|
|
|
|
|
|
gst_buffer_unref (buf);
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_pad_push (cdxa->srcpad, GST_DATA (outbuf));
|
2004-05-13 21:27:14 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxa->byteoffset += got_bytes;
|
|
|
|
if (got_bytes < cdxa->dataleft) {
|
|
|
|
cdxa->dataleft -= got_bytes;
|
2004-05-13 21:27:14 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxa->dataleft = 0;
|
|
|
|
cdxa->state = GST_CDXAPARSE_OTHER;
|
2004-05-13 21:27:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxa->state = GST_CDXAPARSE_OTHER;
|
2002-04-20 21:42:51 +00:00
|
|
|
}
|
2004-05-13 21:27:14 +00:00
|
|
|
}
|
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
switch (cdxa->state) {
|
|
|
|
case GST_CDXAPARSE_START:
|
|
|
|
if (!gst_cdxaparse_stream_init (cdxa)) {
|
2004-05-13 21:27:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxa->state = GST_CDXAPARSE_FMT;
|
2004-05-13 21:27:14 +00:00
|
|
|
/* fall-through */
|
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
case GST_CDXAPARSE_FMT:
|
|
|
|
if (!gst_cdxaparse_fmt (cdxa)) {
|
2004-05-13 21:27:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxa->state = GST_CDXAPARSE_OTHER;
|
2004-05-13 21:27:14 +00:00
|
|
|
/* fall-through */
|
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
case GST_CDXAPARSE_OTHER:
|
|
|
|
if (!gst_cdxaparse_other (cdxa)) {
|
2004-05-13 21:27:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
case GST_CDXAPARSE_DATA:
|
2002-04-20 21:42:51 +00:00
|
|
|
|
2004-05-13 21:27:14 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2002-04-20 21:42:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-05-21 14:09:51 +00:00
|
|
|
gst_cdxaparse_change_state (GstElement * element)
|
2002-04-20 21:42:51 +00:00
|
|
|
{
|
2004-05-21 14:09:51 +00:00
|
|
|
GstCDXAParse *cdxa = GST_CDXAPARSE (element);
|
2002-04-20 21:42:51 +00:00
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
break;
|
2004-05-13 21:27:14 +00:00
|
|
|
|
2002-04-20 21:42:51 +00:00
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxa->state = GST_CDXAPARSE_START;
|
2002-04-20 21:42:51 +00:00
|
|
|
break;
|
2004-05-13 21:27:14 +00:00
|
|
|
|
2002-04-20 21:42:51 +00:00
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
2004-05-13 21:27:14 +00:00
|
|
|
|
2002-04-20 21:42:51 +00:00
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
2004-05-13 21:27:14 +00:00
|
|
|
|
2002-04-20 21:42:51 +00:00
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxa->state = GST_CDXAPARSE_START;
|
2004-05-13 21:27:14 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
cdxa->seek_pending = FALSE;
|
|
|
|
cdxa->seek_offset = 0;
|
2002-04-20 21:42:51 +00:00
|
|
|
break;
|
2004-05-13 21:27:14 +00:00
|
|
|
|
2002-04-20 21:42:51 +00:00
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-05-13 21:27:14 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
2002-04-20 21:42:51 +00:00
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2002-04-20 21:42:51 +00:00
|
|
|
{
|
2004-05-13 21:27:14 +00:00
|
|
|
if (!gst_library_load ("riff")) {
|
2003-11-01 11:56:28 +00:00
|
|
|
return FALSE;
|
2004-05-13 21:27:14 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-05-21 14:09:51 +00:00
|
|
|
return gst_element_register (plugin, "cdxaparse", GST_RANK_PRIMARY,
|
|
|
|
GST_TYPE_CDXAPARSE);
|
2002-04-20 21:42:51 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"cdxaparse",
|
|
|
|
"Parse a .dat file (VCD) into raw mpeg1",
|
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
|