diff options
author | annacc@chromium.org <annacc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-16 22:18:32 +0000 |
---|---|---|
committer | annacc@chromium.org <annacc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-16 22:18:32 +0000 |
commit | b630cb97c620593f9c987fdad0b3271ddbf39a3e (patch) | |
tree | 21295811329d31b302e29be7e16198fdfd5bc463 | |
parent | 99d22e8b1c2c0b6f6457147ab90ce2df98ef02d3 (diff) | |
download | chromium_src-b630cb97c620593f9c987fdad0b3271ddbf39a3e.zip chromium_src-b630cb97c620593f9c987fdad0b3271ddbf39a3e.tar.gz chromium_src-b630cb97c620593f9c987fdad0b3271ddbf39a3e.tar.bz2 |
Description:
This patch gets the channel layout for surround sound channel order from ffmpeg and stores it so that chromium will be able to re-order the channels for various sound cards and OSes later.
- AudioParameters gets a new field (channel_layout).
- channel_layout.h stores an enum that we will use in chromium for channel values.
- ffmpeg_common.h gets a new method for mapping the channel layout received from ffmpeg to an internal chromium enum value.
BUG=None (though storing the channel order should help us solve some other bugs soon)
TEST=media_unittests
Review URL: http://codereview.chromium.org/6930039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85541 0039d316-1c4b-4281-b951-d872f2087c98
25 files changed, 405 insertions, 154 deletions
diff --git a/content/browser/speech/speech_recognizer.cc b/content/browser/speech/speech_recognizer.cc index 7a4ebd1..9408f46 100644 --- a/content/browser/speech/speech_recognizer.cc +++ b/content/browser/speech/speech_recognizer.cc @@ -49,7 +49,7 @@ namespace speech_input { const int SpeechRecognizer::kAudioSampleRate = 16000; const int SpeechRecognizer::kAudioPacketIntervalMs = 100; -const int SpeechRecognizer::kNumAudioChannels = 1; +const ChannelLayout SpeechRecognizer::kChannelLayout = CHANNEL_LAYOUT_MONO; const int SpeechRecognizer::kNumBitsPerAudioSample = 16; const int SpeechRecognizer::kNoSpeechTimeoutSec = 8; const int SpeechRecognizer::kEndpointerEstimationTimeMs = 300; @@ -102,7 +102,7 @@ bool SpeechRecognizer::StartRecording() { encoder_.reset(AudioEncoder::Create(codec_, kAudioSampleRate, kNumBitsPerAudioSample)); int samples_per_packet = (kAudioSampleRate * kAudioPacketIntervalMs) / 1000; - AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kNumAudioChannels, + AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kAudioSampleRate, kNumBitsPerAudioSample, samples_per_packet); audio_controller_ = AudioInputController::Create(this, params); diff --git a/content/browser/speech/speech_recognizer.h b/content/browser/speech/speech_recognizer.h index a87831e..f60a9de 100644 --- a/content/browser/speech/speech_recognizer.h +++ b/content/browser/speech/speech_recognizer.h @@ -113,7 +113,7 @@ class SpeechRecognizer static const int kAudioSampleRate; static const int kAudioPacketIntervalMs; // Duration of each audio packet. - static const int kNumAudioChannels; + static const ChannelLayout kChannelLayout; static const int kNumBitsPerAudioSample; static const int kNoSpeechTimeoutSec; static const int kEndpointerEstimationTimeMs; diff --git a/content/browser/speech/speech_recognizer_unittest.cc b/content/browser/speech/speech_recognizer_unittest.cc index 5e5ce8e..fbb04db 100644 --- a/content/browser/speech/speech_recognizer_unittest.cc +++ b/content/browser/speech/speech_recognizer_unittest.cc @@ -36,7 +36,7 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate, int audio_packet_length_bytes = (SpeechRecognizer::kAudioSampleRate * SpeechRecognizer::kAudioPacketIntervalMs * - SpeechRecognizer::kNumAudioChannels * + ChannelLayoutToChannelCount(SpeechRecognizer::kChannelLayout) * SpeechRecognizer::kNumBitsPerAudioSample) / (8 * 1000); audio_packet_.resize(audio_packet_length_bytes); } diff --git a/content/renderer/media/audio_renderer_impl_unittest.cc b/content/renderer/media/audio_renderer_impl_unittest.cc index ba7a056..cdbb62a 100644 --- a/content/renderer/media/audio_renderer_impl_unittest.cc +++ b/content/renderer/media/audio_renderer_impl_unittest.cc @@ -33,7 +33,9 @@ class AudioRendererImplTest : public ::testing::Test { decoder_ = new media::MockAudioDecoder(); ON_CALL(*decoder_, config()) - .WillByDefault(Return(media::AudioDecoderConfig(16, 1, 44100))); + .WillByDefault(Return(media::AudioDecoderConfig(16, + CHANNEL_LAYOUT_MONO, + 44100))); // Create and initialize audio renderer. renderer_ = new AudioRendererImpl(filter_); diff --git a/media/audio/audio_input_controller_unittest.cc b/media/audio/audio_input_controller_unittest.cc index 5ebf088..6a62871 100644 --- a/media/audio/audio_input_controller_unittest.cc +++ b/media/audio/audio_input_controller_unittest.cc @@ -19,6 +19,7 @@ namespace media { static const int kSampleRate = AudioParameters::kAudioCDSampleRate; static const int kBitsPerSample = 16; static const int kChannels = 2; +static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; static const int kSamplesPerPacket = kSampleRate / 10; ACTION_P3(CheckCountAndSignalEvent, count, limit, event) { @@ -50,7 +51,7 @@ TEST(AudioInputControllerTest, CreateAndClose) { EXPECT_CALL(event_handler, OnCreated(NotNull())) .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); - AudioParameters params(AudioParameters::AUDIO_MOCK, kChannels, + AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, kSampleRate, kBitsPerSample, kSamplesPerPacket); scoped_refptr<AudioInputController> controller = AudioInputController::Create(&event_handler, params); @@ -81,7 +82,7 @@ TEST(AudioInputControllerTest, RecordAndClose) { .Times(AtLeast(10)) .WillRepeatedly(CheckCountAndSignalEvent(&count, 10, &event)); - AudioParameters params(AudioParameters::AUDIO_MOCK, kChannels, + AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, kSampleRate, kBitsPerSample, kSamplesPerPacket); scoped_refptr<AudioInputController> controller = AudioInputController::Create(&event_handler, params); @@ -103,7 +104,7 @@ TEST(AudioInputControllerTest, SamplesPerPacketTooLarge) { // Create an audio device with a very large packet size. MockAudioInputControllerEventHandler event_handler; - AudioParameters params(AudioParameters::AUDIO_MOCK, kChannels, + AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); scoped_refptr<AudioInputController> controller = AudioInputController::Create( &event_handler, params); @@ -114,7 +115,7 @@ TEST(AudioInputControllerTest, SamplesPerPacketTooLarge) { TEST(AudioInputControllerTest, CloseTwice) { MockAudioInputControllerEventHandler event_handler; EXPECT_CALL(event_handler, OnCreated(NotNull())); - AudioParameters params(AudioParameters::AUDIO_MOCK, kChannels, + AudioParameters params(AudioParameters::AUDIO_MOCK, kChannelLayout, kSampleRate, kBitsPerSample, kSamplesPerPacket); scoped_refptr<AudioInputController> controller = AudioInputController::Create(&event_handler, params); diff --git a/media/audio/audio_input_unittest.cc b/media/audio/audio_input_unittest.cc index e4c7f65..f62de94 100644 --- a/media/audio/audio_input_unittest.cc +++ b/media/audio/audio_input_unittest.cc @@ -102,8 +102,8 @@ static bool CanRunAudioTests() { static AudioInputStream* CreateTestAudioInputStream() { AudioManager* audio_man = AudioManager::GetAudioManager(); AudioInputStream* ais = audio_man->MakeAudioInputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, kSamplingRate, - 16, kSamplesPerPacket)); + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + kSamplingRate, 16, kSamplesPerPacket)); EXPECT_TRUE(NULL != ais); return ais; } @@ -115,21 +115,28 @@ TEST(AudioInputTest, SanityOnMakeParams) { AudioManager* audio_man = AudioManager::GetAudioManager(); AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; EXPECT_TRUE(NULL == audio_man->MakeAudioInputStream( - AudioParameters(fmt, 8, 8000, 16, kSamplesPerPacket))); + AudioParameters(fmt, CHANNEL_LAYOUT_7POINT1, 8000, 16, + kSamplesPerPacket))); EXPECT_TRUE(NULL == audio_man->MakeAudioInputStream( - AudioParameters(fmt, 1, 1024 * 1024, 16, kSamplesPerPacket))); + AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, + kSamplesPerPacket))); EXPECT_TRUE(NULL == audio_man->MakeAudioInputStream( - AudioParameters(fmt, 2, 8000, 80, kSamplesPerPacket))); + AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, + kSamplesPerPacket))); EXPECT_TRUE(NULL == audio_man->MakeAudioInputStream( - AudioParameters(fmt, 2, 8000, 80, 1000 * kSamplesPerPacket))); + AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, + 1000 * kSamplesPerPacket))); EXPECT_TRUE(NULL == audio_man->MakeAudioInputStream( - AudioParameters(fmt, -2, 8000, 16, kSamplesPerPacket))); + AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, + kSamplesPerPacket))); EXPECT_TRUE(NULL == audio_man->MakeAudioInputStream( - AudioParameters(fmt, 2, -8000, 16, kSamplesPerPacket))); + AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, -8000, 16, + kSamplesPerPacket))); EXPECT_TRUE(NULL == audio_man->MakeAudioInputStream( - AudioParameters(fmt, 2, 8000, -16, kSamplesPerPacket))); + AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, -16, + kSamplesPerPacket))); EXPECT_TRUE(NULL == audio_man->MakeAudioInputStream( - AudioParameters(fmt, 2, 8000, 16, -1024))); + AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 16, -1024))); } // Test create and close of an AudioInputStream without recording audio. diff --git a/media/audio/audio_output_controller_unittest.cc b/media/audio/audio_output_controller_unittest.cc index 2cf936b..0f94ae5 100644 --- a/media/audio/audio_output_controller_unittest.cc +++ b/media/audio/audio_output_controller_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -20,10 +20,10 @@ using ::testing::Return; static const int kSampleRate = AudioParameters::kAudioCDSampleRate; static const int kBitsPerSample = 16; -static const int kChannels = 2; +static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; static const int kSamplesPerPacket = kSampleRate / 10; -static const int kHardwareBufferSize = kSamplesPerPacket * kChannels * - kBitsPerSample / 8; +static const int kHardwareBufferSize = kSamplesPerPacket * + ChannelLayoutToChannelCount(kChannelLayout) * kBitsPerSample / 8; static const int kBufferCapacity = 3 * kHardwareBufferSize; namespace media { @@ -97,7 +97,7 @@ TEST(AudioOutputControllerTest, CreateAndClose) { .Times(1); EXPECT_CALL(event_handler, OnMoreData(NotNull(), _)); - AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannels, + AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, kBitsPerSample, kSamplesPerPacket); scoped_refptr<AudioOutputController> controller = AudioOutputController::Create(&event_handler, params, kBufferCapacity); @@ -127,7 +127,7 @@ TEST(AudioOutputControllerTest, PlayAndClose) { .Times(AtLeast(10)) .WillRepeatedly(SignalEvent(&event)); - AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannels, + AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, kBitsPerSample, kSamplesPerPacket); scoped_refptr<AudioOutputController> controller = AudioOutputController::Create(&event_handler, params, kBufferCapacity); @@ -176,7 +176,7 @@ TEST(AudioOutputControllerTest, PlayPauseClose) { .Times(Exactly(1)) .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal)); - AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannels, + AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, kBitsPerSample, kSamplesPerPacket); scoped_refptr<AudioOutputController> controller = AudioOutputController::Create(&event_handler, params, kBufferCapacity); @@ -236,7 +236,7 @@ TEST(AudioOutputControllerTest, PlayPausePlay) { .Times(Exactly(1)) .RetiresOnSaturation(); - AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannels, + AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, kBitsPerSample, kSamplesPerPacket); scoped_refptr<AudioOutputController> controller = AudioOutputController::Create(&event_handler, params, kBufferCapacity); @@ -279,7 +279,7 @@ TEST(AudioOutputControllerTest, HardwareBufferTooLarge) { // Create an audio device with a very large hardware buffer size. MockAudioOutputControllerEventHandler event_handler; - AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannels, + AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); scoped_refptr<AudioOutputController> controller = @@ -307,7 +307,7 @@ TEST(AudioOutputControllerTest, CloseTwice) { .Times(AtLeast(1)) .WillRepeatedly(SignalEvent(&event)); - AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannels, + AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, kBitsPerSample, kSamplesPerPacket); scoped_refptr<AudioOutputController> controller = AudioOutputController::Create(&event_handler, params, kBufferCapacity); diff --git a/media/audio/audio_output_proxy_unittest.cc b/media/audio/audio_output_proxy_unittest.cc index be11728..814aca4 100644 --- a/media/audio/audio_output_proxy_unittest.cc +++ b/media/audio/audio_output_proxy_unittest.cc @@ -79,8 +79,8 @@ class AudioOutputProxyTest : public testing::Test { } void InitDispatcher(int close_delay_ms) { - AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, 2, 44100, - 16, 1024); + AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, + CHANNEL_LAYOUT_STEREO, 44100, 16, 1024); dispatcher_ = new AudioOutputDispatcher(&manager_, params, close_delay_ms); } diff --git a/media/audio/audio_parameters.cc b/media/audio/audio_parameters.cc index dfe2d07..029f831 100644 --- a/media/audio/audio_parameters.cc +++ b/media/audio/audio_parameters.cc @@ -8,28 +8,31 @@ AudioParameters::AudioParameters() : format(AUDIO_PCM_LINEAR), - channels(0), + channel_layout(CHANNEL_LAYOUT_NONE), sample_rate(0), bits_per_sample(0), - samples_per_packet(0) { + samples_per_packet(0), + channels(0) { } AudioParameters::AudioParameters(const media::AudioDecoderConfig& config) : format(AUDIO_PCM_LINEAR), - channels(config.channels_per_sample), + channel_layout(config.channel_layout), sample_rate(config.sample_rate), bits_per_sample(config.bits_per_channel), - samples_per_packet(0) { + samples_per_packet(0), + channels(ChannelLayoutToChannelCount(config.channel_layout)) { } -AudioParameters::AudioParameters(Format format, int channels, +AudioParameters::AudioParameters(Format format, ChannelLayout channel_layout, int sample_rate, int bits_per_sample, int samples_per_packet) : format(format), - channels(channels), + channel_layout(channel_layout), sample_rate(sample_rate), bits_per_sample(bits_per_sample), - samples_per_packet(samples_per_packet) { + samples_per_packet(samples_per_packet), + channels(ChannelLayoutToChannelCount(channel_layout)) { } bool AudioParameters::IsValid() const { diff --git a/media/audio/audio_parameters.h b/media/audio/audio_parameters.h index ac08067..26204b0 100644 --- a/media/audio/audio_parameters.h +++ b/media/audio/audio_parameters.h @@ -33,7 +33,7 @@ struct AudioParameters { explicit AudioParameters(const media::AudioDecoderConfig& config); - AudioParameters(Format format, int channels, int sample_rate, + AudioParameters(Format format, ChannelLayout channel_layout, int sample_rate, int bits_per_sample, int samples_per_packet); // Checks that all values are in the expected range. All limits are specified @@ -46,11 +46,14 @@ struct AudioParameters { // Returns the number of bytes representing one second of audio. int GetBytesPerSecond() const; - Format format; // Format of the stream. - int channels; // Number of channels. - int sample_rate; // Sampling frequency/rate. - int bits_per_sample; // Number of bits per sample. - int samples_per_packet; // Size of a packet in frames. + Format format; // Format of the stream. + ChannelLayout channel_layout; // Order of surround sound channels. + int sample_rate; // Sampling frequency/rate. + int bits_per_sample; // Number of bits per sample. + int samples_per_packet; // Size of a packet in frames. + + int channels; // Number of channels. Value set based on + // |channel_layout|. }; #endif // MEDIA_AUDIO_AUDIO_PARAMETERS_H_ diff --git a/media/audio/audio_parameters_unittest.cc b/media/audio/audio_parameters_unittest.cc index 9f5bb2b..afcf6ff 100644 --- a/media/audio/audio_parameters_unittest.cc +++ b/media/audio/audio_parameters_unittest.cc @@ -13,6 +13,7 @@ TEST(AudioParameters, Constructor_Default) { AudioParameters::Format expected_format = AudioParameters::AUDIO_PCM_LINEAR; int expected_bits = 0; int expected_channels = 0; + ChannelLayout expected_channel_layout = CHANNEL_LAYOUT_NONE; int expected_rate = 0; int expected_samples = 0; @@ -21,6 +22,7 @@ TEST(AudioParameters, Constructor_Default) { EXPECT_EQ(expected_format, params.format); EXPECT_EQ(expected_bits, params.bits_per_sample); EXPECT_EQ(expected_channels, params.channels); + EXPECT_EQ(expected_channel_layout, params.channel_layout); EXPECT_EQ(expected_rate, params.sample_rate); EXPECT_EQ(expected_samples, params.samples_per_packet); } @@ -29,82 +31,147 @@ TEST(AudioParameters, Constructor_AudioDecoderConfig) { AudioParameters::Format expected_format = AudioParameters::AUDIO_PCM_LINEAR; int expected_bits = 8; int expected_channels = 2; + ChannelLayout expected_channel_layout = CHANNEL_LAYOUT_STEREO; int expected_rate = 44000; int expected_samples = 0; - AudioDecoderConfig config(expected_bits, expected_channels, expected_rate); + AudioDecoderConfig config(expected_bits, expected_channel_layout, + expected_rate); AudioParameters params(config); EXPECT_EQ(expected_format, params.format); EXPECT_EQ(expected_bits, params.bits_per_sample); EXPECT_EQ(expected_channels, params.channels); + EXPECT_EQ(expected_channel_layout, params.channel_layout); + EXPECT_EQ(expected_rate, params.sample_rate); + EXPECT_EQ(expected_samples, params.samples_per_packet); +} + +TEST(AudioParameters, Constructor_ParameterValues) { + AudioParameters::Format expected_format = + AudioParameters::AUDIO_PCM_LOW_LATENCY; + int expected_bits = 16; + int expected_channels = 6; + ChannelLayout expected_channel_layout = CHANNEL_LAYOUT_5POINT1; + int expected_rate = 44100; + int expected_samples = 880; + + AudioParameters params(expected_format, expected_channel_layout, + expected_rate, expected_bits, expected_samples); + + EXPECT_EQ(expected_format, params.format); + EXPECT_EQ(expected_bits, params.bits_per_sample); + EXPECT_EQ(expected_channels, params.channels); + EXPECT_EQ(expected_channel_layout, params.channel_layout); EXPECT_EQ(expected_rate, params.sample_rate); EXPECT_EQ(expected_samples, params.samples_per_packet); } TEST(AudioParameters, GetPacketSize) { EXPECT_EQ(100, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, - 1, 1000, 8, 100).GetPacketSize()); + CHANNEL_LAYOUT_MONO, 1000, 8, 100) + .GetPacketSize()); EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, - 1, 1000, 16, 100).GetPacketSize()); + CHANNEL_LAYOUT_MONO, 1000, 16, 100) + .GetPacketSize()); EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, - 2, 1000, 8, 100).GetPacketSize()); + CHANNEL_LAYOUT_STEREO, 1000, 8, 100) + .GetPacketSize()); EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, - 1, 1000, 8, 200).GetPacketSize()); + CHANNEL_LAYOUT_MONO, 1000, 8, 200) + .GetPacketSize()); EXPECT_EQ(800, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, - 2, 1000, 16, 200).GetPacketSize()); + CHANNEL_LAYOUT_STEREO, 1000, 16, 200) + .GetPacketSize()); } TEST(AudioParameters, GetBytesPerSecond) { EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, - 0, 0, 0, 0).GetBytesPerSecond()); + CHANNEL_LAYOUT_NONE, 0, 0, 0) + .GetBytesPerSecond()); EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, - 2, 0, 0, 0).GetBytesPerSecond()); + CHANNEL_LAYOUT_STEREO, 0, 0, 0) + .GetBytesPerSecond()); EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, - 0, 100, 0, 0).GetBytesPerSecond()); + CHANNEL_LAYOUT_NONE, 100, 0, 0) + .GetBytesPerSecond()); EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, - 0, 0, 8, 0).GetBytesPerSecond()); + CHANNEL_LAYOUT_NONE, 0, 8, 0) + .GetBytesPerSecond()); EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, - 2, 100, 8, 0).GetBytesPerSecond()); + CHANNEL_LAYOUT_STEREO, 100, 8, 0) + .GetBytesPerSecond()); } TEST(AudioParameters, Compare) { AudioParameters values[] = { - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 1000, 8, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 1000, 8, 200), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 1000, 16, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 1000, 16, 200), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 2000, 8, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 2000, 8, 200), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 2000, 16, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 2000, 16, 200), - - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 1000, 8, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 1000, 8, 200), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 1000, 16, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 1000, 16, 200), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 2000, 8, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 2000, 8, 200), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 2000, 16, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 2000, 16, 200), - - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, 1000, 8, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, 1000, 8, 200), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, 1000, 16, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, 1000, 16, 200), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, 2000, 8, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, 2000, 8, 200), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, 2000, 16, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, 2000, 16, 200), - - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 2, 1000, 8, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 2, 1000, 8, 200), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 2, 1000, 16, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 2, 1000, 16, 200), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 2, 2000, 8, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 2, 2000, 8, 200), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 2, 2000, 16, 100), - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 2, 2000, 16, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, + 1000, 8, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, + 1000, 8, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, + 1000, 16, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, + 1000, 16, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, + 2000, 8, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, + 2000, 8, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, + 2000, 16, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, + 2000, 16, 200), + + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 1000, 8, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 1000, 8, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 1000, 16, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 1000, 16, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 2000, 8, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 2000, 8, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 2000, 16, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 2000, 16, 200), + + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO, + 1000, 8, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO, + 1000, 8, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO, + 1000, 16, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO, + 1000, 16, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO, + 2000, 8, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO, + 2000, 8, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO, + 2000, 16, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO, + 2000, 16, 200), + + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, + CHANNEL_LAYOUT_STEREO, 1000, 8, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, + CHANNEL_LAYOUT_STEREO, 1000, 8, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, + CHANNEL_LAYOUT_STEREO, 1000, 16, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, + CHANNEL_LAYOUT_STEREO, 1000, 16, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, + CHANNEL_LAYOUT_STEREO, 2000, 8, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, + CHANNEL_LAYOUT_STEREO, 2000, 8, 200), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, + CHANNEL_LAYOUT_STEREO, 2000, 16, 100), + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, + CHANNEL_LAYOUT_STEREO, 2000, 16, 200), }; AudioParameters::Compare target; diff --git a/media/audio/linux/alsa_output_unittest.cc b/media/audio/linux/alsa_output_unittest.cc index f7c3b5d..3608fcc 100644 --- a/media/audio/linux/alsa_output_unittest.cc +++ b/media/audio/linux/alsa_output_unittest.cc @@ -91,19 +91,20 @@ class MockAudioManagerLinux : public AudioManagerLinux { class AlsaPcmOutputStreamTest : public testing::Test { protected: AlsaPcmOutputStreamTest() { - test_stream_ = CreateStream(kTestChannels); + test_stream_ = CreateStream(kTestChannelLayout); } virtual ~AlsaPcmOutputStreamTest() { test_stream_ = NULL; } - AlsaPcmOutputStream* CreateStream(int channels) { - return CreateStream(channels, kTestFramesPerPacket); + AlsaPcmOutputStream* CreateStream(ChannelLayout layout) { + return CreateStream(layout, kTestFramesPerPacket); } - AlsaPcmOutputStream* CreateStream(int channels, int32 samples_per_packet) { - AudioParameters params(kTestFormat, channels, kTestSampleRate, + AlsaPcmOutputStream* CreateStream(ChannelLayout layout, + int32 samples_per_packet) { + AudioParameters params(kTestFormat, layout, kTestSampleRate, kTestBitsPerSample, samples_per_packet); return new AlsaPcmOutputStream(kTestDeviceName, params, @@ -131,7 +132,7 @@ class AlsaPcmOutputStreamTest : public testing::Test { test_stream_->buffer_->Append(packet_.get()); } - static const int kTestChannels; + static const ChannelLayout kTestChannelLayout; static const int kTestSampleRate; static const int kTestBitsPerSample; static const int kTestBytesPerFrame; @@ -162,13 +163,14 @@ class AlsaPcmOutputStreamTest : public testing::Test { DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStreamTest); }; -const int AlsaPcmOutputStreamTest::kTestChannels = 2; +const ChannelLayout AlsaPcmOutputStreamTest::kTestChannelLayout = + CHANNEL_LAYOUT_STEREO; const int AlsaPcmOutputStreamTest::kTestSampleRate = AudioParameters::kAudioCDSampleRate; const int AlsaPcmOutputStreamTest::kTestBitsPerSample = 8; const int AlsaPcmOutputStreamTest::kTestBytesPerFrame = AlsaPcmOutputStreamTest::kTestBitsPerSample / 8 * - AlsaPcmOutputStreamTest::kTestChannels; + ChannelLayoutToChannelCount(AlsaPcmOutputStreamTest::kTestChannelLayout); const AudioParameters::Format AlsaPcmOutputStreamTest::kTestFormat = AudioParameters::AUDIO_PCM_LINEAR; const char AlsaPcmOutputStreamTest::kTestDeviceName[] = "TestDevice"; @@ -196,17 +198,17 @@ TEST_F(AlsaPcmOutputStreamTest, ConstructedState) { test_stream_->shared_data_.state()); // Should support mono. - test_stream_ = CreateStream(1); + test_stream_ = CreateStream(CHANNEL_LAYOUT_MONO); EXPECT_EQ(AlsaPcmOutputStream::kCreated, test_stream_->shared_data_.state()); // Should support multi-channel. - test_stream_ = CreateStream(3); + test_stream_ = CreateStream(CHANNEL_LAYOUT_SURROUND); EXPECT_EQ(AlsaPcmOutputStream::kCreated, test_stream_->shared_data_.state()); // Bad bits per sample. - AudioParameters bad_bps_params(kTestFormat, kTestChannels, + AudioParameters bad_bps_params(kTestFormat, kTestChannelLayout, kTestSampleRate, kTestBitsPerSample - 1, kTestFramesPerPacket); test_stream_ = new AlsaPcmOutputStream(kTestDeviceName, @@ -219,8 +221,8 @@ TEST_F(AlsaPcmOutputStreamTest, ConstructedState) { // Bad format. AudioParameters bad_format_params( - AudioParameters::AUDIO_LAST_FORMAT, kTestChannels, - kTestSampleRate, kTestBitsPerSample, kTestFramesPerPacket); + AudioParameters::AUDIO_LAST_FORMAT, kTestChannelLayout, kTestSampleRate, + kTestBitsPerSample, kTestFramesPerPacket); test_stream_ = new AlsaPcmOutputStream(kTestDeviceName, bad_format_params, &mock_alsa_wrapper_, @@ -251,7 +253,7 @@ TEST_F(AlsaPcmOutputStreamTest, LatencyFloor) { SetArgumentPointee<2>(kTestFramesPerPacket / 2), Return(0))); - test_stream_ = CreateStream(kTestChannels, kPacketFramesInMinLatency); + test_stream_ = CreateStream(kTestChannelLayout, kPacketFramesInMinLatency); ASSERT_TRUE(test_stream_->Open()); message_loop_.RunAllPending(); @@ -281,7 +283,7 @@ TEST_F(AlsaPcmOutputStreamTest, LatencyFloor) { SetArgumentPointee<2>(kTestFramesPerPacket / 2), Return(0))); - test_stream_ = CreateStream(kTestChannels, kOverMinLatencyPacketSize); + test_stream_ = CreateStream(kTestChannelLayout, kOverMinLatencyPacketSize); ASSERT_TRUE(test_stream_->Open()); message_loop_.RunAllPending(); @@ -315,7 +317,7 @@ TEST_F(AlsaPcmOutputStreamTest, OpenClose) { PcmSetParams(kFakeHandle, SND_PCM_FORMAT_U8, SND_PCM_ACCESS_RW_INTERLEAVED, - kTestChannels, + ChannelLayoutToChannelCount(kTestChannelLayout), kTestSampleRate, 1, expected_micros)) @@ -645,8 +647,18 @@ TEST_F(AlsaPcmOutputStreamTest, AutoSelectDevice_DeviceSelect) { AlsaPcmOutputStream::kDefaultDevice }; bool kExpectedDownmix[] = { false, false, false, false, false, true, false, false, false, false }; - - for (int i = 1; i <= 9; ++i) { + ChannelLayout kExpectedLayouts[] = { CHANNEL_LAYOUT_NONE, + CHANNEL_LAYOUT_MONO, + CHANNEL_LAYOUT_STEREO, + CHANNEL_LAYOUT_SURROUND, + CHANNEL_LAYOUT_4POINT0, + CHANNEL_LAYOUT_5POINT0, + CHANNEL_LAYOUT_5POINT1, + CHANNEL_LAYOUT_7POINT0, + CHANNEL_LAYOUT_7POINT1 }; + + + for (int i = 1; i < 9; ++i) { if (i == 3 || i == 4 || i == 5) // invalid number of channels continue; SCOPED_TRACE(base::StringPrintf("Attempting %d Channel", i)); @@ -676,8 +688,7 @@ TEST_F(AlsaPcmOutputStreamTest, AutoSelectDevice_DeviceSelect) { EXPECT_CALL(mock_alsa_wrapper_, DeviceNameGetHint(_, StrEq("NAME"))) .WillRepeatedly(Invoke(EchoHint)); - - test_stream_ = CreateStream(i); + test_stream_ = CreateStream(kExpectedLayouts[i]); EXPECT_TRUE(test_stream_->AutoSelectDevice(i)); EXPECT_EQ(kExpectedDownmix[i], test_stream_->should_downmix_); @@ -727,7 +738,7 @@ TEST_F(AlsaPcmOutputStreamTest, AutoSelectDevice_FallbackDevices) { EXPECT_CALL(mock_alsa_wrapper_, PcmOpen(_, StrEq(fourth_try.c_str()), _, _)) .WillOnce(Return(kTestFailedErrno)); - test_stream_ = CreateStream(5); + test_stream_ = CreateStream(CHANNEL_LAYOUT_5POINT0); EXPECT_FALSE(test_stream_->AutoSelectDevice(5)); } @@ -745,7 +756,7 @@ TEST_F(AlsaPcmOutputStreamTest, AutoSelectDevice_HintFail) { EXPECT_CALL(mock_alsa_wrapper_, StrError(kTestFailedErrno)) .WillOnce(Return(kDummyMessage)); - test_stream_ = CreateStream(5); + test_stream_ = CreateStream(CHANNEL_LAYOUT_5POINT0); EXPECT_TRUE(test_stream_->AutoSelectDevice(5)); EXPECT_TRUE(test_stream_->should_downmix_); } diff --git a/media/audio/mac/audio_output_mac_unittest.cc b/media/audio/mac/audio_output_mac_unittest.cc index e330e2b..265e7fd 100644 --- a/media/audio/mac/audio_output_mac_unittest.cc +++ b/media/audio/mac/audio_output_mac_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -57,7 +57,8 @@ TEST(MacAudioTest, PCMWaveStreamGetAndClose) { if (!audio_man->HasAudioOutputDevices()) return; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 8000, 16, 1024)); + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 8000, 16, 1024)); ASSERT_TRUE(NULL != oas); oas->Close(); } @@ -69,7 +70,8 @@ TEST(MacAudioTest, PCMWaveStreamOpenAndClose) { if (!audio_man->HasAudioOutputDevices()) return; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 8000, 16, 1024)); + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 8000, 16, 1024)); ASSERT_TRUE(NULL != oas); EXPECT_TRUE(oas->Open()); oas->Close(); @@ -86,7 +88,7 @@ TEST(MacAudioTest, PCMWaveStreamPlay200HzTone44KssMono) { return; uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, AudioParameters::kAudioCDSampleRate, 16, frames_100_ms)); ASSERT_TRUE(NULL != oas); EXPECT_TRUE(oas->Open()); @@ -117,7 +119,7 @@ TEST(MacAudioTest, PCMWaveStreamPlay200HzTone22KssMono) { return; uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, AudioParameters::kAudioCDSampleRate / 2, 16, frames_100_ms)); ASSERT_TRUE(NULL != oas); @@ -145,7 +147,7 @@ TEST(MacAudioTest, PCMWaveStreamPendingBytes) { uint32 frames_100_ms = AudioParameters::kAudioCDSampleRate / 10; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, AudioParameters::kAudioCDSampleRate, 16, frames_100_ms)); ASSERT_TRUE(NULL != oas); diff --git a/media/audio/simple_sources_unittest.cc b/media/audio/simple_sources_unittest.cc index 49a04fa..ff0e30e 100644 --- a/media/audio/simple_sources_unittest.cc +++ b/media/audio/simple_sources_unittest.cc @@ -71,8 +71,8 @@ TEST(SimpleSources, SineWaveAudio16MonoTest) { AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); AudioParameters params( - AudioParameters::AUDIO_MOCK, 1, AudioParameters::kTelephoneSampleRate, - bytes_per_sample * 2, samples); + AudioParameters::AUDIO_MOCK, CHANNEL_LAYOUT_MONO, + AudioParameters::kTelephoneSampleRate, bytes_per_sample * 2, samples); AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params); ASSERT_TRUE(NULL != oas); EXPECT_TRUE(oas->Open()); diff --git a/media/audio/win/audio_output_win_unittest.cc b/media/audio/win/audio_output_win_unittest.cc index 35ea300..4fcc5c8 100644 --- a/media/audio/win/audio_output_win_unittest.cc +++ b/media/audio/win/audio_output_win_unittest.cc @@ -196,7 +196,8 @@ TEST(WinAudioTest, MockStreamBasicCallbacks) { AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_MOCK, 2, 8000, 8, 128)); + AudioParameters(AudioParameters::AUDIO_MOCK, CHANNEL_LAYOUT_STEREO, 8000, + 8, 128)); ASSERT_TRUE(NULL != oas); EXPECT_TRUE(oas->Open()); TestSourceBasic source; @@ -224,7 +225,8 @@ TEST(WinAudioTest, PCMWaveStreamGetAndClose) { if (!audio_man->HasAudioOutputDevices()) return; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 8000, 16, 256)); + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 8000, 16, 256)); ASSERT_TRUE(NULL != oas); oas->Close(); } @@ -239,21 +241,21 @@ TEST(WinAudioTest, SanityOnMakeParams) { return; AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( - AudioParameters(fmt, 9, 8000, 16, 256))); + AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256))); EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( - AudioParameters(fmt, 1, 1024 * 1024, 16, 256))); + AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256))); EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( - AudioParameters(fmt, 2, 8000, 80, 256))); + AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, 256))); EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( - AudioParameters(fmt, -2, 8000, 16, 256))); + AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256))); EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( - AudioParameters(fmt, 2, -8000, 16, 256))); + AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, -8000, 16, 256))); EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( - AudioParameters(fmt, 1, 8000, 16, -100))); + AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, -100))); EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( - AudioParameters(fmt, 1, 8000, 16, 0))); + AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0))); EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( - AudioParameters(fmt, 1, 8000, 16, 100000))); + AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 100000))); } // Test that it can be opened and closed. @@ -265,7 +267,8 @@ TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { if (!audio_man->HasAudioOutputDevices()) return; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 8000, 16, 256)); + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 8000, 16, 256)); ASSERT_TRUE(NULL != oas); EXPECT_TRUE(oas->Open()); oas->Close(); @@ -280,8 +283,8 @@ TEST(WinAudioTest, PCMWaveStreamOpenLimit) { if (!audio_man->HasAudioOutputDevices()) return; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 2, 8000, 16, - 1024 * 1024 * 1024)); + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, + 8000, 16, 1024 * 1024 * 1024)); EXPECT_TRUE(NULL == oas); if (oas) oas->Close(); @@ -297,7 +300,8 @@ TEST(WinAudioTest, PCMWaveStreamTripleBuffer) { if (!audio_man->HasAudioOutputDevices()) return; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 16000, 16, 256)); + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, + 16000, 16, 256)); ASSERT_TRUE(NULL != oas); TestSourceTripleBuffer test_triple_buffer; EXPECT_TRUE(oas->Open()); @@ -321,7 +325,8 @@ TEST(WinAudioTest, PCMWaveSlowSource) { if (!audio_man->HasAudioOutputDevices()) return; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 16000, 16, 256)); + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, + 16000, 16, 256)); ASSERT_TRUE(NULL != oas); TestSourceLaggy test_laggy(2, 90); EXPECT_TRUE(oas->Open()); @@ -348,7 +353,7 @@ TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { return; uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); ASSERT_TRUE(NULL != oas); @@ -379,7 +384,7 @@ TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { return; uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); ASSERT_TRUE(NULL != oas); @@ -407,7 +412,7 @@ TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { return; uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, AudioParameters::kAudioCDSampleRate / 2, 16, samples_100_ms)); ASSERT_TRUE(NULL != oas); @@ -458,8 +463,8 @@ TEST(WinAudioTest, PushSourceFile16KHz) { const uint32 kSize100ms = kSamples100ms * 2; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, 16000, 16, - kSamples100ms)); + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, + 16000, 16, kSamples100ms)); ASSERT_TRUE(NULL != oas); EXPECT_TRUE(oas->Open()); @@ -503,7 +508,7 @@ TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); ASSERT_TRUE(NULL != oas); @@ -542,8 +547,9 @@ TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44KssLowLatency) { uint32 samples_50_ms = AudioParameters::kAudioCDSampleRate / 20; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, - AudioParameters::kAudioCDSampleRate, 16, samples_50_ms)); + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, + CHANNEL_LAYOUT_MONO, AudioParameters::kAudioCDSampleRate, + 16, samples_50_ms)); ASSERT_TRUE(NULL != oas); SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, @@ -570,7 +576,7 @@ TEST(WinAudioTest, PCMWaveStreamPendingBytes) { uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, 1, + AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); ASSERT_TRUE(NULL != oas); @@ -696,8 +702,8 @@ TEST(WinAudioTest, SyncSocketBasic) { int sample_rate = AudioParameters::kAudioCDSampleRate; const uint32 kSamples20ms = sample_rate / 50; AudioOutputStream* oas = audio_man->MakeAudioOutputStream( - AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 1, - sample_rate, 16, kSamples20ms)); + AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, + CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms)); ASSERT_TRUE(NULL != oas); // compute buffer size for 20ms of audio, 882 samples (mono). diff --git a/media/base/audio_decoder_config.h b/media/base/audio_decoder_config.h index 791d2cd..e2c848d 100644 --- a/media/base/audio_decoder_config.h +++ b/media/base/audio_decoder_config.h @@ -5,17 +5,19 @@ #ifndef MEDIA_BASE_AUDIO_DECODER_CONFIG_H_ #define MEDIA_BASE_AUDIO_DECODER_CONFIG_H_ +#include "media/base/channel_layout.h" + namespace media { struct AudioDecoderConfig { - AudioDecoderConfig(int bits, int channels, int rate) + AudioDecoderConfig(int bits, ChannelLayout layout, int rate) : bits_per_channel(bits), - channels_per_sample(channels), + channel_layout(layout), sample_rate(rate) { } int bits_per_channel; - int channels_per_sample; + ChannelLayout channel_layout; int sample_rate; }; diff --git a/media/base/channel_layout.cc b/media/base/channel_layout.cc new file mode 100644 index 0000000..8e3da4f --- /dev/null +++ b/media/base/channel_layout.cc @@ -0,0 +1,28 @@ +// Copyright (c) 2011 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/channel_layout.h" + +static const int kLayoutToChannels[] = { + 0, // CHANNEL_LAYOUT_NONE + 0, // CHANNEL_LAYOUT_UNSUPPORTED + 1, // CHANNEL_LAYOUT_MONO + 2, // CHANNEL_LAYOUT_STEREO + 3, // CHANNEL_LAYOUT_2_1 + 3, // CHANNEL_LAYOUT_SURROUND + 4, // CHANNEL_LAYOUT_4POINT0 + 4, // CHANNEL_LAYOUT_2_2 + 4, // CHANNEL_LAYOUT_QUAD + 5, // CHANNEL_LAYOUT_5POINT0 + 6, // CHANNEL_LAYOUT_5POINT1 + 5, // CHANNEL_LAYOUT_5POINT0_BACK + 6, // CHANNEL_LAYOUT_5POINT1_BACK + 7, // CHANNEL_LAYOUT_7POINT0 + 8, // CHANNEL_LAYOUT_7POINT1 + 8, // CHANNEL_LAYOUT_7POINT1_WIDE + 2}; // CHANNEL_LAYOUT_STEREO_DOWNMIX + +int ChannelLayoutToChannelCount(ChannelLayout layout) { + return kLayoutToChannels[layout]; +} diff --git a/media/base/channel_layout.h b/media/base/channel_layout.h new file mode 100644 index 0000000..b8e1204 --- /dev/null +++ b/media/base/channel_layout.h @@ -0,0 +1,60 @@ +// Copyright (c) 2011 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_CHANNEL_LAYOUT_H_ +#define MEDIA_BASE_CHANNEL_LAYOUT_H_ + +enum ChannelLayout { + CHANNEL_LAYOUT_NONE = 0, + CHANNEL_LAYOUT_UNSUPPORTED, + + // Front C + CHANNEL_LAYOUT_MONO, + + // Front L, Front R + CHANNEL_LAYOUT_STEREO, + + // Front L, Front R, Back C + CHANNEL_LAYOUT_2_1, + + // Front L, Front R, Front C + CHANNEL_LAYOUT_SURROUND, + + // Front L, Front R, Front C, Back C + CHANNEL_LAYOUT_4POINT0, + + // Front L, Front R, Side L, Side R + CHANNEL_LAYOUT_2_2, + + // Front L, Front R, Back L, Back R + CHANNEL_LAYOUT_QUAD, + + // Front L, Front R, Front C, Side L, Side R + CHANNEL_LAYOUT_5POINT0, + + // Front L, Front R, Front C, Side L, Side R, LFE + CHANNEL_LAYOUT_5POINT1, + + // Front L, Front R, Front C, Back L, Back R + CHANNEL_LAYOUT_5POINT0_BACK, + + // Front L, Front R, Front C, Back L, Back R, LFE + CHANNEL_LAYOUT_5POINT1_BACK, + + // Front L, Front R, Front C, Side L, Side R, Back L, Back R + CHANNEL_LAYOUT_7POINT0, + + // Front L, Front R, Front C, Side L, Side R, LFE, Back L, Back R + CHANNEL_LAYOUT_7POINT1, + + // Front L, Front R, Front C, Back L, Back R, LFE, Front LofC, Front RofC + CHANNEL_LAYOUT_7POINT1_WIDE, + + // Stereo L, Stereo R + CHANNEL_LAYOUT_STEREO_DOWNMIX +}; + +int ChannelLayoutToChannelCount(ChannelLayout layout); + +#endif // MEDIA_BASE_CHANNEL_LAYOUT_H_ diff --git a/media/ffmpeg/ffmpeg_common.cc b/media/ffmpeg/ffmpeg_common.cc index 9f5eaeb..dedc40c 100644 --- a/media/ffmpeg/ffmpeg_common.cc +++ b/media/ffmpeg/ffmpeg_common.cc @@ -61,6 +61,51 @@ CodecID VideoCodecToCodecID(VideoCodec video_codec) { return CODEC_ID_NONE; } +ChannelLayout ChannelLayoutToChromeChannelLayout(int64_t layout, + int channels) { + switch (layout) { + case CH_LAYOUT_MONO: + return CHANNEL_LAYOUT_MONO; + case CH_LAYOUT_STEREO: + return CHANNEL_LAYOUT_STEREO; + case CH_LAYOUT_2_1: + return CHANNEL_LAYOUT_2_1; + case CH_LAYOUT_SURROUND: + return CHANNEL_LAYOUT_SURROUND; + case CH_LAYOUT_4POINT0: + return CHANNEL_LAYOUT_4POINT0; + case CH_LAYOUT_2_2: + return CHANNEL_LAYOUT_2_2; + case CH_LAYOUT_QUAD: + return CHANNEL_LAYOUT_QUAD; + case CH_LAYOUT_5POINT0: + return CHANNEL_LAYOUT_5POINT0; + case CH_LAYOUT_5POINT1: + return CHANNEL_LAYOUT_5POINT1; + case CH_LAYOUT_5POINT0_BACK: + return CHANNEL_LAYOUT_5POINT0_BACK; + case CH_LAYOUT_5POINT1_BACK: + return CHANNEL_LAYOUT_5POINT1_BACK; + case CH_LAYOUT_7POINT0: + return CHANNEL_LAYOUT_7POINT0; + case CH_LAYOUT_7POINT1: + return CHANNEL_LAYOUT_7POINT1; + case CH_LAYOUT_7POINT1_WIDE: + return CHANNEL_LAYOUT_7POINT1_WIDE; + case CH_LAYOUT_STEREO_DOWNMIX: + return CHANNEL_LAYOUT_STEREO_DOWNMIX; + default: + // FFmpeg channel_layout is 0 for .wav and .mp3. We know mono and stereo + // from the number of channels, otherwise report errors. + if (channels == 1) + return CHANNEL_LAYOUT_MONO; + if (channels == 2) + return CHANNEL_LAYOUT_STEREO; + DLOG(WARNING) << "Unsupported/unencountered channel layout values"; + return CHANNEL_LAYOUT_UNSUPPORTED; + } +} + base::TimeDelta GetFrameDuration(AVStream* stream) { AVRational time_base = { stream->r_frame_rate.den, stream->r_frame_rate.num }; return ConvertFromTimeBase(time_base, 1); diff --git a/media/ffmpeg/ffmpeg_common.h b/media/ffmpeg/ffmpeg_common.h index 196b57e..3d39d52 100644 --- a/media/ffmpeg/ffmpeg_common.h +++ b/media/ffmpeg/ffmpeg_common.h @@ -11,6 +11,7 @@ #include "base/compiler_specific.h" #include "base/memory/singleton.h" #include "base/time.h" +#include "media/base/channel_layout.h" #include "media/video/video_decode_engine.h" // Include FFmpeg header files. @@ -66,6 +67,12 @@ int64 ConvertToTimeBase(const AVRational& time_base, VideoCodec CodecIDToVideoCodec(CodecID codec_id); CodecID VideoCodecToCodecID(VideoCodec video_codec); +// Converts FFmpeg's channel layout to chrome's ChannelLayout. |channels| can +// be used when FFmpeg's channel layout is not informative in order to make a +// good guess about the plausible channel layout based on number of channels. +ChannelLayout ChannelLayoutToChromeChannelLayout(int64_t layout, + int channels); + // Calculates duration of one frame in the |stream| based on its frame rate. base::TimeDelta GetFrameDuration(AVStream* stream); diff --git a/media/filters/audio_renderer_base.cc b/media/filters/audio_renderer_base.cc index a98b8a2..2d6205e 100644 --- a/media/filters/audio_renderer_base.cc +++ b/media/filters/audio_renderer_base.cc @@ -105,7 +105,7 @@ void AudioRendererBase::Initialize(AudioDecoder* decoder, // Initialize our algorithm with media properties, initial playback rate, // and a callback to request more reads from the data source. AudioDecoderConfig config = decoder_->config(); - algorithm_->Initialize(config.channels_per_sample, + algorithm_->Initialize(ChannelLayoutToChannelCount(config.channel_layout), config.sample_rate, config.bits_per_channel, 0.0f, diff --git a/media/filters/audio_renderer_base_unittest.cc b/media/filters/audio_renderer_base_unittest.cc index da616ae..cd9b3a4 100644 --- a/media/filters/audio_renderer_base_unittest.cc +++ b/media/filters/audio_renderer_base_unittest.cc @@ -58,7 +58,8 @@ class AudioRendererBaseTest : public ::testing::Test { // Set up audio properties. ON_CALL(*decoder_, config()) - .WillByDefault(Return(AudioDecoderConfig(16, 1, 44100))); + .WillByDefault(Return(AudioDecoderConfig(16, CHANNEL_LAYOUT_MONO, + 44100))); } virtual ~AudioRendererBaseTest() { diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc index 807f1d1..555ccfc 100644 --- a/media/filters/ffmpeg_audio_decoder.cc +++ b/media/filters/ffmpeg_audio_decoder.cc @@ -30,7 +30,7 @@ const size_t FFmpegAudioDecoder::kOutputBufferSize = FFmpegAudioDecoder::FFmpegAudioDecoder(MessageLoop* message_loop) : DecoderBase<AudioDecoder, Buffer>(message_loop), codec_context_(NULL), - config_(0, 0, 0), + config_(0, CHANNEL_LAYOUT_NONE, 0), estimated_next_timestamp_(kNoTimestamp) { } @@ -53,11 +53,13 @@ void FFmpegAudioDecoder::DoInitialize(DemuxerStream* demuxer_stream, int bps = av_get_bits_per_sample_fmt(codec_context_->sample_fmt); if (codec_context_->channels <= 0 || codec_context_->channels > Limits::kMaxChannels || + (codec_context_->channel_layout == 0 && codec_context_->channels > 2) || bps <= 0 || bps > Limits::kMaxBitsPerSample || codec_context_->sample_rate <= 0 || codec_context_->sample_rate > Limits::kMaxSampleRate) { DLOG(WARNING) << "Invalid audio stream -" << " channels: " << codec_context_->channels + << " channel layout:" << codec_context_->channel_layout << " bps: " << bps << " sample rate: " << codec_context_->sample_rate; return; @@ -71,7 +73,9 @@ void FFmpegAudioDecoder::DoInitialize(DemuxerStream* demuxer_stream, config_.bits_per_channel = av_get_bits_per_sample_fmt(codec_context_->sample_fmt); - config_.channels_per_sample = codec_context_->channels; + config_.channel_layout = + ChannelLayoutToChromeChannelLayout(codec_context_->channel_layout, + codec_context_->channels); config_.sample_rate = codec_context_->sample_rate; // Prepare the output buffer. diff --git a/media/filters/null_audio_renderer.cc b/media/filters/null_audio_renderer.cc index de04f0a..21b3e07 100644 --- a/media/filters/null_audio_renderer.cc +++ b/media/filters/null_audio_renderer.cc @@ -63,7 +63,7 @@ void NullAudioRenderer::ThreadMain() { bool NullAudioRenderer::OnInitialize(const AudioDecoderConfig& config) { // Calculate our bytes per millisecond value and allocate our buffer. bytes_per_millisecond_ = - (config.channels_per_sample * config.sample_rate * + (ChannelLayoutToChannelCount(config.channel_layout) * config.sample_rate * config.bits_per_channel / 8) / base::Time::kMillisecondsPerSecond; buffer_size_ = bytes_per_millisecond_ * kBufferSizeInMilliseconds; buffer_.reset(new uint8[buffer_size_]); diff --git a/media/media.gyp b/media/media.gyp index 24b4c10..101ce96 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -82,6 +82,8 @@ 'base/buffers.h', 'base/callback.cc', 'base/callback.h', + 'base/channel_layout.cc', + 'base/channel_layout.h', 'base/clock.cc', 'base/clock.h', 'base/composite_data_source_factory.cc', |