Commit bd7ce60f authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

Update support for default/communications devices in AudioManager

This CL introduces functions to get the ID name of the following
special devices in AudioManager.
- Default audio input device
- Communications audio input device
- Communications audio output device

There was already a similar function for the default audio output device.

In enumeration results, the label of special device entries now have
appended the label of the corresponding real device.

This CL also adds implementation of the new functionality for Mac,
and reverts the effects of http://crrev.com/520087, which implemented
similar but more limited functionality.

Bug: 780492
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Iee5afc2fc231913baddaf6ef3fedd4535b3d9841
Reviewed-on: https://chromium-review.googlesource.com/803814Reviewed-by: default avatarOlga Sharonova <olka@chromium.org>
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521682}
parent 5e84f2f5
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "content/browser/renderer_host/media/in_process_video_capture_provider.h" #include "content/browser/renderer_host/media/in_process_video_capture_provider.h"
...@@ -52,9 +51,7 @@ const char kNormalVideoDeviceID[] = "/dev/video0"; ...@@ -52,9 +51,7 @@ const char kNormalVideoDeviceID[] = "/dev/video0";
const char kNoFormatsVideoDeviceID[] = "/dev/video1"; const char kNoFormatsVideoDeviceID[] = "/dev/video1";
const char kZeroResolutionVideoDeviceID[] = "/dev/video2"; const char kZeroResolutionVideoDeviceID[] = "/dev/video2";
const char* const kDefaultVideoDeviceID = kZeroResolutionVideoDeviceID; const char* const kDefaultVideoDeviceID = kZeroResolutionVideoDeviceID;
const char kUserDefaultAudioInputDeviceID[] = "fake_audio_input_2"; const char kDefaultAudioDeviceID[] = "fake_audio_input_2";
const char kSystemDefaultAudioInputLabel[] = "Fake Audio Input 1";
const char kSystemDefaultAudioOutputLabel[] = "Fake Audio Output 1";
const auto kIgnoreLogMessageCB = base::BindRepeating([](const std::string&) {}); const auto kIgnoreLogMessageCB = base::BindRepeating([](const std::string&) {});
...@@ -95,8 +92,7 @@ class MediaDevicesDispatcherHostTest : public testing::TestWithParam<GURL> { ...@@ -95,8 +92,7 @@ class MediaDevicesDispatcherHostTest : public testing::TestWithParam<GURL> {
switches::kUseFakeDeviceForMediaStream, switches::kUseFakeDeviceForMediaStream,
base::StringPrintf("video-input-default-id=%s, " base::StringPrintf("video-input-default-id=%s, "
"audio-input-default-id=%s", "audio-input-default-id=%s",
kDefaultVideoDeviceID, kDefaultVideoDeviceID, kDefaultAudioDeviceID));
kUserDefaultAudioInputDeviceID));
audio_manager_ = std::make_unique<media::MockAudioManager>( audio_manager_ = std::make_unique<media::MockAudioManager>(
std::make_unique<media::TestAudioThread>()); std::make_unique<media::TestAudioThread>());
audio_system_ = audio_system_ =
...@@ -202,7 +198,7 @@ class MediaDevicesDispatcherHostTest : public testing::TestWithParam<GURL> { ...@@ -202,7 +198,7 @@ class MediaDevicesDispatcherHostTest : public testing::TestWithParam<GURL> {
EXPECT_EQ(kNumExpectedEntries, capabilities.size()); EXPECT_EQ(kNumExpectedEntries, capabilities.size());
std::string expected_first_device_id = std::string expected_first_device_id =
GetHMACForMediaDeviceID(browser_context_->GetMediaDeviceIDSalt(), GetHMACForMediaDeviceID(browser_context_->GetMediaDeviceIDSalt(),
origin_, kUserDefaultAudioInputDeviceID); origin_, kDefaultAudioDeviceID);
EXPECT_EQ(expected_first_device_id, capabilities[0]->device_id); EXPECT_EQ(expected_first_device_id, capabilities[0]->device_id);
for (const auto& capability : capabilities) for (const auto& capability : capabilities)
EXPECT_TRUE(capability->parameters.IsValid()); EXPECT_TRUE(capability->parameters.IsValid());
...@@ -308,15 +304,8 @@ class MediaDevicesDispatcherHostTest : public testing::TestWithParam<GURL> { ...@@ -308,15 +304,8 @@ class MediaDevicesDispatcherHostTest : public testing::TestWithParam<GURL> {
} }
// Returns true if all devices have labels, false otherwise. // Returns true if all devices have labels, false otherwise.
bool DoesContainLabels( bool DoesContainLabels(const MediaDeviceInfoArray& device_infos) {
const MediaDeviceInfoArray& device_infos,
const std::string& system_default_label = std::string()) {
for (const auto& device_info : device_infos) { for (const auto& device_info : device_infos) {
if (media::AudioDeviceDescription::IsDefaultDevice(
device_info.device_id)) {
EXPECT_TRUE(base::EndsWith(device_info.label, system_default_label,
base::CompareCase::SENSITIVE));
}
if (device_info.label.empty()) if (device_info.label.empty())
return false; return false;
} }
...@@ -325,13 +314,8 @@ class MediaDevicesDispatcherHostTest : public testing::TestWithParam<GURL> { ...@@ -325,13 +314,8 @@ class MediaDevicesDispatcherHostTest : public testing::TestWithParam<GURL> {
// Returns true if all devices have labels, false otherwise. // Returns true if all devices have labels, false otherwise.
bool DoesContainLabels(const std::vector<MediaDeviceInfoArray>& enumeration) { bool DoesContainLabels(const std::vector<MediaDeviceInfoArray>& enumeration) {
for (int i = 0; i < NUM_MEDIA_DEVICE_TYPES; i++) { for (const auto& device_infos : enumeration) {
std::string default_label; if (!DoesContainLabels(device_infos))
if (i == MEDIA_DEVICE_TYPE_AUDIO_INPUT)
default_label = kSystemDefaultAudioInputLabel;
else if (i == MEDIA_DEVICE_TYPE_AUDIO_OUTPUT)
default_label = kSystemDefaultAudioOutputLabel;
if (!DoesContainLabels(enumeration[i], default_label))
return false; return false;
} }
return true; return true;
......
...@@ -49,23 +49,23 @@ std::string GetLogMessageString(MediaDeviceType device_type, ...@@ -49,23 +49,23 @@ std::string GetLogMessageString(MediaDeviceType device_type,
return output_string; return output_string;
} }
media::AudioDeviceDescriptions GetFakeAudioDevices(bool is_input) { MediaDeviceInfoArray GetFakeAudioDevices(bool is_input) {
media::AudioDeviceDescriptions result; MediaDeviceInfoArray result;
if (is_input) { if (is_input) {
result.emplace_back("Fake Default Audio Input", result.emplace_back(media::AudioDeviceDescription::kDefaultDeviceId,
media::AudioDeviceDescription::kDefaultDeviceId, "Fake Default Audio Input",
"fake_group_audio_1"); "fake_group_audio_input_default");
result.emplace_back("Fake Audio Input 1", "fake_audio_input_1", result.emplace_back("fake_audio_input_1", "Fake Audio Input 1",
"fake_group_audio_1"); "fake_group_audio_input_1");
result.emplace_back("Fake Audio Input 2", "fake_audio_input_2", result.emplace_back("fake_audio_input_2", "Fake Audio Input 2",
"fake_group_audio_input_2"); "fake_group_audio_input_2");
} else { } else {
result.emplace_back("Fake Default Audio Output", result.emplace_back(media::AudioDeviceDescription::kDefaultDeviceId,
media::AudioDeviceDescription::kDefaultDeviceId, "Fake Default Audio Output",
"fake_group_audio_1"); "fake_group_audio_output_default");
result.emplace_back("Fake Audio Output 1", "fake_audio_output_1", result.emplace_back("fake_audio_output_1", "Fake Audio Output 1",
"fake_group_audio_1"); "fake_group_audio_output_1");
result.emplace_back("Fake Audio Output 2", "fake_audio_output_2", result.emplace_back("fake_audio_output_2", "Fake Audio Output 2",
"fake_group_audio_output_2"); "fake_group_audio_output_2");
} }
...@@ -339,7 +339,7 @@ void MediaDevicesManager::EnumerateAudioDevices(bool is_input) { ...@@ -339,7 +339,7 @@ void MediaDevicesManager::EnumerateAudioDevices(bool is_input) {
is_input ? MEDIA_DEVICE_TYPE_AUDIO_INPUT : MEDIA_DEVICE_TYPE_AUDIO_OUTPUT; is_input ? MEDIA_DEVICE_TYPE_AUDIO_INPUT : MEDIA_DEVICE_TYPE_AUDIO_OUTPUT;
if (use_fake_devices_) { if (use_fake_devices_) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&MediaDevicesManager::AudioDevicesEnumerated, FROM_HERE, base::BindOnce(&MediaDevicesManager::DevicesEnumerated,
weak_factory_.GetWeakPtr(), type, weak_factory_.GetWeakPtr(), type,
GetFakeAudioDevices(is_input))); GetFakeAudioDevices(is_input)));
return; return;
...@@ -365,56 +365,10 @@ void MediaDevicesManager::AudioDevicesEnumerated( ...@@ -365,56 +365,10 @@ void MediaDevicesManager::AudioDevicesEnumerated(
media::AudioDeviceDescriptions device_descriptions) { media::AudioDeviceDescriptions device_descriptions) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
auto it_default_device =
std::find_if(device_descriptions.begin(), device_descriptions.end(),
[](const media::AudioDeviceDescription& description) {
return media::AudioDeviceDescription::IsDefaultDevice(
description.unique_id);
});
auto it_real_default_device = device_descriptions.end();
if (it_default_device != device_descriptions.end()) {
// Find the real device that maps to the default device by finding
// coincidence in the group ID.
// This approach works only when the following is true:
// * group ID is properly supported so that the default device has the
// same group ID as some real device.
// * For input devices, the default device has an associated output device.
// * There is only one device with the same group ID of the default device.
// TODO(guidou): Get the real ID of the default input device from
// media::AudioSystem when the functionality becomes available.
// http://crbug.com/788758
for (auto it = device_descriptions.begin(); it != device_descriptions.end();
++it) {
if (it->group_id == it_default_device->group_id &&
!media::AudioDeviceDescription::IsDefaultDevice(it->unique_id)) {
if (it_real_default_device != device_descriptions.end()) {
// If there is more than one real device with the same group ID as the
// default device, the exact mapping cannot be found.
it_real_default_device = device_descriptions.end();
break;
} else {
it_real_default_device = it;
}
}
}
}
MediaDeviceInfoArray snapshot; MediaDeviceInfoArray snapshot;
for (const media::AudioDeviceDescription& description : device_descriptions) { for (const media::AudioDeviceDescription& description : device_descriptions) {
if (it_real_default_device != device_descriptions.end() && snapshot.emplace_back(description);
media::AudioDeviceDescription::IsDefaultDevice(description.unique_id)) {
// TODO(guidou): Make the concatenation of the default and real device
// labels in a properly localized manner. http://crbug.com/788767
snapshot.emplace_back(
description.unique_id,
description.device_name + " - " + it_real_default_device->device_name,
description.group_id);
} else {
snapshot.emplace_back(description);
}
} }
DevicesEnumerated(type, snapshot); DevicesEnumerated(type, snapshot);
} }
......
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/logging.h"
#include "media/audio/audio_device_description.h" #include "media/audio/audio_device_description.h"
#include <utility>
#include "base/logging.h"
#include "media/base/localized_strings.h" #include "media/base/localized_strings.h"
namespace media { namespace media {
...@@ -19,6 +22,12 @@ bool AudioDeviceDescription::IsDefaultDevice(const std::string& device_id) { ...@@ -19,6 +22,12 @@ bool AudioDeviceDescription::IsDefaultDevice(const std::string& device_id) {
device_id == AudioDeviceDescription::kDefaultDeviceId; device_id == AudioDeviceDescription::kDefaultDeviceId;
} }
// static
bool AudioDeviceDescription::IsCommunicationsDevice(
const std::string& device_id) {
return device_id == AudioDeviceDescription::kCommunicationsDeviceId;
}
// static // static
bool AudioDeviceDescription::IsLoopbackDevice(const std::string& device_id) { bool AudioDeviceDescription::IsLoopbackDevice(const std::string& device_id) {
return device_id.compare(kLoopbackInputDeviceId) == 0 || return device_id.compare(kLoopbackInputDeviceId) == 0 ||
...@@ -52,9 +61,29 @@ std::string AudioDeviceDescription::GetCommunicationsDeviceName() { ...@@ -52,9 +61,29 @@ std::string AudioDeviceDescription::GetCommunicationsDeviceName() {
#endif #endif
} }
AudioDeviceDescription::AudioDeviceDescription(const std::string& device_name, // static
const std::string& unique_id, std::string AudioDeviceDescription::GetDefaultDeviceName(
const std::string& group_id) const std::string& real_device_name) {
: device_name(device_name), unique_id(unique_id), group_id(group_id) {} DCHECK(!real_device_name.empty());
// TODO(guidou): Put the names together in a localized manner.
// http://crbug.com/788767
return GetDefaultDeviceName() + " - " + real_device_name;
}
// static
std::string AudioDeviceDescription::GetCommunicationsDeviceName(
const std::string& real_device_name) {
DCHECK(!real_device_name.empty());
// TODO(guidou): Put the names together in a localized manner.
// http://crbug.com/788767
return GetCommunicationsDeviceName() + " - " + real_device_name;
}
AudioDeviceDescription::AudioDeviceDescription(std::string device_name,
std::string unique_id,
std::string group_id)
: device_name(std::move(device_name)),
unique_id(std::move(unique_id)),
group_id(std::move(group_id)) {}
} // namespace media } // namespace media
...@@ -38,6 +38,9 @@ struct MEDIA_EXPORT AudioDeviceDescription { ...@@ -38,6 +38,9 @@ struct MEDIA_EXPORT AudioDeviceDescription {
// Returns true if |device_id| represents the default device. // Returns true if |device_id| represents the default device.
static bool IsDefaultDevice(const std::string& device_id); static bool IsDefaultDevice(const std::string& device_id);
// Returns true if |device_id| represents the communications device.
static bool IsCommunicationsDevice(const std::string& device_id);
// Returns true if |device_id| represents a loopback audio capture device. // Returns true if |device_id| represents a loopback audio capture device.
static bool IsLoopbackDevice(const std::string& device_id); static bool IsLoopbackDevice(const std::string& device_id);
...@@ -52,14 +55,23 @@ struct MEDIA_EXPORT AudioDeviceDescription { ...@@ -52,14 +55,23 @@ struct MEDIA_EXPORT AudioDeviceDescription {
// Returns the localized name of the generic "default" device. // Returns the localized name of the generic "default" device.
static std::string GetDefaultDeviceName(); static std::string GetDefaultDeviceName();
// Returns a localized version of name of the generic "default" device that
// includes the given |real_device_name|.
static std::string GetDefaultDeviceName(const std::string& real_device_name);
// Returns the localized name of the generic default communications device. // Returns the localized name of the generic default communications device.
// This device is not supported on all platforms. // This device is not supported on all platforms.
static std::string GetCommunicationsDeviceName(); static std::string GetCommunicationsDeviceName();
// Returns a localized version of name of the generic communications device
// that includes the given |real_device_name|.
static std::string GetCommunicationsDeviceName(
const std::string& real_device_name);
AudioDeviceDescription(const AudioDeviceDescription& other) = default; AudioDeviceDescription(const AudioDeviceDescription& other) = default;
AudioDeviceDescription(const std::string& device_name, AudioDeviceDescription(std::string device_name,
const std::string& unique_id, std::string unique_id,
const std::string& group_id); std::string group_id);
~AudioDeviceDescription() = default; ~AudioDeviceDescription() = default;
......
...@@ -61,4 +61,24 @@ std::string AudioDeviceInfoAccessorForTests::GetAssociatedOutputDeviceID( ...@@ -61,4 +61,24 @@ std::string AudioDeviceInfoAccessorForTests::GetAssociatedOutputDeviceID(
return audio_manager_->GetAssociatedOutputDeviceID(input_device_id); return audio_manager_->GetAssociatedOutputDeviceID(input_device_id);
} }
std::string AudioDeviceInfoAccessorForTests::GetDefaultInputDeviceID() {
DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
return audio_manager_->GetDefaultInputDeviceID();
}
std::string AudioDeviceInfoAccessorForTests::GetDefaultOutputDeviceID() {
DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
return audio_manager_->GetDefaultOutputDeviceID();
}
std::string AudioDeviceInfoAccessorForTests::GetCommunicationsInputDeviceID() {
DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
return audio_manager_->GetCommunicationsInputDeviceID();
}
std::string AudioDeviceInfoAccessorForTests::GetCommunicationsOutputDeviceID() {
DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread());
return audio_manager_->GetCommunicationsOutputDeviceID();
}
} // namespace media } // namespace media
...@@ -38,6 +38,14 @@ class AudioDeviceInfoAccessorForTests { ...@@ -38,6 +38,14 @@ class AudioDeviceInfoAccessorForTests {
std::string GetAssociatedOutputDeviceID(const std::string& input_device_id); std::string GetAssociatedOutputDeviceID(const std::string& input_device_id);
std::string GetDefaultInputDeviceID();
std::string GetDefaultOutputDeviceID();
std::string GetCommunicationsInputDeviceID();
std::string GetCommunicationsOutputDeviceID();
private: private:
AudioManager* const audio_manager_; AudioManager* const audio_manager_;
......
...@@ -252,6 +252,15 @@ class MEDIA_EXPORT AudioManager { ...@@ -252,6 +252,15 @@ class MEDIA_EXPORT AudioManager {
virtual std::string GetAssociatedOutputDeviceID( virtual std::string GetAssociatedOutputDeviceID(
const std::string& input_device_id) = 0; const std::string& input_device_id) = 0;
// These functions return the ID of the default/communications audio
// input/output devices respectively.
// Implementations that do not support this functionality should return an
// empty string.
virtual std::string GetDefaultInputDeviceID() = 0;
virtual std::string GetDefaultOutputDeviceID() = 0;
virtual std::string GetCommunicationsInputDeviceID() = 0;
virtual std::string GetCommunicationsOutputDeviceID() = 0;
private: private:
friend class AudioSystemHelper; friend class AudioSystemHelper;
......
...@@ -124,24 +124,68 @@ AudioManagerBase::~AudioManagerBase() { ...@@ -124,24 +124,68 @@ AudioManagerBase::~AudioManagerBase() {
void AudioManagerBase::GetAudioInputDeviceDescriptions( void AudioManagerBase::GetAudioInputDeviceDescriptions(
AudioDeviceDescriptions* device_descriptions) { AudioDeviceDescriptions* device_descriptions) {
CHECK(GetTaskRunner()->BelongsToCurrentThread()); CHECK(GetTaskRunner()->BelongsToCurrentThread());
AudioDeviceNames device_names; GetAudioDeviceDescriptions(device_descriptions,
GetAudioInputDeviceNames(&device_names); &AudioManagerBase::GetAudioInputDeviceNames,
&AudioManagerBase::GetDefaultInputDeviceID,
for (const media::AudioDeviceName& name : device_names) { &AudioManagerBase::GetCommunicationsInputDeviceID,
device_descriptions->emplace_back(name.device_name, name.unique_id, &AudioManagerBase::GetGroupIDInput);
GetGroupIDInput(name.unique_id));
}
} }
void AudioManagerBase::GetAudioOutputDeviceDescriptions( void AudioManagerBase::GetAudioOutputDeviceDescriptions(
AudioDeviceDescriptions* device_descriptions) { AudioDeviceDescriptions* device_descriptions) {
CHECK(GetTaskRunner()->BelongsToCurrentThread()); CHECK(GetTaskRunner()->BelongsToCurrentThread());
GetAudioDeviceDescriptions(device_descriptions,
&AudioManagerBase::GetAudioOutputDeviceNames,
&AudioManagerBase::GetDefaultOutputDeviceID,
&AudioManagerBase::GetCommunicationsOutputDeviceID,
&AudioManagerBase::GetGroupIDOutput);
}
void AudioManagerBase::GetAudioDeviceDescriptions(
AudioDeviceDescriptions* device_descriptions,
void (AudioManagerBase::*get_device_names)(AudioDeviceNames*),
std::string (AudioManagerBase::*get_default_device_id)(),
std::string (AudioManagerBase::*get_communications_device_id)(),
std::string (AudioManagerBase::*get_group_id)(const std::string&)) {
CHECK(GetTaskRunner()->BelongsToCurrentThread());
AudioDeviceNames device_names; AudioDeviceNames device_names;
GetAudioOutputDeviceNames(&device_names); (this->*get_device_names)(&device_names);
std::string real_default_device_id = (this->*get_default_device_id)();
std::string real_communications_device_id =
(this->*get_communications_device_id)();
std::string real_default_name;
std::string real_communications_name;
// Find the names for the real devices that are mapped to the default and
// communications devices.
for (const auto& name : device_names) {
if (name.unique_id == real_default_device_id)
real_default_name = name.device_name;
else if (name.unique_id == real_communications_device_id)
real_communications_name = name.device_name;
}
for (const media::AudioDeviceName& name : device_names) { for (auto& name : device_names) {
device_descriptions->emplace_back(name.device_name, name.unique_id, // The |device_name| field as returned by get_device_names() contains a
GetGroupIDOutput(name.unique_id)); // a generic string such as "Default" or "Communications" for the default
// and communications devices. If the names of the real devices mapped to
// the default or communications devices were found, append the name of
// the real devices to the corresponding entries.
// It is possible that the real names were not found if a new device was
// plugged in and designated as default/communications device after
// get_device_names() returns and before get_default_device_id() or
// get_communications_device_id() is called.
std::string device_name = std::move(name.device_name);
if (AudioDeviceDescription::IsDefaultDevice(name.unique_id) &&
!real_default_name.empty()) {
device_name += " - " + real_default_name;
} else if (AudioDeviceDescription::IsCommunicationsDevice(name.unique_id) &&
!real_communications_name.empty()) {
device_name += " - " + real_communications_name;
}
std::string group_id = (this->*get_group_id)(name.unique_id);
device_descriptions->emplace_back(
std::move(device_name), std::move(name.unique_id), std::move(group_id));
} }
} }
...@@ -456,7 +500,7 @@ AudioParameters AudioManagerBase::GetInputStreamParameters( ...@@ -456,7 +500,7 @@ AudioParameters AudioManagerBase::GetInputStreamParameters(
std::string AudioManagerBase::GetAssociatedOutputDeviceID( std::string AudioManagerBase::GetAssociatedOutputDeviceID(
const std::string& input_device_id) { const std::string& input_device_id) {
return ""; return std::string();
} }
std::string AudioManagerBase::GetGroupIDOutput( std::string AudioManagerBase::GetGroupIDOutput(
...@@ -481,8 +525,20 @@ std::string AudioManagerBase::GetGroupIDInput( ...@@ -481,8 +525,20 @@ std::string AudioManagerBase::GetGroupIDInput(
return GetGroupIDOutput(output_device_id); return GetGroupIDOutput(output_device_id);
} }
std::string AudioManagerBase::GetDefaultInputDeviceID() {
return std::string();
}
std::string AudioManagerBase::GetDefaultOutputDeviceID() { std::string AudioManagerBase::GetDefaultOutputDeviceID() {
return ""; return std::string();
}
std::string AudioManagerBase::GetCommunicationsInputDeviceID() {
return std::string();
}
std::string AudioManagerBase::GetCommunicationsOutputDeviceID() {
return std::string();
} }
// static // static
......
...@@ -151,9 +151,10 @@ class MEDIA_EXPORT AudioManagerBase : public AudioManager { ...@@ -151,9 +151,10 @@ class MEDIA_EXPORT AudioManagerBase : public AudioManager {
// which must initially be empty. // which must initially be empty.
virtual void GetAudioOutputDeviceNames(AudioDeviceNames* device_names); virtual void GetAudioOutputDeviceNames(AudioDeviceNames* device_names);
// Returns the ID of the default audio output device. std::string GetDefaultInputDeviceID() override;
// Implementations that don't yet support this should return an empty string. std::string GetDefaultOutputDeviceID() override;
virtual std::string GetDefaultOutputDeviceID(); std::string GetCommunicationsInputDeviceID() override;
std::string GetCommunicationsOutputDeviceID() override;
virtual std::unique_ptr<AudioDebugRecordingManager> virtual std::unique_ptr<AudioDebugRecordingManager>
CreateAudioDebugRecordingManager( CreateAudioDebugRecordingManager(
...@@ -178,6 +179,13 @@ class MEDIA_EXPORT AudioManagerBase : public AudioManager { ...@@ -178,6 +179,13 @@ class MEDIA_EXPORT AudioManagerBase : public AudioManager {
// AudioManager: // AudioManager:
void InitializeDebugRecording() final; void InitializeDebugRecording() final;
void GetAudioDeviceDescriptions(
AudioDeviceDescriptions* descriptions,
void (AudioManagerBase::*get_device_names)(AudioDeviceNames*),
std::string (AudioManagerBase::*get_default_device_id)(),
std::string (AudioManagerBase::*get_communications_device_id)(),
std::string (AudioManagerBase::*get_group_id)(const std::string&));
// Max number of open output streams, modified by // Max number of open output streams, modified by
// SetMaxOutputStreamsAllowed(). // SetMaxOutputStreamsAllowed().
int max_num_output_streams_; int max_num_output_streams_;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/test/test_message_loop.h" #include "base/test/test_message_loop.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
...@@ -180,6 +181,36 @@ const AudioNode kUSBCameraMic(true, ...@@ -180,6 +181,36 @@ const AudioNode kUSBCameraMic(true,
0); 0);
#endif // defined(USE_CRAS) #endif // defined(USE_CRAS)
const char kRealDefaultInputDeviceID[] = "input3";
const char kRealDefaultOutputDeviceID[] = "output4";
const char kRealCommunicationsInputDeviceID[] = "input2";
const char kRealCommunicationsOutputDeviceID[] = "output2";
void CheckDescriptionLabels(const AudioDeviceDescriptions& descriptions,
const std::string& real_default_id,
const std::string& real_communications_id) {
std::string real_default_label;
std::string real_communications_label;
for (const auto& description : descriptions) {
if (description.unique_id == real_default_id)
real_default_label = description.device_name;
else if (description.unique_id == real_communications_id)
real_communications_label = description.device_name;
}
for (const auto& description : descriptions) {
if (AudioDeviceDescription::IsDefaultDevice(description.unique_id)) {
EXPECT_TRUE(base::EndsWith(description.device_name, real_default_label,
base::CompareCase::SENSITIVE));
} else if (description.unique_id ==
AudioDeviceDescription::kCommunicationsDeviceId) {
EXPECT_TRUE(base::EndsWith(description.device_name,
real_communications_label,
base::CompareCase::SENSITIVE));
}
}
}
} // namespace } // namespace
// Test fixture which allows us to override the default enumeration API on // Test fixture which allows us to override the default enumeration API on
...@@ -258,8 +289,9 @@ class AudioManagerTest : public ::testing::Test { ...@@ -258,8 +289,9 @@ class AudioManagerTest : public ::testing::Test {
AudioDeviceDescriptions::const_iterator it = device_descriptions.begin(); AudioDeviceDescriptions::const_iterator it = device_descriptions.begin();
// The first device in the list should always be the default device. // The first device in the list should always be the default device.
EXPECT_EQ(AudioDeviceDescription::GetDefaultDeviceName(), EXPECT_TRUE(base::StartsWith(
it->device_name); it->device_name, AudioDeviceDescription::GetDefaultDeviceName(),
base::CompareCase::SENSITIVE));
EXPECT_EQ(std::string(AudioDeviceDescription::kDefaultDeviceId), EXPECT_EQ(std::string(AudioDeviceDescription::kDefaultDeviceId),
it->unique_id); it->unique_id);
++it; ++it;
...@@ -600,7 +632,18 @@ class TestAudioManager : public FakeAudioManager { ...@@ -600,7 +632,18 @@ class TestAudioManager : public FakeAudioManager {
AudioLogFactory* audio_log_factory) AudioLogFactory* audio_log_factory)
: FakeAudioManager(std::move(audio_thread), audio_log_factory) {} : FakeAudioManager(std::move(audio_thread), audio_log_factory) {}
std::string GetDefaultOutputDeviceID() override { return "output4"; } std::string GetDefaultInputDeviceID() override {
return kRealDefaultInputDeviceID;
}
std::string GetDefaultOutputDeviceID() override {
return kRealDefaultOutputDeviceID;
}
std::string GetCommunicationsInputDeviceID() override {
return kRealCommunicationsInputDeviceID;
}
std::string GetCommunicationsOutputDeviceID() override {
return kRealCommunicationsOutputDeviceID;
}
std::string GetAssociatedOutputDeviceID( std::string GetAssociatedOutputDeviceID(
const std::string& input_id) override { const std::string& input_id) override {
...@@ -659,6 +702,29 @@ TEST_F(AudioManagerTest, GroupId) { ...@@ -659,6 +702,29 @@ TEST_F(AudioManagerTest, GroupId) {
EXPECT_NE(inputs[1].group_id, outputs[3].group_id); EXPECT_NE(inputs[1].group_id, outputs[3].group_id);
} }
TEST_F(AudioManagerTest, DefaultCommunicationsLabelsContainRealLabels) {
CreateAudioManagerForTesting<TestAudioManager>();
std::string default_input_id =
device_info_accessor_->GetDefaultInputDeviceID();
EXPECT_EQ(default_input_id, kRealDefaultInputDeviceID);
std::string default_output_id =
device_info_accessor_->GetDefaultOutputDeviceID();
EXPECT_EQ(default_output_id, kRealDefaultOutputDeviceID);
std::string communications_input_id =
device_info_accessor_->GetCommunicationsInputDeviceID();
EXPECT_EQ(communications_input_id, kRealCommunicationsInputDeviceID);
std::string communications_output_id =
device_info_accessor_->GetCommunicationsOutputDeviceID();
EXPECT_EQ(communications_output_id, kRealCommunicationsOutputDeviceID);
AudioDeviceDescriptions inputs;
device_info_accessor_->GetAudioInputDeviceDescriptions(&inputs);
CheckDescriptionLabels(inputs, default_input_id, communications_input_id);
AudioDeviceDescriptions outputs;
device_info_accessor_->GetAudioOutputDeviceDescriptions(&outputs);
CheckDescriptionLabels(outputs, default_output_id, communications_output_id);
}
TEST_F(AudioManagerTest, AudioDebugRecording) { TEST_F(AudioManagerTest, AudioDebugRecording) {
CreateAudioManagerForTesting<TestAudioManager>(); CreateAudioManagerForTesting<TestAudioManager>();
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>
#include <utility>
#include <vector> #include <vector>
#include "base/bind.h" #include "base/bind.h"
...@@ -789,9 +790,19 @@ AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( ...@@ -789,9 +790,19 @@ AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream(
} }
std::string AudioManagerMac::GetDefaultOutputDeviceID() { std::string AudioManagerMac::GetDefaultOutputDeviceID() {
DCHECK(GetTaskRunner()->BelongsToCurrentThread());
return GetDefaultDeviceID(false /* is_input */);
}
std::string AudioManagerMac::GetDefaultInputDeviceID() {
DCHECK(GetTaskRunner()->BelongsToCurrentThread());
return GetDefaultDeviceID(true /* is_input */);
}
std::string AudioManagerMac::GetDefaultDeviceID(bool is_input) {
DCHECK(GetTaskRunner()->BelongsToCurrentThread()); DCHECK(GetTaskRunner()->BelongsToCurrentThread());
AudioDeviceID device_id = kAudioObjectUnknown; AudioDeviceID device_id = kAudioObjectUnknown;
if (!GetDefaultOutputDevice(&device_id)) if (!GetDefaultDevice(&device_id, is_input))
return std::string(); return std::string();
const AudioObjectPropertyAddress property_address = { const AudioObjectPropertyAddress property_address = {
......
...@@ -60,6 +60,8 @@ class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase { ...@@ -60,6 +60,8 @@ class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase {
const AudioParameters& params, const AudioParameters& params,
const std::string& device_id, const std::string& device_id,
const LogCallback& log_callback) override; const LogCallback& log_callback) override;
std::string GetDefaultInputDeviceID() override;
std::string GetDefaultOutputDeviceID() override; std::string GetDefaultOutputDeviceID() override;
// Used to track destruction of input and output streams. // Used to track destruction of input and output streams.
...@@ -178,6 +180,8 @@ class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase { ...@@ -178,6 +180,8 @@ class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase {
// account. // account.
bool IncreaseIOBufferSizeIfPossible(AudioDeviceID device_id); bool IncreaseIOBufferSizeIfPossible(AudioDeviceID device_id);
std::string GetDefaultDeviceID(bool is_input);
std::unique_ptr<AudioDeviceListenerMac> output_device_listener_; std::unique_ptr<AudioDeviceListenerMac> output_device_listener_;
// Track the output sample-rate and the default output device // Track the output sample-rate and the default output device
......
...@@ -103,6 +103,19 @@ std::string MockAudioManager::GetAssociatedOutputDeviceID( ...@@ -103,6 +103,19 @@ std::string MockAudioManager::GetAssociatedOutputDeviceID(
: get_associated_output_device_id_cb_.Run(input_device_id); : get_associated_output_device_id_cb_.Run(input_device_id);
} }
std::string MockAudioManager::GetDefaultInputDeviceID() {
return std::string();
}
std::string MockAudioManager::GetDefaultOutputDeviceID() {
return std::string();
}
std::string MockAudioManager::GetCommunicationsInputDeviceID() {
return std::string();
}
std::string MockAudioManager::GetCommunicationsOutputDeviceID() {
return std::string();
}
std::unique_ptr<AudioLog> MockAudioManager::CreateAudioLog( std::unique_ptr<AudioLog> MockAudioManager::CreateAudioLog(
AudioLogFactory::AudioComponent component) { AudioLogFactory::AudioComponent component) {
return nullptr; return nullptr;
......
...@@ -99,6 +99,10 @@ class MockAudioManager : public AudioManager { ...@@ -99,6 +99,10 @@ class MockAudioManager : public AudioManager {
const std::string& device_id) override; const std::string& device_id) override;
std::string GetAssociatedOutputDeviceID( std::string GetAssociatedOutputDeviceID(
const std::string& input_device_id) override; const std::string& input_device_id) override;
std::string GetDefaultInputDeviceID() override;
std::string GetDefaultOutputDeviceID() override;
std::string GetCommunicationsInputDeviceID() override;
std::string GetCommunicationsOutputDeviceID() override;
private: private:
AudioParameters input_params_; AudioParameters input_params_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment