BufferedMPGStreamReader Class Reference

#include <BufferedMPGStreamReader.hpp>

Inheritance diagram for BufferedMPGStreamReader:

MPGStreamIO IO VThread List of all members.

Public Member Functions

 BufferedMPGStreamReader (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.

Static Public Member Functions

int getDefaultBufferSize ()

Detailed Description

Author:
Klaus Schoeffmann

Definition at line 62 of file BufferedMPGStreamReader.hpp.


Member Function Documentation

Frame * BufferedMPGStreamReader::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 180 of file BufferedMPGStreamReader.cpp.

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

00180 { 00181 if (writeOnly || state != OPEN) 00182 return NULL; 00183 00184 if (( (this->currentFrameNumber > this->endFrameNumber) && (endFrameNumber!=0) )) { // || feof(io)) { 00185 close(true); 00186 state=STREAMEOF; 00187 return NULL; 00188 } 00189 00190 // now read the frame 00191 AU *au = new AU(); 00192 Frame *frm = NULL; 00193 Frame::FrameType type = Frame::NN_VOP; 00194 00195 // parse MPGFile for VOB_Code if it is a visual stream 00196 00197 if(es->isVisualStream()) { 00198 // 00 00 01 182 dec -> 0x1B6 (=438 dec) 00199 u32 code = 2000; // don't init to 0, we want the code from the 2nd frame, not the first 00200 int i = 0; 00201 00202 u8 *data = new u8[MAX_FRAME_SIZE]; 00203 00204 do { 00205 data[i] = buffered_getc(); 00206 code = (code << 8) | data[i]; //(u8)buffered_getc(); 00207 i++; 00208 if ((i==4) && code == VOP_START_CODE) code = 0; 00209 } while ((code != VOP_START_CODE) && (i < maxFrameSize) && state != CLOSED); 00210 00211 if (code == VOP_START_CODE) { 00212 goBack(4); 00213 i -= 4; 00214 au->size = i; 00215 au->payload = new u8[i]; 00216 memcpy(au->payload, data, i); 00217 delete [] data; 00218 dprintf_full("BufferedMPGStreamReader::getFrame() read %d bytes of video frame\n", i); 00219 } 00220 00221 if (au->size == 0) { 00222 state = STREAMEOF; 00223 delete au; 00224 return NULL; 00225 } 00226 00227 au->prio = IO_NETWORK_HIGHEST_PRIORITY; 00228 au->duration = es->getVOPTimeIncrement(); 00229 au->cts = currentFrameNumber * es->getVOPTimeIncrement(); 00230 au->dts = currentFrameNumber * es->getVOPTimeIncrement(); 00231 au->sampleFlags = 0; 00232 if (code != VOP_START_CODE) 00233 au->err = SA_EOF; 00234 else 00235 au->err = SA_OK; 00236 00237 } 00238 00239 if(es->isAudioStream()) { //XXX not sure if it works properly 00240 // start code for MP3 frame is 11111111 111 (first 11 bits set) 00241 u32 code = 2000; // don't init to 0, we want the code from the 2nd frame, not the first 00242 int i = 0; 00243 00244 //special handling for first frame 00245 if (framesSeen == 0) { 00246 int ch = 0; 00247 au->payload = new u8[1024]; 00248 do { 00249 ch = buffered_getc(); 00250 au->payload[i] = ch; 00251 i++; 00252 code = (code << 8) | ch; 00253 } 00254 while ((code>>21) != 0x000007FF /*VOP_START_CODE for audio(actually MP3)*/); 00255 au->size = i; 00256 } else { 00257 au->payload = new u8[MAX_FRAME_SIZE]; 00258 au->size = buffered_copy(au->payload, maxFrameSize); 00259 } 00260 00261 dprintf_full("BufferedMPGStreamReader::getFrame() read %d bytes of audio frame\n", au->size); 00262 00263 au->cts = DTS; 00264 au->dts = DTS; 00265 au->duration = 0; 00266 au->sampleFlags = 0; 00267 au->err = SA_OK; 00268 00269 DTS += es->getVOPTimeIncrement(); 00270 } 00271 00272 // frame types will be detected in frm->setAU()! 00273 if(es->isVisualStream()) 00274 frm = new CompressedVideoFrame(type, ((VideoESInfo*)es)->getWidth(), ((VideoESInfo*)es)->getHeight()); 00275 else if(es->isAudioStream()) 00276 frm=new CompressedAudioFrame(type); 00277 else 00278 frm = new CompressedVideoFrame(type, 0, 0); 00279 frm->setAU(au); 00280 frm->setMediaTimeScale(es->getMediaTimeScale()); 00281 framesSeen++; 00282 currentFrameNumber++; 00283 00284 00285 #ifdef _POSIX_PRIORITY_SCHEDULING 00286 sched_yield(); 00287 #else 00288 // for windows pthread lib! 00289 #ifdef WIN32 00290 #ifndef WINCE 00291 sched_yield(); 00292 #else 00293 Sleep(1); 00294 #endif 00295 #endif 00296 #endif 00297 00298 return frm; 00299 }


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