diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/media/audio | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/media/audio')
37 files changed, 431 insertions, 223 deletions
diff --git a/chromium/media/audio/alsa/alsa_input.cc b/chromium/media/audio/alsa/alsa_input.cc index a70748274ae..ee7c5d0305d 100644 --- a/chromium/media/audio/alsa/alsa_input.cc +++ b/chromium/media/audio/alsa/alsa_input.cc @@ -41,10 +41,10 @@ AlsaPcmInputStream::AlsaPcmInputStream(AudioManagerBase* audio_manager, buffer_duration_(base::TimeDelta::FromMicroseconds( params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / static_cast<float>(params.sample_rate()))), - callback_(NULL), - device_handle_(NULL), - mixer_handle_(NULL), - mixer_element_handle_(NULL), + callback_(nullptr), + device_handle_(nullptr), + mixer_handle_(nullptr), + mixer_element_handle_(nullptr), read_callback_behind_schedule_(false), audio_bus_(AudioBus::Create(params)), capture_thread_("AlsaInput"), @@ -91,7 +91,7 @@ bool AlsaPcmInputStream::Open() { } } - return device_handle_ != NULL; + return device_handle_ != nullptr; } void AlsaPcmInputStream::Start(AudioInputCallback* callback) { @@ -108,7 +108,7 @@ void AlsaPcmInputStream::Start(AudioInputCallback* callback) { } if (error < 0) { - callback_ = NULL; + callback_ = nullptr; } else { base::Thread::Options options; options.priority = base::ThreadPriority::REALTIME_AUDIO; @@ -268,7 +268,7 @@ void AlsaPcmInputStream::Stop() { if (error < 0) HandleError("PcmDrop", error); - callback_ = NULL; + callback_ = nullptr; } void AlsaPcmInputStream::Close() { @@ -282,9 +282,9 @@ void AlsaPcmInputStream::Close() { alsa_util::CloseMixer(wrapper_, mixer_handle_, device_name_); audio_buffer_.reset(); - device_handle_ = NULL; - mixer_handle_ = NULL; - mixer_element_handle_ = NULL; + device_handle_ = nullptr; + mixer_handle_ = nullptr; + mixer_element_handle_ = nullptr; } audio_manager_->ReleaseInputStream(this); diff --git a/chromium/media/audio/alsa/alsa_output.cc b/chromium/media/audio/alsa/alsa_output.cc index 74ea72b610c..c2cc61d1d8c 100644 --- a/chromium/media/audio/alsa/alsa_output.cc +++ b/chromium/media/audio/alsa/alsa_output.cc @@ -75,7 +75,7 @@ static const ChannelLayout kDefaultOutputChannelLayout = CHANNEL_LAYOUT_STEREO; // http://0pointer.de/blog/projects/guide-to-sound-apis.html // // This function makes a best guess at the specific > 2 channel device name -// based on the number of channels requested. NULL is returned if no device +// based on the number of channels requested. nullptr is returned if no device // can be found to match the channel numbers. In this case, using // kDefaultDevice is probably the best bet. // @@ -103,7 +103,7 @@ static const char* GuessSpecificDeviceName(uint32_t channels) { return "surround40"; default: - return NULL; + return nullptr; } } @@ -165,11 +165,11 @@ AlsaPcmOutputStream::AlsaPcmOutputStream(const std::string& device_name, wrapper_(wrapper), manager_(manager), task_runner_(base::ThreadTaskRunnerHandle::Get()), - playback_handle_(NULL), + playback_handle_(nullptr), frames_per_packet_(packet_size_ / bytes_per_frame_), state_(kCreated), volume_(1.0f), - source_callback_(NULL), + source_callback_(nullptr), audio_bus_(AudioBus::Create(params)), tick_clock_(base::DefaultTickClock::GetInstance()) { DCHECK(manager_->GetTaskRunner()->BelongsToCurrentThread()); @@ -221,7 +221,7 @@ bool AlsaPcmOutputStream::Open() { } // Finish initializing the stream if the device was opened successfully. - if (playback_handle_ == NULL) { + if (playback_handle_ == nullptr) { stop_stream_ = true; TransitionTo(kInError); return false; @@ -260,7 +260,7 @@ void AlsaPcmOutputStream::Close() { if (alsa_util::CloseDevice(wrapper_, playback_handle_) < 0) { LOG(WARNING) << "Unable to close audio device. Leaking handle."; } - playback_handle_ = NULL; + playback_handle_ = nullptr; // Release the buffer. buffer_.reset(); @@ -330,7 +330,7 @@ void AlsaPcmOutputStream::Stop() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); // Reset the callback, so that it is not called anymore. - set_source_callback(NULL); + set_source_callback(nullptr); weak_factory_.InvalidateWeakPtrs(); TransitionTo(kIsStopped); @@ -559,19 +559,19 @@ std::string AlsaPcmOutputStream::FindDeviceForChannels(uint32_t channels) { return std::string(); std::string guessed_device; - void** hints = NULL; + void** hints = nullptr; int error = wrapper_->DeviceNameHint(kGetAllDevices, kPcmInterfaceName, &hints); if (error == 0) { // NOTE: Do not early return from inside this if statement. The // hints above need to be freed. - for (void** hint_iter = hints; *hint_iter != NULL; hint_iter++) { + for (void** hint_iter = hints; *hint_iter != nullptr; hint_iter++) { // Only examine devices that are output capable.. Valid values are - // "Input", "Output", and NULL which means both input and output. + // "Input", "Output", and nullptr which means both input and output. std::unique_ptr<char, base::FreeDeleter> io( wrapper_->DeviceNameGetHint(*hint_iter, kIoHintName)); - if (io != NULL && strcmp(io.get(), "Input") == 0) + if (io != nullptr && strcmp(io.get(), "Input") == 0) continue; // Attempt to select the closest device for number of channels. @@ -585,7 +585,7 @@ std::string AlsaPcmOutputStream::FindDeviceForChannels(uint32_t channels) { // Destroy the hint now that we're done with it. wrapper_->DeviceNameFreeHint(hints); - hints = NULL; + hints = nullptr; } else { LOG(ERROR) << "Unable to get hints for devices: " << wrapper_->StrError(error); @@ -673,24 +673,22 @@ snd_pcm_t* AlsaPcmOutputStream::AutoSelectDevice(unsigned int latency) { // 4) Fallback to kDefaultDevice. // 5) If that fails too, try the "plug:" version of kDefaultDevice. // 6) Give up. - snd_pcm_t* handle = NULL; + snd_pcm_t* handle = nullptr; device_name_ = FindDeviceForChannels(channels_); // Step 1. if (!device_name_.empty()) { - if ((handle = alsa_util::OpenPlaybackDevice(wrapper_, device_name_.c_str(), - channels_, sample_rate_, - pcm_format_, - latency)) != NULL) { + if ((handle = alsa_util::OpenPlaybackDevice( + wrapper_, device_name_.c_str(), channels_, sample_rate_, + pcm_format_, latency)) != nullptr) { return handle; } // Step 2. device_name_ = kPlugPrefix + device_name_; - if ((handle = alsa_util::OpenPlaybackDevice(wrapper_, device_name_.c_str(), - channels_, sample_rate_, - pcm_format_, - latency)) != NULL) { + if ((handle = alsa_util::OpenPlaybackDevice( + wrapper_, device_name_.c_str(), channels_, sample_rate_, + pcm_format_, latency)) != nullptr) { return handle; } @@ -700,7 +698,7 @@ snd_pcm_t* AlsaPcmOutputStream::AutoSelectDevice(unsigned int latency) { device_name_ = kPlugPrefix + device_name_; if ((handle = alsa_util::OpenPlaybackDevice( wrapper_, device_name_.c_str(), channels_, sample_rate_, - pcm_format_, latency)) != NULL) { + pcm_format_, latency)) != nullptr) { return handle; } } @@ -722,22 +720,22 @@ snd_pcm_t* AlsaPcmOutputStream::AutoSelectDevice(unsigned int latency) { // Step 4. device_name_ = kDefaultDevice; if ((handle = alsa_util::OpenPlaybackDevice( - wrapper_, device_name_.c_str(), default_channels, sample_rate_, - pcm_format_, latency)) != NULL) { + wrapper_, device_name_.c_str(), default_channels, sample_rate_, + pcm_format_, latency)) != nullptr) { return handle; } // Step 5. device_name_ = kPlugPrefix + device_name_; if ((handle = alsa_util::OpenPlaybackDevice( - wrapper_, device_name_.c_str(), default_channels, sample_rate_, - pcm_format_, latency)) != NULL) { + wrapper_, device_name_.c_str(), default_channels, sample_rate_, + pcm_format_, latency)) != nullptr) { return handle; } // Unable to open any device. device_name_.clear(); - return NULL; + return nullptr; } bool AlsaPcmOutputStream::CanTransitionTo(InternalState to) { @@ -800,7 +798,7 @@ void AlsaPcmOutputStream::RunErrorCallback(int code) { source_callback_->OnError(AudioSourceCallback::ErrorType::kUnknown); } -// Changes the AudioSourceCallback to proxy calls to. Pass in NULL to +// Changes the AudioSourceCallback to proxy calls to. Pass in nullptr to // release ownership of the currently registered callback. void AlsaPcmOutputStream::set_source_callback(AudioSourceCallback* callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); diff --git a/chromium/media/audio/alsa/alsa_output.h b/chromium/media/audio/alsa/alsa_output.h index 6070361a032..9922eae8763 100644 --- a/chromium/media/audio/alsa/alsa_output.h +++ b/chromium/media/audio/alsa/alsa_output.h @@ -159,7 +159,7 @@ class MEDIA_EXPORT AlsaPcmOutputStream : public AudioOutputStream { AudioBus* audio_bus); void RunErrorCallback(int code); - // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to + // Changes the AudioSourceCallback to proxy calls to. Pass in nullptr to // release ownership of the currently registered callback. void set_source_callback(AudioSourceCallback* callback); diff --git a/chromium/media/audio/alsa/alsa_output_unittest.cc b/chromium/media/audio/alsa/alsa_output_unittest.cc index bca316b71d4..9183721af1b 100644 --- a/chromium/media/audio/alsa/alsa_output_unittest.cc +++ b/chromium/media/audio/alsa/alsa_output_unittest.cc @@ -5,6 +5,7 @@ #include <stdint.h> #include <memory> +#include "base/logging.h" #include "base/macros.h" #include "base/run_loop.h" #include "base/strings/stringprintf.h" @@ -177,7 +178,7 @@ char AlsaPcmOutputStreamTest::kSurround70[] = "surround70:CARD=foo,DEV=0"; char AlsaPcmOutputStreamTest::kSurround71[] = "surround71:CARD=foo,DEV=0"; void* AlsaPcmOutputStreamTest::kFakeHints[] = { kSurround40, kSurround41, kSurround50, kSurround51, - kSurround70, kSurround71, NULL }; + kSurround70, kSurround71, nullptr}; char AlsaPcmOutputStreamTest::kGenericSurround50[] = "surround50"; // Custom action to clear a memory buffer. @@ -315,7 +316,7 @@ TEST_F(AlsaPcmOutputStreamTest, PcmOpenFailed) { // Ensure internal state is set for a no-op stream if PcmOpen() failes. EXPECT_TRUE(test_stream->stop_stream_); - EXPECT_TRUE(test_stream->playback_handle_ == NULL); + EXPECT_FALSE(test_stream->playback_handle_); EXPECT_FALSE(test_stream->buffer_.get()); // Close the stream since we opened it to make destruction happy. @@ -342,7 +343,7 @@ TEST_F(AlsaPcmOutputStreamTest, PcmSetParamsFailed) { // Ensure internal state is set for a no-op stream if PcmSetParams() failes. EXPECT_TRUE(test_stream->stop_stream_); - EXPECT_TRUE(test_stream->playback_handle_ == NULL); + EXPECT_FALSE(test_stream->playback_handle_); EXPECT_FALSE(test_stream->buffer_.get()); // Close the stream since we opened it to make destruction happy. @@ -636,13 +637,16 @@ TEST_F(AlsaPcmOutputStreamTest, AutoSelectDevice_DeviceSelect) { // // Note that the loop starts at "1", so the first parameter is ignored in // these arrays. - const char* kExpectedDeviceName[] = { NULL, - AlsaPcmOutputStream::kDefaultDevice, - AlsaPcmOutputStream::kDefaultDevice, - AlsaPcmOutputStream::kDefaultDevice, - kSurround40, kSurround50, kSurround51, - kSurround70, kSurround71, - AlsaPcmOutputStream::kDefaultDevice }; + const char* kExpectedDeviceName[] = {nullptr, + AlsaPcmOutputStream::kDefaultDevice, + AlsaPcmOutputStream::kDefaultDevice, + AlsaPcmOutputStream::kDefaultDevice, + kSurround40, + kSurround50, + kSurround51, + kSurround70, + kSurround71, + AlsaPcmOutputStream::kDefaultDevice}; bool kExpectedDownmix[] = { false, false, false, false, false, true, false, false, false, false }; ChannelLayout kExpectedLayouts[] = { CHANNEL_LAYOUT_NONE, diff --git a/chromium/media/audio/android/audio_android_unittest.cc b/chromium/media/audio/android/audio_android_unittest.cc index c3cd2ba0e67..ea3a4024d3e 100644 --- a/chromium/media/audio/android/audio_android_unittest.cc +++ b/chromium/media/audio/android/audio_android_unittest.cc @@ -9,6 +9,7 @@ #include "base/android/build_info.h" #include "base/bind.h" #include "base/files/file_util.h" +#include "base/logging.h" #include "base/macros.h" #include "base/path_service.h" #include "base/run_loop.h" diff --git a/chromium/media/audio/android/opensles_util.h b/chromium/media/audio/android/opensles_util.h index 2673d14f3b6..2e8d27055bf 100644 --- a/chromium/media/audio/android/opensles_util.h +++ b/chromium/media/audio/android/opensles_util.h @@ -7,7 +7,7 @@ #include <SLES/OpenSLES.h> -#include "base/logging.h" +#include "base/check.h" #include "media/base/media_export.h" namespace media { diff --git a/chromium/media/audio/audio_debug_recording_helper.cc b/chromium/media/audio/audio_debug_recording_helper.cc index bad2c5b2f72..7b0341d3a45 100644 --- a/chromium/media/audio/audio_debug_recording_helper.cc +++ b/chromium/media/audio/audio_debug_recording_helper.cc @@ -9,6 +9,7 @@ #include "base/bind.h" #include "base/files/file.h" +#include "base/logging.h" #include "base/memory/ptr_util.h" #include "base/single_thread_task_runner.h" #include "media/audio/audio_debug_file_writer.h" diff --git a/chromium/media/audio/audio_input_device.cc b/chromium/media/audio/audio_input_device.cc index aad6984307d..b6bc304fbbd 100644 --- a/chromium/media/audio/audio_input_device.cc +++ b/chromium/media/audio/audio_input_device.cc @@ -11,6 +11,7 @@ #include "base/bind.h" #include "base/callback_forward.h" #include "base/format_macros.h" +#include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/metrics/histogram_macros.h" @@ -98,13 +99,15 @@ class AudioInputDevice::AudioThreadCallback }; AudioInputDevice::AudioInputDevice(std::unique_ptr<AudioInputIPC> ipc, - Purpose purpose) + Purpose purpose, + DeadStreamDetection detect_dead_stream) : thread_priority_(ThreadPriorityFromPurpose(purpose)), enable_uma_(purpose == AudioInputDevice::Purpose::kUserInput), callback_(nullptr), ipc_(std::move(ipc)), state_(IDLE), - agc_is_enabled_(false) { + agc_is_enabled_(false), + detect_dead_stream_(detect_dead_stream) { CHECK(ipc_); // The correctness of the code depends on the relative values assigned in the @@ -142,9 +145,11 @@ void AudioInputDevice::Stop() { TRACE_EVENT0("audio", "AudioInputDevice::Stop"); if (enable_uma_) { - UMA_HISTOGRAM_BOOLEAN( - "Media.Audio.Capture.DetectedMissingCallbacks", - alive_checker_ ? alive_checker_->DetectedDead() : false); + if (detect_dead_stream_ == DeadStreamDetection::kEnabled) { + UMA_HISTOGRAM_BOOLEAN( + "Media.Audio.Capture.DetectedMissingCallbacks", + alive_checker_ ? alive_checker_->DetectedDead() : false); + } UMA_HISTOGRAM_ENUMERATION("Media.Audio.Capture.StreamCallbackError2", had_error_); @@ -247,6 +252,7 @@ void AudioInputDevice::OnStreamCreated( // also a risk of false positives if we are suspending when starting the stream // here. See comments in AliveChecker and PowerObserverHelper for details and // todos. + if (detect_dead_stream_ == DeadStreamDetection::kEnabled) { #if defined(OS_LINUX) const bool stop_at_first_alive_notification = true; const bool pause_check_during_suspend = false; @@ -259,13 +265,19 @@ void AudioInputDevice::OnStreamCreated( base::TimeDelta::FromSeconds(kCheckMissingCallbacksIntervalSeconds), base::TimeDelta::FromSeconds(kMissingCallbacksTimeBeforeErrorSeconds), stop_at_first_alive_notification, pause_check_during_suspend); + } // Unretained is safe since |alive_checker_| outlives |audio_callback_|. + base::RepeatingClosure notify_alive_closure = + alive_checker_ + ? base::BindRepeating(&AliveChecker::NotifyAlive, + base::Unretained(alive_checker_.get())) + : base::DoNothing::Repeatedly(); + audio_callback_ = std::make_unique<AudioInputDevice::AudioThreadCallback>( audio_parameters_, std::move(shared_memory_region), kRequestedSharedMemoryCount, enable_uma_, callback_, - base::BindRepeating(&AliveChecker::NotifyAlive, - base::Unretained(alive_checker_.get()))); + notify_alive_closure); audio_thread_ = std::make_unique<AudioDeviceThread>( audio_callback_.get(), std::move(socket_handle), "AudioInputDevice", thread_priority_); @@ -274,7 +286,8 @@ void AudioInputDevice::OnStreamCreated( ipc_->RecordStream(); // Start detecting missing audio data. - alive_checker_->Start(); + if (alive_checker_) + alive_checker_->Start(); } void AudioInputDevice::OnError() { diff --git a/chromium/media/audio/audio_input_device.h b/chromium/media/audio/audio_input_device.h index 96a5b4d72d5..219b79301d8 100644 --- a/chromium/media/audio/audio_input_device.h +++ b/chromium/media/audio/audio_input_device.h @@ -68,11 +68,15 @@ class MEDIA_EXPORT AudioInputDevice : public AudioCapturerSource, public AudioInputIPCDelegate { public: enum Purpose : int8_t { kUserInput, kLoopback }; + enum class DeadStreamDetection : bool { kDisabled = false, kEnabled = true }; // NOTE: Clients must call Initialize() before using. // |enable_uma| controls logging of UMA stats. It is used to ensure that // stats are not logged for mirroring service streams. - AudioInputDevice(std::unique_ptr<AudioInputIPC> ipc, Purpose purpose); + // |detect_dead_stream| controls the dead stream detection. + AudioInputDevice(std::unique_ptr<AudioInputIPC> ipc, + Purpose purpose, + DeadStreamDetection detect_dead_stream); // AudioCapturerSource implementation. void Initialize(const AudioParameters& params, @@ -142,6 +146,10 @@ class MEDIA_EXPORT AudioInputDevice : public AudioCapturerSource, // Stores the Automatic Gain Control state. Default is false. bool agc_is_enabled_; + // Controls the dead stream detection. Only the DSP hotword devices set this + // to kDisabled to disable dead stream detection. + const DeadStreamDetection detect_dead_stream_; + // Checks regularly that the input stream is alive and notifies us if it // isn't by calling DetectedDeadInputStream(). Must outlive |audio_callback_|. std::unique_ptr<AliveChecker> alive_checker_; diff --git a/chromium/media/audio/audio_input_device_unittest.cc b/chromium/media/audio/audio_input_device_unittest.cc index 2b20c59cf00..d951d344522 100644 --- a/chromium/media/audio/audio_input_device_unittest.cc +++ b/chromium/media/audio/audio_input_device_unittest.cc @@ -63,13 +63,17 @@ class MockCaptureCallback : public AudioCapturerSource::CaptureCallback { } // namespace. +class AudioInputDeviceTest + : public ::testing::TestWithParam<AudioInputDevice::DeadStreamDetection> {}; + // Regular construction. -TEST(AudioInputDeviceTest, Noop) { +TEST_P(AudioInputDeviceTest, Noop) { base::test::SingleThreadTaskEnvironment task_environment( base::test::SingleThreadTaskEnvironment::MainThreadType::IO); MockAudioInputIPC* input_ipc = new MockAudioInputIPC(); scoped_refptr<AudioInputDevice> device(new AudioInputDevice( - base::WrapUnique(input_ipc), AudioInputDevice::Purpose::kUserInput)); + base::WrapUnique(input_ipc), AudioInputDevice::Purpose::kUserInput, + AudioInputDeviceTest::GetParam())); } ACTION_P(ReportStateChange, device) { @@ -77,23 +81,25 @@ ACTION_P(ReportStateChange, device) { } // Verify that we get an OnCaptureError() callback if CreateStream fails. -TEST(AudioInputDeviceTest, FailToCreateStream) { +TEST_P(AudioInputDeviceTest, FailToCreateStream) { AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, 48000, 480); MockCaptureCallback callback; MockAudioInputIPC* input_ipc = new MockAudioInputIPC(); scoped_refptr<AudioInputDevice> device(new AudioInputDevice( - base::WrapUnique(input_ipc), AudioInputDevice::Purpose::kUserInput)); + base::WrapUnique(input_ipc), AudioInputDevice::Purpose::kUserInput, + AudioInputDeviceTest::GetParam())); device->Initialize(params, &callback); EXPECT_CALL(*input_ipc, CreateStream(_, _, _, _)) .WillOnce(ReportStateChange(device.get())); EXPECT_CALL(callback, OnCaptureError(_)); + EXPECT_CALL(*input_ipc, CloseStream()); device->Start(); device->Stop(); } -TEST(AudioInputDeviceTest, CreateStream) { +TEST_P(AudioInputDeviceTest, CreateStream) { AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, 48000, 480); base::MappedReadOnlyRegion shared_memory; @@ -117,7 +123,8 @@ TEST(AudioInputDeviceTest, CreateStream) { MockCaptureCallback callback; MockAudioInputIPC* input_ipc = new MockAudioInputIPC(); scoped_refptr<AudioInputDevice> device(new AudioInputDevice( - base::WrapUnique(input_ipc), AudioInputDevice::Purpose::kUserInput)); + base::WrapUnique(input_ipc), AudioInputDevice::Purpose::kUserInput, + AudioInputDeviceTest::GetParam())); device->Initialize(params, &callback); EXPECT_CALL(*input_ipc, CreateStream(_, _, _, _)) @@ -134,4 +141,10 @@ TEST(AudioInputDeviceTest, CreateStream) { device->Stop(); } +INSTANTIATE_TEST_SUITE_P( + AudioInputDeviceGroup, + AudioInputDeviceTest, + ::testing::Values(AudioInputDevice::DeadStreamDetection::kDisabled, + AudioInputDevice::DeadStreamDetection::kEnabled)); + } // namespace media. diff --git a/chromium/media/audio/audio_input_unittest.cc b/chromium/media/audio/audio_input_unittest.cc index 133673a58be..5a38c8d6b89 100644 --- a/chromium/media/audio/audio_input_unittest.cc +++ b/chromium/media/audio/audio_input_unittest.cc @@ -108,7 +108,7 @@ class AudioInputTest : public testing::Test { void CloseAudioInputStreamOnAudioThread() { RunOnAudioThread(base::BindOnce(&AudioInputStream::Close, base::Unretained(audio_input_stream_))); - audio_input_stream_ = NULL; + audio_input_stream_ = nullptr; } void OpenAndCloseAudioInputStreamOnAudioThread() { @@ -148,7 +148,7 @@ class AudioInputTest : public testing::Test { DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); EXPECT_TRUE(audio_input_stream_->Open()); audio_input_stream_->Close(); - audio_input_stream_ = NULL; + audio_input_stream_ = nullptr; } void OpenAndStart(AudioInputStream::AudioInputCallback* sink) { @@ -162,14 +162,14 @@ class AudioInputTest : public testing::Test { EXPECT_TRUE(audio_input_stream_->Open()); audio_input_stream_->Stop(); audio_input_stream_->Close(); - audio_input_stream_ = NULL; + audio_input_stream_ = nullptr; } void StopAndClose() { DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); audio_input_stream_->Stop(); audio_input_stream_->Close(); - audio_input_stream_ = NULL; + audio_input_stream_ = nullptr; } // Synchronously runs the provided callback/closure on the audio thread. diff --git a/chromium/media/audio/audio_low_latency_input_output_unittest.cc b/chromium/media/audio/audio_low_latency_input_output_unittest.cc index 00250cc4d22..a6e11feb192 100644 --- a/chromium/media/audio/audio_low_latency_input_output_unittest.cc +++ b/chromium/media/audio/audio_low_latency_input_output_unittest.cc @@ -11,6 +11,7 @@ #include "base/bind.h" #include "base/environment.h" #include "base/files/file_util.h" +#include "base/logging.h" #include "base/macros.h" #include "base/path_service.h" #include "base/run_loop.h" diff --git a/chromium/media/audio/audio_manager_base.cc b/chromium/media/audio/audio_manager_base.cc index 7bb71fe0cdf..473d9e4979a 100644 --- a/chromium/media/audio/audio_manager_base.cc +++ b/chromium/media/audio/audio_manager_base.cc @@ -26,6 +26,7 @@ #include "media/audio/fake_audio_output_stream.h" #include "media/base/media_switches.h" +#include "base/logging.h" #include "media/audio/audio_input_stream_data_interceptor.h" namespace media { diff --git a/chromium/media/audio/audio_manager_unittest.cc b/chromium/media/audio/audio_manager_unittest.cc index 65948647255..f9db1276a2b 100644 --- a/chromium/media/audio/audio_manager_unittest.cc +++ b/chromium/media/audio/audio_manager_unittest.cc @@ -102,6 +102,12 @@ struct TestAudioManagerFactory<std::nullptr_t> { using chromeos::AudioNode; using chromeos::AudioNodeList; +const int kDefaultSampleRate = 48000; + +const uint64_t kInternalSpeakerId = 10001; +const uint64_t kInternalSpeakerStableDeviceId = 10001; +const uint64_t kInternalMicId = 10002; +const uint64_t kInternalMicStableDeviceId = 10002; const uint64_t kJabraSpeaker1Id = 30001; const uint64_t kJabraSpeaker1StableDeviceId = 80001; const uint64_t kJabraSpeaker2Id = 30002; @@ -115,6 +121,30 @@ const uint64_t kJabraMic2StableDeviceId = 90002; const uint64_t kWebcamMicId = 40003; const uint64_t kWebcamMicStableDeviceId = 90003; +const AudioNode kInternalSpeaker(false, + kInternalSpeakerId, + true, + kInternalSpeakerStableDeviceId, + kInternalSpeakerStableDeviceId ^ 0xFF, + "Internal Speaker", + "INTERNAL_SPEAKER", + "Speaker", + false, + 0, + 2); + +const AudioNode kInternalMic(true, + kInternalMicId, + true, + kInternalMicStableDeviceId, + kInternalMicStableDeviceId ^ 0xFF, + "Internal Mic", + "INTERNAL_MIC", + "Internal Mic", + false, + 0, + 1); + const AudioNode kJabraSpeaker1(false, kJabraSpeaker1Id, true, @@ -124,7 +154,8 @@ const AudioNode kJabraSpeaker1(false, "USB", "Jabra Speaker 1", false, - 0); + 0, + 2); // expects CHANNEL_LAYOUT_STEREO const AudioNode kJabraSpeaker2(false, kJabraSpeaker2Id, @@ -135,7 +166,8 @@ const AudioNode kJabraSpeaker2(false, "USB", "Jabra Speaker 2", false, - 0); + 0, + 6); // expects CHANNEL_LAYOUT_5_1 const AudioNode kHDMIOutput(false, kHDMIOutputId, @@ -146,7 +178,8 @@ const AudioNode kHDMIOutput(false, "HDMI", "HDA Intel MID", false, - 0); + 0, + 8); // expects CHANNEL_LAYOUT_7_1 const AudioNode kJabraMic1(true, kJabraMic1Id, @@ -157,7 +190,8 @@ const AudioNode kJabraMic1(true, "USB", "Jabra Mic 1", false, - 0); + 0, + 1); const AudioNode kJabraMic2(true, kJabraMic2Id, @@ -168,7 +202,8 @@ const AudioNode kJabraMic2(true, "USB", "Jabra Mic 2", false, - 0); + 0, + 1); const AudioNode kUSBCameraMic(true, kWebcamMicId, @@ -179,7 +214,8 @@ const AudioNode kUSBCameraMic(true, "USB", "Logitech Webcam", false, - 0); + 0, + 1); #endif // defined(USE_CRAS) const char kRealDefaultInputDeviceID[] = "input2"; @@ -274,6 +310,27 @@ class AudioManagerTest : public ::testing::Test { cras_audio_handler_ = chromeos::CrasAudioHandler::Get(); base::RunLoop().RunUntilIdle(); } + + void SetActiveOutputNode(uint64_t node_id) { + cras_audio_handler_->SwitchToDevice( + *cras_audio_handler_->GetDeviceFromId(node_id), true /* notify */, + chromeos::CrasAudioHandler::ACTIVATE_BY_USER /* activate_by */); + } + + AudioParameters GetPreferredOutputStreamParameters( + ChannelLayout channel_layout, int32_t user_buffer_size = 0) { + // Generated AudioParameters should follow the same rule as in + // AudioManagerCras::GetPreferredOutputStreamParameters(). + int sample_rate = kDefaultSampleRate; + int32_t buffer_size = user_buffer_size; + if (buffer_size == 0) // Not user-provided. + cras_audio_handler_->GetDefaultOutputBufferSize(&buffer_size); + return AudioParameters( + AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, sample_rate, + buffer_size, + AudioParameters::HardwareCapabilities(limits::kMinAudioBufferSize, + limits::kMaxAudioBufferSize)); + } #endif // defined(USE_CRAS) protected: @@ -367,6 +424,19 @@ class AudioManagerTest : public ::testing::Test { LOG(WARNING) << "No input devices detected"; } } + + // Helper method for (USE_CRAS) which returns |group_id| from |device_id|. + std::string getGroupID(const AudioDeviceDescriptions& device_descriptions, + const std::string device_id) { + AudioDeviceDescriptions::const_iterator it = + std::find_if(device_descriptions.begin(), device_descriptions.end(), + [&device_id](const auto& audio_device_desc) { + return audio_device_desc.unique_id == device_id; + }); + + EXPECT_NE(it, device_descriptions.end()); + return it->group_id; + } #endif // defined(USE_CRAS) bool InputDevicesAvailable() { @@ -464,6 +534,175 @@ TEST_F(AudioManagerTest, EnumerateOutputDevicesCras) { device_info_accessor_->GetAudioOutputDeviceDescriptions(&device_descriptions); CheckDeviceDescriptionsCras(device_descriptions, expectation); } + +TEST_F(AudioManagerTest, CheckOutputStreamParametersCras) { + // Setup the devices without internal mic, so that it doesn't exist + // beamforming capable mic. + AudioNodeList audio_nodes; + audio_nodes.push_back(kJabraMic1); + audio_nodes.push_back(kJabraMic2); + audio_nodes.push_back(kUSBCameraMic); + audio_nodes.push_back(kHDMIOutput); + audio_nodes.push_back(kJabraSpeaker1); + audio_nodes.push_back(kJabraSpeaker2); + + SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); + + ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); + + DVLOG(2) << "Testing AudioManagerCras."; + CreateAudioManagerForTesting<AudioManagerCras>(); + AudioParameters params, golden_params; + + // channel_layout: + // JabraSpeaker1 (2-channel): CHANNEL_LAYOUT_STEREO + // JabraSpeaker2 (6-channel): CHANNEL_LAYOUT_5_1 + // HDMIOutput (8-channel): CHANNEL_LAYOUT_7_1 + + // Check GetOutputStreamParameters() with device ID. The returned parameters + // should be reflected to the specific output device. + params = device_info_accessor_->GetOutputStreamParameters( + base::NumberToString(kJabraSpeaker1Id)); + golden_params = GetPreferredOutputStreamParameters( + ChannelLayout::CHANNEL_LAYOUT_STEREO); + EXPECT_TRUE(params.Equals(golden_params)); + params = device_info_accessor_->GetOutputStreamParameters( + base::NumberToString(kJabraSpeaker2Id)); + golden_params = GetPreferredOutputStreamParameters( + ChannelLayout::CHANNEL_LAYOUT_5_1); + EXPECT_TRUE(params.Equals(golden_params)); + params = device_info_accessor_->GetOutputStreamParameters( + base::NumberToString(kHDMIOutputId)); + golden_params = GetPreferredOutputStreamParameters( + ChannelLayout::CHANNEL_LAYOUT_7_1); + EXPECT_TRUE(params.Equals(golden_params)); + + // Set user-provided audio buffer size by command line, then check the buffer + // size in stream parameters is equal to the user-provided one. + int argc = 2; + char const *argv0 = "dummy"; + char const *argv1 = "--audio-buffer-size=2048"; + const char* argv[] = {argv0, argv1, 0}; + base::CommandLine::Reset(); + EXPECT_TRUE(base::CommandLine::Init(argc, argv)); + + // Check GetOutputStreamParameters() with default ID. The returned parameters + // should reflect the currently active output device. + SetActiveOutputNode(kJabraSpeaker1Id); + params = device_info_accessor_->GetOutputStreamParameters( + AudioDeviceDescription::kDefaultDeviceId); + golden_params = GetPreferredOutputStreamParameters( + ChannelLayout::CHANNEL_LAYOUT_STEREO, 2048); + EXPECT_TRUE(params.Equals(golden_params)); + SetActiveOutputNode(kJabraSpeaker2Id); + params = device_info_accessor_->GetOutputStreamParameters( + AudioDeviceDescription::kDefaultDeviceId); + golden_params = GetPreferredOutputStreamParameters( + ChannelLayout::CHANNEL_LAYOUT_5_1, 2048); + EXPECT_TRUE(params.Equals(golden_params)); + SetActiveOutputNode(kHDMIOutputId); + params = device_info_accessor_->GetOutputStreamParameters( + AudioDeviceDescription::kDefaultDeviceId); + golden_params = GetPreferredOutputStreamParameters( + ChannelLayout::CHANNEL_LAYOUT_7_1, 2048); + EXPECT_TRUE(params.Equals(golden_params)); + + // Check non-default device again. + params = device_info_accessor_->GetOutputStreamParameters( + base::NumberToString(kJabraSpeaker1Id)); + golden_params = GetPreferredOutputStreamParameters( + ChannelLayout::CHANNEL_LAYOUT_STEREO, 2048); + EXPECT_TRUE(params.Equals(golden_params)); +} + +TEST_F(AudioManagerTest, LookupDefaultInputDeviceWithProperGroupId) { + // Setup devices with external microphone as active device. + // Switch active device to the internal microphone. + // Check if default device has the same group id as internal microphone. + AudioNodeList audio_nodes; + audio_nodes.push_back(kInternalMic); + audio_nodes.push_back(kJabraMic1); + SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); + + ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); + + // Setup expectation with physical devices. + std::map<uint64_t, std::string> expectation; + expectation[kInternalMic.id] = + cras_audio_handler_->GetDeviceFromId(kInternalMic.id)->display_name; + expectation[kJabraMic1.id] = + cras_audio_handler_->GetDeviceFromId(kJabraMic1.id)->display_name; + + CreateAudioManagerForTesting<AudioManagerCras>(); + auto previous_default_device_id = + device_info_accessor_->GetDefaultInputDeviceID(); + EXPECT_EQ(base::NumberToString(kJabraMic1.id), previous_default_device_id); + AudioDeviceDescriptions device_descriptions; + device_info_accessor_->GetAudioInputDeviceDescriptions(&device_descriptions); + + CheckDeviceDescriptions(device_descriptions); + + // Set internal microphone as active. + chromeos::AudioDevice internal_microphone(kInternalMic); + cras_audio_handler_->SwitchToDevice( + internal_microphone, true, chromeos::CrasAudioHandler::ACTIVATE_BY_USER); + auto new_default_device_id = device_info_accessor_->GetDefaultInputDeviceID(); + EXPECT_NE(previous_default_device_id, new_default_device_id); + + auto default_device_group_id = + getGroupID(device_descriptions, new_default_device_id); + auto mic_group_id = + getGroupID(device_descriptions, base::NumberToString(kInternalMic.id)); + + EXPECT_EQ(default_device_group_id, mic_group_id); + EXPECT_EQ(base::NumberToString(kInternalMic.id), new_default_device_id); +} + +TEST_F(AudioManagerTest, LookupDefaultOutputDeviceWithProperGroupId) { + // Setup devices with external speaker as active device. + // Switch active device to the internal speaker. + // Check if default device has the same group id as internal speaker. + AudioNodeList audio_nodes; + audio_nodes.push_back(kInternalSpeaker); + audio_nodes.push_back(kJabraSpeaker1); + + SetUpCrasAudioHandlerWithTestingNodes(audio_nodes); + + ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); + + // Setup expectation with physical devices. + std::map<uint64_t, std::string> expectation; + expectation[kInternalSpeaker.id] = + cras_audio_handler_->GetDeviceFromId(kInternalSpeaker.id)->display_name; + expectation[kJabraSpeaker1.id] = + cras_audio_handler_->GetDeviceFromId(kJabraSpeaker1.id)->display_name; + + CreateAudioManagerForTesting<AudioManagerCras>(); + auto previous_default_device_id = + device_info_accessor_->GetDefaultOutputDeviceID(); + EXPECT_EQ(base::NumberToString(kJabraSpeaker1.id), + previous_default_device_id); + AudioDeviceDescriptions device_descriptions; + device_info_accessor_->GetAudioOutputDeviceDescriptions(&device_descriptions); + + CheckDeviceDescriptions(device_descriptions); + + // Set internal speaker as active. + chromeos::AudioDevice internal_speaker(kInternalSpeaker); + cras_audio_handler_->SwitchToDevice( + internal_speaker, true, chromeos::CrasAudioHandler::ACTIVATE_BY_USER); + auto new_default_device_id = + device_info_accessor_->GetDefaultOutputDeviceID(); + EXPECT_NE(previous_default_device_id, new_default_device_id); + + auto default_device_group_id = + getGroupID(device_descriptions, new_default_device_id); + auto speaker_group_id = getGroupID(device_descriptions, + base::NumberToString(kInternalSpeaker.id)); + + EXPECT_EQ(default_device_group_id, speaker_group_id); + EXPECT_EQ(base::NumberToString(kInternalSpeaker.id), new_default_device_id); +} #else // !defined(USE_CRAS) TEST_F(AudioManagerTest, HandleDefaultDeviceIDs) { diff --git a/chromium/media/audio/audio_output_device.cc b/chromium/media/audio/audio_output_device.cc index 92448e7469f..d18408f0002 100644 --- a/chromium/media/audio/audio_output_device.cc +++ b/chromium/media/audio/audio_output_device.cc @@ -11,6 +11,7 @@ #include <utility> #include "base/callback_helpers.h" +#include "base/logging.h" #include "base/macros.h" #include "base/metrics/histogram_macros.h" #include "base/single_thread_task_runner.h" @@ -33,7 +34,7 @@ AudioOutputDevice::AudioOutputDevice( const AudioSinkParameters& sink_params, base::TimeDelta authorization_timeout) : io_task_runner_(io_task_runner), - callback_(NULL), + callback_(nullptr), ipc_(std::move(ipc)), state_(IDLE), session_id_(sink_params.session_id), diff --git a/chromium/media/audio/audio_output_device_thread_callback.cc b/chromium/media/audio/audio_output_device_thread_callback.cc index c834b0d77d8..37a88086aea 100644 --- a/chromium/media/audio/audio_output_device_thread_callback.cc +++ b/chromium/media/audio/audio_output_device_thread_callback.cc @@ -6,6 +6,7 @@ #include <utility> +#include "base/logging.h" #include "base/metrics/histogram_macros.h" #include "base/trace_event/trace_event.h" diff --git a/chromium/media/audio/audio_output_resampler.cc b/chromium/media/audio/audio_output_resampler.cc index 7e7c94c00d5..49ed554f8df 100644 --- a/chromium/media/audio/audio_output_resampler.cc +++ b/chromium/media/audio/audio_output_resampler.cc @@ -14,6 +14,7 @@ #include "base/bind.h" #include "base/bind_helpers.h" #include "base/compiler_specific.h" +#include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/metrics/histogram_functions.h" diff --git a/chromium/media/audio/audio_output_stream_sink.cc b/chromium/media/audio/audio_output_stream_sink.cc index b70b58e13e1..682d05e4813 100644 --- a/chromium/media/audio/audio_output_stream_sink.cc +++ b/chromium/media/audio/audio_output_stream_sink.cc @@ -19,10 +19,10 @@ namespace media { AudioOutputStreamSink::AudioOutputStreamSink() : initialized_(false), started_(false), - render_callback_(NULL), - active_render_callback_(NULL), + render_callback_(nullptr), + active_render_callback_(nullptr), audio_task_runner_(AudioManager::Get()->GetTaskRunner()), - stream_(NULL) {} + stream_(nullptr) {} AudioOutputStreamSink::~AudioOutputStreamSink() = default; @@ -137,7 +137,7 @@ void AudioOutputStreamSink::DoStart(const AudioParameters& params) { } if (stream_) stream_->Close(); - stream_ = NULL; + stream_ = nullptr; } } @@ -149,7 +149,7 @@ void AudioOutputStreamSink::DoStop() { DoPause(); stream_->Close(); - stream_ = NULL; + stream_ = nullptr; } void AudioOutputStreamSink::DoPause() { @@ -176,7 +176,7 @@ void AudioOutputStreamSink::DoSetVolume(double volume) { void AudioOutputStreamSink::ClearCallback() { base::AutoLock al(callback_lock_); - active_render_callback_ = NULL; + active_render_callback_ = nullptr; } } // namespace media diff --git a/chromium/media/audio/audio_output_unittest.cc b/chromium/media/audio/audio_output_unittest.cc index 99f8bbb78d7..8191243e21f 100644 --- a/chromium/media/audio/audio_output_unittest.cc +++ b/chromium/media/audio/audio_output_unittest.cc @@ -41,12 +41,6 @@ class AudioOutputTest : public testing::TestWithParam<bool> { if (GetParam()) features_.InitAndEnableFeature(features::kUseAAudioDriver); #endif -#if defined(OS_LINUX) - // Due to problems with PulseAudio failing to start, use a fake audio - // stream. https://crbug.com/1047655#c70 - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kDisableAudioOutput); -#endif base::RunLoop().RunUntilIdle(); } ~AudioOutputTest() override { diff --git a/chromium/media/audio/audio_thread_hang_monitor.cc b/chromium/media/audio/audio_thread_hang_monitor.cc index f07dea512e9..c26d3f59590 100644 --- a/chromium/media/audio/audio_thread_hang_monitor.cc +++ b/chromium/media/audio/audio_thread_hang_monitor.cc @@ -11,6 +11,7 @@ #include "base/callback.h" #include "base/debug/dump_without_crashing.h" #include "base/location.h" +#include "base/logging.h" #include "base/metrics/histogram_macros.h" #include "base/power_monitor/power_monitor.h" #include "base/process/process.h" diff --git a/chromium/media/audio/cras/audio_manager_cras.cc b/chromium/media/audio/cras/audio_manager_cras.cc index fb4f792d5d0..24540cbfa73 100644 --- a/chromium/media/audio/cras/audio_manager_cras.cc +++ b/chromium/media/audio/cras/audio_manager_cras.cc @@ -374,29 +374,59 @@ int32_t AudioManagerCras::GetSystemAecGroupIdPerBoard() { AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( const std::string& output_device_id, const AudioParameters& input_params) { + DCHECK(GetTaskRunner()->BelongsToCurrentThread()); + ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; int sample_rate = kDefaultSampleRate; - int buffer_size = GetDefaultOutputBufferSizePerBoard(); + int buffer_size = GetUserBufferSize(); if (input_params.IsValid()) { - sample_rate = input_params.sample_rate(); channel_layout = input_params.channel_layout(); - buffer_size = - std::min(static_cast<int>(limits::kMaxAudioBufferSize), - std::max(static_cast<int>(limits::kMinAudioBufferSize), - input_params.frames_per_buffer())); + sample_rate = input_params.sample_rate(); + if (!buffer_size) // Not user-provided. + buffer_size = + std::min(static_cast<int>(limits::kMaxAudioBufferSize), + std::max(static_cast<int>(limits::kMinAudioBufferSize), + input_params.frames_per_buffer())); + return AudioParameters( + AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, sample_rate, + buffer_size, + AudioParameters::HardwareCapabilities(limits::kMinAudioBufferSize, + limits::kMaxAudioBufferSize)); } - int user_buffer_size = GetUserBufferSize(); - if (user_buffer_size) - buffer_size = user_buffer_size; + // Get max supported channels from |output_device_id| or the primary active + // one if |output_device_id| is the default device. + uint64_t preferred_device_id; + if (AudioDeviceDescription::IsDefaultDevice(output_device_id)) { + preferred_device_id = GetPrimaryActiveOutputNode(); + } else { + if (!base::StringToUint64(output_device_id, &preferred_device_id)) + preferred_device_id = 0; // 0 represents invalid |output_device_id|. + } - AudioParameters params( + if (preferred_device_id) { + chromeos::AudioDeviceList devices; + GetAudioDevices(&devices); + const chromeos::AudioDevice* device = + GetDeviceFromId(devices, preferred_device_id); + if (device && device->is_input == false) { + channel_layout = GuessChannelLayout( + static_cast<int>(device->max_supported_channels)); + // Fall-back to old fashion: always fixed to STEREO layout. + if (channel_layout == CHANNEL_LAYOUT_UNSUPPORTED) { + channel_layout = CHANNEL_LAYOUT_STEREO; + } + } + } + + if (!buffer_size) // Not user-provided. + buffer_size = GetDefaultOutputBufferSizePerBoard(); + + return AudioParameters( AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, sample_rate, buffer_size, AudioParameters::HardwareCapabilities(limits::kMinAudioBufferSize, limits::kMaxAudioBufferSize)); - - return params; } AudioOutputStream* AudioManagerCras::MakeOutputStream( diff --git a/chromium/media/audio/fake_audio_input_stream.cc b/chromium/media/audio/fake_audio_input_stream.cc index ce75d1e175e..89af0a9f506 100644 --- a/chromium/media/audio/fake_audio_input_stream.cc +++ b/chromium/media/audio/fake_audio_input_stream.cc @@ -12,6 +12,7 @@ #include "base/bind_helpers.h" #include "base/command_line.h" #include "base/files/file_path.h" +#include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/memory/ref_counted.h" diff --git a/chromium/media/audio/fake_audio_output_stream.cc b/chromium/media/audio/fake_audio_output_stream.cc index 04a624e321f..067172b0617 100644 --- a/chromium/media/audio/fake_audio_output_stream.cc +++ b/chromium/media/audio/fake_audio_output_stream.cc @@ -23,7 +23,7 @@ FakeAudioOutputStream::FakeAudioOutputStream(AudioManagerBase* manager, const AudioParameters& params) : audio_manager_(manager), fixed_data_delay_(FakeAudioWorker::ComputeFakeOutputDelay(params)), - callback_(NULL), + callback_(nullptr), fake_worker_(manager->GetWorkerTaskRunner(), params), audio_bus_(AudioBus::Create(params)) {} @@ -47,7 +47,7 @@ void FakeAudioOutputStream::Start(AudioSourceCallback* callback) { void FakeAudioOutputStream::Stop() { DCHECK(audio_manager_->GetTaskRunner()->BelongsToCurrentThread()); fake_worker_.Stop(); - callback_ = NULL; + callback_ = nullptr; } void FakeAudioOutputStream::Close() { diff --git a/chromium/media/audio/fuchsia/audio_output_stream_fuchsia.cc b/chromium/media/audio/fuchsia/audio_output_stream_fuchsia.cc index a3f7a94e91e..2a5f8dcf8da 100644 --- a/chromium/media/audio/fuchsia/audio_output_stream_fuchsia.cc +++ b/chromium/media/audio/fuchsia/audio_output_stream_fuchsia.cc @@ -8,7 +8,8 @@ #include <zircon/syscalls.h> #include "base/bind.h" -#include "base/fuchsia/default_context.h" +#include "base/fuchsia/process_context.h" +#include "base/logging.h" #include "base/memory/writable_shared_memory_region.h" #include "media/audio/fuchsia/audio_manager_fuchsia.h" #include "media/base/audio_sample_types.h" @@ -38,7 +39,7 @@ bool AudioOutputStreamFuchsia::Open() { // Connect |audio_renderer_| to the audio service. fuchsia::media::AudioPtr audio_server = - base::fuchsia::ComponentContextForCurrentProcess() + base::ComponentContextForProcess() ->svc() ->Connect<fuchsia::media::Audio>(); audio_server->CreateAudioRenderer(audio_renderer_.NewRequest()); diff --git a/chromium/media/audio/linux/audio_manager_linux.cc b/chromium/media/audio/linux/audio_manager_linux.cc index 2986b094580..cb8f271efbd 100644 --- a/chromium/media/audio/linux/audio_manager_linux.cc +++ b/chromium/media/audio/linux/audio_manager_linux.cc @@ -5,6 +5,7 @@ #include <memory> #include "base/command_line.h" +#include "base/logging.h" #include "base/metrics/histogram_macros.h" #include "media/audio/fake_audio_manager.h" #include "media/base/media_switches.h" diff --git a/chromium/media/audio/mac/audio_manager_mac.cc b/chromium/media/audio/mac/audio_manager_mac.cc index 26436b47942..a994f74bb68 100644 --- a/chromium/media/audio/mac/audio_manager_mac.cc +++ b/chromium/media/audio/mac/audio_manager_mac.cc @@ -1054,14 +1054,7 @@ bool AudioManagerMac::MaybeChangeBufferSize(AudioDeviceID device_id, DVLOG_IF(1, result == noErr) << "IO buffer size changed to: " << buffer_size; // Store the currently used (after a change) I/O buffer frame size. *io_buffer_frame_size = buffer_size; - - // If the size was changed, update the actual output buffer size used for the - // given device ID. - if (!is_input && (result == noErr)) { - output_io_buffer_size_map_[device_id] = buffer_size; - } - - return (result == noErr); + return result == noErr; } // static @@ -1192,76 +1185,6 @@ void AudioManagerMac::UnsuppressNoiseReduction(AudioDeviceID device_id) { } } -void AudioManagerMac::IncreaseIOBufferSizeIfPossible(AudioDeviceID device_id) { - DCHECK(GetTaskRunner()->BelongsToCurrentThread()); - DVLOG(1) << "IncreaseIOBufferSizeIfPossible(id=0x" << std::hex << device_id - << ")"; - if (in_shutdown_) { - DVLOG(1) << "Disabled since we are shutting down"; - return; - } - - // Start by getting the actual I/O buffer size. Then scan all active output - // streams using the specified |device_id| and find the minimum requested - // buffer size. In addition, store a reference to the audio unit of the first - // output stream using |device_id|. - // All active output streams use the same actual I/O buffer size given - // a unique device ID. - // TODO(henrika): it would also be possible to use AudioUnitGetProperty(..., - // kAudioDevicePropertyBufferFrameSize,...) instead of caching the actual - // buffer size but I have chosen to use the map instead to avoid possibly - // expensive Core Audio API calls and the risk of failure when asking while - // closing a stream. - // TODO(http://crbug.com/961629): There seems to be bugs in the caching. - const size_t actual_size = - output_io_buffer_size_map_.find(device_id) != - output_io_buffer_size_map_.end() - ? output_io_buffer_size_map_[device_id] - : 0; // This leads to trying to update the buffer size below. - AudioUnit audio_unit; - size_t min_requested_size = std::numeric_limits<std::size_t>::max(); - for (auto* stream : output_streams_) { - if (stream->device_id() == device_id) { - if (min_requested_size == std::numeric_limits<std::size_t>::max()) { - // Store reference to the first audio unit using the specified ID. - audio_unit = stream->audio_unit(); - } - if (stream->requested_buffer_size() < min_requested_size) - min_requested_size = stream->requested_buffer_size(); - DVLOG(1) << "requested:" << stream->requested_buffer_size() - << " actual: " << actual_size; - } - } - - if (min_requested_size == std::numeric_limits<std::size_t>::max()) { - DVLOG(1) << "No action since there is no active stream for given device id"; - return; - } - - // It is only possible to revert to a larger buffer size if the lowest - // requested is not in use. Example: if the actual I/O buffer size is 256 and - // at least one output stream has asked for 256 as its buffer size, we can't - // start using a larger I/O buffer size. - DCHECK_GE(min_requested_size, actual_size); - if (min_requested_size == actual_size) { - DVLOG(1) << "No action since lowest possible size is already in use: " - << actual_size; - return; - } - - // It should now be safe to increase the I/O buffer size to a new (higher) - // value using the |min_requested_size|. Doing so will save system resources. - // All active output streams with the same |device_id| are affected by this - // change but it is only required to apply the change to one of the streams. - // We ignore the result from MaybeChangeBufferSize(). Logging is done in that - // function and it could fail if the device was removed during the operation. - DVLOG(1) << "min_requested_size: " << min_requested_size; - bool size_was_changed = false; - size_t io_buffer_frame_size = 0; - MaybeChangeBufferSize(device_id, audio_unit, 0, min_requested_size, - &size_was_changed, &io_buffer_frame_size); -} - bool AudioManagerMac::AudioDeviceIsUsedForInput(AudioDeviceID device_id) { DCHECK(GetTaskRunner()->BelongsToCurrentThread()); if (!basic_input_streams_.empty()) { @@ -1299,25 +1222,6 @@ void AudioManagerMac::ReleaseOutputStreamUsingRealDevice( // Start by closing down the specified output stream. output_streams_.remove(static_cast<AUHALStream*>(stream)); AudioManagerBase::ReleaseOutputStream(stream); - - // Prevent attempt to alter buffer size if the released stream was the last - // output stream. - if (output_streams_.empty()) - return; - - // If the audio device exists (i.e. has not been removed from the system) and - // is not used for input, see if it is possible to increase the IO buffer size - // (saves power) given the remaining output audio streams and their buffer - // size requirements. - // TODO(grunell): When closing several idle streams - // (AudioOutputDispatcherImpl::CloseIdleStreams), we should ideally only - // update the buffer size once after closing all those streams. - std::vector<AudioObjectID> device_ids = - core_audio_mac::GetAllAudioDeviceIDs(); - const bool device_exists = std::find(device_ids.begin(), device_ids.end(), - device_id) != device_ids.end(); - if (device_exists && !AudioDeviceIsUsedForInput(device_id)) - IncreaseIOBufferSizeIfPossible(device_id); } void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { diff --git a/chromium/media/audio/mac/audio_manager_mac.h b/chromium/media/audio/mac/audio_manager_mac.h index c2fb8dec46c..74de0a11bdf 100644 --- a/chromium/media/audio/mac/audio_manager_mac.h +++ b/chromium/media/audio/mac/audio_manager_mac.h @@ -169,21 +169,6 @@ class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase { // Returns true if any active input stream is using the specified |device_id|. bool AudioDeviceIsUsedForInput(AudioDeviceID device_id); - // This method is called when an output stream has been released and it takes - // the given |device_id| and scans all active output streams that are - // using this id. The goal is to find a new (larger) I/O buffer size which - // can be applied to all active output streams since doing so will save - // system resources. - // Note that, it is only called if no input stream is also using the device. - // Example: two active output streams where #1 wants 1024 as buffer size but - // is using 256 since stream #2 wants it. Now, if stream #2 is closed down, - // the native I/O buffer size will be increased to 1024 instead of 256. - // Returns true if it was possible to increase the I/O buffer size and - // false otherwise. - // TODO(henrika): possibly extend the scheme to also take input streams into - // account. - void IncreaseIOBufferSizeIfPossible(AudioDeviceID device_id); - std::string GetDefaultDeviceID(bool is_input); std::unique_ptr<AudioDeviceListenerMac> output_device_listener_; @@ -208,10 +193,6 @@ class MEDIA_EXPORT AudioManagerMac : public AudioManagerBase { std::list<AUAudioInputStream*> low_latency_input_streams_; std::list<AUHALStream*> output_streams_; - // Maps device IDs and their corresponding actual (I/O) buffer sizes for - // all output streams using the specific device. - std::map<AudioDeviceID, size_t> output_io_buffer_size_map_; - // Set to true in the destructor. Ensures that methods that touches native // Core Audio APIs are not executed during shutdown. bool in_shutdown_; diff --git a/chromium/media/audio/null_audio_sink.cc b/chromium/media/audio/null_audio_sink.cc index 56d7c23b9a1..ceda2ae30ac 100644 --- a/chromium/media/audio/null_audio_sink.cc +++ b/chromium/media/audio/null_audio_sink.cc @@ -18,7 +18,7 @@ NullAudioSink::NullAudioSink( : initialized_(false), started_(false), playing_(false), - callback_(NULL), + callback_(nullptr), task_runner_(task_runner) {} NullAudioSink::~NullAudioSink() = default; diff --git a/chromium/media/audio/power_observer_helper.cc b/chromium/media/audio/power_observer_helper.cc index aa0dc32bb01..d8e6d8199bd 100644 --- a/chromium/media/audio/power_observer_helper.cc +++ b/chromium/media/audio/power_observer_helper.cc @@ -7,6 +7,7 @@ #include <utility> #include "base/bind.h" +#include "base/logging.h" #include "base/power_monitor/power_monitor.h" namespace media { diff --git a/chromium/media/audio/pulse/pulse_output.cc b/chromium/media/audio/pulse/pulse_output.cc index cdcda5f9c60..2b773a39157 100644 --- a/chromium/media/audio/pulse/pulse_output.cc +++ b/chromium/media/audio/pulse/pulse_output.cc @@ -253,6 +253,9 @@ void PulseAudioOutputStream::Stop() { // outstanding callbacks have completed. AutoPulseLock auto_lock(pa_mainloop_); + if (!source_callback_) + return; + // Set |source_callback_| to nullptr so all FulfillWriteRequest() calls which // may occur while waiting on the flush and cork exit immediately. auto* callback = source_callback_; diff --git a/chromium/media/audio/pulse/pulse_util.cc b/chromium/media/audio/pulse/pulse_util.cc index 085036bb967..d8e6ce1ca5c 100644 --- a/chromium/media/audio/pulse/pulse_util.cc +++ b/chromium/media/audio/pulse/pulse_util.cc @@ -13,6 +13,7 @@ #include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" +#include "base/notreached.h" #include "base/synchronization/waitable_event.h" #include "build/branding_buildflags.h" #include "media/audio/audio_device_description.h" diff --git a/chromium/media/audio/wav_audio_handler.cc b/chromium/media/audio/wav_audio_handler.cc index e5a8a7eb41d..4d0f5d29a32 100644 --- a/chromium/media/audio/wav_audio_handler.cc +++ b/chromium/media/audio/wav_audio_handler.cc @@ -9,6 +9,7 @@ #include "base/logging.h" #include "base/memory/ptr_util.h" +#include "base/notreached.h" #include "base/sys_byteorder.h" #include "build/build_config.h" #include "media/base/audio_bus.h" diff --git a/chromium/media/audio/win/audio_device_listener_win.cc b/chromium/media/audio/win/audio_device_listener_win.cc index 166a1e53851..cdf7bec9061 100644 --- a/chromium/media/audio/win/audio_device_listener_win.cc +++ b/chromium/media/audio/win/audio_device_listener_win.cc @@ -19,7 +19,7 @@ using base::win::ScopedCoMem; namespace media { static std::string FlowToString(EDataFlow flow) { - return flow == eRender ? "eRender" : "eConsole"; + return flow == eRender ? "eRender" : "eCapture"; } static std::string RoleToString(ERole role) { @@ -134,8 +134,10 @@ HRESULT AudioDeviceListenerWin::OnDefaultDeviceChanged( // it provides a substantially faster resumption of playback. bool did_run_listener_cb = false; const base::TimeTicks now = tick_clock_->NowTicks(); - if (flow == eRender && now - last_device_change_time_ > kDeviceChangeLimit) { + if (flow == eRender && (now - last_device_change_time_ > kDeviceChangeLimit || + new_device_id.compare(last_device_id_) != 0)) { last_device_change_time_ = now; + last_device_id_ = new_device_id; listener_cb_.Run(); did_run_listener_cb = true; } diff --git a/chromium/media/audio/win/audio_device_listener_win.h b/chromium/media/audio/win/audio_device_listener_win.h index c40054a723d..4ea3568482c 100644 --- a/chromium/media/audio/win/audio_device_listener_win.h +++ b/chromium/media/audio/win/audio_device_listener_win.h @@ -63,6 +63,7 @@ class MEDIA_EXPORT AudioDeviceListenerWin : public IMMNotificationClient { // Used to rate limit device change events. base::TimeTicks last_device_change_time_; + std::string last_device_id_; // AudioDeviceListenerWin must be constructed and destructed on one thread. THREAD_CHECKER(thread_checker_); diff --git a/chromium/media/audio/win/audio_low_latency_output_win_unittest.cc b/chromium/media/audio/win/audio_low_latency_output_win_unittest.cc index 84b87e21428..c796ab32a0c 100644 --- a/chromium/media/audio/win/audio_low_latency_output_win_unittest.cc +++ b/chromium/media/audio/win/audio_low_latency_output_win_unittest.cc @@ -13,6 +13,7 @@ #include "base/environment.h" #include "base/files/file_util.h" +#include "base/logging.h" #include "base/memory/ptr_util.h" #include "base/path_service.h" #include "base/run_loop.h" diff --git a/chromium/media/audio/win/audio_output_win_unittest.cc b/chromium/media/audio/win/audio_output_win_unittest.cc index 7a4fc8648c4..e3c0377f163 100644 --- a/chromium/media/audio/win/audio_output_win_unittest.cc +++ b/chromium/media/audio/win/audio_output_win_unittest.cc @@ -10,6 +10,7 @@ #include <memory> #include "base/base_paths.h" +#include "base/logging.h" #include "base/memory/aligned_memory.h" #include "base/memory/ptr_util.h" #include "base/run_loop.h" diff --git a/chromium/media/audio/win/audio_session_event_listener_win.cc b/chromium/media/audio/win/audio_session_event_listener_win.cc index 7d568e7bd35..d344295c077 100644 --- a/chromium/media/audio/win/audio_session_event_listener_win.cc +++ b/chromium/media/audio/win/audio_session_event_listener_win.cc @@ -4,6 +4,8 @@ #include "media/audio/win/audio_session_event_listener_win.h" +#include "base/logging.h" + namespace media { AudioSessionEventListener::AudioSessionEventListener( |