DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
es_parser_adts.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 MEDIA_FORMATS_MP2T_ES_PARSER_ADTS_H_
6 #define MEDIA_FORMATS_MP2T_ES_PARSER_ADTS_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 
18 namespace shaka {
19 namespace media {
20 class AudioTimestampHelper;
21 class BitReader;
22 
23 namespace mp2t {
24 
25 class EsParserAdts : public EsParser {
26  public:
27  EsParserAdts(uint32_t pid,
28  const NewStreamInfoCB& new_stream_info_cb,
29  const EmitSampleCB& emit_sample_cb,
30  bool sbr_in_mimetype);
31  ~EsParserAdts() override;
32 
33  // EsParser implementation.
34  bool Parse(const uint8_t* buf, int size, int64_t pts, int64_t dts) override;
35  void Flush() override;
36  void Reset() override;
37 
38  private:
39  // Used to link a PTS with a byte position in the ES stream.
40  typedef std::pair<int, int64_t> EsPts;
41  typedef std::list<EsPts> EsPtsList;
42 
43  // Signal any audio configuration change (if any).
44  // Return false if the current audio config is not
45  // a supported ADTS audio config.
46  bool UpdateAudioConfiguration(const uint8_t* adts_frame, size_t frame_size);
47 
48  // Discard some bytes from the ES stream.
49  void DiscardEs(int nbytes);
50 
51  // Callbacks:
52  // - to signal a new audio configuration,
53  // - to send ES buffers.
54  NewStreamInfoCB new_stream_info_cb_;
55  EmitSampleCB emit_sample_cb_;
56 
57  // True when AAC SBR extension is signalled in the mimetype
58  // (mp4a.40.5 in the codecs parameter).
59  bool sbr_in_mimetype_;
60 
61  // Bytes of the ES stream that have not been emitted yet.
62  ByteQueue es_byte_queue_;
63 
64  // List of PTS associated with a position in the ES stream.
65  EsPtsList pts_list_;
66 
67  // Interpolated PTS for frames that don't have one.
68  std::unique_ptr<AudioTimestampHelper> audio_timestamp_helper_;
69 
70  scoped_refptr<StreamInfo> last_audio_decoder_config_;
71 
72  DISALLOW_COPY_AND_ASSIGN(EsParserAdts);
73 };
74 
75 } // namespace mp2t
76 } // namespace media
77 } // namespace shaka
78 
79 #endif