OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_MPEG2_ES_PARSER_H264_H_ |
| 6 #define MEDIA_MPEG2_ES_PARSER_H264_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <utility> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" |
| 14 #include "base/compiler_specific.h" |
| 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/time/time.h" |
| 17 #include "media/mpeg2/es_parser.h" |
| 18 |
| 19 namespace media { |
| 20 class BitReader; |
| 21 class VideoDecoderConfig; |
| 22 class StreamParserBuffer; |
| 23 } |
| 24 |
| 25 namespace media { |
| 26 namespace mpeg2ts { |
| 27 |
| 28 // Remark: |
| 29 // In this h264 parser, frame splitting is based on AUD nals. |
| 30 // Mpeg2 TS spec: "2.14 Carriage of Rec. ITU-T H.264 | ISO/IEC 14496-10 video" |
| 31 // "Each AVC access unit shall contain an access unit delimiter NAL Unit;" |
| 32 // |
| 33 class EsParserH264 : public EsParser { |
| 34 public: |
| 35 typedef base::Callback<void(const VideoDecoderConfig&)> NewVideoConfigCB; |
| 36 typedef base::Callback<void(scoped_refptr<StreamParserBuffer>)> EmitBufferCB; |
| 37 |
| 38 EsParserH264(NewVideoConfigCB new_video_config_cb, |
| 39 EmitBufferCB emit_buffer_cb); |
| 40 virtual ~EsParserH264(); |
| 41 |
| 42 // EsParser implementation. |
| 43 virtual void Parse(const uint8* buf, int size, |
| 44 bool is_pts_valid, base::TimeDelta pts, |
| 45 bool is_dts_valid, base::TimeDelta dts) OVERRIDE; |
| 46 virtual void Flush() OVERRIDE; |
| 47 |
| 48 private: |
| 49 enum NalUnitType { |
| 50 kNalUnitTypeInvalid = -1, |
| 51 kNalUnitTypeNonIdrSlice = 1, |
| 52 kNalUnitTypeIdrSlice = 5, |
| 53 kNalUnitTypeSPS = 7, |
| 54 kNalUnitTypePPS = 8, |
| 55 kNalUnitTypeAUD = 9, |
| 56 }; |
| 57 |
| 58 struct NalDesc { |
| 59 // Position of the NAL start code. |
| 60 int position; |
| 61 // Nal type. |
| 62 NalUnitType nal_unit_type; |
| 63 }; |
| 64 typedef std::list<NalDesc> NalDescList; |
| 65 |
| 66 struct TimingDesc { |
| 67 base::TimeDelta dts; |
| 68 base::TimeDelta pts; |
| 69 }; |
| 70 |
| 71 void FindNals(const uint8* buf, int size); |
| 72 void FindAccessUnits(std::list<NalDescList::iterator>* access_unit_list); |
| 73 void EmitFrame(NalDescList::iterator cur_frame, |
| 74 NalDescList::iterator nxt_frame, |
| 75 int nxt_frame_position); |
| 76 void DiscardEs(int nbytes); |
| 77 |
| 78 void NalParser(const uint8* buf, int size); |
| 79 bool ProcessSPS(const uint8* buf, int size); |
| 80 bool ProcessSliceLayer(const uint8* buf, int size); |
| 81 bool ReadBitsExpGolomb(BitReader* bit_reader, uint32* exp_golomb_value); |
| 82 |
| 83 // Bytes of the ES stream that have not been emitted yet. |
| 84 std::vector<uint8> raw_es_; |
| 85 std::list<std::pair<int, TimingDesc> > timing_desc_list_; |
| 86 |
| 87 // NAL segmentation. |
| 88 NalDescList nal_desc_list_; |
| 89 int nal_es_pos_; |
| 90 |
| 91 // Callbacks to pass the stream configuration and the frames. |
| 92 NewVideoConfigCB new_video_config_cb_; |
| 93 EmitBufferCB emit_buffer_cb_; |
| 94 |
| 95 // Last video decoder config. |
| 96 bool is_video_config_known_; |
| 97 int profile_idc_; |
| 98 int level_idc_; |
| 99 uint32 pic_width_in_mbs_minus1_; |
| 100 uint32 pic_height_in_map_units_minus1_; |
| 101 }; |
| 102 |
| 103 } // namespace mpeg2ts |
| 104 } // namespace media |
| 105 |
| 106 #endif |
OLD | NEW |