- add sources.
[platform/framework/web/crosswalk.git] / src / media / mp2t / es_parser_adts.h
1 // Copyright 2013 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_MP2T_ES_PARSER_ADTS_H_
6 #define MEDIA_MP2T_ES_PARSER_ADTS_H_
7
8 #include <list>
9 #include <utility>
10
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
15 #include "media/base/audio_decoder_config.h"
16 #include "media/base/byte_queue.h"
17 #include "media/mp2t/es_parser.h"
18
19 namespace media {
20 class AudioTimestampHelper;
21 class BitReader;
22 class StreamParserBuffer;
23 }
24
25 namespace media {
26 namespace mp2t {
27
28 class EsParserAdts : public EsParser {
29  public:
30   typedef base::Callback<void(const AudioDecoderConfig&)> NewAudioConfigCB;
31
32   EsParserAdts(const NewAudioConfigCB& new_audio_config_cb,
33                const EmitBufferCB& emit_buffer_cb);
34   virtual ~EsParserAdts();
35
36   // EsParser implementation.
37   virtual bool Parse(const uint8* buf, int size,
38                      base::TimeDelta pts,
39                      base::TimeDelta dts) OVERRIDE;
40   virtual void Flush() OVERRIDE;
41   virtual void Reset() OVERRIDE;
42
43  private:
44   // Used to link a PTS with a byte position in the ES stream.
45   typedef std::pair<int, base::TimeDelta> EsPts;
46   typedef std::list<EsPts> EsPtsList;
47
48   // Signal any audio configuration change (if any).
49   // Return false if the current audio config is not
50   // a supported ADTS audio config.
51   bool UpdateAudioConfiguration(const uint8* adts_header);
52
53   // Discard some bytes from the ES stream.
54   void DiscardEs(int nbytes);
55
56   // Callbacks:
57   // - to signal a new audio configuration,
58   // - to send ES buffers.
59   NewAudioConfigCB new_audio_config_cb_;
60   EmitBufferCB emit_buffer_cb_;
61
62   // Bytes of the ES stream that have not been emitted yet.
63   ByteQueue es_byte_queue_;
64
65   // List of PTS associated with a position in the ES stream.
66   EsPtsList pts_list_;
67
68   // Interpolated PTS for frames that don't have one.
69   scoped_ptr<AudioTimestampHelper> audio_timestamp_helper_;
70
71   // Last audio config.
72   AudioDecoderConfig last_audio_decoder_config_;
73
74   DISALLOW_COPY_AND_ASSIGN(EsParserAdts);
75 };
76
77 }  // namespace mp2t
78 }  // namespace media
79
80 #endif
81