MPEG1or2AudioStreamParser Class Reference

Inheritance diagram for MPEG1or2AudioStreamParser:

Inheritance graph
[legend]
Collaboration diagram for MPEG1or2AudioStreamParser:

Collaboration graph
[legend]

Public Member Functions

 MPEG1or2AudioStreamParser (MPEG1or2AudioStreamFramer *usingSource, FramedSource *inputSource)
virtual ~MPEG1or2AudioStreamParser ()
unsigned parse (unsigned &numTruncatedBytes)
void registerReadInterest (unsigned char *to, unsigned maxSize)
MP3FrameParams const & currentFrame () const
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 Attributes

unsigned char * fTo
unsigned fMaxSize
MP3FrameParams fCurrentFrame

Detailed Description

Definition at line 28 of file MPEG1or2AudioStreamFramer.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

MPEG1or2AudioStreamParser::MPEG1or2AudioStreamParser ( MPEG1or2AudioStreamFramer usingSource,
FramedSource inputSource 
)

Definition at line 164 of file MPEG1or2AudioStreamFramer.cpp.

00166   : StreamParser(inputSource, FramedSource::handleClosure, usingSource,
00167                  &MPEG1or2AudioStreamFramer::continueReadProcessing, usingSource) {
00168 }

MPEG1or2AudioStreamParser::~MPEG1or2AudioStreamParser (  )  [virtual]

Definition at line 170 of file MPEG1or2AudioStreamFramer.cpp.

00170                                                       {
00171 }


Member Function Documentation

unsigned MPEG1or2AudioStreamParser::parse ( unsigned &  numTruncatedBytes  ) 

Definition at line 179 of file MPEG1or2AudioStreamFramer.cpp.

References fCurrentFrame, fMaxSize, MP3FrameParams::frameSize, frameSize, fTo, StreamParser::getBytes(), MP3FrameParams::hdr, StreamParser::saveParserState(), MP3FrameParams::setParamsFromHeader(), StreamParser::skipBytes(), and StreamParser::test4Bytes().

Referenced by MPEG1or2AudioStreamFramer::continueReadProcessing().

00179                                                                      {
00180   try {
00181     saveParserState();
00182 
00183     // We expect a MPEG audio header (first 11 bits set to 1) at the start:
00184     while (((fCurrentFrame.hdr = test4Bytes())&0xFFE00000) != 0xFFE00000) {
00185       skipBytes(1);
00186       saveParserState();
00187     }
00188 
00189     fCurrentFrame.setParamsFromHeader();
00190 
00191     // Copy the frame to the requested destination:
00192     unsigned frameSize = fCurrentFrame.frameSize + 4; // include header
00193     if (frameSize > fMaxSize) {
00194       numTruncatedBytes = frameSize - fMaxSize;
00195       frameSize = fMaxSize;
00196     } else {
00197       numTruncatedBytes = 0;
00198     }
00199 
00200     getBytes(fTo, frameSize);
00201     skipBytes(numTruncatedBytes);
00202 
00203     return frameSize;
00204   } catch (int /*e*/) {
00205 #ifdef DEBUG
00206     fprintf(stderr, "MPEG1or2AudioStreamParser::parse() EXCEPTION (This is normal behavior - *not* an error)\n");
00207 #endif
00208     return 0;  // the parsing got interrupted
00209   }
00210 }

void MPEG1or2AudioStreamParser::registerReadInterest ( unsigned char *  to,
unsigned  maxSize 
)

Definition at line 173 of file MPEG1or2AudioStreamFramer.cpp.

References fMaxSize, and fTo.

Referenced by MPEG1or2AudioStreamFramer::doGetNextFrame().

00174                                                                    {
00175   fTo = to;
00176   fMaxSize = maxSize;
00177 }

MP3FrameParams const& MPEG1or2AudioStreamParser::currentFrame (  )  const [inline]

Definition at line 40 of file MPEG1or2AudioStreamFramer.cpp.

References fCurrentFrame.

Referenced by MPEG1or2AudioStreamFramer::currentFramePlayTime().

00040 { return fCurrentFrame; }

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(), parse(), OggFileParser::parseAndDeliverPage(), AC3AudioStreamParser::parseFrame(), OggFileParser::parseStartOfPage(), MPEGVideoStreamParser::setParseState(), MPEGProgramStreamParser::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(), MPEGProgramStreamParser::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(), MPEGProgramStreamParser::parsePackHeader(), MPEGProgramStreamParser::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(), parse(), H264or5VideoStreamParser::parse(), AC3AudioStreamParser::parseFrame(), MPEG1or2VideoStreamParser::parseGOPHeader(), MPEGProgramStreamParser::parsePackHeader(), MPEGProgramStreamParser::parsePESPacket(), OggFileParser::parseStartOfPage(), MPEGProgramStreamParser::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 MPEGProgramStreamParser::parsePESPacket(), and MPEGProgramStreamParser::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(), MPEGProgramStreamParser::parsePackHeader(), MPEGProgramStreamParser::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(), parse(), AC3AudioStreamParser::parseFrame(), MPEG4VideoStreamParser::parseGroupOfVideoObjectPlane(), H263plusVideoStreamParser::parseH263Frame(), OggFileParser::parseInitialPage(), and MPEGProgramStreamParser::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(), parse(), H264or5VideoStreamParser::parse(), OggFileParser::parseAndDeliverPage(), MatroskaFileParser::parseBlock(), AC3AudioStreamParser::parseFrame(), OggFileParser::parseInitialPage(), MPEGProgramStreamParser::parsePackHeader(), MPEGProgramStreamParser::parsePESPacket(), OggFileParser::parseStartOfPage(), MPEGProgramStreamParser::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 MPEGProgramStreamParser::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(), MPEGProgramStreamParser::parsePackHeader(), MPEGProgramStreamParser::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 MPEGProgramStreamParser::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

unsigned char* MPEG1or2AudioStreamParser::fTo [private]

Definition at line 43 of file MPEG1or2AudioStreamFramer.cpp.

Referenced by parse(), and registerReadInterest().

unsigned MPEG1or2AudioStreamParser::fMaxSize [private]

Definition at line 44 of file MPEG1or2AudioStreamFramer.cpp.

Referenced by parse(), and registerReadInterest().

MP3FrameParams MPEG1or2AudioStreamParser::fCurrentFrame [private]

Definition at line 47 of file MPEG1or2AudioStreamFramer.cpp.

Referenced by currentFrame(), and parse().


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