DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs
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 <utility>
10 
11 #include "packager/base/callback.h"
12 #include "packager/base/compiler_specific.h"
13 #include "packager/base/memory/scoped_ptr.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 edash_packager {
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  virtual ~EsParserAdts();
32 
33  // EsParser implementation.
34  virtual bool Parse(const uint8_t* buf,
35  int size,
36  int64_t pts,
37  int64_t dts) OVERRIDE;
38  virtual void Flush() OVERRIDE;
39  virtual void Reset() OVERRIDE;
40 
41  private:
42  // Used to link a PTS with a byte position in the ES stream.
43  typedef std::pair<int, int64_t> EsPts;
44  typedef std::list<EsPts> EsPtsList;
45 
46  // Signal any audio configuration change (if any).
47  // Return false if the current audio config is not
48  // a supported ADTS audio config.
49  bool UpdateAudioConfiguration(const uint8_t* adts_frame, size_t frame_size);
50 
51  // Discard some bytes from the ES stream.
52  void DiscardEs(int nbytes);
53 
54  // Callbacks:
55  // - to signal a new audio configuration,
56  // - to send ES buffers.
57  NewStreamInfoCB new_stream_info_cb_;
58  EmitSampleCB emit_sample_cb_;
59 
60  // True when AAC SBR extension is signalled in the mimetype
61  // (mp4a.40.5 in the codecs parameter).
62  bool sbr_in_mimetype_;
63 
64  // Bytes of the ES stream that have not been emitted yet.
65  ByteQueue es_byte_queue_;
66 
67  // List of PTS associated with a position in the ES stream.
68  EsPtsList pts_list_;
69 
70  // Interpolated PTS for frames that don't have one.
71  scoped_ptr<AudioTimestampHelper> audio_timestamp_helper_;
72 
73  scoped_refptr<StreamInfo> last_audio_decoder_config_;
74 
75  DISALLOW_COPY_AND_ASSIGN(EsParserAdts);
76 };
77 
78 } // namespace mp2t
79 } // namespace media
80 } // namespace edash_packager
81 
82 #endif