2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 22:43:37 +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.
|
|
|
|
*/
|
2004-01-27 09:00:00 +00:00
|
|
|
/* Element-Checklist-Version: 5 */
|
2001-12-22 22:43:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define PCM_BUFFER_SIZE (1152*4)
|
|
|
|
|
|
|
|
/*#define DEBUG_ENABLED*/
|
2003-06-29 19:46:09 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 22:43:37 +00:00
|
|
|
#include <gstac3parse.h>
|
|
|
|
|
|
|
|
/* struct and table stolen from ac3dec by Aaron Holtzman */
|
2004-03-14 22:34:30 +00:00
|
|
|
struct frmsize_s
|
|
|
|
{
|
2001-12-22 22:43:37 +00:00
|
|
|
guint16 bit_rate;
|
|
|
|
guint16 frm_size[3];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct frmsize_s frmsizecod_tbl[] = {
|
2004-03-14 22:34:30 +00:00
|
|
|
{32, {64, 69, 96}},
|
|
|
|
{32, {64, 70, 96}},
|
|
|
|
{40, {80, 87, 120}},
|
|
|
|
{40, {80, 88, 120}},
|
|
|
|
{48, {96, 104, 144}},
|
|
|
|
{48, {96, 105, 144}},
|
|
|
|
{56, {112, 121, 168}},
|
|
|
|
{56, {112, 122, 168}},
|
|
|
|
{64, {128, 139, 192}},
|
|
|
|
{64, {128, 140, 192}},
|
|
|
|
{80, {160, 174, 240}},
|
|
|
|
{80, {160, 175, 240}},
|
|
|
|
{96, {192, 208, 288}},
|
|
|
|
{96, {192, 209, 288}},
|
|
|
|
{112, {224, 243, 336}},
|
|
|
|
{112, {224, 244, 336}},
|
|
|
|
{128, {256, 278, 384}},
|
|
|
|
{128, {256, 279, 384}},
|
|
|
|
{160, {320, 348, 480}},
|
|
|
|
{160, {320, 349, 480}},
|
|
|
|
{192, {384, 417, 576}},
|
|
|
|
{192, {384, 418, 576}},
|
|
|
|
{224, {448, 487, 672}},
|
|
|
|
{224, {448, 488, 672}},
|
|
|
|
{256, {512, 557, 768}},
|
|
|
|
{256, {512, 558, 768}},
|
|
|
|
{320, {640, 696, 960}},
|
|
|
|
{320, {640, 697, 960}},
|
|
|
|
{384, {768, 835, 1152}},
|
|
|
|
{384, {768, 836, 1152}},
|
|
|
|
{448, {896, 975, 1344}},
|
|
|
|
{448, {896, 976, 1344}},
|
|
|
|
{512, {1024, 1114, 1536}},
|
|
|
|
{512, {1024, 1115, 1536}},
|
|
|
|
{576, {1152, 1253, 1728}},
|
|
|
|
{576, {1152, 1254, 1728}},
|
|
|
|
{640, {1280, 1393, 1920}},
|
|
|
|
{640, {1280, 1394, 1920}}
|
|
|
|
};
|
2001-12-22 22:43:37 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
2004-03-14 22:34:30 +00:00
|
|
|
static GstElementDetails ac3parse_details = GST_ELEMENT_DETAILS ("AC3 Parser",
|
|
|
|
"Codec/Parser/Audio",
|
|
|
|
"Parses and frames AC3 audio streams, provides seek",
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>");
|
2001-12-22 22:43:37 +00:00
|
|
|
|
|
|
|
/* GstAc3Parse signals and args */
|
2004-03-14 22:34:30 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-22 22:43:37 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-22 22:43:37 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_SKIP,
|
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2003-12-22 01:47:08 +00:00
|
|
|
static GstStaticPadTemplate gst_ac3parse_src_template =
|
2004-03-14 22:34:30 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2004-05-10 00:27:36 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-ac3, "
|
2004-03-15 19:32:25 +00:00
|
|
|
"channels = (int) [ 1, 6 ], " "rate = (int) [ 32000, 48000 ]")
|
2004-03-14 22:34:30 +00:00
|
|
|
);
|
2003-07-06 20:49:50 +00:00
|
|
|
|
2003-12-22 01:47:08 +00:00
|
|
|
static GstStaticPadTemplate gst_ac3parse_sink_template =
|
2004-03-14 22:34:30 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-ac3")
|
|
|
|
);
|
2003-07-06 20:49:50 +00:00
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
static void gst_ac3parse_class_init (gpointer g_class);
|
|
|
|
static void gst_ac3parse_init (GstAc3Parse * ac3parse);
|
|
|
|
|
|
|
|
static void gst_ac3parse_chain (GstPad * pad, GstData * data);
|
|
|
|
|
|
|
|
static void gst_ac3parse_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_ac3parse_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
static GstElementStateReturn gst_ac3parse_change_state (GstElement * element);
|
2001-12-22 22:43:37 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2001-12-22 22:43:37 +00:00
|
|
|
/*static guint gst_ac3parse_signals[LAST_SIGNAL] = { 0 };*/
|
|
|
|
|
|
|
|
GType
|
|
|
|
ac3parse_get_type (void)
|
|
|
|
{
|
|
|
|
static GType ac3parse_type = 0;
|
|
|
|
|
|
|
|
if (!ac3parse_type) {
|
|
|
|
static const GTypeInfo ac3parse_info = {
|
2004-03-14 22:34:30 +00:00
|
|
|
sizeof (GstAc3ParseClass), NULL,
|
2001-12-22 22:43:37 +00:00
|
|
|
NULL,
|
2004-03-14 22:34:30 +00:00
|
|
|
(GClassInitFunc) gst_ac3parse_class_init,
|
2001-12-22 22:43:37 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:30 +00:00
|
|
|
sizeof (GstAc3Parse),
|
2001-12-22 22:43:37 +00:00
|
|
|
0,
|
2004-03-14 22:34:30 +00:00
|
|
|
(GInstanceInitFunc) gst_ac3parse_init,
|
2001-12-22 22:43:37 +00:00
|
|
|
};
|
2004-03-15 19:32:25 +00:00
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
ac3parse_type =
|
2004-03-15 19:32:25 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstAc3Parse", &ac3parse_info,
|
|
|
|
0);
|
2001-12-22 22:43:37 +00:00
|
|
|
}
|
|
|
|
return ac3parse_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-01 01:11:05 +00:00
|
|
|
gst_ac3parse_class_init (gpointer g_class)
|
2001-12-22 22:43:37 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
2003-11-01 01:11:05 +00:00
|
|
|
GstAc3ParseClass *klass;
|
2001-12-22 22:43:37 +00:00
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
klass = (GstAc3ParseClass *) g_class;
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-12-22 22:43:37 +00:00
|
|
|
|
2003-11-01 01:11:05 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
2003-12-22 01:47:08 +00:00
|
|
|
gst_static_pad_template_get (&gst_ac3parse_src_template));
|
2003-11-01 01:11:05 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
2003-12-22 01:47:08 +00:00
|
|
|
gst_static_pad_template_get (&gst_ac3parse_sink_template));
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_element_class_set_details (gstelement_class, &ac3parse_details);
|
2003-11-01 01:11:05 +00:00
|
|
|
|
2004-03-15 19:32:25 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SKIP, g_param_spec_int ("skip", "skip", "skip", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */
|
2001-12-22 22:43:37 +00:00
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2001-12-22 22:43:37 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_ac3parse_set_property;
|
|
|
|
gobject_class->get_property = gst_ac3parse_get_property;
|
|
|
|
|
2003-07-06 20:49:50 +00:00
|
|
|
gstelement_class->change_state = gst_ac3parse_change_state;
|
2001-12-22 22:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_ac3parse_init (GstAc3Parse * ac3parse)
|
2001-12-22 22:43:37 +00:00
|
|
|
{
|
2004-03-14 22:34:30 +00:00
|
|
|
ac3parse->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&gst_ac3parse_sink_template), "sink");
|
2001-12-22 22:43:37 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (ac3parse), ac3parse->sinkpad);
|
|
|
|
gst_pad_set_chain_function (ac3parse->sinkpad, gst_ac3parse_chain);
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
ac3parse->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&gst_ac3parse_src_template), "src");
|
2004-01-02 07:09:23 +00:00
|
|
|
gst_pad_use_explicit_caps (ac3parse->srcpad);
|
2001-12-22 22:43:37 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (ac3parse), ac3parse->srcpad);
|
|
|
|
|
|
|
|
ac3parse->partialbuf = NULL;
|
|
|
|
ac3parse->skip = 0;
|
2003-07-06 20:49:50 +00:00
|
|
|
|
|
|
|
ac3parse->sample_rate = ac3parse->channels = -1;
|
2001-12-22 22:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_ac3parse_chain (GstPad * pad, GstData * _data)
|
2001-12-22 22:43:37 +00:00
|
|
|
{
|
2003-10-08 16:08:10 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-22 22:43:37 +00:00
|
|
|
GstAc3Parse *ac3parse;
|
|
|
|
guchar *data;
|
2004-03-14 22:34:30 +00:00
|
|
|
glong size, offset = 0;
|
2003-07-06 20:49:50 +00:00
|
|
|
guint16 header;
|
|
|
|
guint8 channeldata, acmod, mask;
|
2001-12-22 22:43:37 +00:00
|
|
|
GstBuffer *outbuf = NULL;
|
|
|
|
gint bpf;
|
2003-07-06 20:49:50 +00:00
|
|
|
guint sample_rate = -1, channels = -1;
|
2001-12-22 22:43:37 +00:00
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
2001-12-22 22:43:37 +00:00
|
|
|
/* g_return_if_fail(GST_IS_BUFFER(buf)); */
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
ac3parse = GST_AC3PARSE (GST_OBJECT_PARENT (pad));
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("ac3parse: received buffer of %d bytes", GST_BUFFER_SIZE (buf));
|
2001-12-22 22:43:37 +00:00
|
|
|
|
|
|
|
/* deal with partial frame from previous buffer */
|
|
|
|
if (ac3parse->partialbuf) {
|
2004-03-06 20:56:28 +00:00
|
|
|
GstBuffer *merge;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
|
|
|
merge = gst_buffer_merge (ac3parse->partialbuf, buf);
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
gst_buffer_unref (ac3parse->partialbuf);
|
2004-03-06 20:56:28 +00:00
|
|
|
ac3parse->partialbuf = merge;
|
2004-03-14 22:34:30 +00:00
|
|
|
} else {
|
2001-12-22 22:43:37 +00:00
|
|
|
ac3parse->partialbuf = buf;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
data = GST_BUFFER_DATA (ac3parse->partialbuf);
|
|
|
|
size = GST_BUFFER_SIZE (ac3parse->partialbuf);
|
2001-12-22 22:43:37 +00:00
|
|
|
|
2003-07-06 20:49:50 +00:00
|
|
|
/* we're searching for at least 7 bytes. first the
|
|
|
|
* syncinfo, where 2 bytes are for the syncword
|
|
|
|
* (header ID, 0x0b77), 2 bytes crc1 (checksum) and 1 byte
|
|
|
|
* fscod+fmrsizecod (framerate/bitrate) and then the
|
|
|
|
* bitstreaminfo bsid (version), bsmod (data type) and
|
|
|
|
* acmod (channel info, 3 bits). Then some "maybe"
|
|
|
|
* bits, and then the LFE indicator (subwoofer bit) */
|
2004-03-14 22:34:30 +00:00
|
|
|
while (offset < size - 6) {
|
2001-12-22 22:43:37 +00:00
|
|
|
int skipped = 0;
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
GST_DEBUG ("ac3parse: offset %ld, size %ld ", offset, size);
|
2001-12-22 22:43:37 +00:00
|
|
|
|
|
|
|
/* search for a possible start byte */
|
2004-03-14 22:34:30 +00:00
|
|
|
for (; ((data[offset] != 0x0b) && (offset < size - 6)); offset++)
|
|
|
|
skipped++;
|
2001-12-22 22:43:37 +00:00
|
|
|
if (skipped) {
|
2004-03-14 22:34:30 +00:00
|
|
|
fprintf (stderr, "ac3parse: **** now at %ld skipped %d bytes (FIXME?)\n",
|
2004-03-15 19:32:25 +00:00
|
|
|
offset, skipped);
|
2001-12-22 22:43:37 +00:00
|
|
|
}
|
|
|
|
/* construct the header word */
|
2004-03-14 22:34:30 +00:00
|
|
|
header = GUINT16_TO_BE (*((guint16 *) (data + offset)));
|
2001-12-22 22:43:37 +00:00
|
|
|
/* g_print("AC3PARSE: sync word is 0x%02X\n",header); */
|
|
|
|
/* if it's a valid header, go ahead and send off the frame */
|
|
|
|
if (header == 0x0b77) {
|
|
|
|
gint rate, fsize;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2001-12-22 22:43:37 +00:00
|
|
|
/* g_print("AC3PARSE: found sync at %d\n",offset); */
|
|
|
|
/* get the bits we're interested in */
|
2004-03-14 22:34:30 +00:00
|
|
|
rate = (data[offset + 4] >> 6) & 0x3;
|
2003-07-06 20:49:50 +00:00
|
|
|
switch (rate) {
|
2004-03-15 19:32:25 +00:00
|
|
|
case 0x0: /* 00b */
|
|
|
|
sample_rate = 48000;
|
|
|
|
break;
|
|
|
|
case 0x1: /* 01b */
|
|
|
|
sample_rate = 44100;
|
|
|
|
break;
|
|
|
|
case 0x2: /* 10b */
|
|
|
|
sample_rate = 32000;
|
|
|
|
break;
|
|
|
|
case 0x3: /* 11b */
|
|
|
|
default:
|
|
|
|
/* reserved. if this happens, we're screwed */
|
|
|
|
g_assert (0);
|
|
|
|
break;
|
2003-07-06 20:49:50 +00:00
|
|
|
}
|
2004-03-14 22:34:30 +00:00
|
|
|
fsize = data[offset + 4] & 0x3f;
|
2001-12-22 22:43:37 +00:00
|
|
|
/* calculate the bpf of the frame */
|
|
|
|
bpf = frmsizecod_tbl[fsize].frm_size[rate] * 2;
|
2003-07-06 20:49:50 +00:00
|
|
|
/* calculate number of channels */
|
2004-03-15 19:32:25 +00:00
|
|
|
channeldata = data[offset + 6]; /* skip bsid/bsmod */
|
2003-07-06 20:49:50 +00:00
|
|
|
acmod = (channeldata >> 5) & 0x7;
|
|
|
|
switch (acmod) {
|
2004-03-15 19:32:25 +00:00
|
|
|
case 0x1: /* 001b = 1 channel */
|
|
|
|
channels = 1;
|
|
|
|
break;
|
|
|
|
case 0x0: /* 000b = 2 independent channels */
|
|
|
|
case 0x2: /* 010b = 2x front (stereo) */
|
|
|
|
channels = 2;
|
|
|
|
break;
|
|
|
|
case 0x3: /* 011b = 3 front */
|
|
|
|
case 0x4: /* 100b = 2 front, 1 rear */
|
|
|
|
channels = 3;
|
|
|
|
break;
|
|
|
|
case 0x5: /* 101b = 3 front, 1 rear */
|
|
|
|
case 0x6: /* 110b = 2 front, 2 rear */
|
|
|
|
channels = 4;
|
|
|
|
break;
|
|
|
|
case 0x7: /* 111b = 3 front, 2 rear */
|
|
|
|
channels = 5;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* whaaaaaaaaaaaaaa!!!!!!!!!!! */
|
|
|
|
g_assert (0);
|
2003-07-06 20:49:50 +00:00
|
|
|
}
|
|
|
|
/* fetch LFE bit (subwoofer) */
|
|
|
|
mask = 0x10;
|
2004-03-15 19:32:25 +00:00
|
|
|
if (acmod & 0x1 && acmod != 0x1) /* 3 front speakers? */
|
|
|
|
mask >>= 2;
|
|
|
|
if (acmod & 0x4) /* surround channel? */
|
|
|
|
mask >>= 2;
|
|
|
|
if (acmod == 0x2) /* 2/0 mode? */
|
|
|
|
mask >>= 2;
|
|
|
|
if (channeldata & mask) /* LFE: do we have a subwoofer channel? */
|
|
|
|
channels++;
|
2001-12-22 22:43:37 +00:00
|
|
|
/* if we don't have the whole frame... */
|
|
|
|
if ((size - offset) < bpf) {
|
2004-03-15 19:32:25 +00:00
|
|
|
GST_DEBUG ("ac3parse: partial buffer needed %ld < %d ", size - offset,
|
|
|
|
bpf);
|
|
|
|
break;
|
2001-12-22 22:43:37 +00:00
|
|
|
} else {
|
2004-03-15 19:32:25 +00:00
|
|
|
gboolean need_capsnego = FALSE;
|
|
|
|
|
|
|
|
outbuf = gst_buffer_create_sub (ac3parse->partialbuf, offset, bpf);
|
|
|
|
|
|
|
|
/* make sure our properties still match */
|
|
|
|
if (channels > 0 && ac3parse->channels != channels) {
|
|
|
|
ac3parse->channels = channels;
|
|
|
|
need_capsnego = TRUE;
|
|
|
|
}
|
|
|
|
if (sample_rate > 0 && ac3parse->sample_rate != sample_rate) {
|
|
|
|
ac3parse->sample_rate = sample_rate;
|
|
|
|
need_capsnego = TRUE;
|
|
|
|
}
|
|
|
|
if (need_capsnego) {
|
|
|
|
GstCaps *newcaps;
|
|
|
|
|
|
|
|
newcaps = gst_caps_new_simple ("audio/x-ac3",
|
|
|
|
"channels", G_TYPE_INT, channels,
|
|
|
|
"rate", G_TYPE_INT, sample_rate, NULL);
|
|
|
|
gst_pad_set_explicit_caps (ac3parse->srcpad, newcaps);
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += bpf;
|
|
|
|
if (ac3parse->skip == 0 && GST_PAD_IS_LINKED (ac3parse->srcpad)) {
|
|
|
|
GST_DEBUG ("ac3parse: pushing buffer of %d bytes",
|
|
|
|
GST_BUFFER_SIZE (outbuf));
|
|
|
|
gst_pad_push (ac3parse->srcpad, GST_DATA (outbuf));
|
|
|
|
} else {
|
|
|
|
GST_DEBUG ("ac3parse: skipping buffer of %d bytes",
|
|
|
|
GST_BUFFER_SIZE (outbuf));
|
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
ac3parse->skip--;
|
|
|
|
}
|
2001-12-22 22:43:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
offset++;
|
2004-03-14 22:34:30 +00:00
|
|
|
fprintf (stderr, "ac3parse: *** wrong header, skipping byte (FIXME?)\n");
|
2001-12-22 22:43:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if we have processed this block and there are still */
|
|
|
|
/* bytes left not in a partial block, copy them over. */
|
2004-03-14 22:34:30 +00:00
|
|
|
if (size - offset > 0) {
|
2001-12-22 22:43:37 +00:00
|
|
|
gint remainder = (size - offset);
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
GST_DEBUG ("ac3parse: partial buffer needed %d for trailing bytes",
|
2004-03-15 19:32:25 +00:00
|
|
|
remainder);
|
2004-03-14 22:34:30 +00:00
|
|
|
|
|
|
|
outbuf = gst_buffer_create_sub (ac3parse->partialbuf, offset, remainder);
|
|
|
|
gst_buffer_unref (ac3parse->partialbuf);
|
2001-12-22 22:43:37 +00:00
|
|
|
ac3parse->partialbuf = outbuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_ac3parse_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2001-12-22 22:43:37 +00:00
|
|
|
{
|
|
|
|
GstAc3Parse *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:30 +00:00
|
|
|
g_return_if_fail (GST_IS_AC3PARSE (object));
|
|
|
|
src = GST_AC3PARSE (object);
|
2001-12-22 22:43:37 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_SKIP:
|
|
|
|
src->skip = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_ac3parse_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-22 22:43:37 +00:00
|
|
|
{
|
|
|
|
GstAc3Parse *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:30 +00:00
|
|
|
g_return_if_fail (GST_IS_AC3PARSE (object));
|
|
|
|
src = GST_AC3PARSE (object);
|
2001-12-22 22:43:37 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_SKIP:
|
|
|
|
g_value_set_int (value, src->skip);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-06 20:49:50 +00:00
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_ac3parse_change_state (GstElement * element)
|
2003-07-06 20:49:50 +00:00
|
|
|
{
|
2004-03-14 22:34:30 +00:00
|
|
|
GstAc3Parse *ac3parse = GST_AC3PARSE (element);
|
2003-07-06 20:49:50 +00:00
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
/* reset stream info */
|
|
|
|
ac3parse->channels = ac3parse->sample_rate = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2001-12-22 22:43:37 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:30 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-22 22:43:37 +00:00
|
|
|
{
|
2004-03-14 22:34:30 +00:00
|
|
|
if (!gst_element_register (plugin, "ac3parse", GST_RANK_SECONDARY,
|
2004-03-15 19:32:25 +00:00
|
|
|
GST_TYPE_AC3PARSE)) {
|
2003-11-01 01:11:05 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-12-22 22:43:37 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"ac3parse",
|
|
|
|
"ac3 parsing", plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
|