H263plusVideoStreamParser Class Reference

#include <H263plusVideoStreamParser.hh>

Inheritance diagram for H263plusVideoStreamParser:

Inheritance graph
[legend]
Collaboration diagram for H263plusVideoStreamParser:

Collaboration graph
[legend]

Public Member Functions

 H263plusVideoStreamParser (class H263plusVideoStreamFramer *usingSource, FramedSource *inputSource)
virtual ~H263plusVideoStreamParser ()
void registerReadInterest (unsigned char *to, unsigned maxSize)
unsigned parse (u_int64_t &currentDuration)
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 saveParserState ()
u_int32_t get4Bytes ()
u_int32_t test4Bytes ()
u_int16_t get2Bytes ()
u_int8_t get1Byte ()
u_int8_t test1Byte (unsigned numBytes)
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

H263plusVideoStreamFramerfUsingSource
unsigned char * fTo
unsigned fMaxSize
unsigned char * fStartOfFrame
unsigned char * fSavedTo
unsigned char * fLimit
unsigned fNumTruncatedBytes
unsigned fSavedNumTruncatedBytes

Private Member Functions

int parseH263Frame ()
bool ParseShortHeader (u_int8_t *headerBuffer, H263INFO *outputInfoStruct)
void GetMaxBitrate (MaxBitrate_CTX *ctx, u_int32_t frameSize, u_int8_t frameTRDiff)
u_int64_t CalculateDuration (u_int8_t trDiff)
bool GetWidthAndHeight (u_int8_t fmt, u_int16_t *width, u_int16_t *height)
u_int8_t GetTRDifference (u_int8_t nextTR, u_int8_t currentTR)
virtual void restoreSavedParserState ()

Private Attributes

H263INFO fNextInfo
H263INFO fCurrentInfo
MaxBitrate_CTX fMaxBitrateCtx
char fStates [3][256]
u_int8_t fNextHeader [H263_REQUIRE_HEADER_SIZE_BYTES]
u_int32_t fnextTR
u_int64_t fcurrentPT

Detailed Description

Definition at line 71 of file H263plusVideoStreamParser.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

H263plusVideoStreamParser::H263plusVideoStreamParser ( class H263plusVideoStreamFramer usingSource,
FramedSource inputSource 
)

Definition at line 28 of file H263plusVideoStreamParser.cpp.

References fCurrentInfo, fMaxBitrateCtx, fNextHeader, fNextInfo, fStates, and H263_REQUIRE_HEADER_SIZE_BYTES.

00031                               : StreamParser(inputSource,
00032                                    FramedSource::handleClosure,
00033                                    usingSource,
00034                                    &H263plusVideoStreamFramer::continueReadProcessing,
00035                                    usingSource),
00036                                 fUsingSource(usingSource),
00037                                 fnextTR(0),
00038                                 fcurrentPT(0)
00039 {
00040    memset(fStates, 0, sizeof(fStates));
00041    memset(&fNextInfo, 0, sizeof(fNextInfo));
00042    memset(&fCurrentInfo, 0, sizeof(fCurrentInfo));
00043    memset(&fMaxBitrateCtx, 0, sizeof(fMaxBitrateCtx));
00044    memset(fNextHeader,0, H263_REQUIRE_HEADER_SIZE_BYTES);
00045 }

H263plusVideoStreamParser::~H263plusVideoStreamParser (  )  [virtual]

Definition at line 48 of file H263plusVideoStreamParser.cpp.

00049 {
00050 }


Member Function Documentation

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

Definition at line 70 of file H263plusVideoStreamParser.cpp.

References fLimit, fMaxSize, fNumTruncatedBytes, fSavedNumTruncatedBytes, fSavedTo, fStartOfFrame, and fTo.

Referenced by H263plusVideoStreamFramer::doGetNextFrame().

00073 {
00074    fStartOfFrame = fTo = fSavedTo = to;
00075    fLimit = to + maxSize;
00076    fMaxSize = maxSize;
00077    fNumTruncatedBytes = fSavedNumTruncatedBytes = 0;
00078 }

unsigned H263plusVideoStreamParser::parse ( u_int64_t &  currentDuration  ) 

Definition at line 82 of file H263plusVideoStreamParser.cpp.

References CalculateDuration(), fCurrentInfo, fNextInfo, frameSize, fTo, GetTRDifference(), parseH263Frame(), ParseShortHeader(), setParseState(), and _H263INFO::tr.

Referenced by H263plusVideoStreamFramer::continueReadProcessing().

00083 {
00084 
00085 //   u_int8_t       frameBuffer[H263_BUFFER_SIZE]; // The input buffer
00086                  // Pointer which tells LoadNextH263Object where to read data to
00087 //   u_int8_t*      pFrameBuffer = fTo + H263_REQUIRE_HEADER_SIZE_BYTES;
00088    u_int32_t      frameSize;        // The current frame size
00089                                 // Pointer to receive address of the header data
00090 //   u_int8_t*      pCurrentHeader;// = pFrameBuffer;
00091 //   u_int64_t      currentDuration;  // The current frame's duration
00092    u_int8_t       trDifference;     // The current TR difference
00093                                    // The previous TR difference
00094 //   u_int8_t       prevTrDifference = H263_BASIC_FRAME_RATE;
00095 //   u_int64_t      totalDuration = 0;// Duration accumulator
00096 //   u_int64_t      avgBitrate;       // Average bitrate
00097 //   u_int64_t      totalBytes = 0;   // Size accumulator
00098 
00099 
00100    try    // The get data routines of the class FramedFilter returns an error when
00101    {      // the buffer is empty. This occurs at the beginning and at the end of the file.
00102       fCurrentInfo = fNextInfo;
00103 
00104       // Parse 1 frame
00105       // For the first time, only the first frame's header is returned.
00106       // The second time the full first frame is returned
00107       frameSize = parseH263Frame();
00108 
00109       currentDuration = 0;
00110       if ((frameSize > 0)){
00111          // We were able to acquire a frame from the input.
00112 
00113          // Parse the returned frame header (if any)
00114          if (!ParseShortHeader(fTo, &fNextInfo)) {
00115 #ifdef DEBUG
00116            fprintf(stderr,"H263plusVideoStreamParser: Fatal error\n");
00117 #endif
00118          }
00119 
00120          trDifference = GetTRDifference(fNextInfo.tr, fCurrentInfo.tr);
00121 
00122          // calculate the current frame duration
00123          currentDuration = CalculateDuration(trDifference);
00124 
00125          // Accumulate the frame's size and duration for avgBitrate calculation
00126          //totalDuration += currentDuration;
00127          //totalBytes += frameSize;
00128          //  If needed, recalculate bitrate information
00129          //    if (h263Bitrates)
00130          //GetMaxBitrate(&fMaxBitrateCtx, frameSize, prevTrDifference);
00131          //prevTrDifference = trDifference;
00132 
00133          setParseState(); // Needed for the parsing process in StreamParser
00134       }
00135    } catch (int /*e*/) {
00136 #ifdef DEBUG
00137       fprintf(stderr, "H263plusVideoStreamParser::parse() EXCEPTION (This is normal behavior - *not* an error)\n");
00138 #endif
00139       frameSize=0;
00140    }
00141 
00142    return frameSize;
00143 }

unsigned H263plusVideoStreamParser::numTruncatedBytes (  )  const [inline]

Definition at line 82 of file H263plusVideoStreamParser.hh.

References fNumTruncatedBytes.

00082 { return fNumTruncatedBytes; }  // The number of truncated bytes (if any)

void H263plusVideoStreamParser::setParseState (  )  [protected]

Definition at line 61 of file H263plusVideoStreamParser.cpp.

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

Referenced by parse().

00062 {
00063    fSavedTo = fTo;
00064    fSavedNumTruncatedBytes = fNumTruncatedBytes;
00065    saveParserState();  // Needed for the parsing process in StreamParser
00066 }

int H263plusVideoStreamParser::parseH263Frame (  )  [private]

Definition at line 166 of file H263plusVideoStreamParser.cpp.

References ADDITIONAL_BYTES_NEEDED, fMaxSize, fNextHeader, fStates, fTo, StreamParser::get1Byte(), StreamParser::getBytes(), H263_REQUIRE_HEADER_SIZE_BYTES, and H263_STARTCODE_SIZE_BYTES.

Referenced by parse().

00167 {
00168    char     row = 0;
00169    u_int8_t * bufferIndex = fTo;
00170    // The buffer end which will allow the loop to leave place for
00171    // the additionalBytesNeeded
00172    u_int8_t * bufferEnd = fTo + fMaxSize - ADDITIONAL_BYTES_NEEDED - 1;
00173 
00174    memcpy(fTo, fNextHeader, H263_REQUIRE_HEADER_SIZE_BYTES);
00175    bufferIndex += H263_REQUIRE_HEADER_SIZE_BYTES;
00176 
00177 
00178    // The state table and the following loop implements a state machine enabling
00179    // us to read bytes from the file until (and inclusing) the requested
00180    // start code (00 00 8X) is found
00181 
00182    // Initialize the states array, if it hasn't been initialized yet...
00183    if (!fStates[0][0]) {
00184       // One 00 was read
00185       fStates[0][0] = 1;
00186       // Two sequential 0x00 ware read
00187       fStates[1][0] = fStates[2][0] = 2;
00188       // A full start code was read
00189       fStates[2][128] = fStates[2][129] = fStates[2][130] = fStates[2][131] = -1;
00190    }
00191 
00192    // Read data from file into the output buffer until either a start code
00193    // is found, or the end of file has been reached.
00194    do {
00195       *bufferIndex = get1Byte();
00196    } while ((bufferIndex < bufferEnd) &&                    // We have place in the buffer
00197             ((row = fStates[(unsigned char)row][*(bufferIndex++)]) != -1)); // Start code was not found
00198 
00199    if (row != -1) {
00200       fprintf(stderr, "%s: Buffer too small (%lu)\n",
00201          "h263reader:", bufferEnd - fTo + ADDITIONAL_BYTES_NEEDED);
00202       return 0;
00203    }
00204 
00205    // Cool ... now we have a start code
00206    // Now we just have to read the additionalBytesNeeded
00207    getBytes(bufferIndex, ADDITIONAL_BYTES_NEEDED);
00208    memcpy(fNextHeader, bufferIndex - H263_STARTCODE_SIZE_BYTES, H263_REQUIRE_HEADER_SIZE_BYTES);
00209 
00210         int sz = bufferIndex - fTo - H263_STARTCODE_SIZE_BYTES;
00211 
00212    if (sz == 5) // first frame
00213       memcpy(fTo, fTo+H263_REQUIRE_HEADER_SIZE_BYTES, H263_REQUIRE_HEADER_SIZE_BYTES);
00214 
00215    return sz;
00216 }

bool H263plusVideoStreamParser::ParseShortHeader ( u_int8_t *  headerBuffer,
H263INFO outputInfoStruct 
) [private]

Definition at line 247 of file H263plusVideoStreamParser.cpp.

References GetWidthAndHeight(), _H263INFO::height, _H263INFO::isSyncFrame, _H263INFO::tr, and _H263INFO::width.

Referenced by parse().

00250 {
00251    u_int8_t fmt = 0;
00252    // Extract temporal reference (TR) from the buffer (bits 22-29 inclusive)
00253    outputInfoStruct->tr  = (headerBuffer[2] << 6) & 0xC0; // 2 LS bits out of the 3rd byte
00254    outputInfoStruct->tr |= (headerBuffer[3] >> 2) & 0x3F; // 6 MS bits out of the 4th byte
00255    // Extract the FMT part of PTYPE from the buffer (bits 35-37 inclusive)
00256    fmt = (headerBuffer[4] >> 2) & 0x07; // bits 3-5 ouf of the 5th byte
00257    // If PTYPE is not supported, return a failure notice to the calling function
00258    // FIXME: PLUSPTYPE is not supported
00259    if (fmt == 0x07) {
00260       return false;
00261    }
00262    // If PTYPE is supported, calculate the current width and height according to
00263    // a predefined table
00264    if (!GetWidthAndHeight(fmt, &(outputInfoStruct->width),
00265                                &(outputInfoStruct->height))) {
00266       return false;
00267    }
00268    // Extract the frame-type bit, which is the 9th bit of PTYPE (bit 38)
00269    outputInfoStruct->isSyncFrame = !(headerBuffer[4] & 0x02);
00270 
00271   return true;
00272 }

void H263plusVideoStreamParser::GetMaxBitrate ( MaxBitrate_CTX ctx,
u_int32_t  frameSize,
u_int8_t  frameTRDiff 
) [private]

Definition at line 289 of file H263plusVideoStreamParser.cpp.

References _MaxBitrate_CTX::bitrateTable, _MaxBitrate_CTX::maxBitrate, _MaxBitrate_CTX::tableIndex, and _MaxBitrate_CTX::windowBitrate.

00292 {
00293    if (frameTRDiff == 0)
00294       return;
00295 
00296    // Calculate the current frame's bitrate as bits per TR unit (round the result
00297    // upwards)
00298    u_int32_t frameBitrate = frameSize * 8 / frameTRDiff + 1;
00299 
00300    // for each TRdiff received,
00301    while (frameTRDiff--) {
00302       // Subtract the oldest bitrate entry from the current bitrate
00303       ctx->windowBitrate -= ctx->bitrateTable[ctx->tableIndex];
00304       // Update the oldest bitrate entry with the current frame's bitrate
00305       ctx->bitrateTable[ctx->tableIndex] = frameBitrate;
00306       // Add the current frame's bitrate to the current bitrate
00307       ctx->windowBitrate += frameBitrate;
00308       // Check if we have a new maximum bitrate
00309       if (ctx->windowBitrate > ctx->maxBitrate) {
00310          ctx->maxBitrate = ctx->windowBitrate;
00311           }
00312       // Advance the table index
00313       // Wrapping around the bitrateTable size
00314       ctx->tableIndex = (ctx->tableIndex + 1) %
00315         ( sizeof(ctx->bitrateTable) / sizeof(ctx->bitrateTable[0]) );
00316    }
00317 }

u_int64_t H263plusVideoStreamParser::CalculateDuration ( u_int8_t  trDiff  )  [private]

Definition at line 329 of file H263plusVideoStreamParser.cpp.

References duration, fcurrentPT, fnextTR, and H263_BASIC_FRAME_RATE.

Referenced by parse().

00330 {
00331   u_int64_t        nextPT;          // The next frame's presentation time in milli-seconds
00332   u_int64_t        duration;        // The current frame's duration in milli-seconds
00333 
00334   fnextTR += trDiff;
00335   // Calculate the next frame's presentation time, in milli-seconds
00336   nextPT = (fnextTR * 1001) / H263_BASIC_FRAME_RATE;
00337   // The frame's duration is the difference between the next presentation
00338   // time and the current presentation time.
00339   duration = nextPT - fcurrentPT;
00340   // "Remember" the next presentation time for the next time this function is called
00341   fcurrentPT = nextPT;
00342 
00343   return duration;
00344 }

bool H263plusVideoStreamParser::GetWidthAndHeight ( u_int8_t  fmt,
u_int16_t *  width,
u_int16_t *  height 
) [private]

Definition at line 347 of file H263plusVideoStreamParser.cpp.

Referenced by ParseShortHeader().

00350 {
00351    // The 'fmt' corresponds to bits 5-7 of the PTYPE
00352   static struct {
00353       u_int16_t width;
00354       u_int16_t height;
00355    } const dimensionsTable[8] = {
00356            { 0,    0 },      // 000 - 0 - forbidden, generates an error
00357            { 128,  96 },     // 001 - 1 - Sub QCIF
00358            { 176,  144 },    // 010 - 2 - QCIF
00359            { 352,  288 },    // 011 - 3 - CIF
00360            { 704,  576 },    // 100 - 4 - 4CIF
00361            { 1409, 1152 },   // 101 - 5 - 16CIF
00362            { 0,    0 },      // 110 - 6 - reserved, generates an error
00363            { 0,    0 }       // 111 - 7 - extended, not supported by profile 0
00364    };
00365 
00366    if (fmt > 7)
00367       return false;
00368 
00369    *width  = dimensionsTable[fmt].width;
00370    *height = dimensionsTable[fmt].height;
00371 
00372    if (*width  == 0)
00373      return false;
00374 
00375    return true;
00376 }

u_int8_t H263plusVideoStreamParser::GetTRDifference ( u_int8_t  nextTR,
u_int8_t  currentTR 
) [private]

Definition at line 379 of file H263plusVideoStreamParser.cpp.

Referenced by parse().

00382 {
00383    if (currentTR > nextTR) {
00384       // Wrap around 255...
00385       return nextTR + (256 - currentTR);
00386    } else {
00387       return nextTR - currentTR;
00388    }
00389 }

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

Reimplemented from StreamParser.

Definition at line 53 of file H263plusVideoStreamParser.cpp.

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

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

Reimplemented in H264VideoStreamParser, 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(), H264VideoStreamParser::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 MPEG1or2AudioStreamParser::parse(), AC3AudioStreamParser::parseFrame(), MPEGVideoStreamParser::setParseState(), MPEGProgramStreamParser::setParseState(), MatroskaFileParser::setParseState(), and 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 AC3AudioStreamParser::parseFrame(), MPEG1or2VideoStreamParser::parseGOPHeader(), MPEG4VideoStreamParser::parseGroupOfVideoObjectPlane(), MPEGProgramStreamParser::parsePackHeader(), MPEGProgramStreamParser::parsePESPacket(), MPEG1or2VideoStreamParser::parsePictureHeader(), 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(), H264VideoStreamParser::parse(), AC3AudioStreamParser::parseFrame(), MPEG1or2VideoStreamParser::parseGOPHeader(), MPEGProgramStreamParser::parsePackHeader(), MPEGProgramStreamParser::parsePESPacket(), 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(), H264VideoStreamParser::parse(), MatroskaFileParser::parseBlock(), MatroskaFileParser::parseEBMLNumber(), MatroskaFileParser::parseEBMLVal_binary(), MatroskaFileParser::parseEBMLVal_string(), MatroskaFileParser::parseEBMLVal_unsigned64(), MPEG1or2VideoStreamParser::parseGOPHeader(), parseH263Frame(), MPEGProgramStreamParser::parsePackHeader(), MPEGProgramStreamParser::parsePESPacket(), 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 ( unsigned  numBytes  )  [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(), MPEG1or2AudioStreamParser::parse(), AC3AudioStreamParser::parseFrame(), MPEG4VideoStreamParser::parseGroupOfVideoObjectPlane(), parseH263Frame(), 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(), and H264VideoStreamParser::parse().

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(), H264VideoStreamParser::parse(), MatroskaFileParser::parseBlock(), AC3AudioStreamParser::parseFrame(), MPEGProgramStreamParser::parsePackHeader(), MPEGProgramStreamParser::parsePESPacket(), MPEGProgramStreamParser::parseSystemHeader(), and MatroskaFileParser::skipHeader().

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 MPEGProgramStreamParser::parsePackHeader(), and MPEGProgramStreamParser::parsePESPacket().

00082                                                {
00083   if (numBits <= fRemainingUnparsedBits) {
00084     unsigned char lastByte = *lastParsed();
00085     lastByte >>= (fRemainingUnparsedBits - numBits);
00086     fRemainingUnparsedBits -= numBits;
00087 
00088     return (unsigned)lastByte &~ ((~0)<<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 &=~ ((~0)<<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 H264VideoStreamParser::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 H264VideoStreamParser::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 H264VideoStreamParser::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::skipHeader().

00115                                       {
00116   return BANK_SIZE;
00117 }


Field Documentation

class H263plusVideoStreamFramer* H263plusVideoStreamParser::fUsingSource [protected]

Definition at line 105 of file H263plusVideoStreamParser.hh.

unsigned char* H263plusVideoStreamParser::fTo [protected]

Definition at line 107 of file H263plusVideoStreamParser.hh.

Referenced by parse(), parseH263Frame(), registerReadInterest(), restoreSavedParserState(), and setParseState().

unsigned H263plusVideoStreamParser::fMaxSize [protected]

Definition at line 108 of file H263plusVideoStreamParser.hh.

Referenced by parseH263Frame(), and registerReadInterest().

unsigned char* H263plusVideoStreamParser::fStartOfFrame [protected]

Definition at line 109 of file H263plusVideoStreamParser.hh.

Referenced by registerReadInterest().

unsigned char* H263plusVideoStreamParser::fSavedTo [protected]

Definition at line 110 of file H263plusVideoStreamParser.hh.

Referenced by registerReadInterest(), restoreSavedParserState(), and setParseState().

unsigned char* H263plusVideoStreamParser::fLimit [protected]

Definition at line 111 of file H263plusVideoStreamParser.hh.

Referenced by registerReadInterest().

unsigned H263plusVideoStreamParser::fNumTruncatedBytes [protected]

Definition at line 112 of file H263plusVideoStreamParser.hh.

Referenced by numTruncatedBytes(), registerReadInterest(), restoreSavedParserState(), and setParseState().

unsigned H263plusVideoStreamParser::fSavedNumTruncatedBytes [protected]

Definition at line 113 of file H263plusVideoStreamParser.hh.

Referenced by registerReadInterest(), restoreSavedParserState(), and setParseState().

H263INFO H263plusVideoStreamParser::fNextInfo [private]

Definition at line 116 of file H263plusVideoStreamParser.hh.

Referenced by H263plusVideoStreamParser(), and parse().

H263INFO H263plusVideoStreamParser::fCurrentInfo [private]

Definition at line 117 of file H263plusVideoStreamParser.hh.

Referenced by H263plusVideoStreamParser(), and parse().

MaxBitrate_CTX H263plusVideoStreamParser::fMaxBitrateCtx [private]

Definition at line 118 of file H263plusVideoStreamParser.hh.

Referenced by H263plusVideoStreamParser().

char H263plusVideoStreamParser::fStates[3][256] [private]

Definition at line 119 of file H263plusVideoStreamParser.hh.

Referenced by H263plusVideoStreamParser(), and parseH263Frame().

u_int8_t H263plusVideoStreamParser::fNextHeader[H263_REQUIRE_HEADER_SIZE_BYTES] [private]

Definition at line 120 of file H263plusVideoStreamParser.hh.

Referenced by H263plusVideoStreamParser(), and parseH263Frame().

u_int32_t H263plusVideoStreamParser::fnextTR [private]

Definition at line 122 of file H263plusVideoStreamParser.hh.

Referenced by CalculateDuration().

u_int64_t H263plusVideoStreamParser::fcurrentPT [private]

Definition at line 123 of file H263plusVideoStreamParser.hh.

Referenced by CalculateDuration().


The documentation for this class was generated from the following files:
Generated on Mon Apr 29 13:31:35 2013 for live by  doxygen 1.5.2