--- gst-1.2.2/gst-plugins-bad-1.2.2/gst/mpegtsdemux/mpegtsbase.c	2013-09-24 15:06:21.000000000 +0200
+++ mpegtsdemux_prepared4patch/mpegtsbase.c	2014-01-03 09:59:41.006769718 +0100
@@ -37,6 +37,7 @@
 
 #include <glib.h>
 
+#include <gst/gst.h>
 #include <gst/gst-i18n-plugin.h>
 #include "mpegtsbase.h"
 #include "gstmpegdesc.h"
@@ -65,7 +66,11 @@
 enum
 {
   PROP_0,
-  PROP_PARSE_PRIVATE_SECTIONS,
+	PROP_PARSE_PRIVATE_SECTIONS,
+	/* <AWOX> */
+	PROP_ADD_PAT,
+	PROP_ADD_PMT,
+	/* </AWOX> */
   /* FILL ME */
 };
 
@@ -91,6 +96,16 @@
 static gboolean remove_each_program (gpointer key, MpegTSBaseProgram * program,
     MpegTSBase * base);
 
+/* <AWOX> */
+static gboolean
+mpegts_base_apply_pat (MpegTSBase * base, GstMpegTsSection * section);
+static gboolean
+mpegts_base_apply_pmt (MpegTSBase * base, GstMpegTsSection * section);
+static void
+mpegts_base_handle_psi (MpegTSBase * base, GstMpegTsSection * section);
+/* </AWOX> */
+
+
 static void
 _extra_init (void)
 {
@@ -129,8 +144,34 @@
           "Parse private sections", FALSE,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  /* <AWOX> */
+  g_object_class_install_property (gobject_class, PROP_ADD_PAT,
+	g_param_spec_boxed( "add-pat", "Add a PAT entry",
+		  "Add a PAT entry", GST_TYPE_STRUCTURE, G_PARAM_WRITABLE|G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_property (gobject_class, PROP_ADD_PMT,
+	g_param_spec_boxed( "add-pmt", "Add a PMT entry",
+		  "Add a PMT entry", GST_TYPE_STRUCTURE, G_PARAM_WRITABLE|G_PARAM_STATIC_STRINGS));
+  /* </AWOX> */
+}
+
+
+/* <AWOX> this is code duplication from ... ===================================================================== */
+
+static void
+_mpegts_pat_program_free (GstMpegTsPatProgram * orig)
+{
+  g_slice_free (GstMpegTsPatProgram, orig);
+}
+static void
+_gst_mpegts_pmt_stream_free (GstMpegTsPMTStream * pmt)
+{
+  g_ptr_array_unref (pmt->descriptors);
+  g_slice_free (GstMpegTsPMTStream, pmt);
 }
 
+/* </AWOX> this shouldn't stay here !!! ========================================================================= */
+
 static void
 mpegts_base_set_property (GObject * object, guint prop_id,
     const GValue * value, GParamSpec * pspec)
@@ -141,6 +182,108 @@
     case PROP_PARSE_PRIVATE_SECTIONS:
       base->parse_private_sections = g_value_get_boolean (value);
       break;
+	  /* <AWOX> */
+	  case PROP_ADD_PAT:
+	  {
+		  const GstStructure *thePAT = gst_value_get_structure(value);
+		  guint theProgamNumber;
+		  guint thePMT_Id;
+
+		  if(gst_structure_get_uint(thePAT, "program-number", &theProgamNumber)&&
+				  gst_structure_get_uint(thePAT, "pmt-id", &thePMT_Id)
+				  )
+		  {
+			  /* create a PAT */
+			  GstMpegTsSection *thePAT = gst_mpegts_section_new_empty(0, 0, 0);
+			  GPtrArray *thePAT_Array;
+			  GstMpegTsPatProgram *theProgram = NULL;
+
+			  thePAT->pid = 0;
+			  thePAT->offset = 0;
+			  thePAT->section_type = GST_MPEGTS_SECTION_PAT;
+			  thePAT->table_id = GST_MTS_TABLE_ID_PROGRAM_ASSOCIATION;
+			  thePAT->short_section = FALSE;
+			  thePAT->subtable_extension = 1;
+			  thePAT->version_number = 1;
+
+			  thePAT_Array = g_ptr_array_new_full ( 1, (GDestroyNotify) _mpegts_pat_program_free);
+
+			  theProgram = g_slice_new0 (GstMpegTsPatProgram);
+			  theProgram->program_number = theProgamNumber;
+			  theProgram->network_or_program_map_PID = thePMT_Id;
+
+			  g_ptr_array_index (thePAT_Array, 0) = theProgram;
+
+			  thePAT_Array->len = 1;
+
+			  thePAT->cached_parsed = (gpointer)thePAT_Array;
+
+			  mpegts_base_handle_psi(base, thePAT);
+
+		  }
+				  break;
+	  }
+	  case PROP_ADD_PMT:
+	  {
+		  const GstStructure *thePMT = gst_value_get_structure(value);
+		  guint thePMT_pid;
+		  guint theVideoPid, theAudioPid;
+		  guint theProgramNumber;
+
+		  if( gst_structure_get_uint(thePMT, "pmt-pid", &thePMT_pid)&&
+				  gst_structure_get_uint(thePMT, "video-pid", &theVideoPid)&&
+				  gst_structure_get_uint(thePMT, "audio-pid", &theAudioPid)&&
+				  gst_structure_get_uint(thePMT, "program-number", &theProgramNumber)
+				  )
+		  {
+			  /* create a PMT */
+
+			  GstMpegTsSection *thePMTSection = gst_mpegts_section_new_empty(0, 0, 0);
+			  GstMpegTsPMT *thePMTEntry = NULL;
+			  GstMpegTsPMTStream *theStream = NULL;
+
+			  thePMTSection->pid = thePMT_pid;
+			  thePMTSection->offset = 0;
+			  thePMTSection->section_type = GST_MPEGTS_SECTION_PMT;
+			  thePMTSection->table_id = GST_MTS_TABLE_ID_TS_PROGRAM_MAP;
+			  thePMTSection->subtable_extension = theProgramNumber;
+			  thePMTSection->short_section = TRUE;
+
+			  thePMTEntry = g_slice_new0 (GstMpegTsPMT);
+			  thePMTEntry->pcr_pid = theVideoPid;//0x1FFFF;
+			  thePMTEntry->streams = g_ptr_array_new_full( 1, (GDestroyNotify) _gst_mpegts_pmt_stream_free);
+
+			  thePMTEntry->descriptors = g_ptr_array_new (); /* will stay empty */
+
+			  theStream = g_slice_new0 (GstMpegTsPMTStream);
+			  theStream->stream_type = GST_MPEG_TS_STREAM_TYPE_VIDEO_H264;
+			  theStream->descriptors = g_ptr_array_new();
+			  theStream->pid = theVideoPid;
+			  g_ptr_array_add (thePMTEntry->streams, theStream);
+
+
+
+			  theStream = g_slice_new0 (GstMpegTsPMTStream);
+			  theStream->stream_type = 0x81;
+			  theStream->descriptors = g_ptr_array_new();
+			  theStream->pid = theAudioPid;
+			  g_ptr_array_add (thePMTEntry->streams, theStream);
+
+			  theStream = g_slice_new0 (GstMpegTsPMTStream);
+			  theStream->stream_type = GST_MPEG_TS_STREAM_TYPE_PRIVATE_PES_PACKETS;
+			  theStream->descriptors = g_ptr_array_new();
+			  theStream->pid = theVideoPid;
+			  g_ptr_array_add (thePMTEntry->streams, theStream);
+
+
+			  thePMTSection->cached_parsed = (gpointer)thePMTEntry;
+
+			  mpegts_base_handle_psi(base, thePMTSection);
+		  }
+
+		  break;
+	  }
+		  /* </AWOX> */
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   }
@@ -282,7 +425,7 @@
 const guint8 *
 mpegts_get_descriptor_from_stream (MpegTSBaseStream * stream, guint8 tag)
 {
-  const GstMpegTsDescriptor *desc;
+ const GstMpegTsDescriptor *desc;
   GstMpegTsPMTStream *pmt = stream->stream;
 
   GST_DEBUG ("Searching for tag 0x%02x in stream 0x%04x (stream_type 0x%02x)",
@@ -899,7 +1042,7 @@
       post_message = mpegts_base_apply_pat (base, section);
       if (base->seen_pat == FALSE) {
         base->seen_pat = TRUE;
-        GST_DEBUG ("First PAT offset: %" G_GUINT64_FORMAT, section->offset);
+		GST_DEBUG ("First PAT offset: %" G_GUINT64_FORMAT, section->offset);
         mpegts_packetizer_set_reference_offset (base->packetizer,
             section->offset);
       }
@@ -1016,14 +1159,14 @@
   switch (GST_EVENT_TYPE (event)) {
     case GST_EVENT_SEGMENT:
       gst_event_copy_segment (event, &base->segment);
-      GST_DEBUG_OBJECT (base, "Received segment %" GST_SEGMENT_FORMAT,
-          &base->segment);
-      /* Check if we need to switch PCR/PTS handling */
+	  GST_DEBUG_OBJECT (base, "Received segment %" GST_SEGMENT_FORMAT,
+		  &base->segment);
+	  /* Check if we need to switch PCR/PTS handling */
       if (base->segment.format == GST_FORMAT_TIME) {
         base->packetizer->calculate_offset = FALSE;
         base->packetizer->calculate_skew = TRUE;
       } else {
-        base->packetizer->calculate_offset = TRUE;
+		base->packetizer->calculate_offset = TRUE;
         base->packetizer->calculate_skew = FALSE;
       }
       res = GST_MPEGTS_BASE_GET_CLASS (base)->push_event (base, event);
@@ -1037,7 +1180,7 @@
       break;
     case GST_EVENT_CAPS:
       /* FIXME, do something */
-      gst_event_unref (event);
+	  gst_event_unref (event);
       break;
     case GST_EVENT_FLUSH_STOP:
       res = GST_MPEGTS_BASE_GET_CLASS (base)->push_event (base, event);
@@ -1108,7 +1251,7 @@
     }
 
     /* If it's a known PES, push it */
-    if (MPEGTS_BIT_IS_SET (base->is_pes, packet.pid)) {
+	if (MPEGTS_BIT_IS_SET (base->is_pes, packet.pid)) {
       /* push the packet downstream */
       if (base->push_data)
         res = klass->push (base, &packet, NULL);
@@ -1132,7 +1275,7 @@
         res = klass->push (base, &packet, section);
 
     } else if (packet.payload && packet.pid != 0x1fff)
-      GST_LOG ("PID 0x%04x Saw packet on a pid we don't handle", packet.pid);
+		GST_LOG ("PID 0x%04x Saw packet on a pid we don't handle", packet.pid);
 
   next:
     mpegts_packetizer_clear_packet (base->packetizer, &packet);
@@ -1512,8 +1655,10 @@
 
   switch (transition) {
     case GST_STATE_CHANGE_READY_TO_PAUSED:
-      mpegts_base_reset (base);
-      break;
+		  /* <AWOX>   Commented next line */
+//      mpegts_base_reset (base);
+		  /* </AWOX> */
+	  break;
     default:
       break;
   }
