OLD | NEW |
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_manager_mac.h" | 5 #include "media/audio/mac/audio_manager_mac.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 iter != associated_devices.end(); ++iter) { | 591 iter != associated_devices.end(); ++iter) { |
592 if (default_device == *iter) | 592 if (default_device == *iter) |
593 return *iter; | 593 return *iter; |
594 } | 594 } |
595 | 595 |
596 // Failed to figure out which is the matching device, return an empty string. | 596 // Failed to figure out which is the matching device, return an empty string. |
597 return std::string(); | 597 return std::string(); |
598 } | 598 } |
599 | 599 |
600 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream( | 600 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream( |
601 const AudioParameters& params) { | 601 const AudioParameters& params, |
| 602 const LogCallback& log_callback) { |
602 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 603 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
603 return MakeLowLatencyOutputStream(params, std::string()); | 604 return MakeLowLatencyOutputStream(params, std::string(), log_callback); |
604 } | 605 } |
605 | 606 |
606 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( | 607 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( |
607 const AudioParameters& params, | 608 const AudioParameters& params, |
608 const std::string& device_id) { | 609 const std::string& device_id, |
| 610 const LogCallback& log_callback) { |
609 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 611 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
610 bool device_listener_first_init = false; | 612 bool device_listener_first_init = false; |
611 // Lazily create the audio device listener on the first stream creation, | 613 // Lazily create the audio device listener on the first stream creation, |
612 // even if getting an audio device fails. Otherwise, if we have 0 audio | 614 // even if getting an audio device fails. Otherwise, if we have 0 audio |
613 // devices, the listener will never be initialized, and new valid devices | 615 // devices, the listener will never be initialized, and new valid devices |
614 // will never be detected. | 616 // will never be detected. |
615 if (!output_device_listener_) { | 617 if (!output_device_listener_) { |
616 // NOTE: Use BindToCurrentLoop() to ensure the callback is always PostTask'd | 618 // NOTE: Use BindToCurrentLoop() to ensure the callback is always PostTask'd |
617 // even if OSX calls us on the right thread. Some CoreAudio drivers will | 619 // even if OSX calls us on the right thread. Some CoreAudio drivers will |
618 // fire the callbacks during stream creation, leading to re-entrancy issues | 620 // fire the callbacks during stream creation, leading to re-entrancy issues |
(...skipping 14 matching lines...) Expand all Loading... |
633 // listener. | 635 // listener. |
634 if (device_listener_first_init) { | 636 if (device_listener_first_init) { |
635 // Only set the current output device for the default device. | 637 // Only set the current output device for the default device. |
636 if (AudioDeviceDescription::IsDefaultDevice(device_id)) | 638 if (AudioDeviceDescription::IsDefaultDevice(device_id)) |
637 current_output_device_ = device; | 639 current_output_device_ = device; |
638 // Just use the current sample rate since we don't allow non-native sample | 640 // Just use the current sample rate since we don't allow non-native sample |
639 // rates on OSX. | 641 // rates on OSX. |
640 current_sample_rate_ = params.sample_rate(); | 642 current_sample_rate_ = params.sample_rate(); |
641 } | 643 } |
642 | 644 |
643 AUHALStream* stream = new AUHALStream(this, params, device); | 645 AUHALStream* stream = new AUHALStream(this, params, device, log_callback); |
644 output_streams_.push_back(stream); | 646 output_streams_.push_back(stream); |
645 return stream; | 647 return stream; |
646 } | 648 } |
647 | 649 |
648 std::string AudioManagerMac::GetDefaultOutputDeviceID() { | 650 std::string AudioManagerMac::GetDefaultOutputDeviceID() { |
649 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 651 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
650 AudioDeviceID device_id = kAudioObjectUnknown; | 652 AudioDeviceID device_id = kAudioObjectUnknown; |
651 if (!GetDefaultOutputDevice(&device_id)) | 653 if (!GetDefaultOutputDevice(&device_id)) |
652 return std::string(); | 654 return std::string(); |
653 | 655 |
(...skipping 13 matching lines...) Expand all Loading... |
667 if (status != kAudioHardwareNoError || !device_uid) | 669 if (status != kAudioHardwareNoError || !device_uid) |
668 return std::string(); | 670 return std::string(); |
669 | 671 |
670 std::string ret(base::SysCFStringRefToUTF8(device_uid)); | 672 std::string ret(base::SysCFStringRefToUTF8(device_uid)); |
671 CFRelease(device_uid); | 673 CFRelease(device_uid); |
672 | 674 |
673 return ret; | 675 return ret; |
674 } | 676 } |
675 | 677 |
676 AudioInputStream* AudioManagerMac::MakeLinearInputStream( | 678 AudioInputStream* AudioManagerMac::MakeLinearInputStream( |
677 const AudioParameters& params, const std::string& device_id) { | 679 const AudioParameters& params, |
| 680 const std::string& device_id, |
| 681 const LogCallback& log_callback) { |
678 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 682 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
679 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 683 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
680 AudioInputStream* stream = new PCMQueueInAudioInputStream(this, params); | 684 AudioInputStream* stream = new PCMQueueInAudioInputStream(this, params); |
681 basic_input_streams_.push_back(stream); | 685 basic_input_streams_.push_back(stream); |
682 return stream; | 686 return stream; |
683 } | 687 } |
684 | 688 |
685 AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream( | 689 AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream( |
686 const AudioParameters& params, const std::string& device_id) { | 690 const AudioParameters& params, |
| 691 const std::string& device_id, |
| 692 const LogCallback& log_callback) { |
687 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 693 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
688 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 694 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
689 // Gets the AudioDeviceID that refers to the AudioInputDevice with the device | 695 // Gets the AudioDeviceID that refers to the AudioInputDevice with the device |
690 // unique id. This AudioDeviceID is used to set the device for Audio Unit. | 696 // unique id. This AudioDeviceID is used to set the device for Audio Unit. |
691 AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, device_id); | 697 AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, device_id); |
692 AUAudioInputStream* stream = NULL; | 698 AUAudioInputStream* stream = NULL; |
693 if (audio_device_id != kAudioObjectUnknown) { | 699 if (audio_device_id != kAudioObjectUnknown) { |
694 stream = new AUAudioInputStream(this, params, audio_device_id); | 700 stream = |
| 701 new AUAudioInputStream(this, params, audio_device_id, log_callback); |
695 low_latency_input_streams_.push_back(stream); | 702 low_latency_input_streams_.push_back(stream); |
696 } | 703 } |
697 | 704 |
698 return stream; | 705 return stream; |
699 } | 706 } |
700 | 707 |
701 AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters( | 708 AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters( |
702 const std::string& output_device_id, | 709 const std::string& output_device_id, |
703 const AudioParameters& input_params) { | 710 const AudioParameters& input_params) { |
704 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 711 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 ScopedAudioManagerPtr CreateAudioManager( | 1066 ScopedAudioManagerPtr CreateAudioManager( |
1060 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 1067 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
1061 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 1068 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
1062 AudioLogFactory* audio_log_factory) { | 1069 AudioLogFactory* audio_log_factory) { |
1063 return ScopedAudioManagerPtr( | 1070 return ScopedAudioManagerPtr( |
1064 new AudioManagerMac(std::move(task_runner), std::move(worker_task_runner), | 1071 new AudioManagerMac(std::move(task_runner), std::move(worker_task_runner), |
1065 audio_log_factory)); | 1072 audio_log_factory)); |
1066 } | 1073 } |
1067 | 1074 |
1068 } // namespace media | 1075 } // namespace media |
OLD | NEW |