/* * mpegtsbase.h - GStreamer MPEG transport stream base class * Copyright (C) 2009 Edward Hervey * 2007 Alessandro Decina * * Authors: * Alessandro Decina * Edward Hervey * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #ifndef GST_MPEG_TS_BASE_H #define GST_MPEG_TS_BASE_H #include #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)) 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; gint patcount; /* Pending Tags for the program */ GstTagList *tags; guint event_id; }; typedef enum { BASE_MODE_SCANNING, BASE_MODE_SEEKING, BASE_MODE_STREAMING } MpegTSBaseMode; struct _MpegTSBase { GstElement element; GstPad *sinkpad; /* pull-based behaviour */ MpegTSBaseMode mode; /* location of first sync point */ guint64 initial_sync_point; /* 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; /* arrays that say whether a pid is a known psi pid or a pes pid * FIXME: Make these bit arrays so we can make them 8 times smaller */ gboolean *known_psi; gboolean *is_pes; 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; /*Offset from the origin to the first PAT (pullmode) */ guint64 first_pat_offset; }; struct _MpegTSBaseClass { GstElementClass parent_class; /* Virtual methods */ GstFlowReturn (*push) (MpegTSBase *base, MpegTSPacketizerPacket *packet, MpegTSPacketizerSection * section); gboolean (*push_event) (MpegTSBase *base, GstEvent * event); /* 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 */ GstFlowReturn (*find_timestamps) (MpegTSBase * base, guint64 initoff, guint64 *offset); /* 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); }; GType mpegts_base_get_type(void); MpegTSBaseProgram *mpegts_base_get_program (MpegTSBase * base, gint program_number); MpegTSBaseProgram *mpegts_base_add_program (MpegTSBase * base, gint program_number, guint16 pmt_pid); guint8 *mpegts_get_descriptor_from_stream (MpegTSBaseStream * stream, guint8 tag); guint8 *mpegts_get_descriptor_from_program (MpegTSBaseProgram * program, guint8 tag); gboolean gst_mpegtsbase_plugin_init (GstPlugin * plugin); gboolean mpegts_base_is_psi (MpegTSBase * base, MpegTSPacketizerPacket * packet); gboolean mpegts_base_handle_psi (MpegTSBase * base, MpegTSPacketizerSection * section); void mpegts_base_program_remove_stream (MpegTSBase * base, MpegTSBaseProgram * program, guint16 pid); void mpegts_base_remove_program(MpegTSBase *base, gint program_number); G_END_DECLS #endif /* GST_MPEG_TS_BASE_H */