Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / base / audio_decoder_config.h
blobc9c85938f5a7d37ecd14dbc45c8c85544da38c3e
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.
5 #ifndef MEDIA_BASE_AUDIO_DECODER_CONFIG_H_
6 #define MEDIA_BASE_AUDIO_DECODER_CONFIG_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/time/time.h"
13 #include "media/base/channel_layout.h"
14 #include "media/base/media_export.h"
15 #include "media/base/sample_format.h"
17 namespace media {
19 enum AudioCodec {
20 // These values are histogrammed over time; do not change their ordinal
21 // values. When deleting a codec replace it with a dummy value; when adding a
22 // codec, do so at the bottom before kAudioCodecMax, and update the value of
23 // kAudioCodecMax to equal the new codec.
24 kUnknownAudioCodec = 0,
25 kCodecAAC = 1,
26 kCodecMP3 = 2,
27 kCodecPCM = 3,
28 kCodecVorbis = 4,
29 kCodecFLAC = 5,
30 kCodecAMR_NB = 6,
31 kCodecAMR_WB = 7,
32 kCodecPCM_MULAW = 8,
33 kCodecGSM_MS = 9,
34 kCodecPCM_S16BE = 10,
35 kCodecPCM_S24BE = 11,
36 kCodecOpus = 12,
37 // kCodecEAC3 = 13,
38 kCodecPCM_ALAW = 14,
39 kCodecALAC = 15,
40 // DO NOT ADD RANDOM AUDIO CODECS!
42 // The only acceptable time to add a new codec is if there is production code
43 // that uses said codec in the same CL.
45 // Must always be equal to the largest entry ever logged.
46 kAudioCodecMax = kCodecALAC,
49 // TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of
50 // |bits_per_channel|, we should switch over since bits are generally confusing
51 // to work with.
52 class MEDIA_EXPORT AudioDecoderConfig {
53 public:
54 // Constructs an uninitialized object. Clients should call Initialize() with
55 // appropriate values before using.
56 AudioDecoderConfig();
58 // Constructs an initialized object. It is acceptable to pass in NULL for
59 // |extra_data|, otherwise the memory is copied.
60 AudioDecoderConfig(AudioCodec codec, SampleFormat sample_format,
61 ChannelLayout channel_layout, int samples_per_second,
62 const uint8* extra_data, size_t extra_data_size,
63 bool is_encrypted);
65 ~AudioDecoderConfig();
67 // Resets the internal state of this object. |codec_delay| is in frames.
68 void Initialize(AudioCodec codec,
69 SampleFormat sample_format,
70 ChannelLayout channel_layout,
71 int samples_per_second,
72 const uint8* extra_data,
73 size_t extra_data_size,
74 bool is_encrypted,
75 base::TimeDelta seek_preroll,
76 int codec_delay);
78 // Returns true if this object has appropriate configuration values, false
79 // otherwise.
80 bool IsValidConfig() const;
82 // Returns true if all fields in |config| match this config.
83 // Note: The contents of |extra_data_| are compared not the raw pointers.
84 bool Matches(const AudioDecoderConfig& config) const;
86 // Returns a human-readable string describing |*this|. For debugging & test
87 // output only.
88 std::string AsHumanReadableString() const;
90 std::string GetHumanReadableCodecName() const;
92 AudioCodec codec() const { return codec_; }
93 int bits_per_channel() const { return bytes_per_channel_ * 8; }
94 int bytes_per_channel() const { return bytes_per_channel_; }
95 ChannelLayout channel_layout() const { return channel_layout_; }
96 int samples_per_second() const { return samples_per_second_; }
97 SampleFormat sample_format() const { return sample_format_; }
98 int bytes_per_frame() const { return bytes_per_frame_; }
99 base::TimeDelta seek_preroll() const { return seek_preroll_; }
100 int codec_delay() const { return codec_delay_; }
102 // Optional byte data required to initialize audio decoders such as Vorbis
103 // codebooks.
104 const uint8* extra_data() const {
105 return extra_data_.empty() ? NULL : &extra_data_[0];
107 size_t extra_data_size() const { return extra_data_.size(); }
109 // Whether the audio stream is potentially encrypted.
110 // Note that in a potentially encrypted audio stream, individual buffers
111 // can be encrypted or not encrypted.
112 bool is_encrypted() const { return is_encrypted_; }
114 private:
115 AudioCodec codec_;
116 SampleFormat sample_format_;
117 int bytes_per_channel_;
118 ChannelLayout channel_layout_;
119 int samples_per_second_;
120 int bytes_per_frame_;
121 std::vector<uint8> extra_data_;
122 bool is_encrypted_;
124 // |seek_preroll_| is the duration of the data that the decoder must decode
125 // before the decoded data is valid.
126 base::TimeDelta seek_preroll_;
128 // |codec_delay_| is the number of frames the decoder should discard before
129 // returning decoded data. This value can include both decoder delay as well
130 // as padding added during encoding.
131 int codec_delay_;
133 // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
134 // generated copy constructor and assignment operator. Since the extra data is
135 // typically small, the performance impact is minimal.
138 } // namespace media
140 #endif // MEDIA_BASE_AUDIO_DECODER_CONFIG_H_