BufferedHttpMPGStreamReader Class Reference

#include <BufferedHttpMPGStreamReader.hpp>

Inheritance diagram for BufferedHttpMPGStreamReader:

MPGStreamIO IO VThread List of all members.

Public Member Functions

 BufferedHttpMPGStreamReader (ESInfo *es, const char *file, bool writeOnly, bool omitHeader=false, int bufferSize=STREAMREADER_DEF_BUFFER_SIZE, int maxFrameSize=MAX_FRAME_SIZE)
bool testFileopen ()
FramegetFrame ()
 returns a frame if one complete frame is available, otherwise null is returned.
int writeFrame (const Frame *frm)
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
bool setToFrameNumber (u32 frameNumber)
 repositions the IO class to the given frame.
long setToClosestIFrame (u32 frameNumber, bool backwards)
 repositions to previous I-VOP,
u32 getContentLength ()

Static Public Member Functions

int getDefaultBufferSize ()

Detailed Description

Author:
Klaus Schoeffmann

Definition at line 73 of file BufferedHttpMPGStreamReader.hpp.


Member Function Documentation

bool BufferedHttpMPGStreamReader::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)

Reimplemented from MPGStreamIO.

Definition at line 112 of file BufferedHttpMPGStreamReader.cpp.

References HttpRequest::closeSock(), and IO::setState().

Referenced by getFrame().

00113 { 00114 if (http != NULL) { 00115 http->closeSock(); 00116 } 00117 dprintf_small("BufferedHttpMPGStreamReader::close() set state to CLOSED!\n"); 00118 setState(CLOSED); 00119 return true; 00120 }

Frame * BufferedHttpMPGStreamReader::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()!

Reimplemented from MPGStreamIO.

Definition at line 230 of file BufferedHttpMPGStreamReader.cpp.

References close(), ESInfo::getVOPTimeIncrement(), ESInfo::isAudioStream(), ESInfo::isVisualStream(), Frame::setAU(), and Frame::setMediaTimeScale().

00230 { 00231 if (writeOnly || state != OPEN) 00232 return NULL; 00233 00234 if (( (this->currentFrameNumber > this->endFrameNumber) && (endFrameNumber!=0) )) { // || feof(io)) { 00235 close(true); 00236 state=STREAMEOF; 00237 return NULL; 00238 } 00239 00240 // now read the frame 00241 AU *au = new AU(); 00242 Frame *frm = NULL; 00243 Frame::FrameType type = Frame::NN_VOP; 00244 00245 // parse MPGFile for VOB_Code if it is a visual stream 00246 00247 if(es->isVisualStream()) { 00248 // 00 00 01 182 dec -> 0x1B6 (=438 dec) 00249 u32 code = 2000; // don't init to 0, we want the code from the 2nd frame, not the first 00250 int i = 0; 00251 00252 u8 *data = new u8[MAX_FRAME_SIZE]; 00253 00254 do { 00255 data[i] = buffered_getc(); 00256 code = (code << 8) | data[i]; //(u8)buffered_getc(); 00257 i++; 00258 if ((i==4) && code == VOP_START_CODE) code = 0; 00259 } while ((code != VOP_START_CODE) && (i < maxFrameSize) && state != CLOSED); 00260 00261 if (code == VOP_START_CODE) { 00262 goBack(4); 00263 i -= 4; 00264 au->size = i; 00265 au->payload = new u8[i]; 00266 memcpy(au->payload, data, i); 00267 delete [] data; 00268 dprintf_full("BufferedHttpMPGStreamReader::getFrame() read %d bytes of video frame\n", i); 00269 } 00270 00271 if (au->size == 0) { 00272 state = STREAMEOF; 00273 delete au; 00274 return NULL; 00275 } 00276 00277 au->prio = IO_NETWORK_HIGHEST_PRIORITY; 00278 au->duration = es->getVOPTimeIncrement(); 00279 au->cts = currentFrameNumber * es->getVOPTimeIncrement(); 00280 au->dts = currentFrameNumber * es->getVOPTimeIncrement(); 00281 au->sampleFlags = 0; 00282 if (code != VOP_START_CODE) 00283 au->err = SA_EOF; 00284 else 00285 au->err = SA_OK; 00286 00287 } 00288 00289 if(es->isAudioStream()) { //XXX not sure if it works properly 00290 // start code for MP3 frame is 11111111 111 (first 11 bits set) 00291 u32 code = 2000; // don't init to 0, we want the code from the 2nd frame, not the first 00292 int i = 0; 00293 00294 //special handling for first frame 00295 if (framesSeen == 0) { 00296 int ch = 0; 00297 au->payload = new u8[1024]; 00298 do { 00299 ch = buffered_getc(); 00300 au->payload[i] = ch; 00301 i++; 00302 code = (code << 8) | ch; 00303 } 00304 while ((code>>21) != 0x000007FF /*VOP_START_CODE for audio(actually MP3)*/); 00305 au->size = i; 00306 } else { 00307 au->payload = new u8[MAX_FRAME_SIZE]; 00308 au->size = buffered_copy(au->payload, maxFrameSize); 00309 } 00310 00311 dprintf_full("BufferedHttpMPGStreamReader::getFrame() read %d bytes of audio frame\n", au->size); 00312 00313 au->cts = DTS; 00314 au->dts = DTS; 00315 au->duration = 0; 00316 au->sampleFlags = 0; 00317 au->err = SA_OK; 00318 00319 DTS += es->getVOPTimeIncrement(); 00320 } 00321 00322 // frame types will be detected in frm->setAU()! 00323 if(es->isVisualStream()) 00324 frm = new CompressedVideoFrame(type, ((VideoESInfo*)es)->getWidth(), ((VideoESInfo*)es)->getHeight()); 00325 else if(es->isAudioStream()) 00326 frm=new CompressedAudioFrame(type); 00327 else 00328 frm = new CompressedVideoFrame(type, 0, 0); 00329 frm->setAU(au); 00330 frm->setMediaTimeScale(es->getMediaTimeScale()); 00331 framesSeen++; 00332 currentFrameNumber++; 00333 00334 00335 #ifdef _POSIX_PRIORITY_SCHEDULING 00336 sched_yield(); 00337 #else 00338 // for windows pthread lib! 00339 #ifdef WIN32 00340 #ifndef WINCE 00341 sched_yield(); 00342 #else 00343 Sleep(1); 00344 #endif 00345 #endif 00346 #endif 00347 00348 return frm; 00349 }

bool BufferedHttpMPGStreamReader::open  )  [virtual]
 

opens the IO connection.

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

Reimplemented from MPGStreamIO.

Definition at line 92 of file BufferedHttpMPGStreamReader.cpp.

References HttpRequest::getContentLength(), HttpRequest::makeHttpRequest(), and IO::setState().

00093 { 00094 00095 setState(OPENING); 00096 00097 http = new HttpRequest(url); 00098 00099 if (http->makeHttpRequest()) { 00100 initBuffer(); 00101 contentLength = http->getContentLength(); 00102 00103 setState(OPEN); 00104 return true; 00105 } 00106 00107 setState(CLOSED); 00108 return false; 00109 }

long BufferedHttpMPGStreamReader::setToClosestIFrame u32  frameNumber,
bool  backwards
[inline, virtual]
 

repositions to previous I-VOP,

Returns:
frameNr or -1 if no previous I-VOP found

Reimplemented from MPGStreamIO.

Definition at line 97 of file BufferedHttpMPGStreamReader.hpp.

00097 { return 0; };

bool BufferedHttpMPGStreamReader::setToFrameNumber u32  frameNumber  )  [inline, 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 MPGStreamIO.

Definition at line 95 of file BufferedHttpMPGStreamReader.hpp.

00095 { return false; };


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