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