michael@0: // Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef MEDIA_BASE_AUDIO_DECODER_CONFIG_H_ michael@0: #define MEDIA_BASE_AUDIO_DECODER_CONFIG_H_ michael@0: michael@0: #include michael@0: michael@0: #include "mp4_demuxer/basictypes.h" michael@0: #include "mp4_demuxer/channel_layout.h" michael@0: michael@0: namespace mp4_demuxer { michael@0: michael@0: enum AudioCodec { michael@0: // These values are histogrammed over time; do not change their ordinal michael@0: // values. When deleting a codec replace it with a dummy value; when adding a michael@0: // codec, do so at the bottom before kAudioCodecMax. michael@0: kUnknownAudioCodec = 0, michael@0: kCodecAAC, michael@0: kCodecMP3, michael@0: kCodecPCM, michael@0: kCodecVorbis, michael@0: kCodecFLAC, michael@0: kCodecAMR_NB, michael@0: kCodecAMR_WB, michael@0: kCodecPCM_MULAW, michael@0: kCodecGSM_MS, michael@0: kCodecPCM_S16BE, michael@0: kCodecPCM_S24BE, michael@0: kCodecOpus, michael@0: // DO NOT ADD RANDOM AUDIO CODECS! michael@0: // michael@0: // The only acceptable time to add a new codec is if there is production code michael@0: // that uses said codec in the same CL. michael@0: michael@0: // Must always be last! michael@0: kAudioCodecMax michael@0: }; michael@0: michael@0: enum SampleFormat { michael@0: // These values are histogrammed over time; do not change their ordinal michael@0: // values. When deleting a sample format replace it with a dummy value; when michael@0: // adding a sample format, do so at the bottom before kSampleFormatMax. michael@0: kUnknownSampleFormat = 0, michael@0: kSampleFormatU8, // Unsigned 8-bit w/ bias of 128. michael@0: kSampleFormatS16, // Signed 16-bit. michael@0: kSampleFormatS32, // Signed 32-bit. michael@0: kSampleFormatF32, // Float 32-bit. michael@0: kSampleFormatPlanarS16, // Signed 16-bit planar. michael@0: kSampleFormatPlanarF32, // Float 32-bit planar. michael@0: michael@0: // Must always be last! michael@0: kSampleFormatMax michael@0: }; michael@0: michael@0: // TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of michael@0: // |bits_per_channel|, we should switch over since bits are generally confusing michael@0: // to work with. michael@0: class AudioDecoderConfig { michael@0: public: michael@0: // Constructs an uninitialized object. Clients should call Initialize() with michael@0: // appropriate values before using. michael@0: AudioDecoderConfig(); michael@0: michael@0: // Constructs an initialized object. It is acceptable to pass in NULL for michael@0: // |extra_data|, otherwise the memory is copied. michael@0: AudioDecoderConfig(AudioCodec codec, SampleFormat sample_format, michael@0: ChannelLayout channel_layout, int samples_per_second, michael@0: const uint8_t* extra_data, size_t extra_data_size, michael@0: bool is_encrypted); michael@0: michael@0: ~AudioDecoderConfig(); michael@0: michael@0: // Resets the internal state of this object. michael@0: void Initialize(AudioCodec codec, SampleFormat sample_format, michael@0: ChannelLayout channel_layout, int samples_per_second, michael@0: const uint8_t* extra_data, size_t extra_data_size, michael@0: bool is_encrypted); michael@0: michael@0: // Returns true if this object has appropriate configuration values, false michael@0: // otherwise. michael@0: bool IsValidConfig() const; michael@0: michael@0: // Returns true if all fields in |config| match this config. michael@0: // Note: The contents of |extra_data_| are compared not the raw pointers. michael@0: bool Matches(const AudioDecoderConfig& config) const; michael@0: michael@0: AudioCodec codec() const { return codec_; } michael@0: int bits_per_channel() const { return bits_per_channel_; } michael@0: ChannelLayout channel_layout() const { return channel_layout_; } michael@0: int samples_per_second() const { return samples_per_second_; } michael@0: SampleFormat sample_format() const { return sample_format_; } michael@0: int bytes_per_frame() const { return bytes_per_frame_; } michael@0: michael@0: // Optional byte data required to initialize audio decoders such as Vorbis michael@0: // codebooks. michael@0: const uint8_t* extra_data() const { michael@0: return extra_data_.empty() ? NULL : &extra_data_[0]; michael@0: } michael@0: size_t extra_data_size() const { return extra_data_.size(); } michael@0: michael@0: // Whether the audio stream is potentially encrypted. michael@0: // Note that in a potentially encrypted audio stream, individual buffers michael@0: // can be encrypted or not encrypted. michael@0: bool is_encrypted() const { return is_encrypted_; } michael@0: michael@0: std::string AsHumanReadableString() const; michael@0: michael@0: private: michael@0: AudioCodec codec_; michael@0: SampleFormat sample_format_; michael@0: int bits_per_channel_; michael@0: ChannelLayout channel_layout_; michael@0: int samples_per_second_; michael@0: int bytes_per_frame_; michael@0: std::vector extra_data_; michael@0: bool is_encrypted_; michael@0: michael@0: // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler michael@0: // generated copy constructor and assignment operator. Since the extra data is michael@0: // typically small, the performance impact is minimal. michael@0: }; michael@0: michael@0: } // namespace mp4_demuxer michael@0: michael@0: #endif // MEDIA_BASE_AUDIO_DECODER_CONFIG_H_