RawStreamIO Class Reference

writes raw frames (eg. <short description=""> More...

#include <RawStreamIO.hpp>

Inheritance diagram for RawStreamIO:

IO VThread YUVStreamIO List of all members.

Public Member Functions

 RawStreamIO (ESInfo *es, const char *file, bool writeOnly)
void setFrameSize (u32 size)
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 a value from 0..100 indicating buffer usage.
IOclone () const
const char * getURL () const
 returns a local file name or an URL
bool setToFrameNumber (u32 frameNumber)
 repositions the IO class to the given frame.
void setESInfo (ESInfo *esi)
ESInfogetESInfo ()

Protected Attributes

FILE * io
char * url
bool writeOnly
ESInfoes
bool atFileStart
long lastCTSSeen
u64 frameSize

Detailed Description

writes raw frames (eg. <short description="">

YUV, audio-pcm or any other raw content)

Author:
Michael Kropfberger and Peter Schojer
Version:
Id
RawStreamIO.hpp,v 1.4 2006/01/26 11:42:00 mkropfbe Exp

Definition at line 61 of file RawStreamIO.hpp.


Member Function Documentation

bool RawStreamIO::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 146 of file RawStreamIO.cpp.

Referenced by YUVinYUVoverlay::adapt(), and destroy().

00146 { 00147 state = CLOSING; 00148 if (io) { 00149 fclose(io); 00150 io=NULL; 00151 } 00152 state = CLOSED; 00153 // this->es->setDuration(lastCTSSeen+es->getVOPTimeIncrement()); 00154 return true; 00155 }

int RawStreamIO::getBufferFillLevel  )  const [inline, virtual]
 

returns a value from 0..100 indicating buffer usage.

Fixme: returns a constant value of 50

Implements IO.

Definition at line 96 of file RawStreamIO.hpp.

00096 { 00097 return 50; 00098 };

Frame * RawStreamIO::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 valuse to conclude STREAMEOF, always check with getState()!

Implements IO.

Reimplemented in YUVStreamIO.

Definition at line 203 of file RawStreamIO.cpp.

References ESInfo::getDuration(), ESInfo::getMediaTimeScale(), ESInfo::getVOPTimeIncrement(), Frame::setAU(), and Frame::setMediaTimeScale().

Referenced by YUVStreamIO::getFrame().

00203 { 00204 if (writeOnly || state != OPEN) 00205 return NULL; 00206 00207 if (frameSize == 0) { 00208 dprintf_err("RawStreamIO::getFrame() has no frameSize, so use \"setFrameSize\" first!\n"); 00209 ::exit(1); 00210 } 00211 00212 if (atFileStart) { 00213 atFileStart = false; 00214 // return NULL; 00215 } 00216 // now read the frame 00217 // first check hintfile 00218 AU *au = new AU(); 00219 Frame *frm = NULL; 00220 Frame::FrameType type = Frame::NN_VOP; 00221 00222 au->size = frameSize; 00223 au->payload = new u8[frameSize]; 00224 if (fread(au->payload,1,frameSize,io) < frameSize) { 00225 if (ferror(io)) { 00226 #ifndef WINCE 00227 perror("RawStreamIO::getFrame failed to read full frame"); 00228 #endif 00229 state = STREAMERR; 00230 } 00231 else 00232 state = STREAMEOF; 00233 return NULL; 00234 } 00235 au->cts = framesSeen * es->getVOPTimeIncrement(); 00236 au->dts = au->cts; 00237 au->duration = es->getDuration(); 00238 au->sampleFlags = 0; 00239 au->err = SA_OK; 00240 00241 frm = new Frame(type); 00242 frm->setAU(au); 00243 frm->setMediaTimeScale(es->getMediaTimeScale()); 00244 framesSeen++; 00245 currentFrameNumber++; 00246 dprintf_full("RawStreamIO::getFrame: file offset %li cts %i dts %i\r\n",ftell(io),au->cts,au->dts); 00247 00248 #ifdef _POSIX_PRIORITY_SCHEDULING 00249 sched_yield(); //this is necessary to give parallel getFrames a chance 00250 #endif 00251 00252 return frm; 00253 }

bool RawStreamIO::open  )  [virtual]
 

opens the IO connection.

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

Implements IO.

Definition at line 93 of file RawStreamIO.cpp.

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

Referenced by YUVinYUVoverlay::adapt().

00093 { 00094 if(!url) 00095 return false; 00096 dprintf_full("RawStreamIO::open() Trying to open %s\r\n", url); 00097 if(state==OPEN) 00098 return true; 00099 00100 bool ret = false; 00101 atFileStart = true; 00102 state = OPENING; 00103 lastCTSSeen=0; 00104 char *name = new char[512]; 00105 strcpy(name,url); 00106 strcat(name,".hint"); 00107 00108 if (writeOnly) { 00109 // we want to write to a local file 00110 // reset statistic 00111 dprintf_full("RawStreamIO::open(): resetting Statistic to %u dur %u ticks %u\n",es->getNumberOfMediaSamples(),(unsigned)es->getDuration(),es->getVOPTimeIncrement()); 00112 es->disableFrameStatistic(); 00113 es->enableFrameStatistic(); 00114 io=fopen(url,"wb"); 00115 ret = (io!=NULL); 00116 if (ret==true) { 00117 #ifndef WIN32 00118 int val = flock(fileno(io),LOCK_EX | LOCK_NB); 00119 if (val == -1) 00120 perror("RawStreamIO::open flock out-file"); 00121 ret = ((val == 0) || (errno == ENOLCK)); //eg. NFS might not support flocks 00122 if (errno == EWOULDBLOCK) { 00123 dprintf_err("RawStreamIO::open(): FATAL: lock on %s is held by other process! \n", url); 00124 ::exit(1); 00125 } 00126 #endif 00127 ; 00128 } 00129 } else { 00130 // we want to read from a local file 00131 io=fopen(url,"rb"); 00132 ret = (io!=NULL); 00133 } 00134 00135 if (ret) 00136 state = OPEN; 00137 else 00138 state = CLOSED; 00139 currentFrameNumber=0; 00140 framesSeen=0; 00141 delete [] name; 00142 return ret; 00143 }

bool RawStreamIO::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 256 of file RawStreamIO.cpp.

00256 { 00257 // check if valid 00258 // e.g.: writeOnly streams can not be seeked 00259 if(writeOnly || !io) { 00260 dprintf_full("RawStreamIO::setToFrameNumber(u32 %i) failed: not WriteClass or no Input IO\n",frameNumber); 00261 return false; 00262 } 00263 00264 dprintf_full("RawStreamIO::setToFrameNumber(u32 %i)\r\n",frameNumber); 00265 fseek(io,frameSize * frameNumber,SEEK_SET); 00266 currentFrameNumber=frameNumber; 00267 00268 if (frameNumber == 0) 00269 atFileStart = true; 00270 return true; 00271 }

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

returns the number of packets sent.

Returns 0 on error

Implements IO.

Definition at line 159 of file RawStreamIO.cpp.

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

00159 { 00160 dprintf_full("RawStreamIO::writeFrame %p\n",frm); 00161 // drop frames we have already written!! 00162 if ( (lastCTSSeen >= (signed)frm->getAU()->cts) && (lastCTSSeen != 0) ) { 00163 dprintf_small("RawStreamIO::writeFrame WARNING: CTS %u already seen (lastCTSSeen %li) still writing to file!\n", 00164 frm->getAU()->cts,lastCTSSeen); 00165 } else 00166 lastCTSSeen = frm->getAU()->cts; 00167 00168 if (!writeOnly || state != OPEN) { 00169 dprintf_small("RawStreamIO::writeFrame esID %llu Warning: Output is readonly or not open\n", es->getStreamId()); 00170 return -1; 00171 } 00172 if (frm->getAU()->size == 0) { 00173 dprintf_small("RawStreamIO::writeFrame esID %llu: Cannot write zero sized frames\n", es->getStreamId()); 00174 return 0; 00175 } 00176 00177 dprintf_full("RawStreamIO::writeFrame: Saving %i bytes of CTS %i\n", 00178 frm->getAU()->size, frm->getAU()->cts); 00179 // save the frame 00180 int i = fwrite(frm->getAU()->payload,sizeof(char), frm->getAU()->size , io); 00181 00182 00183 framesSeen++; 00184 es->getFrameStatistic()->setBit(frm->getAU()->cts/es->getVOPTimeIncrement()); 00185 00186 #ifdef _POSIX_PRIORITY_SCHEDULING 00187 sched_yield(); //this is necessary to give parallel getFrames a chance 00188 #endif 00189 00190 return ((signed)frm->getAU()->size == i); 00191 }


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