Ticket #2064: patch-shared-rtsp.diff
File patch-shared-rtsp.diff, 12.1 KB (added by , 18 years ago) |
---|
-
libs/libmythtv/freeboxsignalmonitor.cpp
1 1 // -*- Mode: c++ -*- 2 2 3 #include "mythcontext.h" 3 // main header 4 #include "freeboxsignalmonitor.h" 5 6 // MythTV headers 4 7 #include "mpegstreamdata.h" 5 6 #include "freeboxchannel.h"7 #include "freeboxsignalmonitor.h"8 8 #include "rtspcomms.h" 9 9 10 10 #undef DBG_SM … … 14 14 #define LOC QString("FreeboxSM(%1): ").arg(channel->GetDevice()) 15 15 #define LOC_ERR QString("FreeboxSM(%1), Error: ").arg(channel->GetDevice()) 16 16 17 17 18 /** \fn FreeboxSignalMonitor::FreeboxSignalMonitor(int,FreeboxChannel*,uint,const char*) 18 19 * \brief Initializes signal lock and signal values. 19 20 * … … 30 31 * \param _name Instance name for Qt signal/slot debugging 31 32 */ 32 33 FreeboxSignalMonitor::FreeboxSignalMonitor( 33 int db_cardnum, FreeboxChannel * _channel,34 int db_cardnum, FreeboxChannel *channel, 34 35 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), 37 38 dtvMonitorRunning(false) 38 39 { 39 40 bool isLocked = false; 40 if (rtsp ->Init())41 if (rtsp().Init()) 41 42 { 42 43 FreeboxChannelInfo chaninfo = _channel->GetCurrentChanInfo(); 43 isLocked = chaninfo.isValid() && rtsp ->Open(chaninfo.m_url);44 isLocked = chaninfo.isValid() && rtsp().Open(chaninfo.m_url); 44 45 } 45 46 46 47 QMutexLocker locker(&statusLock); … … 53 54 */ 54 55 FreeboxSignalMonitor::~FreeboxSignalMonitor() 55 56 { 57 _channel->SetMonitor(NULL); 56 58 Stop(); 59 } 57 60 58 if (rtsp) 59 { 60 delete rtsp; 61 rtsp = NULL; 62 } 61 RTSPComms& FreeboxSignalMonitor::rtsp() 62 { 63 return _channel->rtsp(); 63 64 } 64 65 65 66 void FreeboxSignalMonitor::deleteLater(void) 66 67 { 67 68 disconnect(); // disconnect signals we may be sending... 69 _channel->SetMonitor(NULL); 68 70 Stop(); 69 71 DTVSignalMonitor::deleteLater(); 70 72 } … … 75 77 void FreeboxSignalMonitor::Stop(void) 76 78 { 77 79 DBG_SM("Stop", "begin"); 80 _channel->SetMonitor(NULL); 78 81 SignalMonitor::Stop(); 79 82 if (dtvMonitorRunning) 80 83 { 81 rtsp ->Stop();84 rtsp().Stop(); 82 85 dtvMonitorRunning = false; 83 86 pthread_join(table_monitor_thread, NULL); 84 87 } … … 101 104 102 105 GetStreamData()->AddListeningPID(0); 103 106 104 rtsp->Run(); 107 _channel->SetMonitor(this); 108 rtsp().Run(); 109 _channel->SetMonitor(NULL); 105 110 106 111 dtvMonitorRunning = false; 107 112 DBG_SM("Run", "end"); -
libs/libmythtv/freeboxchannel.h
9 9 10 10 #include "channelbase.h" 11 11 #include "freeboxchannelinfo.h" 12 #include "freeboxmediasink.h" 12 13 13 14 #include <qmutex.h> 14 15 15 class FreeboxRecorder;16 class RTSPComms; 16 17 17 class FreeboxChannel : public ChannelBase 18 19 class FreeboxChannel : public ChannelBase, 20 public RTSPListener 18 21 { 19 22 public: 20 23 FreeboxChannel(TVRec *parent, const QString &videodev); … … 31 34 32 35 FreeboxChannelInfo GetCurrentChanInfo(void) const 33 36 { return GetChanInfo(curchannelname); } 37 RTSPComms& rtsp() { return *m_rtsp; } 38 39 void SetMonitor(RTSPListener* monitor); 40 void SetRecorder(RTSPListener* recorder); 34 41 35 42 private: 36 43 FreeboxChannelInfo GetChanInfo(const QString& channum, 37 44 uint sourceid = 0) const; 45 // implements RTSPListener 46 void AddData(unsigned char *data, 47 unsigned int dataSize, 48 struct timeval presentationTime); 38 49 50 private: 39 51 QString m_videodev; 40 52 fbox_chan_map_t m_freeboxchannels; 53 RTSPComms *m_rtsp; 54 RTSPListener *m_monitor; 55 RTSPListener *m_recorder; 41 56 mutable QMutex m_lock; 42 57 43 58 private: -
libs/libmythtv/freeboxchannel.cpp
6 6 7 7 #include "freeboxchannel.h" 8 8 9 #include <qdeepcopy.h> 10 11 #include "libmyth/mythcontext.h" 12 #include "libmyth/mythdbcon.h" 9 13 #include "libmythtv/freeboxchannelfetcher.h" 10 #include "libmythtv/freeboxrecorder.h" 11 #include "libmythtv/tv_rec.h" 14 #include "libmythtv/rtspcomms.h" 12 15 13 16 #define LOC QString("FBChan(%1): ").arg(GetCardID()) 14 17 #define LOC_ERR QString("FBChan(%1), Error: ").arg(GetCardID()) 15 18 19 16 20 FreeboxChannel::FreeboxChannel(TVRec *parent, 17 21 const QString &videodev) 18 22 : ChannelBase(parent), 19 23 m_videodev(QDeepCopy<QString>(videodev)), 24 m_rtsp(new RTSPComms(this)), 25 m_monitor(NULL), 26 m_recorder(NULL), 20 27 m_lock(true) 21 28 { 22 29 VERBOSE(VB_CHANNEL, LOC + "ctor"); … … 24 31 25 32 FreeboxChannel::~FreeboxChannel() 26 33 { 27 VERBOSE(VB_CHANNEL, LOC + "dtor"); 34 VERBOSE(VB_CHANNEL, LOC + "dtor -- begin"); 35 delete m_rtsp; 36 VERBOSE(VB_CHANNEL, LOC + "dtor -- end"); 28 37 } 29 38 30 39 bool FreeboxChannel::Open(void) … … 196 205 return dummy; 197 206 } 198 207 208 void FreeboxChannel::SetMonitor(RTSPListener* monitor) 209 { 210 QMutexLocker locker(&m_lock); 211 m_monitor = monitor; 212 } 213 214 void FreeboxChannel::SetRecorder(RTSPListener* recorder) 215 { 216 QMutexLocker locker(&m_lock); 217 m_recorder = recorder; 218 } 219 220 void 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 199 231 /* vim: set expandtab tabstop=4 shiftwidth=4: */ -
libs/libmythtv/freeboxsignalmonitor.h
9 9 class RTSPComms; 10 10 class FreeboxChannel; 11 11 12 12 13 class FreeboxSignalMonitor : public DTVSignalMonitor, public RTSPListener 13 14 { 14 15 Q_OBJECT … … 39 40 static void *TableMonitorThread(void *param); 40 41 void RunTableMonitor(void); 41 42 42 protected: 43 RTSPComms *rtsp; 43 private: 44 RTSPComms& rtsp(); 45 46 private: 47 FreeboxChannel *_channel; 44 48 bool dtvMonitorRunning; 45 49 pthread_t table_monitor_thread; 46 50 }; -
libs/libmythtv/freeboxrecorder.cpp
4 4 * Distributed as part of MythTV under GPL v2 and later. 5 5 */ 6 6 7 // main header 8 #include "freeboxrecorder.h" 9 7 10 // MythTV headers 11 #include "freeboxchannel.h" 8 12 #include "mpegstreamdata.h" 13 #include "rtspcomms.h" 9 14 #include "tspacket.h" 10 #include "freeboxchannel.h"11 #include "freeboxrecorder.h"12 15 13 16 #define LOC QString("FBRec: ") 14 17 #define LOC_ERR QString("FBRec, Error: ") 15 18 19 16 20 // ============================================================================ 17 21 // FreeboxRecorder : Processes data from RTSPComms and writes it to disk 18 22 // ============================================================================ … … 20 24 FreeboxRecorder::FreeboxRecorder(TVRec *rec, FreeboxChannel *channel) : 21 25 DTVRecorder(rec), 22 26 _channel(channel), 23 _stream_data(NULL), 24 _rtsp(new RTSPComms(this)) 27 _stream_data(NULL) 25 28 { 29 _channel->SetRecorder(this); 26 30 } 27 31 28 32 FreeboxRecorder::~FreeboxRecorder() 29 33 { 30 34 StopRecording(); 35 _channel->SetRecorder(NULL); 36 } 31 37 32 if (_rtsp) 33 { 34 delete _rtsp; 35 _rtsp = NULL; 36 } 38 RTSPComms& FreeboxRecorder::rtsp() 39 { 40 return _channel->rtsp(); 37 41 } 38 42 39 43 bool FreeboxRecorder::Open(void) 40 44 { 41 45 VERBOSE(VB_RECORD, LOC + "Open() -- begin"); 42 46 43 if ( _rtsp->IsOpen())44 _rtsp->Close();47 if (rtsp().IsOpen()) 48 rtsp().Close(); 45 49 46 50 FreeboxChannelInfo chaninfo = _channel->GetCurrentChanInfo(); 47 51 if (!chaninfo.isValid()) … … 50 54 } 51 55 else 52 56 { 53 _error = !( _rtsp->Init());57 _error = !(rtsp().Init()); 54 58 if (!_error) 55 _error = !( _rtsp->Open(chaninfo.m_url));59 _error = !(rtsp().Open(chaninfo.m_url)); 56 60 } 57 61 58 62 VERBOSE(VB_RECORD, LOC + "Open() -- end err("<<_error<<")"); … … 62 66 void FreeboxRecorder::Close(void) 63 67 { 64 68 VERBOSE(VB_RECORD, LOC + "Close() -- begin"); 65 _rtsp->Stop();66 _rtsp->Close();69 rtsp().Stop(); 70 rtsp().Close(); 67 71 VERBOSE(VB_RECORD, LOC + "Close() -- end"); 68 72 } 69 73 … … 71 75 { 72 76 VERBOSE(VB_RECORD, LOC + "Pause() -- begin"); 73 77 DTVRecorder::Pause(clear); 74 _rtsp->Stop();75 _rtsp->Close();78 rtsp().Stop(); 79 rtsp().Close(); 76 80 VERBOSE(VB_RECORD, LOC + "Pause() -- end"); 77 81 } 78 82 79 83 void FreeboxRecorder::Unpause(void) 80 84 { 81 85 VERBOSE(VB_RECORD, LOC + "Unpause() -- begin"); 82 if (_recording && ! _rtsp->IsOpen())86 if (_recording && !rtsp().IsOpen()) 83 87 Open(); 84 88 DTVRecorder::Unpause(); 85 89 VERBOSE(VB_RECORD, LOC + "Unpause() -- end"); … … 103 107 if (PauseAndWait()) 104 108 continue; 105 109 106 if (! _rtsp->IsOpen())110 if (!rtsp().IsOpen()) 107 111 { 108 112 usleep(5000); 109 113 continue; 110 114 } 111 115 112 116 // Go into main RTSP loop, feeding data to AddData 113 _rtsp->Run();117 rtsp().Run(); 114 118 } 115 119 116 120 // Finish up... … … 126 130 { 127 131 VERBOSE(VB_RECORD, LOC + "StopRecording() -- begin"); 128 132 Pause(); 129 _rtsp->Close();133 rtsp().Close(); 130 134 131 135 _request_recording = false; 132 136 while (_recording) -
libs/libmythtv/rtspcomms.cpp
107 107 QString("Freebox # Failed to create RTSP client: %1") 108 108 .arg(_live_env->getResultMsg())); 109 109 110 _live_env = NULL; // TODO free resources. 110 _live_env->reclaim(); 111 _live_env = NULL; 112 delete scheduler; 111 113 } 112 114 113 115 VERBOSE(VB_RECORD, LOC + "Init() -- end"); … … 127 129 _rtsp_client = NULL; 128 130 } 129 131 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 } 131 139 VERBOSE(VB_RECORD, LOC + "Deinit() -- end"); 132 140 } 133 141 -
libs/libmythtv/freeboxmediasink.h
16 16 virtual void AddData(unsigned char *data, 17 17 unsigned int dataSize, 18 18 struct timeval presentationTime) = 0; 19 protected: 20 virtual ~RTSPListener() {} 19 21 }; 20 22 21 23 // ============================================================================ -
libs/libmythtv/freeboxrecorder.h
11 11 12 12 #include "dtvrecorder.h" 13 13 #include "freeboxmediasink.h" 14 #include "rtspcomms.h"15 14 #include "streamlisteners.h" 16 15 17 class TSPacket;18 16 class FreeboxChannel; 19 class FreeboxChannelInfo; 20 class MPEGStreamData; 17 class RTSPComms; 21 18 19 22 20 /** \brief Processes data from RTSPComms and writes it to disk. 23 21 */ 24 22 class FreeboxRecorder : public DTVRecorder, public RTSPListener, … … 57 55 // implements MPEGSingleProgramStreamListener 58 56 void HandleSingleProgramPAT(ProgramAssociationTable *pat); 59 57 void HandleSingleProgramPMT(ProgramMapTable *pmt); 58 RTSPComms& rtsp(); 60 59 61 60 private: 62 61 FreeboxChannel *_channel; 63 62 MPEGStreamData *_stream_data; 64 RTSPComms *_rtsp;65 63 QWaitCondition _cond_recording; 66 64 67 65