BufferedIO Class Reference

stores writeFrame() written frames in an internal list-buffer, to be fetchted FIFO-style with getFrame() <short description=""> More...

#include <BufferedIO.hpp>

Inheritance diagram for BufferedIO:

IO VThread List of all members.

Public Member Functions

 BufferedIO (ESInfo *es, MuxDemuxIO *muxio, bool writeOnly)
virtual FramegetFrame ()
 returns a frame if one complete frame is available, otherwise null is returned.
virtual 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 elementary stream and its extra hint-file
int getBufferFillLevel () const
 returns the number of elems in the buffer
IOclone () const
const char * getURL () const
 not implemented/needed
void setESInfo (ESInfo *esi)
ESInfogetESInfo ()
void addToBuffer (Frame *frm)
s64 nextCTSinBuf ()

Protected Attributes

bool writeOnly
ESInfoes
MuxDemuxIOmuxio
bool atFileStart
long lastCTSSeen
list< Frame * > buffer

Detailed Description

stores writeFrame() written frames in an internal list-buffer, to be fetchted FIFO-style with getFrame() <short description="">

Author:
Michael Kropfberger
Version:
Id
BufferedIO.hpp,v 1.7 2006/02/11 16:35:26 klschoef Exp

Definition at line 66 of file BufferedIO.hpp.


Member Function Documentation

bool BufferedIO::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 105 of file BufferedIO.cpp.

References ESInfo::getStreamId(), MuxDemuxIO::processFrame(), and MuxDemuxIO::removeBufferedIO().

Referenced by destroy().

00105 { 00106 dprintf_full("BufferedIO::close ES-ID %lli, immediate=%i, %i frames left in buffer\n",es->getStreamId(), immediate, buffer.size()); 00107 00108 if (state == CLOSED) 00109 return true; 00110 00111 state = CLOSING; 00112 if (!immediate) 00113 while(!buffer.empty()) { //wait until MuxDemuxIO got everything... 00114 dprintf_full("BufferedIO::close ES-ID %lli, %i frames left in buffer\n",es->getStreamId(), buffer.size()); 00115 //if (muxio->getNumberOfConnectedBufferedIO() == 1) //we are the last one, so poll empty 00116 muxio->processFrame(); 00117 // else 00118 //sleep(1); 00119 } 00120 else 00121 buffer.clear(); 00122 00123 muxio->removeBufferedIO(es->getStreamId(), this); 00124 state = CLOSED; 00125 return true; 00126 }

Frame * BufferedIO::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 182 of file BufferedIO.cpp.

References Frame::getAU(), IO::getState(), ESInfo::getStreamId(), and MuxDemuxIO::processFrame().

00182 { 00183 Frame *frm = NULL; 00184 00185 dprintf_full("BufferedIO::getFrame: ES-ID %lli state %i, buffer: %i frames\n",es->getStreamId(), state, buffer.size()); 00186 00187 if ( (state != OPEN) && (state != CLOSING)) 00188 return NULL; 00189 00190 if (atFileStart) { 00191 atFileStart = false; 00192 // return NULL; 00193 } 00194 00195 if (!writeOnly && muxio->getState() != STREAMEOF) 00196 muxio->processFrame(); 00197 00198 if (!buffer.empty()) { 00199 frm = buffer.front(); 00200 buffer.pop_front(); 00201 00202 lastCTSSeen = frm->getAU()->cts; 00203 framesSeen++; 00204 currentFrameNumber++; 00205 dprintf_full("BufferedIO::getFrame: %p AU %p ES-ID %lli cts %i size %i, %i frames left in buffer\n", frm, frm->getAU(), 00206 es->getStreamId(), frm->getAU()->cts, frm->getAU()->size, buffer.size()); 00207 00208 } else { //buffer is empty 00209 if (muxio->getState() == OPEN) { 00210 dprintf_full("BufferedIO::getFrame: ES-ID %lli no frame in buffer right now!\n",es->getStreamId()); 00211 } else 00212 state = muxio->getState(); //may be closed 00213 } 00214 00215 #ifdef _POSIX_PRIORITY_SCHEDULING 00216 sched_yield(); //this is necessary to give parallel getFrames a chance 00217 #endif 00218 00219 return frm; 00220 }

bool BufferedIO::open  )  [virtual]
 

opens the IO connection.

State is set to OPENING. When the connection is ready for use, State is OPEN

Implements IO.

Definition at line 77 of file BufferedIO.cpp.

References ESInfo::disableFrameStatistic(), ESInfo::enableFrameStatistic(), ESInfo::getDuration(), ESInfo::getNumberOfMediaSamples(), ESInfo::getVOPTimeIncrement(), and MuxDemuxIO::open().

00077 { 00078 bool ret = false; 00079 atFileStart = true; 00080 state = OPENING; 00081 lastCTSSeen=0; 00082 00083 if (writeOnly) { 00084 // reset statistic 00085 dprintf_full("BufferedIO::open(): resetting Statistic to %u dur %lli ticks %u\n",es->getNumberOfMediaSamples(), 00086 es->getDuration(), es->getVOPTimeIncrement()); 00087 es->disableFrameStatistic(); 00088 es->enableFrameStatistic(); 00089 } 00090 00091 ret = muxio->open(); 00092 00093 if (ret) 00094 state = OPEN; 00095 else 00096 state = CLOSED; 00097 00098 currentFrameNumber=0; 00099 framesSeen=0; 00100 00101 return ret; 00102 }

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

returns the number of packets sent.

Returns 0 on error

Implements IO.

Definition at line 130 of file BufferedIO.cpp.

References Frame::getAU(), ESInfo::getFrameStatistic(), ESInfo::getStreamId(), ESInfo::getVOPTimeIncrement(), Frame::markForDelete(), MuxDemuxIO::processFrame(), and BitField::setBit().

00130 { 00131 00132 dprintf_full("BufferedIO::writeFrame %p, AU %p, ES-ID %lli\n",frm, frm->getAU(),es->getStreamId()); 00133 // drop frames we have already written!! 00134 if ( (lastCTSSeen >= (signed)frm->getAU()->cts) && (lastCTSSeen != 0) ) { 00135 dprintf_small("BufferedIO::writeFrame WARNING: CTS %u already seen (lastCTSSeen %li) still writing to file!\n", 00136 frm->getAU()->cts,lastCTSSeen); 00137 } else 00138 lastCTSSeen = frm->getAU()->cts; 00139 00140 if (!writeOnly || state != OPEN) { 00141 dprintf_small("BufferedIO::writeFrame esID %llu Warning: Output is readonly or not open\n", es->getStreamId()); 00142 return -1; 00143 } 00144 if (frm->getAU()->size == 0) { 00145 dprintf_small("BufferedIO::writeFrame esID %llu: Cannot write zero sized frames\n", es->getStreamId()); 00146 return 0; 00147 } 00148 00149 dprintf_full("BufferedIO::writeFrame: Storing %i bytes of CTS %i into buffer (already holds %i frames)\n", 00150 frm->getAU()->size, frm->getAU()->cts, buffer.size()); 00151 00152 es->getFrameStatistic()->setBit(frm->getAU()->cts/es->getVOPTimeIncrement()); 00153 00154 // buffer the frame FIFO style 00155 addToBuffer(frm); 00156 frm->markForDelete(false); //take away from DataChannel GarbageCollector, will be deleted in MuxDemuxIO 00157 00158 muxio->processFrame(); 00159 00160 framesSeen++; 00161 00162 #ifdef _POSIX_PRIORITY_SCHEDULING 00163 sched_yield(); //this is necessary to give parallel getFrames a chance 00164 #endif 00165 00166 return true; 00167 }


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