diff -Naur D:\code\Gstreamer\gstreamer-1.0.8\mpegtsdemux/mpegtsbase.c D:\TASK_DATA\c_code\TsDemuxer\gstreamer\DEMUX_FIX_V1/mpegtsbase.c
--- D:\code\Gstreamer\gstreamer-1.0.8\mpegtsdemux/mpegtsbase.c	2013-07-12 01:10:49.000000000 +0530
+++ D:\TASK_DATA\c_code\TsDemuxer\gstreamer\DEMUX_FIX_V1/mpegtsbase.c	2013-08-13 15:18:56.355217900 +0530
@@ -43,6 +43,7 @@
 
 #include <gst/gst-i18n-plugin.h>
 #include "mpegtsbase.h"
+#include "tsdemux.h"
 #include "gstmpegdesc.h"
 
 /* latency in mseconds */
@@ -232,6 +233,13 @@
 
   g_hash_table_foreach_remove (base->programs, (GHRFunc) remove_each_program,
       base);
+  
+  /*RS_FIX: */
+  base->packetizer->requested_pcr_id 		 = -1;
+  base->packetizer->num_streams_in_program 	 = 0;
+  base->packetizer->seen_program 			 = FALSE;
+  base->packetizer->stream_found 			 = FALSE;
+  memset(base->packetizer->requested_pes_id, 0, sizeof(base->packetizer->requested_pes_id));
 
   if (klass->reset)
     klass->reset (base);
@@ -258,6 +266,7 @@
   base->program_size = sizeof (MpegTSBaseProgram);
   base->stream_size = sizeof (MpegTSBaseStream);
 
+  base->packetizer->requested_program_number = -1;
   mpegts_base_reset (base);
 }
 
@@ -521,7 +530,7 @@
 
   GST_DEBUG ("pid:0x%04x, stream_type:0x%03x, stream_info:%" GST_PTR_FORMAT,
       pid, stream_type, stream_info);
-
+	
   if (G_UNLIKELY (program->streams[pid])) {
     GST_WARNING ("Stream already present !");
     return NULL;
@@ -701,6 +710,7 @@
   const GValue *new_streams;
   const GValue *value;
   MpegTSBaseClass *klass;
+  gint index=0;
 
   if (G_UNLIKELY (program->active))
     return;
@@ -716,10 +726,19 @@
   program->pmt_info = pmt_info;
   program->pmt_pid = pmt_pid;
   program->pcr_pid = pcr_pid;
-
+  
   new_streams = gst_structure_id_get_value (pmt_info, QUARK_STREAMS);
   nbstreams = gst_value_list_get_size (new_streams);
 
+  if((program->program_number == base->packetizer->requested_program_number) || 
+	(base->packetizer->requested_program_number == -1))
+  {
+	base->packetizer->requested_program_number  = program->program_number;
+	base->packetizer->seen_program 			 	= TRUE;
+	base->packetizer->requested_pcr_id 		 	= program->pcr_pid;
+	base->packetizer->num_streams_in_program 	= nbstreams;
+  }
+
   for (i = 0; i < nbstreams; ++i) {
     value = gst_value_list_get_value (new_streams, i);
     stream = g_value_get_boxed (value);
@@ -727,6 +746,17 @@
     gst_structure_id_get (stream, QUARK_PID, G_TYPE_UINT, &pid,
         QUARK_STREAM_TYPE, G_TYPE_UINT, &stream_type, NULL);
     MPEGTS_BIT_SET (base->is_pes, pid);
+	
+	if((program->program_number == base->packetizer->requested_program_number))
+	 {
+		if (i4_index < MAX_STREAMS)
+		{
+			base->packetizer->requested_pes_id[i4_index] = pid;
+			index++;
+		}
+		else
+			GST_WARNING("Number of streams in a program are exceeding MAX stream limit!!!");
+	 }
     mpegts_base_program_add_stream (base, program,
         (guint16) pid, (guint8) stream_type, stream);
 
@@ -853,7 +883,7 @@
     program_info = g_value_get_boxed (value);
     gst_structure_id_get (program_info, QUARK_PROGRAM_NUMBER, G_TYPE_UINT,
         &program_number, QUARK_PID, G_TYPE_UINT, &pid, NULL);
-
+		
     program = mpegts_base_get_program (base, program_number);
     if (program) {
       /* IF the program already existed, just check if the PMT PID changed */
@@ -904,7 +934,7 @@
 
       GST_INFO_OBJECT (base, "PAT removing program %" GST_PTR_FORMAT,
           program_info);
-
+	  
       mpegts_base_deactivate_program (base, program);
       mpegts_base_remove_program (base, program_number);
       /* FIXME: when this happens it may still be pmt pid of another
@@ -939,7 +969,7 @@
 
   GST_DEBUG ("Applying PMT (program_number:%d, pid:0x%04x)",
       program_number, pmt_pid);
-
+	  
   /* In order for stream switching to happen properly in decodebin(2),
    * we need to first add the new pads (i.e. activate the new program)
    * before removing the old ones (i.e. deactivating the old program)
@@ -1393,7 +1423,7 @@
 
   base = GST_MPEGTS_BASE (parent);
   klass = GST_MPEGTS_BASE_GET_CLASS (base);
-
+  
   packetizer = base->packetizer;
 
   if (G_UNLIKELY (base->queried_latency == FALSE)) {
@@ -1404,10 +1434,10 @@
     gst_buffer_ref (buf);
 
   mpegts_packetizer_push (base->packetizer, buf);
-
+  
   while (res == GST_FLOW_OK) {
     pret = mpegts_packetizer_next_packet (base->packetizer, &packet);
-
+	
     /* If we don't have enough data, return */
     if (G_UNLIKELY (pret == PACKET_NEED_MORE))
       break;
@@ -1571,7 +1601,7 @@
 mpegts_base_loop (MpegTSBase * base)
 {
   GstFlowReturn ret = GST_FLOW_ERROR;
-
+  
   switch (base->mode) {
     case BASE_MODE_SCANNING:
       /* Find first sync point */
diff -Naur D:\code\Gstreamer\gstreamer-1.0.8\mpegtsdemux/mpegtspacketizer.c D:\TASK_DATA\c_code\TsDemuxer\gstreamer\DEMUX_FIX_V1/mpegtspacketizer.c
--- D:\code\Gstreamer\gstreamer-1.0.8\mpegtsdemux/mpegtspacketizer.c	2013-07-12 01:13:01.000000000 +0530
+++ D:\TASK_DATA\c_code\TsDemuxer\gstreamer\DEMUX_FIX_V1/mpegtspacketizer.c	2013-08-13 15:15:28.534331200 +0530
@@ -476,7 +476,7 @@
   guint8 *data;
 
   length = *packet->data++;
-
+  
   /* an adaptation field with length 0 is valid and
    * can be used to insert a single stuffing byte */
   if (!length) {
@@ -558,6 +558,25 @@
   /* PID 13 */
   packet->pid = GST_READ_UINT16_BE (data) & 0x1FFF;
   data += 2;
+  
+  /* Dont parse the packet if the pid doesnt match with the requested pid */
+  packetizer->stream_found = FALSE;
+  if(packetizer->seen_program)
+  {
+	gint index;
+	for( index=0; index < packetizer->num_streams_in_program; index++ )
+	{
+		if(packet->pid == packetizer->requested_pes_id[index])
+		{
+			packetizer->stream_found = TRUE;
+			//g_print("\nStreams found in current packet");
+			break;
+		}
+	}
+
+	if(!packetizer->stream_found)
+		return PACKET_BAD;
+  }
 
   /* transport_scrambling_control 2 */
   if (G_UNLIKELY (*data >> 6))
@@ -3374,7 +3393,7 @@
   gint pos, i;
   GstClockTime gstpcrtime, out_time;
   guint64 slope;
-
+  
   gstpcrtime = PCRTIME_TO_GSTTIME (pcrtime) + pcr->pcroffset;
 
   /* first time, lock on to time and gstpcrtime */
diff -Naur D:\code\Gstreamer\gstreamer-1.0.8\mpegtsdemux/mpegtspacketizer.h D:\TASK_DATA\c_code\TsDemuxer\gstreamer\DEMUX_FIX_V1/mpegtspacketizer.h
--- D:\code\Gstreamer\gstreamer-1.0.8\mpegtsdemux/mpegtspacketizer.h	2013-07-12 01:10:49.000000000 +0530
+++ D:\TASK_DATA\c_code\TsDemuxer\gstreamer\DEMUX_FIX_V1/mpegtspacketizer.h	2013-08-13 15:22:57.139990000 +0530
@@ -81,6 +81,9 @@
   guint64 offset;
 } MpegTSPacketizerStream;
 
+/*we are assuming 16 maximum streams in a program */
+#define MAX_STREAMS 16
+
 struct _MpegTSPacketizer2 {
   GObject     parent;
 
@@ -99,9 +102,18 @@
 
   /* clock skew calculation */
   gboolean       calculate_skew;
+  
+  gboolean       calculate_offset;
+
+  /* Fix */
+  gint 		requested_program_number;
+  guint 	requested_pes_id[MAX_STREAMS];
+  gint 		requested_pcr_id;
+  gint 		num_streams_in_program;
+  gboolean 	seen_program;
+  gboolean	stream_found;
 
   /* offset/bitrate calculator */
-  gboolean       calculate_offset;
 
   MpegTSPacketizerPrivate *priv;
 };
diff -Naur D:\code\Gstreamer\gstreamer-1.0.8\mpegtsdemux/tsdemux.c D:\TASK_DATA\c_code\TsDemuxer\gstreamer\DEMUX_FIX_V1/tsdemux.c
--- D:\code\Gstreamer\gstreamer-1.0.8\mpegtsdemux/tsdemux.c	2013-07-12 01:10:49.000000000 +0530
+++ D:\TASK_DATA\c_code\TsDemuxer\gstreamer\DEMUX_FIX_V1/tsdemux.c	2013-08-13 15:17:59.153946200 +0530
@@ -336,7 +336,9 @@
 gst_ts_demux_init (GstTSDemux * demux)
 {
   GST_MPEGTS_BASE (demux)->stream_size = sizeof (TSDemuxStream);
-
+  
+  demux->requested_program_number = -1;
+  GST_MPEGTS_BASE (demux)->packetizer->requested_program_number = -1;
   gst_ts_demux_reset ((MpegTSBase *) demux);
 }
 
@@ -351,8 +353,9 @@
     case PROP_PROGRAM_NUMBER:
       /* FIXME: do something if program is switched as opposed to set at
        * beginning */
-      demux->program_number = g_value_get_int (value);
-      break;
+	  demux->requested_program_number = g_value_get_int (value);
+	 GST_MPEGTS_BASE (demux)->packetizer->requested_program_number = demux->requested_program_number;  
+	 break;
     case PROP_EMIT_STATS:
       demux->emit_statistics = g_value_get_boolean (value);
       break;
@@ -369,7 +372,8 @@
 
   switch (prop_id) {
     case PROP_PROGRAM_NUMBER:
-      g_value_set_int (value, demux->program_number);
+      g_value_set_int (value, demux->requested_program_number);
+	  GST_MPEGTS_BASE (demux)->packetizer->requested_program_number = demux->requested_program_number;
       break;
     case PROP_EMIT_STATS:
       g_value_set_boolean (value, demux->emit_statistics);
@@ -1002,7 +1006,7 @@
     MpegTSBaseProgram * program)
 {
   TSDemuxStream *stream = (TSDemuxStream *) bstream;
-
+  
   if (!stream->pad) {
     /* Create the pad */
     if (bstream->stream_type != 0xff)
@@ -1106,11 +1110,12 @@
 {
   GstTSDemux *demux = GST_TS_DEMUX (base);
 
-  GST_DEBUG ("Current program %d, new program %d",
-      demux->program_number, program->program_number);
+  GST_DEBUG ("Current program %d, new program %d requested program %d",
+      (gint) demux->program_number, program->program_number,
+      demux->requested_program_number);
 
-  if (demux->program_number == -1 ||
-      demux->program_number == program->program_number) {
+  if (demux->requested_program_number == program->program_number ||
+     (demux->requested_program_number == -1 && demux->program_number == -1)) {
 
     GST_LOG ("program %d started", program->program_number);
     demux->program_number = program->program_number;
@@ -1529,8 +1534,8 @@
   GST_LOG ("pid 0x%04x pusi:%d, afc:%d, cont:%d, payload:%p", packet->pid,
       packet->payload_unit_start_indicator, packet->adaptation_field_control,
       packet->continuity_counter, packet->payload);
-
-  if (section) {
+	  
+   if (section) {
     GST_DEBUG ("section complete:%d, buffer size %d",
         section->complete, section->section_length);
     return res;
diff -Naur D:\code\Gstreamer\gstreamer-1.0.8\mpegtsdemux/tsdemux.h D:\TASK_DATA\c_code\TsDemuxer\gstreamer\DEMUX_FIX_V1/tsdemux.h
--- D:\code\Gstreamer\gstreamer-1.0.8\mpegtsdemux/tsdemux.h	2013-05-12 00:13:53.000000000 +0530
+++ D:\TASK_DATA\c_code\TsDemuxer\gstreamer\DEMUX_FIX_V1/tsdemux.h	2013-08-07 18:46:16.000000000 +0530
@@ -55,7 +55,8 @@
 
   /* the following vars must be protected with the OBJECT_LOCK as they can be
    * accessed from the application thread and the streaming thread */
-  guint program_number;		/* Required program number (ignore:-1) */
+  gint requested_program_number; /* Required program number (ignore:-1) */
+  guint program_number;		
   gboolean emit_statistics;
 
   /*< private >*/
