diff options
author | jrummell@chromium.org <jrummell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-12 21:42:10 +0000 |
---|---|---|
committer | jrummell@chromium.org <jrummell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-12 21:42:10 +0000 |
commit | d1d4595ae1cee37c14b800b3cde15a2798129a39 (patch) | |
tree | ef639b5099bf86c60eccbe1fff0eb257b506fdd3 | |
parent | cadd30fea95dbec58c69078b959789be93917c37 (diff) | |
download | chromium_src-d1d4595ae1cee37c14b800b3cde15a2798129a39.zip chromium_src-d1d4595ae1cee37c14b800b3cde15a2798129a39.tar.gz chromium_src-d1d4595ae1cee37c14b800b3cde15a2798129a39.tar.bz2 |
Expose SampleFormat -> bytes per frame calculations.
First part of converting audio streams to reduce copying the data.
BUG=248989
Review URL: https://chromiumcodereview.appspot.com/16404013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205937 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | media/base/audio_decoder_config.cc | 34 | ||||
-rw-r--r-- | media/base/audio_decoder_config.h | 22 | ||||
-rw-r--r-- | media/base/limits.h | 5 | ||||
-rw-r--r-- | media/base/sample_format.cc | 32 | ||||
-rw-r--r-- | media/base/sample_format.h | 34 | ||||
-rw-r--r-- | media/media.gyp | 2 |
6 files changed, 82 insertions, 47 deletions
diff --git a/media/base/audio_decoder_config.cc b/media/base/audio_decoder_config.cc index a4e57c2..38db05d 100644 --- a/media/base/audio_decoder_config.cc +++ b/media/base/audio_decoder_config.cc @@ -8,34 +8,14 @@ #include "base/metrics/histogram.h" #include "media/audio/sample_rates.h" #include "media/base/limits.h" +#include "media/base/sample_format.h" namespace media { -static int SampleFormatToBitsPerChannel(SampleFormat sample_format) { - switch (sample_format) { - case kUnknownSampleFormat: - return 0; - case kSampleFormatU8: - return 8; - case kSampleFormatS16: - case kSampleFormatPlanarS16: - return 16; - case kSampleFormatS32: - case kSampleFormatF32: - case kSampleFormatPlanarF32: - return 32; - case kSampleFormatMax: - break; - } - - NOTREACHED() << "Invalid sample format provided: " << sample_format; - return 0; -} - AudioDecoderConfig::AudioDecoderConfig() : codec_(kUnknownAudioCodec), sample_format_(kUnknownSampleFormat), - bits_per_channel_(0), + bytes_per_channel_(0), channel_layout_(CHANNEL_LAYOUT_UNSUPPORTED), samples_per_second_(0), bytes_per_frame_(0), @@ -83,12 +63,12 @@ void AudioDecoderConfig::Initialize(AudioCodec codec, channel_layout_ = channel_layout; samples_per_second_ = samples_per_second; sample_format_ = sample_format; - bits_per_channel_ = SampleFormatToBitsPerChannel(sample_format); + bytes_per_channel_ = SampleFormatToBytesPerChannel(sample_format); extra_data_.assign(extra_data, extra_data + extra_data_size); is_encrypted_ = is_encrypted; int channels = ChannelLayoutToChannelCount(channel_layout_); - bytes_per_frame_ = channels * bits_per_channel_ / 8; + bytes_per_frame_ = channels * bytes_per_channel_; } AudioDecoderConfig::~AudioDecoderConfig() {} @@ -96,8 +76,8 @@ AudioDecoderConfig::~AudioDecoderConfig() {} bool AudioDecoderConfig::IsValidConfig() const { return codec_ != kUnknownAudioCodec && channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && - bits_per_channel_ > 0 && - bits_per_channel_ <= limits::kMaxBitsPerSample && + bytes_per_channel_ > 0 && + bytes_per_channel_ <= limits::kMaxBytesPerSample && samples_per_second_ > 0 && samples_per_second_ <= limits::kMaxSampleRate && sample_format_ != kUnknownSampleFormat; @@ -105,7 +85,7 @@ bool AudioDecoderConfig::IsValidConfig() const { bool AudioDecoderConfig::Matches(const AudioDecoderConfig& config) const { return ((codec() == config.codec()) && - (bits_per_channel() == config.bits_per_channel()) && + (bytes_per_channel() == config.bytes_per_channel()) && (channel_layout() == config.channel_layout()) && (samples_per_second() == config.samples_per_second()) && (extra_data_size() == config.extra_data_size()) && diff --git a/media/base/audio_decoder_config.h b/media/base/audio_decoder_config.h index 5b886e0..1c61e70 100644 --- a/media/base/audio_decoder_config.h +++ b/media/base/audio_decoder_config.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "media/base/channel_layout.h" #include "media/base/media_export.h" +#include "media/base/sample_format.h" namespace media { @@ -40,22 +41,6 @@ enum AudioCodec { kAudioCodecMax }; -enum SampleFormat { - // These values are histogrammed over time; do not change their ordinal - // values. When deleting a sample format replace it with a dummy value; when - // adding a sample format, do so at the bottom before kSampleFormatMax. - kUnknownSampleFormat = 0, - kSampleFormatU8, // Unsigned 8-bit w/ bias of 128. - kSampleFormatS16, // Signed 16-bit. - kSampleFormatS32, // Signed 32-bit. - kSampleFormatF32, // Float 32-bit. - kSampleFormatPlanarS16, // Signed 16-bit planar. - kSampleFormatPlanarF32, // Float 32-bit planar. - - // Must always be last! - kSampleFormatMax -}; - // TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of // |bits_per_channel|, we should switch over since bits are generally confusing // to work with. @@ -89,7 +74,8 @@ class MEDIA_EXPORT AudioDecoderConfig { bool Matches(const AudioDecoderConfig& config) const; AudioCodec codec() const { return codec_; } - int bits_per_channel() const { return bits_per_channel_; } + int bits_per_channel() const { return bytes_per_channel_ * 8; } + int bytes_per_channel() const { return bytes_per_channel_; } ChannelLayout channel_layout() const { return channel_layout_; } int samples_per_second() const { return samples_per_second_; } SampleFormat sample_format() const { return sample_format_; } @@ -110,7 +96,7 @@ class MEDIA_EXPORT AudioDecoderConfig { private: AudioCodec codec_; SampleFormat sample_format_; - int bits_per_channel_; + int bytes_per_channel_; ChannelLayout channel_layout_; int samples_per_second_; int bytes_per_frame_; diff --git a/media/base/limits.h b/media/base/limits.h index 309635f..ed7ac51 100644 --- a/media/base/limits.h +++ b/media/base/limits.h @@ -34,10 +34,11 @@ enum { kMaxSampleRate = 192000, kMinSampleRate = 3000, kMaxChannels = 32, - kMaxBitsPerSample = 32, + kMaxBytesPerSample = 4, + kMaxBitsPerSample = kMaxBytesPerSample * 8, kMaxSamplesPerPacket = kMaxSampleRate, kMaxPacketSizeInBytes = - (kMaxBitsPerSample / 8) * kMaxChannels * kMaxSamplesPerPacket, + kMaxBytesPerSample * kMaxChannels * kMaxSamplesPerPacket, // This limit is used by ParamTraits<VideoCaptureParams>. kMaxFramesPerSecond = 1000, diff --git a/media/base/sample_format.cc b/media/base/sample_format.cc new file mode 100644 index 0000000..3fdcf101 --- /dev/null +++ b/media/base/sample_format.cc @@ -0,0 +1,32 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/base/sample_format.h" + +#include "base/logging.h" + +namespace media { + +int SampleFormatToBytesPerChannel(SampleFormat sample_format) { + switch (sample_format) { + case kUnknownSampleFormat: + return 0; + case kSampleFormatU8: + return 1; + case kSampleFormatS16: + case kSampleFormatPlanarS16: + return 2; + case kSampleFormatS32: + case kSampleFormatF32: + case kSampleFormatPlanarF32: + return 4; + case kSampleFormatMax: + break; + } + + NOTREACHED() << "Invalid sample format provided: " << sample_format; + return 0; +} + +} // namespace media diff --git a/media/base/sample_format.h b/media/base/sample_format.h new file mode 100644 index 0000000..bcaa5b2 --- /dev/null +++ b/media/base/sample_format.h @@ -0,0 +1,34 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MEDIA_BASE_SAMPLE_FORMAT_H +#define MEDIA_BASE_SAMPLE_FORMAT_H + +#include "media/base/media_export.h" + +namespace media { + +enum SampleFormat { + // These values are histogrammed over time; do not change their ordinal + // values. When deleting a sample format replace it with a dummy value; when + // adding a sample format, do so at the bottom before kSampleFormatMax. + kUnknownSampleFormat = 0, + kSampleFormatU8, // Unsigned 8-bit w/ bias of 128. + kSampleFormatS16, // Signed 16-bit. + kSampleFormatS32, // Signed 32-bit. + kSampleFormatF32, // Float 32-bit. + kSampleFormatPlanarS16, // Signed 16-bit planar. + kSampleFormatPlanarF32, // Float 32-bit planar. + + // Must always be last! + kSampleFormatMax +}; + +// Returns the number of bytes used per channel for the specified +// |sample_format|. +MEDIA_EXPORT int SampleFormatToBytesPerChannel(SampleFormat sample_format); + +} // namespace media + +#endif // MEDIA_BASE_SAMPLE_FORMAT_H diff --git a/media/media.gyp b/media/media.gyp index 955d0c8..d71454e 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -275,6 +275,8 @@ 'base/pipeline_status.h', 'base/ranges.cc', 'base/ranges.h', + 'base/sample_format.cc', + 'base/sample_format.h', 'base/scoped_histogram_timer.h', 'base/seekable_buffer.cc', 'base/seekable_buffer.h', |