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/base/byte_queue.h" |
| 18 #include "media/mpeg2/es_parser.h" |
| 19 |
| 20 namespace media { |
| 21 class BitReader; |
| 22 class VideoDecoderConfig; |
| 23 class StreamParserBuffer; |
| 24 } |
| 25 |
| 26 namespace media { |
| 27 namespace mpeg2ts { |
| 28 |
| 29 // Remark: |
| 30 // In this h264 parser, frame splitting is based on AUD nals. |
| 31 // Mpeg2 TS spec: "2.14 Carriage of Rec. ITU-T H.264 | ISO/IEC 14496-10 video" |
| 32 // "Each AVC access unit shall contain an access unit delimiter NAL Unit;" |
| 33 // |
| 34 class EsParserH264 : public EsParser { |
| 35 public: |
| 36 typedef base::Callback<void(const VideoDecoderConfig&)> NewVideoConfigCB; |
| 37 typedef base::Callback<void(scoped_refptr<StreamParserBuffer>)> EmitBufferCB; |
| 38 |
| 39 EsParserH264(NewVideoConfigCB new_video_config_cb, |
| 40 EmitBufferCB emit_buffer_cb); |
| 41 virtual ~EsParserH264(); |
| 42 |
| 43 // EsParser implementation. |
| 44 virtual void Parse(const uint8* buf, int size, |
| 45 base::TimeDelta pts, |
| 46 base::TimeDelta dts) OVERRIDE; |
| 47 virtual void Flush() OVERRIDE; |
| 48 |
| 49 private: |
| 50 enum NalUnitType { |
| 51 kNalUnitTypeInvalid = -1, |
| 52 kNalUnitTypeNonIdrSlice = 1, |
| 53 kNalUnitTypeIdrSlice = 5, |
| 54 kNalUnitTypeSPS = 7, |
| 55 kNalUnitTypePPS = 8, |
| 56 kNalUnitTypeAUD = 9, |
| 57 }; |
| 58 |
| 59 struct NalDesc { |
| 60 // Position of the NAL start code. |
| 61 int position; |
| 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 |
| 72 void FindNals(const uint8* buf, int size); |
| 73 |
| 74 void FindAccessUnits(std::list<NalDescList::iterator>* access_unit_list); |
| 75 |
| 76 // Emit a frame whose first NAL is given by |cur_frame|. |
| 77 // The frame includes all the NALs located between |cur_frame| |
| 78 // and |nxt_frame| (not included). |
| 79 void EmitFrame(NalDescList::iterator cur_frame, |
| 80 NalDescList::iterator nxt_frame, |
| 81 int nxt_frame_position); |
| 82 |
| 83 void DiscardEs(int nbytes); |
| 84 |
| 85 void NalParser(const uint8* buf, int size); |
| 86 |
| 87 // Parse a SPS / Slice layer. |
| 88 // Returns true if successful (compliant bitstream). |
| 89 bool ProcessSPS(const uint8* buf, int size); |
| 90 bool ProcessSliceLayer(const uint8* buf, int size); |
| 91 |
| 92 // Helper function to read an unsigned exp-golomb value. |
| 93 // TODO(damienv): should be part of the BitReader class. |
| 94 bool ReadBitsExpGolomb(BitReader* bit_reader, uint32* exp_golomb_value); |
| 95 |
| 96 // Bytes of the ES stream that have not been emitted yet. |
| 97 ByteQueue es_byte_queue_; |
| 98 std::list<std::pair<int, TimingDesc> > timing_desc_list_; |
| 99 |
| 100 // NAL segmentation. |
| 101 NalDescList nal_desc_list_; |
| 102 int nal_es_pos_; |
| 103 |
| 104 // Callbacks to pass the stream configuration and the frames. |
| 105 NewVideoConfigCB new_video_config_cb_; |
| 106 EmitBufferCB emit_buffer_cb_; |
| 107 |
| 108 // Last video decoder config. |
| 109 bool is_video_config_known_; |
| 110 int profile_idc_; |
| 111 int level_idc_; |
| 112 uint32 pic_width_in_mbs_minus1_; |
| 113 uint32 pic_height_in_map_units_minus1_; |
| 114 }; |
| 115 |
| 116 } // namespace mpeg2ts |
| 117 } // namespace media |
| 118 |
| 119 #endif |
| 120 |
OLD | NEW |