Add integration browser tests for settings hardening.
[chromium-blink-merge.git] / media / formats / mp2t / es_parser_h264.h
blob674b2c650a9c5be50e63a6c5a802806ba58c5c91
1 // Copyright 2014 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.
5 #ifndef MEDIA_FORMATS_MP2T_ES_PARSER_H264_H_
6 #define MEDIA_FORMATS_MP2T_ES_PARSER_H264_H_
8 #include <list>
9 #include <utility>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/time/time.h"
16 #include "media/base/media_export.h"
17 #include "media/base/video_decoder_config.h"
18 #include "media/formats/mp2t/es_adapter_video.h"
19 #include "media/formats/mp2t/es_parser.h"
21 namespace media {
22 class H264Parser;
23 struct H264SPS;
24 class OffsetByteQueue;
27 namespace media {
28 namespace mp2t {
30 // Remark:
31 // In this h264 parser, frame splitting is based on AUD nals.
32 // Mpeg2 TS spec: "2.14 Carriage of Rec. ITU-T H.264 | ISO/IEC 14496-10 video"
33 // "Each AVC access unit shall contain an access unit delimiter NAL Unit;"
35 class MEDIA_EXPORT EsParserH264 : NON_EXPORTED_BASE(public EsParser) {
36 public:
37 typedef base::Callback<void(const VideoDecoderConfig&)> NewVideoConfigCB;
39 EsParserH264(const NewVideoConfigCB& new_video_config_cb,
40 const EmitBufferCB& emit_buffer_cb);
41 virtual ~EsParserH264();
43 // EsParser implementation.
44 virtual bool Parse(const uint8* buf, int size,
45 base::TimeDelta pts,
46 base::TimeDelta dts) OVERRIDE;
47 virtual void Flush() OVERRIDE;
48 virtual void Reset() OVERRIDE;
50 private:
51 struct TimingDesc {
52 base::TimeDelta dts;
53 base::TimeDelta pts;
56 // Find the AUD located at or after |*stream_pos|.
57 // Return true if an AUD is found.
58 // If found, |*stream_pos| corresponds to the position of the AUD start code
59 // in the stream. Otherwise, |*stream_pos| corresponds to the last position
60 // of the start code parser.
61 bool FindAUD(int64* stream_pos);
63 // Resumes the H264 ES parsing.
64 // Return true if successful.
65 bool ParseInternal();
67 // Emit a frame whose position in the ES queue starts at |access_unit_pos|.
68 // Returns true if successful, false if no PTS is available for the frame.
69 bool EmitFrame(int64 access_unit_pos, int access_unit_size,
70 bool is_key_frame, int pps_id);
72 // Update the video decoder config based on an H264 SPS.
73 // Return true if successful.
74 bool UpdateVideoDecoderConfig(const H264SPS* sps);
76 EsAdapterVideo es_adapter_;
78 // Bytes of the ES stream that have not been emitted yet.
79 scoped_ptr<media::OffsetByteQueue> es_queue_;
80 std::list<std::pair<int64, TimingDesc> > timing_desc_list_;
82 // H264 parser state.
83 // - |current_access_unit_pos_| is pointing to an annexB syncword
84 // representing the first NALU of an H264 access unit.
85 scoped_ptr<H264Parser> h264_parser_;
86 int64 current_access_unit_pos_;
87 int64 next_access_unit_pos_;
89 // Last video decoder config.
90 VideoDecoderConfig last_video_decoder_config_;
92 DISALLOW_COPY_AND_ASSIGN(EsParserH264);
95 } // namespace mp2t
96 } // namespace media
98 #endif