MPEG4VideoStreamParser Class Reference

Inheritance diagram for MPEG4VideoStreamParser:

Inheritance graph
[legend]
Collaboration diagram for MPEG4VideoStreamParser:

Collaboration graph
[legend]

Public Member Functions

 MPEG4VideoStreamParser (MPEG4VideoStreamFramer *usingSource, FramedSource *inputSource)
virtual ~MPEG4VideoStreamParser ()
void registerReadInterest (unsigned char *to, unsigned maxSize)
unsigned numTruncatedBytes () const

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 ()
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 flushInput ()
virtual unsigned parse ()
MPEG4VideoStreamFramerusingSource ()
void setParseState (MPEGParseState parseState)
unsigned parseVisualObjectSequence (Boolean haveSeenStartCode=False)
unsigned parseVisualObject ()
unsigned parseVideoObjectLayer ()
unsigned parseGroupOfVideoObjectPlane ()
unsigned parseVideoObjectPlane ()
unsigned parseVisualObjectSequenceEndCode ()
Boolean getNextFrameBit (u_int8_t &result)
Boolean getNextFrameBits (unsigned numBits, u_int32_t &result)
void analyzeVOLHeader ()

Private Attributes

MPEGParseState fCurrentParseState
unsigned fNumBitsSeenSoFar
u_int32_t vop_time_increment_resolution
unsigned fNumVTIRBits
u_int8_t fixed_vop_rate
unsigned fixed_vop_time_increment
unsigned fSecondsSinceLastTimeCode
unsigned fTotalTicksSinceLastTimeCode
unsigned fPrevNewTotalTicks
unsigned fPrevPictureCountDelta
Boolean fJustSawTimeCode

Detailed Description

Definition at line 44 of file MPEG4VideoStreamFramer.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

MPEG4VideoStreamParser::MPEG4VideoStreamParser ( MPEG4VideoStreamFramer usingSource,
FramedSource inputSource 
)

Definition at line 160 of file MPEG4VideoStreamFramer.cpp.

MPEG4VideoStreamParser::~MPEG4VideoStreamParser (  )  [virtual]

Definition at line 170 of file MPEG4VideoStreamFramer.cpp.

00170                                                 {
00171 }


Member Function Documentation

void MPEG4VideoStreamParser::flushInput (  )  [private, virtual]

Reimplemented from StreamParser.

Definition at line 178 of file MPEG4VideoStreamFramer.cpp.

References fCurrentParseState, StreamParser::flushInput(), fPrevNewTotalTicks, fPrevPictureCountDelta, fSecondsSinceLastTimeCode, fTotalTicksSinceLastTimeCode, PARSING_VISUAL_OBJECT_SEQUENCE, and MPEGVideoStreamParser::setParseState().

00178                                         {
00179   fSecondsSinceLastTimeCode = 0;
00180   fTotalTicksSinceLastTimeCode = 0;
00181   fPrevNewTotalTicks = 0;
00182   fPrevPictureCountDelta = 1;
00183 
00184   StreamParser::flushInput();
00185   if (fCurrentParseState != PARSING_VISUAL_OBJECT_SEQUENCE) {
00186     setParseState(PARSING_VISUAL_OBJECT_SEQUENCE); // later, change to GOV or VOP? #####
00187   }
00188 }

unsigned MPEG4VideoStreamParser::parse (  )  [private, virtual]

Implements MPEGVideoStreamParser.

Definition at line 191 of file MPEG4VideoStreamFramer.cpp.

References fCurrentParseState, parseGroupOfVideoObjectPlane(), parseVideoObjectLayer(), parseVideoObjectPlane(), parseVisualObject(), parseVisualObjectSequence(), parseVisualObjectSequenceEndCode(), PARSING_GROUP_OF_VIDEO_OBJECT_PLANE, PARSING_VIDEO_OBJECT_LAYER, PARSING_VIDEO_OBJECT_PLANE, PARSING_VISUAL_OBJECT, PARSING_VISUAL_OBJECT_SEQUENCE, PARSING_VISUAL_OBJECT_SEQUENCE_END_CODE, PARSING_VISUAL_OBJECT_SEQUENCE_SEEN_CODE, and True.

00191                                        {
00192   try {
00193     switch (fCurrentParseState) {
00194     case PARSING_VISUAL_OBJECT_SEQUENCE: {
00195       return parseVisualObjectSequence();
00196     }
00197     case PARSING_VISUAL_OBJECT_SEQUENCE_SEEN_CODE: {
00198       return parseVisualObjectSequence(True);
00199     }
00200     case PARSING_VISUAL_OBJECT: {
00201       return parseVisualObject();
00202     }
00203     case PARSING_VIDEO_OBJECT_LAYER: {
00204       return parseVideoObjectLayer();
00205     }
00206     case PARSING_GROUP_OF_VIDEO_OBJECT_PLANE: {
00207       return parseGroupOfVideoObjectPlane();
00208     }
00209     case PARSING_VIDEO_OBJECT_PLANE: {
00210       return parseVideoObjectPlane();
00211     }
00212     case PARSING_VISUAL_OBJECT_SEQUENCE_END_CODE: {
00213       return parseVisualObjectSequenceEndCode();
00214     }
00215     default: {
00216       return 0; // shouldn't happen
00217     }
00218     }
00219   } catch (int /*e*/) {
00220 #ifdef DEBUG
00221     fprintf(stderr, "MPEG4VideoStreamParser::parse() EXCEPTION (This is normal behavior - *not* an error)\n");
00222 #endif
00223     return 0;  // the parsing got interrupted
00224   }
00225 }

MPEG4VideoStreamFramer* MPEG4VideoStreamParser::usingSource (  )  [inline, private]

Definition at line 55 of file MPEG4VideoStreamFramer.cpp.

References MPEGVideoStreamParser::fUsingSource.

Referenced by analyzeVOLHeader(), parseGroupOfVideoObjectPlane(), parseVideoObjectLayer(), parseVideoObjectPlane(), parseVisualObject(), parseVisualObjectSequence(), and parseVisualObjectSequenceEndCode().

00055                                         {
00056     return (MPEG4VideoStreamFramer*)fUsingSource;
00057   }

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

Definition at line 173 of file MPEG4VideoStreamFramer.cpp.

References fCurrentParseState, and MPEGVideoStreamParser::setParseState().

00173                                                                     {
00174   fCurrentParseState = parseState;
00175   MPEGVideoStreamParser::setParseState();
00176 }

unsigned MPEG4VideoStreamParser::parseVisualObjectSequence ( Boolean  haveSeenStartCode = False  )  [private]

Definition at line 234 of file MPEG4VideoStreamFramer.cpp.

References MPEG4VideoStreamFramer::appendToNewConfig(), MPEGVideoStreamFramer::computePresentationTime(), MPEGVideoStreamParser::curFrameSize(), MPEG4VideoStreamFramer::fProfileAndLevelIndication, MPEGVideoStreamParser::fStartOfFrame, fTotalTicksSinceLastTimeCode, StreamParser::get1Byte(), StreamParser::get4Bytes(), PARSING_VISUAL_OBJECT, PARSING_VISUAL_OBJECT_SEQUENCE, MPEGVideoStreamParser::save4Bytes(), MPEGVideoStreamParser::saveByte(), MPEGVideoStreamParser::saveToNextCode(), MPEGVideoStreamParser::setParseState(), MPEG4VideoStreamFramer::startNewConfig(), StreamParser::test4Bytes(), usingSource(), VISUAL_OBJECT_SEQUENCE_START_CODE, and VISUAL_OBJECT_START_CODE.

Referenced by parse().

00234                                                      {
00235 #ifdef DEBUG
00236   fprintf(stderr, "parsing VisualObjectSequence\n");
00237 #endif
00238   usingSource()->startNewConfig();
00239   u_int32_t first4Bytes;
00240   if (!haveSeenStartCode) {
00241     while ((first4Bytes = test4Bytes()) != VISUAL_OBJECT_SEQUENCE_START_CODE) {
00242 #ifdef DEBUG
00243       fprintf(stderr, "ignoring non VS header: 0x%08x\n", first4Bytes);
00244 #endif
00245       get1Byte(); setParseState(PARSING_VISUAL_OBJECT_SEQUENCE);
00246           // ensures we progress over bad data
00247     }
00248     first4Bytes = get4Bytes();
00249   } else {
00250     // We've already seen the start code
00251     first4Bytes = VISUAL_OBJECT_SEQUENCE_START_CODE;
00252   }
00253   save4Bytes(first4Bytes);
00254 
00255   // The next byte is the "profile_and_level_indication":
00256   u_int8_t pali = get1Byte();
00257 #ifdef DEBUG
00258   fprintf(stderr, "profile_and_level_indication: %02x\n", pali);
00259 #endif
00260   saveByte(pali);
00261   usingSource()->fProfileAndLevelIndication = pali;
00262 
00263   // Now, copy all bytes that we see, up until we reach
00264   // a VISUAL_OBJECT_START_CODE:
00265   u_int32_t next4Bytes = get4Bytes();
00266   while (next4Bytes != VISUAL_OBJECT_START_CODE) {
00267     saveToNextCode(next4Bytes);
00268   }
00269 
00270   setParseState(PARSING_VISUAL_OBJECT);
00271 
00272   // Compute this frame's presentation time:
00273   usingSource()->computePresentationTime(fTotalTicksSinceLastTimeCode);
00274 
00275   // This header forms part of the 'configuration' information:
00276   usingSource()->appendToNewConfig(fStartOfFrame, curFrameSize());
00277 
00278   return curFrameSize();
00279 }

unsigned MPEG4VideoStreamParser::parseVisualObject (  )  [private]

Definition at line 285 of file MPEG4VideoStreamFramer.cpp.

References MPEG4VideoStreamFramer::appendToNewConfig(), MPEGVideoStreamFramer::computePresentationTime(), MPEGVideoStreamParser::curFrameSize(), Medium::envir(), MPEGVideoStreamParser::fStartOfFrame, fTotalTicksSinceLastTimeCode, StreamParser::get1Byte(), StreamParser::get4Bytes(), isVideoObjectStartCode(), PARSING_VIDEO_OBJECT_LAYER, MPEGVideoStreamParser::save4Bytes(), MPEGVideoStreamParser::saveByte(), MPEGVideoStreamParser::saveToNextCode(), MPEGVideoStreamParser::setParseState(), usingSource(), and VISUAL_OBJECT_START_CODE.

Referenced by parse().

00285                                                    {
00286 #ifdef DEBUG
00287   fprintf(stderr, "parsing VisualObject\n");
00288 #endif
00289   // Note that we've already read the VISUAL_OBJECT_START_CODE
00290   save4Bytes(VISUAL_OBJECT_START_CODE);
00291 
00292   // Next, extract the "visual_object_type" from the next 1 or 2 bytes:
00293   u_int8_t nextByte = get1Byte(); saveByte(nextByte);
00294   Boolean is_visual_object_identifier = (nextByte&0x80) != 0;
00295   u_int8_t visual_object_type;
00296   if (is_visual_object_identifier) {
00297 #ifdef DEBUG
00298     fprintf(stderr, "visual_object_verid: 0x%x; visual_object_priority: 0x%x\n", (nextByte&0x78)>>3, (nextByte&0x07));
00299 #endif
00300     nextByte = get1Byte(); saveByte(nextByte);
00301     visual_object_type = (nextByte&0xF0)>>4;
00302   } else {
00303     visual_object_type = (nextByte&0x78)>>3;
00304   }
00305 #ifdef DEBUG
00306   fprintf(stderr, "visual_object_type: 0x%x\n", visual_object_type);
00307 #endif
00308   // At present, we support only the "Video ID" "visual_object_type" (1)
00309   if (visual_object_type != 1) {
00310     usingSource()->envir() << "MPEG4VideoStreamParser::parseVisualObject(): Warning: We don't handle visual_object_type " << visual_object_type << "\n";
00311   }
00312 
00313   // Now, copy all bytes that we see, up until we reach
00314   // a video_object_start_code
00315   u_int32_t next4Bytes = get4Bytes();
00316   while (!isVideoObjectStartCode(next4Bytes)) {
00317     saveToNextCode(next4Bytes);
00318   }
00319   save4Bytes(next4Bytes);
00320 #ifdef DEBUG
00321   fprintf(stderr, "saw a video_object_start_code: 0x%08x\n", next4Bytes);
00322 #endif
00323 
00324   setParseState(PARSING_VIDEO_OBJECT_LAYER);
00325 
00326   // Compute this frame's presentation time:
00327   usingSource()->computePresentationTime(fTotalTicksSinceLastTimeCode);
00328 
00329   // This header forms part of the 'configuration' information:
00330   usingSource()->appendToNewConfig(fStartOfFrame, curFrameSize());
00331 
00332   return curFrameSize();
00333 }

unsigned MPEG4VideoStreamParser::parseVideoObjectLayer (  )  [private]

Definition at line 437 of file MPEG4VideoStreamFramer.cpp.

References analyzeVOLHeader(), MPEG4VideoStreamFramer::appendToNewConfig(), MPEG4VideoStreamFramer::completeNewConfig(), MPEGVideoStreamFramer::computePresentationTime(), MPEGVideoStreamParser::curFrameSize(), Medium::envir(), MPEGVideoStreamParser::fStartOfFrame, fTotalTicksSinceLastTimeCode, StreamParser::get4Bytes(), GROUP_VOP_START_CODE, isVideoObjectLayerStartCode(), PARSING_GROUP_OF_VIDEO_OBJECT_PLANE, PARSING_VIDEO_OBJECT_PLANE, MPEGVideoStreamParser::saveToNextCode(), MPEGVideoStreamParser::setParseState(), usingSource(), and VOP_START_CODE.

Referenced by parse().

00437                                                        {
00438 #ifdef DEBUG
00439   fprintf(stderr, "parsing VideoObjectLayer\n");
00440 #endif
00441   // The first 4 bytes must be a "video_object_layer_start_code".
00442   // If not, this is a 'short video header', which we currently
00443   // don't support:
00444   u_int32_t next4Bytes = get4Bytes();
00445   if (!isVideoObjectLayerStartCode(next4Bytes)) {
00446     usingSource()->envir() << "MPEG4VideoStreamParser::parseVideoObjectLayer(): This appears to be a 'short video header', which we current don't support\n";
00447   }
00448 
00449   // Now, copy all bytes that we see, up until we reach
00450   // a GROUP_VOP_START_CODE or a VOP_START_CODE:
00451   do {
00452     saveToNextCode(next4Bytes);
00453   } while (next4Bytes != GROUP_VOP_START_CODE
00454            && next4Bytes != VOP_START_CODE);
00455 
00456   analyzeVOLHeader();
00457 
00458   setParseState((next4Bytes == GROUP_VOP_START_CODE)
00459                 ? PARSING_GROUP_OF_VIDEO_OBJECT_PLANE
00460                 : PARSING_VIDEO_OBJECT_PLANE);
00461 
00462   // Compute this frame's presentation time:
00463   usingSource()->computePresentationTime(fTotalTicksSinceLastTimeCode);
00464 
00465   // This header ends the 'configuration' information:
00466   usingSource()->appendToNewConfig(fStartOfFrame, curFrameSize());
00467   usingSource()->completeNewConfig();
00468 
00469   return curFrameSize();
00470 }

unsigned MPEG4VideoStreamParser::parseGroupOfVideoObjectPlane (  )  [private]

Definition at line 472 of file MPEG4VideoStreamFramer.cpp.

References MPEGVideoStreamFramer::computePresentationTime(), MPEGVideoStreamParser::curFrameSize(), fixed_vop_rate, fJustSawTimeCode, fSecondsSinceLastTimeCode, fTotalTicksSinceLastTimeCode, StreamParser::get4Bytes(), StreamParser::getBytes(), GROUP_VOP_START_CODE, PARSING_VIDEO_OBJECT_PLANE, MPEGVideoStreamParser::save4Bytes(), MPEGVideoStreamParser::saveByte(), MPEGVideoStreamParser::saveToNextCode(), MPEGVideoStreamParser::setParseState(), MPEGVideoStreamFramer::setTimeCode(), True, usingSource(), and VOP_START_CODE.

Referenced by parse().

00472                                                               {
00473 #ifdef DEBUG
00474   fprintf(stderr, "parsing GroupOfVideoObjectPlane\n");
00475 #endif
00476   // Note that we've already read the GROUP_VOP_START_CODE
00477   save4Bytes(GROUP_VOP_START_CODE);
00478 
00479   // Next, extract the (18-bit) time code from the next 3 bytes:
00480   u_int8_t next3Bytes[3];
00481   getBytes(next3Bytes, 3);
00482   saveByte(next3Bytes[0]);saveByte(next3Bytes[1]);saveByte(next3Bytes[2]);
00483   unsigned time_code
00484     = (next3Bytes[0]<<10)|(next3Bytes[1]<<2)|(next3Bytes[2]>>6);
00485   unsigned time_code_hours    = (time_code&0x0003E000)>>13;
00486   unsigned time_code_minutes  = (time_code&0x00001F80)>>7;
00487 #if defined(DEBUG) || defined(DEBUG_TIMESTAMPS)
00488   Boolean marker_bit          = (time_code&0x00000040) != 0;
00489 #endif
00490   unsigned time_code_seconds  = (time_code&0x0000003F);
00491 #if defined(DEBUG) || defined(DEBUG_TIMESTAMPS)
00492   fprintf(stderr, "time_code: 0x%05x, hours %d, minutes %d, marker_bit %d, seconds %d\n", time_code, time_code_hours, time_code_minutes, marker_bit, time_code_seconds);
00493 #endif
00494   fJustSawTimeCode = True;
00495 
00496   // Now, copy all bytes that we see, up until we reach a VOP_START_CODE:
00497   u_int32_t next4Bytes = get4Bytes();
00498   while (next4Bytes != VOP_START_CODE) {
00499     saveToNextCode(next4Bytes);
00500   }
00501 
00502   // Compute this frame's presentation time:
00503   usingSource()->computePresentationTime(fTotalTicksSinceLastTimeCode);
00504 
00505   // Record the time code:
00506   usingSource()->setTimeCode(time_code_hours, time_code_minutes,
00507                              time_code_seconds, 0, 0);
00508     // Note: Because the GOV header can appear anywhere (not just at a 1s point), we
00509     // don't pass "fTotalTicksSinceLastTimeCode" as the "picturesSinceLastGOP" parameter.
00510   fSecondsSinceLastTimeCode = 0;
00511   if (fixed_vop_rate) fTotalTicksSinceLastTimeCode = 0;
00512 
00513   setParseState(PARSING_VIDEO_OBJECT_PLANE);
00514 
00515   return curFrameSize();
00516 }

unsigned MPEG4VideoStreamParser::parseVideoObjectPlane (  )  [private]

Definition at line 518 of file MPEG4VideoStreamFramer.cpp.

References MPEGVideoStreamFramer::computePresentationTime(), MPEGVideoStreamParser::curFrameSize(), Medium::envir(), False, fixed_vop_time_increment, fJustSawTimeCode, fNumVTIRBits, MPEGVideoStreamFramer::fPictureCount, MPEGVideoStreamFramer::fPictureEndMarker, fPrevNewTotalTicks, fPrevPictureCountDelta, fSecondsSinceLastTimeCode, fTotalTicksSinceLastTimeCode, StreamParser::get1Byte(), StreamParser::get4Bytes(), GROUP_VOP_START_CODE, isVideoObjectLayerStartCode(), isVideoObjectStartCode(), PARSING_GROUP_OF_VIDEO_OBJECT_PLANE, PARSING_VIDEO_OBJECT_LAYER, PARSING_VIDEO_OBJECT_PLANE, PARSING_VISUAL_OBJECT, PARSING_VISUAL_OBJECT_SEQUENCE_END_CODE, PARSING_VISUAL_OBJECT_SEQUENCE_SEEN_CODE, MPEGVideoStreamParser::save4Bytes(), MPEGVideoStreamParser::saveByte(), MPEGVideoStreamParser::saveToNextCode(), MPEGVideoStreamParser::setParseState(), True, usingSource(), VISUAL_OBJECT_SEQUENCE_END_CODE, VISUAL_OBJECT_SEQUENCE_START_CODE, VISUAL_OBJECT_START_CODE, VOP_START_CODE, and vop_time_increment_resolution.

Referenced by parse().

00518                                                        {
00519 #ifdef DEBUG
00520   fprintf(stderr, "#parsing VideoObjectPlane\n");
00521 #endif
00522   // Note that we've already read the VOP_START_CODE
00523   save4Bytes(VOP_START_CODE);
00524 
00525   // Get the "vop_coding_type" from the next byte:
00526   u_int8_t nextByte = get1Byte(); saveByte(nextByte);
00527   u_int8_t vop_coding_type = nextByte>>6;
00528 
00529   // Next, get the "modulo_time_base" by counting the '1' bits that follow.
00530   // We look at the next 32-bits only.  This should be enough in most cases.
00531   u_int32_t next4Bytes = get4Bytes();
00532   u_int32_t timeInfo = (nextByte<<(32-6))|(next4Bytes>>6);
00533   unsigned modulo_time_base = 0;
00534   u_int32_t mask = 0x80000000;
00535   while ((timeInfo&mask) != 0) {
00536     ++modulo_time_base;
00537     mask >>= 1;
00538   }
00539   mask >>= 1;
00540 
00541   // Check the following marker bit:
00542   if ((timeInfo&mask) == 0) {
00543     usingSource()->envir() << "MPEG4VideoStreamParser::parseVideoObjectPlane(): marker bit not set!\n";
00544   }
00545   mask >>= 1;
00546 
00547   // Then, get the "vop_time_increment".
00548   // First, make sure we have enough bits left for this:
00549   if ((mask>>(fNumVTIRBits-1)) == 0) {
00550     usingSource()->envir() << "MPEG4VideoStreamParser::parseVideoObjectPlane(): 32-bits are not enough to get \"vop_time_increment\"!\n";
00551   }
00552   unsigned vop_time_increment = 0;
00553   for (unsigned i = 0; i < fNumVTIRBits; ++i) {
00554     vop_time_increment |= timeInfo&mask;
00555     mask >>= 1;
00556   }
00557   while (mask != 0) {
00558     vop_time_increment >>= 1;
00559     mask >>= 1;
00560   }
00561 #ifdef DEBUG
00562   fprintf(stderr, "vop_coding_type: %d(%c), modulo_time_base: %d, vop_time_increment: %d\n", vop_coding_type, "IPBS"[vop_coding_type], modulo_time_base, vop_time_increment);
00563 #endif
00564 
00565   // Now, copy all bytes that we see, up until we reach a code of some sort:
00566   saveToNextCode(next4Bytes);
00567 
00568   // Update our counters based on the frame timing information that we saw:
00569   if (fixed_vop_time_increment > 0) {
00570     // This is a 'fixed_vop_rate' stream.  Use 'fixed_vop_time_increment':
00571     usingSource()->fPictureCount += fixed_vop_time_increment;
00572     if (vop_time_increment > 0 || modulo_time_base > 0) {
00573       fTotalTicksSinceLastTimeCode += fixed_vop_time_increment;
00574       // Note: "fSecondsSinceLastTimeCode" and "fPrevNewTotalTicks" are not used.
00575     }
00576   } else {
00577     // Use 'vop_time_increment':
00578     unsigned newTotalTicks
00579       = (fSecondsSinceLastTimeCode + modulo_time_base)*vop_time_increment_resolution
00580       + vop_time_increment;
00581     if (newTotalTicks == fPrevNewTotalTicks && fPrevNewTotalTicks > 0) {
00582       // This is apparently a buggy MPEG-4 video stream, because
00583       // "vop_time_increment" did not change.  Overcome this error,
00584       // by pretending that it did change.
00585 #ifdef DEBUG
00586       fprintf(stderr, "Buggy MPEG-4 video stream: \"vop_time_increment\" did not change!\n");
00587 #endif
00588       // The following assumes that we don't have 'B' frames.  If we do, then TARFU!
00589       usingSource()->fPictureCount += vop_time_increment;
00590       fTotalTicksSinceLastTimeCode += vop_time_increment;
00591       fSecondsSinceLastTimeCode += modulo_time_base;
00592     } else {
00593       if (newTotalTicks < fPrevNewTotalTicks && vop_coding_type != 2/*B*/
00594           && modulo_time_base == 0 && vop_time_increment == 0 && !fJustSawTimeCode) {
00595         // This is another kind of buggy MPEG-4 video stream, in which
00596         // "vop_time_increment" wraps around, but without
00597         // "modulo_time_base" changing (or just having had a new time code).
00598         // Overcome this by pretending that "vop_time_increment" *did* wrap around:
00599 #ifdef DEBUG
00600         fprintf(stderr, "Buggy MPEG-4 video stream: \"vop_time_increment\" wrapped around, but without \"modulo_time_base\" changing!\n");
00601 #endif
00602         ++fSecondsSinceLastTimeCode;
00603         newTotalTicks += vop_time_increment_resolution;
00604       }
00605       fPrevNewTotalTicks = newTotalTicks;
00606       if (vop_coding_type != 2/*B*/) {
00607         int pictureCountDelta = newTotalTicks - fTotalTicksSinceLastTimeCode;
00608         if (pictureCountDelta <= 0) pictureCountDelta = fPrevPictureCountDelta;
00609             // ensures that the picture count is always increasing
00610         usingSource()->fPictureCount += pictureCountDelta;
00611         fPrevPictureCountDelta = pictureCountDelta;
00612         fTotalTicksSinceLastTimeCode = newTotalTicks;
00613         fSecondsSinceLastTimeCode += modulo_time_base;
00614       }
00615     }
00616   }
00617   fJustSawTimeCode = False; // for next time
00618 
00619   // The next thing to parse depends on the code that we just saw,
00620   // but we are assumed to have ended the current picture:
00621   usingSource()->fPictureEndMarker = True; // HACK #####
00622   switch (next4Bytes) {
00623   case VISUAL_OBJECT_SEQUENCE_END_CODE: {
00624     setParseState(PARSING_VISUAL_OBJECT_SEQUENCE_END_CODE);
00625     break;
00626   }
00627   case VISUAL_OBJECT_SEQUENCE_START_CODE: {
00628     setParseState(PARSING_VISUAL_OBJECT_SEQUENCE_SEEN_CODE);
00629     break;
00630   }
00631   case VISUAL_OBJECT_START_CODE: {
00632     setParseState(PARSING_VISUAL_OBJECT);
00633     break;
00634   }
00635   case GROUP_VOP_START_CODE: {
00636     setParseState(PARSING_GROUP_OF_VIDEO_OBJECT_PLANE);
00637     break;
00638   }
00639   case VOP_START_CODE: {
00640     setParseState(PARSING_VIDEO_OBJECT_PLANE);
00641     break;
00642   }
00643   default: {
00644     if (isVideoObjectStartCode(next4Bytes)) {
00645       setParseState(PARSING_VIDEO_OBJECT_LAYER);
00646     } else if (isVideoObjectLayerStartCode(next4Bytes)){
00647       // copy all bytes that we see, up until we reach a VOP_START_CODE:
00648       u_int32_t next4Bytes = get4Bytes();
00649       while (next4Bytes != VOP_START_CODE) {
00650         saveToNextCode(next4Bytes);
00651       }
00652       setParseState(PARSING_VIDEO_OBJECT_PLANE);
00653     } else {
00654       usingSource()->envir() << "MPEG4VideoStreamParser::parseVideoObjectPlane(): Saw unexpected code "
00655                              << (void*)next4Bytes << "\n";
00656       setParseState(PARSING_VIDEO_OBJECT_PLANE); // the safest way to recover...
00657     }
00658     break;
00659   }
00660   }
00661 
00662   // Compute this frame's presentation time:
00663   usingSource()->computePresentationTime(fTotalTicksSinceLastTimeCode);
00664 
00665   return curFrameSize();
00666 }

unsigned MPEG4VideoStreamParser::parseVisualObjectSequenceEndCode (  )  [private]

Definition at line 668 of file MPEG4VideoStreamFramer.cpp.

References MPEGVideoStreamParser::curFrameSize(), MPEGVideoStreamFramer::fPictureEndMarker, PARSING_VISUAL_OBJECT_SEQUENCE, MPEGVideoStreamParser::save4Bytes(), MPEGVideoStreamParser::setParseState(), True, usingSource(), and VISUAL_OBJECT_SEQUENCE_END_CODE.

Referenced by parse().

00668                                                                   {
00669 #ifdef DEBUG
00670   fprintf(stderr, "parsing VISUAL_OBJECT_SEQUENCE_END_CODE\n");
00671 #endif
00672   // Note that we've already read the VISUAL_OBJECT_SEQUENCE_END_CODE
00673   save4Bytes(VISUAL_OBJECT_SEQUENCE_END_CODE);
00674 
00675   setParseState(PARSING_VISUAL_OBJECT_SEQUENCE);
00676 
00677   // Treat this as if we had ended a picture:
00678   usingSource()->fPictureEndMarker = True; // HACK #####
00679 
00680   return curFrameSize();
00681 }

Boolean MPEG4VideoStreamParser::getNextFrameBit ( u_int8_t &  result  )  [private]

Definition at line 339 of file MPEG4VideoStreamFramer.cpp.

References MPEGVideoStreamParser::curFrameSize(), False, fNumBitsSeenSoFar, MPEGVideoStreamParser::fStartOfFrame, and True.

Referenced by analyzeVOLHeader(), and getNextFrameBits().

00339                                                                 {
00340   if (fNumBitsSeenSoFar/8 >= curFrameSize()) return False;
00341 
00342   u_int8_t nextByte = fStartOfFrame[fNumBitsSeenSoFar/8];
00343   result = (nextByte>>(7-fNumBitsSeenSoFar%8))&1;
00344   ++fNumBitsSeenSoFar;
00345   return True;
00346 }

Boolean MPEG4VideoStreamParser::getNextFrameBits ( unsigned  numBits,
u_int32_t &  result 
) [private]

Definition at line 348 of file MPEG4VideoStreamFramer.cpp.

References False, getNextFrameBit(), and True.

Referenced by analyzeVOLHeader().

00349                                                                     {
00350   result = 0;
00351   for (unsigned i = 0; i < numBits; ++i) {
00352     u_int8_t nextBit;
00353     if (!getNextFrameBit(nextBit)) return False;
00354     result = (result<<1)|nextBit;
00355   }
00356   return True;
00357 }

void MPEG4VideoStreamParser::analyzeVOLHeader (  )  [private]

Definition at line 359 of file MPEG4VideoStreamFramer.cpp.

References MPEGVideoStreamParser::curFrameSize(), Medium::envir(), MPEGVideoStreamFramer::fFrameRate, fixed_vop_rate, fixed_vop_time_increment, fNumBitsSeenSoFar, fNumVTIRBits, getNextFrameBit(), getNextFrameBits(), usingSource(), and vop_time_increment_resolution.

Referenced by parseVideoObjectLayer().

00359                                               {
00360   // Extract timing information (in particular,
00361   // "vop_time_increment_resolution") from the VOL Header:
00362   fNumBitsSeenSoFar = 41;
00363   do {
00364     u_int8_t is_object_layer_identifier;
00365     if (!getNextFrameBit(is_object_layer_identifier)) break;
00366     if (is_object_layer_identifier) fNumBitsSeenSoFar += 7;
00367 
00368     u_int32_t aspect_ratio_info;
00369     if (!getNextFrameBits(4, aspect_ratio_info)) break;
00370     if (aspect_ratio_info == 15 /*extended_PAR*/) fNumBitsSeenSoFar += 16;
00371 
00372     u_int8_t vol_control_parameters;
00373     if (!getNextFrameBit(vol_control_parameters)) break;
00374     if (vol_control_parameters) {
00375       fNumBitsSeenSoFar += 3; // chroma_format; low_delay
00376       u_int8_t vbw_parameters;
00377       if (!getNextFrameBit(vbw_parameters)) break;
00378       if (vbw_parameters) fNumBitsSeenSoFar += 79;
00379     }
00380 
00381     fNumBitsSeenSoFar += 2; // video_object_layer_shape
00382     u_int8_t marker_bit;
00383     if (!getNextFrameBit(marker_bit)) break;
00384     if (marker_bit != 1) { // sanity check
00385       usingSource()->envir() << "MPEG4VideoStreamParser::analyzeVOLHeader(): marker_bit 1 not set!\n";
00386       break;
00387     }
00388 
00389     if (!getNextFrameBits(16, vop_time_increment_resolution)) break;
00390 #ifdef DEBUG
00391     fprintf(stderr, "vop_time_increment_resolution: %d\n", vop_time_increment_resolution);
00392 #endif
00393     if (vop_time_increment_resolution == 0) {
00394       usingSource()->envir() << "MPEG4VideoStreamParser::analyzeVOLHeader(): vop_time_increment_resolution is zero!\n";
00395       break;
00396     }
00397     // Compute how many bits are necessary to represent this:
00398     fNumVTIRBits = 0;
00399     for (unsigned test = vop_time_increment_resolution; test>0; test /= 2) {
00400       ++fNumVTIRBits;
00401     }
00402 
00403     if (!getNextFrameBit(marker_bit)) break;
00404     if (marker_bit != 1) { // sanity check
00405       usingSource()->envir() << "MPEG4VideoStreamParser::analyzeVOLHeader(): marker_bit 2 not set!\n";
00406       break;
00407     }
00408 
00409     if (!getNextFrameBit(fixed_vop_rate)) break;
00410     if (fixed_vop_rate) {
00411       // Get the following "fixed_vop_time_increment":
00412       if (!getNextFrameBits(fNumVTIRBits, fixed_vop_time_increment)) break;
00413 #ifdef DEBUG
00414       fprintf(stderr, "fixed_vop_time_increment: %d\n", fixed_vop_time_increment);
00415       if (fixed_vop_time_increment == 0) {
00416         usingSource()->envir() << "MPEG4VideoStreamParser::analyzeVOLHeader(): fixed_vop_time_increment is zero!\n";
00417       }
00418 #endif
00419     }
00420     // Use "vop_time_increment_resolution" as the 'frame rate'
00421     // (really, 'tick rate'):
00422     usingSource()->fFrameRate = (double)vop_time_increment_resolution;
00423 #ifdef DEBUG
00424     fprintf(stderr, "fixed_vop_rate: %d; 'frame' (really tick) rate: %f\n", fixed_vop_rate, usingSource()->fFrameRate);
00425 #endif
00426 
00427     return;
00428   } while (0);
00429 
00430   if (fNumBitsSeenSoFar/8 >= curFrameSize()) {
00431     char errMsg[200];
00432     sprintf(errMsg, "Not enough bits in VOL header: %d/8 >= %d\n", fNumBitsSeenSoFar, curFrameSize());
00433     usingSource()->envir() << errMsg;
00434   }
00435 }

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

Definition at line 40 of file MPEGVideoStreamParser.cpp.

References MPEGVideoStreamParser::fLimit, MPEGVideoStreamParser::fNumTruncatedBytes, MPEGVideoStreamParser::fSavedNumTruncatedBytes, MPEGVideoStreamParser::fSavedTo, MPEGVideoStreamParser::fStartOfFrame, and MPEGVideoStreamParser::fTo.

Referenced by MPEGVideoStreamFramer::doGetNextFrame().

00041                                                                    {
00042   fStartOfFrame = fTo = fSavedTo = to;
00043   fLimit = to + maxSize;
00044   fNumTruncatedBytes = fSavedNumTruncatedBytes = 0;
00045 }

unsigned MPEGVideoStreamParser::numTruncatedBytes (  )  const [inline, inherited]

Definition at line 45 of file MPEGVideoStreamParser.hh.

References MPEGVideoStreamParser::fNumTruncatedBytes.

Referenced by MPEGVideoStreamFramer::continueReadProcessing().

00045 { return fNumTruncatedBytes; }

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

Definition at line 48 of file MPEGVideoStreamParser.hh.

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

Referenced by flushInput(), MPEG1or2VideoStreamParser::flushInput(), H264VideoStreamParser::parse(), MPEG1or2VideoStreamParser::parseGOPHeader(), parseGroupOfVideoObjectPlane(), MPEG1or2VideoStreamParser::parsePictureHeader(), MPEG1or2VideoStreamParser::parseSlice(), parseVideoObjectLayer(), parseVideoObjectPlane(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), parseVisualObject(), parseVisualObjectSequence(), parseVisualObjectSequenceEndCode(), setParseState(), and MPEG1or2VideoStreamParser::setParseState().

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

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

Definition at line 55 of file MPEGVideoStreamParser.hh.

References MPEGVideoStreamParser::fLimit, MPEGVideoStreamParser::fNumTruncatedBytes, and MPEGVideoStreamParser::fTo.

Referenced by H264VideoStreamParser::parse(), parseGroupOfVideoObjectPlane(), parseVideoObjectPlane(), parseVisualObject(), parseVisualObjectSequence(), and MPEGVideoStreamParser::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, inherited]

Definition at line 64 of file MPEGVideoStreamParser.hh.

References MPEGVideoStreamParser::fLimit, MPEGVideoStreamParser::fNumTruncatedBytes, and MPEGVideoStreamParser::fTo.

Referenced by H264VideoStreamParser::parse(), MPEG1or2VideoStreamParser::parseGOPHeader(), parseGroupOfVideoObjectPlane(), MPEG1or2VideoStreamParser::parsePictureHeader(), parseVideoObjectPlane(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), parseVisualObject(), parseVisualObjectSequence(), parseVisualObjectSequenceEndCode(), and MPEGVideoStreamParser::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, inherited]

Definition at line 74 of file MPEGVideoStreamParser.hh.

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

Referenced by MPEG1or2VideoStreamParser::parseGOPHeader(), parseGroupOfVideoObjectPlane(), MPEG1or2VideoStreamParser::parsePictureHeader(), MPEG1or2VideoStreamParser::parseSlice(), parseVideoObjectLayer(), parseVideoObjectPlane(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), parseVisualObject(), and parseVisualObjectSequence().

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, inherited]

Definition at line 92 of file MPEGVideoStreamParser.hh.

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

Referenced by MPEG1or2VideoStreamParser::parsePictureHeader(), and MPEG1or2VideoStreamParser::parseSlice().

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, inherited]

Definition at line 114 of file MPEGVideoStreamParser.hh.

References MPEGVideoStreamParser::fStartOfFrame, and MPEGVideoStreamParser::fTo.

Referenced by analyzeVOLHeader(), getNextFrameBit(), H264VideoStreamParser::parse(), MPEG1or2VideoStreamParser::parseGOPHeader(), parseGroupOfVideoObjectPlane(), MPEG1or2VideoStreamParser::parsePictureHeader(), MPEG1or2VideoStreamParser::parseSlice(), parseVideoObjectLayer(), parseVideoObjectPlane(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), parseVisualObject(), parseVisualObjectSequence(), parseVisualObjectSequenceEndCode(), and MPEG1or2VideoStreamParser::saveCurrentVSH().

00114 { return fTo - fStartOfFrame; }

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 H263plusVideoStreamParser::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(), parseGroupOfVideoObjectPlane(), MPEGProgramStreamParser::parsePackHeader(), MPEGProgramStreamParser::parsePESPacket(), MPEG1or2VideoStreamParser::parsePictureHeader(), parseVideoObjectLayer(), parseVideoObjectPlane(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), parseVisualObject(), 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 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(), H263plusVideoStreamParser::parseH263Frame(), MPEGProgramStreamParser::parsePackHeader(), MPEGProgramStreamParser::parsePESPacket(), parseVideoObjectPlane(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), parseVisualObject(), parseVisualObjectSequence(), MPEGVideoStreamParser::saveToNextCode(), and MPEGVideoStreamParser::skipToNextCode().

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

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

Definition at line 78 of file StreamParser.hh.

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

Referenced by MatroskaFileParser::deliverFrameBytes(), MPEG1or2AudioStreamParser::parse(), AC3AudioStreamParser::parseFrame(), parseGroupOfVideoObjectPlane(), H263plusVideoStreamParser::parseH263Frame(), and MPEGProgramStreamParser::parsePESPacket().

00078                                                  {
00079     testBytes(to, numBytes);
00080     fCurParserIndex += numBytes;
00081     fRemainingUnparsedBits = 0;
00082   }

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

Definition at line 83 of file StreamParser.hh.

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

Referenced by StreamParser::getBytes(), and H264VideoStreamParser::parse().

00083                                                   { // as above, but doesn't advance ptr
00084     ensureValidBytes(numBytes);
00085     memmove(to, nextToParse(), numBytes);
00086   }

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

Definition at line 87 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().

00087                                     {
00088     ensureValidBytes(numBytes);
00089     fCurParserIndex += numBytes;
00090   }

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 96 of file StreamParser.hh.

References StreamParser::fCurParserIndex.

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

00096 { return fCurParserIndex; }

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

Definition at line 98 of file StreamParser.hh.

References StreamParser::fTotNumValidBytes.

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

00098 { return fTotNumValidBytes; }

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

Definition at line 100 of file StreamParser.hh.

References StreamParser::fHaveSeenEOF.

Referenced by H264VideoStreamParser::parse().

00100 { 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

MPEGParseState MPEG4VideoStreamParser::fCurrentParseState [private]

Definition at line 75 of file MPEG4VideoStreamFramer.cpp.

Referenced by flushInput(), parse(), and setParseState().

unsigned MPEG4VideoStreamParser::fNumBitsSeenSoFar [private]

Definition at line 76 of file MPEG4VideoStreamFramer.cpp.

Referenced by analyzeVOLHeader(), and getNextFrameBit().

u_int32_t MPEG4VideoStreamParser::vop_time_increment_resolution [private]

Definition at line 77 of file MPEG4VideoStreamFramer.cpp.

Referenced by analyzeVOLHeader(), and parseVideoObjectPlane().

unsigned MPEG4VideoStreamParser::fNumVTIRBits [private]

Definition at line 78 of file MPEG4VideoStreamFramer.cpp.

Referenced by analyzeVOLHeader(), and parseVideoObjectPlane().

u_int8_t MPEG4VideoStreamParser::fixed_vop_rate [private]

Definition at line 80 of file MPEG4VideoStreamFramer.cpp.

Referenced by analyzeVOLHeader(), and parseGroupOfVideoObjectPlane().

unsigned MPEG4VideoStreamParser::fixed_vop_time_increment [private]

Definition at line 81 of file MPEG4VideoStreamFramer.cpp.

Referenced by analyzeVOLHeader(), and parseVideoObjectPlane().

unsigned MPEG4VideoStreamParser::fSecondsSinceLastTimeCode [private]

Definition at line 82 of file MPEG4VideoStreamFramer.cpp.

Referenced by flushInput(), parseGroupOfVideoObjectPlane(), and parseVideoObjectPlane().

unsigned MPEG4VideoStreamParser::fTotalTicksSinceLastTimeCode [private]

Definition at line 82 of file MPEG4VideoStreamFramer.cpp.

Referenced by flushInput(), parseGroupOfVideoObjectPlane(), parseVideoObjectLayer(), parseVideoObjectPlane(), parseVisualObject(), and parseVisualObjectSequence().

unsigned MPEG4VideoStreamParser::fPrevNewTotalTicks [private]

Definition at line 82 of file MPEG4VideoStreamFramer.cpp.

Referenced by flushInput(), and parseVideoObjectPlane().

unsigned MPEG4VideoStreamParser::fPrevPictureCountDelta [private]

Definition at line 83 of file MPEG4VideoStreamFramer.cpp.

Referenced by flushInput(), and parseVideoObjectPlane().

Boolean MPEG4VideoStreamParser::fJustSawTimeCode [private]

Definition at line 84 of file MPEG4VideoStreamFramer.cpp.

Referenced by parseGroupOfVideoObjectPlane(), and parseVideoObjectPlane().

MPEGVideoStreamFramer* MPEGVideoStreamParser::fUsingSource [protected, inherited]

Definition at line 107 of file MPEGVideoStreamParser.hh.

Referenced by usingSource(), MPEG1or2VideoStreamParser::usingSource(), and H264VideoStreamParser::usingSource().

unsigned char* MPEGVideoStreamParser::fStartOfFrame [protected, inherited]

Definition at line 110 of file MPEGVideoStreamParser.hh.

Referenced by MPEGVideoStreamParser::curFrameSize(), getNextFrameBit(), H264VideoStreamParser::parse(), parseVideoObjectLayer(), parseVisualObject(), parseVisualObjectSequence(), MPEGVideoStreamParser::registerReadInterest(), H264VideoStreamParser::removeEmulationBytes(), MPEG1or2VideoStreamParser::saveCurrentVSH(), and MPEG1or2VideoStreamParser::useSavedVSH().

unsigned char* MPEGVideoStreamParser::fTo [protected, inherited]

Definition at line 111 of file MPEGVideoStreamParser.hh.

Referenced by MPEGVideoStreamParser::curFrameSize(), H264VideoStreamParser::parse(), MPEGVideoStreamParser::registerReadInterest(), H264VideoStreamParser::removeEmulationBytes(), MPEGVideoStreamParser::restoreSavedParserState(), MPEGVideoStreamParser::save4Bytes(), MPEGVideoStreamParser::saveByte(), and MPEGVideoStreamParser::setParseState().

unsigned char* MPEGVideoStreamParser::fLimit [protected, inherited]

Definition at line 112 of file MPEGVideoStreamParser.hh.

Referenced by MPEGVideoStreamParser::registerReadInterest(), MPEGVideoStreamParser::save4Bytes(), MPEGVideoStreamParser::saveByte(), and MPEG1or2VideoStreamParser::useSavedVSH().

unsigned MPEGVideoStreamParser::fNumTruncatedBytes [protected, inherited]

Definition at line 113 of file MPEGVideoStreamParser.hh.

Referenced by MPEGVideoStreamParser::numTruncatedBytes(), MPEGVideoStreamParser::registerReadInterest(), MPEGVideoStreamParser::restoreSavedParserState(), MPEGVideoStreamParser::save4Bytes(), MPEGVideoStreamParser::saveByte(), and MPEGVideoStreamParser::setParseState().

unsigned char* MPEGVideoStreamParser::fSavedTo [protected, inherited]

Definition at line 115 of file MPEGVideoStreamParser.hh.

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

unsigned MPEGVideoStreamParser::fSavedNumTruncatedBytes [protected, inherited]

Definition at line 116 of file MPEGVideoStreamParser.hh.

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


The documentation for this class was generated from the following file:
Generated on Thu May 17 07:15:55 2012 for live by  doxygen 1.5.2