Alex Bikfalvi
SimStream Documentation
StreamClientPushMulti.h
00001 #pragma once 00002 00003 #include "StreamClient.h" 00004 #include "StreamBuffer.h" 00005 #include "StreamBufferMulti.h" 00006 #include "StreamEncoderFrame.h" 00007 #include "StreamDecoderFrame.h" 00008 #include "InfoPushMulti.h" 00009 #include "Link.h" 00010 #include "Timer.h" 00011 00012 #include "StreamMessagePushMultiJoin.h" 00013 #include "StreamMessagePushMultiLeave.h" 00014 #include "StreamMessagePushMultiClose.h" 00015 #include "StreamMessageBootPushMultiRequest.h" 00016 #include "StreamMessageBootPushMultiResponse.h" 00017 #include "StreamMessageBootPushMultiRegister.h" 00018 #include "StreamMessageBootPushMultiDeregister.h" 00019 00020 class CStreamClientPushMulti : public CStreamClient 00021 { 00022 private: 00023 enum EClientState 00024 { 00025 STOPPED = 0, 00026 MCAST_STREAM_FIRST = 10, 00027 MCAST_STREAM_BUFFERING = 11, 00028 MCAST_STREAM_PLAY = 12, 00029 MCAST_STREAM_WAIT = 13, 00030 UCAST_BOOTSTRAP_REQUEST = 20, 00031 UCAST_BOOTSTRAP_RESPONSE = 21, 00032 UCAST_JOIN_REQUEST = 22, 00033 UCAST_STREAM_FIRST = 23, 00034 UCAST_STREAM_BUFFERING = 24, 00035 UCAST_STREAM_PLAY = 25, 00036 UCAST_STREAM_WAIT = 26, 00037 UCAST_STREAM_RESET = 27 00038 }; 00039 00040 enum ERegistrationState 00041 { 00042 NOT_REGISTERED = 0, 00043 REGISTERED = 1 00044 }; 00045 00046 enum ELayerState 00047 { 00048 LAYER_IDLE = 0, 00049 LAYER_BUFFERING = 1, 00050 LAYER_READY = 2 00051 }; 00052 00053 class CLayersInfo 00054 { 00055 private: 00056 __uint32 numBuffering; 00057 __uint32 numReady; 00058 00059 __uint32 numRegistered; 00060 00061 public: 00062 CLayersInfo(); 00063 virtual ~CLayersInfo() { } 00064 00065 inline __uint32 NumBuffering() { return this->numBuffering; } 00066 inline __uint32 NumReady() { return this->numReady; } 00067 inline __uint32 NumRegistered() { return this->numRegistered; } 00068 inline __uint32 NumTotal() { return this->numBuffering + this->numReady; } 00069 00070 inline void IdleToBuffering() { this->numBuffering++; } 00071 inline void BufferingToReady() { assert(this->numBuffering); this->numBuffering--; this->numReady++; } 00072 inline void ReadyToBuffering() { assert(this->numReady); this->numReady--; this->numBuffering++; } 00073 00074 inline void Register() { this->numRegistered++; } 00075 inline void Deregister() { assert(this->numRegistered); this->numRegistered--; } 00076 00077 inline void Reset() { this->numBuffering = 0; this->numReady = 0; this->numRegistered = 0; } 00078 }; 00079 00080 class CLayer : public CTimerInfo 00081 { 00082 private: 00083 // Layer 00084 __uint32 layer; 00085 CLayersInfo* info; 00086 CChannel* channel; 00087 00088 // State 00089 ELayerState stateLayer; 00090 ERegistrationState stateRegister; 00091 00092 // Stream 00093 void (CStreamClientPushMulti::*process)(CStreamFrame frame, __uint32 layer); // Layer processing 00094 set<CAddress> neighbors; 00095 set<CAddress> receivers; 00096 CAddress sender; 00097 00098 CTimer<CStreamClientPushMulti>* timerRegister; // Register timer 00099 CTimer<CStreamClientPushMulti>* timerBuffer; // Buffering timer 00100 00101 public: 00102 CLayer( 00103 __uint32 layer, 00104 CSimHandler* sim, 00105 CStreamClientPushMulti* client, 00106 CLayersInfo* info, 00107 void (CStreamClientPushMulti::*timerBootHandler)(CTimerInfo*), 00108 void (CStreamClientPushMulti::*timerRegisterHandler)(CTimerInfo*), 00109 void (CStreamClientPushMulti::*timerBufferHandler)(CTimerInfo*) 00110 ); 00111 virtual ~CLayer(); 00112 00113 inline __uint32 Layer() { return this->layer; } 00114 00115 inline CTimer<CStreamClientPushMulti>* TimerRegister() { return this->timerRegister; } 00116 inline CTimer<CStreamClientPushMulti>* TimerBuffer() { return this->timerBuffer; } 00117 00118 inline ELayerState StateLayer() { return this->stateLayer; } 00119 inline ERegistrationState StateRegister() { return this->stateRegister; } 00120 00121 void Buffering(); 00122 void Ready(); 00123 00124 inline void Register() { this->stateRegister = REGISTERED; this->info->Register(); } 00125 inline void Deregister() { this->stateRegister = NOT_REGISTERED; this->info->Deregister(); } 00126 00127 inline set<CAddress>* Neighbors() { return &this->neighbors; } 00128 inline set<CAddress>* Receivers() { return &this->receivers; } 00129 inline CAddress Sender() { return this->sender; } 00130 inline void Sender(CAddress sender) { this->sender = sender; } 00131 00132 void Start(CChannel* channel); 00133 void Stop(); 00134 00135 inline void (CStreamClientPushMulti::*ProcessFrame())(CStreamFrame frame, __uint32 layer) { return this->process; } 00136 inline void Process(void (CStreamClientPushMulti::*process)(CStreamFrame frame, __uint32 layer)) { this->process = process; } 00137 }; 00138 00139 // State 00140 EClientState stateClient; 00141 00142 // Simulator 00143 CInfoPushMulti* info; 00144 CAddress address; 00145 00146 // Channel 00147 CChannel* channel; 00148 00149 // Buffer 00150 CStreamBuffer* bufferMcast; 00151 CStreamBufferMulti* bufferUcast; 00152 00153 // Session 00154 void (CStreamClientPushMulti::*processFrame)(CStreamFrame frame); // Client processing 00155 __time sessionTimeLastStart; 00156 __time sessionTimeLastStop; 00157 __uint32 sessionFrameLastStart; 00158 __uint32 sessionFrameLastStop; 00159 00160 // Unicast session 00161 __bitrate bw; // Uplink bandwidth 00162 __bitrate bwUsed; // Used uplink bandwidth 00163 00164 CLayer** layers; 00165 CLayersInfo layersInfo; 00166 00167 // Multicast session 00168 __uint32 entry; // Multicast interface (0 - as host have only one interface) 00169 00170 // Timer 00171 CTimer<CStreamClientPushMulti>* timerPlayMcast; // Playback timer (multicast channels) 00172 CTimer<CStreamClientPushMulti>* timerPlayUcast; // Playback timer (unicast channels) 00173 CTimer<CStreamClientPushMulti>* timerBoot; // Bootstrap timer (global - all layers) 00174 00175 __uint32 timerBufferChannel; 00176 00177 // Delegates - receive 00178 Delegate2<CStreamClientPushMulti, void, CAddress, CStreamFrame>* 00179 delegateRecvFrameMcast; 00180 Delegate2<CStreamClientPushMulti, void, CAddress, CStreamFrame>* 00181 delegateRecvFrameUcast; 00182 00183 IDelegate2<void, CAddress, CPacketStream*>* 00184 delegateSendStream; 00185 IDelegate2<void, CAddress, CStreamMessage*>* 00186 delegateSendMessage; 00187 00188 IDelegate2<void, CAddress, __uint32>* 00189 delegateIgmpJoin; 00190 IDelegate1<void, CAddress>* delegateIgmpLeave; 00191 00192 00193 IDelegate0<CLink*>* delegateLink; 00194 00195 00196 // Encoder 00197 CStreamEncoderFrame* encoder; 00198 00199 // Decoders 00200 CStreamDecoder* decoder; 00201 CStreamDecoderFrame* decoderMcast; 00202 CStreamDecoderFrame* decoderUcast; 00203 00204 // Statistics 00205 __uint32 statRecvFrames; 00206 __uint32 statDiscardedFrames; 00207 __uint32 statPlayFrames; 00208 __uint32 statSuccessFrames[3]; 00209 __uint32 statFailFrames[3]; 00210 00211 __uint32 statPlayFirstFrame; 00212 __uint32 statPlayLastFrame; 00213 00214 __time statTimeClientStart; 00215 __time statTimeRecvStart; 00216 __time statTimePlayStart; 00217 __time statTimeFinish; 00218 __time statTimeWait; 00219 00220 __time statSyncDelaySum; 00221 __uint32 statSyncDelayCount; 00222 00223 public: 00224 CStreamClientPushMulti( 00225 CSimHandler* sim, 00226 CInfoPushMulti* info, 00227 CAddress address, 00228 IDelegate2<void, CAddress, CPacketStream*>* delegateSendStream, 00229 IDelegate2<void, CAddress, CStreamMessage*>* delegateSendMessage, 00230 IDelegate2<void, CAddress, __uint32>* delegateIgmpJoin, 00231 IDelegate1<void, CAddress>* delegateIgmpLeave, 00232 IDelegate0<CLink*>* delegateLink, 00233 __uint32 entry, 00234 __bitrate bw 00235 ); 00236 virtual ~CStreamClientPushMulti(); 00237 00238 virtual void Start(CChannel* channel); 00239 virtual void Stop(); 00240 00241 virtual void Recv(CAddress srcAddress, CAddress dstAddress, __uint16 srcPort, __uint16 dstPort, CPacket* packet); 00242 00243 virtual inline __uint32 StatRecvFrames() { return this->statRecvFrames; } 00244 virtual inline __uint32 StatDiscardedFrames() { return this->statDiscardedFrames; } 00245 virtual inline __uint32 StatPlayFrames() { return this->statPlayFrames; } 00246 virtual inline __uint32* StatSuccessFrames() { return this->statSuccessFrames; } 00247 virtual inline __uint32* StatFailFrames() { return this->statFailFrames; } 00248 00249 virtual inline __time StatTimeClientStart() { return this->statTimeClientStart; } 00250 virtual inline __time StatTimeRecvStart() { return this->statTimeRecvStart; } 00251 virtual inline __time StatTimePlayStart() { return this->statTimePlayStart; } 00252 virtual inline __time StatTimeFinish() { return this->statTimeFinish; } 00253 virtual inline __time StatTimeWait() { return this->statTimeWait; } 00254 00255 virtual inline __uint32 StatPlayFirstFrame() { return this->statPlayFirstFrame; } 00256 virtual inline __uint32 StatPlayLastFrame() { return this->statPlayLastFrame; } 00257 00258 virtual inline __time StatSyncDelay() { return this->statSyncDelayCount?(this->statSyncDelaySum / this->statSyncDelayCount):-1; } 00259 00260 virtual void Finalize(); 00261 00262 private: 00263 void StartMcast(); 00264 void StartUcast(); 00265 00266 void StopMcast(); 00267 void StopUcast(); 00268 00269 void RecvStream(CAddress dst, CPacketStream* packet); 00270 void RecvMessage(CAddress src, CStreamMessage* message); 00271 00272 void RecvFrameMcast(CAddress src, CStreamFrame frame); 00273 00274 void ProcessFrameMcastFirst(CStreamFrame frame); 00275 void ProcessFrameMcastBuffering(CStreamFrame frame); 00276 void ProcessFrameMcastPlay(CStreamFrame frame); 00277 void ProcessFrameMcastWait(CStreamFrame frame); 00278 00279 void RecvFrameUcast(CAddress src, CStreamFrame frame); 00280 00281 void ProcessFrameUcastFirst(CStreamFrame frame); 00282 void ProcessFrameUcastBuffering(CStreamFrame frame); 00283 void ProcessFrameUcastPlay(CStreamFrame frame); 00284 void ProcessFrameUcastWait(CStreamFrame frame); 00285 void ProcessFrameUcastReset(CStreamFrame frame); 00286 00287 void ProcessFrameUcastLayerBuffering(CStreamFrame frame, __uint32 layer); 00288 void ProcessFrameUcastLayerReady(CStreamFrame frame, __uint32 layer); 00289 00290 void RecvMessageJoin(CAddress src, CStreamMessagePushMultiJoin* message); 00291 void RecvMessageLeave(CAddress src, CStreamMessagePushMultiLeave* message); 00292 void RecvMessageClose(CAddress src, CStreamMessagePushMultiClose* message); 00293 void RecvMessageBootResponse(CAddress src, CStreamMessageBootPushMultiResponse* message); 00294 00295 void StreamBootstrap(); 00296 void StreamJoin(); 00297 void StreamJoin(__uint32 layer); 00298 void StreamLeave(); 00299 void StreamLeave(__uint32 layer); 00300 void StreamRegister(__uint32 layer); 00301 void StreamDeregister(__uint32 layer); 00302 void StreamClose(); 00303 00304 void SendStream(CStreamFrame frame, __uint32 layer); 00305 00306 void RejectJoin(CAddress src, CStreamMessagePushMultiJoin* message); 00307 00308 void TimerPlayMcast(CTimerInfo* info); 00309 void TimerPlayUcast(CTimerInfo* info); 00310 void TimerBoot(CTimerInfo* info); 00311 void TimerRegister(CTimerInfo* info); 00312 void TimerBuffer(CTimerInfo* info); 00313 };
Last updated: February 8, 2011