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

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

Issue 1695303002: Adds Media.Audio.InputDevicePropertyChangedMac UMA stat on Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/mac/audio_low_latency_input_mac.cc
diff --git a/media/audio/mac/audio_low_latency_input_mac.cc b/media/audio/mac/audio_low_latency_input_mac.cc
index 5f4507ad93769e7a8b6ba4ea338d5cf700abed2c..13bc41a95fa1562a052587eff584358e91bc6eb3 100644
--- a/media/audio/mac/audio_low_latency_input_mac.cc
+++ b/media/audio/mac/audio_low_latency_input_mac.cc
@@ -58,6 +58,20 @@ static std::ostream& operator<<(std::ostream& os,
return os;
}
+// Log if the input device is used exclusively (~hogged) by us or any other
+// process in the system.
+enum InputAudioDeviceHogResult {
+ DEVICE_IS_NOT_HOGGED = 0,
+ DEVICE_IS_HOGGED_BY_OTHER_PROCESS = 1,
+ DEVICE_IS_HOGGED_BY_OWN_PROCESS = 2,
+ DEVICE_IS_HOGGED_MAX = DEVICE_IS_HOGGED_BY_OWN_PROCESS
+};
+
+static void InputAudioDeviceHogResult(InputAudioDeviceHogResult result) {
+ UMA_HISTOGRAM_ENUMERATION("Media.Audio.InputDeviceIsHoggedMac", result,
+ DEVICE_IS_HOGGED_MAX + 1);
+}
+
static OSStatus GetInputDeviceStreamFormat(
AudioUnit audio_unit,
AudioStreamBasicDescription* format) {
@@ -72,6 +86,44 @@ static OSStatus GetInputDeviceStreamFormat(
return result;
}
+static void CheckAudioDeviceProperties(AudioDeviceID device_id) {
+ DVLOG(1) << "CheckAudioDeviceProperties(device ID: 0x" << std::hex
+ << device_id << ")";
+ // Check if the specified audio device is running in at least one process
+ // on the system. A value of 0 means that it is not running at all.
+ // The idea of checking this state is to see if the device is "alive" or not.
+ AudioObjectPropertyAddress address = {
+ kAudioDevicePropertyDeviceIsRunningSomewhere,
+ kAudioObjectPropertyScopeInput, kAudioObjectPropertyElementMaster};
+ UInt32 is_running_somewhere = 0;
+ UInt32 data_size = sizeof(is_running_somewhere);
+ OSStatus error = AudioObjectGetPropertyData(
+ device_id, &address, 0, NULL, &data_size, &is_running_somewhere);
+ DVLOG_IF(1, !error) << "kAudioDevicePropertyDeviceIsRunningSomewhere: "
+ << is_running_somewhere;
+ // TOOD(henrika): consider if it is worth adding this state to UMA.
+
+ // Check if there is any device conflict, i.e., if the device is currently
+ // owned exclusively by any other process than our own.
+ address.mSelector = kAudioDevicePropertyHogMode;
+ pid_t hog_pid = -1;
+ data_size = sizeof(hog_pid);
+ error = AudioObjectGetPropertyData(device_id, &address, 0, NULL, &data_size,
+ &hog_pid);
+ if (!error) {
+ if (hog_pid == -1) {
+ InputAudioDeviceHogResult(DEVICE_IS_NOT_HOGGED);
+ DVLOG(1) << "Device is available to all processes";
+ } else {
+ hog_pid != getpid()
+ ? InputAudioDeviceHogResult(DEVICE_IS_HOGGED_BY_OTHER_PROCESS)
+ : InputAudioDeviceHogResult(DEVICE_IS_HOGGED_BY_OWN_PROCESS);
+ DVLOG(1) << "Process with PID=" << hog_pid << " has exclusive access"
+ << " (our own PID=" << getpid() << ")";
+ }
+ }
+}
+
// See "Technical Note TN2091 - Device input using the HAL Output Audio Unit"
// http://developer.apple.com/library/mac/#technotes/tn2091/_index.html
// for more details and background regarding this implementation.
@@ -372,7 +424,8 @@ void AUAudioInputStream::Start(AudioInputCallback* callback) {
last_success_time_ = base::TimeTicks::Now();
audio_unit_render_has_worked_ = false;
StartAgc();
- OSStatus result = AudioOutputUnitStart(audio_unit_);
+ // OSStatus result = AudioOutputUnitStart(audio_unit_);
+ OSStatus result = noErr;
if (result == noErr) {
// For UMA stat purposes, start a one-shot timer which detects when input
// callbacks starts indicating if input audio recording works as intended.
@@ -904,7 +957,7 @@ void AUAudioInputStream::CheckInputStartupSuccess() {
DCHECK(thread_checker_.CalledOnValidThread());
// Only add UMA stat related to failing input audio for streams where
// the AGC has been enabled, e.g. WebRTC audio input streams.
- if (IsRunning() && GetAutomaticGainControl()) {
+ if (/*IsRunning() &&*/ GetAutomaticGainControl()) {
tommi (sloooow) - chröme 2016/02/15 15:30:12 unintentional?
// Check if we have called Start() and input callbacks have actually
// started in time as they should. If that is not the case, we have a
// problem and the stream is considered dead.
@@ -965,6 +1018,8 @@ void AUAudioInputStream::AddHistogramsForFailedStartup() {
// fixed when we understand the problem better.
UMA_HISTOGRAM_BOOLEAN("Media.Audio.AutomaticGainControlMac",
GetAutomaticGainControl());
+ // Check some extra device properties and add more UMA stats if needed.
+ CheckAudioDeviceProperties(input_device_id_);
}
} // namespace media
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698