IncompleteIO Class Reference

<class description="" goes="" here=""> <short description=""> More...

#include <IncompleteIO.hpp>

Inheritance diagram for IncompleteIO:

IO VThread List of all members.

Public Member Functions

 IncompleteIO (const char *localFile, const char *url, int remotePrt, const char *address, int localPrt, ESInfo *es, PacketizationLayer *packetization, bool writeOnly, GlobalTimer *globalTimer, Statistics *stats)
 creates an RTP object
FramegetFrame ()
 returns a frame if one complete frame is available, otherwise null is returned.
int writeFrame (Frame *frm, ESInfo *out_es=NULL)
 returns the number of packets sent.
bool open ()
 opens the IO connection.
bool close (bool immediate=false)
 closes the IO class.
bool destroy ()
 deletes the data source for this IO class.
State getState () const
State setState (State s)
 returns the newly set state
int getBufferFillLevel () const
 returns a value from 0..100 indicating buffer usage
int flushBuffer (long from_ts=0, long to_ts=-1)
 flushes the buffer from starting TimeStamp to end TS
const char * getURL () const
 returns a pointer to the local file name or an URL
bool setToFrameNumber (u32 frameNumber)
 repositions the IO class to the given frame.
long setToClosestIFrame (u32 frameNumber, bool backwards)
 repositions the IO class to
void setResendFrameHeader (bool set)
 indicates if the next call to getFrame will send the frame header.
void run ()
void setRtxInfo (const rtx_info *rtx)
 sets a shallow copy of
State play (double prefetchTime=0.0)
State pause ()
State mute ()
void setESInfo (ESInfo *es)
const ESInfo *const getESInfo () const

Protected Member Functions

void flushLocalCache ()
FramefindAndUnlinkFrame (u32 cts)
 returns a pointer and removes the frame from the cache
void setFrame (Frame *frm)

Protected Attributes

MPGStreamIOlocalInput
SimpleRtp * remoteInput
u32 vopTimeIncrement
 a backup from the voptimeincrement in the es.
PointerRingBuffer< Frame * > frameCache
int cacheUsage
 cacheUsage: how many frames are currently stored in the cache
u32 lastCTS
ESInfoes

Detailed Description

<class description="" goes="" here=""> <short description="">

Author:
Michael Kropfberger and Peter Schojer
Version:
Id
IncompleteIO.hpp,v 1.12 2006/01/20 15:37:18 mkropfbe Exp

Definition at line 73 of file IncompleteIO.hpp.


Constructor & Destructor Documentation

IncompleteIO::IncompleteIO const char *  localFile,
const char *  url,
int  remotePrt,
const char *  address,
int  localPrt,
ESInfo es,
PacketizationLayer packetization,
bool  writeOnly,
GlobalTimer globalTimer,
Statistics stats
 

creates an RTP object

Parameters:
localFile: the partially cached data for this stream
url: the source/dest for this IO class, deep-copied
remotePrt: the remote port where data is sent to
address: the ip address of the remote host, deep-copied
localPrt: the local port, where we are binding and receiving
es: the ElementaryStream sent, shallow-copied
packetization: specifies the transport mode: can be RFC3016, multiSL or flexmux
writeonly specifies if the RTP connection is for sending (writeonly is set to true), of for reading
tc: the TerminalCapabilities, shallow-copied (eg. RTX on/off)
Definition at line 53 of file IncompleteIO.cpp.

References cacheUsage, and vopTimeIncrement.

00056 :IO(),frameCache(INCOMPLETEIO__MAX_FRAMES) 00057 { 00058 assert(es); 00059 this->es=es; 00060 vopTimeIncrement=es->getVOPTimeIncrement(); 00061 dprintf_full("IncompleteIO::IncompleteIO with es=%p\n",es); 00062 //omitheader??? default is false, should be ok 00063 localInput=new MPGStreamIO(es,localFile,writeOnly); 00064 #ifndef WINCE 00065 remoteInput=new SimpleRtp(url, remotePrt, localPrt, address, es, 00066 packetization, writeOnly, NULL,true,SimpleRtp::NO_DELAY,false,false); 00067 #endif //wince 00068 lastCTS=0; 00069 framesSeen=0; 00070 cacheUsage=0; 00071 };


Member Function Documentation

bool IncompleteIO::close bool  immediate = false  )  [virtual]
 

closes the IO class.

Parameters:
immediate specifies, if (optional) buffered data should be read/sent to the client (==false), or immediately dumped (==true)

Implements IO.

Definition at line 240 of file IncompleteIO.cpp.

References MPGStreamIO::close().

Referenced by getFrame().

00241 { 00242 #ifndef WINCE 00243 bool ret=localInput->close(immediate) && remoteInput->close(immediate); 00244 #else 00245 bool ret = false; 00246 #endif 00247 return ret; 00248 };

bool IncompleteIO::destroy  )  [virtual]
 

deletes the data source for this IO class.

Will only work with local files, remote files can not be deleted and will always return true.

Implements IO.

Definition at line 253 of file IncompleteIO.cpp.

References MPGStreamIO::destroy().

00254 { 00255 return localInput->destroy(); 00256 };

int IncompleteIO::flushBuffer long  from_ts = 0,
long  to_ts = -1
[virtual]
 

flushes the buffer from starting TimeStamp to end TS

Parameters:
from_ts: 0 is beginning, everything else is somewhere in the stream
to_ts: -1 is ending, everything else is somewhere in the stream
Returns:
the number of freed bytes

Reimplemented from IO.

Definition at line 273 of file IncompleteIO.cpp.

References IO::flushBuffer().

00274 { 00275 int b=localInput->flushBuffer(from_ts,to_ts); 00276 #ifndef WINCE 00277 b+=remoteInput->flushBuffer(from_ts,to_ts); 00278 #endif 00279 this->flushLocalCache(); 00280 return b; 00281 };

Frame * IncompleteIO::getFrame  )  [virtual]
 

returns a frame if one complete frame is available, otherwise null is returned.

This function is typically blocking. Don't use a NULL return value to conclude STREAMEOF, always check with getState()!

Implements IO.

Definition at line 101 of file IncompleteIO.cpp.

References cacheUsage, close(), findAndUnlinkFrame(), Frame::getAU(), ESInfo::getDuration(), MPGStreamIO::getFrame(), and vopTimeIncrement.

00102 { 00103 // first check the locally cached frames 00104 // then check MpgStreamIO 00105 // then try Rtp (blocking!) 00106 // then return from local cache 00107 dprintf_full("IncompleteIO::getFrame(): expecting CTS %u\n",(lastCTS==0)?0:lastCTS+vopTimeIncrement); 00108 00109 // get packets from remote to avoid buffer overflow in Rtp 00110 #ifndef WINCE 00111 remoteInput->preBufferPackets(0); 00112 #endif 00113 if(lastCTS>=es->getDuration()) { 00114 dprintf_full("IncompleteIO::getFrame() eos detected\n"); 00115 close(true); 00116 return NULL; 00117 } 00118 00119 Frame* frm=NULL; 00120 // check the cache 00121 if(lastCTS==0) 00122 frm=findAndUnlinkFrame(0); 00123 else 00124 frm=findAndUnlinkFrame(vopTimeIncrement+lastCTS); 00125 00126 if(frm) { 00127 lastCTS=frm->getAU()->cts; 00128 dprintf_full("IncompleteIO::getFrame(): found buffered frame with CTS %u\n",lastCTS); 00129 framesSeen++; 00130 return frm; 00131 } 00132 // it's not in the cache 00133 // so get the next frm from MpgStreamIO 00134 dprintf_full("IncompleteIO::getFrame(): before reading next local frame\n"); 00135 frm=localInput->getFrame(); 00136 dprintf_full("IncompleteIO::getFrame(): after reading local frame\n"); 00137 if(!frm && framesSeen==0) { 00138 // header treatment 00139 frm=localInput->getFrame(); 00140 } 00141 00142 dprintf_full("IncompleteIO::getFrame(): read cached frame %p with CTS %u\n",frm, ( (frm && frm->getAU())?frm->getAU()->cts:0)); 00143 if(frm) { 00144 if(frm->getAU()->cts==(lastCTS+vopTimeIncrement) 00145 || frm->getAU()->cts==0) { 00146 // found 00147 framesSeen++; 00148 if(frm->getAU()->cts!=0) 00149 lastCTS=frm->getAU()->cts; 00150 dprintf_full("IncompleteIO::getFrame(): local frame is returned\n"); 00151 return frm; 00152 } 00153 else if(frm->getAU()->cts>lastCTS) { 00154 // store in cache 00155 setFrame(frm); 00156 dprintf_full("IncompleteIO::getFrame(): local frame is cached\n"); 00157 } 00158 else { 00159 delete frm; // frame is too old 00160 dprintf_full("IncompleteIO::getFrame(): local frame is too old. Deleted!\n"); 00161 frm=NULL; 00162 } 00163 } 00164 // if we have not found a local or cached frame, check network 00165 #ifndef WINCE 00166 frm=remoteInput->getFrame(); 00167 #else 00168 frm = NULL; 00169 #endif 00170 dprintf_full("IncompleteIO::getFrame(): read remote frame %p with CTS %u\n",frm, ( (frm && frm->getAU())?frm->getAU()->cts:0)); 00171 if(frm) { 00172 if(frm->getAU()->cts==(lastCTS+vopTimeIncrement) 00173 || frm->getAU()->cts==0) { 00174 // found 00175 framesSeen++; 00176 if(frm->getAU()->cts!=0) 00177 lastCTS=frm->getAU()->cts; 00178 dprintf_full("IncompleteIO::getFrame(): remote frame is returned\n"); 00179 return frm; 00180 } 00181 else if(frm->getAU()->cts>lastCTS) { 00182 // store in cache 00183 setFrame(frm); 00184 dprintf_full("IncompleteIO::getFrame(): remote frame is cached\n"); 00185 } 00186 else { 00187 delete frm; // frame is too old 00188 dprintf_full("IncompleteIO::getFrame(): remote frame is too old. Deleted!\n"); 00189 } 00190 } 00191 frm=NULL; 00192 // we have to return sth 00193 // so look in the frameCache and return the first 00194 if(cacheUsage>0) { 00195 // search the cache for the next n frames 00196 // vopTimeIncrement+lastCTS was not found, thus check the next first 00197 u32 nextCTS=2*vopTimeIncrement+lastCTS; 00198 for(u32 iCts=nextCTS;iCts<nextCTS+INCOMPLETEIO__MAX_FRAME_LOOK_AHEAD*vopTimeIncrement;iCts+=vopTimeIncrement) { 00199 frm=findAndUnlinkFrame(iCts); 00200 if(frm) { 00201 framesSeen++; 00202 if(frm->getAU()->cts!=0) 00203 lastCTS=frm->getAU()->cts; 00204 dprintf_full("IncompleteIO::getFrame(): gap detected, just returning the first cached frame %p with CTS %u\n",frm,frm->getAU()->cts); 00205 return frm; 00206 }; 00207 } 00208 } 00209 assert(frm==NULL); 00210 //we still have to increase lastCTS, otherwise infinite loop for one and the same CTS 00211 lastCTS+=vopTimeIncrement; 00212 dprintf_full("IncompleteIO::getFrame(): gap detected, returning NULL\n"); 00213 return frm; 00214 };

bool IncompleteIO::open  )  [virtual]
 

opens the IO connection.

State is set to OPENING. Depending on the underlying QIODevice, a network connection or a file connection is established. When the connection is ready for use, State is OPEN

Implements IO.

Definition at line 225 of file IncompleteIO.cpp.

References MPGStreamIO::open().

00226 { 00227 framesSeen=0;lastCTS=0; 00228 #ifndef WINCE 00229 bool ret=localInput->open() && remoteInput->open(); 00230 #else 00231 bool ret = false; 00232 #endif 00233 return ret; 00234 };

void IncompleteIO::setRtxInfo const rtx_info *  rtx  )  [virtual]
 

sets a shallow copy of

Parameters:
rtx at the ESInfo object

Reimplemented from IO.

Definition at line 324 of file IncompleteIO.cpp.

00325 { 00326 #ifndef WINCE 00327 remoteInput->setRtxInfo(rtx); 00328 #endif 00329 };

long IncompleteIO::setToClosestIFrame u32  frameNumber,
bool  backwards
[virtual]
 

repositions the IO class to

Parameters:
frameNumber,if this Frame is an I-frame. Otherwise, according to
backwards,a frameNumber lower or higher than
frameNumber is searched and returned.
Returns:
the chosen frameNumber or -1 in case of an error will only work with IO classes opened for reading.

Reimplemented from IO.

Definition at line 96 of file IncompleteIO.cpp.

References MPGStreamIO::setToClosestIFrame().

00097 { 00098 return localInput->setToClosestIFrame(frameNumber, backwards); 00099 };

bool IncompleteIO::setToFrameNumber u32  frameNumber  )  [virtual]
 

repositions the IO class to the given frame.

Will return false in the following cases:

  • an illegal frame number (too large) was specified
  • the stream is not seekable, because the underlying device is a network device and the requested frame is already out of range: FIXME: implement

Reimplemented from IO.

Definition at line 293 of file IncompleteIO.cpp.

References MPGStreamIO::setToFrameNumber().

00294 { 00295 #ifndef WINCE 00296 bool ret=remoteInput->setToFrameNumber(frameNumber); 00297 #else 00298 bool ret = false; 00299 #endif 00300 // we don't care about remote 00301 ret=localInput->setToFrameNumber(frameNumber); 00302 00303 return ret; 00304 };

int IncompleteIO::writeFrame Frame frm,
ESInfo out_es = NULL
[virtual]
 

returns the number of packets sent.

Returns 0 on error

Implements IO.

Definition at line 216 of file IncompleteIO.cpp.

00217 { 00218 assert(false && "Not Implemented"); 00219 return -1; 00220 };


Member Data Documentation

u32 IncompleteIO::vopTimeIncrement [protected]
 

a backup from the voptimeincrement in the es.

needed because rtp overwrites the value with a wrong detected increment Definition at line 162 of file IncompleteIO.hpp.

Referenced by getFrame(), and IncompleteIO().


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