00001 #ifndef __RTVC_RTSP_CLIENT_SESSION
00002 #define __RTVC_RTSP_CLIENT_SESSION
00003
00004
00005 #include <string>
00006 #include <vector>
00007
00008 #include <liveMedia.hh>
00009
00010
00011 class RtspSourceFilter;
00012
00013
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
00043 }
00044
00045 void beginQOSMeasurement();
00046
00047 void scheduleNextQOSMeasurement();
00048 void periodicQOSMeasurement();
00049 static void doPeriodicQOSMeasurement(void* clientData) ;
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
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
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
00106 virtual bool afterSessionInit()
00107 {
00108 return true;
00109 }
00110
00111
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
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
00145 RtspSourceFilter* m_pSourceFilter;
00146 bool m_bStreamUsingTCP;
00147
00148 std::string m_sUrl;
00149 std::string m_sLastError;
00150 };
00151 #endif