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_MP2T_ES_PARSER_H264_H_ | |
6 #define MEDIA_MP2T_ES_PARSER_H264_H_ | |
7 | |
8 #include <list> | |
9 #include <utility> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/callback.h" | |
13 #include "base/compiler_specific.h" | |
14 #include "base/memory/ref_counted.h" | |
damienv1
2013/09/12 20:43:02
Not needed here.
damienv1
2013/09/12 20:53:51
Done.
| |
15 #include "base/time/time.h" | |
16 #include "media/base/byte_queue.h" | |
17 #include "media/mp2t/es_parser.h" | |
18 | |
19 namespace media { | |
20 class BitReader; | |
21 class VideoDecoderConfig; | |
22 class StreamParserBuffer; | |
23 } | |
24 | |
25 namespace media { | |
26 namespace mp2t { | |
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 | |
37 EsParserH264(NewVideoConfigCB new_video_config_cb, | |
38 EmitBufferCB emit_buffer_cb); | |
39 virtual ~EsParserH264(); | |
40 | |
41 // EsParser implementation. | |
42 virtual bool Parse(const uint8* buf, int size, | |
43 base::TimeDelta pts, | |
44 base::TimeDelta dts) OVERRIDE; | |
45 virtual void Flush() OVERRIDE; | |
46 virtual void Reset() 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 NalUnitType nal_unit_type; | |
62 }; | |
63 typedef std::list<NalDesc> NalDescList; | |
64 | |
65 struct TimingDesc { | |
66 base::TimeDelta dts; | |
67 base::TimeDelta pts; | |
68 }; | |
69 | |
70 // Find all the NALs in the ES byte queue | |
71 // starting from position |nal_es_pos_|. | |
72 void FindNals(); | |
73 | |
74 // Split the list of NALs into access units. | |
75 // Return a list of iterators pointing to the 1st NAL of each access unit. | |
76 void FindAccessUnits( | |
77 std::list<NalDescList::const_iterator>* access_unit_list); | |
78 | |
79 // Emit a frame whose first NAL is given by |cur_frame|. | |
80 // The frame includes all the NALs located between |cur_frame| (included) | |
81 // and |nxt_frame| (not included). | |
82 // Return true if successful. | |
83 bool EmitFrame(NalDescList::const_iterator& cur_frame, | |
84 NalDescList::const_iterator& nxt_frame, | |
85 int nxt_frame_position); | |
86 | |
87 // Discard |nbytes| of ES from the ES byte queue. | |
88 void DiscardEs(int nbytes); | |
89 | |
90 // Parse a NAL / SPS. | |
91 // Returns true if successful (compliant bitstream). | |
92 bool NalParser(const uint8* buf, int size); | |
93 bool ProcessSPS(const uint8* buf, int size); | |
94 | |
95 // Bytes of the ES stream that have not been emitted yet. | |
96 ByteQueue es_byte_queue_; | |
97 std::list<std::pair<int, TimingDesc> > timing_desc_list_; | |
98 | |
99 // NAL segmentation. | |
100 NalDescList nal_desc_list_; | |
101 int nal_es_pos_; | |
102 | |
103 // Callbacks to pass the stream configuration and the frames. | |
104 NewVideoConfigCB new_video_config_cb_; | |
105 EmitBufferCB emit_buffer_cb_; | |
106 | |
107 // Last video decoder config. | |
108 bool is_video_config_known_; | |
109 int profile_idc_; | |
110 int level_idc_; | |
111 uint32 pic_width_in_mbs_minus1_; | |
112 uint32 pic_height_in_map_units_minus1_; | |
113 }; | |
114 | |
115 } // namespace mp2t | |
116 } // namespace media | |
117 | |
118 #endif | |
119 | |
OLD | NEW |