MPEGVideoStreamParser Class Reference

#include <MPEGVideoStreamParser.hh>

Inheritance diagram for MPEGVideoStreamParser:

Inheritance graph
[legend]
Collaboration diagram for MPEGVideoStreamParser:

Collaboration graph
[legend]

Public Member Functions

 MPEGVideoStreamParser (MPEGVideoStreamFramer *usingSource, FramedSource *inputSource)
virtual ~MPEGVideoStreamParser ()
void registerReadInterest (unsigned char *to, unsigned maxSize)
virtual unsigned parse ()=0
unsigned numTruncatedBytes () const
virtual void flushInput ()

Protected Types

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

Protected Member Functions

void setParseState ()
void saveByte (u_int8_t byte)
void save4Bytes (u_int32_t word)
void saveToNextCode (u_int32_t &curWord)
void skipToNextCode (u_int32_t &curWord)
unsigned curFrameSize ()
void saveParserState ()
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

Protected Attributes

MPEGVideoStreamFramerfUsingSource
unsigned char * fStartOfFrame
unsigned char * fTo
unsigned char * fLimit
unsigned fNumTruncatedBytes
unsigned char * fSavedTo
unsigned fSavedNumTruncatedBytes

Private Member Functions

virtual void restoreSavedParserState ()

Detailed Description

Definition at line 33 of file MPEGVideoStreamParser.hh.


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

MPEGVideoStreamParser::MPEGVideoStreamParser ( MPEGVideoStreamFramer usingSource,
FramedSource inputSource 
)

virtual MPEGVideoStreamParser::~MPEGVideoStreamParser (  )  [virtual]


Member Function Documentation

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

virtual unsigned MPEGVideoStreamParser::parse (  )  [pure virtual]

unsigned MPEGVideoStreamParser::numTruncatedBytes (  )  const [inline]

Definition at line 45 of file MPEGVideoStreamParser.hh.

References fNumTruncatedBytes.

00045 { return fNumTruncatedBytes; }

void MPEGVideoStreamParser::setParseState (  )  [inline, protected]

Definition at line 48 of file MPEGVideoStreamParser.hh.

References fNumTruncatedBytes, fSavedNumTruncatedBytes, fSavedTo, fTo, and StreamParser::saveParserState().

00048                        {
00049     fSavedTo = fTo;
00050     fSavedNumTruncatedBytes = fNumTruncatedBytes;
00051     saveParserState();
00052   }

void MPEGVideoStreamParser::saveByte ( u_int8_t  byte  )  [inline, protected]

Definition at line 55 of file MPEGVideoStreamParser.hh.

References fLimit, fNumTruncatedBytes, and fTo.

Referenced by saveToNextCode().

00055                                {
00056     if (fTo >= fLimit) { // there's no space left
00057       ++fNumTruncatedBytes;
00058       return;
00059     }
00060 
00061     *fTo++ = byte;
00062   }

void MPEGVideoStreamParser::save4Bytes ( u_int32_t  word  )  [inline, protected]

Definition at line 64 of file MPEGVideoStreamParser.hh.

References fLimit, fNumTruncatedBytes, and fTo.

Referenced by saveToNextCode().

00064                                   {
00065     if (fTo+4 > fLimit) { // there's no space left
00066       fNumTruncatedBytes += 4;
00067       return;
00068     }
00069 
00070     *fTo++ = word>>24; *fTo++ = word>>16; *fTo++ = word>>8; *fTo++ = word;
00071   }

void MPEGVideoStreamParser::saveToNextCode ( u_int32_t &  curWord  )  [inline, protected]

Definition at line 74 of file MPEGVideoStreamParser.hh.

References StreamParser::get1Byte(), StreamParser::get4Bytes(), save4Bytes(), and saveByte().

00074                                           {
00075     saveByte(curWord>>24);
00076     curWord = (curWord<<8)|get1Byte();
00077     while ((curWord&0xFFFFFF00) != 0x00000100) {
00078       if ((unsigned)(curWord&0xFF) > 1) {
00079         // a sync word definitely doesn't begin anywhere in "curWord"
00080         save4Bytes(curWord);
00081         curWord = get4Bytes();
00082       } else {
00083         // a sync word might begin in "curWord", although not at its start
00084         saveByte(curWord>>24);
00085         unsigned char newByte = get1Byte();
00086         curWord = (curWord<<8)|newByte;
00087       }
00088     }
00089   }

void MPEGVideoStreamParser::skipToNextCode ( u_int32_t &  curWord  )  [inline, protected]

Definition at line 92 of file MPEGVideoStreamParser.hh.

References StreamParser::get1Byte(), and StreamParser::get4Bytes().

00092                                           {
00093     curWord = (curWord<<8)|get1Byte();
00094     while ((curWord&0xFFFFFF00) != 0x00000100) {
00095       if ((unsigned)(curWord&0xFF) > 1) {
00096         // a sync word definitely doesn't begin anywhere in "curWord"
00097         curWord = get4Bytes();
00098       } else {
00099         // a sync word might begin in "curWord", although not at its start
00100         unsigned char newByte = get1Byte();
00101         curWord = (curWord<<8)|newByte;
00102       }
00103     }
00104   }

unsigned MPEGVideoStreamParser::curFrameSize (  )  [inline, protected]

Definition at line 114 of file MPEGVideoStreamParser.hh.

References fStartOfFrame, and fTo.

00114 { return fTo - fStartOfFrame; }

virtual void MPEGVideoStreamParser::restoreSavedParserState (  )  [private, virtual]

Reimplemented from StreamParser.

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

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

Referenced by setParseState().

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 saveToNextCode(), and 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().

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

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 saveToNextCode(), and 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().

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

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.

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

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

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

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

Definition at line 100 of file StreamParser.hh.

References StreamParser::fCurParserIndex.

00100 { return fCurParserIndex; }

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

Definition at line 102 of file StreamParser.hh.

References StreamParser::fTotNumValidBytes.

00102 { return fTotNumValidBytes; }

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

Definition at line 104 of file StreamParser.hh.

References StreamParser::fHaveSeenEOF.

00104 { return fHaveSeenEOF; }

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


Field Documentation

MPEGVideoStreamFramer* MPEGVideoStreamParser::fUsingSource [protected]

Definition at line 107 of file MPEGVideoStreamParser.hh.

unsigned char* MPEGVideoStreamParser::fStartOfFrame [protected]

Definition at line 110 of file MPEGVideoStreamParser.hh.

Referenced by curFrameSize().

unsigned char* MPEGVideoStreamParser::fTo [protected]

Definition at line 111 of file MPEGVideoStreamParser.hh.

Referenced by curFrameSize(), save4Bytes(), saveByte(), and setParseState().

unsigned char* MPEGVideoStreamParser::fLimit [protected]

Definition at line 112 of file MPEGVideoStreamParser.hh.

Referenced by save4Bytes(), and saveByte().

unsigned MPEGVideoStreamParser::fNumTruncatedBytes [protected]

Definition at line 113 of file MPEGVideoStreamParser.hh.

Referenced by numTruncatedBytes(), save4Bytes(), saveByte(), and setParseState().

unsigned char* MPEGVideoStreamParser::fSavedTo [protected]

Definition at line 115 of file MPEGVideoStreamParser.hh.

Referenced by setParseState().

unsigned MPEGVideoStreamParser::fSavedNumTruncatedBytes [protected]

Definition at line 116 of file MPEGVideoStreamParser.hh.

Referenced by setParseState().


The documentation for this class was generated from the following file:
Generated on Sun Jul 13 05:12:00 2014 for live by  doxygen 1.5.2