Fix some surprising reverse key mappings.
[chromium-blink-merge.git] / media / formats / mp2t / es_parser_adts.h
blob03c90110e76704135b293f435c199b3e0300b912
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.
5 #ifndef MEDIA_FORMATS_MP2T_ES_PARSER_ADTS_H_
6 #define MEDIA_FORMATS_MP2T_ES_PARSER_ADTS_H_
8 #include <list>
9 #include <utility>
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/formats/mp2t/es_parser.h"
18 namespace media {
19 class AudioTimestampHelper;
20 class BitReader;
21 class OffsetByteQueue;
22 class StreamParserBuffer;
25 namespace media {
26 namespace mp2t {
28 class EsParserAdts : public EsParser {
29 public:
30 typedef base::Callback<void(const AudioDecoderConfig&)> NewAudioConfigCB;
32 EsParserAdts(const NewAudioConfigCB& new_audio_config_cb,
33 const EmitBufferCB& emit_buffer_cb,
34 bool sbr_in_mimetype);
35 virtual ~EsParserAdts();
37 // EsParser implementation.
38 virtual bool Parse(const uint8* buf, int size,
39 base::TimeDelta pts,
40 base::TimeDelta dts) OVERRIDE;
41 virtual void Flush() OVERRIDE;
42 virtual void Reset() OVERRIDE;
44 private:
45 // Used to link a PTS with a byte position in the ES stream.
46 typedef std::pair<int64, base::TimeDelta> EsPts;
47 typedef std::list<EsPts> EsPtsList;
49 struct AdtsFrame;
51 // Synchronize the stream on an ADTS syncword (consuming bytes from
52 // |es_queue_| if needed).
53 // Returns true when a full ADTS frame has been found: in that case
54 // |adts_frame| structure is filled up accordingly.
55 // Returns false otherwise (no ADTS syncword found or partial ADTS frame).
56 bool LookForAdtsFrame(AdtsFrame* adts_frame);
58 // Skip an ADTS frame in the ES queue.
59 void SkipAdtsFrame(const AdtsFrame& adts_frame);
61 // Signal any audio configuration change (if any).
62 // Return false if the current audio config is not
63 // a supported ADTS audio config.
64 bool UpdateAudioConfiguration(const uint8* adts_header);
66 // Callbacks:
67 // - to signal a new audio configuration,
68 // - to send ES buffers.
69 NewAudioConfigCB new_audio_config_cb_;
70 EmitBufferCB emit_buffer_cb_;
72 // True when AAC SBR extension is signalled in the mimetype
73 // (mp4a.40.5 in the codecs parameter).
74 bool sbr_in_mimetype_;
76 // Bytes of the ES stream that have not been emitted yet.
77 scoped_ptr<media::OffsetByteQueue> es_queue_;
79 // List of PTS associated with a position in the ES stream.
80 EsPtsList pts_list_;
82 // Interpolated PTS for frames that don't have one.
83 scoped_ptr<AudioTimestampHelper> audio_timestamp_helper_;
85 // Last audio config.
86 AudioDecoderConfig last_audio_decoder_config_;
88 DISALLOW_COPY_AND_ASSIGN(EsParserAdts);
91 } // namespace mp2t
92 } // namespace media
94 #endif