Index: libs/libmythtv/freeboxsignalmonitor.cpp
===================================================================
--- libs/libmythtv/freeboxsignalmonitor.cpp	(revision 10568)
+++ libs/libmythtv/freeboxsignalmonitor.cpp	(working copy)
@@ -1,10 +1,10 @@
 // -*- Mode: c++ -*-
 
-#include "mythcontext.h"
+// main header
+#include "freeboxsignalmonitor.h"
+
+// MythTV headers
 #include "mpegstreamdata.h"
-
-#include "freeboxchannel.h"
-#include "freeboxsignalmonitor.h"
 #include "rtspcomms.h"
 
 #undef DBG_SM
@@ -14,6 +14,7 @@
 #define LOC QString("FreeboxSM(%1): ").arg(channel->GetDevice())
 #define LOC_ERR QString("FreeboxSM(%1), Error: ").arg(channel->GetDevice())
 
+
 /** \fn FreeboxSignalMonitor::FreeboxSignalMonitor(int,FreeboxChannel*,uint,const char*)
  *  \brief Initializes signal lock and signal values.
  *
@@ -30,17 +31,17 @@
  *  \param _name    Instance name for Qt signal/slot debugging
  */
 FreeboxSignalMonitor::FreeboxSignalMonitor(
-    int db_cardnum, FreeboxChannel *_channel,
+    int db_cardnum, FreeboxChannel *channel,
     uint _flags, const char *_name)
-    : DTVSignalMonitor(db_cardnum, _channel, _flags, _name),
-      rtsp(new RTSPComms(this)),
+    : DTVSignalMonitor(db_cardnum, channel, _flags, _name),
+      _channel(channel),
       dtvMonitorRunning(false)
 {
     bool isLocked = false;
-    if (rtsp->Init())
+    if (rtsp().Init())
     {
         FreeboxChannelInfo chaninfo = _channel->GetCurrentChanInfo();
-        isLocked = chaninfo.isValid() && rtsp->Open(chaninfo.m_url);
+        isLocked = chaninfo.isValid() && rtsp().Open(chaninfo.m_url);
     }
 
     QMutexLocker locker(&statusLock);
@@ -53,18 +54,19 @@
  */
 FreeboxSignalMonitor::~FreeboxSignalMonitor()
 {
+    _channel->SetMonitor(NULL);
     Stop();
+}
 
-    if (rtsp)
-    {
-        delete rtsp;
-        rtsp = NULL;
-    }
+RTSPComms& FreeboxSignalMonitor::rtsp()
+{
+    return _channel->rtsp();
 }
 
 void FreeboxSignalMonitor::deleteLater(void)
 {
     disconnect(); // disconnect signals we may be sending...
+    _channel->SetMonitor(NULL);
     Stop();
     DTVSignalMonitor::deleteLater();
 }
@@ -75,10 +77,11 @@
 void FreeboxSignalMonitor::Stop(void)
 {
     DBG_SM("Stop", "begin");
+    _channel->SetMonitor(NULL);
     SignalMonitor::Stop();
     if (dtvMonitorRunning)
     {
-        rtsp->Stop();
+        rtsp().Stop();
         dtvMonitorRunning = false;
         pthread_join(table_monitor_thread, NULL);
     }
@@ -101,7 +104,9 @@
 
     GetStreamData()->AddListeningPID(0);
 
-    rtsp->Run();
+    _channel->SetMonitor(this);
+    rtsp().Run();
+    _channel->SetMonitor(NULL);
 
     dtvMonitorRunning = false;
     DBG_SM("Run", "end");
Index: libs/libmythtv/freeboxchannel.h
===================================================================
--- libs/libmythtv/freeboxchannel.h	(revision 10568)
+++ libs/libmythtv/freeboxchannel.h	(working copy)
@@ -9,12 +9,15 @@
 
 #include "channelbase.h"
 #include "freeboxchannelinfo.h"
+#include "freeboxmediasink.h"
 
 #include <qmutex.h>
 
-class FreeboxRecorder;
+class RTSPComms;
 
-class FreeboxChannel : public ChannelBase
+
+class FreeboxChannel : public ChannelBase,
+                       public RTSPListener
 {
   public:
     FreeboxChannel(TVRec *parent, const QString &videodev);
@@ -31,13 +34,25 @@
 
     FreeboxChannelInfo GetCurrentChanInfo(void) const
         { return GetChanInfo(curchannelname); }
+    RTSPComms& rtsp() { return *m_rtsp; }
+    
+    void SetMonitor(RTSPListener* monitor);
+    void SetRecorder(RTSPListener* recorder);
 
   private:
     FreeboxChannelInfo GetChanInfo(const QString& channum,
                                    uint           sourceid = 0) const;
+    // implements RTSPListener
+    void AddData(unsigned char *data,
+                 unsigned int   dataSize,
+                 struct timeval presentationTime);
 
+  private:
     QString               m_videodev;
     fbox_chan_map_t       m_freeboxchannels;
+    RTSPComms            *m_rtsp;
+    RTSPListener         *m_monitor;
+    RTSPListener         *m_recorder;
     mutable QMutex        m_lock;
 
   private:
Index: libs/libmythtv/freeboxchannel.cpp
===================================================================
--- libs/libmythtv/freeboxchannel.cpp	(revision 10568)
+++ libs/libmythtv/freeboxchannel.cpp	(working copy)
@@ -6,17 +6,24 @@
 
 #include "freeboxchannel.h"
 
+#include <qdeepcopy.h>
+
+#include "libmyth/mythcontext.h"
+#include "libmyth/mythdbcon.h"
 #include "libmythtv/freeboxchannelfetcher.h"
-#include "libmythtv/freeboxrecorder.h"
-#include "libmythtv/tv_rec.h"
+#include "libmythtv/rtspcomms.h"
 
 #define LOC QString("FBChan(%1): ").arg(GetCardID())
 #define LOC_ERR QString("FBChan(%1), Error: ").arg(GetCardID())
 
+
 FreeboxChannel::FreeboxChannel(TVRec         *parent,
                                const QString &videodev)
     : ChannelBase(parent),
       m_videodev(QDeepCopy<QString>(videodev)),
+      m_rtsp(new RTSPComms(this)),
+      m_monitor(NULL),
+      m_recorder(NULL),
       m_lock(true)
 {
     VERBOSE(VB_CHANNEL, LOC + "ctor");
@@ -24,7 +31,9 @@
 
 FreeboxChannel::~FreeboxChannel()
 {
-    VERBOSE(VB_CHANNEL, LOC + "dtor");
+    VERBOSE(VB_CHANNEL, LOC + "dtor -- begin");
+    delete m_rtsp;
+    VERBOSE(VB_CHANNEL, LOC + "dtor -- end");
 }
 
 bool FreeboxChannel::Open(void)
@@ -196,4 +205,27 @@
     return dummy;
 }
 
+void FreeboxChannel::SetMonitor(RTSPListener* monitor)
+{
+    QMutexLocker locker(&m_lock);
+    m_monitor = monitor;
+}
+
+void FreeboxChannel::SetRecorder(RTSPListener* recorder)
+{
+    QMutexLocker locker(&m_lock);
+    m_recorder = recorder;
+}
+
+void FreeboxChannel::AddData(unsigned char *data,
+                             unsigned int   dataSize,
+                             struct timeval presentationTime)
+{
+    QMutexLocker locker(&m_lock);
+    if (m_monitor)
+        m_monitor->AddData(data, dataSize, presentationTime);
+    if (m_recorder)
+        m_recorder->AddData(data, dataSize, presentationTime);
+}
+
 /* vim: set expandtab tabstop=4 shiftwidth=4: */
Index: libs/libmythtv/freeboxsignalmonitor.h
===================================================================
--- libs/libmythtv/freeboxsignalmonitor.h	(revision 10568)
+++ libs/libmythtv/freeboxsignalmonitor.h	(working copy)
@@ -9,6 +9,7 @@
 class RTSPComms;
 class FreeboxChannel;
 
+
 class FreeboxSignalMonitor : public DTVSignalMonitor, public RTSPListener
 {
     Q_OBJECT
@@ -39,8 +40,11 @@
     static void *TableMonitorThread(void *param);
     void RunTableMonitor(void);
 
-  protected:
-    RTSPComms         *rtsp;
+  private:
+    RTSPComms& rtsp();
+
+  private:
+    FreeboxChannel    *_channel;
     bool               dtvMonitorRunning;
     pthread_t          table_monitor_thread;
 };
Index: libs/libmythtv/freeboxrecorder.cpp
===================================================================
--- libs/libmythtv/freeboxrecorder.cpp	(revision 10568)
+++ libs/libmythtv/freeboxrecorder.cpp	(working copy)
@@ -4,15 +4,19 @@
  *  Distributed as part of MythTV under GPL v2 and later.
  */
 
+// main header
+#include "freeboxrecorder.h"
+
 // MythTV headers
+#include "freeboxchannel.h"
 #include "mpegstreamdata.h"
+#include "rtspcomms.h"
 #include "tspacket.h"
-#include "freeboxchannel.h"
-#include "freeboxrecorder.h"
 
 #define LOC QString("FBRec: ")
 #define LOC_ERR QString("FBRec, Error: ")
 
+
 // ============================================================================
 // FreeboxRecorder : Processes data from RTSPComms and writes it to disk
 // ============================================================================
@@ -20,28 +24,28 @@
 FreeboxRecorder::FreeboxRecorder(TVRec *rec, FreeboxChannel *channel) :
     DTVRecorder(rec),
     _channel(channel),
-    _stream_data(NULL),
-    _rtsp(new RTSPComms(this))
+    _stream_data(NULL)
 {
+    _channel->SetRecorder(this);
 }
 
 FreeboxRecorder::~FreeboxRecorder()
 {
     StopRecording();
+    _channel->SetRecorder(NULL);
+}
 
-    if (_rtsp)
-    {
-        delete _rtsp;
-        _rtsp = NULL;
-    }
+RTSPComms& FreeboxRecorder::rtsp()
+{
+    return _channel->rtsp();
 }
 
 bool FreeboxRecorder::Open(void)
 {
     VERBOSE(VB_RECORD, LOC + "Open() -- begin");
 
-    if (_rtsp->IsOpen())
-        _rtsp->Close();
+    if (rtsp().IsOpen())
+        rtsp().Close();
 
     FreeboxChannelInfo chaninfo = _channel->GetCurrentChanInfo();
     if (!chaninfo.isValid())
@@ -50,9 +54,9 @@
     }
     else
     {
-        _error = !(_rtsp->Init()); 
+        _error = !(rtsp().Init()); 
         if (!_error)
-            _error = !(_rtsp->Open(chaninfo.m_url));
+            _error = !(rtsp().Open(chaninfo.m_url));
     }
 
     VERBOSE(VB_RECORD, LOC + "Open() -- end err("<<_error<<")");
@@ -62,8 +66,8 @@
 void FreeboxRecorder::Close(void)
 {
     VERBOSE(VB_RECORD, LOC + "Close() -- begin");
-    _rtsp->Stop();
-    _rtsp->Close();
+    rtsp().Stop();
+    rtsp().Close();
     VERBOSE(VB_RECORD, LOC + "Close() -- end");
 }
 
@@ -71,15 +75,15 @@
 {
     VERBOSE(VB_RECORD, LOC + "Pause() -- begin");
     DTVRecorder::Pause(clear);
-    _rtsp->Stop();
-    _rtsp->Close();
+    rtsp().Stop();
+    rtsp().Close();
     VERBOSE(VB_RECORD, LOC + "Pause() -- end");
 }
 
 void FreeboxRecorder::Unpause(void)
 {
     VERBOSE(VB_RECORD, LOC + "Unpause() -- begin");
-    if (_recording && !_rtsp->IsOpen())
+    if (_recording && !rtsp().IsOpen())
         Open();
     DTVRecorder::Unpause();
     VERBOSE(VB_RECORD, LOC + "Unpause() -- end");
@@ -103,14 +107,14 @@
         if (PauseAndWait())
             continue;
 
-        if (!_rtsp->IsOpen())
+        if (!rtsp().IsOpen())
         {
             usleep(5000);
             continue;
         }
 
         // Go into main RTSP loop, feeding data to AddData
-        _rtsp->Run();
+        rtsp().Run();
     }
 
     // Finish up...
@@ -126,7 +130,7 @@
 {
     VERBOSE(VB_RECORD, LOC + "StopRecording() -- begin");
     Pause();
-    _rtsp->Close();
+    rtsp().Close();
 
     _request_recording = false;
     while (_recording)
Index: libs/libmythtv/rtspcomms.cpp
===================================================================
--- libs/libmythtv/rtspcomms.cpp	(revision 10568)
+++ libs/libmythtv/rtspcomms.cpp	(working copy)
@@ -107,7 +107,9 @@
                 QString("Freebox # Failed to create RTSP client: %1")
                 .arg(_live_env->getResultMsg()));
 
-        _live_env = NULL; // TODO free resources.
+        _live_env->reclaim();
+        _live_env = NULL;
+        delete scheduler;
     }
 
     VERBOSE(VB_RECORD, LOC + "Init() -- end");
@@ -127,7 +129,13 @@
         _rtsp_client = NULL;
     }
 
-    _live_env = NULL; // TODO free resources.
+    if (_live_env)
+    {
+        TaskScheduler *scheduler = &_live_env->taskScheduler();
+        _live_env->reclaim();
+        _live_env = NULL;
+        delete scheduler;
+    }
     VERBOSE(VB_RECORD, LOC + "Deinit() -- end");
 }
 
Index: libs/libmythtv/freeboxmediasink.h
===================================================================
--- libs/libmythtv/freeboxmediasink.h	(revision 10568)
+++ libs/libmythtv/freeboxmediasink.h	(working copy)
@@ -16,6 +16,8 @@
     virtual void AddData(unsigned char *data,
                          unsigned int   dataSize,
                          struct timeval presentationTime) = 0;
+  protected:
+    virtual ~RTSPListener() {}
 };
 
 // ============================================================================
Index: libs/libmythtv/freeboxrecorder.h
===================================================================
--- libs/libmythtv/freeboxrecorder.h	(revision 10568)
+++ libs/libmythtv/freeboxrecorder.h	(working copy)
@@ -11,14 +11,12 @@
 
 #include "dtvrecorder.h"
 #include "freeboxmediasink.h"
-#include "rtspcomms.h"
 #include "streamlisteners.h"
 
-class TSPacket;
 class FreeboxChannel;
-class FreeboxChannelInfo;
-class MPEGStreamData;
+class RTSPComms;
 
+
 /** \brief Processes data from RTSPComms and writes it to disk.
  */
 class FreeboxRecorder : public DTVRecorder, public RTSPListener,
@@ -57,11 +55,11 @@
     // implements MPEGSingleProgramStreamListener
     void HandleSingleProgramPAT(ProgramAssociationTable *pat);
     void HandleSingleProgramPMT(ProgramMapTable *pmt);
+    RTSPComms& rtsp();
 
   private:
     FreeboxChannel *_channel;
     MPEGStreamData *_stream_data;
-    RTSPComms      *_rtsp;
     QWaitCondition  _cond_recording;
 
 
