summaryrefslogtreecommitdiffstats
path: root/media/audio
diff options
context:
space:
mode:
authorxians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-11 20:53:22 +0000
committerxians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-11 20:53:22 +0000
commit1defb9855a6bc4e410173eb817989aff81010193 (patch)
treec3923ab35df4c23d41d80a9fa8f4981d9747a416 /media/audio
parent6c3df71ad58c3e66db2e72355060244c6b04e399 (diff)
downloadchromium_src-1defb9855a6bc4e410173eb817989aff81010193.zip
chromium_src-1defb9855a6bc4e410173eb817989aff81010193.tar.gz
chromium_src-1defb9855a6bc4e410173eb817989aff81010193.tar.bz2
Synchronized IO handles the mono input device.
Some of the input devices like webcam microphone only supports mono, and it will fail if we open the device in stereo mode. But webaudio only supports stereo now. This patch use a channel_mixer to transform the mono data to stereo, so that live audio can work with webcam microphone now. BUG=246521 TEST=goto http://chromium.googlecode.com/svn/trunk/samples/audio/visualizer-live.html, choose the logitech webcam microphone, the demo works. Review URL: https://chromiumcodereview.appspot.com/16064004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205633 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio')
-rw-r--r--media/audio/mac/audio_synchronized_mac.cc38
-rw-r--r--media/audio/mac/audio_synchronized_mac.h6
2 files changed, 39 insertions, 5 deletions
diff --git a/media/audio/mac/audio_synchronized_mac.cc b/media/audio/mac/audio_synchronized_mac.cc
index 8a2a463..a2484ca 100644
--- a/media/audio/mac/audio_synchronized_mac.cc
+++ b/media/audio/mac/audio_synchronized_mac.cc
@@ -13,6 +13,7 @@
#include "base/mac/mac_logging.h"
#include "media/audio/audio_util.h"
#include "media/audio/mac/audio_manager_mac.h"
+#include "media/base/channel_mixer.h"
namespace media {
@@ -714,17 +715,38 @@ OSStatus AudioSynchronizedStream::SetupStreamFormats() {
}
void AudioSynchronizedStream::AllocateInputData() {
+ // Get the native number of input channels that the hardware supports.
+ int hardware_channels = 0;
+ bool got_hardware_channels = AudioManagerMac::GetDeviceChannels(
+ input_id_, kAudioDevicePropertyScopeInput, &hardware_channels);
+ if (!got_hardware_channels || hardware_channels > 2) {
+ // Only mono and stereo are supported on the input side. When it fails to
+ // get the native channel number or the native channel number is bigger
+ // than 2, we open the device in stereo mode.
+ hardware_channels = 2;
+ }
+
// Allocate storage for the AudioBufferList used for the
// input data from the input AudioUnit.
// We allocate enough space for with one AudioBuffer per channel.
size_t malloc_size = offsetof(AudioBufferList, mBuffers[0]) +
- (sizeof(AudioBuffer) * channels_);
+ (sizeof(AudioBuffer) * hardware_channels);
input_buffer_list_ = static_cast<AudioBufferList*>(malloc(malloc_size));
- input_buffer_list_->mNumberBuffers = channels_;
+ input_buffer_list_->mNumberBuffers = hardware_channels;
- input_bus_ = AudioBus::Create(channels_, hardware_buffer_size_);
+ input_bus_ = AudioBus::Create(hardware_channels, hardware_buffer_size_);
wrapper_bus_ = AudioBus::CreateWrapper(channels_);
+ if (hardware_channels != params_.input_channels()) {
+ ChannelLayout hardware_channel_layout =
+ GuessChannelLayout(hardware_channels);
+ ChannelLayout requested_channel_layout =
+ GuessChannelLayout(params_.input_channels());
+ channel_mixer_.reset(new ChannelMixer(hardware_channel_layout,
+ requested_channel_layout));
+ mixer_bus_ = AudioBus::Create(params_.input_channels(),
+ hardware_buffer_size_);
+ }
// Allocate buffers for AudioBufferList.
UInt32 buffer_size_bytes = input_bus_->frames() * sizeof(Float32);
@@ -762,8 +784,14 @@ OSStatus AudioSynchronizedStream::HandleInputCallback(
// Buffer input into FIFO.
int available_frames = fifo_.max_frames() - fifo_.frames();
- if (input_bus_->frames() <= available_frames)
- fifo_.Push(input_bus_.get());
+ if (input_bus_->frames() <= available_frames) {
+ if (channel_mixer_) {
+ channel_mixer_->Transform(input_bus_.get(), mixer_bus_.get());
+ fifo_.Push(mixer_bus_.get());
+ } else {
+ fifo_.Push(input_bus_.get());
+ }
+ }
return result;
}
diff --git a/media/audio/mac/audio_synchronized_mac.h b/media/audio/mac/audio_synchronized_mac.h
index e99d9c8..a6db48e 100644
--- a/media/audio/mac/audio_synchronized_mac.h
+++ b/media/audio/mac/audio_synchronized_mac.h
@@ -19,6 +19,7 @@
namespace media {
class AudioManagerMac;
+class ChannelMixer;
// AudioSynchronizedStream allows arbitrary combinations of input and output
// devices running off different clocks and using different drivers, with
@@ -202,6 +203,11 @@ class AudioSynchronizedStream : public AudioOutputStream {
int hardware_buffer_size_;
int channels_;
+ // Channel mixer used to transform mono to stereo data. It is only created
+ // if the input_hardware_channels is mono.
+ scoped_ptr<ChannelMixer> channel_mixer_;
+ scoped_ptr<AudioBus> mixer_bus_;
+
DISALLOW_COPY_AND_ASSIGN(AudioSynchronizedStream);
};