2011-02-16 16:57:42 +00:00
|
|
|
/*
|
|
|
|
* tsdemux.c
|
|
|
|
* Copyright (C) 2009 Zaheer Abbas Merali
|
|
|
|
* 2010 Edward Hervey
|
2011-09-08 22:13:19 +00:00
|
|
|
* Copyright (C) 2011, Hewlett-Packard Development Company, L.P.
|
|
|
|
* Author: Youness Alaoui <youness.alaoui@collabora.co.uk>, Collabora Ltd.
|
|
|
|
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
|
|
|
|
* Author: Edward Hervey <bilboed@bilboed.com>, Collabora Ltd.
|
2011-02-16 16:57:42 +00:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Zaheer Abbas Merali <zaheerabbas at merali dot org>
|
|
|
|
* Edward Hervey <edward.hervey@collabora.co.uk>
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2011-02-16 16:57:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-02-22 11:33:56 +00:00
|
|
|
#include <glib.h>
|
2012-04-10 10:36:15 +00:00
|
|
|
#include <gst/tag/tag.h>
|
2013-06-14 05:28:29 +00:00
|
|
|
#include <gst/pbutils/pbutils.h>
|
2011-02-22 11:33:56 +00:00
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
#include "mpegtsbase.h"
|
|
|
|
#include "tsdemux.h"
|
|
|
|
#include "gstmpegdesc.h"
|
|
|
|
#include "gstmpegdefs.h"
|
|
|
|
#include "mpegtspacketizer.h"
|
2011-07-18 07:12:16 +00:00
|
|
|
#include "pesparse.h"
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-02-15 14:06:57 +00:00
|
|
|
/*
|
2011-11-16 11:46:04 +00:00
|
|
|
* tsdemux
|
|
|
|
*
|
|
|
|
* See TODO for explanations on improvements needed
|
|
|
|
*/
|
|
|
|
|
2013-04-11 11:08:57 +00:00
|
|
|
#define CONTINUITY_UNSET 255
|
|
|
|
#define MAX_CONTINUITY 15
|
|
|
|
|
2012-02-29 09:33:00 +00:00
|
|
|
/* Seeking/Scanning related variables */
|
|
|
|
|
2011-03-23 17:50:25 +00:00
|
|
|
/* seek to SEEK_TIMESTAMP_OFFSET before the desired offset and search then
|
|
|
|
* either accurately or for the next timestamp
|
|
|
|
*/
|
2012-03-01 17:05:17 +00:00
|
|
|
#define SEEK_TIMESTAMP_OFFSET (500 * GST_MSECOND)
|
2011-03-23 17:50:25 +00:00
|
|
|
|
2012-03-01 17:05:17 +00:00
|
|
|
#define SEGMENT_FORMAT "[format:%s, rate:%f, start:%" \
|
|
|
|
GST_TIME_FORMAT", stop:%"GST_TIME_FORMAT", time:%"GST_TIME_FORMAT \
|
2012-04-19 12:20:52 +00:00
|
|
|
", base:%"GST_TIME_FORMAT", position:%"GST_TIME_FORMAT \
|
2012-03-01 17:05:17 +00:00
|
|
|
", duration:%"GST_TIME_FORMAT"]"
|
|
|
|
|
|
|
|
#define SEGMENT_ARGS(a) gst_format_get_name((a).format), (a).rate, \
|
|
|
|
GST_TIME_ARGS((a).start), GST_TIME_ARGS((a).stop), \
|
2012-04-19 12:20:52 +00:00
|
|
|
GST_TIME_ARGS((a).time), GST_TIME_ARGS((a).base), \
|
|
|
|
GST_TIME_ARGS((a).position), GST_TIME_ARGS((a).duration)
|
2012-02-29 09:33:00 +00:00
|
|
|
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (ts_demux_debug);
|
|
|
|
#define GST_CAT_DEFAULT ts_demux_debug
|
|
|
|
|
2012-01-10 10:37:13 +00:00
|
|
|
#define ABSDIFF(a,b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a)))
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
static GQuark QUARK_TSDEMUX;
|
|
|
|
static GQuark QUARK_PID;
|
|
|
|
static GQuark QUARK_PCR;
|
|
|
|
static GQuark QUARK_OPCR;
|
|
|
|
static GQuark QUARK_PTS;
|
|
|
|
static GQuark QUARK_DTS;
|
|
|
|
static GQuark QUARK_OFFSET;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PENDING_PACKET_EMPTY = 0, /* No pending packet/buffer
|
|
|
|
* Push incoming buffers to the array */
|
|
|
|
PENDING_PACKET_HEADER, /* PES header needs to be parsed
|
|
|
|
* Push incoming buffers to the array */
|
|
|
|
PENDING_PACKET_BUFFER, /* Currently filling up output buffer
|
|
|
|
* Push incoming buffers to the bufferlist */
|
|
|
|
PENDING_PACKET_DISCONT /* Discontinuity in incoming packets
|
|
|
|
* Drop all incoming buffers */
|
|
|
|
} PendingPacketState;
|
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
/* Pending buffer */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/* The fully reconstructed buffer */
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
|
|
|
/* Raw PTS/DTS (in 90kHz units) */
|
|
|
|
guint64 pts, dts;
|
|
|
|
} PendingBuffer;
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
typedef struct _TSDemuxStream TSDemuxStream;
|
|
|
|
|
|
|
|
struct _TSDemuxStream
|
|
|
|
{
|
|
|
|
MpegTSBaseStream stream;
|
|
|
|
|
|
|
|
GstPad *pad;
|
2013-07-29 06:10:07 +00:00
|
|
|
|
2012-02-29 14:14:15 +00:00
|
|
|
/* Whether the pad was added or not */
|
|
|
|
gboolean active;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
/* TRUE if we are waiting for a valid timestamp */
|
|
|
|
gboolean pending_ts;
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
/* the return of the latest push */
|
|
|
|
GstFlowReturn flow_return;
|
|
|
|
|
|
|
|
/* Output data */
|
|
|
|
PendingPacketState state;
|
2012-05-21 15:53:37 +00:00
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
/* Data being reconstructed (allocated) */
|
2012-05-21 15:53:37 +00:00
|
|
|
guint8 *data;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
/* Size of data being reconstructed (if known, else 0) */
|
2012-03-05 08:38:57 +00:00
|
|
|
guint expected_size;
|
2012-05-21 15:53:37 +00:00
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
/* Amount of bytes in current ->data */
|
2012-03-05 08:38:57 +00:00
|
|
|
guint current_size;
|
2013-07-29 06:10:07 +00:00
|
|
|
/* Size of ->data */
|
2012-05-21 15:53:37 +00:00
|
|
|
guint allocated_size;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
/* Current PTS/DTS for this stream (in running time) */
|
2011-02-16 16:57:42 +00:00
|
|
|
GstClockTime pts;
|
2012-01-10 10:37:13 +00:00
|
|
|
GstClockTime dts;
|
2012-03-01 17:05:17 +00:00
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
/* Current PTS/DTS for this stream (in 90kHz unit) */
|
|
|
|
guint64 raw_pts, raw_dts;
|
|
|
|
|
2012-03-01 17:05:17 +00:00
|
|
|
/* Whether this stream needs to send a newsegment */
|
|
|
|
gboolean need_newsegment;
|
2012-04-10 10:36:15 +00:00
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
/* The value to use when calculating the newsegment */
|
|
|
|
GstClockTime first_dts;
|
|
|
|
|
2012-04-10 10:36:15 +00:00
|
|
|
GstTagList *taglist;
|
2013-04-11 11:08:57 +00:00
|
|
|
|
|
|
|
gint continuity_counter;
|
2013-07-29 06:10:07 +00:00
|
|
|
|
|
|
|
/* List of pending buffers */
|
|
|
|
GList *pending;
|
2014-03-03 12:07:47 +00:00
|
|
|
|
|
|
|
/* if != 0, output only PES from that substream */
|
|
|
|
guint8 target_pes_substream;
|
2011-02-16 16:57:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define VIDEO_CAPS \
|
|
|
|
GST_STATIC_CAPS (\
|
|
|
|
"video/mpeg, " \
|
|
|
|
"mpegversion = (int) { 1, 2, 4 }, " \
|
|
|
|
"systemstream = (boolean) FALSE; " \
|
2011-04-24 23:42:03 +00:00
|
|
|
"video/x-h264,stream-format=(string)byte-stream," \
|
|
|
|
"alignment=(string)nal;" \
|
2011-02-16 16:57:42 +00:00
|
|
|
"video/x-dirac;" \
|
|
|
|
"video/x-wmv," \
|
|
|
|
"wmvversion = (int) 3, " \
|
2012-04-19 12:20:52 +00:00
|
|
|
"format = (string) WVC1" \
|
2011-02-16 16:57:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
#define AUDIO_CAPS \
|
|
|
|
GST_STATIC_CAPS ( \
|
|
|
|
"audio/mpeg, " \
|
2012-02-02 11:37:55 +00:00
|
|
|
"mpegversion = (int) 1;" \
|
2012-02-21 14:12:53 +00:00
|
|
|
"audio/mpeg, " \
|
|
|
|
"mpegversion = (int) 2, " \
|
|
|
|
"stream-format = (string) adts; " \
|
2012-02-02 11:37:55 +00:00
|
|
|
"audio/mpeg, " \
|
|
|
|
"mpegversion = (int) 4, " \
|
2012-06-28 15:40:16 +00:00
|
|
|
"stream-format = (string) loas; " \
|
2011-02-16 16:57:42 +00:00
|
|
|
"audio/x-lpcm, " \
|
|
|
|
"width = (int) { 16, 20, 24 }, " \
|
|
|
|
"rate = (int) { 48000, 96000 }, " \
|
|
|
|
"channels = (int) [ 1, 8 ], " \
|
|
|
|
"dynamic_range = (int) [ 0, 255 ], " \
|
|
|
|
"emphasis = (boolean) { FALSE, TRUE }, " \
|
|
|
|
"mute = (boolean) { FALSE, TRUE }; " \
|
|
|
|
"audio/x-ac3; audio/x-eac3;" \
|
|
|
|
"audio/x-dts;" \
|
|
|
|
"audio/x-private-ts-lpcm" \
|
|
|
|
)
|
|
|
|
|
|
|
|
/* Can also use the subpicture pads for text subtitles? */
|
|
|
|
#define SUBPICTURE_CAPS \
|
2012-08-20 22:37:00 +00:00
|
|
|
GST_STATIC_CAPS ("subpicture/x-pgs; subpicture/x-dvd")
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate video_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("video_%04x", GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
VIDEO_CAPS);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate audio_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("audio_%04x",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
AUDIO_CAPS);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate subpicture_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("subpicture_%04x",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
SUBPICTURE_CAPS);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate private_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("private_%04x",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_SOMETIMES,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
PROP_PROGRAM_NUMBER,
|
|
|
|
PROP_EMIT_STATS,
|
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Pad functions */
|
|
|
|
|
|
|
|
|
|
|
|
/* mpegtsbase methods */
|
|
|
|
static void
|
|
|
|
gst_ts_demux_program_started (MpegTSBase * base, MpegTSBaseProgram * program);
|
2012-10-12 13:26:20 +00:00
|
|
|
static void
|
|
|
|
gst_ts_demux_program_stopped (MpegTSBase * base, MpegTSBaseProgram * program);
|
2011-02-22 11:33:56 +00:00
|
|
|
static void gst_ts_demux_reset (MpegTSBase * base);
|
2011-02-16 16:57:42 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_ts_demux_push (MpegTSBase * base, MpegTSPacketizerPacket * packet,
|
2013-07-03 11:57:38 +00:00
|
|
|
GstMpegTsSection * section);
|
2013-05-24 08:59:59 +00:00
|
|
|
static void gst_ts_demux_flush (MpegTSBase * base, gboolean hard);
|
2011-02-16 16:57:42 +00:00
|
|
|
static void
|
|
|
|
gst_ts_demux_stream_added (MpegTSBase * base, MpegTSBaseStream * stream,
|
|
|
|
MpegTSBaseProgram * program);
|
|
|
|
static void
|
|
|
|
gst_ts_demux_stream_removed (MpegTSBase * base, MpegTSBaseStream * stream);
|
2012-02-29 09:33:00 +00:00
|
|
|
static GstFlowReturn gst_ts_demux_do_seek (MpegTSBase * base, GstEvent * event);
|
2011-02-16 16:57:42 +00:00
|
|
|
static void gst_ts_demux_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_ts_demux_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2011-02-22 11:33:56 +00:00
|
|
|
static void gst_ts_demux_flush_streams (GstTSDemux * tsdemux);
|
2011-08-01 08:54:16 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_ts_demux_push_pending_data (GstTSDemux * demux, TSDemuxStream * stream);
|
2012-03-30 17:19:12 +00:00
|
|
|
static void gst_ts_demux_stream_flush (TSDemuxStream * stream);
|
2011-08-01 08:54:16 +00:00
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
static gboolean push_event (MpegTSBase * base, GstEvent * event);
|
|
|
|
|
|
|
|
static void
|
2012-04-19 12:20:52 +00:00
|
|
|
_extra_init (void)
|
2011-02-16 16:57:42 +00:00
|
|
|
{
|
|
|
|
QUARK_TSDEMUX = g_quark_from_string ("tsdemux");
|
|
|
|
QUARK_PID = g_quark_from_string ("pid");
|
|
|
|
QUARK_PCR = g_quark_from_string ("pcr");
|
|
|
|
QUARK_OPCR = g_quark_from_string ("opcr");
|
|
|
|
QUARK_PTS = g_quark_from_string ("pts");
|
|
|
|
QUARK_DTS = g_quark_from_string ("dts");
|
|
|
|
QUARK_OFFSET = g_quark_from_string ("offset");
|
|
|
|
}
|
|
|
|
|
2012-04-19 12:20:52 +00:00
|
|
|
#define gst_ts_demux_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstTSDemux, gst_ts_demux, GST_TYPE_MPEGTS_BASE,
|
|
|
|
_extra_init ());
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ts_demux_class_init (GstTSDemuxClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2012-04-19 12:20:52 +00:00
|
|
|
GstElementClass *element_class;
|
2011-02-16 16:57:42 +00:00
|
|
|
MpegTSBaseClass *ts_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
gobject_class->set_property = gst_ts_demux_set_property;
|
|
|
|
gobject_class->get_property = gst_ts_demux_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PROGRAM_NUMBER,
|
|
|
|
g_param_spec_int ("program-number", "Program number",
|
|
|
|
"Program Number to demux for (-1 to ignore)", -1, G_MAXINT,
|
|
|
|
-1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_EMIT_STATS,
|
|
|
|
g_param_spec_boolean ("emit-stats", "Emit statistics",
|
|
|
|
"Emit messages for every pcr/opcr/pts/dts", FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-04-19 12:20:52 +00:00
|
|
|
element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&video_template));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&audio_template));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&subpicture_template));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&private_template));
|
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class,
|
2012-04-19 12:20:52 +00:00
|
|
|
"MPEG transport stream demuxer",
|
|
|
|
"Codec/Demuxer",
|
|
|
|
"Demuxes MPEG2 transport streams",
|
|
|
|
"Zaheer Abbas Merali <zaheerabbas at merali dot org>\n"
|
|
|
|
"Edward Hervey <edward.hervey@collabora.co.uk>");
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
ts_class = GST_MPEGTS_BASE_CLASS (klass);
|
2011-02-22 11:33:56 +00:00
|
|
|
ts_class->reset = GST_DEBUG_FUNCPTR (gst_ts_demux_reset);
|
2011-02-16 16:57:42 +00:00
|
|
|
ts_class->push = GST_DEBUG_FUNCPTR (gst_ts_demux_push);
|
|
|
|
ts_class->push_event = GST_DEBUG_FUNCPTR (push_event);
|
|
|
|
ts_class->program_started = GST_DEBUG_FUNCPTR (gst_ts_demux_program_started);
|
2012-10-12 13:26:20 +00:00
|
|
|
ts_class->program_stopped = GST_DEBUG_FUNCPTR (gst_ts_demux_program_stopped);
|
2011-02-16 16:57:42 +00:00
|
|
|
ts_class->stream_added = gst_ts_demux_stream_added;
|
|
|
|
ts_class->stream_removed = gst_ts_demux_stream_removed;
|
2011-02-22 11:33:56 +00:00
|
|
|
ts_class->seek = GST_DEBUG_FUNCPTR (gst_ts_demux_do_seek);
|
2011-08-26 22:44:08 +00:00
|
|
|
ts_class->flush = GST_DEBUG_FUNCPTR (gst_ts_demux_flush);
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 11:33:56 +00:00
|
|
|
static void
|
|
|
|
gst_ts_demux_reset (MpegTSBase * base)
|
|
|
|
{
|
|
|
|
GstTSDemux *demux = (GstTSDemux *) base;
|
2011-07-16 11:47:45 +00:00
|
|
|
|
2012-03-01 17:05:17 +00:00
|
|
|
demux->calculate_update_segment = FALSE;
|
2012-02-24 16:53:52 +00:00
|
|
|
|
2013-07-24 13:50:14 +00:00
|
|
|
demux->rate = 1.0;
|
2012-11-13 21:40:25 +00:00
|
|
|
gst_segment_init (&demux->segment, GST_FORMAT_UNDEFINED);
|
2012-03-01 17:05:17 +00:00
|
|
|
if (demux->segment_event) {
|
|
|
|
gst_event_unref (demux->segment_event);
|
|
|
|
demux->segment_event = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (demux->update_segment) {
|
|
|
|
gst_event_unref (demux->update_segment);
|
|
|
|
demux->update_segment = NULL;
|
|
|
|
}
|
2013-07-23 08:24:22 +00:00
|
|
|
|
2014-02-25 01:43:56 +00:00
|
|
|
if (demux->global_tags) {
|
|
|
|
gst_tag_list_unref (demux->global_tags);
|
|
|
|
demux->global_tags = NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-23 08:24:22 +00:00
|
|
|
demux->have_group_id = FALSE;
|
|
|
|
demux->group_id = G_MAXUINT;
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
|
2012-02-24 16:52:33 +00:00
|
|
|
static void
|
2012-04-19 12:20:52 +00:00
|
|
|
gst_ts_demux_init (GstTSDemux * demux)
|
2012-02-24 16:52:33 +00:00
|
|
|
{
|
2013-07-06 12:50:52 +00:00
|
|
|
MpegTSBase *base = (MpegTSBase *) demux;
|
2012-02-24 16:52:33 +00:00
|
|
|
|
2013-07-06 12:50:52 +00:00
|
|
|
base->stream_size = sizeof (TSDemuxStream);
|
|
|
|
base->parse_private_sections = TRUE;
|
2013-07-07 09:42:50 +00:00
|
|
|
/* We are not interested in sections (all handled by mpegtsbase) */
|
|
|
|
base->push_section = FALSE;
|
|
|
|
|
2013-03-09 23:07:40 +00:00
|
|
|
demux->requested_program_number = -1;
|
2013-03-06 11:15:47 +00:00
|
|
|
demux->program_number = -1;
|
2013-07-06 12:50:52 +00:00
|
|
|
gst_ts_demux_reset (base);
|
2012-02-24 16:52:33 +00:00
|
|
|
}
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ts_demux_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstTSDemux *demux = GST_TS_DEMUX (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PROGRAM_NUMBER:
|
|
|
|
/* FIXME: do something if program is switched as opposed to set at
|
|
|
|
* beginning */
|
2013-03-09 23:07:40 +00:00
|
|
|
demux->requested_program_number = g_value_get_int (value);
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
|
|
|
case PROP_EMIT_STATS:
|
|
|
|
demux->emit_statistics = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ts_demux_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstTSDemux *demux = GST_TS_DEMUX (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PROGRAM_NUMBER:
|
2013-03-09 23:07:40 +00:00
|
|
|
g_value_set_int (value, demux->requested_program_number);
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
|
|
|
case PROP_EMIT_STATS:
|
|
|
|
g_value_set_boolean (value, demux->emit_statistics);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-04-19 12:20:52 +00:00
|
|
|
gst_ts_demux_srcpad_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
2011-02-16 16:57:42 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
2011-02-22 11:33:56 +00:00
|
|
|
GstFormat format;
|
2011-02-16 16:57:42 +00:00
|
|
|
GstTSDemux *demux;
|
2011-08-23 22:40:25 +00:00
|
|
|
MpegTSBase *base;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-04-19 12:20:52 +00:00
|
|
|
demux = GST_TS_DEMUX (parent);
|
2011-08-23 22:40:25 +00:00
|
|
|
base = GST_MPEGTS_BASE (demux);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_DURATION:
|
2012-02-29 09:33:00 +00:00
|
|
|
{
|
2011-02-22 11:33:56 +00:00
|
|
|
GST_DEBUG ("query duration");
|
2011-02-16 16:57:42 +00:00
|
|
|
gst_query_parse_duration (query, &format, NULL);
|
2011-02-22 11:33:56 +00:00
|
|
|
if (format == GST_FORMAT_TIME) {
|
2012-03-01 17:05:17 +00:00
|
|
|
if (!gst_pad_peer_query (base->sinkpad, query)) {
|
|
|
|
gint64 val;
|
|
|
|
|
|
|
|
format = GST_FORMAT_BYTES;
|
2012-04-19 12:20:52 +00:00
|
|
|
if (!gst_pad_peer_query_duration (base->sinkpad, format, &val))
|
2012-03-01 17:05:17 +00:00
|
|
|
res = FALSE;
|
|
|
|
else {
|
|
|
|
GstClockTime dur =
|
2012-06-26 16:59:32 +00:00
|
|
|
mpegts_packetizer_offset_to_ts (base->packetizer, val,
|
|
|
|
demux->program->pcr_pid);
|
2012-03-01 17:05:17 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (dur))
|
|
|
|
gst_query_set_duration (query, GST_FORMAT_TIME, dur);
|
|
|
|
else
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2011-02-22 11:33:56 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (demux, "only query duration on TIME is supported");
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2012-02-29 09:33:00 +00:00
|
|
|
}
|
2011-11-08 19:12:50 +00:00
|
|
|
case GST_QUERY_LATENCY:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("query latency");
|
|
|
|
res = gst_pad_peer_query (base->sinkpad, query);
|
|
|
|
if (res && base->upstream_live) {
|
|
|
|
GstClockTime min_lat, max_lat;
|
|
|
|
gboolean live;
|
|
|
|
|
|
|
|
/* According to H.222.0
|
|
|
|
Annex D.0.3 (System Time Clock recovery in the decoder)
|
|
|
|
and D.0.2 (Audio and video presentation synchronization)
|
|
|
|
|
|
|
|
We can end up with an interval of up to 700ms between valid
|
|
|
|
PCR/SCR. We therefore allow a latency of 700ms for that.
|
|
|
|
*/
|
|
|
|
gst_query_parse_latency (query, &live, &min_lat, &max_lat);
|
|
|
|
if (min_lat != -1)
|
|
|
|
min_lat += 700 * GST_MSECOND;
|
|
|
|
if (max_lat != -1)
|
|
|
|
max_lat += 700 * GST_MSECOND;
|
|
|
|
gst_query_set_latency (query, live, min_lat, max_lat);
|
|
|
|
}
|
|
|
|
break;
|
2012-02-29 09:33:00 +00:00
|
|
|
}
|
2011-02-22 11:33:56 +00:00
|
|
|
case GST_QUERY_SEEKING:
|
2012-02-29 09:33:00 +00:00
|
|
|
{
|
2011-02-22 11:33:56 +00:00
|
|
|
GST_DEBUG ("query seeking");
|
|
|
|
gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
|
|
|
|
if (format == GST_FORMAT_TIME) {
|
2011-08-23 07:40:16 +00:00
|
|
|
gboolean seekable = FALSE;
|
|
|
|
|
2011-08-23 22:40:25 +00:00
|
|
|
if (gst_pad_peer_query (base->sinkpad, query))
|
2011-08-23 07:40:16 +00:00
|
|
|
gst_query_parse_seeking (query, NULL, &seekable, NULL, NULL);
|
|
|
|
|
|
|
|
/* If upstream is not seekable in TIME format we use
|
|
|
|
* our own values here */
|
|
|
|
if (!seekable)
|
2013-05-24 16:18:35 +00:00
|
|
|
gst_query_set_seeking (query, GST_FORMAT_TIME, TRUE, 0,
|
2011-08-23 07:40:16 +00:00
|
|
|
demux->segment.duration);
|
2011-02-22 11:33:56 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (demux, "only TIME is supported for query seeking");
|
|
|
|
res = FALSE;
|
|
|
|
}
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
2012-02-29 09:33:00 +00:00
|
|
|
}
|
2013-07-29 09:01:09 +00:00
|
|
|
case GST_QUERY_SEGMENT:{
|
|
|
|
GstFormat format;
|
|
|
|
gint64 start, stop;
|
|
|
|
|
|
|
|
format = demux->segment.format;
|
|
|
|
|
|
|
|
start =
|
|
|
|
gst_segment_to_stream_time (&demux->segment, format,
|
|
|
|
demux->segment.start);
|
|
|
|
if ((stop = demux->segment.stop) == -1)
|
|
|
|
stop = demux->segment.duration;
|
|
|
|
else
|
|
|
|
stop = gst_segment_to_stream_time (&demux->segment, format, stop);
|
|
|
|
|
|
|
|
gst_query_set_segment (query, demux->segment.rate, format, start, stop);
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-16 16:57:42 +00:00
|
|
|
default:
|
2012-04-19 12:20:52 +00:00
|
|
|
res = gst_pad_query_default (pad, parent, query);
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
2011-02-22 11:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-02-29 09:33:00 +00:00
|
|
|
gst_ts_demux_do_seek (MpegTSBase * base, GstEvent * event)
|
2011-02-22 11:33:56 +00:00
|
|
|
{
|
|
|
|
GstTSDemux *demux = (GstTSDemux *) base;
|
|
|
|
GstFlowReturn res = GST_FLOW_ERROR;
|
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType start_type, stop_type;
|
|
|
|
gint64 start, stop;
|
|
|
|
GstSegment seeksegment;
|
|
|
|
gboolean update;
|
2012-03-01 17:05:17 +00:00
|
|
|
guint64 start_offset;
|
2011-02-22 11:33:56 +00:00
|
|
|
|
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
|
|
|
|
&stop_type, &stop);
|
|
|
|
|
|
|
|
GST_DEBUG ("seek event, rate: %f start: %" GST_TIME_FORMAT
|
|
|
|
" stop: %" GST_TIME_FORMAT, rate, GST_TIME_ARGS (start),
|
|
|
|
GST_TIME_ARGS (stop));
|
|
|
|
|
2013-08-21 12:44:38 +00:00
|
|
|
if (rate <= 0.0) {
|
|
|
|
GST_WARNING ("Negative rate not supported");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2014-01-30 19:28:04 +00:00
|
|
|
if (flags & (GST_SEEK_FLAG_SEGMENT)) {
|
2011-02-22 11:33:56 +00:00
|
|
|
GST_WARNING ("seek flags 0x%x are not supported", (int) flags);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy segment, we need this because we still need the old
|
|
|
|
* segment when we close the current segment. */
|
|
|
|
memcpy (&seeksegment, &demux->segment, sizeof (GstSegment));
|
2013-05-28 14:14:42 +00:00
|
|
|
|
2011-02-22 11:33:56 +00:00
|
|
|
/* configure the segment with the seek variables */
|
|
|
|
GST_DEBUG_OBJECT (demux, "configuring seek");
|
2012-03-01 17:05:17 +00:00
|
|
|
GST_DEBUG ("seeksegment before set_seek " SEGMENT_FORMAT,
|
|
|
|
SEGMENT_ARGS (seeksegment));
|
|
|
|
|
2012-04-19 12:20:52 +00:00
|
|
|
gst_segment_do_seek (&seeksegment, rate, format, flags, start_type, start,
|
2011-02-22 11:33:56 +00:00
|
|
|
stop_type, stop, &update);
|
2012-03-01 17:05:17 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("seeksegment after set_seek " SEGMENT_FORMAT,
|
|
|
|
SEGMENT_ARGS (seeksegment));
|
|
|
|
|
|
|
|
/* Convert start/stop to offset */
|
|
|
|
start_offset =
|
|
|
|
mpegts_packetizer_ts_to_offset (base->packetizer, MAX (0,
|
2012-06-26 16:59:32 +00:00
|
|
|
start - SEEK_TIMESTAMP_OFFSET), demux->program->pcr_pid);
|
2012-03-01 17:05:17 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (start_offset == -1)) {
|
|
|
|
GST_WARNING ("Couldn't convert start position to an offset");
|
2011-02-16 16:57:42 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2011-02-22 11:33:56 +00:00
|
|
|
|
2013-07-24 13:50:14 +00:00
|
|
|
/* record offset and rate */
|
2012-03-01 17:05:17 +00:00
|
|
|
base->seek_offset = start_offset;
|
2013-07-24 13:50:14 +00:00
|
|
|
demux->rate = rate;
|
2012-03-01 17:05:17 +00:00
|
|
|
res = GST_FLOW_OK;
|
|
|
|
|
2013-05-28 14:14:42 +00:00
|
|
|
/* Drop segment info, it needs to be recreated after the actual seek */
|
|
|
|
gst_segment_init (&demux->segment, GST_FORMAT_UNDEFINED);
|
|
|
|
if (demux->segment_event) {
|
|
|
|
gst_event_unref (demux->segment_event);
|
|
|
|
demux->segment_event = NULL;
|
2011-02-22 11:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return res;
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 11:33:56 +00:00
|
|
|
static gboolean
|
2012-04-19 12:20:52 +00:00
|
|
|
gst_ts_demux_srcpad_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2011-02-22 11:33:56 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
2012-04-19 12:20:52 +00:00
|
|
|
GstTSDemux *demux = GST_TS_DEMUX (parent);
|
2011-02-22 11:33:56 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "Got event %s",
|
|
|
|
gst_event_type_get_name (GST_EVENT_TYPE (event)));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
res = mpegts_base_handle_seek_event ((MpegTSBase *) demux, pad, event);
|
2011-08-26 22:44:08 +00:00
|
|
|
if (!res)
|
2011-02-22 11:33:56 +00:00
|
|
|
GST_WARNING ("seeking failed");
|
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
|
|
|
default:
|
2012-04-19 12:20:52 +00:00
|
|
|
res = gst_pad_event_default (pad, parent, event);
|
2011-02-22 11:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2014-02-25 01:43:56 +00:00
|
|
|
static void
|
|
|
|
clean_global_taglist (GstTagList * taglist)
|
|
|
|
{
|
|
|
|
gst_tag_list_remove_tag (taglist, GST_TAG_CONTAINER_FORMAT);
|
|
|
|
gst_tag_list_remove_tag (taglist, GST_TAG_CODEC);
|
|
|
|
}
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
static gboolean
|
|
|
|
push_event (MpegTSBase * base, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstTSDemux *demux = (GstTSDemux *) base;
|
2011-07-19 07:34:37 +00:00
|
|
|
GList *tmp;
|
2014-02-25 01:43:56 +00:00
|
|
|
gboolean early_ret = FALSE;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2013-03-30 12:39:49 +00:00
|
|
|
if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
|
|
|
|
GST_DEBUG_OBJECT (base, "Ignoring segment event (recreated later)");
|
|
|
|
gst_event_unref (event);
|
|
|
|
return TRUE;
|
2014-02-25 01:43:56 +00:00
|
|
|
|
|
|
|
} else if (GST_EVENT_TYPE (event) == GST_EVENT_TAG) {
|
|
|
|
/* In case we receive tags before data, store them to send later
|
|
|
|
* If we already have the program, send it right away */
|
|
|
|
GstTagList *taglist;
|
|
|
|
|
|
|
|
gst_event_parse_tag (event, &taglist);
|
|
|
|
|
|
|
|
if (demux->global_tags == NULL) {
|
|
|
|
demux->global_tags = gst_tag_list_copy (taglist);
|
|
|
|
|
|
|
|
/* Tags that are stream specific for the container should be considered
|
|
|
|
* global for the container streams */
|
|
|
|
if (gst_tag_list_get_scope (taglist) == GST_TAG_SCOPE_STREAM) {
|
|
|
|
gst_tag_list_set_scope (demux->global_tags, GST_TAG_SCOPE_GLOBAL);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
demux->global_tags = gst_tag_list_make_writable (demux->global_tags);
|
|
|
|
gst_tag_list_insert (demux->global_tags, taglist, GST_TAG_MERGE_REPLACE);
|
|
|
|
}
|
|
|
|
clean_global_taglist (demux->global_tags);
|
|
|
|
|
|
|
|
/* tags are stored to be used after if there are no streams yet,
|
|
|
|
* so we should never reject */
|
|
|
|
early_ret = TRUE;
|
2013-03-30 12:39:49 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 11:59:37 +00:00
|
|
|
if (G_UNLIKELY (demux->program == NULL)) {
|
|
|
|
gst_event_unref (event);
|
2014-02-25 01:43:56 +00:00
|
|
|
return early_ret;
|
2012-04-19 11:59:37 +00:00
|
|
|
}
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2011-07-19 07:34:37 +00:00
|
|
|
for (tmp = demux->program->stream_list; tmp; tmp = tmp->next) {
|
|
|
|
TSDemuxStream *stream = (TSDemuxStream *) tmp->data;
|
|
|
|
if (stream->pad) {
|
2013-07-29 06:20:10 +00:00
|
|
|
/* If we are pushing out EOS, flush out pending data first */
|
|
|
|
if (GST_EVENT_TYPE (event) == GST_EVENT_EOS && stream->active &&
|
|
|
|
gst_pad_is_active (stream->pad))
|
|
|
|
gst_ts_demux_push_pending_data (demux, stream);
|
|
|
|
|
2011-07-19 07:34:37 +00:00
|
|
|
gst_event_ref (event);
|
|
|
|
gst_pad_push_event (stream->pad, event);
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 11:59:37 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
tsdemux_combine_flows (GstTSDemux * demux, TSDemuxStream * stream,
|
|
|
|
GstFlowReturn ret)
|
|
|
|
{
|
2011-07-19 07:34:37 +00:00
|
|
|
GList *tmp;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
/* Store the value */
|
|
|
|
stream->flow_return = ret;
|
|
|
|
|
|
|
|
/* any other error that is not-linked can be returned right away */
|
|
|
|
if (ret != GST_FLOW_NOT_LINKED)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Only return NOT_LINKED if all other pads returned NOT_LINKED */
|
2011-07-19 07:34:37 +00:00
|
|
|
for (tmp = demux->program->stream_list; tmp; tmp = tmp->next) {
|
|
|
|
stream = (TSDemuxStream *) tmp->data;
|
|
|
|
if (stream->pad) {
|
|
|
|
ret = stream->flow_return;
|
|
|
|
/* some other return value (must be SUCCESS but we can return
|
|
|
|
* other values as well) */
|
|
|
|
if (ret != GST_FLOW_NOT_LINKED)
|
|
|
|
goto done;
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
/* if we get here, all other pads were unlinked and we return
|
|
|
|
* NOT_LINKED then */
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-11 08:29:20 +00:00
|
|
|
static inline void
|
|
|
|
add_iso639_language_to_tags (TSDemuxStream * stream, gchar * lang_code)
|
|
|
|
{
|
|
|
|
const gchar *lc;
|
|
|
|
|
|
|
|
GST_LOG ("Add language code for stream: '%s'", lang_code);
|
|
|
|
|
|
|
|
if (!stream->taglist)
|
|
|
|
stream->taglist = gst_tag_list_new_empty ();
|
|
|
|
|
|
|
|
/* descriptor contains ISO 639-2 code, we want the ISO 639-1 code */
|
|
|
|
lc = gst_tag_get_language_code (lang_code);
|
|
|
|
|
|
|
|
/* Only set tag if we have a valid one */
|
|
|
|
if (lc || (lang_code[0] && lang_code[1]))
|
|
|
|
gst_tag_list_add (stream->taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_LANGUAGE_CODE, (lc) ? lc : lang_code, NULL);
|
|
|
|
}
|
|
|
|
|
2012-04-10 10:36:15 +00:00
|
|
|
static void
|
|
|
|
gst_ts_demux_create_tags (TSDemuxStream * stream)
|
|
|
|
{
|
2013-06-23 06:43:23 +00:00
|
|
|
MpegTSBaseStream *bstream = (MpegTSBaseStream *) stream;
|
2013-10-05 12:45:32 +00:00
|
|
|
const GstMpegTsDescriptor *desc = NULL;
|
2013-10-11 08:29:20 +00:00
|
|
|
int i, nb;
|
2012-04-10 10:36:15 +00:00
|
|
|
|
2013-06-23 06:43:23 +00:00
|
|
|
desc =
|
|
|
|
mpegts_get_descriptor_from_stream (bstream,
|
|
|
|
GST_MTS_DESC_ISO_639_LANGUAGE);
|
2013-10-11 08:29:20 +00:00
|
|
|
if (desc) {
|
|
|
|
gchar lang_code[4];
|
2012-07-26 18:38:28 +00:00
|
|
|
|
2013-10-11 08:29:20 +00:00
|
|
|
nb = gst_mpegts_descriptor_parse_iso_639_language_nb (desc);
|
|
|
|
|
|
|
|
GST_DEBUG ("Found ISO 639 descriptor (%d entries)", nb);
|
|
|
|
|
|
|
|
for (i = 0; i < nb; i++)
|
|
|
|
if (gst_mpegts_descriptor_parse_iso_639_language_idx (desc, i, &lang_code,
|
|
|
|
NULL))
|
|
|
|
add_iso639_language_to_tags (stream, lang_code);
|
|
|
|
|
|
|
|
return;
|
2012-07-26 18:38:28 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 08:29:20 +00:00
|
|
|
desc =
|
|
|
|
mpegts_get_descriptor_from_stream (bstream, GST_MTS_DESC_DVB_SUBTITLING);
|
|
|
|
|
2012-04-10 10:36:15 +00:00
|
|
|
if (desc) {
|
2013-10-05 12:45:33 +00:00
|
|
|
gchar lang_code[4];
|
2012-04-10 10:36:15 +00:00
|
|
|
|
2013-10-11 08:29:20 +00:00
|
|
|
nb = gst_mpegts_descriptor_parse_dvb_subtitling_nb (desc);
|
2012-04-10 10:36:15 +00:00
|
|
|
|
2013-10-11 08:29:20 +00:00
|
|
|
GST_DEBUG ("Found SUBTITLING descriptor (%d entries)", nb);
|
2012-04-10 10:36:15 +00:00
|
|
|
|
2013-10-11 08:29:20 +00:00
|
|
|
for (i = 0; i < nb; i++)
|
|
|
|
if (gst_mpegts_descriptor_parse_dvb_subtitling_idx (desc, i, &lang_code,
|
|
|
|
NULL, NULL, NULL))
|
|
|
|
add_iso639_language_to_tags (stream, lang_code);
|
2012-04-10 10:36:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
static GstPad *
|
2011-02-21 10:44:01 +00:00
|
|
|
create_pad_for_stream (MpegTSBase * base, MpegTSBaseStream * bstream,
|
2011-02-16 16:57:42 +00:00
|
|
|
MpegTSBaseProgram * program)
|
|
|
|
{
|
2013-07-23 08:24:22 +00:00
|
|
|
GstTSDemux *demux = GST_TS_DEMUX (base);
|
2011-02-16 16:57:42 +00:00
|
|
|
TSDemuxStream *stream = (TSDemuxStream *) bstream;
|
|
|
|
gchar *name = NULL;
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
GstPadTemplate *template = NULL;
|
2013-10-05 12:45:32 +00:00
|
|
|
const GstMpegTsDescriptor *desc = NULL;
|
2011-02-16 16:57:42 +00:00
|
|
|
GstPad *pad = NULL;
|
|
|
|
|
2012-04-10 10:36:15 +00:00
|
|
|
gst_ts_demux_create_tags (stream);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
GST_LOG ("Attempting to create pad for stream 0x%04x with stream_type %d",
|
|
|
|
bstream->pid, bstream->stream_type);
|
|
|
|
|
2013-04-17 20:45:19 +00:00
|
|
|
/* First handle BluRay-specific stream types since there is some overlap
|
|
|
|
* between BluRay and non-BluRay streay type identifiers */
|
2013-07-06 08:36:33 +00:00
|
|
|
if (program->registration_id == DRF_ID_HDMV) {
|
|
|
|
switch (bstream->stream_type) {
|
|
|
|
case ST_BD_AUDIO_AC3:
|
|
|
|
{
|
2013-10-05 12:45:32 +00:00
|
|
|
const GstMpegTsDescriptor *ac3_desc;
|
2013-07-06 08:36:33 +00:00
|
|
|
|
|
|
|
/* ATSC ac3 audio descriptor */
|
|
|
|
ac3_desc =
|
|
|
|
mpegts_get_descriptor_from_stream (bstream,
|
|
|
|
GST_MTS_DESC_AC3_AUDIO_STREAM);
|
2013-10-05 12:45:32 +00:00
|
|
|
if (ac3_desc && DESC_AC_AUDIO_STREAM_bsid (ac3_desc->data) != 16) {
|
2013-07-06 08:36:33 +00:00
|
|
|
GST_LOG ("ac3 audio");
|
2013-04-17 20:45:19 +00:00
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
2013-07-06 08:36:33 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-ac3");
|
|
|
|
} else {
|
2013-04-17 20:45:19 +00:00
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
2013-07-06 08:36:33 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-eac3");
|
|
|
|
}
|
|
|
|
break;
|
2013-04-17 20:45:19 +00:00
|
|
|
}
|
2013-07-06 08:36:33 +00:00
|
|
|
case ST_BD_AUDIO_EAC3:
|
2014-03-03 12:07:47 +00:00
|
|
|
case ST_BD_AUDIO_AC3_PLUS:
|
2013-07-06 08:36:33 +00:00
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-eac3");
|
|
|
|
break;
|
|
|
|
case ST_BD_AUDIO_AC3_TRUE_HD:
|
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-true-hd");
|
2014-03-03 12:07:47 +00:00
|
|
|
stream->target_pes_substream = 0x72;
|
2013-07-06 08:36:33 +00:00
|
|
|
break;
|
|
|
|
case ST_BD_AUDIO_LPCM:
|
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-private-ts-lpcm");
|
|
|
|
break;
|
|
|
|
case ST_BD_PGS_SUBPICTURE:
|
|
|
|
template = gst_static_pad_template_get (&subpicture_template);
|
|
|
|
name = g_strdup_printf ("subpicture_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_empty_simple ("subpicture/x-pgs");
|
|
|
|
break;
|
2014-03-03 12:07:47 +00:00
|
|
|
case ST_BD_AUDIO_DTS_HD:
|
|
|
|
case ST_BD_AUDIO_DTS_HD_MASTER_AUDIO:
|
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-dts");
|
|
|
|
stream->target_pes_substream = 0x71;
|
|
|
|
break;
|
2013-04-17 20:45:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (template && name && caps)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Handle non-BluRay stream types */
|
2011-02-16 16:57:42 +00:00
|
|
|
switch (bstream->stream_type) {
|
2013-07-04 05:49:37 +00:00
|
|
|
case GST_MPEG_TS_STREAM_TYPE_VIDEO_MPEG1:
|
|
|
|
case GST_MPEG_TS_STREAM_TYPE_VIDEO_MPEG2:
|
2013-04-17 20:45:19 +00:00
|
|
|
case ST_PS_VIDEO_MPEG2_DCII:
|
2013-06-23 06:43:23 +00:00
|
|
|
/* FIXME : Use DCII registration code (ETV1 ?) to handle that special
|
|
|
|
* Stream type (ST_PS_VIDEO_MPEG2_DCII) */
|
2013-07-04 05:49:37 +00:00
|
|
|
/* FIXME : Use video decriptor (0x1) to refine caps with:
|
|
|
|
* * frame_rate
|
|
|
|
* * profile_and_level
|
|
|
|
*/
|
2011-02-16 16:57:42 +00:00
|
|
|
GST_LOG ("mpeg video");
|
|
|
|
template = gst_static_pad_template_get (&video_template);
|
|
|
|
name = g_strdup_printf ("video_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_simple ("video/mpeg",
|
|
|
|
"mpegversion", G_TYPE_INT,
|
2013-07-04 05:49:37 +00:00
|
|
|
bstream->stream_type == GST_MPEG_TS_STREAM_TYPE_VIDEO_MPEG1 ? 1 : 2,
|
|
|
|
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
break;
|
2013-07-04 05:49:37 +00:00
|
|
|
case GST_MPEG_TS_STREAM_TYPE_AUDIO_MPEG1:
|
|
|
|
case GST_MPEG_TS_STREAM_TYPE_AUDIO_MPEG2:
|
2011-02-16 16:57:42 +00:00
|
|
|
GST_LOG ("mpeg audio");
|
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
|
|
|
caps =
|
|
|
|
gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1,
|
|
|
|
NULL);
|
2013-07-27 10:17:34 +00:00
|
|
|
/* HDV is always mpeg 1 audio layer 2 */
|
|
|
|
if (program->registration_id == DRF_ID_TSHV)
|
|
|
|
gst_caps_set_simple (caps, "layer", G_TYPE_INT, 2, NULL);
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
2013-07-04 05:49:37 +00:00
|
|
|
case GST_MPEG_TS_STREAM_TYPE_PRIVATE_PES_PACKETS:
|
2011-02-16 16:57:42 +00:00
|
|
|
GST_LOG ("private data");
|
2013-06-23 06:43:23 +00:00
|
|
|
/* FIXME: Move all of this into a common method (there might be other
|
|
|
|
* types also, depending on registratino descriptors also
|
|
|
|
*/
|
2013-07-06 08:36:33 +00:00
|
|
|
desc = mpegts_get_descriptor_from_stream (bstream, GST_MTS_DESC_DVB_AC3);
|
2011-02-16 16:57:42 +00:00
|
|
|
if (desc) {
|
|
|
|
GST_LOG ("ac3 audio");
|
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
2012-04-19 12:20:52 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-ac3");
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-02-20 20:32:21 +00:00
|
|
|
|
2013-07-06 08:36:33 +00:00
|
|
|
desc =
|
|
|
|
mpegts_get_descriptor_from_stream (bstream,
|
2013-06-23 06:43:23 +00:00
|
|
|
GST_MTS_DESC_DVB_ENHANCED_AC3);
|
2011-02-16 16:57:42 +00:00
|
|
|
if (desc) {
|
|
|
|
GST_LOG ("ac3 audio");
|
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
2012-04-19 12:20:52 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-eac3");
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-07-06 08:36:33 +00:00
|
|
|
desc =
|
|
|
|
mpegts_get_descriptor_from_stream (bstream,
|
2013-06-23 06:43:23 +00:00
|
|
|
GST_MTS_DESC_DVB_TELETEXT);
|
2011-02-16 16:57:42 +00:00
|
|
|
if (desc) {
|
|
|
|
GST_LOG ("teletext");
|
|
|
|
template = gst_static_pad_template_get (&private_template);
|
|
|
|
name = g_strdup_printf ("private_%04x", bstream->pid);
|
2013-07-30 15:08:17 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("application/x-teletext");
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
desc =
|
2013-07-06 08:36:33 +00:00
|
|
|
mpegts_get_descriptor_from_stream (bstream,
|
2013-06-23 06:43:23 +00:00
|
|
|
GST_MTS_DESC_DVB_SUBTITLING);
|
2011-02-16 16:57:42 +00:00
|
|
|
if (desc) {
|
|
|
|
GST_LOG ("subtitling");
|
|
|
|
template = gst_static_pad_template_get (&private_template);
|
|
|
|
name = g_strdup_printf ("private_%04x", bstream->pid);
|
2012-04-19 12:20:52 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("subpicture/x-dvb");
|
2012-01-23 13:10:43 +00:00
|
|
|
break;
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
2012-02-20 20:32:21 +00:00
|
|
|
|
2013-07-06 08:36:33 +00:00
|
|
|
switch (bstream->registration_id) {
|
|
|
|
case DRF_ID_DTS1:
|
|
|
|
case DRF_ID_DTS2:
|
|
|
|
case DRF_ID_DTS3:
|
|
|
|
/* SMPTE registered DTS */
|
|
|
|
GST_LOG ("subtitling");
|
|
|
|
template = gst_static_pad_template_get (&private_template);
|
|
|
|
name = g_strdup_printf ("private_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-dts");
|
|
|
|
break;
|
|
|
|
case DRF_ID_S302M:
|
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-smpte-302m");
|
|
|
|
break;
|
2014-01-06 12:51:01 +00:00
|
|
|
case DRF_ID_HEVC:
|
|
|
|
template = gst_static_pad_template_get (&video_template);
|
|
|
|
name = g_strdup_printf ("video_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_simple ("video/x-h265",
|
|
|
|
"stream-format", G_TYPE_STRING, "byte-stream",
|
|
|
|
"alignment", G_TYPE_STRING, "nal", NULL);
|
|
|
|
break;
|
2012-02-20 20:32:21 +00:00
|
|
|
}
|
|
|
|
if (template)
|
|
|
|
break;
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
/* hack for itv hd (sid 10510, video pid 3401 */
|
|
|
|
if (program->program_number == 10510 && bstream->pid == 3401) {
|
|
|
|
template = gst_static_pad_template_get (&video_template);
|
|
|
|
name = g_strdup_printf ("video_%04x", bstream->pid);
|
2011-04-24 23:42:03 +00:00
|
|
|
caps = gst_caps_new_simple ("video/x-h264",
|
|
|
|
"stream-format", G_TYPE_STRING, "byte-stream",
|
|
|
|
"alignment", G_TYPE_STRING, "nal", NULL);
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ST_HDV_AUX_V:
|
2013-06-23 06:43:23 +00:00
|
|
|
/* FIXME : Should only be used with specific PMT registration_descriptor */
|
2011-02-16 16:57:42 +00:00
|
|
|
/* We don't expose those streams since they're only helper streams */
|
|
|
|
/* template = gst_static_pad_template_get (&private_template); */
|
|
|
|
/* name = g_strdup_printf ("private_%04x", bstream->pid); */
|
|
|
|
/* caps = gst_caps_new_simple ("hdv/aux-v", NULL); */
|
|
|
|
break;
|
|
|
|
case ST_HDV_AUX_A:
|
2013-06-23 06:43:23 +00:00
|
|
|
/* FIXME : Should only be used with specific PMT registration_descriptor */
|
2011-02-16 16:57:42 +00:00
|
|
|
/* We don't expose those streams since they're only helper streams */
|
|
|
|
/* template = gst_static_pad_template_get (&private_template); */
|
|
|
|
/* name = g_strdup_printf ("private_%04x", bstream->pid); */
|
|
|
|
/* caps = gst_caps_new_simple ("hdv/aux-a", NULL); */
|
|
|
|
break;
|
2013-07-04 05:49:37 +00:00
|
|
|
case GST_MPEG_TS_STREAM_TYPE_AUDIO_AAC_ADTS:
|
2011-02-16 16:57:42 +00:00
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_simple ("audio/mpeg",
|
2012-02-21 14:12:53 +00:00
|
|
|
"mpegversion", G_TYPE_INT, 2,
|
2012-02-02 11:37:55 +00:00
|
|
|
"stream-format", G_TYPE_STRING, "adts", NULL);
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
2013-07-04 05:49:37 +00:00
|
|
|
case GST_MPEG_TS_STREAM_TYPE_AUDIO_AAC_LATM:
|
2012-02-14 14:44:48 +00:00
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_simple ("audio/mpeg",
|
|
|
|
"mpegversion", G_TYPE_INT, 4,
|
2012-06-28 15:40:16 +00:00
|
|
|
"stream-format", G_TYPE_STRING, "loas", NULL);
|
2012-02-14 14:44:48 +00:00
|
|
|
break;
|
2013-07-04 05:49:37 +00:00
|
|
|
case GST_MPEG_TS_STREAM_TYPE_VIDEO_MPEG4:
|
2011-02-16 16:57:42 +00:00
|
|
|
template = gst_static_pad_template_get (&video_template);
|
|
|
|
name = g_strdup_printf ("video_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_simple ("video/mpeg",
|
|
|
|
"mpegversion", G_TYPE_INT, 4,
|
|
|
|
"systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
|
|
|
|
break;
|
2013-07-04 05:49:37 +00:00
|
|
|
case GST_MPEG_TS_STREAM_TYPE_VIDEO_H264:
|
2011-02-16 16:57:42 +00:00
|
|
|
template = gst_static_pad_template_get (&video_template);
|
|
|
|
name = g_strdup_printf ("video_%04x", bstream->pid);
|
2011-04-24 23:42:03 +00:00
|
|
|
caps = gst_caps_new_simple ("video/x-h264",
|
|
|
|
"stream-format", G_TYPE_STRING, "byte-stream",
|
|
|
|
"alignment", G_TYPE_STRING, "nal", NULL);
|
2014-01-06 12:51:01 +00:00
|
|
|
break;
|
|
|
|
case GST_MPEG_TS_STREAM_TYPE_VIDEO_HEVC:
|
|
|
|
template = gst_static_pad_template_get (&video_template);
|
|
|
|
name = g_strdup_printf ("video_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_simple ("video/x-h265",
|
|
|
|
"stream-format", G_TYPE_STRING, "byte-stream",
|
|
|
|
"alignment", G_TYPE_STRING, "nal", NULL);
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
|
|
|
case ST_VIDEO_DIRAC:
|
2013-07-06 08:36:33 +00:00
|
|
|
if (bstream->registration_id == 0x64726163) {
|
|
|
|
GST_LOG ("dirac");
|
|
|
|
/* dirac in hex */
|
|
|
|
template = gst_static_pad_template_get (&video_template);
|
|
|
|
name = g_strdup_printf ("video_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_empty_simple ("video/x-dirac");
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ST_PRIVATE_EA: /* Try to detect a VC1 stream */
|
|
|
|
{
|
2013-02-05 22:07:12 +00:00
|
|
|
gboolean is_vc1 = FALSE;
|
2013-07-06 08:36:33 +00:00
|
|
|
|
|
|
|
/* Note/FIXME: RP-227 specifies that the registration descriptor
|
|
|
|
* for vc1 can also contain other information, such as profile,
|
|
|
|
* level, alignment, buffer_size, .... */
|
|
|
|
if (bstream->registration_id == DRF_ID_VC1)
|
|
|
|
is_vc1 = TRUE;
|
2013-02-05 22:07:12 +00:00
|
|
|
if (!is_vc1) {
|
|
|
|
GST_WARNING ("0xea private stream type found but no descriptor "
|
|
|
|
"for VC1. Assuming plain VC1.");
|
|
|
|
}
|
|
|
|
|
|
|
|
template = gst_static_pad_template_get (&video_template);
|
|
|
|
name = g_strdup_printf ("video_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_simple ("video/x-wmv",
|
|
|
|
"wmvversion", G_TYPE_INT, 3, "format", G_TYPE_STRING, "WVC1", NULL);
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-04-17 20:45:19 +00:00
|
|
|
case ST_PS_AUDIO_AC3:
|
2011-02-16 16:57:42 +00:00
|
|
|
/* DVB_ENHANCED_AC3 */
|
2013-07-06 08:36:33 +00:00
|
|
|
desc =
|
|
|
|
mpegts_get_descriptor_from_stream (bstream,
|
2013-06-23 06:43:23 +00:00
|
|
|
GST_MTS_DESC_DVB_ENHANCED_AC3);
|
2011-02-16 16:57:42 +00:00
|
|
|
if (desc) {
|
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
2012-04-19 12:20:52 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-eac3");
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-29 06:23:30 +00:00
|
|
|
/* If stream has ac3 descriptor
|
|
|
|
* OR program is ATSC (GA94)
|
|
|
|
* OR stream registration is AC-3
|
|
|
|
* then it's regular AC3 */
|
|
|
|
if (bstream->registration_id == DRF_ID_AC3 ||
|
|
|
|
program->registration_id == DRF_ID_GA94 ||
|
|
|
|
mpegts_get_descriptor_from_stream (bstream, GST_MTS_DESC_DVB_AC3)) {
|
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-ac3");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_WARNING ("AC3 stream type found but no guaranteed "
|
|
|
|
"way found to differentiate between AC3 and EAC3. "
|
|
|
|
"Assuming plain AC3.");
|
2011-02-16 16:57:42 +00:00
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
2012-04-19 12:20:52 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-ac3");
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
|
|
|
case ST_PS_AUDIO_DTS:
|
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
2012-04-19 12:20:52 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-dts");
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
|
|
|
case ST_PS_AUDIO_LPCM:
|
|
|
|
template = gst_static_pad_template_get (&audio_template);
|
|
|
|
name = g_strdup_printf ("audio_%04x", bstream->pid);
|
2012-04-19 12:20:52 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("audio/x-lpcm");
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
|
|
|
case ST_PS_DVD_SUBPICTURE:
|
|
|
|
template = gst_static_pad_template_get (&subpicture_template);
|
|
|
|
name = g_strdup_printf ("subpicture_%04x", bstream->pid);
|
2012-08-20 22:37:00 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("subpicture/x-dvd");
|
2011-02-16 16:57:42 +00:00
|
|
|
break;
|
2011-07-21 11:26:55 +00:00
|
|
|
default:
|
|
|
|
GST_WARNING ("Non-media stream (stream_type:0x%x). Not creating pad",
|
|
|
|
bstream->stream_type);
|
|
|
|
break;
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
2013-04-17 20:45:19 +00:00
|
|
|
|
|
|
|
done:
|
2011-02-16 16:57:42 +00:00
|
|
|
if (template && name && caps) {
|
2013-07-23 08:24:22 +00:00
|
|
|
GstEvent *event;
|
2012-08-06 11:59:27 +00:00
|
|
|
gchar *stream_id;
|
|
|
|
|
2013-04-23 18:19:14 +00:00
|
|
|
GST_LOG ("stream:%p creating pad with name %s and caps %" GST_PTR_FORMAT,
|
|
|
|
stream, name, caps);
|
2011-02-16 16:57:42 +00:00
|
|
|
pad = gst_pad_new_from_template (template, name);
|
2012-04-19 12:20:52 +00:00
|
|
|
gst_pad_set_active (pad, TRUE);
|
2011-02-16 16:57:42 +00:00
|
|
|
gst_pad_use_fixed_caps (pad);
|
2012-08-06 11:59:27 +00:00
|
|
|
stream_id =
|
|
|
|
gst_pad_create_stream_id_printf (pad, GST_ELEMENT_CAST (base), "%08x",
|
|
|
|
bstream->pid);
|
2013-07-23 08:24:22 +00:00
|
|
|
|
|
|
|
event = gst_pad_get_sticky_event (base->sinkpad, GST_EVENT_STREAM_START, 0);
|
|
|
|
if (event) {
|
|
|
|
if (gst_event_parse_group_id (event, &demux->group_id))
|
|
|
|
demux->have_group_id = TRUE;
|
|
|
|
else
|
|
|
|
demux->have_group_id = FALSE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
} else if (!demux->have_group_id) {
|
|
|
|
demux->have_group_id = TRUE;
|
|
|
|
demux->group_id = gst_util_group_id_next ();
|
|
|
|
}
|
|
|
|
event = gst_event_new_stream_start (stream_id);
|
|
|
|
if (demux->have_group_id)
|
|
|
|
gst_event_set_group_id (event, demux->group_id);
|
|
|
|
|
|
|
|
gst_pad_push_event (pad, event);
|
2012-08-06 11:59:27 +00:00
|
|
|
g_free (stream_id);
|
2011-02-16 16:57:42 +00:00
|
|
|
gst_pad_set_caps (pad, caps);
|
2013-06-14 05:28:29 +00:00
|
|
|
if (!stream->taglist)
|
|
|
|
stream->taglist = gst_tag_list_new_empty ();
|
|
|
|
gst_pb_utils_add_codec_description_to_tag_list (stream->taglist, NULL,
|
|
|
|
caps);
|
2011-02-16 16:57:42 +00:00
|
|
|
gst_pad_set_query_function (pad, gst_ts_demux_srcpad_query);
|
2011-02-22 11:33:56 +00:00
|
|
|
gst_pad_set_event_function (pad, gst_ts_demux_srcpad_event);
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
|
2012-02-24 18:26:21 +00:00
|
|
|
if (name)
|
|
|
|
g_free (name);
|
2012-04-19 11:59:37 +00:00
|
|
|
if (template)
|
|
|
|
gst_object_unref (template);
|
2012-02-24 18:26:21 +00:00
|
|
|
if (caps)
|
|
|
|
gst_caps_unref (caps);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ts_demux_stream_added (MpegTSBase * base, MpegTSBaseStream * bstream,
|
|
|
|
MpegTSBaseProgram * program)
|
|
|
|
{
|
|
|
|
TSDemuxStream *stream = (TSDemuxStream *) bstream;
|
|
|
|
|
|
|
|
if (!stream->pad) {
|
|
|
|
/* Create the pad */
|
|
|
|
if (bstream->stream_type != 0xff)
|
2011-02-21 10:44:01 +00:00
|
|
|
stream->pad = create_pad_for_stream (base, bstream, program);
|
2012-02-29 14:14:15 +00:00
|
|
|
stream->active = FALSE;
|
2012-01-10 10:37:13 +00:00
|
|
|
|
2012-03-01 17:05:17 +00:00
|
|
|
stream->need_newsegment = TRUE;
|
2011-02-16 16:57:42 +00:00
|
|
|
stream->pts = GST_CLOCK_TIME_NONE;
|
2012-01-10 10:37:13 +00:00
|
|
|
stream->dts = GST_CLOCK_TIME_NONE;
|
2013-07-29 06:10:07 +00:00
|
|
|
stream->raw_pts = -1;
|
|
|
|
stream->raw_dts = -1;
|
|
|
|
stream->pending_ts = TRUE;
|
|
|
|
stream->first_dts = GST_CLOCK_TIME_NONE;
|
2013-04-11 11:08:57 +00:00
|
|
|
stream->continuity_counter = CONTINUITY_UNSET;
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
stream->flow_return = GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ts_demux_stream_removed (MpegTSBase * base, MpegTSBaseStream * bstream)
|
|
|
|
{
|
|
|
|
TSDemuxStream *stream = (TSDemuxStream *) bstream;
|
2011-07-21 11:26:55 +00:00
|
|
|
|
2011-08-01 08:54:16 +00:00
|
|
|
if (stream->pad) {
|
2012-02-29 14:14:15 +00:00
|
|
|
if (stream->active && gst_pad_is_active (stream->pad)) {
|
2011-08-01 08:54:16 +00:00
|
|
|
/* Flush out all data */
|
2011-08-18 23:52:37 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Flushing out pending data");
|
2011-08-01 08:54:16 +00:00
|
|
|
gst_ts_demux_push_pending_data ((GstTSDemux *) base, stream);
|
2011-08-18 23:52:37 +00:00
|
|
|
|
2011-08-01 08:54:16 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Pushing out EOS");
|
|
|
|
gst_pad_push_event (stream->pad, gst_event_new_eos ());
|
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Deactivating and removing pad");
|
|
|
|
gst_pad_set_active (stream->pad, FALSE);
|
|
|
|
gst_element_remove_pad (GST_ELEMENT_CAST (base), stream->pad);
|
2012-02-29 14:14:15 +00:00
|
|
|
stream->active = FALSE;
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
2011-08-01 08:54:16 +00:00
|
|
|
stream->pad = NULL;
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
2012-03-30 17:19:12 +00:00
|
|
|
gst_ts_demux_stream_flush (stream);
|
2011-08-01 08:54:16 +00:00
|
|
|
stream->flow_return = GST_FLOW_NOT_LINKED;
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
activate_pad_for_stream (GstTSDemux * tsdemux, TSDemuxStream * stream)
|
|
|
|
{
|
2012-05-18 08:07:56 +00:00
|
|
|
GList *tmp;
|
|
|
|
gboolean alldone = TRUE;
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
if (stream->pad) {
|
|
|
|
GST_DEBUG_OBJECT (tsdemux, "Activating pad %s:%s for stream %p",
|
|
|
|
GST_DEBUG_PAD_NAME (stream->pad), stream);
|
|
|
|
gst_element_add_pad ((GstElement *) tsdemux, stream->pad);
|
2012-02-29 14:14:15 +00:00
|
|
|
stream->active = TRUE;
|
2011-02-16 16:57:42 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "done adding pad");
|
2012-05-18 08:07:56 +00:00
|
|
|
|
|
|
|
/* Check if all pads were activated, and if so emit no-more-pads */
|
|
|
|
for (tmp = tsdemux->program->stream_list; tmp; tmp = tmp->next) {
|
|
|
|
stream = (TSDemuxStream *) tmp->data;
|
|
|
|
if (stream->pad && !stream->active)
|
|
|
|
alldone = FALSE;
|
|
|
|
}
|
|
|
|
if (alldone) {
|
|
|
|
GST_DEBUG_OBJECT (tsdemux, "All pads were activated, emit no-more-pads");
|
|
|
|
gst_element_no_more_pads ((GstElement *) tsdemux);
|
|
|
|
}
|
2011-02-16 16:57:42 +00:00
|
|
|
} else
|
2011-07-21 11:26:55 +00:00
|
|
|
GST_WARNING_OBJECT (tsdemux,
|
|
|
|
"stream %p (pid 0x%04x, type:0x%03x) has no pad", stream,
|
|
|
|
((MpegTSBaseStream *) stream)->pid,
|
|
|
|
((MpegTSBaseStream *) stream)->stream_type);
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 11:33:56 +00:00
|
|
|
static void
|
|
|
|
gst_ts_demux_stream_flush (TSDemuxStream * stream)
|
|
|
|
{
|
2012-05-21 15:53:37 +00:00
|
|
|
GST_DEBUG ("flushing stream %p", stream);
|
2012-03-30 17:19:12 +00:00
|
|
|
|
2012-05-21 15:53:37 +00:00
|
|
|
if (stream->data)
|
|
|
|
g_free (stream->data);
|
|
|
|
stream->data = NULL;
|
2012-04-30 10:28:42 +00:00
|
|
|
stream->state = PENDING_PACKET_EMPTY;
|
2012-03-05 08:38:57 +00:00
|
|
|
stream->expected_size = 0;
|
2012-05-21 15:53:37 +00:00
|
|
|
stream->allocated_size = 0;
|
2012-03-05 08:38:57 +00:00
|
|
|
stream->current_size = 0;
|
2012-03-01 17:05:17 +00:00
|
|
|
stream->need_newsegment = TRUE;
|
|
|
|
stream->pts = GST_CLOCK_TIME_NONE;
|
|
|
|
stream->dts = GST_CLOCK_TIME_NONE;
|
2013-07-29 06:10:07 +00:00
|
|
|
stream->first_dts = GST_CLOCK_TIME_NONE;
|
|
|
|
stream->raw_pts = -1;
|
|
|
|
stream->raw_dts = -1;
|
2012-11-11 11:46:43 +00:00
|
|
|
if (stream->flow_return == GST_FLOW_FLUSHING) {
|
|
|
|
stream->flow_return = GST_FLOW_OK;
|
|
|
|
}
|
2013-04-11 11:08:57 +00:00
|
|
|
stream->continuity_counter = CONTINUITY_UNSET;
|
2011-02-22 11:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ts_demux_flush_streams (GstTSDemux * demux)
|
|
|
|
{
|
2011-07-19 07:34:37 +00:00
|
|
|
g_list_foreach (demux->program->stream_list,
|
|
|
|
(GFunc) gst_ts_demux_stream_flush, NULL);
|
2011-02-22 11:33:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
static void
|
|
|
|
gst_ts_demux_program_started (MpegTSBase * base, MpegTSBaseProgram * program)
|
|
|
|
{
|
|
|
|
GstTSDemux *demux = GST_TS_DEMUX (base);
|
|
|
|
|
2013-03-09 23:07:40 +00:00
|
|
|
GST_DEBUG ("Current program %d, new program %d requested program %d",
|
|
|
|
(gint) demux->program_number, program->program_number,
|
|
|
|
demux->requested_program_number);
|
2011-07-21 11:26:55 +00:00
|
|
|
|
2013-03-09 23:07:40 +00:00
|
|
|
if (demux->requested_program_number == program->program_number ||
|
|
|
|
(demux->requested_program_number == -1 && demux->program_number == -1)) {
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
GST_LOG ("program %d started", program->program_number);
|
|
|
|
demux->program_number = program->program_number;
|
|
|
|
demux->program = program;
|
|
|
|
|
2012-03-01 17:05:17 +00:00
|
|
|
/* If this is not the initial program, we need to calculate
|
|
|
|
* an update newsegment */
|
|
|
|
demux->calculate_update_segment = !program->initial_program;
|
|
|
|
|
2012-02-29 14:14:15 +00:00
|
|
|
/* FIXME : When do we emit no_more_pads ? */
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 13:26:20 +00:00
|
|
|
static void
|
|
|
|
gst_ts_demux_program_stopped (MpegTSBase * base, MpegTSBaseProgram * program)
|
|
|
|
{
|
|
|
|
GstTSDemux *demux = GST_TS_DEMUX (base);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-10-12 13:26:20 +00:00
|
|
|
if (demux->program == program) {
|
|
|
|
demux->program = NULL;
|
|
|
|
demux->program_number = -1;
|
|
|
|
}
|
|
|
|
}
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
gst_ts_demux_record_pts (GstTSDemux * demux, TSDemuxStream * stream,
|
|
|
|
guint64 pts, guint64 offset)
|
|
|
|
{
|
|
|
|
MpegTSBaseStream *bs = (MpegTSBaseStream *) stream;
|
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
stream->raw_pts = pts;
|
2012-07-13 14:56:11 +00:00
|
|
|
if (pts == -1) {
|
|
|
|
stream->pts = GST_CLOCK_TIME_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-26 13:39:30 +00:00
|
|
|
GST_LOG ("pid 0x%04x raw pts:%" G_GUINT64_FORMAT " at offset %"
|
2012-01-10 10:37:13 +00:00
|
|
|
G_GUINT64_FORMAT, bs->pid, pts, offset);
|
|
|
|
|
|
|
|
/* Compute PTS in GstClockTime */
|
2013-04-26 13:39:30 +00:00
|
|
|
stream->pts =
|
|
|
|
mpegts_packetizer_pts_to_ts (MPEG_TS_BASE_PACKETIZER (demux),
|
|
|
|
MPEGTIME_TO_GSTTIME (pts), demux->program->pcr_pid);
|
2012-01-10 10:37:13 +00:00
|
|
|
|
2013-04-26 13:39:30 +00:00
|
|
|
GST_LOG ("pid 0x%04x Stored PTS %" G_GUINT64_FORMAT, bs->pid, stream->pts);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (demux->emit_statistics)) {
|
|
|
|
GstStructure *st;
|
2012-04-19 12:20:52 +00:00
|
|
|
st = gst_structure_new_id_empty (QUARK_TSDEMUX);
|
2011-02-16 16:57:42 +00:00
|
|
|
gst_structure_id_set (st,
|
|
|
|
QUARK_PID, G_TYPE_UINT, bs->pid,
|
|
|
|
QUARK_OFFSET, G_TYPE_UINT64, offset, QUARK_PTS, G_TYPE_UINT64, pts,
|
|
|
|
NULL);
|
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (demux),
|
|
|
|
gst_message_new_element (GST_OBJECT (demux), st));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
gst_ts_demux_record_dts (GstTSDemux * demux, TSDemuxStream * stream,
|
|
|
|
guint64 dts, guint64 offset)
|
|
|
|
{
|
|
|
|
MpegTSBaseStream *bs = (MpegTSBaseStream *) stream;
|
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
stream->raw_dts = dts;
|
2012-07-13 14:56:11 +00:00
|
|
|
if (dts == -1) {
|
|
|
|
stream->dts = GST_CLOCK_TIME_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-26 13:39:30 +00:00
|
|
|
GST_LOG ("pid 0x%04x raw dts:%" G_GUINT64_FORMAT " at offset %"
|
2012-01-10 10:37:13 +00:00
|
|
|
G_GUINT64_FORMAT, bs->pid, dts, offset);
|
|
|
|
|
|
|
|
/* Compute DTS in GstClockTime */
|
2013-04-26 13:39:30 +00:00
|
|
|
stream->dts =
|
|
|
|
mpegts_packetizer_pts_to_ts (MPEG_TS_BASE_PACKETIZER (demux),
|
|
|
|
MPEGTIME_TO_GSTTIME (dts), demux->program->pcr_pid);
|
2012-01-10 10:37:13 +00:00
|
|
|
|
2013-04-26 13:39:30 +00:00
|
|
|
GST_LOG ("pid 0x%04x Stored DTS %" G_GUINT64_FORMAT, bs->pid, stream->dts);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (demux->emit_statistics)) {
|
|
|
|
GstStructure *st;
|
2012-04-19 12:20:52 +00:00
|
|
|
st = gst_structure_new_id_empty (QUARK_TSDEMUX);
|
2011-02-16 16:57:42 +00:00
|
|
|
gst_structure_id_set (st,
|
|
|
|
QUARK_PID, G_TYPE_UINT, bs->pid,
|
|
|
|
QUARK_OFFSET, G_TYPE_UINT64, offset, QUARK_DTS, G_TYPE_UINT64, dts,
|
|
|
|
NULL);
|
|
|
|
gst_element_post_message (GST_ELEMENT_CAST (demux),
|
|
|
|
gst_message_new_element (GST_OBJECT (demux), st));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
/* This is called when we haven't got a valid initial PTS/DTS on all streams */
|
|
|
|
static gboolean
|
|
|
|
check_pending_buffers (GstTSDemux * demux, TSDemuxStream * stream)
|
|
|
|
{
|
|
|
|
gboolean have_observation = FALSE;
|
|
|
|
/* The biggest offset */
|
|
|
|
guint64 offset = 0;
|
|
|
|
GList *tmp;
|
|
|
|
|
|
|
|
/* 1. Go over all streams */
|
|
|
|
for (tmp = demux->program->stream_list; tmp; tmp = tmp->next) {
|
|
|
|
TSDemuxStream *tmpstream = (TSDemuxStream *) tmp->data;
|
|
|
|
/* 1.1 check if at least one stream got a valid DTS */
|
|
|
|
if ((tmpstream->raw_dts != -1 && tmpstream->dts != GST_CLOCK_TIME_NONE) ||
|
|
|
|
(tmpstream->raw_pts != -1 && tmpstream->pts != GST_CLOCK_TIME_NONE)) {
|
|
|
|
have_observation = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 2. If we don't have a valid value yet, break out */
|
|
|
|
if (have_observation == FALSE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* 3. Go over all streams that have current/pending data */
|
|
|
|
for (tmp = demux->program->stream_list; tmp; tmp = tmp->next) {
|
|
|
|
TSDemuxStream *tmpstream = (TSDemuxStream *) tmp->data;
|
|
|
|
PendingBuffer *pend;
|
|
|
|
guint64 firstval, lastval, ts;
|
|
|
|
|
|
|
|
/* 3.1 Calculate the offset between current DTS and first DTS */
|
|
|
|
if (tmpstream->pending == NULL || tmpstream->state == PENDING_PACKET_EMPTY)
|
|
|
|
continue;
|
|
|
|
/* If we don't have any pending data, the offset is 0 for this stream */
|
|
|
|
if (tmpstream->pending == NULL)
|
|
|
|
break;
|
|
|
|
if (tmpstream->raw_dts != -1)
|
|
|
|
lastval = tmpstream->raw_dts;
|
|
|
|
else if (tmpstream->raw_pts != -1)
|
|
|
|
lastval = tmpstream->raw_pts;
|
|
|
|
else {
|
|
|
|
GST_WARNING ("Don't have a last DTS/PTS to use for offset recalculation");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pend = tmpstream->pending->data;
|
|
|
|
if (pend->dts != -1)
|
|
|
|
firstval = pend->dts;
|
|
|
|
else if (pend->pts != -1)
|
|
|
|
firstval = pend->pts;
|
|
|
|
else {
|
|
|
|
GST_WARNING
|
|
|
|
("Don't have a first DTS/PTS to use for offset recalculation");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* 3.2 Add to the offset the report TS for the current DTS */
|
|
|
|
ts = mpegts_packetizer_pts_to_ts (MPEG_TS_BASE_PACKETIZER (demux),
|
|
|
|
MPEGTIME_TO_GSTTIME (lastval), demux->program->pcr_pid);
|
|
|
|
if (ts == GST_CLOCK_TIME_NONE) {
|
|
|
|
GST_WARNING ("THIS SHOULD NOT HAPPEN !");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ts += MPEGTIME_TO_GSTTIME (lastval - firstval);
|
|
|
|
/* 3.3 If that offset is bigger than the current offset, store it */
|
|
|
|
if (ts > offset)
|
|
|
|
offset = ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG ("New initial pcr_offset %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (offset));
|
|
|
|
|
|
|
|
/* 4. Set the offset on the packetizer */
|
|
|
|
mpegts_packetizer_set_current_pcr_offset (MPEG_TS_BASE_PACKETIZER (demux),
|
|
|
|
offset, demux->program->pcr_pid);
|
|
|
|
|
|
|
|
/* 4. Go over all streams */
|
|
|
|
for (tmp = demux->program->stream_list; tmp; tmp = tmp->next) {
|
|
|
|
TSDemuxStream *stream = (TSDemuxStream *) tmp->data;
|
|
|
|
|
|
|
|
stream->pending_ts = FALSE;
|
|
|
|
/* 4.1 Set pending_ts for FALSE */
|
|
|
|
|
|
|
|
/* 4.2 Recalculate PTS/DTS (in running time) for pending data */
|
|
|
|
if (stream->pending) {
|
|
|
|
GList *tmp2;
|
|
|
|
for (tmp2 = stream->pending; tmp2; tmp2 = tmp2->next) {
|
|
|
|
PendingBuffer *pend = (PendingBuffer *) tmp2->data;
|
|
|
|
if (pend->pts != -1)
|
|
|
|
GST_BUFFER_PTS (pend->buffer) =
|
|
|
|
mpegts_packetizer_pts_to_ts (MPEG_TS_BASE_PACKETIZER (demux),
|
|
|
|
MPEGTIME_TO_GSTTIME (pend->pts), demux->program->pcr_pid);
|
|
|
|
if (pend->dts != -1)
|
|
|
|
GST_BUFFER_DTS (pend->buffer) =
|
|
|
|
mpegts_packetizer_pts_to_ts (MPEG_TS_BASE_PACKETIZER (demux),
|
|
|
|
MPEGTIME_TO_GSTTIME (pend->dts), demux->program->pcr_pid);
|
|
|
|
/* 4.2.2 Set first_dts to TS of lowest DTS (for segment) */
|
|
|
|
if (stream->first_dts == GST_CLOCK_TIME_NONE) {
|
|
|
|
if (GST_BUFFER_DTS (pend->buffer) != GST_CLOCK_TIME_NONE)
|
|
|
|
stream->first_dts = GST_BUFFER_DTS (pend->buffer);
|
|
|
|
else if (GST_BUFFER_PTS (pend->buffer) != GST_CLOCK_TIME_NONE)
|
|
|
|
stream->first_dts = GST_BUFFER_PTS (pend->buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Recalculate PTS/DTS (in running time) for current data */
|
|
|
|
if (stream->state != PENDING_PACKET_EMPTY) {
|
|
|
|
if (stream->raw_dts != -1) {
|
|
|
|
stream->dts =
|
|
|
|
mpegts_packetizer_pts_to_ts (MPEG_TS_BASE_PACKETIZER (demux),
|
|
|
|
MPEGTIME_TO_GSTTIME (stream->raw_dts), demux->program->pcr_pid);
|
|
|
|
if (stream->first_dts == GST_CLOCK_TIME_NONE)
|
|
|
|
stream->first_dts = stream->dts;
|
|
|
|
}
|
|
|
|
if (stream->raw_pts != -1) {
|
|
|
|
stream->pts =
|
|
|
|
mpegts_packetizer_pts_to_ts (MPEG_TS_BASE_PACKETIZER (demux),
|
|
|
|
MPEGTIME_TO_GSTTIME (stream->raw_pts), demux->program->pcr_pid);
|
|
|
|
if (stream->first_dts == GST_CLOCK_TIME_NONE)
|
|
|
|
stream->first_dts = stream->pts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-05-21 15:53:37 +00:00
|
|
|
static void
|
|
|
|
gst_ts_demux_parse_pes_header (GstTSDemux * demux, TSDemuxStream * stream,
|
|
|
|
guint8 * data, guint32 length, guint64 bufferoffset)
|
2011-02-16 16:57:42 +00:00
|
|
|
{
|
2011-07-18 07:12:16 +00:00
|
|
|
PESHeader header;
|
|
|
|
PESParsingResult parseres;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-05-21 15:53:37 +00:00
|
|
|
GST_MEMDUMP ("Header buffer", data, MIN (length, 32));
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2013-08-14 08:33:14 +00:00
|
|
|
parseres = mpegts_parse_pes_header (data, length, &header);
|
2011-07-18 07:12:16 +00:00
|
|
|
if (G_UNLIKELY (parseres == PES_PARSING_NEED_MORE))
|
|
|
|
goto discont;
|
|
|
|
if (G_UNLIKELY (parseres == PES_PARSING_BAD)) {
|
|
|
|
GST_WARNING ("Error parsing PES header. pid: 0x%x stream_type: 0x%x",
|
2011-02-21 10:44:01 +00:00
|
|
|
stream->stream.pid, stream->stream.stream_type);
|
2011-02-16 16:57:42 +00:00
|
|
|
goto discont;
|
|
|
|
}
|
2011-02-22 11:33:56 +00:00
|
|
|
|
2014-03-03 12:07:47 +00:00
|
|
|
if (stream->target_pes_substream != 0
|
|
|
|
&& header.stream_id_extension != stream->target_pes_substream) {
|
|
|
|
GST_DEBUG ("Skipping unwanted substream");
|
|
|
|
goto discont;
|
|
|
|
}
|
|
|
|
|
2012-07-13 14:56:11 +00:00
|
|
|
gst_ts_demux_record_dts (demux, stream, header.DTS, bufferoffset);
|
|
|
|
gst_ts_demux_record_pts (demux, stream, header.PTS, bufferoffset);
|
2013-07-29 06:10:07 +00:00
|
|
|
if (G_UNLIKELY (stream->pending_ts &&
|
|
|
|
(stream->pts != GST_CLOCK_TIME_NONE
|
|
|
|
|| stream->dts != GST_CLOCK_TIME_NONE))) {
|
|
|
|
GST_DEBUG ("Got pts/dts update, rechecking all streams");
|
|
|
|
check_pending_buffers (demux, stream);
|
|
|
|
} else if (stream->first_dts == GST_CLOCK_TIME_NONE) {
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (stream->dts))
|
|
|
|
stream->first_dts = stream->dts;
|
|
|
|
else if (GST_CLOCK_TIME_IS_VALID (stream->pts))
|
|
|
|
stream->first_dts = stream->pts;
|
|
|
|
}
|
2011-07-18 07:12:16 +00:00
|
|
|
|
2013-06-05 13:51:58 +00:00
|
|
|
GST_DEBUG_OBJECT (demux,
|
2012-07-13 14:56:11 +00:00
|
|
|
"stream PTS %" GST_TIME_FORMAT " DTS %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (stream->pts), GST_TIME_ARGS (stream->dts));
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
/* Remove PES headers */
|
2012-05-21 15:53:37 +00:00
|
|
|
GST_DEBUG ("Moving data forward by %d bytes (packet_size:%d, have:%d)",
|
|
|
|
header.header_size, header.packet_length, length);
|
2012-07-12 08:13:50 +00:00
|
|
|
stream->expected_size = header.packet_length;
|
|
|
|
if (stream->expected_size) {
|
|
|
|
if (G_LIKELY (stream->expected_size > header.header_size)) {
|
|
|
|
stream->expected_size -= header.header_size;
|
|
|
|
} else {
|
|
|
|
/* next packet will have to complete this one */
|
|
|
|
GST_ERROR ("invalid header and packet size combination");
|
|
|
|
stream->expected_size = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-05-21 15:53:37 +00:00
|
|
|
data += header.header_size;
|
|
|
|
length -= header.header_size;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-05-21 15:53:37 +00:00
|
|
|
/* Create the output buffer */
|
|
|
|
if (stream->expected_size)
|
2013-09-16 09:42:48 +00:00
|
|
|
stream->allocated_size = MAX (stream->expected_size, length);
|
2012-05-21 15:53:37 +00:00
|
|
|
else
|
2013-09-16 09:42:48 +00:00
|
|
|
stream->allocated_size = MAX (8192, length);
|
|
|
|
|
2012-05-21 15:53:37 +00:00
|
|
|
g_assert (stream->data == NULL);
|
|
|
|
stream->data = g_malloc (stream->allocated_size);
|
|
|
|
memcpy (stream->data, data, length);
|
|
|
|
stream->current_size = length;
|
|
|
|
|
|
|
|
stream->state = PENDING_PACKET_BUFFER;
|
|
|
|
|
|
|
|
return;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
discont:
|
|
|
|
stream->state = PENDING_PACKET_DISCONT;
|
2012-05-21 15:53:37 +00:00
|
|
|
return;
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ONLY CALL THIS:
|
|
|
|
* * WITH packet->payload != NULL
|
|
|
|
* * WITH pending/current flushed out if beginning of new PES packet
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
gst_ts_demux_queue_data (GstTSDemux * demux, TSDemuxStream * stream,
|
|
|
|
MpegTSPacketizerPacket * packet)
|
|
|
|
{
|
2012-05-21 15:53:37 +00:00
|
|
|
guint8 *data;
|
|
|
|
guint size;
|
2013-06-23 06:43:23 +00:00
|
|
|
guint8 cc = FLAGS_CONTINUITY_COUNTER (packet->scram_afc_cc);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2013-05-24 08:59:55 +00:00
|
|
|
GST_LOG ("pid: 0x%04x state:%d", stream->stream.pid, stream->state);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-05-21 15:53:37 +00:00
|
|
|
size = packet->data_end - packet->payload;
|
|
|
|
data = packet->payload;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2013-04-11 11:08:57 +00:00
|
|
|
if (stream->continuity_counter == CONTINUITY_UNSET) {
|
2013-06-23 06:43:23 +00:00
|
|
|
GST_DEBUG ("CONTINUITY: Initialize to %d", cc);
|
|
|
|
} else if ((cc == stream->continuity_counter + 1 ||
|
|
|
|
(stream->continuity_counter == MAX_CONTINUITY && cc == 0))) {
|
|
|
|
GST_LOG ("CONTINUITY: Got expected %d", cc);
|
2013-04-11 11:08:57 +00:00
|
|
|
} else {
|
2013-10-11 09:23:16 +00:00
|
|
|
GST_WARNING ("CONTINUITY: Mismatch packet %d, stream %d",
|
2013-06-23 06:43:23 +00:00
|
|
|
cc, stream->continuity_counter);
|
2013-04-11 11:08:57 +00:00
|
|
|
stream->state = PENDING_PACKET_DISCONT;
|
|
|
|
}
|
2013-06-23 06:43:23 +00:00
|
|
|
stream->continuity_counter = cc;
|
2013-04-11 11:08:57 +00:00
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
if (stream->state == PENDING_PACKET_EMPTY) {
|
|
|
|
if (G_UNLIKELY (!packet->payload_unit_start_indicator)) {
|
|
|
|
stream->state = PENDING_PACKET_DISCONT;
|
2013-05-23 12:56:40 +00:00
|
|
|
GST_DEBUG ("Didn't get the first packet of this PES");
|
2011-02-16 16:57:42 +00:00
|
|
|
} else {
|
|
|
|
GST_LOG ("EMPTY=>HEADER");
|
|
|
|
stream->state = PENDING_PACKET_HEADER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-30 17:19:12 +00:00
|
|
|
switch (stream->state) {
|
|
|
|
case PENDING_PACKET_HEADER:
|
|
|
|
{
|
2012-05-21 15:53:37 +00:00
|
|
|
GST_LOG ("HEADER: Parsing PES header");
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-03-30 17:19:12 +00:00
|
|
|
/* parse the header */
|
2012-05-21 15:53:37 +00:00
|
|
|
gst_ts_demux_parse_pes_header (demux, stream, data, size, packet->offset);
|
2012-03-30 17:19:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PENDING_PACKET_BUFFER:
|
|
|
|
{
|
2012-05-21 15:53:37 +00:00
|
|
|
GST_LOG ("BUFFER: appending data");
|
|
|
|
if (G_UNLIKELY (stream->current_size + size > stream->allocated_size)) {
|
|
|
|
GST_LOG ("resizing buffer");
|
2013-09-16 09:42:48 +00:00
|
|
|
do {
|
|
|
|
stream->allocated_size *= 2;
|
|
|
|
} while (stream->current_size + size > stream->allocated_size);
|
2012-05-21 15:53:37 +00:00
|
|
|
stream->data = g_realloc (stream->data, stream->allocated_size);
|
|
|
|
}
|
|
|
|
memcpy (stream->data + stream->current_size, data, size);
|
|
|
|
stream->current_size += size;
|
2012-03-30 17:19:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PENDING_PACKET_DISCONT:
|
|
|
|
{
|
2012-05-21 15:53:37 +00:00
|
|
|
GST_LOG ("DISCONT: not storing/pushing");
|
|
|
|
if (G_UNLIKELY (stream->data)) {
|
|
|
|
g_free (stream->data);
|
|
|
|
stream->data = NULL;
|
|
|
|
}
|
2013-04-11 11:08:57 +00:00
|
|
|
stream->continuity_counter = CONTINUITY_UNSET;
|
2012-03-30 17:19:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-16 11:44:00 +00:00
|
|
|
static void
|
|
|
|
calculate_and_push_newsegment (GstTSDemux * demux, TSDemuxStream * stream)
|
|
|
|
{
|
|
|
|
MpegTSBase *base = (MpegTSBase *) demux;
|
2012-03-01 17:05:17 +00:00
|
|
|
GstClockTime lowest_pts = GST_CLOCK_TIME_NONE;
|
2012-03-02 16:11:33 +00:00
|
|
|
GstClockTime firstts = 0;
|
2011-08-16 22:05:14 +00:00
|
|
|
GList *tmp;
|
2011-07-16 11:44:00 +00:00
|
|
|
|
2011-08-16 22:05:14 +00:00
|
|
|
GST_DEBUG ("Creating new newsegment for stream %p", stream);
|
2011-07-16 11:44:00 +00:00
|
|
|
|
2012-03-01 17:05:17 +00:00
|
|
|
/* 1) If we need to calculate an update newsegment, do it
|
|
|
|
* 2) If we need to calculate a new newsegment, do it
|
|
|
|
* 3) If an update_segment is valid, push it
|
|
|
|
* 4) If a newsegment is valid, push it */
|
2011-07-16 11:44:00 +00:00
|
|
|
|
2012-03-01 17:05:17 +00:00
|
|
|
/* Speedup : if we don't need to calculate anything, go straight to pushing */
|
|
|
|
if (!demux->calculate_update_segment && demux->segment_event)
|
|
|
|
goto push_new_segment;
|
|
|
|
|
|
|
|
/* Calculate the 'new_start' value, used for both updates and newsegment */
|
2011-08-16 22:05:14 +00:00
|
|
|
for (tmp = demux->program->stream_list; tmp; tmp = tmp->next) {
|
|
|
|
TSDemuxStream *pstream = (TSDemuxStream *) tmp->data;
|
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (pstream->first_dts)) {
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (lowest_pts)
|
|
|
|
|| pstream->first_dts < lowest_pts)
|
|
|
|
lowest_pts = pstream->first_dts;
|
2011-11-08 19:19:41 +00:00
|
|
|
}
|
2012-03-01 17:05:17 +00:00
|
|
|
}
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (lowest_pts))
|
2013-04-26 13:39:30 +00:00
|
|
|
firstts = lowest_pts;
|
2012-03-01 17:05:17 +00:00
|
|
|
GST_DEBUG ("lowest_pts %" G_GUINT64_FORMAT " => clocktime %" GST_TIME_FORMAT,
|
|
|
|
lowest_pts, GST_TIME_ARGS (firstts));
|
|
|
|
|
|
|
|
if (demux->calculate_update_segment) {
|
|
|
|
GST_DEBUG ("Calculating update segment");
|
|
|
|
/* If we have a valid segment, create an update of that */
|
|
|
|
if (demux->segment.format == GST_FORMAT_TIME) {
|
2012-04-19 12:20:52 +00:00
|
|
|
GstSegment update_segment;
|
2012-03-01 17:05:17 +00:00
|
|
|
GST_DEBUG ("Re-using segment " SEGMENT_FORMAT,
|
|
|
|
SEGMENT_ARGS (demux->segment));
|
2012-04-19 12:20:52 +00:00
|
|
|
gst_segment_copy_into (&demux->segment, &update_segment);
|
|
|
|
update_segment.stop = firstts;
|
|
|
|
demux->update_segment = gst_event_new_segment (&update_segment);
|
2012-03-01 17:05:17 +00:00
|
|
|
}
|
|
|
|
demux->calculate_update_segment = FALSE;
|
2011-07-16 11:44:00 +00:00
|
|
|
}
|
|
|
|
|
2013-05-28 14:14:42 +00:00
|
|
|
if (demux->segment.format != GST_FORMAT_TIME) {
|
|
|
|
/* It will happen only if it's first program or after flushes. */
|
2012-03-01 17:05:17 +00:00
|
|
|
GST_DEBUG ("Calculating actual segment");
|
2013-05-28 14:14:42 +00:00
|
|
|
if (base->segment.format == GST_FORMAT_TIME) {
|
|
|
|
/* Try to recover segment info from base if it's in TIME format */
|
|
|
|
demux->segment = base->segment;
|
|
|
|
} else {
|
2012-04-19 12:20:52 +00:00
|
|
|
/* Start from the first ts/pts */
|
2013-05-28 14:14:42 +00:00
|
|
|
gst_segment_init (&demux->segment, GST_FORMAT_TIME);
|
|
|
|
demux->segment.start = firstts;
|
|
|
|
demux->segment.stop = GST_CLOCK_TIME_NONE;
|
|
|
|
demux->segment.position = firstts;
|
|
|
|
demux->segment.time = firstts;
|
2013-07-24 13:50:14 +00:00
|
|
|
demux->segment.rate = demux->rate;
|
2012-04-05 04:18:28 +00:00
|
|
|
}
|
2012-03-01 17:05:17 +00:00
|
|
|
}
|
2011-07-16 11:44:00 +00:00
|
|
|
|
2013-07-15 09:15:11 +00:00
|
|
|
if (!demux->segment_event) {
|
2013-05-28 14:14:42 +00:00
|
|
|
demux->segment_event = gst_event_new_segment (&demux->segment);
|
2013-07-15 09:15:11 +00:00
|
|
|
GST_EVENT_SEQNUM (demux->segment_event) = base->last_seek_seqnum;
|
|
|
|
}
|
2013-05-28 14:14:42 +00:00
|
|
|
|
2012-03-01 17:05:17 +00:00
|
|
|
push_new_segment:
|
|
|
|
if (demux->update_segment) {
|
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Pushing update segment");
|
|
|
|
gst_event_ref (demux->update_segment);
|
|
|
|
gst_pad_push_event (stream->pad, demux->update_segment);
|
|
|
|
}
|
2011-07-16 11:44:00 +00:00
|
|
|
|
2012-03-01 17:05:17 +00:00
|
|
|
if (demux->segment_event) {
|
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Pushing newsegment event");
|
|
|
|
gst_event_ref (demux->segment_event);
|
|
|
|
gst_pad_push_event (stream->pad, demux->segment_event);
|
|
|
|
}
|
|
|
|
|
2014-02-25 01:43:56 +00:00
|
|
|
if (demux->global_tags) {
|
|
|
|
gst_pad_push_event (stream->pad,
|
|
|
|
gst_event_new_tag (gst_tag_list_ref (demux->global_tags)));
|
|
|
|
}
|
|
|
|
|
2012-04-10 10:36:15 +00:00
|
|
|
/* Push pending tags */
|
|
|
|
if (stream->taglist) {
|
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Sending tags %" GST_PTR_FORMAT,
|
|
|
|
stream->taglist);
|
2012-07-27 22:32:58 +00:00
|
|
|
gst_pad_push_event (stream->pad, gst_event_new_tag (stream->taglist));
|
2012-04-10 10:36:15 +00:00
|
|
|
stream->taglist = NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-01 17:05:17 +00:00
|
|
|
stream->need_newsegment = FALSE;
|
2011-07-16 11:44:00 +00:00
|
|
|
}
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_ts_demux_push_pending_data (GstTSDemux * demux, TSDemuxStream * stream)
|
|
|
|
{
|
|
|
|
GstFlowReturn res = GST_FLOW_OK;
|
2013-06-05 13:51:58 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2011-02-16 16:57:42 +00:00
|
|
|
MpegTSBaseStream *bs = (MpegTSBaseStream *) stream;
|
2013-06-05 13:51:58 +00:00
|
|
|
#endif
|
2012-05-21 15:53:37 +00:00
|
|
|
GstBuffer *buffer = NULL;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2011-11-08 19:19:41 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
|
|
|
"stream:%p, pid:0x%04x stream_type:%d state:%d", stream, bs->pid,
|
|
|
|
bs->stream_type, stream->state);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-05-21 15:53:37 +00:00
|
|
|
if (G_UNLIKELY (stream->data == NULL)) {
|
|
|
|
GST_LOG ("stream->data == NULL");
|
2011-02-16 16:57:42 +00:00
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (stream->state == PENDING_PACKET_EMPTY)) {
|
|
|
|
GST_LOG ("EMPTY: returning");
|
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
|
2012-03-30 17:19:12 +00:00
|
|
|
if (G_UNLIKELY (stream->state != PENDING_PACKET_BUFFER)) {
|
|
|
|
GST_LOG ("state:%d, returning", stream->state);
|
2011-07-16 11:44:00 +00:00
|
|
|
goto beach;
|
2012-03-30 17:19:12 +00:00
|
|
|
}
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
if (G_UNLIKELY (demux->program == NULL)) {
|
|
|
|
GST_LOG_OBJECT (demux, "No program");
|
2012-05-21 15:53:37 +00:00
|
|
|
g_free (stream->data);
|
2011-07-16 11:44:00 +00:00
|
|
|
goto beach;
|
|
|
|
}
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
buffer = gst_buffer_new_wrapped (stream->data, stream->current_size);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (stream->pending_ts && !check_pending_buffers (demux, stream))) {
|
|
|
|
PendingBuffer *pend;
|
|
|
|
pend = g_slice_new0 (PendingBuffer);
|
|
|
|
pend->buffer = buffer;
|
|
|
|
pend->pts = stream->raw_pts;
|
|
|
|
pend->dts = stream->raw_dts;
|
|
|
|
stream->pending = g_list_append (stream->pending, pend);
|
|
|
|
GST_DEBUG ("Not enough information to push buffers yet, storing buffer");
|
2012-10-17 23:47:57 +00:00
|
|
|
goto beach;
|
|
|
|
}
|
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
if (G_UNLIKELY (!stream->active))
|
|
|
|
activate_pad_for_stream (demux, stream);
|
|
|
|
|
2012-03-01 17:05:17 +00:00
|
|
|
if (G_UNLIKELY (stream->need_newsegment))
|
2011-07-16 11:44:00 +00:00
|
|
|
calculate_and_push_newsegment (demux, stream);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2013-07-29 06:10:07 +00:00
|
|
|
/* FIXME : Push pending buffers if any */
|
|
|
|
if (G_UNLIKELY (stream->pending)) {
|
|
|
|
GList *tmp;
|
|
|
|
for (tmp = stream->pending; tmp; tmp = tmp->next) {
|
|
|
|
PendingBuffer *pend = (PendingBuffer *) tmp->data;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
|
|
|
"Pushing pending buffer PTS:%" GST_TIME_FORMAT " DTS:%"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_PTS (pend->buffer)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DTS (pend->buffer)));
|
|
|
|
|
|
|
|
res = gst_pad_push (stream->pad, pend->buffer);
|
|
|
|
g_slice_free (PendingBuffer, pend);
|
|
|
|
}
|
|
|
|
g_list_free (stream->pending);
|
|
|
|
stream->pending = NULL;
|
|
|
|
}
|
2011-11-08 19:19:41 +00:00
|
|
|
|
2012-02-24 16:53:52 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "stream->pts %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (stream->pts));
|
2012-05-21 15:53:37 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (stream->pts))
|
2013-04-26 13:39:30 +00:00
|
|
|
GST_BUFFER_PTS (buffer) = stream->pts;
|
2012-05-21 15:53:37 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (stream->dts))
|
2013-04-26 13:39:30 +00:00
|
|
|
GST_BUFFER_DTS (buffer) = stream->dts;
|
2011-11-08 19:19:41 +00:00
|
|
|
|
2011-07-16 11:44:00 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad,
|
2012-07-13 14:56:11 +00:00
|
|
|
"Pushing buffer with PTS: %" GST_TIME_FORMAT " , DTS: %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (buffer)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DTS (buffer)));
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-05-21 15:53:37 +00:00
|
|
|
res = gst_pad_push (stream->pad, buffer);
|
2011-07-16 11:44:00 +00:00
|
|
|
GST_DEBUG_OBJECT (stream->pad, "Returned %s", gst_flow_get_name (res));
|
|
|
|
res = tsdemux_combine_flows (demux, stream, res);
|
|
|
|
GST_DEBUG_OBJECT (stream->pad, "combined %s", gst_flow_get_name (res));
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
beach:
|
|
|
|
/* Reset everything */
|
2012-03-01 17:05:17 +00:00
|
|
|
GST_LOG ("Resetting to EMPTY, returning %s", gst_flow_get_name (res));
|
2011-02-16 16:57:42 +00:00
|
|
|
stream->state = PENDING_PACKET_EMPTY;
|
2012-05-21 15:53:37 +00:00
|
|
|
stream->data = NULL;
|
2012-03-05 08:38:57 +00:00
|
|
|
stream->expected_size = 0;
|
|
|
|
stream->current_size = 0;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_ts_demux_handle_packet (GstTSDemux * demux, TSDemuxStream * stream,
|
2013-07-03 11:57:38 +00:00
|
|
|
MpegTSPacketizerPacket * packet, GstMpegTsSection * section)
|
2011-02-16 16:57:42 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn res = GST_FLOW_OK;
|
|
|
|
|
2012-05-21 15:53:37 +00:00
|
|
|
GST_LOG ("pid 0x%04x pusi:%d, afc:%d, cont:%d, payload:%p", packet->pid,
|
2013-06-23 06:43:23 +00:00
|
|
|
packet->payload_unit_start_indicator, packet->scram_afc_cc & 0x30,
|
|
|
|
FLAGS_CONTINUITY_COUNTER (packet->scram_afc_cc), packet->payload);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-05-16 14:15:58 +00:00
|
|
|
if (G_UNLIKELY (packet->payload_unit_start_indicator) &&
|
2013-06-23 06:43:23 +00:00
|
|
|
FLAGS_HAS_PAYLOAD (packet->scram_afc_cc))
|
2011-02-16 16:57:42 +00:00
|
|
|
/* Flush previous data */
|
|
|
|
res = gst_ts_demux_push_pending_data (demux, stream);
|
|
|
|
|
2012-05-18 08:15:15 +00:00
|
|
|
if (packet->payload && (res == GST_FLOW_OK || res == GST_FLOW_NOT_LINKED)
|
|
|
|
&& stream->pad) {
|
2011-02-16 16:57:42 +00:00
|
|
|
gst_ts_demux_queue_data (demux, stream, packet);
|
2013-05-24 08:59:55 +00:00
|
|
|
GST_LOG ("current_size:%d, expected_size:%d",
|
2012-03-05 08:38:57 +00:00
|
|
|
stream->current_size, stream->expected_size);
|
|
|
|
/* Finally check if the data we queued completes a packet */
|
2012-07-11 18:34:05 +00:00
|
|
|
if (stream->expected_size && stream->current_size == stream->expected_size) {
|
|
|
|
GST_LOG ("pushing complete packet");
|
2012-03-05 08:38:57 +00:00
|
|
|
res = gst_ts_demux_push_pending_data (demux, stream);
|
2012-07-11 18:34:05 +00:00
|
|
|
}
|
2012-05-21 15:53:37 +00:00
|
|
|
}
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:44:08 +00:00
|
|
|
static void
|
2013-05-24 08:59:59 +00:00
|
|
|
gst_ts_demux_flush (MpegTSBase * base, gboolean hard)
|
2011-08-26 22:44:08 +00:00
|
|
|
{
|
|
|
|
GstTSDemux *demux = GST_TS_DEMUX_CAST (base);
|
|
|
|
|
|
|
|
gst_ts_demux_flush_streams (demux);
|
2012-11-13 21:40:25 +00:00
|
|
|
|
|
|
|
if (demux->segment_event) {
|
|
|
|
gst_event_unref (demux->segment_event);
|
|
|
|
demux->segment_event = NULL;
|
|
|
|
}
|
|
|
|
demux->calculate_update_segment = FALSE;
|
2014-02-25 01:43:56 +00:00
|
|
|
if (demux->global_tags) {
|
|
|
|
gst_tag_list_unref (demux->global_tags);
|
|
|
|
demux->global_tags = NULL;
|
|
|
|
}
|
2013-05-24 08:59:59 +00:00
|
|
|
if (hard) {
|
|
|
|
/* For pull mode seeks the current segment needs to be preserved */
|
2013-07-24 13:50:14 +00:00
|
|
|
demux->rate = 1.0;
|
2013-05-24 08:59:59 +00:00
|
|
|
gst_segment_init (&demux->segment, GST_FORMAT_UNDEFINED);
|
|
|
|
}
|
2011-08-26 22:44:08 +00:00
|
|
|
}
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_ts_demux_push (MpegTSBase * base, MpegTSPacketizerPacket * packet,
|
2013-07-03 11:57:38 +00:00
|
|
|
GstMpegTsSection * section)
|
2011-02-16 16:57:42 +00:00
|
|
|
{
|
|
|
|
GstTSDemux *demux = GST_TS_DEMUX_CAST (base);
|
|
|
|
TSDemuxStream *stream = NULL;
|
|
|
|
GstFlowReturn res = GST_FLOW_OK;
|
|
|
|
|
|
|
|
if (G_LIKELY (demux->program)) {
|
|
|
|
stream = (TSDemuxStream *) demux->program->streams[packet->pid];
|
|
|
|
|
|
|
|
if (stream) {
|
|
|
|
res = gst_ts_demux_handle_packet (demux, stream, packet, section);
|
2012-05-21 15:53:37 +00:00
|
|
|
}
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_ts_demux_plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
GST_DEBUG_CATEGORY_INIT (ts_demux_debug, "tsdemux", 0,
|
|
|
|
"MPEG transport stream demuxer");
|
2011-07-18 07:12:16 +00:00
|
|
|
init_pes_parser ();
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
return gst_element_register (plugin, "tsdemux",
|
2012-03-05 08:46:17 +00:00
|
|
|
GST_RANK_PRIMARY, GST_TYPE_TS_DEMUX);
|
2011-02-16 16:57:42 +00:00
|
|
|
}
|