Ticket #2064: patch-shared-rtsp.diff

File patch-shared-rtsp.diff, 12.1 KB (added by mythtv@…, 14 years ago)

The patch

  • libs/libmythtv/freeboxsignalmonitor.cpp

     
    11// -*- Mode: c++ -*-
    22
    3 #include "mythcontext.h"
     3// main header
     4#include "freeboxsignalmonitor.h"
     5
     6// MythTV headers
    47#include "mpegstreamdata.h"
    5 
    6 #include "freeboxchannel.h"
    7 #include "freeboxsignalmonitor.h"
    88#include "rtspcomms.h"
    99
    1010#undef DBG_SM
     
    1414#define LOC QString("FreeboxSM(%1): ").arg(channel->GetDevice())
    1515#define LOC_ERR QString("FreeboxSM(%1), Error: ").arg(channel->GetDevice())
    1616
     17
    1718/** \fn FreeboxSignalMonitor::FreeboxSignalMonitor(int,FreeboxChannel*,uint,const char*)
    1819 *  \brief Initializes signal lock and signal values.
    1920 *
     
    3031 *  \param _name    Instance name for Qt signal/slot debugging
    3132 */
    3233FreeboxSignalMonitor::FreeboxSignalMonitor(
    33     int db_cardnum, FreeboxChannel *_channel,
     34    int db_cardnum, FreeboxChannel *channel,
    3435    uint _flags, const char *_name)
    35     : DTVSignalMonitor(db_cardnum, _channel, _flags, _name),
    36       rtsp(new RTSPComms(this)),
     36    : DTVSignalMonitor(db_cardnum, channel, _flags, _name),
     37      _channel(channel),
    3738      dtvMonitorRunning(false)
    3839{
    3940    bool isLocked = false;
    40     if (rtsp->Init())
     41    if (rtsp().Init())
    4142    {
    4243        FreeboxChannelInfo chaninfo = _channel->GetCurrentChanInfo();
    43         isLocked = chaninfo.isValid() && rtsp->Open(chaninfo.m_url);
     44        isLocked = chaninfo.isValid() && rtsp().Open(chaninfo.m_url);
    4445    }
    4546
    4647    QMutexLocker locker(&statusLock);
     
    5354 */
    5455FreeboxSignalMonitor::~FreeboxSignalMonitor()
    5556{
     57    _channel->SetMonitor(NULL);
    5658    Stop();
     59}
    5760
    58     if (rtsp)
    59     {
    60         delete rtsp;
    61         rtsp = NULL;
    62     }
     61RTSPComms& FreeboxSignalMonitor::rtsp()
     62{
     63    return _channel->rtsp();
    6364}
    6465
    6566void FreeboxSignalMonitor::deleteLater(void)
    6667{
    6768    disconnect(); // disconnect signals we may be sending...
     69    _channel->SetMonitor(NULL);
    6870    Stop();
    6971    DTVSignalMonitor::deleteLater();
    7072}
     
    7577void FreeboxSignalMonitor::Stop(void)
    7678{
    7779    DBG_SM("Stop", "begin");
     80    _channel->SetMonitor(NULL);
    7881    SignalMonitor::Stop();
    7982    if (dtvMonitorRunning)
    8083    {
    81         rtsp->Stop();
     84        rtsp().Stop();
    8285        dtvMonitorRunning = false;
    8386        pthread_join(table_monitor_thread, NULL);
    8487    }
     
    101104
    102105    GetStreamData()->AddListeningPID(0);
    103106
    104     rtsp->Run();
     107    _channel->SetMonitor(this);
     108    rtsp().Run();
     109    _channel->SetMonitor(NULL);
    105110
    106111    dtvMonitorRunning = false;
    107112    DBG_SM("Run", "end");
  • libs/libmythtv/freeboxchannel.h

     
    99
    1010#include "channelbase.h"
    1111#include "freeboxchannelinfo.h"
     12#include "freeboxmediasink.h"
    1213
    1314#include <qmutex.h>
    1415
    15 class FreeboxRecorder;
     16class RTSPComms;
    1617
    17 class FreeboxChannel : public ChannelBase
     18
     19class FreeboxChannel : public ChannelBase,
     20                       public RTSPListener
    1821{
    1922  public:
    2023    FreeboxChannel(TVRec *parent, const QString &videodev);
     
    3134
    3235    FreeboxChannelInfo GetCurrentChanInfo(void) const
    3336        { return GetChanInfo(curchannelname); }
     37    RTSPComms& rtsp() { return *m_rtsp; }
     38   
     39    void SetMonitor(RTSPListener* monitor);
     40    void SetRecorder(RTSPListener* recorder);
    3441
    3542  private:
    3643    FreeboxChannelInfo GetChanInfo(const QString& channum,
    3744                                   uint           sourceid = 0) const;
     45    // implements RTSPListener
     46    void AddData(unsigned char *data,
     47                 unsigned int   dataSize,
     48                 struct timeval presentationTime);
    3849
     50  private:
    3951    QString               m_videodev;
    4052    fbox_chan_map_t       m_freeboxchannels;
     53    RTSPComms            *m_rtsp;
     54    RTSPListener         *m_monitor;
     55    RTSPListener         *m_recorder;
    4156    mutable QMutex        m_lock;
    4257
    4358  private:
  • libs/libmythtv/freeboxchannel.cpp

     
    66
    77#include "freeboxchannel.h"
    88
     9#include <qdeepcopy.h>
     10
     11#include "libmyth/mythcontext.h"
     12#include "libmyth/mythdbcon.h"
    913#include "libmythtv/freeboxchannelfetcher.h"
    10 #include "libmythtv/freeboxrecorder.h"
    11 #include "libmythtv/tv_rec.h"
     14#include "libmythtv/rtspcomms.h"
    1215
    1316#define LOC QString("FBChan(%1): ").arg(GetCardID())
    1417#define LOC_ERR QString("FBChan(%1), Error: ").arg(GetCardID())
    1518
     19
    1620FreeboxChannel::FreeboxChannel(TVRec         *parent,
    1721                               const QString &videodev)
    1822    : ChannelBase(parent),
    1923      m_videodev(QDeepCopy<QString>(videodev)),
     24      m_rtsp(new RTSPComms(this)),
     25      m_monitor(NULL),
     26      m_recorder(NULL),
    2027      m_lock(true)
    2128{
    2229    VERBOSE(VB_CHANNEL, LOC + "ctor");
     
    2431
    2532FreeboxChannel::~FreeboxChannel()
    2633{
    27     VERBOSE(VB_CHANNEL, LOC + "dtor");
     34    VERBOSE(VB_CHANNEL, LOC + "dtor -- begin");
     35    delete m_rtsp;
     36    VERBOSE(VB_CHANNEL, LOC + "dtor -- end");
    2837}
    2938
    3039bool FreeboxChannel::Open(void)
     
    196205    return dummy;
    197206}
    198207
     208void FreeboxChannel::SetMonitor(RTSPListener* monitor)
     209{
     210    QMutexLocker locker(&m_lock);
     211    m_monitor = monitor;
     212}
     213
     214void FreeboxChannel::SetRecorder(RTSPListener* recorder)
     215{
     216    QMutexLocker locker(&m_lock);
     217    m_recorder = recorder;
     218}
     219
     220void FreeboxChannel::AddData(unsigned char *data,
     221                             unsigned int   dataSize,
     222                             struct timeval presentationTime)
     223{
     224    QMutexLocker locker(&m_lock);
     225    if (m_monitor)
     226        m_monitor->AddData(data, dataSize, presentationTime);
     227    if (m_recorder)
     228        m_recorder->AddData(data, dataSize, presentationTime);
     229}
     230
    199231/* vim: set expandtab tabstop=4 shiftwidth=4: */
  • libs/libmythtv/freeboxsignalmonitor.h

     
    99class RTSPComms;
    1010class FreeboxChannel;
    1111
     12
    1213class FreeboxSignalMonitor : public DTVSignalMonitor, public RTSPListener
    1314{
    1415    Q_OBJECT
     
    3940    static void *TableMonitorThread(void *param);
    4041    void RunTableMonitor(void);
    4142
    42   protected:
    43     RTSPComms         *rtsp;
     43  private:
     44    RTSPComms& rtsp();
     45
     46  private:
     47    FreeboxChannel    *_channel;
    4448    bool               dtvMonitorRunning;
    4549    pthread_t          table_monitor_thread;
    4650};
  • libs/libmythtv/freeboxrecorder.cpp

     
    44 *  Distributed as part of MythTV under GPL v2 and later.
    55 */
    66
     7// main header
     8#include "freeboxrecorder.h"
     9
    710// MythTV headers
     11#include "freeboxchannel.h"
    812#include "mpegstreamdata.h"
     13#include "rtspcomms.h"
    914#include "tspacket.h"
    10 #include "freeboxchannel.h"
    11 #include "freeboxrecorder.h"
    1215
    1316#define LOC QString("FBRec: ")
    1417#define LOC_ERR QString("FBRec, Error: ")
    1518
     19
    1620// ============================================================================
    1721// FreeboxRecorder : Processes data from RTSPComms and writes it to disk
    1822// ============================================================================
     
    2024FreeboxRecorder::FreeboxRecorder(TVRec *rec, FreeboxChannel *channel) :
    2125    DTVRecorder(rec),
    2226    _channel(channel),
    23     _stream_data(NULL),
    24     _rtsp(new RTSPComms(this))
     27    _stream_data(NULL)
    2528{
     29    _channel->SetRecorder(this);
    2630}
    2731
    2832FreeboxRecorder::~FreeboxRecorder()
    2933{
    3034    StopRecording();
     35    _channel->SetRecorder(NULL);
     36}
    3137
    32     if (_rtsp)
    33     {
    34         delete _rtsp;
    35         _rtsp = NULL;
    36     }
     38RTSPComms& FreeboxRecorder::rtsp()
     39{
     40    return _channel->rtsp();
    3741}
    3842
    3943bool FreeboxRecorder::Open(void)
    4044{
    4145    VERBOSE(VB_RECORD, LOC + "Open() -- begin");
    4246
    43     if (_rtsp->IsOpen())
    44         _rtsp->Close();
     47    if (rtsp().IsOpen())
     48        rtsp().Close();
    4549
    4650    FreeboxChannelInfo chaninfo = _channel->GetCurrentChanInfo();
    4751    if (!chaninfo.isValid())
     
    5054    }
    5155    else
    5256    {
    53         _error = !(_rtsp->Init());
     57        _error = !(rtsp().Init());
    5458        if (!_error)
    55             _error = !(_rtsp->Open(chaninfo.m_url));
     59            _error = !(rtsp().Open(chaninfo.m_url));
    5660    }
    5761
    5862    VERBOSE(VB_RECORD, LOC + "Open() -- end err("<<_error<<")");
     
    6266void FreeboxRecorder::Close(void)
    6367{
    6468    VERBOSE(VB_RECORD, LOC + "Close() -- begin");
    65     _rtsp->Stop();
    66     _rtsp->Close();
     69    rtsp().Stop();
     70    rtsp().Close();
    6771    VERBOSE(VB_RECORD, LOC + "Close() -- end");
    6872}
    6973
     
    7175{
    7276    VERBOSE(VB_RECORD, LOC + "Pause() -- begin");
    7377    DTVRecorder::Pause(clear);
    74     _rtsp->Stop();
    75     _rtsp->Close();
     78    rtsp().Stop();
     79    rtsp().Close();
    7680    VERBOSE(VB_RECORD, LOC + "Pause() -- end");
    7781}
    7882
    7983void FreeboxRecorder::Unpause(void)
    8084{
    8185    VERBOSE(VB_RECORD, LOC + "Unpause() -- begin");
    82     if (_recording && !_rtsp->IsOpen())
     86    if (_recording && !rtsp().IsOpen())
    8387        Open();
    8488    DTVRecorder::Unpause();
    8589    VERBOSE(VB_RECORD, LOC + "Unpause() -- end");
     
    103107        if (PauseAndWait())
    104108            continue;
    105109
    106         if (!_rtsp->IsOpen())
     110        if (!rtsp().IsOpen())
    107111        {
    108112            usleep(5000);
    109113            continue;
    110114        }
    111115
    112116        // Go into main RTSP loop, feeding data to AddData
    113         _rtsp->Run();
     117        rtsp().Run();
    114118    }
    115119
    116120    // Finish up...
     
    126130{
    127131    VERBOSE(VB_RECORD, LOC + "StopRecording() -- begin");
    128132    Pause();
    129     _rtsp->Close();
     133    rtsp().Close();
    130134
    131135    _request_recording = false;
    132136    while (_recording)
  • libs/libmythtv/rtspcomms.cpp

     
    107107                QString("Freebox # Failed to create RTSP client: %1")
    108108                .arg(_live_env->getResultMsg()));
    109109
    110         _live_env = NULL; // TODO free resources.
     110        _live_env->reclaim();
     111        _live_env = NULL;
     112        delete scheduler;
    111113    }
    112114
    113115    VERBOSE(VB_RECORD, LOC + "Init() -- end");
     
    127129        _rtsp_client = NULL;
    128130    }
    129131
    130     _live_env = NULL; // TODO free resources.
     132    if (_live_env)
     133    {
     134        TaskScheduler *scheduler = &_live_env->taskScheduler();
     135        _live_env->reclaim();
     136        _live_env = NULL;
     137        delete scheduler;
     138    }
    131139    VERBOSE(VB_RECORD, LOC + "Deinit() -- end");
    132140}
    133141
  • libs/libmythtv/freeboxmediasink.h

     
    1616    virtual void AddData(unsigned char *data,
    1717                         unsigned int   dataSize,
    1818                         struct timeval presentationTime) = 0;
     19  protected:
     20    virtual ~RTSPListener() {}
    1921};
    2022
    2123// ============================================================================
  • libs/libmythtv/freeboxrecorder.h

     
    1111
    1212#include "dtvrecorder.h"
    1313#include "freeboxmediasink.h"
    14 #include "rtspcomms.h"
    1514#include "streamlisteners.h"
    1615
    17 class TSPacket;
    1816class FreeboxChannel;
    19 class FreeboxChannelInfo;
    20 class MPEGStreamData;
     17class RTSPComms;
    2118
     19
    2220/** \brief Processes data from RTSPComms and writes it to disk.
    2321 */
    2422class FreeboxRecorder : public DTVRecorder, public RTSPListener,
     
    5755    // implements MPEGSingleProgramStreamListener
    5856    void HandleSingleProgramPAT(ProgramAssociationTable *pat);
    5957    void HandleSingleProgramPMT(ProgramMapTable *pmt);
     58    RTSPComms& rtsp();
    6059
    6160  private:
    6261    FreeboxChannel *_channel;
    6362    MPEGStreamData *_stream_data;
    64     RTSPComms      *_rtsp;
    6563    QWaitCondition  _cond_recording;
    6664
    6765