GlobalTimer Class Reference

This adaptor class provides a means for synchronizing DataChannels (media streams) by providing methods for obtaining the elapsed time since the start of streaming (not including PAUSED states) and for blocking DataChannels when set to the PREFETCHING or PAUSED state. Adaptor for synchronizing several DataChannels with PREFETCHING or PAUSED states. More...

#include <GlobalTimer.hpp>

Inheritance diagram for GlobalTimer:

Adaptor List of all members.

Public Member Functions

list< Frame * > adapt (Frame *frm)
 Accepts as input a frame, and checks if it can adapt the frame, If the frame is modified, a new Frame object is created and inserted into the return list.
Adaptorclone ()
 Create a shallow copy of the Adaptor.
void reset ()
void initialize ()
 Initialize internal data structures.
list< Frame * > close ()
 Close and destroy an Adaptor.
double getActualSec ()
 Return the time elapsed since the start of streaming, excluding any time periods when the GlobalTimer was was blocked.
void adjustToTS (int ts, int mediaTimeScale)
void adjust (double sec)
 Adjust timer to play-out time point.
void setPaused (bool pause)
bool isPaused () const
void setPrefetching (bool pause)
bool isPrefetching ()
void dropFramesUntil (u32 cts)
 Drop all frames with a CTS less than the given one.
void setESInfo (ESInfo *esi)
 dummy implementations since a GlobalTimer is used by many ESs
ESInfogetESInfo ()
u32 getTranscodingCosts () const
 returns adaptation costs (CPU only)

Detailed Description

This adaptor class provides a means for synchronizing DataChannels (media streams) by providing methods for obtaining the elapsed time since the start of streaming (not including PAUSED states) and for blocking DataChannels when set to the PREFETCHING or PAUSED state. Adaptor for synchronizing several DataChannels with PREFETCHING or PAUSED states.

All DataChannels representing synchronized media streams (usually 1 video and 1 audio stream) need to include the same GlobalTimer instance as a SharedAdaptor. Note that a GlobalTimer needs to be coupled with an ESSynchronizer to achieve display rate control for video streams.

See also:
SharedAdaptor

ESSynchronizer

Author:
Michael Kropfberger, Peter Schojer, Mario Taschwer
Version:
Id
GlobalTimer.hpp,v 1.13 2006/01/20 15:37:17 mkropfbe Exp

Definition at line 83 of file GlobalTimer.hpp.


Member Function Documentation

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

Accepts as input a frame, and checks if it can adapt the frame, If the frame is modified, a new Frame object is created and inserted into the return list.

This new frame is returned only, if the size of the payload is larger than zero. If the frame was not modified, it is also inserted into the list. For more complex adaptors, it will happen, that the adaptor caches up one complete GOP and returns the full GOP in network order. A caching adaptor has to create deep-copies for each frames. Never directly modify the payload of the input frm, always create copies!!!

Parameters:
frm object to adapt. An Adaptor is never allowed to free the input frame. This has to be done in the caller.
Returns:
List of adapted Frame objects

Reimplemented from Adaptor.

Definition at line 173 of file GlobalTimer.cpp.

References VCondition::condWait(), Frame::getAU(), VMutex::getMutexObject(), ReferenceCounter::getUsage(), VMutex::lock(), and VMutex::release().

00173 { 00174 list < Frame * >tmp; 00175 assert(frm); 00176 if (dropUntil && frm->getAU()->cts < dropUntil) { 00177 dprintf_full("GlobalTimer::adapt() dropUntil = %u, DROPPING frame CTS %u\n", 00178 dropUntil, frm->getAU()->cts); 00179 return tmp; 00180 } 00181 cond_block_mutex.lock(); 00182 while (!COND_NOT_BLOCKED) { 00183 dprintf_full("GlobalTimer(%p)::adapt blocking on CTS %u (Pausers %d, Prefetchers %d)\n", 00184 this, ( (frm&&frm->getAU()) ? frm->getAU()->cts : (unsigned)-1 ), 00185 pauseRefCnt.getUsage(), prefetchRefCnt.getUsage()); 00186 cond_block.condWait(cond_block_mutex.getMutexObject()); 00187 } 00188 00189 if(frm) { 00190 tmp.push_front(frm); 00191 00192 time_mutex.lock(); 00193 gettimeofday(&tv,NULL); 00194 if(wasBlocked) { //adjust base time 00195 wasBlocked = false; 00196 double pause_dtime = now_dtime; //store old dtime 00197 now_dtime = tv.tv_sec + tv.tv_usec/1000000.0; 00198 start_dtime += (now_dtime - pause_dtime); 00199 actualSec = now_dtime - start_dtime; 00200 } 00201 00202 now_dtime = tv.tv_sec + tv.tv_usec/1000000.0; 00203 if (firstFrame) { 00204 firstFrame = false; 00205 start_dtime = now_dtime; 00206 } 00207 actualSec = now_dtime - start_dtime; 00208 dprintf_full("GlobalTimer::adapt forwarding frame CTS %u at time %2.3f\n", 00209 ( (frm&&frm->getAU()) ? frm->getAU()->cts : (unsigned)-1 ), 00210 actualSec); 00211 time_mutex.release(); 00212 } 00213 cond_block_mutex.release(); 00214 return tmp; 00215 }

void GlobalTimer::adjust double  sec  ) 
 

Adjust timer to play-out time point.

Parameters:
sec play-out time point in seconds.
Definition at line 163 of file GlobalTimer.cpp.

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

Referenced by ESSynchronizer::adapt(), ESSynchronizer::adjust(), and ESSynchronizer::setOutputRateFactor().

00163 { 00164 time_mutex.lock(); 00165 gettimeofday(&tv, NULL); 00166 now_dtime = tv.tv_sec + tv.tv_usec/1000000.0; 00167 start_dtime = now_dtime - sec; 00168 time_mutex.release(); 00169 }

Adaptor* GlobalTimer::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 95 of file GlobalTimer.hpp.

00095 { return new GlobalTimer(); };

list< Frame * > GlobalTimer::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 101 of file GlobalTimer.hpp.

00101 { 00102 list < Frame * >tmp; 00103 return tmp; 00104 };

void GlobalTimer::dropFramesUntil u32  cts  ) 
 

Drop all frames with a CTS less than the given one.

Frames are dropped even if the GlobalTimer is PAUSED or PREFETCHING. This allows media streams to be sychronized to a given time stamp, e.g. after a PAUSE/PLAY in a network player application.

Note that you need to insert a decoder before the GlobalTimer into the adaptor chain if you want to use this method.Definition at line 141 of file GlobalTimer.cpp.

00141 { 00142 dprintf_full("GlobalTimer::dropFramesUntil(cts = %u)\n", cts); 00143 dropUntil = cts; 00144 }

double GlobalTimer::getActualSec  ) 
 

Return the time elapsed since the start of streaming, excluding any time periods when the GlobalTimer was was blocked.

Definition at line 127 of file GlobalTimer.cpp.

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

Referenced by ESSynchronizer::adapt(), and ESSynchronizer::setOutputRateFactor().

00127 { 00128 if (start_dtime == 0.0) 00129 return 0.0; 00130 if (!isPaused()) { 00131 time_mutex.lock(); 00132 gettimeofday(&tv,NULL); 00133 now_dtime = tv.tv_sec + tv.tv_usec/1000000.0; 00134 actualSec = now_dtime - start_dtime; 00135 time_mutex.release(); 00136 } 00137 return actualSec; 00138 }

void GlobalTimer::initialize  )  [virtual]
 

Initialize internal data structures.

Implements Adaptor.

Definition at line 90 of file GlobalTimer.cpp.

00090 { 00091 reset(); 00092 }


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