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

Side by Side Diff: media/mpeg2/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: Address comments from patch set #3 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_MPEG2_ES_PARSER_H264_H_
6 #define MEDIA_MPEG2_ES_PARSER_H264_H_
7
8 #include <list>
9 #include <utility>
10 #include <vector>
damienv1 2013/09/10 04:57:01 <vector> not needed anymore.
damienv1 2013/09/10 21:03:48 Done.
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
38 EsParserH264(NewVideoConfigCB new_video_config_cb,
39 EmitBufferCB emit_buffer_cb);
40 virtual ~EsParserH264();
41
42 // EsParser implementation.
43 virtual bool Parse(const uint8* buf, int size,
44 base::TimeDelta pts,
45 base::TimeDelta dts) OVERRIDE;
46 virtual void Flush() OVERRIDE;
47 virtual void Reset() 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 // Find all the NALs in the ES byte queue
72 // starting from position |nal_es_pos_|.
73 void FindNals();
74
75 // Split the list of NALs into access units.
76 // Return a list of iterators pointing to the 1st NAL of each access unit.
77 void FindAccessUnits(
78 std::list<NalDescList::const_iterator>* access_unit_list);
79
80 // Emit a frame whose first NAL is given by |cur_frame|.
81 // The frame includes all the NALs located between |cur_frame| (included)
82 // and |nxt_frame| (not included).
83 // Return true if successful.
84 bool EmitFrame(NalDescList::const_iterator& cur_frame,
85 NalDescList::const_iterator& nxt_frame,
86 int nxt_frame_position);
87
88 // Discard |nbytes| of ES from the ES byte queue.
89 void DiscardEs(int nbytes);
90
91 // Parse a NAL / SPS.
92 // Returns true if successful (compliant bitstream).
93 bool NalParser(const uint8* buf, int size);
94 bool ProcessSPS(const uint8* buf, int size);
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.
damienv1 2013/09/10 04:57:01 Should use a VideoDecoderConfig instead of all the
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698