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_
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/video_decoder_config.h"
17 #include "media/formats/mp2t/es_parser.h"
22 class OffsetByteQueue;
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;"
33 class EsParserH264 : public EsParser {
35 typedef base::Callback<void(const VideoDecoderConfig&)> NewVideoConfigCB;
37 EsParserH264(const NewVideoConfigCB& new_video_config_cb,
38 const EmitBufferCB& emit_buffer_cb);
39 virtual ~EsParserH264();
41 // EsParser implementation.
42 virtual bool Parse(const uint8* buf, int size,
44 base::TimeDelta dts) OVERRIDE;
45 virtual void Flush() OVERRIDE;
46 virtual void Reset() OVERRIDE;
54 // Find the AUD located at or after |*stream_pos|.
55 // Return true if an AUD is found.
56 // If found, |*stream_pos| corresponds to the position of the AUD start code
57 // in the stream. Otherwise, |*stream_pos| corresponds to the last position
58 // of the start code parser.
59 bool FindAUD(int64* stream_pos);
61 // Resumes the H264 ES parsing.
62 // Return true if successful.
65 // Emit a frame whose position in the ES queue starts at |access_unit_pos|.
66 // Returns true if successful, false if no PTS is available for the frame.
67 bool EmitFrame(int64 access_unit_pos, int access_unit_size,
68 bool is_key_frame, int pps_id);
70 // Update the video decoder config based on an H264 SPS.
71 // Return true if successful.
72 bool UpdateVideoDecoderConfig(const H264SPS* sps);
74 // Callbacks to pass the stream configuration and the frames.
75 NewVideoConfigCB new_video_config_cb_;
76 EmitBufferCB emit_buffer_cb_;
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_;
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_;