Index: libs/libmythtv/firewirerecorder.cpp
===================================================================
--- libs/libmythtv/firewirerecorder.cpp	(revision 8671)
+++ libs/libmythtv/firewirerecorder.cpp	(working copy)
@@ -15,7 +15,8 @@
 // MythTV includes
 #include "firewirerecorder.h"
 #include "mythcontext.h"
-#include "tspacket.h"
+#include "mpegtables.h"
+#include "mpegstreamdata.h"
 #include "tv_rec.h"
 
 // callback function for libiec61883
@@ -44,6 +45,31 @@
     return 1;
 }
 
+FirewireRecorder::FirewireRecorder(TVRec *rec)
+    : DTVRecorder(rec, "FirewireRecorder"),
+      fwport(-1),     fwchannel(-1), fwspeed(-1),   fwbandwidth(-1),
+      fwfd(-1),       fwconnection(FIREWIRE_CONNECTION_P2P),
+      fwoplug(-1),    fwiplug(-1),   fwmodel(""),   fwnode(0),
+      fwhandle(NULL), fwmpeg(NULL),  isopen(false), lastpacket(0),
+      _mpeg_stream_data(NULL)
+{
+
+    _mpeg_stream_data = new MPEGStreamData(1, true);
+    connect(_mpeg_stream_data, SIGNAL(UpdatePATSingleProgram(
+                                          ProgramAssociationTable*)),
+            this, SLOT(WritePAT(ProgramAssociationTable*)));
+    connect(_mpeg_stream_data, SIGNAL(UpdatePMTSingleProgram(ProgramMapTable*)),
+            this, SLOT(WritePMT(ProgramMapTable*)));
+
+}
+
+FirewireRecorder::~FirewireRecorder()
+{
+   Close();
+   if (_mpeg_stream_data)
+       delete(_mpeg_stream_data);
+}
+      
 void FirewireRecorder::deleteLater(void)
 {
     Close();
@@ -55,6 +81,9 @@
      if (isopen)
          return true;
     
+     if(!_mpeg_stream_data)
+         return false;
+
      VERBOSE(VB_GENERAL,QString("Firewire: Initializing Port: %1, Node: %2, Speed: %3")
                                .arg(fwport)
                                .arg(fwnode)
@@ -113,6 +142,17 @@
      return true;
 }
 
+void FirewireRecorder::SetStreamData(MPEGStreamData *stream_data)
+{
+    if (stream_data == _mpeg_stream_data)
+        return;
+
+    MPEGStreamData *old_data = _mpeg_stream_data;
+    _mpeg_stream_data = stream_data;
+    if (old_data)
+        delete old_data;
+}
+
 void FirewireRecorder::Close(void)
 {
     if (!isopen)
@@ -189,11 +229,59 @@
     _recording = false;
 }  
 
+void FirewireRecorder::WritePAT(ProgramAssociationTable *pat)
+{
+    if (!pat)
+        return;
+
+    int next = (pat->tsheader()->ContinuityCounter()+1)&0xf;
+    pat->tsheader()->SetContinuityCounter(next);
+    BufferedWrite(*(reinterpret_cast<TSPacket*>(pat->tsheader())));
+}
+
+void FirewireRecorder::WritePMT(ProgramMapTable* pmt)
+{
+    if (!pmt)
+        return;
+
+    int next = (pmt->tsheader()->ContinuityCounter()+1)&0xf;
+    pmt->tsheader()->SetContinuityCounter(next);
+    BufferedWrite(*(reinterpret_cast<TSPacket*>(pmt->tsheader())));
+}
+
 void FirewireRecorder::ProcessTSPacket(const TSPacket &tspacket)
 {
-    lastpacket = time(NULL);
-    _buffer_packets = !FindKeyframes(&tspacket);
-    BufferedWrite(tspacket);
+
+    bool ok = !tspacket.TransportError();
+    if (ok && !tspacket.ScramplingControl())
+    {
+        if (tspacket.HasAdaptationField())
+            StreamData()->HandleAdaptationFieldControl(&tspacket);
+        if (tspacket.HasPayload())
+        {
+            const unsigned int lpid = tspacket.PID();
+            // Pass or reject frames based on PID, and parse info from them
+            if (lpid == StreamData()->VideoPIDSingleProgram())
+            {
+                _buffer_packets = !FindKeyframes(&tspacket);
+                BufferedWrite(tspacket);
+            }
+            else if (StreamData()->IsAudioPID(lpid))
+                BufferedWrite(tspacket);
+            else if (StreamData()->IsListeningPID(lpid))
+                StreamData()->HandleTSTables(&tspacket);
+            else if (StreamData()->IsWritingPID(lpid))
+                BufferedWrite(tspacket);
+        }
+    }
+
+    if (ok)
+    {
+       lastpacket = time(NULL);
+       _ts_stats.IncrTSPacketCount();
+       if (0 == _ts_stats.TSPacketCount()%1000000)
+           VERBOSE(VB_RECORD, _ts_stats.toString());
+    }
 }
 
 void FirewireRecorder::SetOptionsFromProfile(RecordingProfile *profile,
Index: libs/libmythtv/firewirerecorder.h
===================================================================
--- libs/libmythtv/firewirerecorder.h	(revision 8671)
+++ libs/libmythtv/firewirerecorder.h	(working copy)
@@ -8,12 +8,15 @@
 #define FIREWIRERECORDER_H_
 
 #include "dtvrecorder.h"
-#include "mpeg/tspacket.h"
+#include "tsstats.h"
 #include <libraw1394/raw1394.h>
 #include <libiec61883/iec61883.h>
-
 #include <time.h>
 
+class MPEGStreamData;
+class ProgramAssociationTable;
+class ProgramMapTable;
+
 #define FIREWIRE_TIMEOUT 15
 
 #define FIREWIRE_CONNECTION_P2P		0
@@ -29,15 +32,13 @@
  */
 class FirewireRecorder : public DTVRecorder
 {
+  Q_OBJECT
+  friend class MPEGStreamData;
+  friend class TSPacketProcessor;
+
   public:
-    FirewireRecorder(TVRec *rec) :
-        DTVRecorder(rec, "FirewireRecorder"),
-        fwport(-1),     fwchannel(-1), fwspeed(-1),   fwbandwidth(-1),
-        fwfd(-1),       fwconnection(FIREWIRE_CONNECTION_P2P),
-        fwoplug(-1),    fwiplug(-1),   fwmodel(""),   fwnode(0),
-        fwhandle(NULL), fwmpeg(NULL),  isopen(false), lastpacket(0) {;}
-        
-    ~FirewireRecorder() { Close(); }
+    FirewireRecorder(TVRec *rec);
+    ~FirewireRecorder();
 
     void StartRecording(void);
     bool Open(void); 
@@ -50,6 +51,8 @@
     void SetOption(const QString &name, const QString &value);
     void SetOption(const QString &name, int value);
     QString FirewireSpeedString(int speed);
+    void SetStreamData(MPEGStreamData*);
+    MPEGStreamData* StreamData(void) { return _mpeg_stream_data; }
 
     bool PauseAndWait(int timeout = 100);
 
@@ -58,6 +61,12 @@
         
   private:
     void Close(void);
+
+  private slots:
+    void WritePAT(ProgramAssociationTable*);
+    void WritePMT(ProgramMapTable*);
+
+  private:
     int fwport, fwchannel, fwspeed, fwbandwidth, fwfd, fwconnection;
     int fwoplug, fwiplug;
     QString fwmodel;
@@ -66,6 +75,9 @@
     iec61883_mpeg2_t fwmpeg;
     bool isopen;
     time_t lastpacket;
+    MPEGStreamData* _mpeg_stream_data;
+    TSStats _ts_stats;
+    
 };
 
 #endif
