OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_AUDIO_DECODER_CONFIG_H_ | 5 #ifndef MEDIA_BASE_AUDIO_DECODER_CONFIG_H_ |
6 #define MEDIA_BASE_AUDIO_DECODER_CONFIG_H_ | 6 #define MEDIA_BASE_AUDIO_DECODER_CONFIG_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "media/base/channel_layout.h" | 10 #include "media/base/channel_layout.h" |
11 #include "media/base/media_export.h" | 11 #include "media/base/media_export.h" |
12 | 12 |
13 namespace media { | 13 namespace media { |
14 | 14 |
15 enum AudioCodec { | 15 enum AudioCodec { |
16 // These values are histogrammed over time; do not change their ordinal | 16 // These values are histogrammed over time; do not change their ordinal |
17 // values. When deleting a codec replace it with a dummy value; when adding a | 17 // values. When deleting a codec replace it with a dummy value; when adding a |
18 // codec, do so at the bottom (and update kAudioCodecMax). | 18 // codec, do so at the bottom before kAudioCodecMax. |
19 kUnknownAudioCodec = 0, | 19 kUnknownAudioCodec = 0, |
20 kCodecAAC, | 20 kCodecAAC, |
21 kCodecMP3, | 21 kCodecMP3, |
22 kCodecPCM, | 22 kCodecPCM, |
23 kCodecVorbis, | 23 kCodecVorbis, |
24 // ChromiumOS and ChromeOS specific codecs. | 24 // ChromiumOS and ChromeOS specific codecs. |
25 kCodecFLAC, | 25 kCodecFLAC, |
26 // ChromeOS specific codecs. | 26 // ChromeOS specific codecs. |
27 kCodecAMR_NB, | 27 kCodecAMR_NB, |
28 kCodecAMR_WB, | 28 kCodecAMR_WB, |
29 kCodecPCM_MULAW, | 29 kCodecPCM_MULAW, |
30 kCodecGSM_MS, | 30 kCodecGSM_MS, |
31 kCodecPCM_S16BE, | 31 kCodecPCM_S16BE, |
32 kCodecPCM_S24BE, | 32 kCodecPCM_S24BE, |
33 // DO NOT ADD RANDOM AUDIO CODECS! | 33 // DO NOT ADD RANDOM AUDIO CODECS! |
34 // | 34 // |
35 // The only acceptable time to add a new codec is if there is production code | 35 // The only acceptable time to add a new codec is if there is production code |
36 // that uses said codec in the same CL. | 36 // that uses said codec in the same CL. |
37 | 37 |
38 kAudioCodecMax = kCodecPCM_S24BE // Must equal the last "real" codec above. | 38 // Must always be last! |
| 39 kAudioCodecMax |
| 40 }; |
| 41 |
| 42 enum SampleFormat { |
| 43 // These values are histogrammed over time; do not change their ordinal |
| 44 // values. When deleting a sample format replace it with a dummy value; when |
| 45 // adding a sample format, do so at the bottom before kSampleFormatMax. |
| 46 kUnknownSampleFormat = 0, |
| 47 kSampleFormatU8, // Unsigned 8-bit w/ bias of 128. |
| 48 kSampleFormatS16, // Signed 16-bit. |
| 49 kSampleFormatS32, // Signed 32-bit. |
| 50 kSampleFormatF32, // Float 32-bit. |
| 51 kSampleFormatPlanarF32, // Float planar. |
| 52 |
| 53 // Must always be last! |
| 54 kSampleFormatMax |
39 }; | 55 }; |
40 | 56 |
41 // TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of | 57 // TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of |
42 // |bits_per_channel|, we should switch over since bits are generally confusing | 58 // |bits_per_channel|, we should switch over since bits are generally confusing |
43 // to work with. | 59 // to work with. |
44 class MEDIA_EXPORT AudioDecoderConfig { | 60 class MEDIA_EXPORT AudioDecoderConfig { |
45 public: | 61 public: |
46 // Constructs an uninitialized object. Clients should call Initialize() with | 62 // Constructs an uninitialized object. Clients should call Initialize() with |
47 // appropriate values before using. | 63 // appropriate values before using. |
48 AudioDecoderConfig(); | 64 AudioDecoderConfig(); |
49 | 65 |
50 // Constructs an initialized object. It is acceptable to pass in NULL for | 66 // Constructs an initialized object. It is acceptable to pass in NULL for |
51 // |extra_data|, otherwise the memory is copied. | 67 // |extra_data|, otherwise the memory is copied. |
52 AudioDecoderConfig(AudioCodec codec, int bits_per_channel, | 68 AudioDecoderConfig(AudioCodec codec, SampleFormat sample_format, |
53 ChannelLayout channel_layout, int samples_per_second, | 69 ChannelLayout channel_layout, int samples_per_second, |
54 const uint8* extra_data, size_t extra_data_size, | 70 const uint8* extra_data, size_t extra_data_size, |
55 bool is_encrypted); | 71 bool is_encrypted); |
56 | 72 |
57 ~AudioDecoderConfig(); | 73 ~AudioDecoderConfig(); |
58 | 74 |
59 // Resets the internal state of this object. | 75 // Resets the internal state of this object. |
60 void Initialize(AudioCodec codec, int bits_per_channel, | 76 void Initialize(AudioCodec codec, SampleFormat sample_format, |
61 ChannelLayout channel_layout, int samples_per_second, | 77 ChannelLayout channel_layout, int samples_per_second, |
62 const uint8* extra_data, size_t extra_data_size, | 78 const uint8* extra_data, size_t extra_data_size, |
63 bool is_encrypted, | 79 bool is_encrypted, bool record_stats); |
64 bool record_stats); | |
65 | 80 |
66 // Deep copies |audio_config|. | 81 // Deep copies |audio_config|. |
67 void CopyFrom(const AudioDecoderConfig& audio_config); | 82 void CopyFrom(const AudioDecoderConfig& audio_config); |
68 | 83 |
69 // Returns true if this object has appropriate configuration values, false | 84 // Returns true if this object has appropriate configuration values, false |
70 // otherwise. | 85 // otherwise. |
71 bool IsValidConfig() const; | 86 bool IsValidConfig() const; |
72 | 87 |
73 // Returns true if all fields in |config| match this config. | 88 // Returns true if all fields in |config| match this config. |
74 // Note: The contents of |extra_data_| are compared not the raw pointers. | 89 // Note: The contents of |extra_data_| are compared not the raw pointers. |
75 bool Matches(const AudioDecoderConfig& config) const; | 90 bool Matches(const AudioDecoderConfig& config) const; |
76 | 91 |
77 AudioCodec codec() const; | 92 AudioCodec codec() const { return codec_; } |
78 int bits_per_channel() const; | 93 int bits_per_channel() const { return bits_per_channel_; } |
79 ChannelLayout channel_layout() const; | 94 ChannelLayout channel_layout() const { return channel_layout_; } |
80 int samples_per_second() const; | 95 int samples_per_second() const { return samples_per_second_; } |
81 int bytes_per_frame() const; | 96 SampleFormat sample_format() const { return sample_format_; } |
| 97 int bytes_per_frame() const { return bytes_per_frame_; } |
82 | 98 |
83 // Optional byte data required to initialize audio decoders such as Vorbis | 99 // Optional byte data required to initialize audio decoders such as Vorbis |
84 // codebooks. | 100 // codebooks. |
85 uint8* extra_data() const; | 101 uint8* extra_data() const { return extra_data_.get(); } |
86 size_t extra_data_size() const; | 102 size_t extra_data_size() const { return extra_data_size_; } |
87 | 103 |
88 // Whether the audio stream is potentially encrypted. | 104 // Whether the audio stream is potentially encrypted. |
89 // Note that in a potentially encrypted audio stream, individual buffers | 105 // Note that in a potentially encrypted audio stream, individual buffers |
90 // can be encrypted or not encrypted. | 106 // can be encrypted or not encrypted. |
91 bool is_encrypted() const; | 107 bool is_encrypted() const { return is_encrypted_; } |
92 | 108 |
93 private: | 109 private: |
94 AudioCodec codec_; | 110 AudioCodec codec_; |
| 111 SampleFormat sample_format_; |
95 int bits_per_channel_; | 112 int bits_per_channel_; |
96 ChannelLayout channel_layout_; | 113 ChannelLayout channel_layout_; |
97 int samples_per_second_; | 114 int samples_per_second_; |
98 int bytes_per_frame_; | 115 int bytes_per_frame_; |
99 | 116 |
100 scoped_array<uint8> extra_data_; | 117 scoped_array<uint8> extra_data_; |
101 size_t extra_data_size_; | 118 size_t extra_data_size_; |
102 | 119 |
103 bool is_encrypted_; | 120 bool is_encrypted_; |
104 | 121 |
105 DISALLOW_COPY_AND_ASSIGN(AudioDecoderConfig); | 122 DISALLOW_COPY_AND_ASSIGN(AudioDecoderConfig); |
106 }; | 123 }; |
107 | 124 |
108 } // namespace media | 125 } // namespace media |
109 | 126 |
110 #endif // MEDIA_BASE_AUDIO_DECODER_CONFIG_H_ | 127 #endif // MEDIA_BASE_AUDIO_DECODER_CONFIG_H_ |
OLD | NEW |