Alex Bikfalvi
SimStream Documentation
StreamClientPush.h
00001 #pragma once 00002 00003 #include "StreamClient.h" 00004 #include "StreamBuffer.h" 00005 #include "StreamEncoderFrame.h" 00006 #include "StreamDecoderFrame.h" 00007 #include "InfoPush.h" 00008 #include "Link.h" 00009 #include "Timer.h" 00010 00011 #include "StreamMessagePushJoin.h" 00012 #include "StreamMessagePushLeave.h" 00013 #include "StreamMessagePushClose.h" 00014 #include "StreamMessageBootPushRequest.h" 00015 #include "StreamMessageBootPushResponse.h" 00016 #include "StreamMessageBootPushRegister.h" 00017 #include "StreamMessageBootPushDeregister.h" 00018 00019 class CStreamClientPush : public CStreamClient 00020 { 00021 private: 00022 enum EClientState 00023 { 00024 STOPPED = 0, 00025 MCAST_STREAM_FIRST = 10, 00026 MCAST_STREAM_BUFFERING = 11, 00027 MCAST_STREAM_PLAY = 12, 00028 MCAST_STREAM_WAIT = 13, 00029 UCAST_BOOTSTRAP_REQUEST = 20, 00030 UCAST_BOOTSTRAP_RESPONSE = 21, 00031 UCAST_JOIN_REQUEST = 22, 00032 UCAST_STREAM_FIRST = 23, 00033 UCAST_STREAM_BUFFERING = 24, 00034 UCAST_STREAM_PLAY = 25, 00035 UCAST_STREAM_WAIT = 26, 00036 UCAST_STREAM_RESET = 27 00037 }; 00038 00039 enum ERegistrationState 00040 { 00041 NOT_REGISTERED = 0, 00042 REGISTERED = 1 00043 }; 00044 00045 // State 00046 EClientState stateClient; 00047 ERegistrationState stateRegistration; 00048 00049 // Simulator 00050 CInfoPush* info; 00051 CAddress address; 00052 00053 // Channel 00054 CChannel* channel; 00055 00056 // Buffer 00057 CStreamBuffer* buffer; 00058 00059 // Session 00060 void (CStreamClientPush::*processFrame)(CStreamFrame frame); 00061 __time sessionTimeLastStart; 00062 __time sessionTimeLastStop; 00063 __uint32 sessionFrameLastStart; 00064 __uint32 sessionFrameLastStop; 00065 00066 // Unicast session 00067 __bitrate bw; // Uplink bandwidth 00068 __bitrate bwUsed; // Used uplink bandwidth 00069 00070 set<CAddress> neighbors; // Client neighbor list 00071 set<CAddress> receivers; // Client receiver list 00072 CAddress sender; // Client sender 00073 00074 // Multicast session 00075 __uint32 entry; // Multicast interface (0 - as host have only one interface) 00076 00077 // Timer 00078 CTimer<CStreamClientPush>* timerPlayMcast; // Playback timer (multicast channels) 00079 CTimer<CStreamClientPush>* timerPlayUcast; // Playback timer (unicast channels) 00080 CTimer<CStreamClientPush>* timerBoot; // Bootstrap timer 00081 CTimer<CStreamClientPush>* timerRegister; // Registrap timer 00082 CTimer<CStreamClientPush>* timerBuffer; // Buffering timer 00083 00084 __uint32 timerBufferChannel; 00085 00086 // Delegates - receive 00087 Delegate2<CStreamClientPush, void, CAddress, CStreamFrame>* 00088 delegateRecvFrameMcast; 00089 Delegate2<CStreamClientPush, void, CAddress, CStreamFrame>* 00090 delegateRecvFrameUcast; 00091 00092 IDelegate2<void, CAddress, CPacketStream*>* 00093 delegateSendStream; 00094 IDelegate2<void, CAddress, CStreamMessage*>* 00095 delegateSendMessage; 00096 00097 IDelegate2<void, CAddress, __uint32>* 00098 delegateIgmpJoin; 00099 IDelegate1<void, CAddress>* delegateIgmpLeave; 00100 00101 00102 IDelegate0<CLink*>* delegateLink; 00103 00104 00105 // Encoder 00106 CStreamEncoderFrame* encoder; 00107 00108 // Decoders 00109 CStreamDecoder* decoder; 00110 CStreamDecoderFrame* decoderMcast; 00111 CStreamDecoderFrame* decoderUcast; 00112 00113 // Statistics 00114 __uint32 statRecvFrames; 00115 __uint32 statDiscardedFrames; 00116 __uint32 statPlayFrames; 00117 __uint32 statSuccessFrames[3]; 00118 __uint32 statFailFrames[3]; 00119 00120 __uint32 statPlayFirstFrame; 00121 __uint32 statPlayLastFrame; 00122 00123 __time statTimeClientStart; 00124 __time statTimeRecvStart; 00125 __time statTimePlayStart; 00126 __time statTimeFinish; 00127 __time statTimeWait; 00128 00129 __time statSyncDelaySum; 00130 __uint32 statSyncDelayCount; 00131 00132 public: 00133 CStreamClientPush( 00134 CSimHandler* sim, 00135 CInfoPush* info, 00136 CAddress address, 00137 IDelegate2<void, CAddress, CPacketStream*>* delegateSendStream, 00138 IDelegate2<void, CAddress, CStreamMessage*>* delegateSendMessage, 00139 IDelegate2<void, CAddress, __uint32>* delegateIgmpJoin, 00140 IDelegate1<void, CAddress>* delegateIgmpLeave, 00141 IDelegate0<CLink*>* delegateLink, 00142 __uint32 entry, 00143 __bitrate bw 00144 ); 00145 virtual ~CStreamClientPush(); 00146 00147 virtual void Start(CChannel* channel); 00148 virtual void Stop(); 00149 00150 virtual void Recv(CAddress srcAddress, CAddress dstAddress, __uint16 srcPort, __uint16 dstPort, CPacket* packet); 00151 00152 virtual inline __uint32 StatRecvFrames() { return this->statRecvFrames; } 00153 virtual inline __uint32 StatDiscardedFrames() { return this->statDiscardedFrames; } 00154 virtual inline __uint32 StatPlayFrames() { return this->statPlayFrames; } 00155 virtual inline __uint32* StatSuccessFrames() { return this->statSuccessFrames; } 00156 virtual inline __uint32* StatFailFrames() { return this->statFailFrames; } 00157 00158 virtual inline __time StatTimeClientStart() { return this->statTimeClientStart; } 00159 virtual inline __time StatTimeRecvStart() { return this->statTimeRecvStart; } 00160 virtual inline __time StatTimePlayStart() { return this->statTimePlayStart; } 00161 virtual inline __time StatTimeFinish() { return this->statTimeFinish; } 00162 virtual inline __time StatTimeWait() { return this->statTimeWait; } 00163 00164 virtual inline __uint32 StatPlayFirstFrame() { return this->statPlayFirstFrame; } 00165 virtual inline __uint32 StatPlayLastFrame() { return this->statPlayLastFrame; } 00166 00167 virtual inline __time StatSyncDelay() { return this->statSyncDelayCount?(this->statSyncDelaySum / this->statSyncDelayCount):-1; } 00168 00169 virtual void Finalize(); 00170 00171 private: 00172 void StartMcast(); 00173 void StartUcast(); 00174 00175 void StopMcast(); 00176 void StopUcast(); 00177 00178 void RecvStream(CAddress dst, CPacketStream* packet); 00179 void RecvMessage(CAddress src, CStreamMessage* message); 00180 00181 void RecvFrameMcast(CAddress src, CStreamFrame frame); 00182 00183 void ProcessFrameMcastFirst(CStreamFrame frame); 00184 void ProcessFrameMcastBuffering(CStreamFrame frame); 00185 void ProcessFrameMcastPlay(CStreamFrame frame); 00186 void ProcessFrameMcastWait(CStreamFrame frame); 00187 00188 void RecvFrameUcast(CAddress src, CStreamFrame frame); 00189 00190 void ProcessFrameUcastFirst(CStreamFrame frame); 00191 void ProcessFrameUcastBuffering(CStreamFrame frame); 00192 void ProcessFrameUcastPlay(CStreamFrame frame); 00193 void ProcessFrameUcastWait(CStreamFrame frame); 00194 void ProcessFrameUcastReset(CStreamFrame frame); 00195 00196 void RecvMessageJoin(CAddress src, CStreamMessagePushJoin* message); 00197 void RecvMessageLeave(CAddress src, CStreamMessagePushLeave* message); 00198 void RecvMessageClose(CAddress src, CStreamMessagePushClose* message); 00199 void RecvMessageBootResponse(CAddress src, CStreamMessageBootPushResponse* message); 00200 00201 void StreamBootstrap(); 00202 void StreamJoin(); 00203 void StreamLeave(); 00204 void StreamRegister(); 00205 void StreamDeregister(); 00206 void StreamClose(); 00207 00208 void SendStream(CStreamFrame frame); 00209 00210 void RejectJoin(CAddress src, CStreamMessagePushJoin* message); 00211 00212 void TimerPlayMcast(CTimerInfo* info); 00213 void TimerPlayUcast(CTimerInfo* info); 00214 void TimerBoot(CTimerInfo* info); 00215 void TimerRegister(CTimerInfo* info); 00216 void TimerBuffer(CTimerInfo* info); 00217 };
Last updated: February 8, 2011