Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: media/audio/mac/audio_manager_mac.cc

Issue 12387006: Pass more detailed audio hardware configuration information to the renderer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/audio/mac/audio_manager_mac.cc
===================================================================
--- media/audio/mac/audio_manager_mac.cc (revision 186233)
+++ media/audio/mac/audio_manager_mac.cc (working copy)
@@ -23,6 +23,7 @@
#include "media/base/channel_layout.h"
#include "media/base/limits.h"
#include "media/base/media_switches.h"
+#include "media/ffmpeg/ffmpeg_common.h"
DaleCurtis 2013/03/07 02:41:39 You can't include this here which is why I said th
Chris Rogers 2013/03/09 01:37:50 Ah I didn't understand what you had meant before -
namespace media {
@@ -263,6 +264,99 @@
return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice);
}
+// TODO(crogers): There are several places on the OSX specific code which
+// could benefit from this helper function.
+bool AudioManagerMac::GetDefaultOutputDevice(
+ AudioDeviceID* device) {
+ if (!device)
DaleCurtis 2013/03/07 02:41:39 CHECK().
Chris Rogers 2013/03/09 01:37:50 Done.
+ return false;
+
+ // Obtain the current output device selected by the user.
+ AudioObjectPropertyAddress pa;
DaleCurtis 2013/03/07 02:41:39 static const this like: static const AudioObject
Chris Rogers 2013/03/09 01:37:50 Done.
+ pa.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
+ pa.mScope = kAudioObjectPropertyScopeGlobal;
+ pa.mElement = kAudioObjectPropertyElementMaster;
+
+ UInt32 size = sizeof(*device);
+
+ OSStatus result = AudioObjectGetPropertyData(
+ kAudioObjectSystemObject,
+ &pa,
+ 0,
+ 0,
+ &size,
+ device);
+
+ if ((result != kAudioHardwareNoError) || (*device == kAudioDeviceUnknown)) {
+ LOG(ERROR) << "Error getting default output AudioDevice.";
DaleCurtis 2013/03/07 02:41:39 DLOG?
Chris Rogers 2013/03/09 01:37:50 Done.
+ return false;
+ }
+
+ return true;
+}
+
+bool AudioManagerMac::GetDefaultOutputChannels(
+ int* channels, int* channels_per_frame) {
+ AudioDeviceID device;
+ if (!GetDefaultOutputDevice(&device))
+ return false;
+
+ return GetDeviceChannels(device,
+ kAudioDevicePropertyScopeOutput,
+ channels,
+ channels_per_frame);
+}
+
+bool AudioManagerMac::GetDeviceChannels(
+ AudioDeviceID device,
+ AudioObjectPropertyScope scope,
+ int* channels,
+ int* channels_per_frame) {
DaleCurtis 2013/03/07 02:41:39 Nothing seems to be using this? Drop for now?
Chris Rogers 2013/03/09 01:37:50 It will soon be using it (AudioHardwareUnifiedStre
+ if (!channels || !channels_per_frame)
DaleCurtis 2013/03/07 02:41:39 these should be CHECK().
Chris Rogers 2013/03/09 01:37:50 Done.
+ return false;
+
+ // Get stream configuration.
+ AudioObjectPropertyAddress pa;
DaleCurtis 2013/03/07 02:41:39 Same static const comment.
Chris Rogers 2013/03/09 01:37:50 It can't be static const because the scope is set
+ pa.mSelector = kAudioDevicePropertyStreamConfiguration;
+ pa.mScope = scope;
+ pa.mElement = kAudioObjectPropertyElementMaster;
+
+ UInt32 size;
+ OSStatus result = AudioObjectGetPropertyDataSize(device, &pa, 0, 0, &size);
+ OSSTATUS_DCHECK(result == noErr, result);
DaleCurtis 2013/03/07 02:41:39 Don't DCHECK, this should just return false.
Chris Rogers 2013/03/09 01:37:50 Done.
+
+ if (result == noErr && size > 0) {
DaleCurtis 2013/03/07 02:41:39 early return instead of indenting the entire next
Chris Rogers 2013/03/09 01:37:50 Done.
+ // Allocate storage.
+ scoped_array<uint8> list_storage(new uint8[size]);
+ AudioBufferList& buffer_list =
+ *reinterpret_cast<AudioBufferList*>(list_storage.get());
+
+ result = AudioObjectGetPropertyData(
+ device,
+ &pa,
+ 0,
+ 0,
+ &size,
+ &buffer_list);
+ OSSTATUS_DCHECK(result == noErr, result);
DaleCurtis 2013/03/07 02:41:39 Ditto.
Chris Rogers 2013/03/09 01:37:50 Done.
+
+ if (result == noErr) {
+ // Determine number of input channels.
+ *channels_per_frame = buffer_list.mNumberBuffers > 0 ?
+ buffer_list.mBuffers[0].mNumberChannels : 0;
+ if (*channels_per_frame == 1 && buffer_list.mNumberBuffers > 1) {
+ // Non-interleaved.
+ *channels = buffer_list.mNumberBuffers;
+ } else {
+ // Interleaved.
+ *channels = *channels_per_frame;
+ }
+ }
+ }
+
+ return result == noErr;
+}
+
void AudioManagerMac::GetAudioInputDeviceNames(
media::AudioDeviceNames* device_names) {
GetAudioDeviceInfo(true, device_names);
@@ -336,10 +430,14 @@
AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
const AudioParameters& input_params) {
- ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
+ int hardware_channels = 2;
+ int hardware_channels_per_frame;
+ GetDefaultOutputChannels(&hardware_channels, &hardware_channels_per_frame);
+
+ ChannelLayout channel_layout = GuessChannelLayout(hardware_channels);
DaleCurtis 2013/03/07 02:41:39 Hmm, this isn't what I thought you wanted. This wi
Chris Rogers 2013/03/09 01:37:50 Actually, I'm just being consistent with the Audio
+
int input_channels = 0;
if (input_params.IsValid()) {
- channel_layout = input_params.channel_layout();
input_channels = input_params.input_channels();
if (CommandLine::ForCurrentProcess()->HasSwitch(
@@ -352,10 +450,18 @@
}
}
- return AudioParameters(
- AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels,
- AUAudioOutputStream::HardwareSampleRate(), 16,
+ AudioParameters params(
+ AudioParameters::AUDIO_PCM_LOW_LATENCY,
+ channel_layout,
+ input_channels,
+ AUAudioOutputStream::HardwareSampleRate(),
+ 16,
kDefaultLowLatencyBufferSize);
+
+ if (channel_layout == CHANNEL_LAYOUT_UNSUPPORTED)
DaleCurtis 2013/03/07 02:41:39 DISCRETE?
Chris Rogers 2013/03/09 01:37:50 Actually, I think that's right because GuessChanne
+ params.SetDiscreteChannels(hardware_channels);
+
+ return params;
}
void AudioManagerMac::CreateDeviceListener() {

Powered by Google App Engine
This is Rietveld 408576698