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