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

Side by Side Diff: media/audio/mac/audio_low_latency_input_mac.cc

Issue 645923002: Add support for audio input mute detection on all platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed audio_recorder_unittest Created 6 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/audio/mac/audio_low_latency_input_mac.h" 5 #include "media/audio/mac/audio_low_latency_input_mac.h"
6 6
7 #include <CoreServices/CoreServices.h> 7 #include <CoreServices/CoreServices.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 444
445 // Get the average volume of the channels. 445 // Get the average volume of the channels.
446 if (successful_channels != 0) 446 if (successful_channels != 0)
447 return static_cast<double>(volume_float32 / successful_channels); 447 return static_cast<double>(volume_float32 / successful_channels);
448 } 448 }
449 449
450 DLOG(WARNING) << "Failed to get volume"; 450 DLOG(WARNING) << "Failed to get volume";
451 return 0.0; 451 return 0.0;
452 } 452 }
453 453
454 bool AUAudioInputStream::IsMuted() {
455 // Verify that we have a valid device.
456 if (input_device_id_ == kAudioObjectUnknown) {
457 NOTREACHED() << "Device ID is unknown";
tommi (sloooow) - chröme 2014/10/15 17:00:48 should this be a DCHECK then? DCHECK_NE(input_dev
458 return false;
459 }
460
461 AudioObjectPropertyAddress property_address = {
462 kAudioDevicePropertyMute,
tommi (sloooow) - chröme 2014/10/15 17:00:48 nit: indent by two spaces and put the closing brac
henrika (OOO until Aug 14) 2014/10/16 09:58:00 Done.
463 kAudioDevicePropertyScopeInput,
464 kAudioObjectPropertyElementMaster};
465
466 if (!AudioObjectHasProperty(input_device_id_, &property_address)) {
467 NOTREACHED() << "Device does not support checking master mute state";
tommi (sloooow) - chröme 2014/10/15 17:00:48 since NOTREACHED is essentially the same as DCHECK
henrika (OOO until Aug 14) 2014/10/16 09:58:00 Done.
468 return false;
469 }
470
471 UInt32 muted = 0;
472 UInt32 size = sizeof(muted);
473 OSStatus result = AudioObjectGetPropertyData(
474 input_device_id_, &property_address, 0, NULL, &size, &muted);
475 if (result == noErr)
476 return static_cast<bool>(muted);
tommi (sloooow) - chröme 2014/10/15 17:00:48 nit: return muted != 0u; actually, you could also
henrika (OOO until Aug 14) 2014/10/16 09:58:00 Done.
477
478 DLOG(WARNING) << "Failed to get mute state";
479 return false;
480 }
481
454 // AUHAL AudioDeviceOutput unit callback 482 // AUHAL AudioDeviceOutput unit callback
455 OSStatus AUAudioInputStream::InputProc(void* user_data, 483 OSStatus AUAudioInputStream::InputProc(void* user_data,
456 AudioUnitRenderActionFlags* flags, 484 AudioUnitRenderActionFlags* flags,
457 const AudioTimeStamp* time_stamp, 485 const AudioTimeStamp* time_stamp,
458 UInt32 bus_number, 486 UInt32 bus_number,
459 UInt32 number_of_frames, 487 UInt32 number_of_frames,
460 AudioBufferList* io_data) { 488 AudioBufferList* io_data) {
461 // Verify that the correct bus is used (Input bus/Element 1) 489 // Verify that the correct bus is used (Input bus/Element 1)
462 DCHECK_EQ(bus_number, static_cast<UInt32>(1)); 490 DCHECK_EQ(bus_number, static_cast<UInt32>(1));
463 AUAudioInputStream* audio_input = 491 AUAudioInputStream* audio_input =
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 kAudioDevicePropertyScopeInput, 675 kAudioDevicePropertyScopeInput,
648 static_cast<UInt32>(channel) 676 static_cast<UInt32>(channel)
649 }; 677 };
650 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, 678 OSStatus result = AudioObjectIsPropertySettable(input_device_id_,
651 &property_address, 679 &property_address,
652 &is_settable); 680 &is_settable);
653 return (result == noErr) ? is_settable : false; 681 return (result == noErr) ? is_settable : false;
654 } 682 }
655 683
656 } // namespace media 684 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698