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