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/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"
24 class OffsetByteQueue
;
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;"
34 // - PES packets do not necessarily map to an H264 access unit although the HLS
35 // recommendation is to use one PES for each access unit. In this parser,
36 // we handle the general case and do not make any assumption about the access
37 // unit organization within PES packets.
39 class MEDIA_EXPORT EsParserH264
: public EsParser
{
41 typedef base::Callback
<void(const VideoDecoderConfig
&)> NewVideoConfigCB
;
43 EsParserH264(const NewVideoConfigCB
& new_video_config_cb
,
44 const EmitBufferCB
& emit_buffer_cb
);
45 ~EsParserH264() override
;
47 // EsParser implementation.
48 void Flush() override
;
51 // EsParser implementation.
52 bool ParseFromEsQueue() override
;
53 void ResetInternal() override
;
55 // Find the AUD located at or after |*stream_pos|.
56 // Return true if an AUD is found.
57 // If found, |*stream_pos| corresponds to the position of the AUD start code
58 // in the stream. Otherwise, |*stream_pos| corresponds to the last position
59 // of the start code parser.
60 bool FindAUD(int64
* stream_pos
);
62 // Emit a frame whose position in the ES queue starts at |access_unit_pos|.
63 // Returns true if successful, false if no PTS is available for the frame.
64 bool EmitFrame(int64 access_unit_pos
, int access_unit_size
,
65 bool is_key_frame
, int pps_id
);
67 // Update the video decoder config based on an H264 SPS.
68 // Return true if successful.
69 bool UpdateVideoDecoderConfig(const H264SPS
* sps
);
71 EsAdapterVideo es_adapter_
;
74 // - |current_access_unit_pos_| is pointing to an annexB syncword
75 // representing the first NALU of an H264 access unit.
76 scoped_ptr
<H264Parser
> h264_parser_
;
77 int64 current_access_unit_pos_
;
78 int64 next_access_unit_pos_
;
80 // Last video decoder config.
81 VideoDecoderConfig last_video_decoder_config_
;
83 DISALLOW_COPY_AND_ASSIGN(EsParserH264
);