2011-02-16 16:57:42 +00:00
|
|
|
/*
|
|
|
|
* mpegtsbase.h - GStreamer MPEG transport stream base class
|
|
|
|
* Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
|
|
|
|
* 2007 Alessandro Decina
|
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.
|
2011-02-16 16:57:42 +00:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Alessandro Decina <alessandro@nnva.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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GST_MPEG_TS_BASE_H
|
|
|
|
#define GST_MPEG_TS_BASE_H
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include "mpegtspacketizer.h"
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
#define GST_TYPE_MPEGTS_BASE \
|
|
|
|
(mpegts_base_get_type())
|
|
|
|
#define GST_MPEGTS_BASE(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MPEGTS_BASE,MpegTSBase))
|
|
|
|
#define GST_MPEGTS_BASE_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MPEGTS_BASE,MpegTSBaseClass))
|
|
|
|
#define GST_IS_MPEGTS_BASE(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MPEGTS_BASE))
|
|
|
|
#define GST_IS_MPEGTS_BASE_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MPEGTS_BASE))
|
|
|
|
#define GST_MPEGTS_BASE_GET_CLASS(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_MPEGTS_BASE, MpegTSBaseClass))
|
|
|
|
|
2012-02-29 09:33:00 +00:00
|
|
|
#define MPEG_TS_BASE_PACKETIZER(b) (((MpegTSBase*)b)->packetizer)
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
typedef struct _MpegTSBase MpegTSBase;
|
|
|
|
typedef struct _MpegTSBaseClass MpegTSBaseClass;
|
|
|
|
typedef struct _MpegTSBaseStream MpegTSBaseStream;
|
|
|
|
typedef struct _MpegTSBaseProgram MpegTSBaseProgram;
|
|
|
|
|
|
|
|
struct _MpegTSBaseStream
|
|
|
|
{
|
|
|
|
guint16 pid;
|
|
|
|
guint8 stream_type;
|
|
|
|
GstStructure* stream_info;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _MpegTSBaseProgram
|
|
|
|
{
|
|
|
|
gint program_number;
|
|
|
|
guint16 pmt_pid;
|
|
|
|
guint16 pcr_pid;
|
|
|
|
GstStructure *pmt_info;
|
|
|
|
MpegTSBaseStream **streams;
|
2011-07-19 07:34:37 +00:00
|
|
|
GList *stream_list;
|
2011-02-16 16:57:42 +00:00
|
|
|
gint patcount;
|
|
|
|
|
|
|
|
/* Pending Tags for the program */
|
|
|
|
GstTagList *tags;
|
|
|
|
guint event_id;
|
2011-07-21 11:26:55 +00:00
|
|
|
|
|
|
|
/* TRUE if the program is currently being used */
|
|
|
|
gboolean active;
|
2012-03-01 17:05:17 +00:00
|
|
|
/* TRUE if this is the first program created */
|
|
|
|
gboolean initial_program;
|
2011-02-16 16:57:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum {
|
2011-07-16 11:47:45 +00:00
|
|
|
/* PULL MODE */
|
|
|
|
BASE_MODE_SCANNING, /* Looking for PAT/PMT */
|
|
|
|
BASE_MODE_SEEKING, /* Seeking */
|
|
|
|
BASE_MODE_STREAMING, /* Normal mode (pushing out data) */
|
|
|
|
|
|
|
|
/* PUSH MODE */
|
2011-02-22 11:33:56 +00:00
|
|
|
BASE_MODE_PUSHING
|
2011-02-16 16:57:42 +00:00
|
|
|
} MpegTSBaseMode;
|
|
|
|
|
|
|
|
struct _MpegTSBase {
|
|
|
|
GstElement element;
|
|
|
|
|
|
|
|
GstPad *sinkpad;
|
|
|
|
|
|
|
|
/* pull-based behaviour */
|
|
|
|
MpegTSBaseMode mode;
|
|
|
|
|
|
|
|
/* Current pull offset (also set by seek handler) */
|
|
|
|
guint64 seek_offset;
|
|
|
|
|
|
|
|
/* Cached packetsize */
|
|
|
|
guint16 packetsize;
|
|
|
|
|
|
|
|
/* the following vars must be protected with the OBJECT_LOCK as they can be
|
|
|
|
* accessed from the application thread and the streaming thread */
|
|
|
|
GHashTable *programs;
|
|
|
|
|
|
|
|
GstStructure *pat;
|
|
|
|
MpegTSPacketizer2 *packetizer;
|
|
|
|
|
2011-07-19 06:45:51 +00:00
|
|
|
/* arrays that say whether a pid is a known psi pid or a pes pid */
|
|
|
|
/* Use MPEGTS_BIT_* to set/unset/check the values */
|
|
|
|
guint8 *known_psi;
|
|
|
|
guint8 *is_pes;
|
2011-02-16 16:57:42 +00:00
|
|
|
|
|
|
|
gboolean disposed;
|
|
|
|
|
|
|
|
/* size of the MpegTSBaseProgram structure, can be overridden
|
|
|
|
* by subclasses if they have their own MpegTSBaseProgram subclasses. */
|
|
|
|
gsize program_size;
|
|
|
|
|
|
|
|
/* size of the MpegTSBaseStream structure, can be overridden
|
|
|
|
* by subclasses if they have their own MpegTSBaseStream subclasses */
|
|
|
|
gsize stream_size;
|
|
|
|
|
2011-07-14 20:08:56 +00:00
|
|
|
/* Whether we saw a PAT yet */
|
|
|
|
gboolean seen_pat;
|
|
|
|
|
2011-11-08 08:44:18 +00:00
|
|
|
/* Whether upstream is live or not */
|
|
|
|
gboolean upstream_live;
|
|
|
|
/* Whether we queried the upstream latency or not */
|
2012-03-03 15:47:01 +00:00
|
|
|
gboolean queried_latency;
|
2011-08-16 19:54:04 +00:00
|
|
|
|
2011-07-15 10:08:40 +00:00
|
|
|
/* Upstream segment */
|
|
|
|
GstSegment segment;
|
2011-02-16 16:57:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MpegTSBaseClass {
|
|
|
|
GstElementClass parent_class;
|
|
|
|
|
|
|
|
/* Virtual methods */
|
2011-02-22 11:33:56 +00:00
|
|
|
void (*reset) (MpegTSBase *base);
|
2011-02-16 16:57:42 +00:00
|
|
|
GstFlowReturn (*push) (MpegTSBase *base, MpegTSPacketizerPacket *packet, MpegTSPacketizerSection * section);
|
2012-04-20 08:50:19 +00:00
|
|
|
/* takes ownership of @event */
|
2011-02-16 16:57:42 +00:00
|
|
|
gboolean (*push_event) (MpegTSBase *base, GstEvent * event);
|
2011-07-16 11:47:45 +00:00
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
/* program_started gets called when program's pmt arrives for first time */
|
|
|
|
void (*program_started) (MpegTSBase *base, MpegTSBaseProgram *program);
|
|
|
|
/* program_stopped gets called when pat no longer has program's pmt */
|
|
|
|
void (*program_stopped) (MpegTSBase *base, MpegTSBaseProgram *program);
|
|
|
|
|
|
|
|
/* stream_added is called whenever a new stream has been identified */
|
|
|
|
void (*stream_added) (MpegTSBase *base, MpegTSBaseStream *stream, MpegTSBaseProgram *program);
|
|
|
|
/* stream_removed is called whenever a stream is no longer referenced */
|
|
|
|
void (*stream_removed) (MpegTSBase *base, MpegTSBaseStream *stream);
|
|
|
|
|
|
|
|
/* find_timestamps is called to find PCR */
|
2011-07-16 11:47:45 +00:00
|
|
|
GstFlowReturn (*find_timestamps) (MpegTSBase * base, guint64 initoff, guint64 *offset);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2011-02-22 11:33:56 +00:00
|
|
|
/* seek is called to wait for seeking */
|
2012-02-29 09:33:00 +00:00
|
|
|
GstFlowReturn (*seek) (MpegTSBase * base, GstEvent * event);
|
2011-02-22 11:33:56 +00:00
|
|
|
|
2011-08-26 22:44:08 +00:00
|
|
|
/* flush all streams */
|
|
|
|
void (*flush) (MpegTSBase * base);
|
|
|
|
|
2012-06-26 16:51:21 +00:00
|
|
|
/* Notifies subclasses input buffer has been handled */
|
|
|
|
GstFlowReturn (*input_done) (MpegTSBase *base, GstBuffer *buffer);
|
|
|
|
|
2011-02-16 16:57:42 +00:00
|
|
|
/* signals */
|
|
|
|
void (*pat_info) (GstStructure *pat);
|
|
|
|
void (*pmt_info) (GstStructure *pmt);
|
|
|
|
void (*nit_info) (GstStructure *nit);
|
|
|
|
void (*sdt_info) (GstStructure *sdt);
|
|
|
|
void (*eit_info) (GstStructure *eit);
|
|
|
|
};
|
|
|
|
|
2012-05-25 12:15:44 +00:00
|
|
|
#define MPEGTS_BIT_SET(field, offs) ((field)[(offs) >> 3] |= (1 << ((offs) & 0x7)))
|
|
|
|
#define MPEGTS_BIT_UNSET(field, offs) ((field)[(offs) >> 3] &= ~(1 << ((offs) & 0x7)))
|
|
|
|
#define MPEGTS_BIT_IS_SET(field, offs) ((field)[(offs) >> 3] & (1 << ((offs) & 0x7)))
|
2011-07-19 06:45:51 +00:00
|
|
|
|
2012-07-13 14:22:11 +00:00
|
|
|
G_GNUC_INTERNAL GType mpegts_base_get_type(void);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-07-13 14:22:11 +00:00
|
|
|
G_GNUC_INTERNAL MpegTSBaseProgram *mpegts_base_get_program (MpegTSBase * base, gint program_number);
|
|
|
|
G_GNUC_INTERNAL MpegTSBaseProgram *mpegts_base_add_program (MpegTSBase * base, gint program_number, guint16 pmt_pid);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-07-13 14:22:11 +00:00
|
|
|
G_GNUC_INTERNAL guint8 *mpegts_get_descriptor_from_stream (MpegTSBaseStream * stream, guint8 tag);
|
|
|
|
G_GNUC_INTERNAL guint8 *mpegts_get_descriptor_from_program (MpegTSBaseProgram * program, guint8 tag);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-07-13 14:22:11 +00:00
|
|
|
G_GNUC_INTERNAL gboolean
|
2011-02-22 11:33:56 +00:00
|
|
|
mpegts_base_handle_seek_event(MpegTSBase * base, GstPad * pad, GstEvent * event);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-07-13 14:22:11 +00:00
|
|
|
G_GNUC_INTERNAL gboolean gst_mpegtsbase_plugin_init (GstPlugin * plugin);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-07-13 14:22:11 +00:00
|
|
|
G_GNUC_INTERNAL gboolean mpegts_base_handle_psi (MpegTSBase * base, MpegTSPacketizerSection * section);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-07-13 14:22:11 +00:00
|
|
|
G_GNUC_INTERNAL void mpegts_base_program_remove_stream (MpegTSBase * base, MpegTSBaseProgram * program, guint16 pid);
|
2011-02-16 16:57:42 +00:00
|
|
|
|
2012-07-13 14:22:11 +00:00
|
|
|
G_GNUC_INTERNAL void mpegts_base_remove_program(MpegTSBase *base, gint program_number);
|
2011-02-16 16:57:42 +00:00
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* GST_MPEG_TS_BASE_H */
|