2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:26:48 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*#define GST_DEBUG_ENABLED*/
|
2003-06-29 19:46:09 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 23:26:48 +00:00
|
|
|
#include <gstmpegdemux.h>
|
|
|
|
|
2003-07-25 02:04:01 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (GST_CAT_SEEK);
|
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
/* elementfactory information */
|
|
|
|
static GstElementDetails mpeg_demux_details = {
|
2002-04-20 21:42:51 +00:00
|
|
|
"MPEG Demuxer",
|
|
|
|
"Codec/Demuxer",
|
2002-09-18 19:02:46 +00:00
|
|
|
"LGPL",
|
2001-12-22 23:26:48 +00:00
|
|
|
"Demultiplexes MPEG1 and MPEG2 System Streams",
|
|
|
|
VERSION,
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>\n"
|
|
|
|
"Wim Taymans <wim.taymans@chello.be>",
|
|
|
|
"(C) 1999",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* MPEG2Demux signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_BIT_RATE,
|
|
|
|
ARG_MPEG2,
|
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (sink_factory,
|
2001-12-22 23:26:48 +00:00
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"mpeg_demux_sink",
|
|
|
|
"video/mpeg",
|
|
|
|
"mpegversion", GST_PROPS_INT_RANGE (1, 2),
|
|
|
|
"systemstream", GST_PROPS_BOOLEAN (TRUE)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (audio_factory,
|
2002-04-13 17:38:40 +00:00
|
|
|
"audio_%02d",
|
2001-12-22 23:26:48 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"mpeg_demux_audio",
|
2003-07-06 20:49:50 +00:00
|
|
|
"audio/mpeg",
|
|
|
|
NULL
|
2001-12-22 23:26:48 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (video_mpeg1_factory,
|
2002-04-13 17:38:40 +00:00
|
|
|
"video_%02d",
|
2001-12-22 23:26:48 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"mpeg_demux_video_mpeg1",
|
|
|
|
"video/mpeg",
|
|
|
|
"mpegversion", GST_PROPS_INT (1),
|
|
|
|
"systemstream", GST_PROPS_BOOLEAN (FALSE)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (video_mpeg2_factory,
|
2002-04-13 17:38:40 +00:00
|
|
|
"video_%02d",
|
2001-12-22 23:26:48 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"mpeg_demux_video_mpeg2",
|
|
|
|
"video/mpeg",
|
|
|
|
"mpegversion", GST_PROPS_INT (2),
|
|
|
|
"systemstream", GST_PROPS_BOOLEAN (FALSE)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (private1_factory,
|
2002-04-15 09:27:02 +00:00
|
|
|
"private_stream_1_%02d",
|
2001-12-22 23:26:48 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"mpeg_demux_private1",
|
2003-07-06 20:49:50 +00:00
|
|
|
"audio/x-ac3",
|
|
|
|
NULL
|
2001-12-22 23:26:48 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (private2_factory,
|
2001-12-22 23:26:48 +00:00
|
|
|
"private_stream_2",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
2003-07-06 20:49:50 +00:00
|
|
|
NULL
|
2001-12-22 23:26:48 +00:00
|
|
|
);
|
|
|
|
|
2003-03-02 09:48:48 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (pcm_factory,
|
|
|
|
"pcm_stream_%02d",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"mpeg_demux_pcm",
|
2003-07-06 20:49:50 +00:00
|
|
|
"audio/x-raw-int",
|
2003-05-14 21:54:41 +00:00
|
|
|
"endianness", GST_PROPS_INT (G_BIG_ENDIAN),
|
|
|
|
"signed", GST_PROPS_BOOLEAN (TRUE),
|
|
|
|
"width", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_INT (16),
|
|
|
|
GST_PROPS_INT (20),
|
|
|
|
GST_PROPS_INT (24)
|
|
|
|
),
|
|
|
|
"depth", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_INT (16),
|
|
|
|
GST_PROPS_INT (20),
|
|
|
|
GST_PROPS_INT (24)
|
|
|
|
),
|
|
|
|
"rate", GST_PROPS_LIST (
|
|
|
|
GST_PROPS_INT (48000),
|
|
|
|
GST_PROPS_INT (96000)
|
|
|
|
),
|
|
|
|
"channels", GST_PROPS_INT_RANGE (1, 8)
|
2003-03-02 09:48:48 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (subtitle_factory,
|
2002-04-13 17:38:40 +00:00
|
|
|
"subtitle_stream_%d",
|
2001-12-22 23:26:48 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
2003-07-06 20:49:50 +00:00
|
|
|
NULL /* FIXME! */
|
2001-12-22 23:26:48 +00:00
|
|
|
);
|
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
static void gst_mpeg_demux_class_init (GstMPEGDemuxClass *klass);
|
|
|
|
static void gst_mpeg_demux_init (GstMPEGDemux *mpeg_demux);
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
static gboolean gst_mpeg_demux_parse_packhead (GstMPEGParse *mpeg_parse, GstBuffer *buffer);
|
|
|
|
static gboolean gst_mpeg_demux_parse_syshead (GstMPEGParse *mpeg_parse, GstBuffer *buffer);
|
|
|
|
static gboolean gst_mpeg_demux_parse_packet (GstMPEGParse *mpeg_parse, GstBuffer *buffer);
|
|
|
|
static gboolean gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer);
|
|
|
|
static void gst_mpeg_demux_send_data (GstMPEGParse *mpeg_parse,
|
|
|
|
GstData *data, GstClockTime time);
|
|
|
|
|
2003-05-14 21:54:41 +00:00
|
|
|
static void gst_mpeg_demux_lpcm_set_caps (GstPad *pad, guint8 sample_info);
|
|
|
|
static void gst_mpeg_demux_dvd_audio_clear (GstMPEGDemux *mpeg_demux, int channel);
|
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
static void gst_mpeg_demux_handle_discont (GstMPEGParse *mpeg_parse);
|
2002-12-26 22:45:10 +00:00
|
|
|
static gboolean gst_mpeg_demux_handle_src_event (GstPad *pad, GstEvent *event);
|
2002-11-27 21:00:12 +00:00
|
|
|
|
2002-12-27 22:43:28 +00:00
|
|
|
const GstFormat* gst_mpeg_demux_get_src_formats (GstPad *pad);
|
2002-12-12 22:17:10 +00:00
|
|
|
static void gst_mpeg_demux_set_index (GstElement *element, GstIndex *index);
|
|
|
|
static GstIndex* gst_mpeg_demux_get_index (GstElement *element);
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2002-02-03 20:10:04 +00:00
|
|
|
static GstElementStateReturn
|
2002-12-27 22:43:28 +00:00
|
|
|
gst_mpeg_demux_change_state (GstElement *element);
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
static GstMPEGParseClass *parent_class = NULL;
|
|
|
|
/*static guint gst_mpeg_demux_signals[LAST_SIGNAL] = { 0 };*/
|
|
|
|
|
|
|
|
GType
|
|
|
|
mpeg_demux_get_type (void)
|
|
|
|
{
|
|
|
|
static GType mpeg_demux_type = 0;
|
|
|
|
|
|
|
|
if (!mpeg_demux_type) {
|
|
|
|
static const GTypeInfo mpeg_demux_info = {
|
|
|
|
sizeof(GstMPEGDemuxClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_mpeg_demux_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstMPEGDemux),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_mpeg_demux_init,
|
|
|
|
};
|
|
|
|
mpeg_demux_type = g_type_register_static(GST_TYPE_MPEG_PARSE, "GstMPEGDemux", &mpeg_demux_info, 0);
|
|
|
|
}
|
|
|
|
return mpeg_demux_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mpeg_demux_class_init (GstMPEGDemuxClass *klass)
|
|
|
|
{
|
|
|
|
GstMPEGParseClass *mpeg_parse_class;
|
2002-02-03 20:10:04 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_MPEG_PARSE);
|
|
|
|
|
|
|
|
mpeg_parse_class = (GstMPEGParseClass *) klass;
|
2002-02-03 20:10:04 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_mpeg_demux_change_state;
|
2002-12-12 22:17:10 +00:00
|
|
|
gstelement_class->set_index = gst_mpeg_demux_set_index;
|
|
|
|
gstelement_class->get_index = gst_mpeg_demux_get_index;
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
mpeg_parse_class->parse_packhead = gst_mpeg_demux_parse_packhead;
|
|
|
|
mpeg_parse_class->parse_syshead = gst_mpeg_demux_parse_syshead;
|
|
|
|
mpeg_parse_class->parse_packet = gst_mpeg_demux_parse_packet;
|
|
|
|
mpeg_parse_class->parse_pes = gst_mpeg_demux_parse_pes;
|
|
|
|
mpeg_parse_class->send_data = gst_mpeg_demux_send_data;
|
2002-05-26 21:59:22 +00:00
|
|
|
mpeg_parse_class->handle_discont = gst_mpeg_demux_handle_discont;
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mpeg_demux_init (GstMPEGDemux *mpeg_demux)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
GstMPEGParse *mpeg_parse = GST_MPEG_PARSE (mpeg_demux);
|
|
|
|
|
|
|
|
gst_element_remove_pad (GST_ELEMENT (mpeg_parse), mpeg_parse->sinkpad);
|
|
|
|
mpeg_parse->sinkpad = gst_pad_new_from_template(
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_GET (sink_factory), "sink");
|
2001-12-22 23:26:48 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (mpeg_parse), mpeg_parse->sinkpad);
|
|
|
|
gst_element_remove_pad (GST_ELEMENT (mpeg_parse), mpeg_parse->srcpad);
|
|
|
|
|
|
|
|
/* i think everything is already zero'd, but oh well*/
|
2002-11-27 21:00:12 +00:00
|
|
|
for (i=0;i<NUM_PRIVATE_1_STREAMS;i++) {
|
|
|
|
mpeg_demux->private_1_stream[i] = NULL;
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
2003-05-14 21:54:41 +00:00
|
|
|
for (i=0;i<NUM_PCM_STREAMS;i++) {
|
|
|
|
mpeg_demux->pcm_stream[i] = NULL;
|
|
|
|
}
|
2002-11-27 21:00:12 +00:00
|
|
|
for (i=0;i<NUM_SUBTITLE_STREAMS;i++) {
|
|
|
|
mpeg_demux->subtitle_stream[i] = NULL;
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
2002-11-27 21:00:12 +00:00
|
|
|
mpeg_demux->private_2_stream = NULL;
|
|
|
|
for (i=0;i<NUM_VIDEO_STREAMS;i++) {
|
|
|
|
mpeg_demux->video_stream[i] = NULL;
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
2002-11-27 21:00:12 +00:00
|
|
|
for (i=0;i<NUM_AUDIO_STREAMS;i++) {
|
|
|
|
mpeg_demux->audio_stream[i] = NULL;
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_FLAG_SET (mpeg_demux, GST_ELEMENT_EVENT_AWARE);
|
|
|
|
}
|
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
static GstMPEGStream*
|
|
|
|
gst_mpeg_demux_new_stream (void)
|
|
|
|
{
|
|
|
|
GstMPEGStream *stream;
|
|
|
|
|
|
|
|
stream = g_new0 (GstMPEGStream, 1);
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
static void
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_mpeg_demux_send_data (GstMPEGParse *mpeg_parse, GstData *data, GstClockTime time)
|
2001-12-22 23:26:48 +00:00
|
|
|
{
|
2002-11-04 23:16:45 +00:00
|
|
|
/* GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (mpeg_parse); */
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
if (GST_IS_BUFFER (data)) {
|
|
|
|
gst_buffer_unref (GST_BUFFER (data));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GstEvent *event = GST_EVENT (data);
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
default:
|
|
|
|
gst_pad_event_default (mpeg_parse->sinkpad, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
gst_mpeg_demux_handle_discont (GstMPEGParse *mpeg_parse)
|
|
|
|
{
|
|
|
|
GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (mpeg_parse);
|
|
|
|
gint64 current_time = MPEGTIME_TO_GSTTIME (mpeg_parse->current_scr);
|
2002-11-04 23:16:45 +00:00
|
|
|
gint i;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("discont %" G_GUINT64_FORMAT "\n", current_time);
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
for (i=0;i<NUM_VIDEO_STREAMS;i++) {
|
|
|
|
if (mpeg_demux->video_stream[i] &&
|
|
|
|
GST_PAD_IS_USABLE (mpeg_demux->video_stream[i]->pad))
|
2002-05-26 21:59:22 +00:00
|
|
|
{
|
|
|
|
GstEvent *discont;
|
|
|
|
|
|
|
|
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME,
|
|
|
|
current_time, NULL);
|
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
gst_pad_push (mpeg_demux->video_stream[i]->pad, GST_BUFFER (discont));
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
2002-11-27 21:00:12 +00:00
|
|
|
if (mpeg_demux->audio_stream[i] &&
|
|
|
|
GST_PAD_IS_USABLE (mpeg_demux->audio_stream[i]->pad))
|
2002-05-26 21:59:22 +00:00
|
|
|
{
|
|
|
|
GstEvent *discont;
|
|
|
|
|
|
|
|
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME,
|
|
|
|
current_time, NULL);
|
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
gst_pad_push (mpeg_demux->audio_stream[i]->pad, GST_BUFFER (discont));
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_mpeg_demux_parse_packhead (GstMPEGParse *mpeg_parse, GstBuffer *buffer)
|
|
|
|
{
|
|
|
|
guint8 *buf;
|
|
|
|
|
|
|
|
parent_class->parse_packhead (mpeg_parse, buffer);
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("in parse_packhead");
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
buf = GST_BUFFER_DATA (buffer);
|
|
|
|
/* do something usefull here */
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-07-25 02:04:01 +00:00
|
|
|
static gint
|
|
|
|
_demux_get_writer_id (GstIndex *index, GstPad *pad)
|
|
|
|
{
|
|
|
|
gint id;
|
|
|
|
if (!gst_index_get_writer_id (index, GST_OBJECT (pad), &id)) {
|
|
|
|
GST_CAT_WARNING_OBJECT (GST_CAT_SEEK, index,
|
|
|
|
"can't get index id for %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
GST_CAT_LOG_OBJECT (GST_CAT_SEEK, index,
|
|
|
|
"got index id %d for %s:%s",
|
|
|
|
id, GST_DEBUG_PAD_NAME (pad));
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mpeg_demux_parse_syshead (GstMPEGParse *mpeg_parse, GstBuffer *buffer)
|
|
|
|
{
|
|
|
|
GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (mpeg_parse);
|
|
|
|
guint16 header_length;
|
|
|
|
guchar *buf;
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("in parse_syshead");
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
buf = GST_BUFFER_DATA (buffer);
|
|
|
|
buf += 4;
|
|
|
|
|
|
|
|
header_length = GUINT16_FROM_BE (*(guint16 *) buf);
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("header_length %d", header_length);
|
2001-12-22 23:26:48 +00:00
|
|
|
buf += 2;
|
|
|
|
|
|
|
|
/* marker:1==1 ! rate_bound:22 | marker:1==1*/
|
|
|
|
buf += 3;
|
|
|
|
|
|
|
|
/* audio_bound:6==1 ! fixed:1 | constrained:1*/
|
|
|
|
buf += 1;
|
|
|
|
|
|
|
|
/* audio_lock:1 | video_lock:1 | marker:1==1 | video_bound:5 */
|
|
|
|
buf += 1;
|
|
|
|
|
|
|
|
/* apacket_rate_restriction:1 | reserved:7==0x7F */
|
|
|
|
buf += 1;
|
|
|
|
|
|
|
|
if (!GST_MPEG_PARSE_IS_MPEG2 (mpeg_demux)) {
|
|
|
|
gint stream_count = (header_length - 6) / 3;
|
|
|
|
gint i, j=0;
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("number of streams=%d ",
|
2001-12-22 23:26:48 +00:00
|
|
|
stream_count);
|
|
|
|
|
|
|
|
for (i = 0; i < stream_count; i++) {
|
|
|
|
guint8 stream_id;
|
|
|
|
gboolean STD_buffer_bound_scale;
|
|
|
|
guint16 STD_buffer_size_bound;
|
|
|
|
guint32 buf_byte_size_bound;
|
|
|
|
gchar *name = NULL;
|
2002-11-27 21:00:12 +00:00
|
|
|
GstMPEGStream **outstream = NULL;
|
2001-12-22 23:26:48 +00:00
|
|
|
GstPadTemplate *newtemp = NULL;
|
|
|
|
|
|
|
|
stream_id = *buf++;
|
|
|
|
if (!(stream_id & 0x80)) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("error in system header length");
|
2001-12-22 23:26:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check marker bits */
|
|
|
|
if ((*buf & 0xC0) != 0xC0) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("expecting placeholder bit values '11' after stream id\n");
|
2001-12-22 23:26:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
STD_buffer_bound_scale = *buf & 0x20;
|
|
|
|
STD_buffer_size_bound = (*buf++ & 0x1F) << 8;
|
|
|
|
STD_buffer_size_bound |= *buf++;
|
|
|
|
|
|
|
|
if (STD_buffer_bound_scale == 0) {
|
|
|
|
buf_byte_size_bound = STD_buffer_size_bound * 128;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buf_byte_size_bound = STD_buffer_size_bound * 1024;
|
|
|
|
}
|
|
|
|
|
2003-05-22 10:41:49 +00:00
|
|
|
if (stream_id == 0xBD) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* private_stream_1 */
|
2003-05-22 10:41:49 +00:00
|
|
|
name = NULL;
|
|
|
|
outstream = NULL;
|
|
|
|
} else if (stream_id == 0xBF) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* private_stream_2 */
|
2003-05-22 10:41:49 +00:00
|
|
|
name = g_strdup_printf ("private_stream_2");
|
|
|
|
outstream = &mpeg_demux->private_2_stream;
|
|
|
|
newtemp = GST_PAD_TEMPLATE_GET (private2_factory);
|
|
|
|
} else if (stream_id >= 0xC0 && stream_id < 0xE0) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* Audio */
|
2003-05-22 10:41:49 +00:00
|
|
|
name = g_strdup_printf ("audio_%02d", stream_id & 0x1F);
|
|
|
|
outstream = &mpeg_demux->audio_stream[stream_id & 0x1F];
|
|
|
|
newtemp = GST_PAD_TEMPLATE_GET (audio_factory);
|
|
|
|
} else if (stream_id >= 0xE0 && stream_id < 0xF0) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* Video */
|
2003-05-22 10:41:49 +00:00
|
|
|
name = g_strdup_printf ("video_%02d", stream_id & 0x0F);
|
|
|
|
outstream = &mpeg_demux->video_stream[stream_id & 0x0F];
|
|
|
|
if (!GST_MPEG_PARSE_IS_MPEG2 (mpeg_demux)) {
|
|
|
|
newtemp = GST_PAD_TEMPLATE_GET (video_mpeg1_factory);
|
|
|
|
} else {
|
|
|
|
newtemp = GST_PAD_TEMPLATE_GET (video_mpeg2_factory);
|
|
|
|
}
|
|
|
|
} else {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("unkown stream id %d", stream_id);
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("stream ID 0x%02X (%s)", stream_id, name);
|
|
|
|
GST_DEBUG ("STD_buffer_bound_scale %d", STD_buffer_bound_scale);
|
|
|
|
GST_DEBUG ("STD_buffer_size_bound %d or %d bytes",
|
2001-12-22 23:26:48 +00:00
|
|
|
STD_buffer_size_bound, buf_byte_size_bound);
|
|
|
|
|
|
|
|
/* create the pad and add it to self if it does not yet exist
|
|
|
|
* this should trigger the NEW_PAD signal, which should be caught by
|
|
|
|
* the app and used to attach to desired streams.
|
|
|
|
*/
|
2002-11-27 21:00:12 +00:00
|
|
|
if (outstream && *outstream == NULL) {
|
|
|
|
GstPad **outpad;
|
2003-02-02 20:05:59 +00:00
|
|
|
GstCaps *caps;
|
2002-11-27 21:00:12 +00:00
|
|
|
|
|
|
|
*outstream = gst_mpeg_demux_new_stream ();
|
|
|
|
outpad = &((*outstream)->pad);
|
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
*outpad = gst_pad_new_from_template (newtemp, name);
|
2003-02-02 20:05:59 +00:00
|
|
|
caps = gst_pad_template_get_caps (newtemp);
|
|
|
|
gst_pad_try_set_caps (*outpad, caps);
|
|
|
|
gst_caps_unref (caps);
|
2002-07-24 21:43:44 +00:00
|
|
|
|
2002-12-27 22:43:28 +00:00
|
|
|
gst_pad_set_formats_function (*outpad, gst_mpeg_demux_get_src_formats);
|
2002-12-26 22:45:10 +00:00
|
|
|
gst_pad_set_convert_function (*outpad, gst_mpeg_parse_convert_src);
|
2002-07-24 21:43:44 +00:00
|
|
|
gst_pad_set_event_mask_function (*outpad, gst_mpeg_parse_get_src_event_masks);
|
2002-12-26 22:45:10 +00:00
|
|
|
gst_pad_set_event_function (*outpad, gst_mpeg_demux_handle_src_event);
|
2002-07-24 21:43:44 +00:00
|
|
|
gst_pad_set_query_type_function (*outpad, gst_mpeg_parse_get_src_query_types);
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_pad_set_query_function (*outpad, gst_mpeg_parse_handle_src_query);
|
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (mpeg_demux), (*outpad));
|
2002-12-26 22:45:10 +00:00
|
|
|
gst_pad_set_element_private (*outpad, *outstream);
|
|
|
|
|
|
|
|
(*outstream)->size_bound = buf_byte_size_bound;
|
|
|
|
mpeg_demux->total_size_bound += buf_byte_size_bound;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2003-07-25 02:04:01 +00:00
|
|
|
if (mpeg_demux->index)
|
|
|
|
(*outstream)->index_id =
|
|
|
|
_demux_get_writer_id (mpeg_demux->index, *outpad);
|
2002-11-27 21:00:12 +00:00
|
|
|
|
2002-11-04 23:16:45 +00:00
|
|
|
if (GST_PAD_IS_USABLE (*outpad)) {
|
2002-05-26 21:59:22 +00:00
|
|
|
GstEvent *event;
|
2002-11-04 23:16:45 +00:00
|
|
|
gint64 time;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2002-11-04 23:16:45 +00:00
|
|
|
time = mpeg_parse->current_scr;
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
event = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME,
|
2002-11-04 23:16:45 +00:00
|
|
|
MPEGTIME_TO_GSTTIME (time), NULL);
|
2002-05-26 21:59:22 +00:00
|
|
|
|
|
|
|
gst_pad_push (*outpad, GST_BUFFER (event));
|
|
|
|
}
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* we won't be needing this. */
|
|
|
|
if (name)
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_mpeg_demux_parse_packet (GstMPEGParse *mpeg_parse, GstBuffer *buffer)
|
|
|
|
{
|
|
|
|
GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (mpeg_parse);
|
|
|
|
guint8 id;
|
|
|
|
guint16 headerlen;
|
|
|
|
|
|
|
|
guint16 packet_length;
|
|
|
|
gboolean STD_buffer_bound_scale;
|
|
|
|
guint16 STD_buffer_size_bound;
|
|
|
|
guint64 dts;
|
|
|
|
guint8 ps_id_code;
|
2001-12-23 23:18:39 +00:00
|
|
|
gint64 pts = -1;
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
guint16 datalen;
|
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
GstMPEGStream **outstream = NULL;
|
|
|
|
GstPad *outpad = NULL;
|
2001-12-22 23:26:48 +00:00
|
|
|
GstBuffer *outbuf;
|
|
|
|
guint8 *buf, *basebuf;
|
2002-11-27 21:00:12 +00:00
|
|
|
gint64 timestamp;
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("in parse_packet");
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
basebuf = buf = GST_BUFFER_DATA (buffer);
|
|
|
|
id = *(buf+3);
|
|
|
|
buf += 4;
|
|
|
|
|
|
|
|
/* start parsing */
|
|
|
|
packet_length = GUINT16_FROM_BE (*((guint16 *)buf));
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("got packet_length %d", packet_length);
|
2001-12-22 23:26:48 +00:00
|
|
|
headerlen = 2;
|
|
|
|
buf += 2;
|
|
|
|
|
|
|
|
/* loop through looping for stuffing bits, STD, PTS, DTS, etc */
|
|
|
|
do {
|
|
|
|
guint8 bits = *buf++;
|
|
|
|
|
|
|
|
/* stuffing bytes */
|
|
|
|
switch (bits & 0xC0) {
|
|
|
|
case 0xC0:
|
|
|
|
if (bits == 0xff) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("have stuffing byte");
|
2001-12-22 23:26:48 +00:00
|
|
|
} else {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("expected stuffing byte");
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
headerlen++;
|
|
|
|
break;
|
|
|
|
case 0x40:
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("have STD");
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
STD_buffer_bound_scale = bits & 0x20;
|
|
|
|
STD_buffer_size_bound = (bits & 0x1F) << 8;
|
|
|
|
STD_buffer_size_bound |= *buf++;
|
|
|
|
|
|
|
|
headerlen += 2;
|
|
|
|
break;
|
|
|
|
case 0x00:
|
|
|
|
switch (bits & 0x30) {
|
|
|
|
case 0x20:
|
|
|
|
/* pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */
|
2001-12-23 23:18:39 +00:00
|
|
|
pts = (bits & 0x0E) << 29;
|
|
|
|
pts |= *buf++ << 22;
|
|
|
|
pts |= (*buf++ & 0xFE) << 14;
|
|
|
|
pts |= *buf++ << 7;
|
|
|
|
pts |= (*buf++ & 0xFE) >> 1;
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("PTS = %" G_GUINT64_FORMAT, pts);
|
2001-12-22 23:26:48 +00:00
|
|
|
headerlen += 5;
|
|
|
|
goto done;
|
|
|
|
case 0x30:
|
|
|
|
/* pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */
|
2001-12-23 23:18:39 +00:00
|
|
|
pts = (bits & 0x0E) << 29;
|
|
|
|
pts |= *buf++ << 22;
|
|
|
|
pts |= (*buf++ & 0xFE) << 14;
|
|
|
|
pts |= *buf++ << 7;
|
|
|
|
pts |= (*buf++ & 0xFE) >> 1;
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
/* sync:4 ! pts:3 ! 1 ! pts:15 ! 1 | pts:15 ! 1 */
|
|
|
|
dts = (*buf++ & 0x0E) << 29;
|
|
|
|
dts |= *buf++ << 22;
|
|
|
|
dts |= (*buf++ & 0xFE) << 14;
|
|
|
|
dts |= *buf++ << 7;
|
|
|
|
dts |= (*buf++ & 0xFE) >> 1;
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("PTS = %" G_GUINT64_FORMAT ", DTS = %" G_GUINT64_FORMAT, pts, dts);
|
2001-12-22 23:26:48 +00:00
|
|
|
headerlen += 10;
|
|
|
|
goto done;
|
|
|
|
case 0x00:
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("have no pts/dts");
|
|
|
|
GST_DEBUG ("got trailer bits %x", (bits & 0x0f));
|
2001-12-22 23:26:48 +00:00
|
|
|
if ((bits & 0x0f) != 0xf) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("not a valid packet time sequence");
|
2001-12-22 23:26:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
headerlen++;
|
|
|
|
default:
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
} while (1);
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("done with header loop");
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
done:
|
2002-11-04 23:16:45 +00:00
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
/* calculate the amount of real data in this packet */
|
|
|
|
datalen = packet_length - headerlen+2;
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("headerlen is %d, datalen is %d",
|
2001-12-22 23:26:48 +00:00
|
|
|
headerlen,datalen);
|
|
|
|
|
2003-05-22 10:41:49 +00:00
|
|
|
if (id == 0xBD) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* private_stream_1 */
|
2003-05-22 10:41:49 +00:00
|
|
|
/* first find the track code */
|
|
|
|
ps_id_code = *(basebuf + headerlen);
|
2002-11-04 23:16:45 +00:00
|
|
|
|
2003-05-22 10:41:49 +00:00
|
|
|
if (ps_id_code >= 0x80 && ps_id_code <= 0x87) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* make sure it's valid */
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("0x%02X: we have a private_stream_1 (AC3) packet, track %d",
|
2003-05-22 10:41:49 +00:00
|
|
|
id, ps_id_code - 0x80);
|
|
|
|
outstream = &mpeg_demux->private_1_stream[ps_id_code - 0x80];
|
|
|
|
/* scrap first 4 bytes (so-called "mystery AC3 tag") */
|
|
|
|
headerlen += 4;
|
|
|
|
datalen -= 4;
|
|
|
|
}
|
|
|
|
} else if (id == 0xBF) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* private_stream_2 */
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("0x%02X: we have a private_stream_2 packet", id);
|
2003-05-22 10:41:49 +00:00
|
|
|
outstream = &mpeg_demux->private_2_stream;
|
|
|
|
} else if (id >= 0xC0 && id <= 0xDF) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* audio */
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("0x%02X: we have an audio packet", id);
|
2003-05-22 10:41:49 +00:00
|
|
|
outstream = &mpeg_demux->audio_stream[id & 0x1F];
|
|
|
|
} else if (id >= 0xE0 && id <= 0xEF) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* video */
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("0x%02X: we have a video packet", id);
|
2003-05-22 10:41:49 +00:00
|
|
|
outstream = &mpeg_demux->video_stream[id & 0x0F];
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if we don't know what it is, bail */
|
2002-11-27 21:00:12 +00:00
|
|
|
if (outstream == NULL) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("unknown packet id 0x%02X !!", id);
|
2001-12-22 23:26:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
outpad = (*outstream)->pad;
|
|
|
|
|
2002-11-04 23:16:45 +00:00
|
|
|
/* the pad should have been created in parse_syshead */
|
2002-11-27 21:00:12 +00:00
|
|
|
if (outpad == NULL) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("unexpected packet id 0x%02X!!", id);
|
2001-12-22 23:26:48 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
/* attach pts, if any */
|
|
|
|
if (pts != -1) {
|
|
|
|
pts += mpeg_parse->adjust;
|
|
|
|
timestamp = MPEGTIME_TO_GSTTIME (pts);
|
|
|
|
|
2002-12-12 22:17:10 +00:00
|
|
|
if (mpeg_demux->index) {
|
|
|
|
gst_index_add_association (mpeg_demux->index,
|
|
|
|
(*outstream)->index_id, 0,
|
2002-11-27 21:00:12 +00:00
|
|
|
GST_FORMAT_BYTES, GST_BUFFER_OFFSET (buffer),
|
|
|
|
GST_FORMAT_TIME, timestamp,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
timestamp = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
/* create the buffer and send it off to the Other Side */
|
2003-01-10 10:22:24 +00:00
|
|
|
if (GST_PAD_IS_LINKED (outpad) && datalen > 0) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("creating subbuffer len %d", datalen);
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2002-11-04 23:16:45 +00:00
|
|
|
/* if this is part of the buffer, create a subbuffer */
|
|
|
|
outbuf = gst_buffer_create_sub (buffer, headerlen + 4, datalen);
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
|
2003-05-24 10:17:50 +00:00
|
|
|
GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET (buffer) + headerlen + 4;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("pushing buffer of len %d id %d, ts %" G_GINT64_FORMAT,
|
2001-12-22 23:26:48 +00:00
|
|
|
datalen, id, GST_BUFFER_TIMESTAMP (outbuf));
|
2002-11-04 23:16:45 +00:00
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
gst_pad_push (outpad, outbuf);
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_mpeg_demux_parse_pes (GstMPEGParse *mpeg_parse, GstBuffer *buffer)
|
|
|
|
{
|
|
|
|
GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (mpeg_parse);
|
|
|
|
guint8 id;
|
2001-12-23 23:18:39 +00:00
|
|
|
gint64 pts = -1;
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
guint16 packet_length;
|
|
|
|
guint8 header_data_length = 0;
|
|
|
|
|
|
|
|
guint16 datalen;
|
|
|
|
guint16 headerlen;
|
|
|
|
guint8 ps_id_code = 0x80;
|
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
GstMPEGStream **outstream = NULL;
|
2001-12-22 23:26:48 +00:00
|
|
|
GstPad **outpad = NULL;
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
GstPadTemplate *newtemp = NULL;
|
|
|
|
guint8 *buf, *basebuf;
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("in parse_pes");
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
basebuf = buf = GST_BUFFER_DATA (buffer);
|
|
|
|
id = *(buf+3);
|
|
|
|
buf += 4;
|
|
|
|
|
|
|
|
/* start parsing */
|
|
|
|
packet_length = GUINT16_FROM_BE (*((guint16 *)buf));
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("got packet_length %d", packet_length);
|
2001-12-22 23:26:48 +00:00
|
|
|
buf += 2;
|
|
|
|
|
|
|
|
/* we don't operate on: program_stream_map, padding_stream, */
|
|
|
|
/* private_stream_2, ECM, EMM, or program_stream_directory */
|
|
|
|
if ((id != 0xBC) && (id != 0xBE) && (id != 0xBF) && (id != 0xF0) &&
|
|
|
|
(id != 0xF1) && (id != 0xFF))
|
|
|
|
{
|
|
|
|
guchar flags1 = *buf++;
|
|
|
|
guchar flags2 = *buf++;
|
|
|
|
|
|
|
|
if ((flags1 & 0xC0) != 0x80) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
header_data_length = *buf++;
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("header_data_length is %d",header_data_length);
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
/* check for PTS */
|
|
|
|
if ((flags2 & 0x80)) {
|
|
|
|
/*if ((flags2 & 0x80) && id == 0xe0) { */
|
2001-12-23 23:18:39 +00:00
|
|
|
pts = (*buf++ & 0x0E) << 29;
|
|
|
|
pts |= *buf++ << 22;
|
|
|
|
pts |= (*buf++ & 0xFE) << 14;
|
|
|
|
pts |= *buf++ << 7;
|
|
|
|
pts |= (*buf++ & 0xFE) >> 1;
|
2002-11-04 23:16:45 +00:00
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("%x PTS = %" G_GUINT64_FORMAT,
|
2002-11-04 23:16:45 +00:00
|
|
|
id, MPEGTIME_TO_GSTTIME (pts));
|
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
if ((flags2 & 0x40)) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("%x DTS found", id);
|
2001-12-22 23:26:48 +00:00
|
|
|
buf += 5;
|
|
|
|
}
|
|
|
|
if ((flags2 & 0x20)) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("%x ESCR found", id);
|
2001-12-22 23:26:48 +00:00
|
|
|
buf += 6;
|
|
|
|
}
|
|
|
|
if ((flags2 & 0x10)) {
|
|
|
|
guint32 es_rate;
|
|
|
|
|
|
|
|
es_rate = (*buf++ & 0x07) << 14;
|
|
|
|
es_rate |= (*buf++ ) << 7;
|
|
|
|
es_rate |= (*buf++ & 0xFE) >> 1;
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("%x ES Rate found", id);
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
/* FIXME: lots of PES parsing missing here... */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate the amount of real data in this PES packet */
|
|
|
|
/* constant is 2 bytes packet_length, 2 bytes of bits, 1 byte header len */
|
|
|
|
headerlen = 5 + header_data_length;
|
|
|
|
/* constant is 2 bytes of bits, 1 byte header len */
|
|
|
|
datalen = packet_length - (3 + header_data_length);
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("headerlen is %d, datalen is %d",
|
2001-12-22 23:26:48 +00:00
|
|
|
headerlen, datalen);
|
|
|
|
|
2003-05-22 10:41:49 +00:00
|
|
|
if (id == 0xBD) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* private_stream_1 */
|
2003-05-22 10:41:49 +00:00
|
|
|
/* first find the track code */
|
|
|
|
ps_id_code = *(basebuf + headerlen + 4);
|
|
|
|
|
|
|
|
if (ps_id_code >= 0x80 && ps_id_code <= 0x87) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("we have a private_stream_1 (AC3) packet, track %d",
|
2003-05-22 10:41:49 +00:00
|
|
|
ps_id_code - 0x80);
|
|
|
|
outstream = &mpeg_demux->private_1_stream[ps_id_code - 0x80];
|
|
|
|
/* scrap first 4 bytes (so-called "mystery AC3 tag") */
|
|
|
|
headerlen += 4;
|
|
|
|
datalen -= 4;
|
|
|
|
} else if (ps_id_code >= 0xA0 && ps_id_code <= 0xA7) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("we have a pcm_stream packet, track %d",
|
2003-05-22 10:41:49 +00:00
|
|
|
ps_id_code - 0xA0);
|
|
|
|
outstream = &mpeg_demux->pcm_stream[ps_id_code - 0xA0];
|
|
|
|
|
|
|
|
/* Check for changes in the sample format. */
|
|
|
|
if (*outstream != NULL &&
|
|
|
|
basebuf[headerlen + 9] !=
|
|
|
|
mpeg_demux->lpcm_sample_info[ps_id_code - 0xA0]) {
|
|
|
|
/* Change the pad caps.*/
|
|
|
|
gst_mpeg_demux_lpcm_set_caps((*outstream)->pad, basebuf[headerlen + 9]);
|
2002-11-04 23:16:45 +00:00
|
|
|
}
|
2003-05-22 10:41:49 +00:00
|
|
|
|
|
|
|
/* Store the sample info. */
|
|
|
|
mpeg_demux->lpcm_sample_info[ps_id_code - 0xA0] =
|
|
|
|
basebuf[headerlen + 9];
|
|
|
|
|
|
|
|
/* Get rid of the LPCM header. */
|
|
|
|
headerlen += 7;
|
|
|
|
datalen -= 7;
|
|
|
|
} else if (ps_id_code >= 0x20 && ps_id_code <= 0x2F) {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("we have a subtitle_stream packet, track %d",
|
2003-05-22 10:41:49 +00:00
|
|
|
ps_id_code - 0x20);
|
|
|
|
outstream = &mpeg_demux->subtitle_stream[ps_id_code - 0x20];
|
|
|
|
headerlen += 1;
|
|
|
|
datalen -= 1;
|
|
|
|
} else {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("0x%02X: unkonwn id %x",
|
2003-05-22 10:41:49 +00:00
|
|
|
id, ps_id_code);
|
|
|
|
}
|
|
|
|
} else if (id == 0xBF) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* private_stream_2 */
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("we have a private_stream_2 packet");
|
2003-05-22 10:41:49 +00:00
|
|
|
outstream = &mpeg_demux->private_2_stream;
|
|
|
|
} else if (id >= 0xC0 && id <= 0xDF) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* audio */
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("we have an audio packet");
|
2003-05-22 10:41:49 +00:00
|
|
|
outstream = &mpeg_demux->audio_stream[id - 0xC0];
|
|
|
|
} else if (id >= 0xE0 && id <= 0xEF) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* video */
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("we have a video packet");
|
2003-05-22 10:41:49 +00:00
|
|
|
outstream = &mpeg_demux->video_stream[id - 0xE0];
|
|
|
|
} else {
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("we have a unkown packet");
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if we don't know what it is, bail */
|
2002-11-27 21:00:12 +00:00
|
|
|
if (outstream == NULL)
|
2001-12-22 23:26:48 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* create the pad and add it if we don't already have one. */
|
|
|
|
/* this should trigger the NEW_PAD signal, which should be caught by */
|
|
|
|
/* the app and used to attach to desired streams. */
|
2002-11-27 21:00:12 +00:00
|
|
|
if ((*outstream) == NULL) {
|
2001-12-22 23:26:48 +00:00
|
|
|
gchar *name = NULL;
|
|
|
|
|
|
|
|
/* we have to name the stream approriately */
|
2003-05-22 10:41:49 +00:00
|
|
|
if (id == 0xBD) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* private_stream_1 */
|
2003-05-22 10:41:49 +00:00
|
|
|
if (ps_id_code >= 0x80 && ps_id_code <= 0x87) {
|
|
|
|
/* Erase any DVD audio pads. */
|
|
|
|
gst_mpeg_demux_dvd_audio_clear (mpeg_demux, ps_id_code - 0x80);
|
|
|
|
|
|
|
|
name = g_strdup_printf ("private_stream_1_%d",ps_id_code - 0x80);
|
|
|
|
newtemp = GST_PAD_TEMPLATE_GET (private1_factory);
|
|
|
|
} else if (ps_id_code >= 0xA0 && ps_id_code <= 0xA7) {
|
|
|
|
/* Erase any DVD audio pads. */
|
|
|
|
gst_mpeg_demux_dvd_audio_clear (mpeg_demux, ps_id_code - 0xA0);
|
|
|
|
|
|
|
|
name = g_strdup_printf ("pcm_stream_%d", ps_id_code - 0xA0);
|
|
|
|
newtemp = GST_PAD_TEMPLATE_GET (pcm_factory);
|
|
|
|
} else if (ps_id_code >= 0x20 && ps_id_code <= 0x2F) {
|
|
|
|
name = g_strdup_printf ("subtitle_stream_%d",ps_id_code - 0x20);
|
|
|
|
newtemp = GST_PAD_TEMPLATE_GET (subtitle_factory);
|
|
|
|
} else {
|
|
|
|
name = g_strdup_printf ("unknown_stream_%d",ps_id_code);
|
|
|
|
}
|
|
|
|
} else if (id == 0xBF) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* private_stream_2 */
|
2003-05-22 10:41:49 +00:00
|
|
|
name = g_strdup ("private_stream_2");
|
|
|
|
newtemp = GST_PAD_TEMPLATE_GET (private2_factory);
|
|
|
|
} else if (id >= 0xC0 && id <= 0xDF) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* audio */
|
2003-05-22 10:41:49 +00:00
|
|
|
name = g_strdup_printf ("audio_%02d", id - 0xC0);
|
|
|
|
newtemp = GST_PAD_TEMPLATE_GET (audio_factory);
|
|
|
|
} else if (id >= 0xE0 && id <= 0xEF) {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* video */
|
2003-05-22 10:41:49 +00:00
|
|
|
name = g_strdup_printf ("video_%02d", id - 0xE0);
|
|
|
|
newtemp = GST_PAD_TEMPLATE_GET (video_mpeg2_factory);
|
|
|
|
} else {
|
2002-11-04 23:16:45 +00:00
|
|
|
/* unkown */
|
2003-05-22 10:41:49 +00:00
|
|
|
name = g_strdup_printf ("unknown");
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
2002-11-04 23:16:45 +00:00
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
if (newtemp) {
|
2003-02-02 20:05:59 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
*outstream = gst_mpeg_demux_new_stream ();
|
|
|
|
outpad = &((*outstream)->pad);
|
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
/* create the pad and add it to self */
|
2002-11-27 21:00:12 +00:00
|
|
|
*outpad = gst_pad_new_from_template (newtemp, name);
|
2003-05-14 21:54:41 +00:00
|
|
|
if (ps_id_code < 0xA0 || ps_id_code > 0xA7) {
|
|
|
|
caps = gst_pad_template_get_caps (newtemp);
|
|
|
|
gst_pad_try_set_caps (*outpad, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gst_mpeg_demux_lpcm_set_caps(*outpad,
|
|
|
|
mpeg_demux->lpcm_sample_info[ps_id_code
|
|
|
|
- 0xA0]);
|
|
|
|
}
|
2002-07-24 21:43:44 +00:00
|
|
|
|
2002-12-27 22:43:28 +00:00
|
|
|
gst_pad_set_formats_function (*outpad, gst_mpeg_demux_get_src_formats);
|
2002-12-26 22:45:10 +00:00
|
|
|
gst_pad_set_convert_function (*outpad, gst_mpeg_parse_convert_src);
|
2002-07-24 21:43:44 +00:00
|
|
|
gst_pad_set_event_mask_function (*outpad, gst_mpeg_parse_get_src_event_masks);
|
2002-12-26 22:45:10 +00:00
|
|
|
gst_pad_set_event_function (*outpad, gst_mpeg_demux_handle_src_event);
|
2002-07-24 21:43:44 +00:00
|
|
|
gst_pad_set_query_type_function (*outpad, gst_mpeg_parse_get_src_query_types);
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_pad_set_query_function (*outpad, gst_mpeg_parse_handle_src_query);
|
2002-07-24 21:43:44 +00:00
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
gst_element_add_pad(GST_ELEMENT(mpeg_demux), *outpad);
|
2002-12-26 22:45:10 +00:00
|
|
|
gst_pad_set_element_private (*outpad, *outstream);
|
2002-11-27 21:00:12 +00:00
|
|
|
|
2003-07-25 02:04:01 +00:00
|
|
|
if (mpeg_demux->index)
|
|
|
|
(*outstream)->index_id =
|
|
|
|
_demux_get_writer_id (mpeg_demux->index, *outpad);
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-11-04 23:16:45 +00:00
|
|
|
g_warning ("cannot create pad %s, no template for %02x", name, id);
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
if (name)
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
if (*outstream) {
|
|
|
|
gint64 timestamp;
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
outpad = &((*outstream)->pad);
|
2002-11-04 23:16:45 +00:00
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
/* attach pts, if any */
|
2002-11-04 23:16:45 +00:00
|
|
|
if (pts != -1) {
|
|
|
|
pts += mpeg_parse->adjust;
|
2002-11-27 21:00:12 +00:00
|
|
|
timestamp = MPEGTIME_TO_GSTTIME (pts);
|
|
|
|
|
2002-12-12 22:17:10 +00:00
|
|
|
if (mpeg_demux->index) {
|
|
|
|
gst_index_add_association (mpeg_demux->index,
|
|
|
|
(*outstream)->index_id, 0,
|
2002-11-27 21:00:12 +00:00
|
|
|
GST_FORMAT_BYTES, GST_BUFFER_OFFSET (buffer),
|
|
|
|
GST_FORMAT_TIME, timestamp,
|
|
|
|
0);
|
|
|
|
}
|
2002-11-04 23:16:45 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-11-27 21:00:12 +00:00
|
|
|
timestamp = GST_CLOCK_TIME_NONE;
|
2002-11-04 23:16:45 +00:00
|
|
|
}
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
/* create the buffer and send it off to the Other Side */
|
|
|
|
if (*outpad && GST_PAD_IS_USABLE(*outpad)) {
|
|
|
|
/* if this is part of the buffer, create a subbuffer */
|
2003-06-29 19:46:09 +00:00
|
|
|
GST_DEBUG ("creating subbuffer len %d", datalen);
|
2002-11-27 21:00:12 +00:00
|
|
|
|
|
|
|
outbuf = gst_buffer_create_sub (buffer, headerlen+4, datalen);
|
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
|
2003-05-24 10:17:50 +00:00
|
|
|
GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET (buffer) + headerlen + 4;
|
2002-11-27 21:00:12 +00:00
|
|
|
|
|
|
|
gst_pad_push(*outpad,outbuf);
|
|
|
|
}
|
2001-12-22 23:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-05-14 21:54:41 +00:00
|
|
|
/**
|
|
|
|
* Set the capabilities of the given pad based on the provided LPCM
|
|
|
|
* sample information.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_mpeg_demux_lpcm_set_caps (GstPad *pad, guint8 sample_info)
|
|
|
|
{
|
|
|
|
gint width, rate, channels;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
/* Determine the sample width. */
|
|
|
|
switch (sample_info & 0xC0) {
|
|
|
|
case 0x80:
|
|
|
|
width = 24;
|
|
|
|
break;
|
|
|
|
case 0x40:
|
|
|
|
width = 20;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
width = 16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the rate. */
|
|
|
|
if (sample_info & 0x10) {
|
|
|
|
rate = 96000;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rate = 48000;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the number of channels. */
|
|
|
|
channels = (sample_info & 0x7) + 1;
|
|
|
|
|
|
|
|
caps = GST_CAPS_NEW (
|
|
|
|
"mpeg_demux_pcm",
|
2003-07-06 20:49:50 +00:00
|
|
|
"audio/x-raw-int",
|
2003-05-14 21:54:41 +00:00
|
|
|
"endianness", GST_PROPS_INT (G_BIG_ENDIAN),
|
|
|
|
"signed", GST_PROPS_BOOLEAN (TRUE),
|
|
|
|
"width", GST_PROPS_INT (width),
|
|
|
|
"depth", GST_PROPS_INT (width),
|
|
|
|
"rate", GST_PROPS_INT (rate),
|
|
|
|
"channels", GST_PROPS_INT (channels)
|
|
|
|
);
|
|
|
|
gst_pad_try_set_caps (pad, caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Erase the DVD audio pad (if any) associated to the given channel.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_mpeg_demux_dvd_audio_clear (GstMPEGDemux *mpeg_demux, int channel)
|
|
|
|
{
|
|
|
|
GstMPEGStream **stream = NULL;
|
|
|
|
|
|
|
|
if (mpeg_demux->private_1_stream[channel] != NULL) {
|
|
|
|
stream = &mpeg_demux->private_1_stream[channel];
|
|
|
|
}
|
|
|
|
else if (mpeg_demux->pcm_stream[channel] != NULL) {
|
|
|
|
stream = &mpeg_demux->pcm_stream[channel];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_pad_unlink ((*stream)->pad, gst_pad_get_peer((*stream)->pad));
|
|
|
|
gst_element_remove_pad (GST_ELEMENT (mpeg_demux), (*stream)->pad);
|
|
|
|
|
|
|
|
g_free (*stream);
|
|
|
|
*stream = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-27 22:43:28 +00:00
|
|
|
const GstFormat*
|
|
|
|
gst_mpeg_demux_get_src_formats (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstFormat formats[] = {
|
|
|
|
GST_FORMAT_TIME, /* we prefer seeking on time */
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
return formats;
|
|
|
|
}
|
|
|
|
|
2002-12-26 22:45:10 +00:00
|
|
|
static gboolean
|
|
|
|
index_seek (GstPad *pad, GstEvent *event, gint64 *offset)
|
|
|
|
{
|
|
|
|
GstIndexEntry *entry;
|
|
|
|
GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (gst_pad_get_parent (pad));
|
|
|
|
GstMPEGStream *stream = gst_pad_get_element_private (pad);
|
|
|
|
|
|
|
|
entry = gst_index_get_assoc_entry (mpeg_demux->index, stream->index_id,
|
|
|
|
GST_INDEX_LOOKUP_BEFORE, 0,
|
|
|
|
GST_EVENT_SEEK_FORMAT (event),
|
|
|
|
GST_EVENT_SEEK_OFFSET (event));
|
2003-07-25 02:04:01 +00:00
|
|
|
if (!entry) {
|
|
|
|
GST_CAT_WARNING (GST_CAT_SEEK, "%s:%s index %s %" G_GINT64_FORMAT
|
|
|
|
" -> failed",
|
|
|
|
GST_DEBUG_PAD_NAME (pad),
|
|
|
|
gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick,
|
|
|
|
GST_EVENT_SEEK_OFFSET (event));
|
2002-12-26 22:45:10 +00:00
|
|
|
return FALSE;
|
2003-07-25 02:04:01 +00:00
|
|
|
}
|
2002-12-26 22:45:10 +00:00
|
|
|
|
|
|
|
if (gst_index_entry_assoc_map (entry, GST_FORMAT_BYTES, offset)) {
|
2003-07-25 02:04:01 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_SEEK, "%s:%s index %s %" G_GINT64_FORMAT
|
|
|
|
" -> %" G_GINT64_FORMAT " bytes",
|
|
|
|
GST_DEBUG_PAD_NAME (pad),
|
|
|
|
gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick,
|
|
|
|
GST_EVENT_SEEK_OFFSET (event),
|
|
|
|
*offset);
|
2002-12-26 22:45:10 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
normal_seek (GstPad *pad, GstEvent *event, gint64 *offset)
|
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
gint64 adjust;
|
|
|
|
GstFormat format;
|
|
|
|
GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
format = GST_EVENT_SEEK_FORMAT (event);
|
|
|
|
|
|
|
|
res = gst_pad_convert (pad, GST_FORMAT_BYTES, mpeg_demux->total_size_bound,
|
|
|
|
&format, &adjust);
|
|
|
|
|
2003-07-25 02:04:01 +00:00
|
|
|
if (res) {
|
2002-12-26 22:45:10 +00:00
|
|
|
*offset = MAX (GST_EVENT_SEEK_OFFSET (event) - adjust, 0);
|
|
|
|
|
2003-07-25 02:04:01 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_SEEK, "%s:%s guestimate %" G_GINT64_FORMAT
|
|
|
|
" %s -> %" G_GINT64_FORMAT
|
|
|
|
" (total_size_bound = %" G_GINT64_FORMAT ")",
|
|
|
|
GST_DEBUG_PAD_NAME (pad),
|
|
|
|
GST_EVENT_SEEK_OFFSET (event),
|
|
|
|
gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick,
|
|
|
|
*offset,
|
|
|
|
mpeg_demux->total_size_bound);
|
|
|
|
}
|
|
|
|
|
2002-12-26 22:45:10 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_mpeg_demux_handle_src_event (GstPad *pad, GstEvent *event)
|
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
|
|
|
guint64 desired_offset;
|
|
|
|
|
|
|
|
if (mpeg_demux->index)
|
|
|
|
res = index_seek (pad, event, &desired_offset);
|
|
|
|
if (!res)
|
|
|
|
res = normal_seek (pad, event, &desired_offset);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
GstEvent *new_event;
|
|
|
|
|
|
|
|
new_event = gst_event_new_seek (GST_EVENT_SEEK_TYPE (event), desired_offset);
|
|
|
|
gst_event_unref (event);
|
|
|
|
res = gst_mpeg_parse_handle_src_event (pad, new_event);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-02-03 20:10:04 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_mpeg_demux_change_state (GstElement *element)
|
|
|
|
{
|
2002-11-04 23:16:45 +00:00
|
|
|
/* GstMPEGDemux *mpeg_demux = GST_MPEG_DEMUX (element); */
|
2002-02-03 20:10:04 +00:00
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
}
|
|
|
|
|
2002-11-27 21:00:12 +00:00
|
|
|
static void
|
2002-12-12 22:17:10 +00:00
|
|
|
gst_mpeg_demux_set_index (GstElement *element, GstIndex *index)
|
2002-11-27 21:00:12 +00:00
|
|
|
{
|
|
|
|
GstMPEGDemux *mpeg_demux;
|
|
|
|
|
2002-12-12 22:17:10 +00:00
|
|
|
GST_ELEMENT_CLASS (parent_class)->set_index (element, index);
|
2002-11-27 21:00:12 +00:00
|
|
|
|
|
|
|
mpeg_demux = GST_MPEG_DEMUX (element);
|
|
|
|
|
2002-12-12 22:17:10 +00:00
|
|
|
mpeg_demux->index = index;
|
2002-11-27 21:00:12 +00:00
|
|
|
}
|
|
|
|
|
2002-12-12 22:17:10 +00:00
|
|
|
static GstIndex*
|
|
|
|
gst_mpeg_demux_get_index (GstElement *element)
|
2002-11-27 21:00:12 +00:00
|
|
|
{
|
|
|
|
GstMPEGDemux *mpeg_demux;
|
|
|
|
|
|
|
|
mpeg_demux = GST_MPEG_DEMUX (element);
|
|
|
|
|
2002-12-12 22:17:10 +00:00
|
|
|
return mpeg_demux->index;
|
2002-11-27 21:00:12 +00:00
|
|
|
}
|
|
|
|
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2001-12-22 23:26:48 +00:00
|
|
|
gboolean
|
|
|
|
gst_mpeg_demux_plugin_init (GModule *module, GstPlugin *plugin)
|
|
|
|
{
|
|
|
|
GstElementFactory *factory;
|
|
|
|
|
|
|
|
/* this filter needs the bytestream package */
|
2002-09-09 23:24:29 +00:00
|
|
|
if (!gst_library_load ("gstbytestream"))
|
2001-12-22 23:26:48 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* create an elementfactory for the mpeg_demux element */
|
2002-04-11 20:42:25 +00:00
|
|
|
factory = gst_element_factory_new ("mpegdemux", GST_TYPE_MPEG_DEMUX,
|
2002-09-09 23:24:29 +00:00
|
|
|
&mpeg_demux_details);
|
2001-12-22 23:26:48 +00:00
|
|
|
g_return_val_if_fail (factory != NULL, FALSE);
|
2002-05-31 08:24:31 +00:00
|
|
|
gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_PRIMARY);
|
2001-12-22 23:26:48 +00:00
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (sink_factory));
|
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (video_mpeg1_factory));
|
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (video_mpeg2_factory));
|
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (private1_factory));
|
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (private2_factory));
|
2003-03-02 09:48:48 +00:00
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (pcm_factory));
|
2002-04-11 20:42:25 +00:00
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (subtitle_factory));
|
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (audio_factory));
|
2001-12-22 23:26:48 +00:00
|
|
|
|
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|