live
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes
MPEGVideoStreamParser Class Referenceabstract

#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_int16_t test2Bytes ()
 
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 ()
 
unsigned char * curBank ()
 
unsigned char * nextToParse ()
 
unsigned char * lastParsed ()
 
void ensureValidBytes (unsigned numBytesNeeded)
 
void ensureValidBytes1 (unsigned numBytesNeeded)
 
void afterGettingBytes1 (unsigned numBytesRead, struct timeval presentationTime)
 
void onInputClosure1 ()
 

Static Private Member Functions

static void afterGettingBytes (void *clientData, unsigned numBytesRead, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds)
 
static void onInputClosure (void *clientData)
 

Private Attributes

FramedSourcefInputSource
 
FramedSource::onCloseFuncfClientOnInputCloseFunc
 
void * fClientOnInputCloseClientData
 
clientContinueFuncfClientContinueFunc
 
void * fClientContinueClientData
 
unsigned char * fBank [2]
 
unsigned char fCurBankNum
 
unsigned char * fCurBank
 
unsigned fSavedParserIndex
 
unsigned char fSavedRemainingUnparsedBits
 
unsigned fCurParserIndex
 
unsigned char fRemainingUnparsedBits
 
unsigned fTotNumValidBytes
 
Boolean fHaveSeenEOF
 
struct timeval fLastSeenPresentationTime
 

Detailed Description

Definition at line 33 of file MPEGVideoStreamParser.hh.

Member Typedef Documentation

◆ clientContinueFunc

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

Definition at line 33 of file StreamParser.hh.

Constructor & Destructor Documentation

◆ MPEGVideoStreamParser()

MPEGVideoStreamParser::MPEGVideoStreamParser ( MPEGVideoStreamFramer usingSource,
FramedSource inputSource 
)

◆ ~MPEGVideoStreamParser()

virtual MPEGVideoStreamParser::~MPEGVideoStreamParser ( )
virtual

Member Function Documentation

◆ afterGettingBytes()

static void StreamParser::afterGettingBytes ( void *  clientData,
unsigned  numBytesRead,
unsigned  numTruncatedBytes,
struct timeval  presentationTime,
unsigned  durationInMicroseconds 
)
staticprivateinherited

◆ afterGettingBytes1()

void StreamParser::afterGettingBytes1 ( unsigned  numBytesRead,
struct timeval  presentationTime 
)
privateinherited

◆ bankSize()

unsigned StreamParser::bankSize ( ) const
protectedinherited

◆ curBank()

unsigned char* StreamParser::curBank ( )
inlineprivateinherited

Definition at line 116 of file StreamParser.hh.

116 { return fCurBank; }
unsigned char * fCurBank

References StreamParser::fCurBank.

Referenced by StreamParser::get1Byte(), StreamParser::lastParsed(), and StreamParser::nextToParse().

◆ curFrameSize()

unsigned MPEGVideoStreamParser::curFrameSize ( )
inlineprotected

Definition at line 114 of file MPEGVideoStreamParser.hh.

114 { return fTo - fStartOfFrame; }

References fStartOfFrame, and fTo.

◆ curOffset()

unsigned StreamParser::curOffset ( ) const
inlineprotectedinherited

Definition at line 107 of file StreamParser.hh.

107 { return fCurParserIndex; }
unsigned fCurParserIndex

References StreamParser::fCurParserIndex.

◆ ensureValidBytes()

void StreamParser::ensureValidBytes ( unsigned  numBytesNeeded)
inlineprivateinherited

Definition at line 121 of file StreamParser.hh.

121  {
122  // common case: inlined:
123  if (fCurParserIndex + numBytesNeeded <= fTotNumValidBytes) return;
124 
125  ensureValidBytes1(numBytesNeeded);
126  }
unsigned fTotNumValidBytes
void ensureValidBytes1(unsigned numBytesNeeded)

References StreamParser::ensureValidBytes1(), StreamParser::fCurParserIndex, and StreamParser::fTotNumValidBytes.

Referenced by StreamParser::get1Byte(), StreamParser::get2Bytes(), StreamParser::skipBytes(), StreamParser::test1Byte(), StreamParser::test2Bytes(), StreamParser::test4Bytes(), and StreamParser::testBytes().

◆ ensureValidBytes1()

void StreamParser::ensureValidBytes1 ( unsigned  numBytesNeeded)
privateinherited

◆ flushInput()

virtual void StreamParser::flushInput ( )
virtualinherited

◆ get1Byte()

u_int8_t StreamParser::get1Byte ( )
inlineprotectedinherited

Definition at line 79 of file StreamParser.hh.

79  { // byte-aligned
82  return curBank()[fCurParserIndex++];
83  }
unsigned char * curBank()
void ensureValidBytes(unsigned numBytesNeeded)
unsigned char fRemainingUnparsedBits

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

Referenced by saveToNextCode(), and skipToNextCode().

◆ get2Bytes()

u_int16_t StreamParser::get2Bytes ( )
inlineprotectedinherited

Definition at line 60 of file StreamParser.hh.

60  {
62 
63  unsigned char const* ptr = nextToParse();
64  u_int16_t result = (ptr[0]<<8)|ptr[1];
65 
66  fCurParserIndex += 2;
68 
69  return result;
70  }
unsigned char * nextToParse()

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

◆ get4Bytes()

u_int32_t StreamParser::get4Bytes ( )
inlineprotectedinherited

Definition at line 46 of file StreamParser.hh.

46  { // byte-aligned; returned in big-endian order
47  u_int32_t result = test4Bytes();
48  fCurParserIndex += 4;
50 
51  return result;
52  }
u_int32_t test4Bytes()
Definition: StreamParser.hh:53

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

Referenced by saveToNextCode(), and skipToNextCode().

◆ getBits()

unsigned StreamParser::getBits ( unsigned  numBits)
protectedinherited

◆ getBytes()

void StreamParser::getBytes ( u_int8_t *  to,
unsigned  numBytes 
)
inlineprotectedinherited

Definition at line 89 of file StreamParser.hh.

89  {
90  testBytes(to, numBytes);
91  fCurParserIndex += numBytes;
93  }
void testBytes(u_int8_t *to, unsigned numBytes)
Definition: StreamParser.hh:94

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

◆ haveSeenEOF()

Boolean StreamParser::haveSeenEOF ( ) const
inlineprotectedinherited

Definition at line 111 of file StreamParser.hh.

111 { return fHaveSeenEOF; }
Boolean fHaveSeenEOF

References StreamParser::fHaveSeenEOF.

◆ lastParsed()

unsigned char* StreamParser::lastParsed ( )
inlineprivateinherited

Definition at line 118 of file StreamParser.hh.

118 { return &curBank()[fCurParserIndex-1]; }

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

◆ nextToParse()

unsigned char* StreamParser::nextToParse ( )
inlineprivateinherited

◆ numTruncatedBytes()

unsigned MPEGVideoStreamParser::numTruncatedBytes ( ) const
inline

Definition at line 45 of file MPEGVideoStreamParser.hh.

45 { return fNumTruncatedBytes; }

References fNumTruncatedBytes.

◆ onInputClosure()

static void StreamParser::onInputClosure ( void *  clientData)
staticprivateinherited

◆ onInputClosure1()

void StreamParser::onInputClosure1 ( )
privateinherited

◆ parse()

virtual unsigned MPEGVideoStreamParser::parse ( )
pure virtual

◆ registerReadInterest()

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

◆ restoreSavedParserState()

virtual void MPEGVideoStreamParser::restoreSavedParserState ( )
privatevirtual

Reimplemented from StreamParser.

◆ save4Bytes()

void MPEGVideoStreamParser::save4Bytes ( u_int32_t  word)
inlineprotected

Definition at line 64 of file MPEGVideoStreamParser.hh.

64  {
65  if (fTo+4 > fLimit) { // there's no space left
66  fNumTruncatedBytes += 4;
67  return;
68  }
69 
70  *fTo++ = word>>24; *fTo++ = word>>16; *fTo++ = word>>8; *fTo++ = word;
71  }

References fLimit, fNumTruncatedBytes, and fTo.

Referenced by saveToNextCode().

◆ saveByte()

void MPEGVideoStreamParser::saveByte ( u_int8_t  byte)
inlineprotected

Definition at line 55 of file MPEGVideoStreamParser.hh.

55  {
56  if (fTo >= fLimit) { // there's no space left
58  return;
59  }
60 
61  *fTo++ = byte;
62  }

References fLimit, fNumTruncatedBytes, and fTo.

Referenced by saveToNextCode().

◆ saveParserState()

void StreamParser::saveParserState ( )
protectedinherited

Referenced by setParseState().

◆ saveToNextCode()

void MPEGVideoStreamParser::saveToNextCode ( u_int32_t &  curWord)
inlineprotected

Definition at line 74 of file MPEGVideoStreamParser.hh.

74  {
75  saveByte(curWord>>24);
76  curWord = (curWord<<8)|get1Byte();
77  while ((curWord&0xFFFFFF00) != 0x00000100) {
78  if ((unsigned)(curWord&0xFF) > 1) {
79  // a sync word definitely doesn't begin anywhere in "curWord"
80  save4Bytes(curWord);
81  curWord = get4Bytes();
82  } else {
83  // a sync word might begin in "curWord", although not at its start
84  saveByte(curWord>>24);
85  unsigned char newByte = get1Byte();
86  curWord = (curWord<<8)|newByte;
87  }
88  }
89  }
void save4Bytes(u_int32_t word)
void saveByte(u_int8_t byte)
u_int8_t get1Byte()
Definition: StreamParser.hh:79
u_int32_t get4Bytes()
Definition: StreamParser.hh:46

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

◆ setParseState()

void MPEGVideoStreamParser::setParseState ( )
inlineprotected

◆ skipBits()

void StreamParser::skipBits ( unsigned  numBits)
protectedinherited

◆ skipBytes()

void StreamParser::skipBytes ( unsigned  numBytes)
inlineprotectedinherited

Definition at line 98 of file StreamParser.hh.

98  {
99  ensureValidBytes(numBytes);
100  fCurParserIndex += numBytes;
101  }

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

◆ skipToNextCode()

void MPEGVideoStreamParser::skipToNextCode ( u_int32_t &  curWord)
inlineprotected

Definition at line 92 of file MPEGVideoStreamParser.hh.

92  {
93  curWord = (curWord<<8)|get1Byte();
94  while ((curWord&0xFFFFFF00) != 0x00000100) {
95  if ((unsigned)(curWord&0xFF) > 1) {
96  // a sync word definitely doesn't begin anywhere in "curWord"
97  curWord = get4Bytes();
98  } else {
99  // a sync word might begin in "curWord", although not at its start
100  unsigned char newByte = get1Byte();
101  curWord = (curWord<<8)|newByte;
102  }
103  }
104  }

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

◆ test1Byte()

u_int8_t StreamParser::test1Byte ( )
inlineprotectedinherited

Definition at line 84 of file StreamParser.hh.

84  { // as above, but doesn't advance ptr
86  return nextToParse()[0];
87  }

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

◆ test2Bytes()

u_int16_t StreamParser::test2Bytes ( )
inlineprotectedinherited

Definition at line 71 of file StreamParser.hh.

71  {
73 
74  unsigned char const* ptr = nextToParse();
75  return (ptr[0]<<8)|ptr[1];
76  }

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

◆ test4Bytes()

u_int32_t StreamParser::test4Bytes ( )
inlineprotectedinherited

Definition at line 53 of file StreamParser.hh.

53  { // as above, but doesn't advance ptr
55 
56  unsigned char const* ptr = nextToParse();
57  return (ptr[0]<<24)|(ptr[1]<<16)|(ptr[2]<<8)|ptr[3];
58  }

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

Referenced by StreamParser::get4Bytes().

◆ testBytes()

void StreamParser::testBytes ( u_int8_t *  to,
unsigned  numBytes 
)
inlineprotectedinherited

Definition at line 94 of file StreamParser.hh.

94  { // as above, but doesn't advance ptr
95  ensureValidBytes(numBytes);
96  memmove(to, nextToParse(), numBytes);
97  }

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

Referenced by StreamParser::getBytes().

◆ totNumValidBytes()

unsigned& StreamParser::totNumValidBytes ( )
inlineprotectedinherited

Definition at line 109 of file StreamParser.hh.

109 { return fTotNumValidBytes; }

References StreamParser::fTotNumValidBytes.

Field Documentation

◆ fBank

unsigned char* StreamParser::fBank[2]
privateinherited

Definition at line 146 of file StreamParser.hh.

◆ fClientContinueClientData

void* StreamParser::fClientContinueClientData
privateinherited

Definition at line 143 of file StreamParser.hh.

◆ fClientContinueFunc

clientContinueFunc* StreamParser::fClientContinueFunc
privateinherited

Definition at line 142 of file StreamParser.hh.

◆ fClientOnInputCloseClientData

void* StreamParser::fClientOnInputCloseClientData
privateinherited

Definition at line 141 of file StreamParser.hh.

◆ fClientOnInputCloseFunc

FramedSource::onCloseFunc* StreamParser::fClientOnInputCloseFunc
privateinherited

Definition at line 140 of file StreamParser.hh.

◆ fCurBank

unsigned char* StreamParser::fCurBank
privateinherited

Definition at line 148 of file StreamParser.hh.

Referenced by StreamParser::curBank().

◆ fCurBankNum

unsigned char StreamParser::fCurBankNum
privateinherited

Definition at line 147 of file StreamParser.hh.

◆ fCurParserIndex

unsigned StreamParser::fCurParserIndex
privateinherited

◆ fHaveSeenEOF

Boolean StreamParser::fHaveSeenEOF
privateinherited

Definition at line 162 of file StreamParser.hh.

Referenced by StreamParser::haveSeenEOF().

◆ fInputSource

FramedSource* StreamParser::fInputSource
privateinherited

Definition at line 139 of file StreamParser.hh.

◆ fLastSeenPresentationTime

struct timeval StreamParser::fLastSeenPresentationTime
privateinherited

Definition at line 162 of file StreamParser.hh.

◆ fLimit

unsigned char* MPEGVideoStreamParser::fLimit
protected

Definition at line 112 of file MPEGVideoStreamParser.hh.

Referenced by save4Bytes(), and saveByte().

◆ fNumTruncatedBytes

unsigned MPEGVideoStreamParser::fNumTruncatedBytes
protected

Definition at line 113 of file MPEGVideoStreamParser.hh.

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

◆ fRemainingUnparsedBits

unsigned char StreamParser::fRemainingUnparsedBits
privateinherited

◆ fSavedNumTruncatedBytes

unsigned MPEGVideoStreamParser::fSavedNumTruncatedBytes
protected

Definition at line 116 of file MPEGVideoStreamParser.hh.

Referenced by setParseState().

◆ fSavedParserIndex

unsigned StreamParser::fSavedParserIndex
privateinherited

Definition at line 151 of file StreamParser.hh.

◆ fSavedRemainingUnparsedBits

unsigned char StreamParser::fSavedRemainingUnparsedBits
privateinherited

Definition at line 152 of file StreamParser.hh.

◆ fSavedTo

unsigned char* MPEGVideoStreamParser::fSavedTo
protected

Definition at line 115 of file MPEGVideoStreamParser.hh.

Referenced by setParseState().

◆ fStartOfFrame

unsigned char* MPEGVideoStreamParser::fStartOfFrame
protected

Definition at line 110 of file MPEGVideoStreamParser.hh.

Referenced by curFrameSize().

◆ fTo

unsigned char* MPEGVideoStreamParser::fTo
protected

Definition at line 111 of file MPEGVideoStreamParser.hh.

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

◆ fTotNumValidBytes

unsigned StreamParser::fTotNumValidBytes
privateinherited

◆ fUsingSource

MPEGVideoStreamFramer* MPEGVideoStreamParser::fUsingSource
protected

Definition at line 107 of file MPEGVideoStreamParser.hh.


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