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