2014-04-01 01:34:59 +00:00
|
|
|
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef MEDIA_FORMATS_MP2T_ES_PARSER_H264_H_
|
|
|
|
#define MEDIA_FORMATS_MP2T_ES_PARSER_H264_H_
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "base/callback.h"
|
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
#include "base/memory/scoped_ptr.h"
|
|
|
|
#include "media/formats/mp2t/es_parser.h"
|
|
|
|
|
|
|
|
namespace media {
|
2014-04-08 00:39:14 +00:00
|
|
|
|
2014-04-18 01:57:31 +00:00
|
|
|
class H264ByteToUnitStreamConverter;
|
2014-04-01 01:34:59 +00:00
|
|
|
class H264Parser;
|
2014-04-16 23:22:31 +00:00
|
|
|
class OffsetByteQueue;
|
2014-04-01 01:34:59 +00:00
|
|
|
struct H264SPS;
|
2014-04-16 23:22:31 +00:00
|
|
|
|
2014-04-08 00:39:14 +00:00
|
|
|
} // namespace media
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
namespace media {
|
|
|
|
namespace mp2t {
|
|
|
|
|
|
|
|
// Remark:
|
|
|
|
// In this h264 parser, frame splitting is based on AUD nals.
|
|
|
|
// Mpeg2 TS spec: "2.14 Carriage of Rec. ITU-T H.264 | ISO/IEC 14496-10 video"
|
|
|
|
// "Each AVC access unit shall contain an access unit delimiter NAL Unit;"
|
|
|
|
//
|
2014-04-08 00:39:14 +00:00
|
|
|
class EsParserH264 : public EsParser {
|
2014-04-01 01:34:59 +00:00
|
|
|
public:
|
2014-04-10 19:57:10 +00:00
|
|
|
EsParserH264(uint32 pid,
|
|
|
|
const NewStreamInfoCB& new_stream_info_cb,
|
2014-04-08 00:39:14 +00:00
|
|
|
const EmitSampleCB& emit_sample_cb);
|
2014-04-01 01:34:59 +00:00
|
|
|
virtual ~EsParserH264();
|
|
|
|
|
2014-04-16 23:22:31 +00:00
|
|
|
// EsParser implementation overrides.
|
2014-04-08 00:39:14 +00:00
|
|
|
virtual bool Parse(const uint8* buf, int size, int64 pts, int64 dts) OVERRIDE;
|
2014-04-01 01:34:59 +00:00
|
|
|
virtual void Flush() OVERRIDE;
|
|
|
|
virtual void Reset() OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct TimingDesc {
|
2014-04-08 00:39:14 +00:00
|
|
|
int64 dts;
|
|
|
|
int64 pts;
|
2014-04-01 01:34:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Find the AUD located at or after |*stream_pos|.
|
|
|
|
// Return true if an AUD is found.
|
|
|
|
// If found, |*stream_pos| corresponds to the position of the AUD start code
|
|
|
|
// in the stream. Otherwise, |*stream_pos| corresponds to the last position
|
|
|
|
// of the start code parser.
|
|
|
|
bool FindAUD(int64* stream_pos);
|
|
|
|
|
|
|
|
// Resumes the H264 ES parsing.
|
|
|
|
// Return true if successful.
|
|
|
|
bool ParseInternal();
|
|
|
|
|
|
|
|
// Emit a frame whose position in the ES queue starts at |access_unit_pos|.
|
|
|
|
// Returns true if successful, false if no PTS is available for the frame.
|
|
|
|
bool EmitFrame(int64 access_unit_pos, int access_unit_size,
|
|
|
|
bool is_key_frame, int pps_id);
|
|
|
|
|
|
|
|
// Update the video decoder config based on an H264 SPS.
|
|
|
|
// Return true if successful.
|
2014-04-16 23:22:31 +00:00
|
|
|
bool UpdateVideoDecoderConfig(const H264SPS* sps);
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
// Callbacks to pass the stream configuration and the frames.
|
2014-04-10 19:57:10 +00:00
|
|
|
NewStreamInfoCB new_stream_info_cb_;
|
2014-04-08 00:39:14 +00:00
|
|
|
EmitSampleCB emit_sample_cb_;
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
// Bytes of the ES stream that have not been emitted yet.
|
|
|
|
scoped_ptr<media::OffsetByteQueue> es_queue_;
|
|
|
|
std::list<std::pair<int64, TimingDesc> > timing_desc_list_;
|
|
|
|
|
|
|
|
// H264 parser state.
|
|
|
|
// - |current_access_unit_pos_| is pointing to an annexB syncword
|
|
|
|
// representing the first NALU of an H264 access unit.
|
2014-04-16 23:22:31 +00:00
|
|
|
scoped_ptr<H264Parser> h264_parser_;
|
2014-04-01 01:34:59 +00:00
|
|
|
int64 current_access_unit_pos_;
|
|
|
|
int64 next_access_unit_pos_;
|
|
|
|
|
2014-04-18 01:57:31 +00:00
|
|
|
// Filter to convert H.264 Annex B byte stream to unit stream.
|
|
|
|
scoped_ptr<H264ByteToUnitStreamConverter> stream_converter_;
|
|
|
|
|
2014-04-01 01:34:59 +00:00
|
|
|
// Last video decoder config.
|
2014-04-10 19:57:10 +00:00
|
|
|
scoped_refptr<StreamInfo> last_video_decoder_config_;
|
2014-04-18 01:57:31 +00:00
|
|
|
bool decoder_config_check_pending_;
|
|
|
|
|
|
|
|
// Frame for which we do not yet have a duration.
|
|
|
|
scoped_refptr<MediaSample> pending_sample_;
|
|
|
|
uint64 pending_sample_duration_;
|
2014-04-01 01:34:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp2t
|
|
|
|
} // namespace media
|
|
|
|
|
|
|
|
#endif
|