Alex Bikfalvi
SimStream Documentation
StreamServerPushMcast.cpp
00001 #include "Headers.h" 00002 #include "StreamServerPushMcast.h" 00003 00004 CStreamServerPushMcast::CStreamServerPushMcast( 00005 CSimHandler* sim, 00006 CStreamSource* source, 00007 IDelegate2<void, CAddress, CPacketStream*>* delegateSendStream, 00008 IDelegate2<void, CAddress, __uint32>* delegateIgmpJoin, 00009 IDelegate1<void, CAddress>* delegateIgmpLeave, 00010 __uint32 entry 00011 ) : CStreamServer(sim) 00012 { 00013 // Set source 00014 this->source = source; 00015 00016 // Set lower layer delegates 00017 this->delegateSendStream = delegateSendStream; 00018 this->delegateIgmpJoin = delegateIgmpJoin; 00019 this->delegateIgmpLeave = delegateIgmpLeave; 00020 00021 // Create the server timer and hook it to the timer method 00022 this->timer = new CTimer<CStreamServerPushMcast>( 00023 sim, 00024 this, 00025 &CStreamServerPushMcast::Timer); 00026 00027 // Set the schedule rate (the channel fps) 00028 this->scheduleRate = this->source->Channel()->Fps(); 00029 00030 // Set the interface 00031 this->entry = entry; 00032 00033 // Coders 00034 this->encoder = new CStreamEncoderFrame( 00035 this->delegateSendStream 00036 ); 00037 } 00038 00039 CStreamServerPushMcast::~CStreamServerPushMcast() 00040 { 00041 // Timer 00042 delete this->timer; 00043 00044 // Coders 00045 delete this->encoder; 00046 } 00047 00048 void CStreamServerPushMcast::Start() 00049 { 00050 // Check the server timer is stopped 00051 assert(!this->timer->IsSet()); 00052 00053 // Join the multicast group for this channel 00054 (*this->delegateIgmpJoin)(this->source->Channel()->Address(), this->entry); 00055 00056 // Synchronize with the stream source 00057 this->source->Synchronize(this->sim->Time(), this->scheduleTime, this->scheduleFrame); 00058 00059 // Set the delta frame to zero 00060 this->deltaFrame = 0; 00061 00062 // If the schedule time is the current time, call the timer function 00063 if(this->scheduleTime == this->sim->Time()) 00064 this->Timer(NULL); 00065 else // Else, set the timer at the scheduled time 00066 this->timer->SetAt(this->scheduleTime); 00067 } 00068 00069 void CStreamServerPushMcast::Stop() 00070 { 00071 // If the timer is set, cancel 00072 if(this->timer->IsSet()) this->timer->Cancel(); 00073 00074 // Leave the multicast group for this channel 00075 (*this->delegateIgmpLeave)(this->source->Channel()->Address()); 00076 } 00077 00078 void CStreamServerPushMcast::Timer(CTimerInfo* info) 00079 { 00080 // Process server timer 00081 00082 // Fetch the frame from the source and send it to the encoder (the destination is the channel multicast address) 00083 this->encoder->Encode(this->source->Channel()->Address(), this->source->Fetch(this->scheduleFrame + this->deltaFrame)); 00084 00085 // Increment the delta frame 00086 this->deltaFrame++; 00087 00088 // Set a new timer 00089 this->timer->SetAt(this->scheduleTime + ((__time)this->deltaFrame)/this->scheduleRate); 00090 } 00091 00092 void CStreamServerPushMcast::Finalize() 00093 { 00094 // Call base class finalizer 00095 CStreamServer::Finalize(); 00096 }
Last updated: February 8, 2011