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