1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/fmp4/demuxer/audio_decoder_config.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,127 @@ 1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef MEDIA_BASE_AUDIO_DECODER_CONFIG_H_ 1.9 +#define MEDIA_BASE_AUDIO_DECODER_CONFIG_H_ 1.10 + 1.11 +#include <vector> 1.12 + 1.13 +#include "mp4_demuxer/basictypes.h" 1.14 +#include "mp4_demuxer/channel_layout.h" 1.15 + 1.16 +namespace mp4_demuxer { 1.17 + 1.18 +enum AudioCodec { 1.19 + // These values are histogrammed over time; do not change their ordinal 1.20 + // values. When deleting a codec replace it with a dummy value; when adding a 1.21 + // codec, do so at the bottom before kAudioCodecMax. 1.22 + kUnknownAudioCodec = 0, 1.23 + kCodecAAC, 1.24 + kCodecMP3, 1.25 + kCodecPCM, 1.26 + kCodecVorbis, 1.27 + kCodecFLAC, 1.28 + kCodecAMR_NB, 1.29 + kCodecAMR_WB, 1.30 + kCodecPCM_MULAW, 1.31 + kCodecGSM_MS, 1.32 + kCodecPCM_S16BE, 1.33 + kCodecPCM_S24BE, 1.34 + kCodecOpus, 1.35 + // DO NOT ADD RANDOM AUDIO CODECS! 1.36 + // 1.37 + // The only acceptable time to add a new codec is if there is production code 1.38 + // that uses said codec in the same CL. 1.39 + 1.40 + // Must always be last! 1.41 + kAudioCodecMax 1.42 +}; 1.43 + 1.44 +enum SampleFormat { 1.45 + // These values are histogrammed over time; do not change their ordinal 1.46 + // values. When deleting a sample format replace it with a dummy value; when 1.47 + // adding a sample format, do so at the bottom before kSampleFormatMax. 1.48 + kUnknownSampleFormat = 0, 1.49 + kSampleFormatU8, // Unsigned 8-bit w/ bias of 128. 1.50 + kSampleFormatS16, // Signed 16-bit. 1.51 + kSampleFormatS32, // Signed 32-bit. 1.52 + kSampleFormatF32, // Float 32-bit. 1.53 + kSampleFormatPlanarS16, // Signed 16-bit planar. 1.54 + kSampleFormatPlanarF32, // Float 32-bit planar. 1.55 + 1.56 + // Must always be last! 1.57 + kSampleFormatMax 1.58 +}; 1.59 + 1.60 +// TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of 1.61 +// |bits_per_channel|, we should switch over since bits are generally confusing 1.62 +// to work with. 1.63 +class AudioDecoderConfig { 1.64 + public: 1.65 + // Constructs an uninitialized object. Clients should call Initialize() with 1.66 + // appropriate values before using. 1.67 + AudioDecoderConfig(); 1.68 + 1.69 + // Constructs an initialized object. It is acceptable to pass in NULL for 1.70 + // |extra_data|, otherwise the memory is copied. 1.71 + AudioDecoderConfig(AudioCodec codec, SampleFormat sample_format, 1.72 + ChannelLayout channel_layout, int samples_per_second, 1.73 + const uint8_t* extra_data, size_t extra_data_size, 1.74 + bool is_encrypted); 1.75 + 1.76 + ~AudioDecoderConfig(); 1.77 + 1.78 + // Resets the internal state of this object. 1.79 + void Initialize(AudioCodec codec, SampleFormat sample_format, 1.80 + ChannelLayout channel_layout, int samples_per_second, 1.81 + const uint8_t* extra_data, size_t extra_data_size, 1.82 + bool is_encrypted); 1.83 + 1.84 + // Returns true if this object has appropriate configuration values, false 1.85 + // otherwise. 1.86 + bool IsValidConfig() const; 1.87 + 1.88 + // Returns true if all fields in |config| match this config. 1.89 + // Note: The contents of |extra_data_| are compared not the raw pointers. 1.90 + bool Matches(const AudioDecoderConfig& config) const; 1.91 + 1.92 + AudioCodec codec() const { return codec_; } 1.93 + int bits_per_channel() const { return bits_per_channel_; } 1.94 + ChannelLayout channel_layout() const { return channel_layout_; } 1.95 + int samples_per_second() const { return samples_per_second_; } 1.96 + SampleFormat sample_format() const { return sample_format_; } 1.97 + int bytes_per_frame() const { return bytes_per_frame_; } 1.98 + 1.99 + // Optional byte data required to initialize audio decoders such as Vorbis 1.100 + // codebooks. 1.101 + const uint8_t* extra_data() const { 1.102 + return extra_data_.empty() ? NULL : &extra_data_[0]; 1.103 + } 1.104 + size_t extra_data_size() const { return extra_data_.size(); } 1.105 + 1.106 + // Whether the audio stream is potentially encrypted. 1.107 + // Note that in a potentially encrypted audio stream, individual buffers 1.108 + // can be encrypted or not encrypted. 1.109 + bool is_encrypted() const { return is_encrypted_; } 1.110 + 1.111 + std::string AsHumanReadableString() const; 1.112 + 1.113 + private: 1.114 + AudioCodec codec_; 1.115 + SampleFormat sample_format_; 1.116 + int bits_per_channel_; 1.117 + ChannelLayout channel_layout_; 1.118 + int samples_per_second_; 1.119 + int bytes_per_frame_; 1.120 + std::vector<uint8_t> extra_data_; 1.121 + bool is_encrypted_; 1.122 + 1.123 + // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler 1.124 + // generated copy constructor and assignment operator. Since the extra data is 1.125 + // typically small, the performance impact is minimal. 1.126 +}; 1.127 + 1.128 +} // namespace mp4_demuxer 1.129 + 1.130 +#endif // MEDIA_BASE_AUDIO_DECODER_CONFIG_H_