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