Alex Bikfalvi
SimStream Documentation
StreamClientPull.h
00001 #pragma once 00002 00003 #include "StreamClient.h" 00004 #include "StreamBuffer.h" 00005 #include "StreamBufferSegment.h" 00006 #include "StreamDecoderFrame.h" 00007 #include "InfoPull.h" 00008 #include "Link.h" 00009 #include "Timer.h" 00010 #include "ConnectionLayer.h" 00011 #include "ConnectionTag.h" 00012 00013 #include "StreamPullSender.h" 00014 #include "StreamPullReceiver.h" 00015 00016 #include "StreamMessagePullBitmapRequest.h" 00017 #include "StreamMessagePullBitmapResponse.h" 00018 #include "StreamMessagePullSegmentRequest.h" 00019 #include "StreamMessagePullSegmentResponse.h" 00020 00021 #include "StreamMessageBootPullRequest.h" 00022 #include "StreamMessageBootPullResponse.h" 00023 #include "StreamMessageBootPullRegister.h" 00024 #include "StreamMessageBootPullDeregister.h" 00025 00026 class CStreamClientPull : public CStreamClient 00027 { 00028 private: 00029 typedef set<CAddress> TNeighborList; 00030 typedef map<CAddress, CStreamPullSender*> TRequestList; 00031 00032 enum EClientState 00033 { 00034 STOPPED = 0, 00035 MCAST_STREAM_FIRST = 10, 00036 MCAST_STREAM_BUFFERING = 11, 00037 MCAST_STREAM_PLAY = 12, 00038 MCAST_STREAM_WAIT = 13, 00039 UCAST_STREAM_FIRST = 20, 00040 UCAST_STREAM_BUFFERING = 21, 00041 UCAST_STREAM_PLAY = 22 00042 }; 00043 00044 enum EScheduleState 00045 { 00046 SCHEDULE_IDLE = 0, 00047 SCHEDULE_BOOTSTRAP_REQUEST = 1, 00048 SCHEDULE_BOOTSTRAP_RESPONSE = 2, 00049 SCHEDULE_CONNECT_REQUEST = 3, 00050 SCHEDULE_CONNECT_RESPONSE = 4, 00051 SCHEDULE_BITMAP_REQUEST = 5, 00052 SCHEDULE_BITMAP_RESPONSE = 6, 00053 SCHEDULE_POST_BITMAP_RESPONSE = 7, 00054 SCHEDULE_SEGMENT_REQUEST = 8, 00055 SCHEDULE_SEGMENT_RESPONSE = 9, 00056 SCHEDULE_POST_SEGMENT_RESPONSE = 10 00057 }; 00058 00059 enum ERegistrationState 00060 { 00061 NOT_REGISTERED = 0, 00062 REGISTERED = 1 00063 }; 00064 00065 // State 00066 EClientState stateClient; 00067 ERegistrationState stateRegistration; 00068 EScheduleState stateSchedule; 00069 00070 // Simulator 00071 CInfoPull* info; 00072 CAddress address; 00073 00074 // Channel 00075 CChannel* channel; 00076 00077 // Buffer 00078 CStreamBuffer* bufferMcast; 00079 CStreamBufferSegment* bufferUcast; 00080 00081 // Session 00082 void (CStreamClientPull::*processFrame)(CStreamFrame frame); 00083 __time sessionTimeLastStart; 00084 __time sessionTimeLastStop; 00085 __uint32 sessionFrameLastStart; 00086 __uint32 sessionFrameLastStop; 00087 00088 // Multicast session 00089 __uint32 entry; // Multicast interface (0 - as hosts have only one interface) 00090 00091 // Unicast session 00092 CConnectionLayer* connectionLayer; 00093 00094 TNeighborList neighbors; 00095 TRequestList requestBitmaps; 00096 TRequestList requestSegments; 00097 00098 CStreamPullSender::TSenderList sendersConnecting; 00099 CStreamPullSender::TSenderList senders; 00100 CStreamPullReceiver::TReceiverList receivers; 00101 00102 __uint32 scheduleSegment; 00103 __uint8 scheduleNumCopiesLo[64]; 00104 __uint8 scheduleNumCopiesHi[64]; 00105 bool scheduleBitmapLo[PULL_MAX_SENDERS][64]; 00106 bool scheduleBitmapHi[PULL_MAX_SENDERS][64]; 00107 CStreamPullSender* scheduleSenderLo[PULL_MAX_SENDERS][64]; 00108 CStreamPullSender* scheduleSenderHi[PULL_MAX_SENDERS][64]; 00109 __uint8 scheduleSenderIndexLo[PULL_MAX_SENDERS][64]; 00110 __uint8 scheduleSenderIndexHi[PULL_MAX_SENDERS][64]; 00111 __time scheduleDeadlineLo[PULL_MAX_SENDERS][64]; 00112 __time scheduleDeadlineHi[PULL_MAX_SENDERS][64]; 00113 __bitrate scheduleBw[PULL_MAX_SENDERS]; 00114 00115 CStreamPullSender* scheduleSenders[64]; 00116 __time scheduleDeadlineDelta; 00117 00118 00119 // Timer 00120 CTimer<CStreamClientPull>* timerPlayMcast; // Playback timer (multicast channels) 00121 CTimer<CStreamClientPull>* timerPlayUcast; // Playback timer (unicast channels) 00122 CTimer<CStreamClientPull>* timerRegister; // Registrap timer 00123 CTimer<CStreamClientPull>* timerSchedule; // Schedule timer 00124 00125 // Delegates - receive 00126 Delegate2<CStreamClientPull, void, CAddress, CStreamFrame>* 00127 delegateRecvFrameMcast; 00128 00129 Delegate2<CStreamClientPull, void, CConnectionReceiver*, CPacket*>* 00130 delegateConnectionRecv; 00131 Delegate2<CStreamClientPull, bool, CAddress, CPacket*>* 00132 delegateConnectionAccept; 00133 Delegate1<CStreamClientPull, void, CConnectionSender*>* 00134 delegateConnectionAccepted; 00135 00136 Delegate2<CStreamClientPull, void, CConnection*, CConnection::EOpenResult>* 00137 delegateConnectionReceiverOpen; 00138 Delegate2<CStreamClientPull, void, CConnection*, CConnection::ECloseResult>* 00139 delegateConnectionReceiverClose; 00140 00141 Delegate2<CStreamClientPull, void, CConnection*, CConnection::EOpenResult>* 00142 delegateConnectionSenderOpen; 00143 Delegate2<CStreamClientPull, void, CConnection*, CConnection::ECloseResult>* 00144 delegateConnectionSenderClose; 00145 00146 IDelegate2<void, CAddress, __uint32>* 00147 delegateIgmpJoin; 00148 IDelegate1<void, CAddress>* delegateIgmpLeave; 00149 IDelegate5<void, __uint16, __uint16, CAddress, __byte, CPacket*>* 00150 delegateSend; 00151 IDelegate0<CLink*>* delegateLink; 00152 00153 // Decoder 00154 CStreamDecoderFrame* decoderMcast; 00155 00156 // Statistics 00157 __uint32 statRecvFrames; 00158 __uint32 statDiscardedFrames; 00159 __uint32 statPlayFrames; 00160 __uint32 statSuccessFrames[3]; 00161 __uint32 statFailFrames[3]; 00162 00163 __uint32 statPlayFirstFrame; 00164 __uint32 statPlayLastFrame; 00165 00166 __time statTimeClientStart; 00167 __time statTimeRecvStart; 00168 __time statTimePlayStart; 00169 __time statTimeFinish; 00170 __time statTimeWait; 00171 00172 __time statSyncDelaySum; 00173 __uint32 statSyncDelayCount; 00174 00175 public: 00176 CStreamClientPull( 00177 CSimHandler* sim, 00178 CInfoPull* info, 00179 CAddress address, 00180 IDelegate5<void, __uint16, __uint16, CAddress, __byte, CPacket*>* delegateSend, 00181 IDelegate2<void, CAddress, __uint32>* delegateIgmpJoin, 00182 IDelegate1<void, CAddress>* delegateIgmpLeave, 00183 IDelegate0<CLink*>* delegateLink, 00184 __uint32 entry 00185 ); 00186 virtual ~CStreamClientPull(); 00187 00188 virtual void Start(CChannel* channel); 00189 virtual void Stop(); 00190 00191 virtual void Recv(CAddress srcAddress, CAddress dstAddress, __uint16 srcPort, __uint16 dstPort, CPacket* packet); 00192 00193 virtual inline __uint32 StatRecvFrames() { return this->statRecvFrames; } 00194 virtual inline __uint32 StatDiscardedFrames() { return this->statDiscardedFrames; } 00195 virtual inline __uint32 StatPlayFrames() { return this->statPlayFrames; } 00196 virtual inline __uint32* StatSuccessFrames() { return this->statSuccessFrames; } 00197 virtual inline __uint32* StatFailFrames() { return this->statFailFrames; } 00198 00199 virtual inline __time StatTimeClientStart() { return this->statTimeClientStart; } 00200 virtual inline __time StatTimeRecvStart() { return this->statTimeRecvStart; } 00201 virtual inline __time StatTimePlayStart() { return this->statTimePlayStart; } 00202 virtual inline __time StatTimeFinish() { return this->statTimeFinish; } 00203 virtual inline __time StatTimeWait() { return this->statTimeWait; } 00204 00205 virtual inline __uint32 StatPlayFirstFrame() { return this->statPlayFirstFrame; } 00206 virtual inline __uint32 StatPlayLastFrame() { return this->statPlayLastFrame; } 00207 00208 virtual inline __time StatSyncDelay() { return this->statSyncDelayCount?(this->statSyncDelaySum / this->statSyncDelayCount):-1; } 00209 00210 virtual void Finalize(); 00211 00212 private: 00213 void StartMcast(); 00214 void StartUcast(); 00215 00216 void StopMcast(); 00217 void StopUcast(); 00218 00219 void RecvFrameMcast(CAddress address, CStreamFrame frame); 00220 00221 void ProcessFrameMcastFirst(CStreamFrame frame); 00222 void ProcessFrameMcastBuffering(CStreamFrame frame); 00223 void ProcessFrameMcastPlay(CStreamFrame frame); 00224 void ProcessFrameMcastWait(CStreamFrame frame); 00225 00226 void ProcessFrameUcastFirst(CStreamFrame frame); 00227 void ProcessFrameUcastBuffering(CStreamFrame frame); 00228 void ProcessFrameUcastPlay(CStreamFrame frame); 00229 00230 void TimerPlayMcast(CTimerInfo* info); 00231 void TimerPlayUcast(CTimerInfo* info); 00232 void TimerRegister(CTimerInfo* info); 00233 void TimerSchedule(CTimerInfo* info); 00234 00235 void ScheduleBootstrapRequest(); 00236 void ScheduleConnectRequest(); 00237 void ScheduleBitmapRequest(); 00238 void SchedulePostBitmapResponse(); 00239 void ScheduleSegmentRequest(); 00240 00241 void RecvStream(CAddress dst, CPacketStream* packet); 00242 void RecvMessage(CAddress src, CStreamMessage* message); 00243 void RecvConnection(CAddress srcAddress, __uint16 srcPort, __uint16 dstPort, CPacketConnection* packet); 00244 00245 void RecvMessageBootResponse(CAddress src, CStreamMessageBootPullResponse* message); 00246 void RecvMessageBitmapRequest(CAddress src, CStreamMessagePullBitmapRequest* message); 00247 void RecvMessageBitmapResponse(CAddress src, CStreamMessagePullBitmapResponse* message); 00248 void RecvMessageSegmentRequest(CAddress src, CStreamMessagePullSegmentRequest* message); 00249 void RecvMessageSegmentResponse(CAddress src, CStreamMessagePullSegmentResponse* message); 00250 00251 void ConnectionRecv(CConnectionReceiver* receiver, CPacket* packet); 00252 bool ConnectionAccept(CAddress src, CPacket* packet); 00253 void ConnectionAccepted(CConnectionSender* sender); 00254 00255 void ConnectionReceiverOpen(CConnection* receiver, CConnection::EOpenResult result); 00256 void ConnectionReceiverClose(CConnection* receiver, CConnection::ECloseResult result); 00257 00258 void ConnectionSenderOpen(CConnection* sender, CConnection::EOpenResult result); 00259 void ConnectionSenderClose(CConnection* sender, CConnection::ECloseResult result); 00260 00261 void SendMessage(CAddress dst, CStreamMessage* message); 00262 00263 void UcastRegister(); 00264 void UcastDeregister(); 00265 };
Last updated: February 8, 2011