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.
|
|
|
|
|
2017-10-23 05:58:52 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_FORMATS_MP2T_ES_PARSER_AUDIO_H_
|
|
|
|
#define PACKAGER_MEDIA_FORMATS_MP2T_ES_PARSER_AUDIO_H_
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
#include <list>
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
2014-04-01 01:34:59 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2023-08-31 23:59:46 +00:00
|
|
|
#include <functional>
|
|
|
|
#include "packager/macros.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/audio_stream_info.h"
|
|
|
|
#include "packager/media/base/byte_queue.h"
|
|
|
|
#include "packager/media/formats/mp2t/es_parser.h"
|
2017-10-23 05:38:55 +00:00
|
|
|
#include "packager/media/formats/mp2t/ts_stream_type.h"
|
2014-04-01 01:34:59 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-04-01 01:34:59 +00:00
|
|
|
namespace media {
|
|
|
|
class AudioTimestampHelper;
|
|
|
|
class BitReader;
|
|
|
|
|
|
|
|
namespace mp2t {
|
|
|
|
|
2017-10-23 05:27:27 +00:00
|
|
|
class AudioHeader;
|
|
|
|
|
2017-10-23 05:58:52 +00:00
|
|
|
class EsParserAudio : public EsParser {
|
2014-04-01 01:34:59 +00:00
|
|
|
public:
|
2017-10-23 05:58:52 +00:00
|
|
|
EsParserAudio(uint32_t pid,
|
2017-10-23 05:38:55 +00:00
|
|
|
TsStreamType stream_type,
|
2017-10-23 05:58:52 +00:00
|
|
|
const NewStreamInfoCB& new_stream_info_cb,
|
|
|
|
const EmitSampleCB& emit_sample_cb,
|
|
|
|
bool sbr_in_mimetype);
|
|
|
|
~EsParserAudio() override;
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
// EsParser implementation.
|
2015-07-22 23:40:45 +00:00
|
|
|
bool Parse(const uint8_t* buf, int size, int64_t pts, int64_t dts) override;
|
2020-12-10 23:03:41 +00:00
|
|
|
bool Flush() override;
|
2015-07-22 23:40:45 +00:00
|
|
|
void Reset() override;
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
private:
|
2017-10-23 05:58:52 +00:00
|
|
|
EsParserAudio(const EsParserAudio&) = delete;
|
|
|
|
EsParserAudio& operator=(const EsParserAudio&) = delete;
|
|
|
|
|
2014-04-01 01:34:59 +00:00
|
|
|
// Used to link a PTS with a byte position in the ES stream.
|
2014-09-30 21:52:21 +00:00
|
|
|
typedef std::pair<int, int64_t> EsPts;
|
2014-04-01 01:34:59 +00:00
|
|
|
typedef std::list<EsPts> EsPtsList;
|
|
|
|
|
|
|
|
// Signal any audio configuration change (if any).
|
2017-10-23 05:27:27 +00:00
|
|
|
// Return false if the current audio config is not a supported audio config.
|
|
|
|
bool UpdateAudioConfiguration(const AudioHeader& audio_header);
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
// Discard some bytes from the ES stream.
|
|
|
|
void DiscardEs(int nbytes);
|
|
|
|
|
2017-10-23 05:38:55 +00:00
|
|
|
const TsStreamType stream_type_;
|
2017-10-23 05:27:27 +00:00
|
|
|
std::unique_ptr<AudioHeader> audio_header_;
|
|
|
|
|
2014-04-01 01:34:59 +00:00
|
|
|
// Callbacks:
|
|
|
|
// - to signal a new audio configuration,
|
|
|
|
// - to send ES buffers.
|
2014-04-10 19:57:10 +00:00
|
|
|
NewStreamInfoCB new_stream_info_cb_;
|
2014-04-07 17:48:25 +00:00
|
|
|
EmitSampleCB emit_sample_cb_;
|
2014-04-01 01:34:59 +00:00
|
|
|
|
|
|
|
// True when AAC SBR extension is signalled in the mimetype
|
|
|
|
// (mp4a.40.5 in the codecs parameter).
|
|
|
|
bool sbr_in_mimetype_;
|
|
|
|
|
|
|
|
// Bytes of the ES stream that have not been emitted yet.
|
|
|
|
ByteQueue es_byte_queue_;
|
|
|
|
|
|
|
|
// List of PTS associated with a position in the ES stream.
|
|
|
|
EsPtsList pts_list_;
|
|
|
|
|
|
|
|
// Interpolated PTS for frames that don't have one.
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<AudioTimestampHelper> audio_timestamp_helper_;
|
2014-04-01 01:34:59 +00:00
|
|
|
|
2017-01-24 00:55:02 +00:00
|
|
|
std::shared_ptr<StreamInfo> last_audio_decoder_config_;
|
2014-04-01 01:34:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp2t
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2014-04-01 01:34:59 +00:00
|
|
|
|
2017-10-23 05:58:52 +00:00
|
|
|
#endif // PACKAGER_MEDIA_FORMATS_MP2T_ES_PARSER_AUDIO_H_
|