Shaka Packager SDK
Loading...
Searching...
No Matches
es_parser_audio.h
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.
4
5#ifndef PACKAGER_MEDIA_FORMATS_MP2T_ES_PARSER_AUDIO_H_
6#define PACKAGER_MEDIA_FORMATS_MP2T_ES_PARSER_AUDIO_H_
7
8#include <cstdint>
9#include <list>
10#include <memory>
11#include <utility>
12
13#include <packager/media/base/byte_queue.h>
14#include <packager/media/formats/mp2t/es_parser.h>
15#include <packager/media/formats/mp2t/ts_stream_type.h>
16
17namespace shaka {
18namespace media {
19class AudioTimestampHelper;
20class BitReader;
21
22namespace mp2t {
23
24class AudioHeader;
25
26class EsParserAudio : public EsParser {
27 public:
28 EsParserAudio(uint32_t pid,
29 TsStreamType stream_type,
30 const NewStreamInfoCB& new_stream_info_cb,
31 const EmitSampleCB& emit_sample_cb,
32 bool sbr_in_mimetype);
33 ~EsParserAudio() override;
34
35 // EsParser implementation.
36 bool Parse(const uint8_t* buf, int size, int64_t pts, int64_t dts) override;
37 bool Flush() override;
38 void Reset() override;
39
40 private:
41 EsParserAudio(const EsParserAudio&) = delete;
42 EsParserAudio& operator=(const EsParserAudio&) = delete;
43
44 // Used to link a PTS with a byte position in the ES stream.
45 typedef std::pair<int, int64_t> EsPts;
46 typedef std::list<EsPts> EsPtsList;
47
48 // Signal any audio configuration change (if any).
49 // Return false if the current audio config is not a supported audio config.
50 bool UpdateAudioConfiguration(const AudioHeader& audio_header);
51
52 // Discard some bytes from the ES stream.
53 void DiscardEs(int nbytes);
54
55 const TsStreamType stream_type_;
56 std::unique_ptr<AudioHeader> audio_header_;
57
58 // Callbacks:
59 // - to signal a new audio configuration,
60 // - to send ES buffers.
61 NewStreamInfoCB new_stream_info_cb_;
62 EmitSampleCB emit_sample_cb_;
63
64 // True when AAC SBR extension is signalled in the mimetype
65 // (mp4a.40.5 in the codecs parameter).
66 bool sbr_in_mimetype_;
67
68 // Bytes of the ES stream that have not been emitted yet.
69 ByteQueue es_byte_queue_;
70
71 // List of PTS associated with a position in the ES stream.
72 EsPtsList pts_list_;
73
74 // Interpolated PTS for frames that don't have one.
75 std::unique_ptr<AudioTimestampHelper> audio_timestamp_helper_;
76
77 std::shared_ptr<StreamInfo> last_audio_decoder_config_;
78};
79
80} // namespace mp2t
81} // namespace media
82} // namespace shaka
83
84#endif // PACKAGER_MEDIA_FORMATS_MP2T_ES_PARSER_AUDIO_H_
All the methods that are virtual are virtual for mocking.