MPEGProgramStreamParser Class Reference

Inheritance diagram for MPEGProgramStreamParser:

Inheritance graph
[legend]
Collaboration diagram for MPEGProgramStreamParser:

Collaboration graph
[legend]

Public Member Functions

 MPEGProgramStreamParser (MPEG1or2Demux *usingDemux, FramedSource *inputSource)
virtual ~MPEGProgramStreamParser ()
unsigned char parse ()
virtual void flushInput ()

Protected Types

typedef void( clientContinueFunc )(void *clientData, unsigned char *ptr, unsigned size, struct timeval presentationTime)

Protected Member Functions

void saveParserState ()
virtual void restoreSavedParserState ()
u_int32_t get4Bytes ()
u_int32_t test4Bytes ()
u_int16_t get2Bytes ()
u_int8_t get1Byte ()
u_int8_t test1Byte ()
void getBytes (u_int8_t *to, unsigned numBytes)
void testBytes (u_int8_t *to, unsigned numBytes)
void skipBytes (unsigned numBytes)
void skipBits (unsigned numBits)
unsigned getBits (unsigned numBits)
unsigned curOffset () const
unsigned & totNumValidBytes ()
Boolean haveSeenEOF () const
unsigned bankSize () const

Private Member Functions

void setParseState (MPEGParseState parseState)
void parsePackHeader ()
void parseSystemHeader ()
unsigned char parsePESPacket ()
Boolean isSpecialStreamId (unsigned char stream_id) const

Private Attributes

MPEG1or2DemuxfUsingDemux
MPEGParseState fCurrentParseState

Detailed Description

Definition at line 35 of file MPEG1or2Demux.cpp.


Member Typedef Documentation

typedef void( StreamParser::clientContinueFunc)(void *clientData, unsigned char *ptr, unsigned size, struct timeval presentationTime) [protected, inherited]

Definition at line 33 of file StreamParser.hh.


Constructor & Destructor Documentation

MPEGProgramStreamParser::MPEGProgramStreamParser ( MPEG1or2Demux usingDemux,
FramedSource inputSource 
)

Definition at line 328 of file MPEG1or2Demux.cpp.

00330   : StreamParser(inputSource, MPEG1or2Demux::handleClosure, usingDemux,
00331                  &MPEG1or2Demux::continueReadProcessing, usingDemux),
00332   fUsingDemux(usingDemux), fCurrentParseState(PARSING_PACK_HEADER) {
00333 }

MPEGProgramStreamParser::~MPEGProgramStreamParser (  )  [virtual]

Definition at line 335 of file MPEG1or2Demux.cpp.

00335                                                   {
00336 }


Member Function Documentation

unsigned char MPEGProgramStreamParser::parse (  ) 

Definition at line 343 of file MPEG1or2Demux.cpp.

References fCurrentParseState, parsePackHeader(), parsePESPacket(), parseSystemHeader(), PARSING_PACK_HEADER, PARSING_PES_PACKET, and PARSING_SYSTEM_HEADER.

Referenced by MPEG1or2Demux::continueReadProcessing().

00343                                              {
00344   unsigned char acquiredStreamTagId = 0;
00345 
00346   try {
00347     do {
00348       switch (fCurrentParseState) {
00349       case PARSING_PACK_HEADER: {
00350         parsePackHeader();
00351         break;
00352       }
00353       case PARSING_SYSTEM_HEADER: {
00354         parseSystemHeader();
00355         break;
00356       }
00357       case PARSING_PES_PACKET: {
00358         acquiredStreamTagId = parsePESPacket();
00359         break;
00360       }
00361       }
00362     } while(acquiredStreamTagId == 0);
00363 
00364     return acquiredStreamTagId;
00365   } catch (int /*e*/) {
00366 #ifdef DEBUG
00367     fprintf(stderr, "MPEGProgramStreamParser::parse() EXCEPTION (This is normal behavior - *not* an error)\n");
00368     fflush(stderr);
00369 #endif
00370     return 0;  // the parsing got interrupted
00371   }
00372 }

void MPEGProgramStreamParser::setParseState ( MPEGParseState  parseState  )  [private]

Definition at line 338 of file MPEG1or2Demux.cpp.

References fCurrentParseState, and StreamParser::saveParserState().

Referenced by parsePackHeader(), parsePESPacket(), and parseSystemHeader().

00338                                                                      {
00339   fCurrentParseState = parseState;
00340   saveParserState();
00341 }

void MPEGProgramStreamParser::parsePackHeader (  )  [private]

Definition at line 383 of file MPEG1or2Demux.cpp.

References Medium::envir(), MPEG1or2Demux::SCR::extension, MPEG1or2Demux::fLastSeenSCR, MPEG1or2Demux::fMPEGversion, fUsingDemux, StreamParser::get1Byte(), StreamParser::get4Bytes(), StreamParser::getBits(), MPEG1or2Demux::SCR::highBit, isPacketStartCode(), MPEG1or2Demux::SCR::isValid, PACK_START_CODE, PARSING_PACK_HEADER, PARSING_PES_PACKET, PARSING_SYSTEM_HEADER, MPEG1or2Demux::SCR::remainingBits, setParseState(), StreamParser::skipBits(), StreamParser::skipBytes(), SYSTEM_HEADER_START_CODE, StreamParser::test4Bytes(), and True.

Referenced by parse().

00383                                               {
00384 #ifdef DEBUG
00385   fprintf(stderr, "parsing pack header\n"); fflush(stderr);
00386 #endif
00387   unsigned first4Bytes;
00388   while (1) {
00389     first4Bytes = test4Bytes();
00390 
00391     // We're supposed to have a pack header here, but check also for
00392     // a system header or a PES packet, just in case:
00393     if (first4Bytes == PACK_START_CODE) {
00394       skipBytes(4);
00395       break;
00396     } else if (first4Bytes == SYSTEM_HEADER_START_CODE) {
00397 #ifdef DEBUG
00398       fprintf(stderr, "found system header instead of pack header\n");
00399 #endif
00400       setParseState(PARSING_SYSTEM_HEADER);
00401       return;
00402     } else if (isPacketStartCode(first4Bytes)) {
00403 #ifdef DEBUG
00404       fprintf(stderr, "found packet start code 0x%02x instead of pack header\n", first4Bytes);
00405 #endif
00406       setParseState(PARSING_PES_PACKET);
00407       return;
00408     }
00409 
00410     setParseState(PARSING_PACK_HEADER); // ensures we progress over bad data
00411     if ((first4Bytes&0xFF) > 1) { // a system code definitely doesn't start here
00412       skipBytes(4);
00413     } else {
00414       skipBytes(1);
00415     }
00416   }
00417 
00418   // The size of the pack header differs depending on whether it's
00419   // MPEG-1 or MPEG-2.  The next byte tells us this:
00420   unsigned char nextByte = get1Byte();
00421   MPEG1or2Demux::SCR& scr = fUsingDemux->fLastSeenSCR; // alias
00422   if ((nextByte&0xF0) == 0x20) { // MPEG-1
00423     fUsingDemux->fMPEGversion = 1;
00424     scr.highBit =  (nextByte&0x08)>>3;
00425     scr.remainingBits = (nextByte&0x06)<<29;
00426     unsigned next4Bytes = get4Bytes();
00427     scr.remainingBits |= (next4Bytes&0xFFFE0000)>>2;
00428     scr.remainingBits |= (next4Bytes&0x0000FFFE)>>1;
00429     scr.extension = 0;
00430     scr.isValid = True;
00431     skipBits(24);
00432 
00433 #if defined(DEBUG_TIMESTAMPS) || defined(DEBUG_SCR_TIMESTAMPS)
00434     fprintf(stderr, "pack hdr system_clock_reference_base: 0x%x",
00435             scr.highBit);
00436     fprintf(stderr, "%08x\n", scr.remainingBits);
00437 #endif
00438   } else if ((nextByte&0xC0) == 0x40) { // MPEG-2
00439     fUsingDemux->fMPEGversion = 2;
00440     scr.highBit =  (nextByte&0x20)>>5;
00441     scr.remainingBits = (nextByte&0x18)<<27;
00442     scr.remainingBits |= (nextByte&0x03)<<28;
00443     unsigned next4Bytes = get4Bytes();
00444     scr.remainingBits |= (next4Bytes&0xFFF80000)>>4;
00445     scr.remainingBits |= (next4Bytes&0x0003FFF8)>>3;
00446     scr.extension = (next4Bytes&0x00000003)<<7;
00447     next4Bytes = get4Bytes();
00448     scr.extension |= (next4Bytes&0xFE000000)>>25;
00449     scr.isValid = True;
00450     skipBits(5);
00451 
00452 #if defined(DEBUG_TIMESTAMPS) || defined(DEBUG_SCR_TIMESTAMPS)
00453     fprintf(stderr, "pack hdr system_clock_reference_base: 0x%x",
00454             scr.highBit);
00455     fprintf(stderr, "%08x\n", scr.remainingBits);
00456     fprintf(stderr, "pack hdr system_clock_reference_extension: 0x%03x\n",
00457             scr.extension);
00458 #endif
00459     unsigned char pack_stuffing_length = getBits(3);
00460     skipBytes(pack_stuffing_length);
00461   } else { // unknown
00462     fUsingDemux->envir() << "StreamParser::parsePack() saw strange byte "
00463                           << (void*)nextByte
00464                           << " following pack_start_code\n";
00465   }
00466 
00467   // Check for a System Header next:
00468   setParseState(PARSING_SYSTEM_HEADER);
00469 }

void MPEGProgramStreamParser::parseSystemHeader (  )  [private]

Definition at line 471 of file MPEG1or2Demux.cpp.

References Medium::envir(), fUsingDemux, StreamParser::get2Bytes(), PARSING_PES_PACKET, setParseState(), StreamParser::skipBytes(), SYSTEM_HEADER_START_CODE, and StreamParser::test4Bytes().

Referenced by parse().

00471                                                 {
00472 #ifdef DEBUG
00473   fprintf(stderr, "parsing system header\n"); fflush(stderr);
00474 #endif
00475   unsigned next4Bytes = test4Bytes();
00476   if (next4Bytes != SYSTEM_HEADER_START_CODE) {
00477     // The system header was optional.  Look for a PES Packet instead:
00478     setParseState(PARSING_PES_PACKET);
00479     return;
00480   }
00481 
00482 #ifdef DEBUG
00483   fprintf(stderr, "saw system_header_start_code\n"); fflush(stderr);
00484 #endif
00485   skipBytes(4); // we've already seen the system_header_start_code
00486 
00487   unsigned short remaining_header_length = get2Bytes();
00488 
00489   // According to the MPEG-1 and MPEG-2 specs, "remaining_header_length" should be
00490   // at least 6 bytes.  Check this now:
00491   if (remaining_header_length < 6) {
00492     fUsingDemux->envir() << "StreamParser::parseSystemHeader(): saw strange header_length: "
00493                           << remaining_header_length << " < 6\n";
00494   }
00495   skipBytes(remaining_header_length);
00496 
00497   // Check for a PES Packet next:
00498   setParseState(PARSING_PES_PACKET);
00499 }

unsigned char MPEGProgramStreamParser::parsePESPacket (  )  [private]

Definition at line 525 of file MPEG1or2Demux.cpp.

References StreamParser::curOffset(), Medium::envir(), MPEG1or2Demux::fHaveUndeliveredData, MPEG1or2Demux::fMPEGversion, MPEG1or2Demux::fOutput, MPEG1or2Demux::OutputDescriptor::frameSize, fUsingDemux, StreamParser::get1Byte(), StreamParser::get2Bytes(), StreamParser::get4Bytes(), StreamParser::getBits(), StreamParser::getBytes(), MPEG1or2Demux::OutputDescriptor::isCurrentlyActive, MPEG1or2Demux::OutputDescriptor::isCurrentlyAwaitingData, isPacketStartCode(), MPEG1or2Demux::OutputDescriptor::isPotentiallyReadable, isSpecialStreamId(), MPEG1or2Demux::OutputDescriptor::maxSize, NULL, PARSING_PACK_HEADER, PARSING_PES_PACKET, RAW_PES, READER_NOT_READY, StreamParser::restoreSavedParserState(), MPEG1or2Demux::OutputDescriptor::savedDataHead, MPEG1or2Demux::OutputDescriptor::savedDataTail, MPEG1or2Demux::OutputDescriptor::savedDataTotalSize, setParseState(), StreamParser::skipBytes(), StreamParser::test4Bytes(), MPEG1or2Demux::OutputDescriptor::to, and True.

Referenced by parse().

00525                                                       {
00526 #ifdef DEBUG
00527   fprintf(stderr, "parsing PES packet\n"); fflush(stderr);
00528 #endif
00529   unsigned next4Bytes = test4Bytes();
00530   if (!isPacketStartCode(next4Bytes)) {
00531     // The PES Packet was optional.  Look for a Pack Header instead:
00532     setParseState(PARSING_PACK_HEADER);
00533     return 0;
00534   }
00535 
00536 #ifdef DEBUG
00537   fprintf(stderr, "saw packet_start_code_prefix\n"); fflush(stderr);
00538 #endif
00539   skipBytes(3); // we've already seen the packet_start_code_prefix
00540 
00541   unsigned char stream_id = get1Byte();
00542 #if defined(DEBUG) || defined(DEBUG_TIMESTAMPS)
00543   unsigned char streamNum = stream_id;
00544   char const* streamTypeStr;
00545   if ((stream_id&0xE0) == 0xC0) {
00546     streamTypeStr = "audio";
00547     streamNum = stream_id&~0xE0;
00548   } else if ((stream_id&0xF0) == 0xE0) {
00549     streamTypeStr = "video";
00550     streamNum = stream_id&~0xF0;
00551   } else if (stream_id == 0xbc) {
00552     streamTypeStr = "reserved";
00553   } else if (stream_id == 0xbd) {
00554     streamTypeStr = "private_1";
00555   } else if (stream_id == 0xbe) {
00556     streamTypeStr = "padding";
00557   } else if (stream_id == 0xbf) {
00558     streamTypeStr = "private_2";
00559   } else {
00560     streamTypeStr = "unknown";
00561   }
00562 #endif
00563 #ifdef DEBUG
00564   static unsigned frameCount = 1;
00565   fprintf(stderr, "%d, saw %s stream: 0x%02x\n", frameCount, streamTypeStr, streamNum); fflush(stderr);
00566 #endif
00567 
00568   unsigned short PES_packet_length = get2Bytes();
00569 #ifdef DEBUG
00570   fprintf(stderr, "PES_packet_length: %d\n", PES_packet_length); fflush(stderr);
00571 #endif
00572 
00573   // Parse over the rest of the header, until we get to the packet data itself.
00574   // This varies depending upon the MPEG version:
00575   if (fUsingDemux->fOutput[RAW_PES].isPotentiallyReadable) {
00576     // Hack: We've been asked to return raw PES packets, for every stream:
00577     stream_id = RAW_PES;
00578   }
00579   unsigned savedParserOffset = curOffset();
00580 #ifdef DEBUG_TIMESTAMPS
00581   unsigned char pts_highBit = 0;
00582   unsigned pts_remainingBits = 0;
00583   unsigned char dts_highBit = 0;
00584   unsigned dts_remainingBits = 0;
00585 #endif
00586   if (fUsingDemux->fMPEGversion == 1) {
00587     if (!isSpecialStreamId(stream_id)) {
00588       unsigned char nextByte;
00589       while ((nextByte = get1Byte()) == 0xFF) { // stuffing_byte
00590       }
00591       if ((nextByte&0xC0) == 0x40) { // '01'
00592         skipBytes(1);
00593         nextByte = get1Byte();
00594       }
00595       if ((nextByte&0xF0) == 0x20) { // '0010'
00596 #ifdef DEBUG_TIMESTAMPS
00597         pts_highBit =  (nextByte&0x08)>>3;
00598         pts_remainingBits = (nextByte&0x06)<<29;
00599         unsigned next4Bytes = get4Bytes();
00600         pts_remainingBits |= (next4Bytes&0xFFFE0000)>>2;
00601         pts_remainingBits |= (next4Bytes&0x0000FFFE)>>1;
00602 #else
00603         skipBytes(4);
00604 #endif
00605       } else if ((nextByte&0xF0) == 0x30) { // '0011'
00606 #ifdef DEBUG_TIMESTAMPS
00607         pts_highBit =  (nextByte&0x08)>>3;
00608         pts_remainingBits = (nextByte&0x06)<<29;
00609         unsigned next4Bytes = get4Bytes();
00610         pts_remainingBits |= (next4Bytes&0xFFFE0000)>>2;
00611         pts_remainingBits |= (next4Bytes&0x0000FFFE)>>1;
00612 
00613         nextByte = get1Byte();
00614         dts_highBit =  (nextByte&0x08)>>3;
00615         dts_remainingBits = (nextByte&0x06)<<29;
00616         next4Bytes = get4Bytes();
00617         dts_remainingBits |= (next4Bytes&0xFFFE0000)>>2;
00618         dts_remainingBits |= (next4Bytes&0x0000FFFE)>>1;
00619 #else
00620         skipBytes(9);
00621 #endif
00622       }
00623     }
00624   } else { // assume MPEG-2
00625     if (!isSpecialStreamId(stream_id)) {
00626       // Fields in the next 3 bytes determine the size of the rest:
00627       unsigned next3Bytes = getBits(24);
00628 #ifdef DEBUG_TIMESTAMPS
00629       unsigned char PTS_DTS_flags       = (next3Bytes&0x00C000)>>14;
00630 #endif
00631 #ifdef undef
00632       unsigned char ESCR_flag           = (next3Bytes&0x002000)>>13;
00633       unsigned char ES_rate_flag        = (next3Bytes&0x001000)>>12;
00634       unsigned char DSM_trick_mode_flag = (next3Bytes&0x000800)>>11;
00635 #endif
00636       unsigned char PES_header_data_length = (next3Bytes&0x0000FF);
00637 #ifdef DEBUG
00638       fprintf(stderr, "PES_header_data_length: 0x%02x\n", PES_header_data_length); fflush(stderr);
00639 #endif
00640 #ifdef DEBUG_TIMESTAMPS
00641       if (PTS_DTS_flags == 0x2 && PES_header_data_length >= 5) {
00642         unsigned char nextByte = get1Byte();
00643         pts_highBit =  (nextByte&0x08)>>3;
00644         pts_remainingBits = (nextByte&0x06)<<29;
00645         unsigned next4Bytes = get4Bytes();
00646         pts_remainingBits |= (next4Bytes&0xFFFE0000)>>2;
00647         pts_remainingBits |= (next4Bytes&0x0000FFFE)>>1;
00648 
00649         skipBytes(PES_header_data_length-5);
00650       } else if (PTS_DTS_flags == 0x3 && PES_header_data_length >= 10) {
00651         unsigned char nextByte = get1Byte();
00652         pts_highBit =  (nextByte&0x08)>>3;
00653         pts_remainingBits = (nextByte&0x06)<<29;
00654         unsigned next4Bytes = get4Bytes();
00655         pts_remainingBits |= (next4Bytes&0xFFFE0000)>>2;
00656         pts_remainingBits |= (next4Bytes&0x0000FFFE)>>1;
00657 
00658         nextByte = get1Byte();
00659         dts_highBit =  (nextByte&0x08)>>3;
00660         dts_remainingBits = (nextByte&0x06)<<29;
00661         next4Bytes = get4Bytes();
00662         dts_remainingBits |= (next4Bytes&0xFFFE0000)>>2;
00663         dts_remainingBits |= (next4Bytes&0x0000FFFE)>>1;
00664 
00665         skipBytes(PES_header_data_length-10);
00666       }
00667 #else
00668       skipBytes(PES_header_data_length);
00669 #endif
00670     }
00671   }
00672 #ifdef DEBUG_TIMESTAMPS
00673   fprintf(stderr, "%s stream, ", streamTypeStr);
00674   fprintf(stderr, "packet presentation_time_stamp: 0x%x", pts_highBit);
00675   fprintf(stderr, "%08x\n", pts_remainingBits);
00676   fprintf(stderr, "\t\tpacket decoding_time_stamp: 0x%x", dts_highBit);
00677   fprintf(stderr, "%08x\n", dts_remainingBits);
00678 #endif
00679 
00680   // The rest of the packet will be the "PES_packet_data_byte"s
00681   // Make sure that "PES_packet_length" was consistent with where we are now:
00682   unsigned char acquiredStreamIdTag = 0;
00683   unsigned currentParserOffset = curOffset();
00684   unsigned bytesSkipped = currentParserOffset - savedParserOffset;
00685   if (stream_id == RAW_PES) {
00686     restoreSavedParserState(); // so we deliver from the beginning of the PES packet
00687     PES_packet_length += 6; // to include the whole of the PES packet
00688     bytesSkipped = 0;
00689   }
00690   if (PES_packet_length < bytesSkipped) {
00691     fUsingDemux->envir() << "StreamParser::parsePESPacket(): saw inconsistent PES_packet_length "
00692                           << PES_packet_length << " < "
00693                           << bytesSkipped << "\n";
00694   } else {
00695     PES_packet_length -= bytesSkipped;
00696 #ifdef DEBUG
00697     unsigned next4Bytes = test4Bytes();
00698 #endif
00699 
00700     // Check whether our using source is interested in this stream type.
00701     // If so, deliver the frame to him:
00702     MPEG1or2Demux::OutputDescriptor_t& out = fUsingDemux->fOutput[stream_id];
00703     if (out.isCurrentlyAwaitingData) {
00704       unsigned numBytesToCopy;
00705       if (PES_packet_length > out.maxSize) {
00706         fUsingDemux->envir() << "MPEGProgramStreamParser::parsePESPacket() error: PES_packet_length ("
00707                               << PES_packet_length
00708                               << ") exceeds max frame size asked for ("
00709                               << out.maxSize << ")\n";
00710         numBytesToCopy = out.maxSize;
00711       } else {
00712         numBytesToCopy = PES_packet_length;
00713       }
00714 
00715       getBytes(out.to, numBytesToCopy);
00716       out.frameSize = numBytesToCopy;
00717 #ifdef DEBUG
00718       fprintf(stderr, "%d, %d bytes of PES_packet_data (out.maxSize: %d); first 4 bytes: 0x%08x\n", frameCount, numBytesToCopy, out.maxSize, next4Bytes); fflush(stderr);
00719 #endif
00720       // set out.presentationTime later #####
00721       acquiredStreamIdTag = stream_id;
00722       PES_packet_length -= numBytesToCopy;
00723     } else if (out.isCurrentlyActive) {
00724       // Someone has been reading this stream, but isn't right now.
00725       // We can't deliver this frame until he asks for it, so punt for now.
00726       // The next time he asks for a frame, he'll get it.
00727 #ifdef DEBUG
00728       fprintf(stderr, "%d, currently undeliverable PES data; first 4 bytes: 0x%08x - currently undeliverable!\n", frameCount, next4Bytes); fflush(stderr);
00729 #endif
00730       restoreSavedParserState(); // so we read from the beginning next time
00731       fUsingDemux->fHaveUndeliveredData = True;
00732       throw READER_NOT_READY;
00733     } else if (out.isPotentiallyReadable &&
00734                out.savedDataTotalSize + PES_packet_length < 1000000 /*limit*/) {
00735       // Someone is interested in this stream, but hasn't begun reading it yet.
00736       // Save this data, so that the reader will get it when he later asks for it.
00737       unsigned char* buf = new unsigned char[PES_packet_length];
00738       getBytes(buf, PES_packet_length);
00739       MPEG1or2Demux::OutputDescriptor::SavedData* savedData
00740         = new MPEG1or2Demux::OutputDescriptor::SavedData(buf, PES_packet_length);
00741       if (out.savedDataHead == NULL) {
00742         out.savedDataHead = out.savedDataTail = savedData;
00743       } else {
00744         out.savedDataTail->next = savedData;
00745         out.savedDataTail = savedData;
00746       }
00747       out.savedDataTotalSize += PES_packet_length;
00748       PES_packet_length = 0;
00749     }
00750     skipBytes(PES_packet_length);
00751   }
00752 
00753   // Check for another PES Packet next:
00754   setParseState(PARSING_PES_PACKET);
00755 #ifdef DEBUG
00756   ++frameCount;
00757 #endif
00758  return acquiredStreamIdTag;
00759 }

Boolean MPEGProgramStreamParser::isSpecialStreamId ( unsigned char  stream_id  )  const [private]

Definition at line 506 of file MPEG1or2Demux.cpp.

References False, MPEG1or2Demux::fMPEGversion, fUsingDemux, private_stream_1, private_stream_2, RAW_PES, and True.

Referenced by parsePESPacket().

00506                                                  {
00507   if (stream_id == RAW_PES) return True; // hack
00508 
00509   if (fUsingDemux->fMPEGversion == 1) {
00510     return stream_id == private_stream_2;
00511   } else { // assume MPEG-2
00512     if (stream_id <= private_stream_2) {
00513       return stream_id != private_stream_1;
00514     } else if ((stream_id&0xF0) == 0xF0) {
00515       unsigned char lower4Bits = stream_id&0x0F;
00516       return lower4Bits <= 2 || lower4Bits == 0x8 || lower4Bits == 0xF;
00517     } else {
00518       return False;
00519     }
00520   }
00521 }

void StreamParser::flushInput (  )  [virtual, inherited]

Reimplemented in H264or5VideoStreamParser, MPEG1or2VideoStreamParser, and MPEG4VideoStreamParser.

Definition at line 28 of file StreamParser.cpp.

References StreamParser::fCurParserIndex, StreamParser::fRemainingUnparsedBits, StreamParser::fSavedParserIndex, StreamParser::fSavedRemainingUnparsedBits, and StreamParser::fTotNumValidBytes.

Referenced by MPEGVideoStreamFramer::flushInput(), MPEG4VideoStreamParser::flushInput(), MPEG1or2VideoStreamParser::flushInput(), MPEG1or2Demux::flushInput(), MPEG1or2AudioStreamFramer::flushInput(), H264or5VideoStreamParser::flushInput(), AC3AudioStreamFramer::flushInput(), and MatroskaFileParser::resetStateAfterSeeking().

void StreamParser::saveParserState (  )  [protected, inherited]

Definition at line 58 of file StreamParser.cpp.

References StreamParser::fCurParserIndex, StreamParser::fRemainingUnparsedBits, StreamParser::fSavedParserIndex, and StreamParser::fSavedRemainingUnparsedBits.

Referenced by OggFileParser::deliverPacketWithinPage(), MPEG1or2AudioStreamParser::parse(), OggFileParser::parseAndDeliverPage(), AC3AudioStreamParser::parseFrame(), OggFileParser::parseStartOfPage(), MPEGVideoStreamParser::setParseState(), setParseState(), MatroskaFileParser::setParseState(), and H263plusVideoStreamParser::setParseState().

void StreamParser::restoreSavedParserState (  )  [protected, virtual, inherited]

Reimplemented in H263plusVideoStreamParser, MatroskaFileParser, and MPEGVideoStreamParser.

Definition at line 63 of file StreamParser.cpp.

References StreamParser::fCurParserIndex, StreamParser::fRemainingUnparsedBits, StreamParser::fSavedParserIndex, and StreamParser::fSavedRemainingUnparsedBits.

Referenced by StreamParser::afterGettingBytes1(), parsePESPacket(), MPEGVideoStreamParser::restoreSavedParserState(), MatroskaFileParser::restoreSavedParserState(), and H263plusVideoStreamParser::restoreSavedParserState().

u_int32_t StreamParser::get4Bytes (  )  [inline, protected, inherited]

Definition at line 46 of file StreamParser.hh.

References StreamParser::fCurParserIndex, StreamParser::fRemainingUnparsedBits, and StreamParser::test4Bytes().

Referenced by AC3AudioStreamParser::parseFrame(), MPEG1or2VideoStreamParser::parseGOPHeader(), MPEG4VideoStreamParser::parseGroupOfVideoObjectPlane(), parsePackHeader(), parsePESPacket(), MPEG1or2VideoStreamParser::parsePictureHeader(), OggFileParser::parseStartOfPage(), MPEG4VideoStreamParser::parseVideoObjectLayer(), MPEG4VideoStreamParser::parseVideoObjectPlane(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), MPEG4VideoStreamParser::parseVisualObject(), MPEG4VideoStreamParser::parseVisualObjectSequence(), MPEGVideoStreamParser::saveToNextCode(), and MPEGVideoStreamParser::skipToNextCode().

00046                         { // byte-aligned; returned in big-endian order
00047     u_int32_t result = test4Bytes();
00048     fCurParserIndex += 4;
00049     fRemainingUnparsedBits = 0;
00050 
00051     return result;
00052   }

u_int32_t StreamParser::test4Bytes (  )  [inline, protected, inherited]

Definition at line 53 of file StreamParser.hh.

References StreamParser::ensureValidBytes(), and StreamParser::nextToParse().

Referenced by StreamParser::get4Bytes(), StreamParser::getBits(), MPEG1or2AudioStreamParser::parse(), H264or5VideoStreamParser::parse(), AC3AudioStreamParser::parseFrame(), MPEG1or2VideoStreamParser::parseGOPHeader(), parsePackHeader(), parsePESPacket(), OggFileParser::parseStartOfPage(), parseSystemHeader(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), and MPEG4VideoStreamParser::parseVisualObjectSequence().

00053                          { // as above, but doesn't advance ptr
00054     ensureValidBytes(4);
00055 
00056     unsigned char const* ptr = nextToParse();
00057     return (ptr[0]<<24)|(ptr[1]<<16)|(ptr[2]<<8)|ptr[3];
00058   }

u_int16_t StreamParser::get2Bytes (  )  [inline, protected, inherited]

Definition at line 60 of file StreamParser.hh.

References StreamParser::ensureValidBytes(), StreamParser::fCurParserIndex, StreamParser::fRemainingUnparsedBits, and StreamParser::nextToParse().

Referenced by parsePESPacket(), and parseSystemHeader().

00060                         {
00061     ensureValidBytes(2);
00062 
00063     unsigned char const* ptr = nextToParse();
00064     u_int16_t result = (ptr[0]<<8)|ptr[1];
00065 
00066     fCurParserIndex += 2;
00067     fRemainingUnparsedBits = 0;
00068 
00069     return result;
00070   }

u_int8_t StreamParser::get1Byte (  )  [inline, protected, inherited]

Definition at line 72 of file StreamParser.hh.

References StreamParser::curBank(), StreamParser::ensureValidBytes(), StreamParser::fCurParserIndex, and StreamParser::fRemainingUnparsedBits.

Referenced by MatroskaFileParser::deliverFrameWithinBlock(), H264or5VideoStreamParser::parse(), MatroskaFileParser::parseBlock(), MatroskaFileParser::parseEBMLNumber(), MatroskaFileParser::parseEBMLVal_binary(), MatroskaFileParser::parseEBMLVal_string(), MatroskaFileParser::parseEBMLVal_unsigned64(), MPEG1or2VideoStreamParser::parseGOPHeader(), H263plusVideoStreamParser::parseH263Frame(), parsePackHeader(), parsePESPacket(), OggFileParser::parseStartOfPage(), MPEG4VideoStreamParser::parseVideoObjectPlane(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), MPEG4VideoStreamParser::parseVisualObject(), MPEG4VideoStreamParser::parseVisualObjectSequence(), MPEGVideoStreamParser::saveToNextCode(), and MPEGVideoStreamParser::skipToNextCode().

00072                       { // byte-aligned
00073     ensureValidBytes(1);
00074     fRemainingUnparsedBits = 0;
00075     return curBank()[fCurParserIndex++];
00076   }

u_int8_t StreamParser::test1Byte (  )  [inline, protected, inherited]

Definition at line 77 of file StreamParser.hh.

References StreamParser::ensureValidBytes(), and StreamParser::nextToParse().

00077                        { // as above, but doesn't advance ptr
00078     ensureValidBytes(1);
00079     return nextToParse()[0];
00080   }

void StreamParser::getBytes ( u_int8_t *  to,
unsigned  numBytes 
) [inline, protected, inherited]

Definition at line 82 of file StreamParser.hh.

References StreamParser::fCurParserIndex, StreamParser::fRemainingUnparsedBits, and StreamParser::testBytes().

Referenced by MatroskaFileParser::deliverFrameBytes(), OggFileParser::deliverPacketWithinPage(), MPEG1or2AudioStreamParser::parse(), AC3AudioStreamParser::parseFrame(), MPEG4VideoStreamParser::parseGroupOfVideoObjectPlane(), H263plusVideoStreamParser::parseH263Frame(), OggFileParser::parseInitialPage(), and parsePESPacket().

00082                                                  {
00083     testBytes(to, numBytes);
00084     fCurParserIndex += numBytes;
00085     fRemainingUnparsedBits = 0;
00086   }

void StreamParser::testBytes ( u_int8_t *  to,
unsigned  numBytes 
) [inline, protected, inherited]

Definition at line 87 of file StreamParser.hh.

References StreamParser::ensureValidBytes(), and StreamParser::nextToParse().

Referenced by StreamParser::getBytes(), H264or5VideoStreamParser::parse(), and OggFileParser::parseInitialPage().

00087                                                   { // as above, but doesn't advance ptr
00088     ensureValidBytes(numBytes);
00089     memmove(to, nextToParse(), numBytes);
00090   }

void StreamParser::skipBytes ( unsigned  numBytes  )  [inline, protected, inherited]

Definition at line 91 of file StreamParser.hh.

References StreamParser::ensureValidBytes(), and StreamParser::fCurParserIndex.

Referenced by MatroskaFileParser::deliverFrameBytes(), MPEG1or2AudioStreamParser::parse(), H264or5VideoStreamParser::parse(), OggFileParser::parseAndDeliverPage(), MatroskaFileParser::parseBlock(), AC3AudioStreamParser::parseFrame(), OggFileParser::parseInitialPage(), parsePackHeader(), parsePESPacket(), OggFileParser::parseStartOfPage(), parseSystemHeader(), and MatroskaFileParser::skipRemainingHeaderBytes().

00091                                     {
00092     ensureValidBytes(numBytes);
00093     fCurParserIndex += numBytes;
00094   }

void StreamParser::skipBits ( unsigned  numBits  )  [protected, inherited]

Definition at line 68 of file StreamParser.cpp.

References StreamParser::ensureValidBytes(), StreamParser::fCurParserIndex, and StreamParser::fRemainingUnparsedBits.

Referenced by parsePackHeader().

00068                                             {
00069   if (numBits <= fRemainingUnparsedBits) {
00070     fRemainingUnparsedBits -= numBits;
00071   } else {
00072     numBits -= fRemainingUnparsedBits;
00073 
00074     unsigned numBytesToExamine = (numBits+7)/8; // round up
00075     ensureValidBytes(numBytesToExamine);
00076     fCurParserIndex += numBytesToExamine;
00077 
00078     fRemainingUnparsedBits = 8*numBytesToExamine - numBits;
00079   }
00080 }

unsigned StreamParser::getBits ( unsigned  numBits  )  [protected, inherited]

Definition at line 82 of file StreamParser.cpp.

References StreamParser::fCurParserIndex, StreamParser::fRemainingUnparsedBits, StreamParser::lastParsed(), and StreamParser::test4Bytes().

Referenced by LEBitVector::getBits(), parsePackHeader(), parsePESPacket(), and LEBitVector::skipBits().

00082                                                {
00083   if (numBits <= fRemainingUnparsedBits) {
00084     unsigned char lastByte = *lastParsed();
00085     lastByte >>= (fRemainingUnparsedBits - numBits);
00086     fRemainingUnparsedBits -= numBits;
00087 
00088     return (unsigned)lastByte &~ ((~0u)<<numBits);
00089   } else {
00090     unsigned char lastByte;
00091     if (fRemainingUnparsedBits > 0) {
00092       lastByte = *lastParsed();
00093     } else {
00094       lastByte = 0;
00095     }
00096 
00097     unsigned remainingBits = numBits - fRemainingUnparsedBits; // > 0
00098 
00099     // For simplicity, read the next 4 bytes, even though we might not
00100     // need all of them here:
00101     unsigned result = test4Bytes();
00102 
00103     result >>= (32 - remainingBits);
00104     result |= (lastByte << remainingBits);
00105     if (numBits < 32) result &=~ ((~0u)<<numBits);
00106 
00107     unsigned const numRemainingBytes = (remainingBits+7)/8;
00108     fCurParserIndex += numRemainingBytes;
00109     fRemainingUnparsedBits = 8*numRemainingBytes - remainingBits;
00110 
00111     return result;
00112   }
00113 }

unsigned StreamParser::curOffset (  )  const [inline, protected, inherited]

Definition at line 100 of file StreamParser.hh.

References StreamParser::fCurParserIndex.

Referenced by H264or5VideoStreamParser::parse(), MatroskaFileParser::parseBlock(), and parsePESPacket().

00100 { return fCurParserIndex; }

unsigned& StreamParser::totNumValidBytes (  )  [inline, protected, inherited]

Definition at line 102 of file StreamParser.hh.

References StreamParser::fTotNumValidBytes.

Referenced by H264or5VideoStreamParser::parse(), and AC3AudioStreamParser::testStreamCode().

00102 { return fTotNumValidBytes; }

Boolean StreamParser::haveSeenEOF (  )  const [inline, protected, inherited]

Definition at line 104 of file StreamParser.hh.

References StreamParser::fHaveSeenEOF.

Referenced by H264or5VideoStreamParser::parse().

00104 { return fHaveSeenEOF; }

unsigned StreamParser::bankSize (  )  const [protected, inherited]

Definition at line 115 of file StreamParser.cpp.

References BANK_SIZE.

Referenced by MatroskaFileParser::deliverFrameBytes(), and MatroskaFileParser::skipRemainingHeaderBytes().

00115                                       {
00116   return BANK_SIZE;
00117 }


Field Documentation

MPEG1or2Demux* MPEGProgramStreamParser::fUsingDemux [private]

Definition at line 56 of file MPEG1or2Demux.cpp.

Referenced by isSpecialStreamId(), parsePackHeader(), parsePESPacket(), and parseSystemHeader().

MPEGParseState MPEGProgramStreamParser::fCurrentParseState [private]

Definition at line 57 of file MPEG1or2Demux.cpp.

Referenced by parse(), and setParseState().


The documentation for this class was generated from the following file:
Generated on Tue Mar 25 14:40:17 2014 for live by  doxygen 1.5.2