Chromium Code Reviews| 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 <stdint.h> | 7 #include <algorithm> |
| 8 #include <limits> | |
| 9 #include <vector> | |
| 8 | 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 11 #include "base/mac/mac_logging.h" | 13 #include "base/mac/mac_logging.h" |
| 12 #include "base/mac/scoped_cftyperef.h" | 14 #include "base/mac/scoped_cftyperef.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/memory/free_deleter.h" | 16 #include "base/memory/free_deleter.h" |
| 15 #include "base/power_monitor/power_monitor.h" | 17 #include "base/power_monitor/power_monitor.h" |
| 16 #include "base/power_monitor/power_observer.h" | 18 #include "base/power_monitor/power_observer.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 19 #include "base/strings/sys_string_conversions.h" |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 }; | 359 }; |
| 358 | 360 |
| 359 AudioManagerMac::AudioManagerMac( | 361 AudioManagerMac::AudioManagerMac( |
| 360 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 362 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 361 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 363 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
| 362 AudioLogFactory* audio_log_factory) | 364 AudioLogFactory* audio_log_factory) |
| 363 : AudioManagerBase(std::move(task_runner), | 365 : AudioManagerBase(std::move(task_runner), |
| 364 std::move(worker_task_runner), | 366 std::move(worker_task_runner), |
| 365 audio_log_factory), | 367 audio_log_factory), |
| 366 current_sample_rate_(0), | 368 current_sample_rate_(0), |
| 367 current_output_device_(kAudioDeviceUnknown) { | 369 current_output_device_(kAudioDeviceUnknown), |
| 370 device_id_used_by_closing_output_stream_(kAudioDeviceUnknown), | |
| 371 try_to_increase_io_buffer_size_(false) { | |
| 368 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 372 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
| 369 | 373 |
| 370 // Task must be posted last to avoid races from handing out "this" to the | 374 // Task must be posted last to avoid races from handing out "this" to the |
| 371 // audio thread. Always PostTask even if we're on the right thread since | 375 // audio thread. Always PostTask even if we're on the right thread since |
| 372 // AudioManager creation is on the startup path and this may be slow. | 376 // AudioManager creation is on the startup path and this may be slow. |
| 373 GetTaskRunner()->PostTask( | 377 GetTaskRunner()->PostTask( |
| 374 FROM_HERE, base::Bind(&AudioManagerMac::InitializeOnAudioThread, | 378 FROM_HERE, base::Bind(&AudioManagerMac::InitializeOnAudioThread, |
| 375 base::Unretained(this))); | 379 base::Unretained(this))); |
| 376 } | 380 } |
| 377 | 381 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 } | 478 } |
| 475 | 479 |
| 476 void AudioManagerMac::GetAudioOutputDeviceNames( | 480 void AudioManagerMac::GetAudioOutputDeviceNames( |
| 477 media::AudioDeviceNames* device_names) { | 481 media::AudioDeviceNames* device_names) { |
| 478 DCHECK(device_names->empty()); | 482 DCHECK(device_names->empty()); |
| 479 GetAudioDeviceInfo(false, device_names); | 483 GetAudioDeviceInfo(false, device_names); |
| 480 } | 484 } |
| 481 | 485 |
| 482 AudioParameters AudioManagerMac::GetInputStreamParameters( | 486 AudioParameters AudioManagerMac::GetInputStreamParameters( |
| 483 const std::string& device_id) { | 487 const std::string& device_id) { |
| 488 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
| 484 AudioDeviceID device = GetAudioDeviceIdByUId(true, device_id); | 489 AudioDeviceID device = GetAudioDeviceIdByUId(true, device_id); |
| 485 if (device == kAudioObjectUnknown) { | 490 if (device == kAudioObjectUnknown) { |
| 486 DLOG(ERROR) << "Invalid device " << device_id; | 491 DLOG(ERROR) << "Invalid device " << device_id; |
| 487 return AudioParameters( | 492 return AudioParameters( |
| 488 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 493 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 489 kFallbackSampleRate, 16, ChooseBufferSize(true, kFallbackSampleRate)); | 494 kFallbackSampleRate, 16, ChooseBufferSize(true, kFallbackSampleRate)); |
| 490 } | 495 } |
| 491 | 496 |
| 492 int channels = 0; | 497 int channels = 0; |
| 493 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | 498 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 if (default_device == *iter) | 594 if (default_device == *iter) |
| 590 return *iter; | 595 return *iter; |
| 591 } | 596 } |
| 592 | 597 |
| 593 // Failed to figure out which is the matching device, return an empty string. | 598 // Failed to figure out which is the matching device, return an empty string. |
| 594 return std::string(); | 599 return std::string(); |
| 595 } | 600 } |
| 596 | 601 |
| 597 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream( | 602 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream( |
| 598 const AudioParameters& params) { | 603 const AudioParameters& params) { |
| 604 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
| 599 return MakeLowLatencyOutputStream(params, std::string()); | 605 return MakeLowLatencyOutputStream(params, std::string()); |
| 600 } | 606 } |
| 601 | 607 |
| 602 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( | 608 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( |
| 603 const AudioParameters& params, | 609 const AudioParameters& params, |
| 604 const std::string& device_id) { | 610 const std::string& device_id) { |
| 611 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
| 605 bool device_listener_first_init = false; | 612 bool device_listener_first_init = false; |
| 606 // Lazily create the audio device listener on the first stream creation, | 613 // Lazily create the audio device listener on the first stream creation, |
| 607 // 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 |
| 608 // devices, the listener will never be initialized, and new valid devices | 615 // devices, the listener will never be initialized, and new valid devices |
| 609 // will never be detected. | 616 // will never be detected. |
| 610 if (!output_device_listener_) { | 617 if (!output_device_listener_) { |
| 611 // NOTE: Use BindToCurrentLoop() to ensure the callback is always PostTask'd | 618 // NOTE: Use BindToCurrentLoop() to ensure the callback is always PostTask'd |
| 612 // 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 |
| 613 // fire the callbacks during stream creation, leading to re-entrancy issues | 620 // fire the callbacks during stream creation, leading to re-entrancy issues |
| 614 // otherwise. See http://crbug.com/349604 | 621 // otherwise. See http://crbug.com/349604 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 return std::string(); | 670 return std::string(); |
| 664 | 671 |
| 665 std::string ret(base::SysCFStringRefToUTF8(device_uid)); | 672 std::string ret(base::SysCFStringRefToUTF8(device_uid)); |
| 666 CFRelease(device_uid); | 673 CFRelease(device_uid); |
| 667 | 674 |
| 668 return ret; | 675 return ret; |
| 669 } | 676 } |
| 670 | 677 |
| 671 AudioInputStream* AudioManagerMac::MakeLinearInputStream( | 678 AudioInputStream* AudioManagerMac::MakeLinearInputStream( |
| 672 const AudioParameters& params, const std::string& device_id) { | 679 const AudioParameters& params, const std::string& device_id) { |
| 680 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
| 673 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 681 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 674 AudioInputStream* stream = new PCMQueueInAudioInputStream(this, params); | 682 AudioInputStream* stream = new PCMQueueInAudioInputStream(this, params); |
| 675 basic_input_streams_.push_back(stream); | 683 basic_input_streams_.push_back(stream); |
| 676 return stream; | 684 return stream; |
| 677 } | 685 } |
| 678 | 686 |
| 679 AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream( | 687 AudioInputStream* AudioManagerMac::MakeLowLatencyInputStream( |
| 680 const AudioParameters& params, const std::string& device_id) { | 688 const AudioParameters& params, const std::string& device_id) { |
| 689 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
| 681 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 690 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| 682 // Gets the AudioDeviceID that refers to the AudioInputDevice with the device | 691 // Gets the AudioDeviceID that refers to the AudioInputDevice with the device |
| 683 // unique id. This AudioDeviceID is used to set the device for Audio Unit. | 692 // unique id. This AudioDeviceID is used to set the device for Audio Unit. |
| 684 AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, device_id); | 693 AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, device_id); |
| 685 AUAudioInputStream* stream = NULL; | 694 AUAudioInputStream* stream = NULL; |
| 686 if (audio_device_id != kAudioObjectUnknown) { | 695 if (audio_device_id != kAudioObjectUnknown) { |
| 687 stream = new AUAudioInputStream(this, params, audio_device_id); | 696 stream = new AUAudioInputStream(this, params, audio_device_id); |
| 688 low_latency_input_streams_.push_back(stream); | 697 low_latency_input_streams_.push_back(stream); |
| 689 } | 698 } |
| 690 | 699 |
| 691 return stream; | 700 return stream; |
| 692 } | 701 } |
| 693 | 702 |
| 694 AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters( | 703 AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters( |
| 695 const std::string& output_device_id, | 704 const std::string& output_device_id, |
| 696 const AudioParameters& input_params) { | 705 const AudioParameters& input_params) { |
| 706 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
| 697 const AudioDeviceID device = GetAudioDeviceIdByUId(false, output_device_id); | 707 const AudioDeviceID device = GetAudioDeviceIdByUId(false, output_device_id); |
| 698 if (device == kAudioObjectUnknown) { | 708 if (device == kAudioObjectUnknown) { |
| 699 DLOG(ERROR) << "Invalid output device " << output_device_id; | 709 DLOG(ERROR) << "Invalid output device " << output_device_id; |
| 700 return input_params.IsValid() ? input_params : AudioParameters( | 710 return input_params.IsValid() ? input_params : AudioParameters( |
| 701 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 711 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 702 kFallbackSampleRate, 16, ChooseBufferSize(false, kFallbackSampleRate)); | 712 kFallbackSampleRate, 16, ChooseBufferSize(false, kFallbackSampleRate)); |
| 703 } | 713 } |
| 704 | 714 |
| 705 const bool has_valid_input_params = input_params.IsValid(); | 715 const bool has_valid_input_params = input_params.IsValid(); |
| 706 const int hardware_sample_rate = HardwareSampleRateForDevice(device); | 716 const int hardware_sample_rate = HardwareSampleRateForDevice(device); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 848 | 858 |
| 849 // Check if a buffer size change is required. If the caller asks for a | 859 // Check if a buffer size change is required. If the caller asks for a |
| 850 // reduced size (|desired_buffer_size| < |buffer_size|), the new lower size | 860 // reduced size (|desired_buffer_size| < |buffer_size|), the new lower size |
| 851 // will be set. For larger buffer sizes, we have to perform some checks to | 861 // will be set. For larger buffer sizes, we have to perform some checks to |
| 852 // see if the size can actually be changed. If there is any other active | 862 // see if the size can actually be changed. If there is any other active |
| 853 // streams on the same device, either input or output, a larger size than | 863 // streams on the same device, either input or output, a larger size than |
| 854 // their requested buffer size can't be set. The reason is that an existing | 864 // their requested buffer size can't be set. The reason is that an existing |
| 855 // stream can't handle buffer size larger than its requested buffer size. | 865 // stream can't handle buffer size larger than its requested buffer size. |
| 856 // See http://crbug.com/428706 for a reason why. | 866 // See http://crbug.com/428706 for a reason why. |
| 857 | 867 |
| 868 // Update map of actual buffer size given device id if the map is empty. | |
| 869 // Stores a base value that most likely be modified as last action in this | |
| 870 // method. | |
| 871 if (!is_input && output_io_buffer_size_map_.count(device_id) == 0) | |
| 872 output_io_buffer_size_map_[device_id] = buffer_size; | |
|
o1ka
2016/05/12 11:30:17
Should we really do it here? (See my comment to l.
henrika (OOO until Aug 14)
2016/05/12 13:02:08
Nahh, you are probably correct. I must agree that
| |
| 873 | |
| 858 if (buffer_size == desired_buffer_size) | 874 if (buffer_size == desired_buffer_size) |
| 859 return true; | 875 return true; |
| 860 | 876 |
| 861 if (desired_buffer_size > buffer_size) { | 877 if (desired_buffer_size > buffer_size) { |
|
o1ka
2016/05/12 11:30:17
shouldn't we just check (output_io_buffer_size_map
henrika (OOO until Aug 14)
2016/05/12 13:02:08
If you don't mind I would like to avoid making suc
| |
| 862 // Do NOT set the buffer size if there is another output stream using | 878 // Do NOT set the buffer size if there is another output stream using |
| 863 // the same device with a smaller requested buffer size. | 879 // the same device with a smaller requested buffer size. |
| 864 // Note, for the caller stream, its requested_buffer_size() will be the same | 880 // Note, for the caller stream, its requested_buffer_size() will be the same |
| 865 // as |desired_buffer_size|, so it won't return true due to comparing with | 881 // as |desired_buffer_size|, so it won't return true due to comparing with |
| 866 // itself. | 882 // itself. |
| 867 for (auto* stream : output_streams_) { | 883 for (auto* stream : output_streams_) { |
| 868 if (stream->device_id() == device_id && | 884 if (stream->device_id() == device_id && |
| 869 stream->requested_buffer_size() < desired_buffer_size) { | 885 stream->requested_buffer_size() < desired_buffer_size) { |
| 870 return true; | 886 return true; |
| 871 } | 887 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 905 kAudioUnitScope_Global, 0, &buffer_size, | 921 kAudioUnitScope_Global, 0, &buffer_size, |
| 906 sizeof(buffer_size)); | 922 sizeof(buffer_size)); |
| 907 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | 923 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
| 908 << "AudioUnitSetProperty(kAudioDevicePropertyBufferFrameSize) failed. " | 924 << "AudioUnitSetProperty(kAudioDevicePropertyBufferFrameSize) failed. " |
| 909 << "Size:: " << buffer_size; | 925 << "Size:: " << buffer_size; |
| 910 *size_was_changed = (result == noErr); | 926 *size_was_changed = (result == noErr); |
| 911 DVLOG_IF(1, result == noErr) << "IO buffer size changed to: " << buffer_size; | 927 DVLOG_IF(1, result == noErr) << "IO buffer size changed to: " << buffer_size; |
| 912 // Store the currently used (after a change) I/O buffer frame size. | 928 // Store the currently used (after a change) I/O buffer frame size. |
| 913 *io_buffer_frame_size = buffer_size; | 929 *io_buffer_frame_size = buffer_size; |
| 914 | 930 |
| 931 // If the size was changed, update the actual output buffer size used for the | |
| 932 // given device ID. | |
| 933 if (!is_input && (result == noErr)) { | |
|
o1ka
2016/05/12 11:30:17
if (output_io_buffer_size_map_.count(device_id) ==
henrika (OOO until Aug 14)
2016/05/12 13:02:08
Lines 868 - 873 have been removed.
| |
| 934 output_io_buffer_size_map_[device_id] = buffer_size; | |
| 935 } | |
| 936 | |
| 915 return (result == noErr); | 937 return (result == noErr); |
| 916 } | 938 } |
| 917 | 939 |
| 940 bool AudioManagerMac::IncreaseIOBufferSizeIfPossible(AudioDeviceID device_id) { | |
| 941 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
| 942 DVLOG(1) << "IncreaseIOBufferSizeIfPossible(id=0x" << std::hex << device_id | |
| 943 << ")"; | |
| 944 // Start by storing the actual I/O buffer size. Then scan all active output | |
| 945 // streams using the specified |device_id| and find the minimum requested | |
| 946 // buffer size. In addition, store a reference to the audio unit of the first | |
| 947 // output stream using |device_id|. | |
| 948 DCHECK(!output_io_buffer_size_map_.empty()); | |
| 949 // All active output streams use the same actual I/O buffer size given | |
| 950 // a unique device ID. | |
| 951 const size_t& actual_size = output_io_buffer_size_map_[device_id]; | |
| 952 AudioUnit audio_unit; | |
| 953 size_t min_requested_size = std::numeric_limits<std::size_t>::max(); | |
| 954 for (auto* stream : output_streams_) { | |
| 955 if (stream->device_id() == device_id) { | |
| 956 if (min_requested_size == std::numeric_limits<std::size_t>::max()) { | |
| 957 // Store reference to the first audio unit using the specified ID. | |
| 958 audio_unit = stream->audio_unit(); | |
| 959 } | |
| 960 if (stream->requested_buffer_size() < min_requested_size) | |
| 961 min_requested_size = stream->requested_buffer_size(); | |
| 962 DVLOG(1) << "requested:" << stream->requested_buffer_size() | |
| 963 << " actual: " << actual_size; | |
| 964 } | |
| 965 } | |
| 966 | |
| 967 if (min_requested_size == std::numeric_limits<std::size_t>::max()) { | |
| 968 DVLOG(1) << "No action since there is no active stream for given device id"; | |
| 969 return false; | |
| 970 } | |
| 971 | |
| 972 // It is only possible to revert to a larger buffer size if the lowest | |
| 973 // requested is not in use. Example: if the actual I/O buffer size is 256 and | |
| 974 // at least one output stream has asked for 256 as its buffer size, we can't | |
| 975 // start using a larger I/O buffer size. | |
| 976 DCHECK_GE(min_requested_size, actual_size); | |
| 977 if (min_requested_size == actual_size) { | |
| 978 DVLOG(1) << "No action since lowest possible size is already in use: " | |
| 979 << actual_size; | |
| 980 return false; | |
| 981 } | |
| 982 | |
| 983 // It should now be safe to increase the I/O buffer size to a new (higher) | |
| 984 // value using the |min_requested_size|. Doing so will save system resources. | |
| 985 // All active output streams with the same |device_id| are affected by this | |
| 986 // change but it is only required to apply the change to one of the streams. | |
| 987 DVLOG(1) << "min_requested_size: " << min_requested_size; | |
| 988 bool size_was_changed = false; | |
| 989 size_t io_buffer_frame_size = 0; | |
| 990 bool result = | |
| 991 MaybeChangeBufferSize(device_id, audio_unit, 0, min_requested_size, | |
| 992 &size_was_changed, &io_buffer_frame_size); | |
| 993 DCHECK_EQ(io_buffer_frame_size, min_requested_size); | |
| 994 DCHECK(size_was_changed); | |
| 995 return result; | |
| 996 } | |
| 997 | |
| 998 bool AudioManagerMac::AudioDeviceIsUsedForInput(AudioDeviceID device_id) { | |
| 999 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
| 1000 if (!basic_input_streams_.empty()) { | |
| 1001 // For Audio Queues and in the default case (Mac OS X), the audio comes | |
| 1002 // from the system’s default audio input device as set by a user in System | |
| 1003 // Preferences. | |
| 1004 AudioDeviceID default_id; | |
| 1005 GetDefaultDevice(&default_id, true); | |
| 1006 if (default_id == device_id) | |
| 1007 return true; | |
| 1008 } | |
| 1009 | |
| 1010 // Each low latency streams has its own device ID. | |
| 1011 for (auto* stream : low_latency_input_streams_) { | |
| 1012 if (stream->device_id() == device_id) | |
| 1013 return true; | |
| 1014 } | |
| 1015 return false; | |
| 1016 } | |
| 1017 | |
| 1018 void AudioManagerMac::PrepareForAttemptToIncreaseIOBufferSize( | |
| 1019 AudioDeviceID device_id) { | |
| 1020 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
| 1021 device_id_used_by_closing_output_stream_ = device_id; | |
| 1022 try_to_increase_io_buffer_size_ = true; | |
| 1023 } | |
| 1024 | |
| 918 void AudioManagerMac::ReleaseOutputStream(AudioOutputStream* stream) { | 1025 void AudioManagerMac::ReleaseOutputStream(AudioOutputStream* stream) { |
| 1026 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
| 1027 // Start by closing down the specified output stream. | |
| 919 output_streams_.remove(static_cast<AUHALStream*>(stream)); | 1028 output_streams_.remove(static_cast<AUHALStream*>(stream)); |
| 920 AudioManagerBase::ReleaseOutputStream(stream); | 1029 AudioManagerBase::ReleaseOutputStream(stream); |
| 1030 | |
| 1031 if (!try_to_increase_io_buffer_size_) | |
| 1032 return; | |
| 1033 | |
| 1034 const AudioDeviceID id = device_id_used_by_closing_output_stream_; | |
| 1035 DVLOG(1) << "Closed output stream with id=0x" << std::hex << id; | |
| 1036 | |
| 1037 // Prevent attempt to alter buffer size if the released stream was the last | |
| 1038 // output stream. | |
| 1039 if (output_streams_.empty()) | |
| 1040 return; | |
| 1041 | |
| 1042 if (!AudioDeviceIsUsedForInput(id)) { | |
| 1043 // The current audio device is not used for input. See if it is possible to | |
| 1044 // increase the IO buffer size (saves power) given the remaining output | |
| 1045 // audio streams and their buffer size requirements. | |
| 1046 IncreaseIOBufferSizeIfPossible(id); | |
| 1047 } | |
| 1048 | |
| 1049 try_to_increase_io_buffer_size_ = false; | |
| 921 } | 1050 } |
| 922 | 1051 |
| 923 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { | 1052 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { |
| 1053 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
| 924 auto stream_it = std::find(basic_input_streams_.begin(), | 1054 auto stream_it = std::find(basic_input_streams_.begin(), |
| 925 basic_input_streams_.end(), | 1055 basic_input_streams_.end(), |
| 926 stream); | 1056 stream); |
| 927 if (stream_it == basic_input_streams_.end()) | 1057 if (stream_it == basic_input_streams_.end()) |
| 928 low_latency_input_streams_.remove(static_cast<AUAudioInputStream*>(stream)); | 1058 low_latency_input_streams_.remove(static_cast<AUAudioInputStream*>(stream)); |
| 929 else | 1059 else |
| 930 basic_input_streams_.erase(stream_it); | 1060 basic_input_streams_.erase(stream_it); |
| 931 | 1061 |
| 932 AudioManagerBase::ReleaseInputStream(stream); | 1062 AudioManagerBase::ReleaseInputStream(stream); |
| 933 } | 1063 } |
| 934 | 1064 |
| 935 ScopedAudioManagerPtr CreateAudioManager( | 1065 ScopedAudioManagerPtr CreateAudioManager( |
| 936 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 1066 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 937 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 1067 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
| 938 AudioLogFactory* audio_log_factory) { | 1068 AudioLogFactory* audio_log_factory) { |
| 939 return ScopedAudioManagerPtr( | 1069 return ScopedAudioManagerPtr( |
| 940 new AudioManagerMac(std::move(task_runner), std::move(worker_task_runner), | 1070 new AudioManagerMac(std::move(task_runner), std::move(worker_task_runner), |
| 941 audio_log_factory)); | 1071 audio_log_factory)); |
| 942 } | 1072 } |
| 943 | 1073 |
| 944 } // namespace media | 1074 } // namespace media |
| OLD | NEW |