Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: media/mp2t/es_parser_h264.h

Issue 23566013: Mpeg2 TS stream parser for media source. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup - address comments from patch set #8 Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/time/time.h"
15 #include "media/base/byte_queue.h"
16 #include "media/mp2t/es_parser.h"
17
18 namespace media {
19 class BitReader;
20 class VideoDecoderConfig;
21 class StreamParserBuffer;
22 }
23
24 namespace media {
25 namespace mp2t {
26
27 // Remark:
28 // In this h264 parser, frame splitting is based on AUD nals.
29 // Mpeg2 TS spec: "2.14 Carriage of Rec. ITU-T H.264 | ISO/IEC 14496-10 video"
30 // "Each AVC access unit shall contain an access unit delimiter NAL Unit;"
31 //
32 class EsParserH264 : public EsParser {
33 public:
34 typedef base::Callback<void(const VideoDecoderConfig&)> NewVideoConfigCB;
35
36 EsParserH264(NewVideoConfigCB new_video_config_cb,
37 EmitBufferCB emit_buffer_cb);
38 virtual ~EsParserH264();
39
40 // EsParser implementation.
41 virtual bool Parse(const uint8* buf, int size,
42 base::TimeDelta pts,
43 base::TimeDelta dts) OVERRIDE;
44 virtual void Flush() OVERRIDE;
45 virtual void Reset() OVERRIDE;
46
47 private:
48 enum NalUnitType {
49 kNalUnitTypeInvalid = -1,
50 kNalUnitTypeNonIdrSlice = 1,
51 kNalUnitTypeIdrSlice = 5,
52 kNalUnitTypeSPS = 7,
53 kNalUnitTypePPS = 8,
54 kNalUnitTypeAUD = 9,
55 };
56
57 struct NalDesc {
58 // Position of the NAL start code.
59 int position;
60 NalUnitType nal_unit_type;
61 };
62 typedef std::list<NalDesc> NalDescList;
63
64 struct TimingDesc {
65 base::TimeDelta dts;
66 base::TimeDelta pts;
67 };
68
69 // Find all the NALs in the ES byte queue
70 // starting from position |nal_es_pos_|.
71 void FindNals();
72
73 // Split the list of NALs into access units.
74 // Return a list of iterators pointing to the 1st NAL of each access unit.
75 void FindAccessUnits(
76 std::list<NalDescList::const_iterator>* access_unit_list);
77
78 // Emit a frame whose first NAL is given by |cur_frame|.
79 // The frame includes all the NALs located between |cur_frame| (included)
80 // and |nxt_frame| (not included).
81 // Return true if successful.
82 bool EmitFrame(NalDescList::const_iterator& cur_frame,
83 NalDescList::const_iterator& nxt_frame,
84 int nxt_frame_position);
85
86 // Discard |nbytes| of ES from the ES byte queue.
87 void DiscardEs(int nbytes);
88
89 // Parse a NAL / SPS.
90 // Returns true if successful (compliant bitstream).
91 bool NalParser(const uint8* buf, int size);
92 bool ProcessSPS(const uint8* buf, int size);
93
94 // Bytes of the ES stream that have not been emitted yet.
95 ByteQueue es_byte_queue_;
96 std::list<std::pair<int, TimingDesc> > timing_desc_list_;
97
98 // NAL segmentation.
99 NalDescList nal_desc_list_;
100 int nal_es_pos_;
101
102 // Callbacks to pass the stream configuration and the frames.
103 NewVideoConfigCB new_video_config_cb_;
104 EmitBufferCB emit_buffer_cb_;
105
106 // Last video decoder config.
107 bool is_video_config_known_;
108 int profile_idc_;
109 int level_idc_;
110 uint32 pic_width_in_mbs_minus1_;
111 uint32 pic_height_in_map_units_minus1_;
112 };
113
114 } // namespace mp2t
115 } // namespace media
116
117 #endif
118
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698