Alex Bikfalvi
SimStream Documentation
StreamClientPushSelect.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 "InfoPushSelect.h" 00009 #include "Link.h" 00010 #include "Timer.h" 00011 00012 #include "StreamMessagePushSelectJoin.h" 00013 #include "StreamMessagePushSelectLeave.h" 00014 #include "StreamMessagePushSelectClose.h" 00015 #include "StreamMessageBootPushSelectRequest.h" 00016 #include "StreamMessageBootPushSelectResponse.h" 00017 #include "StreamMessageBootPushSelectRegister.h" 00018 #include "StreamMessageBootPushSelectDeregister.h" 00019 00020 class CStreamClientPushSelect : 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 (CStreamClientPushSelect::*process)(CStreamFrame frame, __uint32 layer); // Layer processing 00094 set<CAddress> neighbors; 00095 set<CAddress> receivers; 00096 CAddress sender; 00097 00098 CTimer<CStreamClientPushSelect>* timerRegister; // Register timer 00099 CTimer<CStreamClientPushSelect>* timerBuffer; // Buffering timer 00100 00101 public: 00102 CLayer( 00103 __uint32 layer, 00104 CSimHandler* sim, 00105 CStreamClientPushSelect* client, 00106 CLayersInfo* info, 00107 void (CStreamClientPushSelect::*timerBootHandler)(CTimerInfo*), 00108 void (CStreamClientPushSelect::*timerRegisterHandler)(CTimerInfo*), 00109 void (CStreamClientPushSelect::*timerBufferHandler)(CTimerInfo*) 00110 ); 00111 virtual ~CLayer(); 00112 00113 inline __uint32 Layer() { return this->layer; } 00114 00115 inline CTimer<CStreamClientPushSelect>* TimerRegister() { return this->timerRegister; } 00116 inline CTimer<CStreamClientPushSelect>* 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 (CStreamClientPushSelect::*ProcessFrame())(CStreamFrame frame, __uint32 layer) { return this->process; } 00136 inline void Process(void (CStreamClientPushSelect::*process)(CStreamFrame frame, __uint32 layer)) { this->process = process; } 00137 }; 00138 00139 // State 00140 EClientState stateClient; 00141 00142 // Simulator 00143 CInfoPushSelect* info; 00144 CAddress address; 00145 00146 // Channel 00147 CChannel* channel; 00148 00149 // Buffer 00150 CStreamBufferMulti* buffer; 00151 00152 // Session 00153 void (CStreamClientPushSelect::*processFrame)(CStreamFrame frame); // Client processing 00154 __time sessionTimeLastStart; 00155 __time sessionTimeLastStop; 00156 __uint32 sessionFrameLastStart; 00157 __uint32 sessionFrameLastStop; 00158 00159 // Unicast session 00160 __bitrate bw; // Uplink bandwidth 00161 __bitrate bwUsed; // Used uplink bandwidth 00162 00163 CLayer** layers; 00164 CLayersInfo layersInfo; 00165 00166 // Multicast session 00167 __uint32 entry; // Multicast interface (0 - as host have only one interface) 00168 00169 // Timer 00170 CTimer<CStreamClientPushSelect>* timerPlay; // Playback timer 00171 CTimer<CStreamClientPushSelect>* timerBoot; // Bootstrap timer (global - all layers) 00172 00173 __uint32 timerBufferChannel; 00174 00175 // Delegates - receive 00176 Delegate2<CStreamClientPushSelect, void, CAddress, CStreamFrame>* 00177 delegateRecvFrame; 00178 00179 IDelegate2<void, CAddress, CPacketStream*>* 00180 delegateSendStream; 00181 IDelegate2<void, CAddress, CStreamMessage*>* 00182 delegateSendMessage; 00183 00184 IDelegate2<void, CAddress, __uint32>* 00185 delegateIgmpJoin; 00186 IDelegate1<void, CAddress>* delegateIgmpLeave; 00187 00188 00189 IDelegate0<CLink*>* delegateLink; 00190 00191 00192 // Encoder 00193 CStreamEncoderFrame* encoder; 00194 00195 // Decoders 00196 CStreamDecoderFrame* decoder; 00197 00198 // Statistics 00199 __uint32 statRecvFrames; 00200 __uint32 statDiscardedFrames; 00201 __uint32 statPlayFrames; 00202 __uint32 statSuccessFrames[3]; 00203 __uint32 statFailFrames[3]; 00204 00205 __uint32 statPlayFirstFrame; 00206 __uint32 statPlayLastFrame; 00207 00208 __time statTimeClientStart; 00209 __time statTimeRecvStart; 00210 __time statTimePlayStart; 00211 __time statTimeFinish; 00212 __time statTimeWait; 00213 00214 __time statSyncDelaySum; 00215 __uint32 statSyncDelayCount; 00216 00217 public: 00218 CStreamClientPushSelect( 00219 CSimHandler* sim, 00220 CInfoPushSelect* info, 00221 CAddress address, 00222 IDelegate2<void, CAddress, CPacketStream*>* delegateSendStream, 00223 IDelegate2<void, CAddress, CStreamMessage*>* delegateSendMessage, 00224 IDelegate2<void, CAddress, __uint32>* delegateIgmpJoin, 00225 IDelegate1<void, CAddress>* delegateIgmpLeave, 00226 IDelegate0<CLink*>* delegateLink, 00227 __uint32 entry, 00228 __bitrate bw 00229 ); 00230 virtual ~CStreamClientPushSelect(); 00231 00232 virtual void Start(CChannel* channel); 00233 virtual void Stop(); 00234 00235 virtual void Recv(CAddress srcAddress, CAddress dstAddress, __uint16 srcPort, __uint16 dstPort, CPacket* packet); 00236 00237 virtual inline __uint32 StatRecvFrames() { return this->statRecvFrames; } 00238 virtual inline __uint32 StatDiscardedFrames() { return this->statDiscardedFrames; } 00239 virtual inline __uint32 StatPlayFrames() { return this->statPlayFrames; } 00240 virtual inline __uint32* StatSuccessFrames() { return this->statSuccessFrames; } 00241 virtual inline __uint32* StatFailFrames() { return this->statFailFrames; } 00242 00243 virtual inline __time StatTimeClientStart() { return this->statTimeClientStart; } 00244 virtual inline __time StatTimeRecvStart() { return this->statTimeRecvStart; } 00245 virtual inline __time StatTimePlayStart() { return this->statTimePlayStart; } 00246 virtual inline __time StatTimeFinish() { return this->statTimeFinish; } 00247 virtual inline __time StatTimeWait() { return this->statTimeWait; } 00248 00249 virtual inline __uint32 StatPlayFirstFrame() { return this->statPlayFirstFrame; } 00250 virtual inline __uint32 StatPlayLastFrame() { return this->statPlayLastFrame; } 00251 00252 virtual inline __time StatSyncDelay() { return this->statSyncDelayCount?(this->statSyncDelaySum / this->statSyncDelayCount):-1; } 00253 00254 virtual void Finalize(); 00255 00256 private: 00257 void RecvStream(CAddress dst, CPacketStream* packet); 00258 void RecvMessage(CAddress src, CStreamMessage* message); 00259 00260 void RecvFrame(CAddress src, CStreamFrame frame); 00261 00262 void ProcessFrameFirst(CStreamFrame frame); 00263 void ProcessFrameBuffering(CStreamFrame frame); 00264 void ProcessFramePlay(CStreamFrame frame); 00265 void ProcessFrameWait(CStreamFrame frame); 00266 void ProcessFrameReset(CStreamFrame frame); 00267 00268 void ProcessFrameLayerBuffering(CStreamFrame frame, __uint32 layer); 00269 void ProcessFrameLayerReady(CStreamFrame frame, __uint32 layer); 00270 00271 void RecvMessageJoin(CAddress src, CStreamMessagePushSelectJoin* message); 00272 void RecvMessageLeave(CAddress src, CStreamMessagePushSelectLeave* message); 00273 void RecvMessageClose(CAddress src, CStreamMessagePushSelectClose* message); 00274 void RecvMessageBootResponse(CAddress src, CStreamMessageBootPushSelectResponse* message); 00275 00276 void StreamBootstrap(); 00277 void StreamJoin(); 00278 void StreamJoin(__uint32 layer); 00279 void StreamLeave(); 00280 void StreamLeave(__uint32 layer); 00281 void StreamRegister(__uint32 layer); 00282 void StreamDeregister(__uint32 layer); 00283 void StreamClose(); 00284 00285 void SendStream(CStreamFrame frame, __uint32 layer); 00286 00287 void RejectJoin(CAddress src, CStreamMessagePushSelectJoin* message); 00288 00289 void TimerPlay(CTimerInfo* info); 00290 void TimerBoot(CTimerInfo* info); 00291 void TimerRegister(CTimerInfo* info); 00292 void TimerBuffer(CTimerInfo* info); 00293 };
Last updated: February 8, 2011