- add sources.
[platform/framework/web/crosswalk.git] / src / media / base / audio_decoder_config.h
1 // Copyright (c) 2012 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_BASE_AUDIO_DECODER_CONFIG_H_
6 #define MEDIA_BASE_AUDIO_DECODER_CONFIG_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/time/time.h"
12 #include "media/base/channel_layout.h"
13 #include "media/base/media_export.h"
14 #include "media/base/sample_format.h"
15
16 namespace media {
17
18 enum AudioCodec {
19   // These values are histogrammed over time; do not change their ordinal
20   // values.  When deleting a codec replace it with a dummy value; when adding a
21   // codec, do so at the bottom before kAudioCodecMax.
22   kUnknownAudioCodec = 0,
23   kCodecAAC,
24   kCodecMP3,
25   kCodecPCM,
26   kCodecVorbis,
27   kCodecFLAC,
28   kCodecAMR_NB,
29   kCodecAMR_WB,
30   kCodecPCM_MULAW,
31   kCodecGSM_MS,
32   kCodecPCM_S16BE,
33   kCodecPCM_S24BE,
34   kCodecOpus,
35   kCodecEAC3,
36   // DO NOT ADD RANDOM AUDIO CODECS!
37   //
38   // The only acceptable time to add a new codec is if there is production code
39   // that uses said codec in the same CL.
40
41   // Must always be last!
42   kAudioCodecMax
43 };
44
45 // TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of
46 // |bits_per_channel|, we should switch over since bits are generally confusing
47 // to work with.
48 class MEDIA_EXPORT AudioDecoderConfig {
49  public:
50   // Constructs an uninitialized object. Clients should call Initialize() with
51   // appropriate values before using.
52   AudioDecoderConfig();
53
54   // Constructs an initialized object. It is acceptable to pass in NULL for
55   // |extra_data|, otherwise the memory is copied.
56   AudioDecoderConfig(AudioCodec codec, SampleFormat sample_format,
57                      ChannelLayout channel_layout, int samples_per_second,
58                      const uint8* extra_data, size_t extra_data_size,
59                      bool is_encrypted);
60
61   ~AudioDecoderConfig();
62
63   // Resets the internal state of this object.
64   void Initialize(AudioCodec codec, SampleFormat sample_format,
65                   ChannelLayout channel_layout, int samples_per_second,
66                   const uint8* extra_data, size_t extra_data_size,
67                   bool is_encrypted, bool record_stats,
68                   base::TimeDelta seek_preroll,
69                   base::TimeDelta codec_delay);
70
71   // Returns true if this object has appropriate configuration values, false
72   // otherwise.
73   bool IsValidConfig() const;
74
75   // Returns true if all fields in |config| match this config.
76   // Note: The contents of |extra_data_| are compared not the raw pointers.
77   bool Matches(const AudioDecoderConfig& config) const;
78
79   AudioCodec codec() const { return codec_; }
80   int bits_per_channel() const { return bytes_per_channel_ * 8; }
81   int bytes_per_channel() const { return bytes_per_channel_; }
82   ChannelLayout channel_layout() const { return channel_layout_; }
83   int samples_per_second() const { return samples_per_second_; }
84   SampleFormat sample_format() const { return sample_format_; }
85   int bytes_per_frame() const { return bytes_per_frame_; }
86   base::TimeDelta seek_preroll() const { return seek_preroll_; }
87   base::TimeDelta codec_delay() const { return codec_delay_; }
88
89   // Optional byte data required to initialize audio decoders such as Vorbis
90   // codebooks.
91   const uint8* extra_data() const {
92     return extra_data_.empty() ? NULL : &extra_data_[0];
93   }
94   size_t extra_data_size() const { return extra_data_.size(); }
95
96   // Whether the audio stream is potentially encrypted.
97   // Note that in a potentially encrypted audio stream, individual buffers
98   // can be encrypted or not encrypted.
99   bool is_encrypted() const { return is_encrypted_; }
100
101  private:
102   AudioCodec codec_;
103   SampleFormat sample_format_;
104   int bytes_per_channel_;
105   ChannelLayout channel_layout_;
106   int samples_per_second_;
107   int bytes_per_frame_;
108   std::vector<uint8> extra_data_;
109   bool is_encrypted_;
110
111   // |seek_preroll_| is the duration of the data that the decoder must decode
112   // before the decoded data is valid.
113   base::TimeDelta seek_preroll_;
114
115   // |codec_delay_| is the overall delay overhead added by the codec while
116   // encoding. This value should be subtracted from each block's timestamp to
117   // get the actual timestamp.
118   base::TimeDelta codec_delay_;
119
120   // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
121   // generated copy constructor and assignment operator. Since the extra data is
122   // typically small, the performance impact is minimal.
123 };
124
125 }  // namespace media
126
127 #endif  // MEDIA_BASE_AUDIO_DECODER_CONFIG_H_