RtspClientSession.h

00001 #ifndef __RTVC_RTSP_CLIENT_SESSION
00002 #define __RTVC_RTSP_CLIENT_SESSION
00003 
00004 // STL
00005 #include <string>
00006 #include <vector>
00007 
00008 #include <liveMedia.hh>
00009 
00010 // Forward decl
00011 class RtspSourceFilter;
00012 
00013 // LiveMedia
00014 class UsageEnvironment;
00015 class RTSPClient;
00016 class MediaSession;
00017 class LiveDirectShowSink;
00018 
00019 class RtspClientSession
00020 {
00021 public:
00022         RtspClientSession(RtspSourceFilter* pSourceFilter, bool bStreamUsingTcp = true);
00023         virtual ~RtspClientSession(){}
00024 
00026         std::string LastError() const { return m_sLastError; }
00027 
00028         bool start(std::string sUrl);
00029         
00030         int TimeoutS() const { return m_nTimeoutS; }
00031         void TimeoutS(int val) { m_nTimeoutS = val; }
00032 
00033         bool initialiseRtspSession( const char* szUrl );
00034         bool setupAndPlayRtspSession();
00035 
00036         void shutdown();
00037 
00038         static void subsessionByeHandler(void* clientData) 
00039         {
00040                 RtspClientSession* pClientSession = (RtspClientSession*) clientData;
00041                 pClientSession->shutdown();
00042                 // TODO: still need to notify DS filter that a stop has occurred!!!!!
00043         }
00044 
00045         void beginQOSMeasurement();
00046 
00047         void scheduleNextQOSMeasurement();
00048         void periodicQOSMeasurement();
00049         static void doPeriodicQOSMeasurement(void* clientData) ;
00050 
00051         //static void subsessionAfterPlaying(void* clientData) 
00052         //{
00053         //      // Begin by closing this media subsession's stream:
00054         //      MediaSubsession* subsession = (MediaSubsession*)clientData;
00055         //      Medium::close(subsession->sink);
00056         //      subsession->sink = NULL;
00057 
00058         //      // Next, check whether *all* subsessions' streams have now been closed:
00059         //      MediaSession& session = subsession->parentSession();
00060         //      MediaSubsessionIterator iter(session);
00061         //      while ((subsession = iter.next()) != NULL) {
00062         //              if (subsession->sink != NULL) return; // this subsession is still active
00063         //      }
00064 
00065         //      // All subsessions' streams have now been closed
00066         //      //sessionAfterPlaying();
00067         //}
00068 protected:
00069 
00070         class qosMeasurementRecord {
00071         public:
00072                 qosMeasurementRecord(struct timeval const& startTime, RTPSource* src)
00073                         : fSource(src), fNext(NULL),
00074                         kbits_per_second_min(1e20), kbits_per_second_max(0),
00075                         kBytesTotal(0.0),
00076                         packet_loss_fraction_min(1.0), packet_loss_fraction_max(0.0),
00077                         totNumPacketsReceived(0), totNumPacketsExpected(0) {
00078                                 measurementEndTime = measurementStartTime = startTime;
00079 
00080                                 RTPReceptionStatsDB::Iterator statsIter(src->receptionStatsDB());
00081                                 // Assume that there's only one SSRC source (usually the case):
00082                                 RTPReceptionStats* stats = statsIter.next(True);
00083                                 if (stats != NULL) {
00084                                         kBytesTotal = stats->totNumKBytesReceived();
00085                                         totNumPacketsReceived = stats->totNumPacketsReceived();
00086                                         totNumPacketsExpected = stats->totNumPacketsExpected();
00087                                 }
00088                 }
00089                 virtual ~qosMeasurementRecord() { delete fNext; }
00090 
00091                 void periodicQOSMeasurement(struct timeval const& timeNow);
00092 
00093         public:
00094                 RTPSource* fSource;
00095                 qosMeasurementRecord* fNext;
00096 
00097         public:
00098                 struct timeval measurementStartTime, measurementEndTime;
00099                 double kbits_per_second_min, kbits_per_second_max;
00100                 double kBytesTotal;
00101                 double packet_loss_fraction_min, packet_loss_fraction_max;
00102                 unsigned totNumPacketsReceived, totNumPacketsExpected;
00103         };
00104 protected:
00105         // Override this if you want to do anything after session creation
00106         virtual bool afterSessionInit()
00107         {
00108                 return true;
00109         }
00110 
00111         // This should return false for stream init where the media type does not need to be detected
00112         virtual bool needToPlayStream()
00113         {
00114                 return true;
00115         }
00116 
00117         virtual bool isMediaTypeKnown()
00118         {
00119                 return true;
00120         }
00121         
00122         
00123 
00124         bool createRtpSources();
00125         bool setupStreams();
00126         bool createRtpReceivers();
00127         bool startPlayingStreams();
00128 
00129 
00130         void closeMediaSinks();
00131 
00132         qosMeasurementRecord* qosRecordHead;
00133         unsigned qosMeasurementIntervalMS;
00134         TaskToken qosMeasurementTimerTask;
00135 
00136         // LiveMedia 
00137         UsageEnvironment* env;
00138         RTSPClient* m_pRtspClient;
00139         MediaSession* m_pSession;
00140         unsigned m_statusCode;
00141         unsigned nextQOSMeasurementUSecs;
00142         int m_nTimeoutS;
00143         std::vector<LiveDirectShowSink*> m_vLiveMediaSinks;
00144         // DirectShow stuff
00145         RtspSourceFilter* m_pSourceFilter;
00146         bool m_bStreamUsingTCP;
00147         // URL
00148         std::string m_sUrl;
00149         std::string m_sLastError;
00150 };
00151 #endif

Generated on Fri Mar 13 14:12:38 2009 for RTVC by  doxygen 1.5.3