H264VideoStreamParser Class Reference

Inheritance diagram for H264VideoStreamParser:

Inheritance graph
[legend]
Collaboration diagram for H264VideoStreamParser:

Collaboration graph
[legend]

Public Member Functions

 H264VideoStreamParser (H264VideoStreamFramer *usingSource, FramedSource *inputSource, Boolean includeStartCodeInOutput)
virtual ~H264VideoStreamParser ()
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 ()
H264VideoStreamFramerusingSource ()
void removeEmulationBytes (u_int8_t *nalUnitCopy, unsigned maxSize, unsigned &nalUnitCopySize)
void analyze_seq_parameter_set_data (unsigned &num_units_in_tick, unsigned &time_scale, unsigned &fixed_frame_rate_flag)
void analyze_vui_parameters (BitVector &bv, unsigned &num_units_in_tick, unsigned &time_scale, unsigned &fixed_frame_rate_flag)
void analyze_sei_data ()
void analyze_slice_header (u_int8_t *start, u_int8_t *end, u_int8_t nal_unit_type, unsigned &frame_num, unsigned &pic_parameter_set_id, unsigned &idr_pic_id, Boolean &field_pic_flag, Boolean &bottom_field_flag)

Private Attributes

unsigned fOutputStartCodeSize
Boolean fHaveSeenFirstStartCode
Boolean fHaveSeenFirstByteOfNALUnit
u_int8_t fFirstByteOfNALUnit
unsigned log2_max_frame_num
Boolean separate_colour_plane_flag
Boolean frame_mbs_only_flag

Detailed Description

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

H264VideoStreamParser::H264VideoStreamParser ( H264VideoStreamFramer usingSource,
FramedSource inputSource,
Boolean  includeStartCodeInOutput 
)

Definition at line 130 of file H264VideoStreamFramer.cpp.

00131   : MPEGVideoStreamParser(usingSource, inputSource),
00132     fOutputStartCodeSize(includeStartCodeInOutput ? 4 : 0), fHaveSeenFirstStartCode(False), fHaveSeenFirstByteOfNALUnit(False),
00133     // Default values for our parser variables (in case they're not set explicitly in headers that we parse:
00134     log2_max_frame_num(5), separate_colour_plane_flag(False), frame_mbs_only_flag(True) {
00135 }

H264VideoStreamParser::~H264VideoStreamParser (  )  [virtual]

Definition at line 137 of file H264VideoStreamFramer.cpp.

00137                                               {
00138 }


Member Function Documentation

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

Reimplemented from StreamParser.

Definition at line 557 of file H264VideoStreamFramer.cpp.

References False, fHaveSeenFirstByteOfNALUnit, fHaveSeenFirstStartCode, and StreamParser::flushInput().

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

Implements MPEGVideoStreamParser.

Definition at line 566 of file H264VideoStreamFramer.cpp.

References analyze_sei_data(), analyze_seq_parameter_set_data(), analyze_slice_header(), MPEGVideoStreamParser::curFrameSize(), StreamParser::curOffset(), False, fFirstByteOfNALUnit, MPEGVideoStreamFramer::fFrameRate, fHaveSeenFirstByteOfNALUnit, fHaveSeenFirstStartCode, H264VideoStreamFramer::fNextPresentationTime, fOutputStartCodeSize, MPEGVideoStreamFramer::fPictureCount, MPEGVideoStreamFramer::fPictureEndMarker, FramedSource::fPresentationTime, MPEGVideoStreamParser::fStartOfFrame, MPEGVideoStreamParser::fTo, StreamParser::get1Byte(), StreamParser::haveSeenEOF(), NUM_NEXT_SLICE_HEADER_BYTES_TO_ANALYZE, MPEGVideoStreamParser::save4Bytes(), MPEGVideoStreamParser::saveByte(), H264VideoStreamFramer::saveCopyOfPPS(), H264VideoStreamFramer::saveCopyOfSPS(), MPEGVideoStreamParser::setParseState(), H264VideoStreamFramer::setPresentationTime(), StreamParser::skipBytes(), StreamParser::test4Bytes(), StreamParser::testBytes(), StreamParser::totNumValidBytes(), True, and usingSource().

00566                                       {
00567   try {
00568     // The stream must start with a 0x00000001:
00569     if (!fHaveSeenFirstStartCode) {
00570       // Skip over any input bytes that precede the first 0x00000001:
00571       u_int32_t first4Bytes;
00572       while ((first4Bytes = test4Bytes()) != 0x00000001) {
00573         get1Byte(); setParseState(); // ensures that we progress over bad data
00574       }
00575       skipBytes(4); // skip this initial code
00576       
00577       setParseState();
00578       fHaveSeenFirstStartCode = True; // from now on
00579     }
00580     
00581     if (fOutputStartCodeSize > 0) {
00582       // Include a start code in the output:
00583       save4Bytes(0x00000001);
00584     }
00585 
00586     // Then save everything up until the next 0x00000001 (4 bytes) or 0x000001 (3 bytes), or we hit EOF.
00587     // Also make note of the first byte, because it contains the "nal_unit_type": 
00588     if (haveSeenEOF()) {
00589       // We hit EOF the last time that we tried to parse this data, so we know that any remaining unparsed data
00590       // forms a complete NAL unit, and that there's no 'start code' at the end:
00591       unsigned remainingDataSize = totNumValidBytes() - curOffset();
00592       while (remainingDataSize > 0) {
00593         saveByte(get1Byte());
00594         --remainingDataSize;
00595       }
00596 
00597       if (!fHaveSeenFirstByteOfNALUnit) {
00598         // There's no remaining NAL unit.
00599         (void)get1Byte(); // forces another read, which will cause EOF to get handled for real this time
00600         return 0;
00601       }
00602 #ifdef DEBUG
00603       fprintf(stderr, "This NAL unit (%d bytes) ends with EOF\n", curFrameSize()-fOutputStartCodeSize);
00604 #endif
00605     } else {
00606       u_int32_t next4Bytes = test4Bytes();
00607       if (!fHaveSeenFirstByteOfNALUnit) {
00608         fFirstByteOfNALUnit = next4Bytes>>24;
00609         fHaveSeenFirstByteOfNALUnit = True;
00610       }
00611       while (next4Bytes != 0x00000001 && (next4Bytes&0xFFFFFF00) != 0x00000100) {
00612         // We save at least some of "next4Bytes".
00613         if ((unsigned)(next4Bytes&0xFF) > 1) {
00614           // Common case: 0x00000001 or 0x000001 definitely doesn't begin anywhere in "next4Bytes", so we save all of it:
00615           save4Bytes(next4Bytes);
00616           skipBytes(4);
00617         } else {
00618           // Save the first byte, and continue testing the rest:
00619           saveByte(next4Bytes>>24);
00620           skipBytes(1);
00621         }
00622         setParseState(); // ensures forward progress
00623         next4Bytes = test4Bytes();
00624       }
00625       // Assert: next4Bytes starts with 0x00000001 or 0x000001, and we've saved all previous bytes (forming a complete NAL unit).
00626       // Skip over these remaining bytes, up until the start of the next NAL unit:
00627       if (next4Bytes == 0x00000001) {
00628         skipBytes(4);
00629       } else {
00630         skipBytes(3);
00631       }
00632     }
00633 
00634     u_int8_t nal_ref_idc = (fFirstByteOfNALUnit&0x60)>>5;
00635     u_int8_t nal_unit_type = fFirstByteOfNALUnit&0x1F;
00636     fHaveSeenFirstByteOfNALUnit = False; // for the next NAL unit that we parse
00637 #ifdef DEBUG
00638     fprintf(stderr, "Parsed %d-byte NAL-unit (nal_ref_idc: %d, nal_unit_type: %d (\"%s\"))\n",
00639             curFrameSize()-fOutputStartCodeSize, nal_ref_idc, nal_unit_type, nal_unit_type_description[nal_unit_type]);
00640 #endif
00641 
00642     switch (nal_unit_type) {
00643       case 6: { // Supplemental enhancement information (SEI)
00644         analyze_sei_data();
00645         // Later, perhaps adjust "fPresentationTime" if we saw a "pic_timing" SEI payload??? #####
00646         break;
00647       }
00648       case 7: { // Sequence parameter set
00649         // First, save a copy of this NAL unit, in case the downstream object wants to see it:
00650         usingSource()->saveCopyOfSPS(fStartOfFrame + fOutputStartCodeSize, fTo - fStartOfFrame - fOutputStartCodeSize);
00651 
00652         // Parse this NAL unit to check whether frame rate information is present:
00653         unsigned num_units_in_tick, time_scale, fixed_frame_rate_flag;
00654         analyze_seq_parameter_set_data(num_units_in_tick, time_scale, fixed_frame_rate_flag);
00655         if (time_scale > 0 && num_units_in_tick > 0) {
00656           usingSource()->fFrameRate = time_scale/(2.0*num_units_in_tick);
00657 #ifdef DEBUG
00658           fprintf(stderr, "Set frame rate to %f fps\n", usingSource()->fFrameRate);
00659           if (fixed_frame_rate_flag == 0) {
00660             fprintf(stderr, "\tWARNING: \"fixed_frame_rate_flag\" was not set\n");
00661           }
00662 #endif
00663         } else {
00664 #ifdef DEBUG
00665           fprintf(stderr, "\tThis \"Sequence Parameter Set\" NAL unit contained no frame rate information, so we use a default frame rate of %f fps\n", usingSource()->fFrameRate);
00666 #endif
00667         }
00668         break;
00669       }
00670       case 8: { // Picture parameter set
00671         // Save a copy of this NAL unit, in case the downstream object wants to see it:
00672         usingSource()->saveCopyOfPPS(fStartOfFrame + fOutputStartCodeSize, fTo - fStartOfFrame - fOutputStartCodeSize);
00673       }
00674     }
00675 
00676     usingSource()->setPresentationTime();
00677 #ifdef DEBUG
00678     unsigned long secs = (unsigned long)usingSource()->fPresentationTime.tv_sec;
00679     unsigned uSecs = (unsigned)usingSource()->fPresentationTime.tv_usec;
00680     fprintf(stderr, "\tPresentation time: %lu.%06u\n", secs, uSecs);
00681 #endif
00682 
00683     // If this NAL unit is a VCL NAL unit, we also scan the start of the next NAL unit, to determine whether this NAL unit
00684     // ends the current 'access unit'.  We need this information to figure out when to increment "fPresentationTime".
00685     // (RTP streamers also need to know this in order to figure out whether or not to set the "M" bit.)
00686     Boolean thisNALUnitEndsAccessUnit = False; // until we learn otherwise 
00687     if (haveSeenEOF()) {
00688       // There is no next NAL unit, so we assume that this one ends the current 'access unit':
00689       thisNALUnitEndsAccessUnit = True;
00690     } else {
00691       Boolean const isVCL = nal_unit_type <= 5 && nal_unit_type > 0; // Would need to include type 20 for SVC and MVC #####
00692       if (isVCL) {
00693         u_int32_t first4BytesOfNextNALUnit = test4Bytes();
00694         u_int8_t firstByteOfNextNALUnit = first4BytesOfNextNALUnit>>24;
00695         u_int8_t next_nal_ref_idc = (firstByteOfNextNALUnit&0x60)>>5;
00696         u_int8_t next_nal_unit_type = firstByteOfNextNALUnit&0x1F;
00697         if (next_nal_unit_type >= 6) {
00698           // The next NAL unit is not a VCL; therefore, we assume that this NAL unit ends the current 'access unit':
00699 #ifdef DEBUG
00700           fprintf(stderr, "\t(The next NAL unit is not a VCL)\n");
00701 #endif
00702           thisNALUnitEndsAccessUnit = True;
00703         } else {
00704           // The next NAL unit is also a VCL.  We need to examine it a little to figure out if it's a different 'access unit'.
00705           // (We use many of the criteria described in section 7.4.1.2.4 of the H.264 specification.)
00706           Boolean IdrPicFlag = nal_unit_type == 5;
00707           Boolean next_IdrPicFlag = next_nal_unit_type == 5;
00708           if (next_IdrPicFlag != IdrPicFlag) {
00709             // IdrPicFlag differs in value
00710 #ifdef DEBUG
00711             fprintf(stderr, "\t(IdrPicFlag differs in value)\n");
00712 #endif
00713             thisNALUnitEndsAccessUnit = True;
00714           } else if (next_nal_ref_idc != nal_ref_idc && next_nal_ref_idc*nal_ref_idc == 0) {
00715             // nal_ref_idc differs in value with one of the nal_ref_idc values being equal to 0
00716 #ifdef DEBUG
00717             fprintf(stderr, "\t(nal_ref_idc differs in value with one of the nal_ref_idc values being equal to 0)\n");
00718 #endif
00719             thisNALUnitEndsAccessUnit = True;
00720           } else if ((nal_unit_type == 1 || nal_unit_type == 2 || nal_unit_type == 5)
00721                      && (next_nal_unit_type == 1 || next_nal_unit_type == 2 || next_nal_unit_type == 5)) {
00722             // Both this and the next NAL units begin with a "slice_header".
00723             // Parse this (for each), to get parameters that we can compare:
00724             
00725             // Current NAL unit's "slice_header":
00726             unsigned frame_num, pic_parameter_set_id, idr_pic_id;
00727             Boolean field_pic_flag, bottom_field_flag;
00728             analyze_slice_header(fStartOfFrame + fOutputStartCodeSize, fTo, nal_unit_type,
00729                                  frame_num, pic_parameter_set_id, idr_pic_id, field_pic_flag, bottom_field_flag);
00730             
00731             // Next NAL unit's "slice_header":
00732 #ifdef DEBUG
00733             fprintf(stderr, "    Next NAL unit's slice_header:\n");
00734 #endif
00735             u_int8_t next_slice_header[NUM_NEXT_SLICE_HEADER_BYTES_TO_ANALYZE];
00736             testBytes(next_slice_header, sizeof next_slice_header);
00737             unsigned next_frame_num, next_pic_parameter_set_id, next_idr_pic_id;
00738             Boolean next_field_pic_flag, next_bottom_field_flag;
00739             analyze_slice_header(next_slice_header, &next_slice_header[sizeof next_slice_header], next_nal_unit_type,
00740                                  next_frame_num, next_pic_parameter_set_id, next_idr_pic_id, next_field_pic_flag, next_bottom_field_flag);
00741             
00742             if (next_frame_num != frame_num) {
00743               // frame_num differs in value
00744 #ifdef DEBUG
00745               fprintf(stderr, "\t(frame_num differs in value)\n");
00746 #endif
00747               thisNALUnitEndsAccessUnit = True;
00748             } else if (next_pic_parameter_set_id != pic_parameter_set_id) {
00749               // pic_parameter_set_id differs in value
00750 #ifdef DEBUG
00751               fprintf(stderr, "\t(pic_parameter_set_id differs in value)\n");
00752 #endif
00753               thisNALUnitEndsAccessUnit = True;
00754             } else if (next_field_pic_flag != field_pic_flag) {
00755               // field_pic_flag differs in value
00756 #ifdef DEBUG
00757               fprintf(stderr, "\t(field_pic_flag differs in value)\n");
00758 #endif
00759               thisNALUnitEndsAccessUnit = True;
00760             } else if (next_bottom_field_flag != bottom_field_flag) {
00761               // bottom_field_flag differs in value
00762 #ifdef DEBUG
00763               fprintf(stderr, "\t(bottom_field_flag differs in value)\n");
00764 #endif
00765               thisNALUnitEndsAccessUnit = True;
00766             } else if (next_IdrPicFlag == 1 && next_idr_pic_id != idr_pic_id) {
00767               // IdrPicFlag is equal to 1 for both and idr_pic_id differs in value
00768               // Note: We already know that IdrPicFlag is the same for both.
00769 #ifdef DEBUG
00770               fprintf(stderr, "\t(IdrPicFlag is equal to 1 for both and idr_pic_id differs in value)\n");
00771 #endif
00772               thisNALUnitEndsAccessUnit = True;
00773             }
00774           }
00775         }
00776       }
00777     }
00778         
00779     if (thisNALUnitEndsAccessUnit) {
00780 #ifdef DEBUG
00781       fprintf(stderr, "*****This NAL unit ends the current access unit*****\n");
00782 #endif
00783       usingSource()->fPictureEndMarker = True;
00784       ++usingSource()->fPictureCount;
00785 
00786       // Note that the presentation time for the next NAL unit will be different:
00787       struct timeval& nextPT = usingSource()->fNextPresentationTime; // alias
00788       nextPT = usingSource()->fPresentationTime;
00789       double nextFraction = nextPT.tv_usec/1000000.0 + 1/usingSource()->fFrameRate;
00790       unsigned nextSecsIncrement = (long)nextFraction;
00791       nextPT.tv_sec += (long)nextSecsIncrement;
00792       nextPT.tv_usec = (long)((nextFraction - nextSecsIncrement)*1000000);
00793     }
00794     setParseState();
00795 
00796     return curFrameSize();
00797   } catch (int /*e*/) {
00798 #ifdef DEBUG
00799     fprintf(stderr, "H264VideoStreamParser::parse() EXCEPTION (This is normal behavior - *not* an error)\n");
00800 #endif
00801     return 0;  // the parsing got interrupted
00802   }
00803 }

H264VideoStreamFramer* H264VideoStreamParser::usingSource (  )  [inline, private]

Definition at line 38 of file H264VideoStreamFramer.cpp.

References MPEGVideoStreamParser::fUsingSource.

Referenced by parse().

00038                                        {
00039     return (H264VideoStreamFramer*)fUsingSource;
00040   }

void H264VideoStreamParser::removeEmulationBytes ( u_int8_t *  nalUnitCopy,
unsigned  maxSize,
unsigned &  nalUnitCopySize 
) [private]

Definition at line 140 of file H264VideoStreamFramer.cpp.

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

Referenced by analyze_sei_data(), and analyze_seq_parameter_set_data().

00140                                                                                                                    {
00141   u_int8_t* nalUnitOrig = fStartOfFrame + fOutputStartCodeSize;
00142   unsigned const NumBytesInNALunit = fTo - nalUnitOrig;
00143   if (NumBytesInNALunit > maxSize) return;
00144   nalUnitCopySize = 0;
00145   for (unsigned i = 0; i < NumBytesInNALunit; ++i) {
00146     if (i+2 < NumBytesInNALunit && nalUnitOrig[i] == 0 && nalUnitOrig[i+1] == 0 && nalUnitOrig[i+2] == 3) {
00147       nalUnitCopy[nalUnitCopySize++] = nalUnitOrig[i++];
00148       nalUnitCopy[nalUnitCopySize++] = nalUnitOrig[i++];
00149     } else {
00150       nalUnitCopy[nalUnitCopySize++] = nalUnitOrig[i];
00151     }
00152   }
00153 }

void H264VideoStreamParser::analyze_seq_parameter_set_data ( unsigned &  num_units_in_tick,
unsigned &  time_scale,
unsigned &  fixed_frame_rate_flag 
) [private]

Definition at line 322 of file H264VideoStreamFramer.cpp.

References analyze_vui_parameters(), DEBUG_PRINT, DEBUG_TAB, frame_mbs_only_flag, BitVector::get1Bit(), BitVector::get_expGolomb(), BitVector::getBits(), log2_max_frame_num, removeEmulationBytes(), separate_colour_plane_flag, BitVector::skipBits(), and SPS_MAX_SIZE.

Referenced by parse().

00322                                                                                                                    {
00323   num_units_in_tick = time_scale = fixed_frame_rate_flag = 0; // default values
00324 
00325   // Begin by making a copy of the NAL unit data, removing any 'emulation prevention' bytes:
00326   u_int8_t sps[SPS_MAX_SIZE];
00327   unsigned spsSize;
00328   removeEmulationBytes(sps, sizeof sps, spsSize);
00329 
00330   BitVector bv(sps, 0, 8*spsSize);
00331 
00332   bv.skipBits(8); // forbidden_zero_bit; nal_ref_idc; nal_unit_type
00333   unsigned profile_idc = bv.getBits(8);
00334   DEBUG_PRINT(profile_idc);
00335   unsigned constraint_setN_flag = bv.getBits(8); // also "reserved_zero_2bits" at end
00336   DEBUG_PRINT(constraint_setN_flag);
00337   unsigned level_idc = bv.getBits(8);
00338   DEBUG_PRINT(level_idc);
00339   unsigned seq_parameter_set_id = bv.get_expGolomb();
00340   DEBUG_PRINT(seq_parameter_set_id);
00341   if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || profile_idc == 244 || profile_idc == 44 || profile_idc == 83 || profile_idc == 86 || profile_idc == 118 || profile_idc == 128 ) {
00342     DEBUG_TAB;
00343     unsigned chroma_format_idc = bv.get_expGolomb();
00344     DEBUG_PRINT(chroma_format_idc);
00345     if (chroma_format_idc == 3) {
00346       DEBUG_TAB;
00347       separate_colour_plane_flag = bv.get1Bit();
00348       DEBUG_PRINT(separate_colour_plane_flag);
00349     }
00350     (void)bv.get_expGolomb(); // bit_depth_luma_minus8
00351     (void)bv.get_expGolomb(); // bit_depth_chroma_minus8
00352     bv.skipBits(1); // qpprime_y_zero_transform_bypass_flag
00353     unsigned seq_scaling_matrix_present_flag = bv.get1Bit();
00354     DEBUG_PRINT(seq_scaling_matrix_present_flag);
00355     if (seq_scaling_matrix_present_flag) {
00356       for (int i = 0; i < ((chroma_format_idc != 3) ? 8 : 12); ++i) {
00357         DEBUG_TAB;
00358         DEBUG_PRINT(i);
00359         unsigned seq_scaling_list_present_flag = bv.get1Bit();
00360         DEBUG_PRINT(seq_scaling_list_present_flag);
00361         if (seq_scaling_list_present_flag) {
00362           DEBUG_TAB;
00363           unsigned sizeOfScalingList = i < 6 ? 16 : 64;
00364           unsigned lastScale = 8;
00365           unsigned nextScale = 8;
00366           for (unsigned j = 0; j < sizeOfScalingList; ++j) {
00367             DEBUG_TAB;
00368             DEBUG_PRINT(j);
00369             DEBUG_PRINT(nextScale);
00370             if (nextScale != 0) {
00371               DEBUG_TAB;
00372               unsigned delta_scale = bv.get_expGolomb();
00373               DEBUG_PRINT(delta_scale);
00374               nextScale = (lastScale + delta_scale + 256) % 256;
00375             }
00376             lastScale = (nextScale == 0) ? lastScale : nextScale;
00377             DEBUG_PRINT(lastScale);
00378           }
00379         }
00380       }
00381     }
00382   }
00383   unsigned log2_max_frame_num_minus4 = bv.get_expGolomb();
00384   DEBUG_PRINT(log2_max_frame_num_minus4);
00385   log2_max_frame_num = log2_max_frame_num_minus4 + 4;
00386   unsigned pic_order_cnt_type = bv.get_expGolomb();
00387   DEBUG_PRINT(pic_order_cnt_type);
00388   if (pic_order_cnt_type == 0) {
00389     DEBUG_TAB;
00390     unsigned log2_max_pic_order_cnt_lsb_minus4 = bv.get_expGolomb();
00391     DEBUG_PRINT(log2_max_pic_order_cnt_lsb_minus4);
00392   } else if (pic_order_cnt_type == 1) {
00393     DEBUG_TAB;
00394     bv.skipBits(1); // delta_pic_order_always_zero_flag
00395     (void)bv.get_expGolomb(); // offset_for_non_ref_pic
00396     (void)bv.get_expGolomb(); // offset_for_top_to_bottom_field
00397     unsigned num_ref_frames_in_pic_order_cnt_cycle = bv.get_expGolomb();
00398     DEBUG_PRINT(num_ref_frames_in_pic_order_cnt_cycle);
00399     for (unsigned i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; ++i) {
00400       (void)bv.get_expGolomb(); // offset_for_ref_frame[i]
00401     }
00402   }
00403   unsigned max_num_ref_frames = bv.get_expGolomb();
00404   DEBUG_PRINT(max_num_ref_frames);
00405   unsigned gaps_in_frame_num_value_allowed_flag = bv.get1Bit();
00406   DEBUG_PRINT(gaps_in_frame_num_value_allowed_flag);
00407   unsigned pic_width_in_mbs_minus1 = bv.get_expGolomb();
00408   DEBUG_PRINT(pic_width_in_mbs_minus1);
00409   unsigned pic_height_in_map_units_minus1 = bv.get_expGolomb();
00410   DEBUG_PRINT(pic_height_in_map_units_minus1);
00411   frame_mbs_only_flag = bv.get1Bit();
00412   DEBUG_PRINT(frame_mbs_only_flag);
00413   if (!frame_mbs_only_flag) {
00414     bv.skipBits(1); // mb_adaptive_frame_field_flag
00415   }
00416   bv.skipBits(1); // direct_8x8_inference_flag
00417   unsigned frame_cropping_flag = bv.get1Bit();
00418   DEBUG_PRINT(frame_cropping_flag);
00419   if (frame_cropping_flag) {
00420     (void)bv.get_expGolomb(); // frame_crop_left_offset
00421     (void)bv.get_expGolomb(); // frame_crop_right_offset
00422     (void)bv.get_expGolomb(); // frame_crop_top_offset
00423     (void)bv.get_expGolomb(); // frame_crop_bottom_offset
00424   }
00425   unsigned vui_parameters_present_flag = bv.get1Bit();
00426   DEBUG_PRINT(vui_parameters_present_flag);
00427   if (vui_parameters_present_flag) {
00428     DEBUG_TAB;
00429     analyze_vui_parameters(bv,num_units_in_tick, time_scale, fixed_frame_rate_flag);
00430   }
00431 }

void H264VideoStreamParser::analyze_vui_parameters ( BitVector bv,
unsigned &  num_units_in_tick,
unsigned &  time_scale,
unsigned &  fixed_frame_rate_flag 
) [private]

Definition at line 241 of file H264VideoStreamFramer.cpp.

References DEBUG_PRINT, DEBUG_STR, DEBUG_TAB, BitVector::get1Bit(), BitVector::get_expGolomb(), BitVector::getBits(), and BitVector::skipBits().

Referenced by analyze_seq_parameter_set_data().

00242                                                                                                              {
00243   DEBUG_STR("BEGIN vui_parameters");
00244   unsigned aspect_ratio_info_present_flag = bv.get1Bit();
00245   DEBUG_PRINT(aspect_ratio_info_present_flag);
00246   if (aspect_ratio_info_present_flag) {
00247     DEBUG_TAB;
00248     unsigned aspect_ratio_idc = bv.getBits(8);
00249     DEBUG_PRINT(aspect_ratio_idc);
00250     if (aspect_ratio_idc == 255/*Extended_SAR*/) {
00251       bv.skipBits(32); // sar_width; sar_height
00252     }
00253   }
00254   unsigned overscan_info_present_flag = bv.get1Bit();
00255   DEBUG_PRINT(overscan_info_present_flag);
00256   if (overscan_info_present_flag) {
00257     bv.skipBits(1); // overscan_appropriate_flag
00258   }
00259   unsigned video_signal_type_present_flag = bv.get1Bit();
00260   DEBUG_PRINT(video_signal_type_present_flag);
00261   if (video_signal_type_present_flag) {
00262     DEBUG_TAB;
00263     bv.skipBits(4); // video_format; video_full_range_flag
00264     unsigned colour_description_present_flag = bv.get1Bit();
00265     DEBUG_PRINT(colour_description_present_flag);
00266     if (colour_description_present_flag) {
00267       bv.skipBits(24); // colour_primaries; transfer_characteristics; matrix_coefficients
00268     }
00269   }
00270   unsigned chroma_loc_info_present_flag = bv.get1Bit();
00271   DEBUG_PRINT(chroma_loc_info_present_flag);
00272   if (chroma_loc_info_present_flag) {
00273     (void)bv.get_expGolomb(); // chroma_sample_loc_type_top_field
00274     (void)bv.get_expGolomb(); // chroma_sample_loc_type_bottom_field
00275   }
00276   unsigned timing_info_present_flag = bv.get1Bit();
00277   DEBUG_PRINT(timing_info_present_flag);
00278   if (timing_info_present_flag) {
00279     DEBUG_TAB;
00280     num_units_in_tick = bv.getBits(32);
00281     DEBUG_PRINT(num_units_in_tick);
00282     time_scale = bv.getBits(32);
00283     DEBUG_PRINT(time_scale);
00284     fixed_frame_rate_flag = bv.get1Bit();
00285     DEBUG_PRINT(fixed_frame_rate_flag);
00286   }
00287 #ifdef DO_FULL_SPS_PARSING
00288   unsigned nal_hrd_parameters_present_flag = bv.get1Bit();
00289   DEBUG_PRINT(nal_hrd_parameters_present_flag);
00290   if (nal_hrd_parameters_present_flag) {
00291     DEBUG_TAB;
00292     analyze_hrd_parameters(bv);
00293   }
00294   unsigned vcl_hrd_parameters_present_flag = bv.get1Bit();
00295   DEBUG_PRINT(vcl_hrd_parameters_present_flag);
00296   if (vcl_hrd_parameters_present_flag) {
00297     DEBUG_TAB;
00298     analyze_hrd_parameters(bv);
00299   }
00300   if (nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag) {
00301     bv.skipBits(1); // low_delay_hrd_flag
00302   }
00303   bv.skipBits(1); // pic_struct_present_flag
00304   unsigned bitstream_restriction_flag = bv.get1Bit();
00305   DEBUG_PRINT(bitstream_restriction_flag);
00306   if (bitstream_restriction_flag) {
00307     bv.skipBits(1); // motion_vectors_over_pic_boundaries_flag
00308     (void)bv.get_expGolomb(); // max_bytes_per_pic_denom
00309     (void)bv.get_expGolomb(); // max_bits_per_mb_denom
00310     (void)bv.get_expGolomb(); // log2_max_mv_length_horizontal
00311     (void)bv.get_expGolomb(); // log2_max_mv_length_vertical
00312     (void)bv.get_expGolomb(); // num_reorder_frames
00313     (void)bv.get_expGolomb(); // max_dec_frame_buffering
00314   }
00315   DEBUG_STR("END vui_parameters");
00316 #endif
00317 }

void H264VideoStreamParser::analyze_sei_data (  )  [private]

Definition at line 488 of file H264VideoStreamFramer.cpp.

References removeEmulationBytes(), and SEI_MAX_SIZE.

Referenced by parse().

00488                                              {
00489   // Begin by making a copy of the NAL unit data, removing any 'emulation prevention' bytes:
00490   u_int8_t sei[SEI_MAX_SIZE];
00491   unsigned seiSize;
00492   removeEmulationBytes(sei, sizeof sei, seiSize);
00493 
00494   unsigned j = 1; // skip the initial byte (forbidden_zero_bit; nal_ref_idc; nal_unit_type); we've already seen it 
00495   while (j < seiSize) {
00496     unsigned payloadType = 0;
00497     do {
00498       payloadType += sei[j];
00499     } while (sei[j++] == 255 && j < seiSize);
00500     if (j >= seiSize) break;
00501 
00502     unsigned payloadSize = 0;
00503     do {
00504       payloadSize += sei[j];
00505     } while (sei[j++] == 255 && j < seiSize);
00506     if (j >= seiSize) break;
00507 
00508 #ifdef DEBUG
00509     unsigned descriptionNum = payloadType <= MAX_SEI_PAYLOAD_TYPE_DESCRIPTION ? payloadType : MAX_SEI_PAYLOAD_TYPE_DESCRIPTION;
00510     fprintf(stderr, "\tpayloadType %d (\"%s\"); payloadSize %d\n", payloadType, sei_payloadType_description[descriptionNum], payloadSize);
00511 #endif
00512     j += payloadSize;
00513   }
00514 }

void H264VideoStreamParser::analyze_slice_header ( u_int8_t *  start,
u_int8_t *  end,
u_int8_t  nal_unit_type,
unsigned &  frame_num,
unsigned &  pic_parameter_set_id,
unsigned &  idr_pic_id,
Boolean field_pic_flag,
Boolean bottom_field_flag 
) [private]

Definition at line 517 of file H264VideoStreamFramer.cpp.

References DEBUG_PRINT, DEBUG_TAB, frame_mbs_only_flag, BitVector::get1Bit(), BitVector::get_expGolomb(), BitVector::getBits(), log2_max_frame_num, separate_colour_plane_flag, and BitVector::skipBits().

Referenced by parse().

00519                                                                             {
00520   BitVector bv(start, 0, 8*(end-start));
00521 
00522   // Some of the result parameters might not be present in the header; set them to default values:
00523   field_pic_flag = bottom_field_flag = 0;
00524 
00525   // Note: We assume that there aren't any 'emulation prevention' bytes here to worry about...
00526   bv.skipBits(8); // forbidden_zero_bit; nal_ref_idc; nal_unit_type
00527   unsigned first_mb_in_slice = bv.get_expGolomb();
00528   DEBUG_PRINT(first_mb_in_slice);
00529   unsigned slice_type = bv.get_expGolomb();
00530   DEBUG_PRINT(slice_type);
00531   pic_parameter_set_id = bv.get_expGolomb();
00532   DEBUG_PRINT(pic_parameter_set_id);
00533   if (separate_colour_plane_flag) {
00534     bv.skipBits(2); // colour_plane_id
00535   }
00536   frame_num = bv.getBits(log2_max_frame_num);
00537   DEBUG_PRINT(frame_num);
00538   if (!frame_mbs_only_flag) {
00539     DEBUG_TAB;
00540     field_pic_flag = bv.get1Bit();
00541     DEBUG_PRINT(field_pic_flag);
00542     if (field_pic_flag) {
00543       DEBUG_TAB;
00544       bottom_field_flag = bv.get1Bit();
00545       DEBUG_PRINT(bottom_field_flag);
00546     }
00547   }
00548   Boolean IdrPicFlag = nal_unit_type == 5;
00549   if (IdrPicFlag) {
00550     DEBUG_TAB;
00551     idr_pic_id = bv.get_expGolomb();
00552     DEBUG_PRINT(idr_pic_id);
00553   }
00554   // We don't parse any more of the "slice_header", because we don't need the remaining fields (for our purpose)
00555 }

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 MPEG4VideoStreamParser::flushInput(), MPEG1or2VideoStreamParser::flushInput(), parse(), MPEG1or2VideoStreamParser::parseGOPHeader(), MPEG4VideoStreamParser::parseGroupOfVideoObjectPlane(), MPEG1or2VideoStreamParser::parsePictureHeader(), MPEG1or2VideoStreamParser::parseSlice(), MPEG4VideoStreamParser::parseVideoObjectLayer(), MPEG4VideoStreamParser::parseVideoObjectPlane(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), MPEG4VideoStreamParser::parseVisualObject(), MPEG4VideoStreamParser::parseVisualObjectSequence(), MPEG4VideoStreamParser::parseVisualObjectSequenceEndCode(), MPEG4VideoStreamParser::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 parse(), MPEG4VideoStreamParser::parseGroupOfVideoObjectPlane(), MPEG4VideoStreamParser::parseVideoObjectPlane(), MPEG4VideoStreamParser::parseVisualObject(), MPEG4VideoStreamParser::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 parse(), MPEG1or2VideoStreamParser::parseGOPHeader(), MPEG4VideoStreamParser::parseGroupOfVideoObjectPlane(), MPEG1or2VideoStreamParser::parsePictureHeader(), MPEG4VideoStreamParser::parseVideoObjectPlane(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), MPEG4VideoStreamParser::parseVisualObject(), MPEG4VideoStreamParser::parseVisualObjectSequence(), MPEG4VideoStreamParser::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(), MPEG4VideoStreamParser::parseGroupOfVideoObjectPlane(), MPEG1or2VideoStreamParser::parsePictureHeader(), MPEG1or2VideoStreamParser::parseSlice(), MPEG4VideoStreamParser::parseVideoObjectLayer(), MPEG4VideoStreamParser::parseVideoObjectPlane(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), MPEG4VideoStreamParser::parseVisualObject(), and MPEG4VideoStreamParser::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 MPEG4VideoStreamParser::analyzeVOLHeader(), MPEG4VideoStreamParser::getNextFrameBit(), parse(), MPEG1or2VideoStreamParser::parseGOPHeader(), MPEG4VideoStreamParser::parseGroupOfVideoObjectPlane(), MPEG1or2VideoStreamParser::parsePictureHeader(), MPEG1or2VideoStreamParser::parseSlice(), MPEG4VideoStreamParser::parseVideoObjectLayer(), MPEG4VideoStreamParser::parseVideoObjectPlane(), MPEG1or2VideoStreamParser::parseVideoSequenceHeader(), MPEG4VideoStreamParser::parseVisualObject(), MPEG4VideoStreamParser::parseVisualObjectSequence(), MPEG4VideoStreamParser::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(), 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(), 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(), parse(), MatroskaFileParser::parseBlock(), MatroskaFileParser::parseEBMLNumber(), MatroskaFileParser::parseEBMLVal_binary(), MatroskaFileParser::parseEBMLVal_string(), MatroskaFileParser::parseEBMLVal_unsigned64(), MPEG1or2VideoStreamParser::parseGOPHeader(), H263plusVideoStreamParser::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   }

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(), MPEG4VideoStreamParser::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 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(), 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 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 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 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

unsigned H264VideoStreamParser::fOutputStartCodeSize [private]

Definition at line 56 of file H264VideoStreamFramer.cpp.

Referenced by parse(), and removeEmulationBytes().

Boolean H264VideoStreamParser::fHaveSeenFirstStartCode [private]

Definition at line 57 of file H264VideoStreamFramer.cpp.

Referenced by flushInput(), and parse().

Boolean H264VideoStreamParser::fHaveSeenFirstByteOfNALUnit [private]

Definition at line 57 of file H264VideoStreamFramer.cpp.

Referenced by flushInput(), and parse().

u_int8_t H264VideoStreamParser::fFirstByteOfNALUnit [private]

Definition at line 58 of file H264VideoStreamFramer.cpp.

Referenced by parse().

unsigned H264VideoStreamParser::log2_max_frame_num [private]

Definition at line 61 of file H264VideoStreamFramer.cpp.

Referenced by analyze_seq_parameter_set_data(), and analyze_slice_header().

Boolean H264VideoStreamParser::separate_colour_plane_flag [private]

Definition at line 62 of file H264VideoStreamFramer.cpp.

Referenced by analyze_seq_parameter_set_data(), and analyze_slice_header().

Boolean H264VideoStreamParser::frame_mbs_only_flag [private]

Definition at line 63 of file H264VideoStreamFramer.cpp.

Referenced by analyze_seq_parameter_set_data(), and analyze_slice_header().

MPEGVideoStreamFramer* MPEGVideoStreamParser::fUsingSource [protected, inherited]

Definition at line 107 of file MPEGVideoStreamParser.hh.

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

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

Definition at line 110 of file MPEGVideoStreamParser.hh.

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

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

Definition at line 111 of file MPEGVideoStreamParser.hh.

Referenced by MPEGVideoStreamParser::curFrameSize(), parse(), MPEGVideoStreamParser::registerReadInterest(), 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:24 2012 for live by  doxygen 1.5.2