ESSynchronizer Class Reference

Adaptor class Synchronizer handles stream synchronization can be used for VES and AES <short description="">. More...

#include <ESSynchronizer.hpp>

Inheritance diagram for ESSynchronizer:

Adaptor List of all members.

Public Member Functions

 ESSynchronizer (ESInfo *esi, GlobalTimer *globalTimer)
list< Frame * > adapt (Frame *frm)
 Blocks the calling data channel until the presentation time stamp (CTS) of the given frame matches the play-out media time returned by the associated GlobalTimer.
Adaptorclone ()
 Create a shallow copy of the Adaptor.
void initialize ()
 Initialize internal data structures.
list< Frame * > close ()
 Close and destroy an Adaptor.
void setPaused (bool pause)
 Blocks/deblocks the data channel this ESSynchronizer adaptor belongs to.
void setESInfo (ESInfo *esi)
 Sets a reference to an ESInfo object.
ESInfogetESInfo ()
GlobalTimergetGlobalTimer () const
 Return associated GlobalTimer.
bool setOutputRateFactor (double factor)
 Set output rate factor w.r.t.
double getOutputRateFactor () const
 Returns output rate factor.
bool adjust (double sec)
 Adjust the associated global timer to the given media time point.
virtual u32 getTranscodingCosts () const
 returns adaptation costs (CPU only)

Protected Attributes

ESInfoes
timeval tv
long frmCount
double outputRate
 The output rate factor.

Detailed Description

Adaptor class Synchronizer handles stream synchronization can be used for VES and AES <short description="">.

Author:
Michael Kropfberger and Peter Schojer
Version:
Id
ESSynchronizer.hpp,v 1.15 2006/05/12 11:32:49 mkropfbe Exp

Definition at line 88 of file ESSynchronizer.hpp.


Member Function Documentation

list< Frame * > ESSynchronizer::adapt Frame frm  )  [virtual]
 

Blocks the calling data channel until the presentation time stamp (CTS) of the given frame matches the play-out media time returned by the associated GlobalTimer.

If the frame lags behind the play-out time by more than ESSYNC_GRACE_MSECS milliseconds, the frame will be dropped. If the frame hurries ahead the play-out time by more than ESSYNC_DISCONT_MSECS milliseconds, a media stream discontinuity will be assumed and the GlobalTimer will be adjusted to the frame's CTS.

Reimplemented from Adaptor.

Definition at line 103 of file ESSynchronizer.cpp.

References GlobalTimer::adjust(), VCondition::condWait(), GlobalTimer::getActualSec(), Frame::getAU(), ESInfo::getMediaTimeScale(), Frame::getMediaTimeScale(), VMutex::getMutexObject(), Frame::getType(), VMutex::lock(), Frame::markForDelete(), outputRate, VMutex::release(), and Frame::setMediaTimeScale().

00103 { 00104 bool forwardFrame = false; 00105 list < Frame * >tmp; 00106 int act_wait; 00107 double t, tframe; 00108 00109 /* block until not paused */ 00110 cond_pause_mutex.lock(); 00111 while (paused) { 00112 dprintf_full("ESSynchronizer::adapt() PAUSED @ %4.2f sec, frame %i\n", 00113 globalTimer->getActualSec(), frm->getAU()->cts); 00114 cond_pause.condWait(cond_pause_mutex.getMutexObject()); 00115 } 00116 cond_pause_mutex.release(); 00117 00118 tmp.push_front(frm); 00119 00120 //TURN OFF SYNC IF BENCHMARKING NETWORK! 00121 #ifdef NETBENCH 00122 #define FORCE_DISPLAY 00123 #endif 00124 00125 #ifdef FORCE_DISPLAY 00126 forwardFrame = true; 00127 #endif 00128 00129 Frame::FrameType myType = frm->getType(); 00130 00131 00132 #ifndef LOCALBENCH 00133 if ((myType == Frame::I_VOP) || (myType == Frame::P_VOP) || (myType == Frame::HEADER_VOP)) 00134 forwardFrame = true; 00135 #endif 00136 00137 if(myType == Frame::NN_VOP || myType == Frame::MP3_AUDIO) 00138 forwardFrame = true; 00139 00140 00141 if (frmCount == 0) //always show first frame! 00142 forwardFrame = true; 00143 00144 frmCount++; 00145 00146 // a bypassing YUV_VOP or RGB_VOP is fully subjected to dropping, if time is out! 00147 00148 if(frm->getMediaTimeScale() == 0) 00149 frm->setMediaTimeScale(es->getMediaTimeScale()); 00150 00151 assert(frm->getMediaTimeScale() != 0); 00152 t = (double) frm->getMediaTimeScale(); 00153 if (outputRate != 1.0) 00154 t *= outputRate; 00155 tframe = (double)frm->getAU()->cts / t; // play-out time in seconds 00156 act_wait = (int) ((tframe - globalTimer->getActualSec()) * 1000.0 ); 00157 00158 //dprintf_full("ESSynchronizer::adapt() frame type=%d forwarding=%d cts=%d timescale(t)=%f tframe=%f\n", 00159 // myType, forwardFrame, frm->getAU()->cts, t, tframe); 00160 00161 /* Detect discontinuity in stream and re-synchronize GlobalTimer. 00162 * Re-synchronization is done only if the current frame is *ahead* 00163 * of play-out time to avoid competing with 00164 * SDLaudioIO:sdl_audio_callback(). 00165 */ 00166 if (act_wait > ESSYNC_DISCONT_MSECS) { 00167 dprintf_small("ESSynchronizer::adapt() detected stream discontinuity (%d > %d, " 00168 "re-synchronizing globalTimer to %4.2f sec\n", act_wait, ESSYNC_DISCONT_MSECS, tframe); 00169 globalTimer->adjust(tframe); 00170 act_wait = 0; 00171 } 00172 00173 //dprintf_full("ESSynchronizer::adapt @ %4.2f sec, outputRate %5.3f, frameCTS %i (size %i) -> act_wait: %i\n", 00174 // globalTimer->getActualSec(), outputRate, frm->getAU()->cts, frm->getAU()->size,act_wait); 00175 00176 if (act_wait > (-1) * ESSYNC_GRACE_MSECS) { 00177 forwardFrame = true; 00178 } 00179 00180 if (forwardFrame) { 00181 if(act_wait >= 10 /*&& frm->getType() != Frame::MP3_AUDIO*/) 00182 msleep(act_wait); 00183 } else { //not forward frame 00184 dprintf_err("ESSynchronizer::adapt -> act_wait: %i DROPPING frame (dropCount=%d) ... missed CTS %i!!!\n", 00185 act_wait, ++dropCount, frm->getAU()->cts); 00186 //deletion is done in DataChannel! 00187 frm->markForDelete(); 00188 return tmp; 00189 } 00190 00191 return tmp; 00192 }

bool ESSynchronizer::adjust double  sec  ) 
 

Adjust the associated global timer to the given media time point.

Note that the GlobalTimer::adjust(double) method adjusts to a play-out time point, which is different from the media time point if the output rate factor is not equal to 1.0.

Parameters:
sec media time point in seconds.
Returns:
true on success.
Definition at line 85 of file ESSynchronizer.cpp.

References GlobalTimer::adjust(), and outputRate.

00085 { 00086 if (!globalTimer || sec < 0.0) 00087 return false; 00088 globalTimer->adjust(sec / outputRate); 00089 return true; 00090 }

Adaptor* ESSynchronizer::clone  )  [inline, virtual]
 

Create a shallow copy of the Adaptor.

Creates an Adaptor with the same setup (without copying the current status).

Returns:
An Adaptor object.

Implements Adaptor.

Definition at line 112 of file ESSynchronizer.hpp.

00112 { return new ESSynchronizer(es,globalTimer); };

list< Frame * > ESSynchronizer::close  )  [inline, virtual]
 

Close and destroy an Adaptor.

Releases all internally buffered frame objects, and deallocate all allocated memory. The Adaptor must not be used after calling the close method!!!

Returns:
List of adapted Frame objects.

Reimplemented from Adaptor.

Definition at line 116 of file ESSynchronizer.hpp.

00116 { 00117 list < Frame * >tmp; 00118 return tmp; 00119 };

double ESSynchronizer::getOutputRateFactor  )  const [inline]
 

Returns output rate factor.

See also:
setOutputRateFactor(double)
Definition at line 154 of file ESSynchronizer.hpp.

References outputRate.

00154 { return outputRate; }

void ESSynchronizer::initialize  )  [virtual]
 

Initialize internal data structures.

Implements Adaptor.

Definition at line 70 of file ESSynchronizer.cpp.

00070 { 00071 }

void ESSynchronizer::setESInfo ESInfo esi  )  [inline, virtual]
 

Sets a reference to an ESInfo object.

Adaptors are allowed to change ESInfo objects. If you don't want that, pass an es->clone()

Reimplemented from Adaptor.

Definition at line 137 of file ESSynchronizer.hpp.

00137 {es=esi;};

bool ESSynchronizer::setOutputRateFactor double  factor  ) 
 

Set output rate factor w.r.t.

media frame rate. E.g. setting this value to 0.5 will cause a 30 Hz media stream to be forwarded with 15 Hz.

Parameters:
factor must be positive; 1.0 means media frame rate.
Returns:
true on success.
Definition at line 74 of file ESSynchronizer.cpp.

References GlobalTimer::adjust(), GlobalTimer::getActualSec(), outputRate, and GlobalTimer::setPaused().

00074 { 00075 if (factor <= 0.0 || !globalTimer) 00076 return false; 00077 globalTimer->setPaused(true); 00078 globalTimer->adjust(globalTimer->getActualSec() * outputRate / factor); 00079 outputRate = factor; 00080 globalTimer->setPaused(false); 00081 return true; 00082 }

void ESSynchronizer::setPaused bool  pause  ) 
 

Blocks/deblocks the data channel this ESSynchronizer adaptor belongs to.

The associated GlobalTimer is not paused! As opposed to the corresponding method of GlobalTimer, the pause state of this class is binary, i.e. the calling sequence setPaused(true) - setPaused(true) - setPaused(false) will yield a pause state of false (no reference counting).

Parameters:
pause if true, the data channel will be blocked; if false, it will be deblocked.
See also:
GlobalTimer::setPaused(bool)
Definition at line 93 of file ESSynchronizer.cpp.

References VMutex::lock(), VMutex::release(), and VCondition::signal().

Referenced by SDLaudioIO::open(), DSPaudioIO::open(), and DSPaudioIO::writeFrame().

00093 { 00094 cond_pause_mutex.lock(); 00095 paused = pause; 00096 if (!paused) 00097 cond_pause.signal(); 00098 cond_pause_mutex.release(); 00099 }


Member Data Documentation

double ESSynchronizer::outputRate [protected]
 

The output rate factor.

1.0 means media frame rate. Definition at line 187 of file ESSynchronizer.hpp.

Referenced by adapt(), adjust(), getOutputRateFactor(), and setOutputRateFactor().


The documentation for this class was generated from the following files: