 Chromium Code Reviews
 Chromium Code Reviews Issue 23566013:
  Mpeg2 TS stream parser for media source.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 23566013:
  Mpeg2 TS stream parser for media source.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: media/mpeg2/es_parser_h264.h | 
| diff --git a/media/mpeg2/es_parser_h264.h b/media/mpeg2/es_parser_h264.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..0a8da32946df83207b3025e5f71feef581b458f6 | 
| --- /dev/null | 
| +++ b/media/mpeg2/es_parser_h264.h | 
| @@ -0,0 +1,119 @@ | 
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#ifndef MEDIA_MPEG2_ES_PARSER_H264_H_ | 
| +#define MEDIA_MPEG2_ES_PARSER_H264_H_ | 
| + | 
| +#include <list> | 
| +#include <utility> | 
| +#include <vector> | 
| + | 
| +#include "base/basictypes.h" | 
| +#include "base/callback.h" | 
| +#include "base/compiler_specific.h" | 
| +#include "base/memory/ref_counted.h" | 
| +#include "base/time/time.h" | 
| +#include "media/base/byte_queue.h" | 
| +#include "media/mpeg2/es_parser.h" | 
| + | 
| +namespace media { | 
| +class BitReader; | 
| +class VideoDecoderConfig; | 
| +class StreamParserBuffer; | 
| +} | 
| + | 
| +namespace media { | 
| +namespace mpeg2ts { | 
| + | 
| +// Remark: | 
| +// In this h264 parser, frame splitting is based on AUD nals. | 
| +// Mpeg2 TS spec: "2.14 Carriage of Rec. ITU-T H.264 | ISO/IEC 14496-10 video" | 
| +// "Each AVC access unit shall contain an access unit delimiter NAL Unit;" | 
| +// | 
| +class EsParserH264 : public EsParser { | 
| + public: | 
| + typedef base::Callback<void(const VideoDecoderConfig&)> NewVideoConfigCB; | 
| + typedef base::Callback<void(scoped_refptr<StreamParserBuffer>)> EmitBufferCB; | 
| 
acolwell GONE FROM CHROMIUM
2013/09/05 18:29:10
nit: Perhaps move this to EsParser.h since it is d
 
damienv1
2013/09/09 23:29:45
Done.
 | 
| + | 
| + EsParserH264(NewVideoConfigCB new_video_config_cb, | 
| + EmitBufferCB emit_buffer_cb); | 
| + virtual ~EsParserH264(); | 
| + | 
| + // EsParser implementation. | 
| + virtual void Parse(const uint8* buf, int size, | 
| + base::TimeDelta pts, | 
| + base::TimeDelta dts) OVERRIDE; | 
| + virtual void Flush() OVERRIDE; | 
| + | 
| + private: | 
| + enum NalUnitType { | 
| + kNalUnitTypeInvalid = -1, | 
| + kNalUnitTypeNonIdrSlice = 1, | 
| + kNalUnitTypeIdrSlice = 5, | 
| + kNalUnitTypeSPS = 7, | 
| + kNalUnitTypePPS = 8, | 
| + kNalUnitTypeAUD = 9, | 
| + }; | 
| + | 
| + struct NalDesc { | 
| + // Position of the NAL start code. | 
| + int position; | 
| + NalUnitType nal_unit_type; | 
| + }; | 
| + typedef std::list<NalDesc> NalDescList; | 
| + | 
| + struct TimingDesc { | 
| + base::TimeDelta dts; | 
| + base::TimeDelta pts; | 
| + }; | 
| + | 
| 
acolwell GONE FROM CHROMIUM
2013/09/05 18:29:10
nit: remove extra line.
 
damienv1
2013/09/09 23:29:45
Done.
 | 
| + | 
| + void FindNals(const uint8* buf, int size); | 
| 
acolwell GONE FROM CHROMIUM
2013/09/05 18:29:10
docs for this and the method below.
 
damienv1
2013/09/09 23:29:45
Done.
 | 
| + | 
| + void FindAccessUnits(std::list<NalDescList::iterator>* access_unit_list); | 
| + | 
| + // Emit a frame whose first NAL is given by |cur_frame|. | 
| + // The frame includes all the NALs located between |cur_frame| | 
| + // and |nxt_frame| (not included). | 
| 
acolwell GONE FROM CHROMIUM
2013/09/05 18:29:10
nit: The "between" and "not included" seems to mak
 
damienv1
2013/09/09 23:29:45
Done.
 | 
| + void EmitFrame(NalDescList::iterator cur_frame, | 
| + NalDescList::iterator nxt_frame, | 
| + int nxt_frame_position); | 
| + | 
| + void DiscardEs(int nbytes); | 
| + | 
| + void NalParser(const uint8* buf, int size); | 
| + | 
| + // Parse a SPS / Slice layer. | 
| + // Returns true if successful (compliant bitstream). | 
| + bool ProcessSPS(const uint8* buf, int size); | 
| + bool ProcessSliceLayer(const uint8* buf, int size); | 
| + | 
| + // Helper function to read an unsigned exp-golomb value. | 
| + // TODO(damienv): should be part of the BitReader class. | 
| + bool ReadBitsExpGolomb(BitReader* bit_reader, uint32* exp_golomb_value); | 
| + | 
| + // Bytes of the ES stream that have not been emitted yet. | 
| + ByteQueue es_byte_queue_; | 
| + std::list<std::pair<int, TimingDesc> > timing_desc_list_; | 
| + | 
| + // NAL segmentation. | 
| + NalDescList nal_desc_list_; | 
| + int nal_es_pos_; | 
| + | 
| + // Callbacks to pass the stream configuration and the frames. | 
| + NewVideoConfigCB new_video_config_cb_; | 
| + EmitBufferCB emit_buffer_cb_; | 
| + | 
| + // Last video decoder config. | 
| + bool is_video_config_known_; | 
| + int profile_idc_; | 
| + int level_idc_; | 
| + uint32 pic_width_in_mbs_minus1_; | 
| + uint32 pic_height_in_map_units_minus1_; | 
| +}; | 
| + | 
| +} // namespace mpeg2ts | 
| +} // namespace media | 
| + | 
| +#endif |