summaryrefslogtreecommitdiff
path: root/chromium/media/audio
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2022-11-28 16:14:41 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-12-13 15:19:41 +0000
commit61d9742824d54be5693191fe502325a909feca59 (patch)
treecbf28e779b11338fe52eb75b915684cd8955542c /chromium/media/audio
parent45f9ded08bb7526984b24ccb5a5327aaf6821676 (diff)
downloadqtwebengine-chromium-61d9742824d54be5693191fe502325a909feca59.tar.gz
BASELINE: Update Chromium to 108.0.5359.70
Change-Id: I77334ff232b819600f275bd3cfe41fbaa3619230 Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/445904 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/media/audio')
-rw-r--r--chromium/media/audio/BUILD.gn31
-rw-r--r--chromium/media/audio/aecdump_recording_manager.cc125
-rw-r--r--chromium/media/audio/aecdump_recording_manager.h96
-rw-r--r--chromium/media/audio/aecdump_recording_manager_unittest.cc238
-rw-r--r--chromium/media/audio/agc_audio_stream.h2
-rw-r--r--chromium/media/audio/alive_checker.cc2
-rw-r--r--chromium/media/audio/alive_checker.h2
-rw-r--r--chromium/media/audio/alive_checker_unittest.cc2
-rw-r--r--chromium/media/audio/alsa/alsa_input.cc2
-rw-r--r--chromium/media/audio/alsa/alsa_input.h2
-rw-r--r--chromium/media/audio/alsa/alsa_output.cc2
-rw-r--r--chromium/media/audio/alsa/alsa_output.h2
-rw-r--r--chromium/media/audio/alsa/alsa_output_unittest.cc9
-rw-r--r--chromium/media/audio/alsa/alsa_util.cc2
-rw-r--r--chromium/media/audio/alsa/alsa_util.h2
-rw-r--r--chromium/media/audio/alsa/alsa_util_unittest.cc2
-rw-r--r--chromium/media/audio/alsa/alsa_wrapper.cc2
-rw-r--r--chromium/media/audio/alsa/alsa_wrapper.h2
-rw-r--r--chromium/media/audio/alsa/audio_manager_alsa.cc12
-rw-r--r--chromium/media/audio/alsa/audio_manager_alsa.h2
-rw-r--r--chromium/media/audio/alsa/mock_alsa_wrapper.cc2
-rw-r--r--chromium/media/audio/alsa/mock_alsa_wrapper.h2
-rw-r--r--chromium/media/audio/android/aaudio.sigs2
-rw-r--r--chromium/media/audio/android/aaudio_output.cc2
-rw-r--r--chromium/media/audio/android/aaudio_output.h2
-rw-r--r--chromium/media/audio/android/audio_android_unittest.cc4
-rw-r--r--chromium/media/audio/android/audio_manager_android.cc31
-rw-r--r--chromium/media/audio/android/audio_manager_android.h4
-rw-r--r--chromium/media/audio/android/audio_track_output_stream.cc3
-rw-r--r--chromium/media/audio/android/audio_track_output_stream.h2
-rw-r--r--chromium/media/audio/android/muteable_audio_output_stream.h2
-rw-r--r--chromium/media/audio/android/opensles_input.cc2
-rw-r--r--chromium/media/audio/android/opensles_input.h2
-rw-r--r--chromium/media/audio/android/opensles_output.cc2
-rw-r--r--chromium/media/audio/android/opensles_output.h2
-rw-r--r--chromium/media/audio/android/opensles_util.cc2
-rw-r--r--chromium/media/audio/android/opensles_util.h2
-rw-r--r--chromium/media/audio/android/opensles_wrapper.cc2
-rw-r--r--chromium/media/audio/audio_bus_pool.cc60
-rw-r--r--chromium/media/audio/audio_bus_pool.h76
-rw-r--r--chromium/media/audio/audio_bus_pool_unittest.cc120
-rw-r--r--chromium/media/audio/audio_debug_file_writer.cc173
-rw-r--r--chromium/media/audio/audio_debug_file_writer.h90
-rw-r--r--chromium/media/audio/audio_debug_file_writer_unittest.cc250
-rw-r--r--chromium/media/audio/audio_debug_recording_helper.cc101
-rw-r--r--chromium/media/audio/audio_debug_recording_helper.h49
-rw-r--r--chromium/media/audio/audio_debug_recording_helper_unittest.cc145
-rw-r--r--chromium/media/audio/audio_debug_recording_manager.cc26
-rw-r--r--chromium/media/audio/audio_debug_recording_manager.h17
-rw-r--r--chromium/media/audio/audio_debug_recording_manager_unittest.cc24
-rw-r--r--chromium/media/audio/audio_debug_recording_session.h2
-rw-r--r--chromium/media/audio/audio_debug_recording_test.cc2
-rw-r--r--chromium/media/audio/audio_debug_recording_test.h2
-rw-r--r--chromium/media/audio/audio_device_description.cc2
-rw-r--r--chromium/media/audio/audio_device_description.h2
-rw-r--r--chromium/media/audio/audio_device_info_accessor_for_tests.cc2
-rw-r--r--chromium/media/audio/audio_device_info_accessor_for_tests.h2
-rw-r--r--chromium/media/audio/audio_device_name.cc2
-rw-r--r--chromium/media/audio/audio_device_name.h2
-rw-r--r--chromium/media/audio/audio_device_thread.cc2
-rw-r--r--chromium/media/audio/audio_device_thread.h2
-rw-r--r--chromium/media/audio/audio_encoders_unittest.cc18
-rw-r--r--chromium/media/audio/audio_features.cc89
-rw-r--r--chromium/media/audio/audio_features.h34
-rw-r--r--chromium/media/audio/audio_input_delegate.cc2
-rw-r--r--chromium/media/audio/audio_input_delegate.h2
-rw-r--r--chromium/media/audio/audio_input_device.cc2
-rw-r--r--chromium/media/audio/audio_input_device.h2
-rw-r--r--chromium/media/audio/audio_input_device_unittest.cc6
-rw-r--r--chromium/media/audio/audio_input_ipc.cc2
-rw-r--r--chromium/media/audio/audio_input_ipc.h2
-rw-r--r--chromium/media/audio/audio_input_stream_data_interceptor.cc2
-rw-r--r--chromium/media/audio/audio_input_stream_data_interceptor.h2
-rw-r--r--chromium/media/audio/audio_input_stream_data_interceptor_unittest.cc2
-rw-r--r--chromium/media/audio/audio_input_unittest.cc2
-rw-r--r--chromium/media/audio/audio_io.cc2
-rw-r--r--chromium/media/audio/audio_io.h2
-rw-r--r--chromium/media/audio/audio_logging.h2
-rw-r--r--chromium/media/audio/audio_low_latency_input_output_unittest.cc8
-rw-r--r--chromium/media/audio/audio_manager.cc2
-rw-r--r--chromium/media/audio/audio_manager.h8
-rw-r--r--chromium/media/audio/audio_manager_base.cc56
-rw-r--r--chromium/media/audio/audio_manager_base.h11
-rw-r--r--chromium/media/audio/audio_manager_unittest.cc136
-rw-r--r--chromium/media/audio/audio_opus_encoder.cc14
-rw-r--r--chromium/media/audio/audio_opus_encoder.h2
-rw-r--r--chromium/media/audio/audio_output_delegate.cc2
-rw-r--r--chromium/media/audio/audio_output_delegate.h2
-rw-r--r--chromium/media/audio/audio_output_device.cc2
-rw-r--r--chromium/media/audio/audio_output_device.h2
-rw-r--r--chromium/media/audio/audio_output_device_thread_callback.cc2
-rw-r--r--chromium/media/audio/audio_output_device_thread_callback.h2
-rw-r--r--chromium/media/audio/audio_output_device_unittest.cc4
-rw-r--r--chromium/media/audio/audio_output_dispatcher.cc2
-rw-r--r--chromium/media/audio/audio_output_dispatcher.h2
-rw-r--r--chromium/media/audio/audio_output_dispatcher_impl.cc2
-rw-r--r--chromium/media/audio/audio_output_dispatcher_impl.h2
-rw-r--r--chromium/media/audio/audio_output_ipc.cc2
-rw-r--r--chromium/media/audio/audio_output_ipc.h2
-rw-r--r--chromium/media/audio/audio_output_proxy.cc2
-rw-r--r--chromium/media/audio/audio_output_proxy.h2
-rw-r--r--chromium/media/audio/audio_output_proxy_unittest.cc9
-rw-r--r--chromium/media/audio/audio_output_resampler.cc2
-rw-r--r--chromium/media/audio/audio_output_resampler.h2
-rw-r--r--chromium/media/audio/audio_output_stream_sink.cc2
-rw-r--r--chromium/media/audio/audio_output_stream_sink.h2
-rw-r--r--chromium/media/audio/audio_output_unittest.cc2
-rw-r--r--chromium/media/audio/audio_sink_parameters.cc2
-rw-r--r--chromium/media/audio/audio_sink_parameters.h2
-rw-r--r--chromium/media/audio/audio_source_parameters.cc2
-rw-r--r--chromium/media/audio/audio_source_parameters.h2
-rw-r--r--chromium/media/audio/audio_system.cc2
-rw-r--r--chromium/media/audio/audio_system.h2
-rw-r--r--chromium/media/audio/audio_system_helper.cc5
-rw-r--r--chromium/media/audio/audio_system_helper.h2
-rw-r--r--chromium/media/audio/audio_system_impl.cc3
-rw-r--r--chromium/media/audio/audio_system_impl.h2
-rw-r--r--chromium/media/audio/audio_system_impl_unittest.cc2
-rw-r--r--chromium/media/audio/audio_system_test_util.cc2
-rw-r--r--chromium/media/audio/audio_system_test_util.h26
-rw-r--r--chromium/media/audio/audio_thread.h2
-rw-r--r--chromium/media/audio/audio_thread_hang_monitor.cc2
-rw-r--r--chromium/media/audio/audio_thread_hang_monitor.h2
-rw-r--r--chromium/media/audio/audio_thread_hang_monitor_unittest.cc2
-rw-r--r--chromium/media/audio/audio_thread_impl.cc2
-rw-r--r--chromium/media/audio/audio_thread_impl.h2
-rw-r--r--chromium/media/audio/audio_unittest_util.cc2
-rw-r--r--chromium/media/audio/audio_unittest_util.h2
-rw-r--r--chromium/media/audio/clockless_audio_sink.cc2
-rw-r--r--chromium/media/audio/clockless_audio_sink.h2
-rw-r--r--chromium/media/audio/cras/audio_manager_chromeos.cc31
-rw-r--r--chromium/media/audio/cras/audio_manager_chromeos.h2
-rw-r--r--chromium/media/audio/cras/audio_manager_chromeos_unittest.cc6
-rw-r--r--chromium/media/audio/cras/audio_manager_cras.cc25
-rw-r--r--chromium/media/audio/cras/audio_manager_cras.h2
-rw-r--r--chromium/media/audio/cras/audio_manager_cras_base.cc24
-rw-r--r--chromium/media/audio/cras/audio_manager_cras_base.h16
-rw-r--r--chromium/media/audio/cras/audio_manager_cras_base_unittest.cc90
-rw-r--r--chromium/media/audio/cras/audio_manager_cras_unittest.cc2
-rw-r--r--chromium/media/audio/cras/cras_input.cc32
-rw-r--r--chromium/media/audio/cras/cras_input.h18
-rw-r--r--chromium/media/audio/cras/cras_input_unittest.cc64
-rw-r--r--chromium/media/audio/cras/cras_unified.cc2
-rw-r--r--chromium/media/audio/cras/cras_unified.h2
-rw-r--r--chromium/media/audio/cras/cras_unified_unittest.cc23
-rw-r--r--chromium/media/audio/cras/cras_util.cc2
-rw-r--r--chromium/media/audio/cras/cras_util.h2
-rw-r--r--chromium/media/audio/fake_audio_input_stream.cc2
-rw-r--r--chromium/media/audio/fake_audio_input_stream.h2
-rw-r--r--chromium/media/audio/fake_audio_log_factory.cc2
-rw-r--r--chromium/media/audio/fake_audio_log_factory.h2
-rw-r--r--chromium/media/audio/fake_audio_manager.cc14
-rw-r--r--chromium/media/audio/fake_audio_manager.h2
-rw-r--r--chromium/media/audio/fake_audio_output_stream.cc2
-rw-r--r--chromium/media/audio/fake_audio_output_stream.h2
-rw-r--r--chromium/media/audio/fuchsia/audio_input_stream_fuchsia.cc2
-rw-r--r--chromium/media/audio/fuchsia/audio_input_stream_fuchsia.h2
-rw-r--r--chromium/media/audio/fuchsia/audio_input_stream_fuchsia_test.cc38
-rw-r--r--chromium/media/audio/fuchsia/audio_manager_fuchsia.cc58
-rw-r--r--chromium/media/audio/fuchsia/audio_manager_fuchsia.h3
-rw-r--r--chromium/media/audio/fuchsia/audio_output_stream_fuchsia.cc49
-rw-r--r--chromium/media/audio/fuchsia/audio_output_stream_fuchsia.h6
-rw-r--r--chromium/media/audio/linux/audio_manager_linux.cc2
-rw-r--r--chromium/media/audio/mac/audio_auhal_mac.cc2
-rw-r--r--chromium/media/audio/mac/audio_auhal_mac.h2
-rw-r--r--chromium/media/audio/mac/audio_auhal_mac_unittest.cc2
-rw-r--r--chromium/media/audio/mac/audio_device_listener_mac.cc2
-rw-r--r--chromium/media/audio/mac/audio_device_listener_mac.h2
-rw-r--r--chromium/media/audio/mac/audio_device_listener_mac_unittest.cc4
-rw-r--r--chromium/media/audio/mac/audio_input_mac.cc2
-rw-r--r--chromium/media/audio/mac/audio_input_mac.h2
-rw-r--r--chromium/media/audio/mac/audio_low_latency_input_mac.cc2
-rw-r--r--chromium/media/audio/mac/audio_low_latency_input_mac.h2
-rw-r--r--chromium/media/audio/mac/audio_low_latency_input_mac_unittest.cc15
-rw-r--r--chromium/media/audio/mac/audio_manager_mac.cc24
-rw-r--r--chromium/media/audio/mac/audio_manager_mac.h2
-rw-r--r--chromium/media/audio/mac/core_audio_util_mac.cc5
-rw-r--r--chromium/media/audio/mac/core_audio_util_mac.h2
-rw-r--r--chromium/media/audio/mac/coreaudio_dispatch_override.cc2
-rw-r--r--chromium/media/audio/mac/coreaudio_dispatch_override.h2
-rw-r--r--chromium/media/audio/mac/scoped_audio_unit.cc2
-rw-r--r--chromium/media/audio/mac/scoped_audio_unit.h2
-rw-r--r--chromium/media/audio/mock_aecdump_recording_manager.cc17
-rw-r--r--chromium/media/audio/mock_aecdump_recording_manager.h34
-rw-r--r--chromium/media/audio/mock_audio_debug_recording_manager.cc6
-rw-r--r--chromium/media/audio/mock_audio_debug_recording_manager.h5
-rw-r--r--chromium/media/audio/mock_audio_manager.cc11
-rw-r--r--chromium/media/audio/mock_audio_manager.h5
-rw-r--r--chromium/media/audio/mock_audio_source_callback.cc2
-rw-r--r--chromium/media/audio/mock_audio_source_callback.h2
-rw-r--r--chromium/media/audio/null_audio_sink.cc2
-rw-r--r--chromium/media/audio/null_audio_sink.h2
-rw-r--r--chromium/media/audio/power_observer_helper.cc2
-rw-r--r--chromium/media/audio/power_observer_helper.h2
-rw-r--r--chromium/media/audio/power_observer_helper_unittest.cc2
-rw-r--r--chromium/media/audio/pulse/audio_manager_pulse.cc14
-rw-r--r--chromium/media/audio/pulse/audio_manager_pulse.h2
-rw-r--r--chromium/media/audio/pulse/pulse.sigs2
-rw-r--r--chromium/media/audio/pulse/pulse_input.cc2
-rw-r--r--chromium/media/audio/pulse/pulse_input.h2
-rw-r--r--chromium/media/audio/pulse/pulse_output.cc4
-rw-r--r--chromium/media/audio/pulse/pulse_output.h2
-rw-r--r--chromium/media/audio/pulse/pulse_util.cc2
-rw-r--r--chromium/media/audio/pulse/pulse_util.h2
-rw-r--r--chromium/media/audio/scoped_task_runner_observer.cc2
-rw-r--r--chromium/media/audio/scoped_task_runner_observer.h2
-rw-r--r--chromium/media/audio/simple_sources.cc4
-rw-r--r--chromium/media/audio/simple_sources.h2
-rw-r--r--chromium/media/audio/simple_sources_unittest.cc13
-rw-r--r--chromium/media/audio/system_glitch_reporter.cc2
-rw-r--r--chromium/media/audio/system_glitch_reporter.h2
-rw-r--r--chromium/media/audio/test_audio_thread.cc2
-rw-r--r--chromium/media/audio/test_audio_thread.h2
-rw-r--r--chromium/media/audio/test_data.h2
-rw-r--r--chromium/media/audio/wav_audio_handler.cc2
-rw-r--r--chromium/media/audio/wav_audio_handler.h2
-rw-r--r--chromium/media/audio/wav_audio_handler_fuzzer.cc2
-rw-r--r--chromium/media/audio/wav_audio_handler_unittest.cc2
-rw-r--r--chromium/media/audio/win/audio_device_listener_win.cc2
-rw-r--r--chromium/media/audio/win/audio_device_listener_win.h2
-rw-r--r--chromium/media/audio/win/audio_device_listener_win_unittest.cc2
-rw-r--r--chromium/media/audio/win/audio_edid_scan_win.cc185
-rw-r--r--chromium/media/audio/win/audio_edid_scan_win.h36
-rw-r--r--chromium/media/audio/win/audio_low_latency_input_win.cc22
-rw-r--r--chromium/media/audio/win/audio_low_latency_input_win.h2
-rw-r--r--chromium/media/audio/win/audio_low_latency_input_win_unittest.cc12
-rw-r--r--chromium/media/audio/win/audio_low_latency_output_win.cc50
-rw-r--r--chromium/media/audio/win/audio_low_latency_output_win.h5
-rw-r--r--chromium/media/audio/win/audio_low_latency_output_win_unittest.cc7
-rw-r--r--chromium/media/audio/win/audio_manager_win.cc103
-rw-r--r--chromium/media/audio/win/audio_manager_win.h16
-rw-r--r--chromium/media/audio/win/audio_output_win_unittest.cc40
-rw-r--r--chromium/media/audio/win/audio_session_event_listener_win.cc2
-rw-r--r--chromium/media/audio/win/audio_session_event_listener_win.h2
-rw-r--r--chromium/media/audio/win/audio_session_event_listener_win_unittest.cc2
-rw-r--r--chromium/media/audio/win/avrt_wrapper_win.cc2
-rw-r--r--chromium/media/audio/win/avrt_wrapper_win.h2
-rw-r--r--chromium/media/audio/win/core_audio_util_win.cc26
-rw-r--r--chromium/media/audio/win/core_audio_util_win.h2
-rw-r--r--chromium/media/audio/win/core_audio_util_win_unittest.cc2
-rw-r--r--chromium/media/audio/win/device_enumeration_win.cc2
-rw-r--r--chromium/media/audio/win/device_enumeration_win.h2
-rw-r--r--chromium/media/audio/win/device_enumeration_win_unittest.cc2
-rw-r--r--chromium/media/audio/win/volume_range_util.cc2
-rw-r--r--chromium/media/audio/win/volume_range_util.h2
-rw-r--r--chromium/media/audio/win/volume_range_util_unittest.cc2
-rw-r--r--chromium/media/audio/win/waveout_output_win.cc2
-rw-r--r--chromium/media/audio/win/waveout_output_win.h2
248 files changed, 2516 insertions, 1095 deletions
diff --git a/chromium/media/audio/BUILD.gn b/chromium/media/audio/BUILD.gn
index d872796dee0..cfec184939e 100644
--- a/chromium/media/audio/BUILD.gn
+++ b/chromium/media/audio/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright 2014 The Chromium Authors. All rights reserved.
+# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -52,9 +52,13 @@ source_set("audio") {
"//media/base/android",
]
sources = [
+ "aecdump_recording_manager.cc",
+ "aecdump_recording_manager.h",
"agc_audio_stream.h",
"alive_checker.cc",
"alive_checker.h",
+ "audio_bus_pool.cc",
+ "audio_bus_pool.h",
"audio_debug_file_writer.cc",
"audio_debug_file_writer.h",
"audio_debug_recording_helper.cc",
@@ -208,6 +212,13 @@ source_set("audio") {
"win/waveout_output_win.h",
]
+ if (enable_platform_dts_audio) {
+ sources += [
+ "win/audio_edid_scan_win.cc",
+ "win/audio_edid_scan_win.h",
+ ]
+ }
+
deps += [ "//media/base/win:media_foundation_util" ]
libs += [
@@ -358,6 +369,8 @@ static_library("test_support") {
"audio_system_test_util.h",
"audio_unittest_util.cc",
"audio_unittest_util.h",
+ "mock_aecdump_recording_manager.cc",
+ "mock_aecdump_recording_manager.h",
"mock_audio_debug_recording_manager.cc",
"mock_audio_debug_recording_manager.h",
"mock_audio_manager.cc",
@@ -394,7 +407,9 @@ static_library("test_support") {
source_set("unit_tests") {
testonly = true
sources = [
+ "aecdump_recording_manager_unittest.cc",
"alive_checker_unittest.cc",
+ "audio_bus_pool_unittest.cc",
"audio_debug_file_writer_unittest.cc",
"audio_debug_recording_helper_unittest.cc",
"audio_debug_recording_manager_unittest.cc",
@@ -455,11 +470,7 @@ source_set("unit_tests") {
]
if (use_cras) {
- sources += [
- "cras/audio_manager_chromeos_unittest.cc",
- "cras/cras_input_unittest.cc",
- "cras/cras_unified_unittest.cc",
- ]
+ sources += [ "cras/audio_manager_chromeos_unittest.cc" ]
}
}
@@ -467,6 +478,14 @@ source_set("unit_tests") {
sources += [ "cras/audio_manager_cras_unittest.cc" ]
}
+ if (use_cras) {
+ sources += [
+ "cras/audio_manager_cras_base_unittest.cc",
+ "cras/cras_input_unittest.cc",
+ "cras/cras_unified_unittest.cc",
+ ]
+ }
+
if (is_win) {
sources += [
"win/audio_device_listener_win_unittest.cc",
diff --git a/chromium/media/audio/aecdump_recording_manager.cc b/chromium/media/audio/aecdump_recording_manager.cc
new file mode 100644
index 00000000000..8c4fb1754cf
--- /dev/null
+++ b/chromium/media/audio/aecdump_recording_manager.cc
@@ -0,0 +1,125 @@
+// Copyright 2022 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/audio/aecdump_recording_manager.h"
+
+#include "base/bind.h"
+#include "base/task/single_thread_task_runner.h"
+#include "base/task/thread_pool.h"
+#include "media/audio/audio_manager.h"
+
+namespace media {
+namespace {
+void CloseFileWithoutBlocking(base::File file) {
+ // Post as a low-priority task to a thread pool to avoid blocking the
+ // current thread.
+ base::ThreadPool::PostTask(
+ FROM_HERE, {base::TaskPriority::LOWEST, base::MayBlock()},
+ base::BindOnce([](base::File) {}, std::move(file)));
+}
+} // namespace
+
+AecdumpRecordingManager::AecdumpRecordingManager(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner)
+ : task_runner_(std::move(task_runner)) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+}
+
+AecdumpRecordingManager::~AecdumpRecordingManager() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK_EQ(aecdump_recording_sources_.size(), 0u);
+ DCHECK(!IsDebugRecordingEnabled());
+}
+
+void AecdumpRecordingManager::EnableDebugRecording(
+ CreateFileCallback create_file_callback) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK(create_file_callback);
+ DCHECK(!create_file_callback_);
+ create_file_callback_ = std::move(create_file_callback);
+
+ for (const auto& it : aecdump_recording_sources_) {
+ AecdumpRecordingSource* source = it.first;
+ uint32_t id = it.second;
+ create_file_callback_.Run(
+ id, /*reply_callback=*/base::BindOnce(
+ &StartRecordingIfValidPointer, weak_factory_.GetWeakPtr(), source));
+ }
+}
+
+void AecdumpRecordingManager::StartRecording(AecdumpRecordingSource* source,
+ base::File file) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK(IsDebugRecordingEnabled());
+
+ if (aecdump_recording_sources_.find(source) !=
+ aecdump_recording_sources_.end()) {
+ source->StartAecdump(std::move(file));
+ return;
+ }
+
+ // The source is deregistered and we are responsible for closing the file.
+ CloseFileWithoutBlocking(std::move(file));
+}
+
+void AecdumpRecordingManager::DisableDebugRecording() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK(create_file_callback_);
+ for (const auto& it : aecdump_recording_sources_) {
+ AecdumpRecordingSource* source = it.first;
+ source->StopAecdump();
+ }
+ create_file_callback_.Reset();
+
+ // By invalidating weak pointers, we cancel any recordings in the process of
+ // being started (file creation).
+ weak_factory_.InvalidateWeakPtrs();
+}
+
+void AecdumpRecordingManager::RegisterAecdumpSource(
+ AecdumpRecordingSource* source) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK(aecdump_recording_sources_.find(source) ==
+ aecdump_recording_sources_.end());
+
+ const uint32_t id = recording_id_counter_++;
+
+ if (IsDebugRecordingEnabled()) {
+ create_file_callback_.Run(id, /*reply_callback=*/base::BindOnce(
+ &AecdumpRecordingManager::StartRecording,
+ weak_factory_.GetWeakPtr(), source));
+ }
+ aecdump_recording_sources_[source] = id;
+}
+
+void AecdumpRecordingManager::DeregisterAecdumpSource(
+ AecdumpRecordingSource* source) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK(aecdump_recording_sources_.find(source) !=
+ aecdump_recording_sources_.end());
+
+ if (IsDebugRecordingEnabled()) {
+ source->StopAecdump();
+ }
+ aecdump_recording_sources_.erase(source);
+}
+
+bool AecdumpRecordingManager::IsDebugRecordingEnabled() const {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ return !create_file_callback_.is_null();
+}
+
+// static
+void AecdumpRecordingManager::StartRecordingIfValidPointer(
+ base::WeakPtr<AecdumpRecordingManager> manager,
+ AecdumpRecordingSource* source,
+ base::File file) {
+ if (manager) {
+ manager->StartRecording(source, std::move(file));
+ return;
+ }
+ // Recording has been stopped and we are responsible for closing the file.
+ CloseFileWithoutBlocking(std::move(file));
+}
+} // namespace media
diff --git a/chromium/media/audio/aecdump_recording_manager.h b/chromium/media/audio/aecdump_recording_manager.h
new file mode 100644
index 00000000000..8a7b1034a9e
--- /dev/null
+++ b/chromium/media/audio/aecdump_recording_manager.h
@@ -0,0 +1,96 @@
+// Copyright 2022 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_AUDIO_AECDUMP_RECORDING_MANAGER_H_
+#define MEDIA_AUDIO_AECDUMP_RECORDING_MANAGER_H_
+
+#include <map>
+
+#include "base/callback.h"
+#include "base/files/file.h"
+#include "base/memory/weak_ptr.h"
+#include "media/base/media_export.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+}
+
+namespace media {
+
+class AecdumpRecordingSource {
+ public:
+ // Starts recording an aecdump to |aecdump_file|. If a recording is already
+ // ongoing, then that recording is stopped and and a new recording is started
+ // to |aecdump_file|.
+ virtual void StartAecdump(base::File aecdump_file) = 0;
+
+ // Stops recording an aecdump and closes the file. Does nothing if no
+ // recording is ongoing.
+ virtual void StopAecdump() = 0;
+};
+
+// Manages diagnostic audio processing recordings (so-called aecdumps).
+// Aecdump recording sources implement the AecdumpRecordingSource interface and
+// register/deregister with the AecdumpRecordingManager.
+// All operations, including creation and destruction, must happen on the same
+// thread as the |task_runner| provided in the constructor.
+class MEDIA_EXPORT AecdumpRecordingManager
+ : public base::SupportsWeakPtr<AecdumpRecordingManager> {
+ public:
+ using CreateFileCallback = base::RepeatingCallback<
+ void(uint32_t id, base::OnceCallback<void(base::File)> reply_callback)>;
+
+ explicit AecdumpRecordingManager(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner);
+
+ AecdumpRecordingManager(const AecdumpRecordingManager&) = delete;
+ AecdumpRecordingManager& operator=(const AecdumpRecordingManager&) = delete;
+
+ virtual ~AecdumpRecordingManager();
+
+ // Starts and stops aecdump recording. Overridden by tests.
+ virtual void EnableDebugRecording(CreateFileCallback create_file_callback);
+ virtual void DisableDebugRecording();
+
+ // Registers an aecdump recording source. Overridden by tests.
+ virtual void RegisterAecdumpSource(AecdumpRecordingSource* source);
+ // Registers an aecdump recording source. If aecdump recording is currently
+ // enabled, then StopAecdump will be called on the source. Overridden by
+ // tests.
+ virtual void DeregisterAecdumpSource(AecdumpRecordingSource* source);
+
+ private:
+ // Forwards to StartRecording() if |manager| is valid, otherwise closes |file|
+ // without blocking the thread.
+ static void StartRecordingIfValidPointer(
+ base::WeakPtr<AecdumpRecordingManager> manager,
+ AecdumpRecordingSource* source,
+ base::File file);
+
+ // Used as callback for |create_file_callback_|, to ensure the recording
+ // source has not been deregistered during file creation.
+ void StartRecording(AecdumpRecordingSource* source, base::File file);
+
+ bool IsDebugRecordingEnabled() const;
+
+ // Counter for recording source IDs.
+ uint32_t recording_id_counter_ = 1;
+
+ // The task runner this class lives on. Also used for file creation callbacks.
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ // Recorders, one per source. Maps pointer to source id.
+ std::map<AecdumpRecordingSource*, uint32_t> aecdump_recording_sources_;
+
+ // Callback for creating aecdump files. When this is not null, debug
+ // recording is enabled.
+ CreateFileCallback create_file_callback_;
+
+ // For managing debug recording cycles.
+ base::WeakPtrFactory<AecdumpRecordingManager> weak_factory_{this};
+};
+
+} // namespace media
+
+#endif // MEDIA_AUDIO_AECDUMP_RECORDING_MANAGER_H_
diff --git a/chromium/media/audio/aecdump_recording_manager_unittest.cc b/chromium/media/audio/aecdump_recording_manager_unittest.cc
new file mode 100644
index 00000000000..87bb29fd65f
--- /dev/null
+++ b/chromium/media/audio/aecdump_recording_manager_unittest.cc
@@ -0,0 +1,238 @@
+// Copyright 2022 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/audio/aecdump_recording_manager.h"
+
+#include "base/bind.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/test/task_environment.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::_;
+using testing::InSequence;
+using testing::NiceMock;
+using testing::Sequence;
+
+namespace media {
+namespace {
+
+class MockAecdumpRecordingSource : public AecdumpRecordingSource {
+ public:
+ MOCK_METHOD1(StartAecdump, void(base::File));
+ MOCK_METHOD0(StopAecdump, void());
+};
+
+class AecdumpRecordingManagerTest : public ::testing::Test {
+ public:
+ AecdumpRecordingManagerTest()
+ : manager_(std::make_unique<AecdumpRecordingManager>(
+ task_environment_.GetMainThreadTaskRunner())),
+ create_file_callback_(base::BindRepeating(
+ &AecdumpRecordingManagerTest::AsyncCreateFileCallback,
+ base::Unretained(this))) {}
+
+ void SetUp() override { ASSERT_TRUE(temp_directory_.CreateUniqueTempDir()); }
+
+ protected:
+ // Simulates async file creation by posting the reply to the main thread.
+ void AsyncCreateFileCallback(
+ uint32_t /*id*/,
+ base::OnceCallback<void(base::File)> reply_callback) {
+ base::FilePath temp_file_path;
+ base::File file = base::CreateAndOpenTemporaryFileInDir(
+ temp_directory_.GetPath(), &temp_file_path);
+ ASSERT_TRUE(file.IsValid());
+ task_environment_.GetMainThreadTaskRunner()->PostTask(
+ FROM_HERE, base::BindOnce(std::move(reply_callback), std::move(file)));
+ }
+
+ base::test::TaskEnvironment task_environment_;
+ std::unique_ptr<AecdumpRecordingManager> manager_;
+ AecdumpRecordingManager::CreateFileCallback create_file_callback_;
+ base::ScopedTempDir temp_directory_;
+};
+
+TEST_F(AecdumpRecordingManagerTest, EnableDisableDoesNotCrash) {
+ manager_->EnableDebugRecording(create_file_callback_);
+ manager_->DisableDebugRecording();
+}
+
+TEST_F(AecdumpRecordingManagerTest,
+ EnableDisableWithOneSourceStartsStopsSource) {
+ MockAecdumpRecordingSource mock_source;
+ InSequence s;
+ EXPECT_CALL(mock_source, StartAecdump(_)).Times(1);
+ EXPECT_CALL(mock_source, StopAecdump()).Times(1);
+
+ manager_->RegisterAecdumpSource(&mock_source);
+
+ manager_->EnableDebugRecording(create_file_callback_);
+ base::RunLoop().RunUntilIdle();
+
+ manager_->DisableDebugRecording();
+
+ manager_->DeregisterAecdumpSource(&mock_source);
+}
+
+TEST_F(AecdumpRecordingManagerTest,
+ EnableDisableWithTwoSourcesStartsStopsSources) {
+ MockAecdumpRecordingSource mock_source_a;
+ MockAecdumpRecordingSource mock_source_b;
+ Sequence s1;
+ Sequence s2;
+ EXPECT_CALL(mock_source_a, StartAecdump(_)).Times(1).InSequence(s1);
+ EXPECT_CALL(mock_source_a, StopAecdump()).Times(1).InSequence(s1);
+ EXPECT_CALL(mock_source_b, StartAecdump(_)).Times(1).InSequence(s2);
+ EXPECT_CALL(mock_source_b, StopAecdump()).Times(1).InSequence(s2);
+
+ manager_->RegisterAecdumpSource(&mock_source_a);
+ manager_->RegisterAecdumpSource(&mock_source_b);
+
+ manager_->EnableDebugRecording(create_file_callback_);
+ base::RunLoop().RunUntilIdle();
+
+ manager_->DisableDebugRecording();
+
+ manager_->DeregisterAecdumpSource(&mock_source_a);
+ manager_->DeregisterAecdumpSource(&mock_source_b);
+}
+
+TEST_F(AecdumpRecordingManagerTest,
+ RegisterDeregisterSourceBeforeEnableDisableDoesNotStartStopSource) {
+ MockAecdumpRecordingSource mock_source;
+ EXPECT_CALL(mock_source, StartAecdump(_)).Times(0);
+ EXPECT_CALL(mock_source, StopAecdump()).Times(0);
+
+ manager_->RegisterAecdumpSource(&mock_source);
+ manager_->DeregisterAecdumpSource(&mock_source);
+
+ // Enabling debug recordings should not trigger any calls to the recording
+ // source.
+ manager_->EnableDebugRecording(create_file_callback_);
+ base::RunLoop().RunUntilIdle();
+ manager_->DisableDebugRecording();
+}
+
+TEST_F(AecdumpRecordingManagerTest,
+ RegisterDeregisterSourceAfterEnableDisableDoesNotStartStopSource) {
+ MockAecdumpRecordingSource mock_source;
+ EXPECT_CALL(mock_source, StartAecdump(_)).Times(0);
+ EXPECT_CALL(mock_source, StopAecdump()).Times(0);
+
+ // Enabling debug recordings should not trigger any calls to the recording
+ // source.
+ manager_->EnableDebugRecording(create_file_callback_);
+ manager_->DisableDebugRecording();
+
+ manager_->RegisterAecdumpSource(&mock_source);
+ base::RunLoop().RunUntilIdle();
+ manager_->DeregisterAecdumpSource(&mock_source);
+}
+
+TEST_F(AecdumpRecordingManagerTest,
+ RegisterDeregisterSourceDuringRecordingStartsStopsSource) {
+ InSequence s;
+ MockAecdumpRecordingSource mock_source;
+ EXPECT_CALL(mock_source, StartAecdump(_)).Times(1);
+ EXPECT_CALL(mock_source, StopAecdump()).Times(1);
+
+ manager_->EnableDebugRecording(create_file_callback_);
+
+ manager_->RegisterAecdumpSource(&mock_source);
+ base::RunLoop().RunUntilIdle();
+
+ manager_->DeregisterAecdumpSource(&mock_source);
+ ::testing::Mock::VerifyAndClearExpectations(&mock_source);
+
+ manager_->DisableDebugRecording();
+}
+
+TEST_F(AecdumpRecordingManagerTest,
+ DeregisterSourceBeforeFileCreationCallbackDoesNotStartSource) {
+ NiceMock<MockAecdumpRecordingSource> mock_source;
+ EXPECT_CALL(mock_source, StartAecdump(_)).Times(0);
+
+ manager_->RegisterAecdumpSource(&mock_source);
+
+ // Enabling debug recordings schedules a StartAecdump() call to the recording
+ // source.
+ manager_->EnableDebugRecording(create_file_callback_);
+
+ // Deregister the source before StartAecdump() can be called.
+ manager_->DeregisterAecdumpSource(&mock_source);
+
+ // Run the file creation callback. Aecdumps should not be started.
+ base::RunLoop().RunUntilIdle();
+
+ manager_->DisableDebugRecording();
+}
+
+TEST_F(AecdumpRecordingManagerTest,
+ StopRecordingBeforeFileCreationCallbackDoesNotStartSource) {
+ NiceMock<MockAecdumpRecordingSource> mock_source;
+ EXPECT_CALL(mock_source, StartAecdump(_)).Times(0);
+
+ manager_->RegisterAecdumpSource(&mock_source);
+
+ // Enabling debug recordings schedules a StartAecdump() call to the recording
+ // source.
+ manager_->EnableDebugRecording(create_file_callback_);
+
+ // Stop aecdump recording before StartAecdump() can be called.
+ manager_->DisableDebugRecording();
+
+ // Run the file creation callback. Aecdumps should not be started.
+ base::RunLoop().RunUntilIdle();
+
+ // Clean up.
+ manager_->DeregisterAecdumpSource(&mock_source);
+}
+
+TEST_F(AecdumpRecordingManagerTest,
+ RestartRecordingBeforeFileCreationCallbackDoesNotStartSourceTwice) {
+ NiceMock<MockAecdumpRecordingSource> mock_source;
+ EXPECT_CALL(mock_source, StartAecdump(_)).Times(1);
+
+ manager_->RegisterAecdumpSource(&mock_source);
+
+ // Enabling debug recordings schedules a StartAecdump() call to the recording
+ // source.
+ manager_->EnableDebugRecording(create_file_callback_);
+
+ // Restart aecdump recording before StartAecdump() can be called.
+ manager_->DisableDebugRecording();
+ manager_->EnableDebugRecording(create_file_callback_);
+
+ // Run the file creation callback. The first file created should be discarded,
+ // we expect only one StartAecdump() call.
+ base::RunLoop().RunUntilIdle();
+
+ // Clean up.
+ manager_->DeregisterAecdumpSource(&mock_source);
+ manager_->DisableDebugRecording();
+}
+
+TEST_F(AecdumpRecordingManagerTest,
+ DestroyManagerBeforeFileCreationCallbackDoesNotCrash) {
+ NiceMock<MockAecdumpRecordingSource> mock_source;
+ manager_->RegisterAecdumpSource(&mock_source);
+
+ // Enabling debug recordings schedules a StartAecdump() call to the recording
+ // source.
+ manager_->EnableDebugRecording(create_file_callback_);
+
+ // Destroy the AecdumpRecordingManager before StartAecdump() can be called.
+ manager_->DeregisterAecdumpSource(&mock_source);
+ manager_->DisableDebugRecording();
+ manager_.reset();
+
+ // Run the file creation callback. Aecdumps should not be started.
+ base::RunLoop().RunUntilIdle();
+}
+
+} // namespace
+} // namespace media
diff --git a/chromium/media/audio/agc_audio_stream.h b/chromium/media/audio/agc_audio_stream.h
index a14a9817077..bf1daea8a3e 100644
--- a/chromium/media/audio/agc_audio_stream.h
+++ b/chromium/media/audio/agc_audio_stream.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/alive_checker.cc b/chromium/media/audio/alive_checker.cc
index 8ca4e936c37..aede67fd4af 100644
--- a/chromium/media/audio/alive_checker.cc
+++ b/chromium/media/audio/alive_checker.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/alive_checker.h b/chromium/media/audio/alive_checker.h
index b95c9fecba7..818fe7e8fcc 100644
--- a/chromium/media/audio/alive_checker.h
+++ b/chromium/media/audio/alive_checker.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/alive_checker_unittest.cc b/chromium/media/audio/alive_checker_unittest.cc
index 556d3da3b24..567198e267f 100644
--- a/chromium/media/audio/alive_checker_unittest.cc
+++ b/chromium/media/audio/alive_checker_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/alsa/alsa_input.cc b/chromium/media/audio/alsa/alsa_input.cc
index 1698c0c3411..ad334630141 100644
--- a/chromium/media/audio/alsa/alsa_input.cc
+++ b/chromium/media/audio/alsa/alsa_input.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/alsa/alsa_input.h b/chromium/media/audio/alsa/alsa_input.h
index 591c4ce564c..c24a48c0c80 100644
--- a/chromium/media/audio/alsa/alsa_input.h
+++ b/chromium/media/audio/alsa/alsa_input.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/alsa/alsa_output.cc b/chromium/media/audio/alsa/alsa_output.cc
index 46fe698f63b..ba9134bccee 100644
--- a/chromium/media/audio/alsa/alsa_output.cc
+++ b/chromium/media/audio/alsa/alsa_output.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
diff --git a/chromium/media/audio/alsa/alsa_output.h b/chromium/media/audio/alsa/alsa_output.h
index c674c5c506c..c2ecac8151b 100644
--- a/chromium/media/audio/alsa/alsa_output.h
+++ b/chromium/media/audio/alsa/alsa_output.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
diff --git a/chromium/media/audio/alsa/alsa_output_unittest.cc b/chromium/media/audio/alsa/alsa_output_unittest.cc
index 3560767d361..90d2eb02c0c 100644
--- a/chromium/media/audio/alsa/alsa_output_unittest.cc
+++ b/chromium/media/audio/alsa/alsa_output_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -20,6 +20,7 @@
#include "media/audio/mock_audio_source_callback.h"
#include "media/audio/test_audio_thread.h"
#include "media/base/audio_timestamp_helper.h"
+#include "media/base/channel_layout.h"
#include "media/base/data_buffer.h"
#include "media/base/seekable_buffer.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -94,8 +95,10 @@ class AlsaPcmOutputStreamTest : public testing::Test {
AlsaPcmOutputStream* CreateStream(ChannelLayout layout,
int32_t samples_per_packet) {
- AudioParameters params(kTestFormat, layout, kTestSampleRate,
- samples_per_packet);
+ AudioParameters params(
+ kTestFormat,
+ ChannelLayoutConfig(layout, ChannelLayoutToChannelCount(layout)),
+ kTestSampleRate, samples_per_packet);
return new AlsaPcmOutputStream(kTestDeviceName,
params,
&mock_alsa_wrapper_,
diff --git a/chromium/media/audio/alsa/alsa_util.cc b/chromium/media/audio/alsa/alsa_util.cc
index 84b4133507f..821a750f4ea 100644
--- a/chromium/media/audio/alsa/alsa_util.cc
+++ b/chromium/media/audio/alsa/alsa_util.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/alsa/alsa_util.h b/chromium/media/audio/alsa/alsa_util.h
index 47b5d1b6594..a3855a4f781 100644
--- a/chromium/media/audio/alsa/alsa_util.h
+++ b/chromium/media/audio/alsa/alsa_util.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/alsa/alsa_util_unittest.cc b/chromium/media/audio/alsa/alsa_util_unittest.cc
index 343730dc07b..da6bfc85789 100644
--- a/chromium/media/audio/alsa/alsa_util_unittest.cc
+++ b/chromium/media/audio/alsa/alsa_util_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/alsa/alsa_wrapper.cc b/chromium/media/audio/alsa/alsa_wrapper.cc
index 83493271cbd..abcaa88a634 100644
--- a/chromium/media/audio/alsa/alsa_wrapper.cc
+++ b/chromium/media/audio/alsa/alsa_wrapper.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/alsa/alsa_wrapper.h b/chromium/media/audio/alsa/alsa_wrapper.h
index 29653beede9..94a401f93fb 100644
--- a/chromium/media/audio/alsa/alsa_wrapper.h
+++ b/chromium/media/audio/alsa/alsa_wrapper.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
diff --git a/chromium/media/audio/alsa/audio_manager_alsa.cc b/chromium/media/audio/alsa/audio_manager_alsa.cc
index 19d69a0197c..af69ccd4c82 100644
--- a/chromium/media/audio/alsa/audio_manager_alsa.cc
+++ b/chromium/media/audio/alsa/audio_manager_alsa.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -73,7 +73,7 @@ AudioParameters AudioManagerAlsa::GetInputStreamParameters(
static const int kDefaultInputBufferSize = 1024;
return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_STEREO, kDefaultSampleRate,
+ ChannelLayoutConfig::Stereo(), kDefaultSampleRate,
kDefaultInputBufferSize);
}
@@ -272,7 +272,7 @@ AudioParameters AudioManagerAlsa::GetPreferredOutputStreamParameters(
// TODO(tommi): Support |output_device_id|.
DLOG_IF(ERROR, !output_device_id.empty()) << "Not implemented!";
static const int kDefaultOutputBufferSize = 2048;
- ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
+ ChannelLayoutConfig channel_layout_config = ChannelLayoutConfig::Stereo();
int sample_rate = kDefaultSampleRate;
int buffer_size = kDefaultOutputBufferSize;
if (input_params.IsValid()) {
@@ -282,7 +282,7 @@ AudioParameters AudioManagerAlsa::GetPreferredOutputStreamParameters(
// TODO(dalecurtis): This should include bits per channel and channel layout
// eventually.
sample_rate = input_params.sample_rate();
- channel_layout = input_params.channel_layout();
+ channel_layout_config = input_params.channel_layout_config();
buffer_size = std::min(input_params.frames_per_buffer(), buffer_size);
}
@@ -290,8 +290,8 @@ AudioParameters AudioManagerAlsa::GetPreferredOutputStreamParameters(
if (user_buffer_size)
buffer_size = user_buffer_size;
- return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
- sample_rate, buffer_size);
+ return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
+ channel_layout_config, sample_rate, buffer_size);
}
AudioOutputStream* AudioManagerAlsa::MakeOutputStream(
diff --git a/chromium/media/audio/alsa/audio_manager_alsa.h b/chromium/media/audio/alsa/audio_manager_alsa.h
index f6897b41705..04cd9cc1c34 100644
--- a/chromium/media/audio/alsa/audio_manager_alsa.h
+++ b/chromium/media/audio/alsa/audio_manager_alsa.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/alsa/mock_alsa_wrapper.cc b/chromium/media/audio/alsa/mock_alsa_wrapper.cc
index fdb9573a85a..f6332f5fa5b 100644
--- a/chromium/media/audio/alsa/mock_alsa_wrapper.cc
+++ b/chromium/media/audio/alsa/mock_alsa_wrapper.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/alsa/mock_alsa_wrapper.h b/chromium/media/audio/alsa/mock_alsa_wrapper.h
index 827a17137bd..4f2c948750e 100644
--- a/chromium/media/audio/alsa/mock_alsa_wrapper.h
+++ b/chromium/media/audio/alsa/mock_alsa_wrapper.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/android/aaudio.sigs b/chromium/media/audio/android/aaudio.sigs
index 1d89b56d675..7e64d58ebf6 100644
--- a/chromium/media/audio/android/aaudio.sigs
+++ b/chromium/media/audio/android/aaudio.sigs
@@ -1,4 +1,4 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
+// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/android/aaudio_output.cc b/chromium/media/audio/android/aaudio_output.cc
index 261bb6b0c4a..3210e423ab5 100644
--- a/chromium/media/audio/android/aaudio_output.cc
+++ b/chromium/media/audio/android/aaudio_output.cc
@@ -1,4 +1,4 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
+// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/android/aaudio_output.h b/chromium/media/audio/android/aaudio_output.h
index 261c0920a00..0ed311de1af 100644
--- a/chromium/media/audio/android/aaudio_output.h
+++ b/chromium/media/audio/android/aaudio_output.h
@@ -1,4 +1,4 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
+// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/android/audio_android_unittest.cc b/chromium/media/audio/android/audio_android_unittest.cc
index 0e5434da59f..1e8dde8abfb 100644
--- a/chromium/media/audio/android/audio_android_unittest.cc
+++ b/chromium/media/audio/android/audio_android_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -827,7 +827,7 @@ TEST_F(AudioAndroidOutputTest,
DISABLED_StartOutputStreamCallbacksNonDefaultParameters) {
GetDefaultOutputStreamParametersOnAudioThread();
AudioParameters params(audio_output_parameters().format(),
- CHANNEL_LAYOUT_MONO,
+ ChannelLayoutConfig::Mono(),
audio_output_parameters().sample_rate(),
audio_output_parameters().sample_rate() / 100);
StartOutputStreamCallbacks(params);
diff --git a/chromium/media/audio/android/audio_manager_android.cc b/chromium/media/audio/android/audio_manager_android.cc
index 1547f62de50..b2f3d2bc6c1 100644
--- a/chromium/media/audio/android/audio_manager_android.cc
+++ b/chromium/media/audio/android/audio_manager_android.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -172,7 +172,7 @@ AudioParameters AudioManagerAndroid::GetInputStreamParameters(
// resources. Using mono also avoids a driver issue seen on Samsung
// Galaxy S3 and S4 devices. See http://crbug.com/256851 for details.
JNIEnv* env = AttachCurrentThread();
- ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO;
+ constexpr ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO;
int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize(
env, GetNativeOutputSampleRate(),
ChannelLayoutToChannelCount(channel_layout));
@@ -186,7 +186,8 @@ AudioParameters AudioManagerAndroid::GetInputStreamParameters(
if (user_buffer_size)
buffer_size = user_buffer_size;
- AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
+ AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY,
+ ChannelLayoutConfig::FromLayout<channel_layout>(),
GetNativeOutputSampleRate(), buffer_size);
params.set_effects(effects);
DVLOG(1) << params.AsHumanReadableString();
@@ -365,7 +366,7 @@ AudioParameters AudioManagerAndroid::GetPreferredOutputStreamParameters(
// TODO(tommi): Support |output_device_id|.
DCHECK(GetTaskRunner()->BelongsToCurrentThread());
DLOG_IF(ERROR, !output_device_id.empty()) << "Not implemented!";
- ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
+ ChannelLayoutConfig channel_layout_config = ChannelLayoutConfig::Stereo();
int sample_rate = GetNativeOutputSampleRate();
int buffer_size = GetOptimalOutputFrameSize(sample_rate, 2);
if (input_params.IsValid()) {
@@ -375,7 +376,7 @@ AudioParameters AudioManagerAndroid::GetPreferredOutputStreamParameters(
// AudioManager APIs for GetOptimalOutputFrameSize() don't support channel
// layouts greater than stereo unless low latency audio is supported.
if (input_params.channels() <= 2 || IsAudioLowLatencySupported())
- channel_layout = input_params.channel_layout();
+ channel_layout_config = input_params.channel_layout_config();
// For high latency playback on supported platforms, pass through the
// requested buffer size; this provides significant power savings (~25%) and
@@ -384,8 +385,8 @@ AudioParameters AudioManagerAndroid::GetPreferredOutputStreamParameters(
input_params.latency_tag() == AudioLatency::LATENCY_PLAYBACK) {
buffer_size = input_params.frames_per_buffer();
} else {
- buffer_size = GetOptimalOutputFrameSize(
- sample_rate, ChannelLayoutToChannelCount(channel_layout));
+ buffer_size = GetOptimalOutputFrameSize(sample_rate,
+ channel_layout_config.channels());
}
}
@@ -396,11 +397,11 @@ AudioParameters AudioManagerAndroid::GetPreferredOutputStreamParameters(
// Check if device supports additional audio encodings.
if (IsAudioSinkConnected()) {
return GetAudioFormatsSupportedBySinkDevice(
- output_device_id, channel_layout, sample_rate, buffer_size);
+ output_device_id, channel_layout_config, sample_rate, buffer_size);
}
- return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
- sample_rate, buffer_size);
+ return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
+ channel_layout_config, sample_rate, buffer_size);
}
bool AudioManagerAndroid::HasNoAudioInputStreams() {
@@ -482,16 +483,18 @@ int AudioManagerAndroid::GetSinkAudioEncodingFormats() {
// AudioParameters structure.
AudioParameters AudioManagerAndroid::GetAudioFormatsSupportedBySinkDevice(
const std::string& output_device_id,
- ChannelLayout channel_layout,
+ const ChannelLayoutConfig& channel_layout_config,
int sample_rate,
int buffer_size) {
int formats = GetSinkAudioEncodingFormats();
DVLOG(1) << __func__ << ": IsAudioSinkConnected()==true, output_device_id="
<< output_device_id << ", Supported Encodings=" << formats;
- return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
- sample_rate, buffer_size,
- AudioParameters::HardwareCapabilities(formats));
+ return AudioParameters(
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout_config,
+ sample_rate, buffer_size,
+ AudioParameters::HardwareCapabilities(formats,
+ /*require_encapsulation=*/false));
}
void AudioManagerAndroid::DoSetMuteOnAudioThread(bool muted) {
diff --git a/chromium/media/audio/android/audio_manager_android.h b/chromium/media/audio/android/audio_manager_android.h
index 5c97aff3f7b..5beddd6e675 100644
--- a/chromium/media/audio/android/audio_manager_android.h
+++ b/chromium/media/audio/android/audio_manager_android.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -112,7 +112,7 @@ class MEDIA_EXPORT AudioManagerAndroid : public AudioManagerBase {
int GetOptimalOutputFrameSize(int sample_rate, int channels);
AudioParameters GetAudioFormatsSupportedBySinkDevice(
const std::string& output_device_id,
- ChannelLayout channel_layout,
+ const ChannelLayoutConfig& channel_layout_config,
int sample_rate,
int buffer_size);
diff --git a/chromium/media/audio/android/audio_track_output_stream.cc b/chromium/media/audio/android/audio_track_output_stream.cc
index 0b7b11b94cf..21897c24f04 100644
--- a/chromium/media/audio/android/audio_track_output_stream.cc
+++ b/chromium/media/audio/android/audio_track_output_stream.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -64,6 +64,7 @@ bool AudioTrackOutputStream::Open() {
format = kEncodingDts;
break;
case AudioParameters::AUDIO_BITSTREAM_DTS_HD:
+ case AudioParameters::AUDIO_BITSTREAM_DTS_HD_MA:
format = kEncodingDtshd;
break;
case AudioParameters::AUDIO_BITSTREAM_IEC61937:
diff --git a/chromium/media/audio/android/audio_track_output_stream.h b/chromium/media/audio/android/audio_track_output_stream.h
index 3936b7d5d5e..74a6fb74db2 100644
--- a/chromium/media/audio/android/audio_track_output_stream.h
+++ b/chromium/media/audio/android/audio_track_output_stream.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/android/muteable_audio_output_stream.h b/chromium/media/audio/android/muteable_audio_output_stream.h
index db4f6b19cb5..b31d2865754 100644
--- a/chromium/media/audio/android/muteable_audio_output_stream.h
+++ b/chromium/media/audio/android/muteable_audio_output_stream.h
@@ -1,4 +1,4 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/android/opensles_input.cc b/chromium/media/audio/android/opensles_input.cc
index 800ac877b2c..dbe950b1a7c 100644
--- a/chromium/media/audio/android/opensles_input.cc
+++ b/chromium/media/audio/android/opensles_input.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/android/opensles_input.h b/chromium/media/audio/android/opensles_input.h
index ddad9837d49..f3d63569dc1 100644
--- a/chromium/media/audio/android/opensles_input.h
+++ b/chromium/media/audio/android/opensles_input.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/android/opensles_output.cc b/chromium/media/audio/android/opensles_output.cc
index 1218e4b26a6..d7c9f4f13a5 100644
--- a/chromium/media/audio/android/opensles_output.cc
+++ b/chromium/media/audio/android/opensles_output.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/android/opensles_output.h b/chromium/media/audio/android/opensles_output.h
index c7b927397ef..865911d9523 100644
--- a/chromium/media/audio/android/opensles_output.h
+++ b/chromium/media/audio/android/opensles_output.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/android/opensles_util.cc b/chromium/media/audio/android/opensles_util.cc
index 128a3bd20d2..aee6bd89839 100644
--- a/chromium/media/audio/android/opensles_util.cc
+++ b/chromium/media/audio/android/opensles_util.cc
@@ -1,4 +1,4 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/android/opensles_util.h b/chromium/media/audio/android/opensles_util.h
index 2e8d27055bf..37fdf94d406 100644
--- a/chromium/media/audio/android/opensles_util.h
+++ b/chromium/media/audio/android/opensles_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/android/opensles_wrapper.cc b/chromium/media/audio/android/opensles_wrapper.cc
index ca0385555d6..41746ffd712 100644
--- a/chromium/media/audio/android/opensles_wrapper.cc
+++ b/chromium/media/audio/android/opensles_wrapper.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_bus_pool.cc b/chromium/media/audio/audio_bus_pool.cc
new file mode 100644
index 00000000000..6cbf3a5c57e
--- /dev/null
+++ b/chromium/media/audio/audio_bus_pool.cc
@@ -0,0 +1,60 @@
+// Copyright 2022 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/audio/audio_bus_pool.h"
+#include <memory>
+#include "base/check_op.h"
+#include "base/functional/bind.h"
+#include "base/synchronization/lock.h"
+#include "media/base/audio_bus.h"
+#include "media/base/audio_parameters.h"
+
+namespace media {
+
+AudioBusPoolImpl::AudioBusPoolImpl(const AudioParameters& params,
+ size_t preallocated,
+ size_t max_capacity)
+ : AudioBusPoolImpl(params,
+ preallocated,
+ max_capacity,
+ base::BindRepeating(
+ static_cast<std::unique_ptr<AudioBus> (*)(
+ const AudioParameters&)>(&AudioBus::Create))) {}
+
+AudioBusPoolImpl::~AudioBusPoolImpl() = default;
+
+std::unique_ptr<AudioBus> AudioBusPoolImpl::GetAudioBus() {
+ base::AutoLock auto_lock(lock_);
+ if (!audio_buses_.empty()) {
+ std::unique_ptr<AudioBus> bus = std::move(audio_buses_.top());
+ audio_buses_.pop();
+ return bus;
+ }
+ return create_audio_bus_.Run(params_);
+}
+
+void AudioBusPoolImpl::InsertAudioBus(std::unique_ptr<AudioBus> audio_bus) {
+ CHECK_EQ(audio_bus->channels(), params_.channels());
+ CHECK_EQ(audio_bus->frames(), params_.frames_per_buffer());
+
+ base::AutoLock auto_lock(lock_);
+ if (audio_buses_.size() < max_capacity_) {
+ audio_buses_.push(std::move(audio_bus));
+ }
+}
+
+AudioBusPoolImpl::AudioBusPoolImpl(const AudioParameters& params,
+ size_t preallocated,
+ size_t max_capacity,
+ CreateAudioBusCallback create_audio_bus)
+ : params_(params),
+ max_capacity_(max_capacity),
+ create_audio_bus_(std::move(create_audio_bus)) {
+ DCHECK_GE(max_capacity, preallocated);
+ while (preallocated-- > 0) {
+ audio_buses_.push(create_audio_bus_.Run(params_));
+ }
+}
+
+} // namespace media
diff --git a/chromium/media/audio/audio_bus_pool.h b/chromium/media/audio/audio_bus_pool.h
new file mode 100644
index 00000000000..2439329db8d
--- /dev/null
+++ b/chromium/media/audio/audio_bus_pool.h
@@ -0,0 +1,76 @@
+// Copyright 2022 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_AUDIO_AUDIO_BUS_POOL_H_
+#define MEDIA_AUDIO_AUDIO_BUS_POOL_H_
+
+#include <memory>
+#include <stack>
+
+#include "base/files/file.h"
+#include "base/functional/callback_forward.h"
+#include "base/gtest_prod_util.h"
+#include "base/synchronization/lock.h"
+#include "media/base/audio_bus.h"
+#include "media/base/audio_parameters.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+// Thread-safe interface for reusing AudioBuses.
+class MEDIA_EXPORT AudioBusPool {
+ public:
+ virtual ~AudioBusPool() = default;
+
+ // If there is an AudioBus in the pool, return it. Otherwise, allocate and
+ // return a new AudioBus with the correct number of frames and channels.
+ virtual std::unique_ptr<AudioBus> GetAudioBus() = 0;
+
+ // Inserts an AudioBus to the pool, allowing it to be reused with
+ // GetAudioBus. |audio_bus| needs to have the same number of frames and
+ // channels as was specified when creating the AudioBusPool, or the call will
+ // crash.
+ virtual void InsertAudioBus(std::unique_ptr<AudioBus> audio_bus) = 0;
+};
+
+class MEDIA_EXPORT AudioBusPoolImpl final : public AudioBusPool {
+ public:
+ AudioBusPoolImpl(const AudioParameters& params,
+ size_t preallocated,
+ size_t max_capacity);
+
+ AudioBusPoolImpl(const AudioBusPool&) = delete;
+ AudioBusPoolImpl& operator=(const AudioBusPool&) = delete;
+ ~AudioBusPoolImpl() override;
+
+ std::unique_ptr<AudioBus> GetAudioBus() override;
+
+ void InsertAudioBus(std::unique_ptr<AudioBus> audio_bus) override;
+
+ private:
+ friend class AudioBusPoolTest;
+
+ using CreateAudioBusCallback =
+ base::RepeatingCallback<std::unique_ptr<AudioBus>(
+ const AudioParameters&)>;
+
+ AudioBusPoolImpl(const AudioParameters& params,
+ size_t preallocated,
+ size_t max_capacity,
+ CreateAudioBusCallback create_audio_bus);
+
+ const AudioParameters params_;
+
+ const size_t max_capacity_;
+
+ CreateAudioBusCallback create_audio_bus_;
+
+ std::stack<std::unique_ptr<AudioBus>> audio_buses_ GUARDED_BY(lock_);
+
+ base::Lock lock_;
+};
+
+} // namespace media
+
+#endif // MEDIA_AUDIO_AUDIO_BUS_POOL_H_
diff --git a/chromium/media/audio/audio_bus_pool_unittest.cc b/chromium/media/audio/audio_bus_pool_unittest.cc
new file mode 100644
index 00000000000..e015d9bd89d
--- /dev/null
+++ b/chromium/media/audio/audio_bus_pool_unittest.cc
@@ -0,0 +1,120 @@
+// Copyright 2022 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/audio/audio_bus_pool.h"
+#include <memory>
+#include <utility>
+
+#include "base/check_op.h"
+#include "base/functional/bind.h"
+#include "base/memory/scoped_refptr.h"
+#include "base/test/bind.h"
+#include "media/audio/audio_io.h"
+#include "media/base/audio_bus.h"
+#include "media/base/audio_parameters.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media {
+
+// The test fixture.
+class AudioBusPoolTest : public ::testing::Test {
+ public:
+ AudioBusPoolTest()
+ : params_(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Stereo(),
+ 1000,
+ 100) {}
+
+ AudioBusPoolTest(const AudioBusPoolTest&) = delete;
+ AudioBusPoolTest& operator=(const AudioBusPoolTest&) = delete;
+
+ ~AudioBusPoolTest() override = default;
+
+ MOCK_METHOD0(OnCreateAudioBus, void());
+
+ // Creates an AudioBusPoolImpl and makes OnCreateAudioBus track when it
+ // creates AudioBuses.
+ void CreateAndTrackAudioBusPool(size_t preallocated, size_t max_capacity) {
+ audio_bus_pool_.reset(new AudioBusPoolImpl(
+ params_, preallocated, max_capacity,
+ base::BindLambdaForTesting([&](const AudioParameters& params) {
+ EXPECT_TRUE(params.Equals(params_));
+ OnCreateAudioBus();
+ return AudioBus::Create(params);
+ })));
+ }
+
+ protected:
+ const AudioParameters params_;
+
+ std::unique_ptr<AudioBusPool> audio_bus_pool_;
+};
+
+TEST_F(AudioBusPoolTest, PublicConstructor) {
+ // The other tests use a specialized callback to create AudioBuses which also
+ // tracks when it's called. We need to check that the default callback also
+ // creates correct AudioBuses.
+ audio_bus_pool_ = std::make_unique<AudioBusPoolImpl>(params_, 0, 10);
+ std::unique_ptr<AudioBus> audio_bus = audio_bus_pool_->GetAudioBus();
+ EXPECT_EQ(audio_bus->channels(), params_.channels());
+ EXPECT_EQ(audio_bus->frames(), params_.frames_per_buffer());
+}
+
+TEST_F(AudioBusPoolTest, ReuseAudioBusesInLifoOrder) {
+ CreateAndTrackAudioBusPool(0, 10);
+ EXPECT_CALL(*this, OnCreateAudioBus()).Times(0);
+
+ std::unique_ptr<AudioBus> audio_bus_1 = AudioBus::Create(params_);
+ std::unique_ptr<AudioBus> audio_bus_2 = AudioBus::Create(params_);
+ audio_bus_1->channel(0)[0] = 123;
+ audio_bus_2->channel(0)[0] = 456;
+ audio_bus_pool_->InsertAudioBus(std::move(audio_bus_1));
+ audio_bus_pool_->InsertAudioBus(std::move(audio_bus_2));
+
+ EXPECT_EQ(456, audio_bus_pool_->GetAudioBus()->channel(0)[0]);
+ EXPECT_EQ(123, audio_bus_pool_->GetAudioBus()->channel(0)[0]);
+}
+
+TEST_F(AudioBusPoolTest, Preallocate) {
+ // Expect to create 5 AudioBuses while preallocating.
+ EXPECT_CALL(*this, OnCreateAudioBus()).Times(5);
+ CreateAndTrackAudioBusPool(5, 10);
+
+ // Expect not to have to create any new AudioBuses the first 5 times.
+ EXPECT_CALL(*this, OnCreateAudioBus()).Times(0);
+ for (int i = 0; i < 5; i++) {
+ audio_bus_pool_->GetAudioBus();
+ }
+
+ // Now the pool has run out of AudioBuses and we expect it to create a new
+ // one.
+ EXPECT_CALL(*this, OnCreateAudioBus());
+ audio_bus_pool_->GetAudioBus();
+}
+
+TEST_F(AudioBusPoolTest, MaxCapacity) {
+ const int kMaxCapacity = 10;
+ CreateAndTrackAudioBusPool(0, kMaxCapacity);
+
+ // Insert 15 AudioBuses, but the max capacity is only 10.
+ for (int i = 0; i < 15; i++) {
+ audio_bus_pool_->InsertAudioBus(AudioBus::Create(params_));
+ }
+
+ // Expect not to have to create any new AudioBuses during the first 10 calls
+ // to GetAudioBus.
+ EXPECT_CALL(*this, OnCreateAudioBus()).Times(0);
+ for (int i = 0; i < 10; i++) {
+ audio_bus_pool_->GetAudioBus();
+ }
+
+ // Despite having called InsertAudioBus 15 times above, since the max capacity
+ // is only 10, we should now have run out of stored AudioBuses. We therefore
+ // expect that we will have to create a new AudioBus when we call GetAudioBus.
+ EXPECT_CALL(*this, OnCreateAudioBus());
+ audio_bus_pool_->GetAudioBus();
+}
+
+} // namespace media
diff --git a/chromium/media/audio/audio_debug_file_writer.cc b/chromium/media/audio/audio_debug_file_writer.cc
index ee8ffd569c3..823f3839a13 100644
--- a/chromium/media/audio/audio_debug_file_writer.cc
+++ b/chromium/media/audio/audio_debug_file_writer.cc
@@ -1,4 +1,4 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,13 +7,17 @@
#include <stdint.h>
#include <array>
#include <limits>
+#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
+#include "base/sequence_checker.h"
#include "base/sys_byteorder.h"
+#include "base/task/sequenced_task_runner.h"
+#include "media/audio/audio_bus_pool.h"
#include "media/base/audio_bus.h"
#include "media/base/audio_sample_types.h"
@@ -136,82 +140,53 @@ void WriteWavHeader(WavHeaderBuffer* buf,
} // namespace
-// Manages the debug recording file and writes to it. Can be created on any
-// thread. All the operations must be executed on a thread that has IO
-// permissions.
-class AudioDebugFileWriter::AudioFileWriter {
- public:
- static AudioFileWriterUniquePtr Create(
- base::File file,
- const AudioParameters& params,
- scoped_refptr<base::SequencedTaskRunner> task_runner);
-
- ~AudioFileWriter();
-
- // Write data from |data| to file.
- void Write(const AudioBus* data);
-
- private:
- explicit AudioFileWriter(const AudioParameters& params);
-
- // Write wave header to file. Called on the |task_runner_| twice: on
- // construction
- // of AudioFileWriter size of the wave data is unknown, so the header is
- // written with zero sizes; then on destruction it is re-written with the
- // actual size info accumulated throughout the object lifetime.
- void WriteHeader();
-
- void StartRecording(base::File file);
-
- // The file to write to.
- base::File file_;
-
- // Number of written samples.
- uint64_t samples_;
-
- // Audio parameters required to build wave header. Number of channels and
- // sample rate are used.
- const AudioParameters params_;
-
- // Intermediate buffer to be written to file. Interleaved 16 bit audio data.
- std::unique_ptr<int16_t[]> interleaved_data_;
- int interleaved_data_size_;
+AudioDebugFileWriter::~AudioDebugFileWriter() {
+ DCHECK(task_runner_->RunsTasksInCurrentSequence());
+ if (file_.IsValid())
+ WriteHeader();
+}
- SEQUENCE_CHECKER(sequence_checker_);
-};
+void AudioDebugFileWriter::Write(const AudioBus& data) {
+ std::unique_ptr<AudioBus> data_copy = audio_bus_pool_->GetAudioBus();
+ DCHECK(data_copy);
+ data.CopyTo(data_copy.get());
+ task_runner_->PostTask(
+ FROM_HERE, base::BindOnce(&AudioDebugFileWriter::DoWrite, weak_this_,
+ std::move(data_copy)));
+}
-// static
-AudioDebugFileWriter::AudioFileWriterUniquePtr
-AudioDebugFileWriter::AudioFileWriter::Create(
- base::File file,
+AudioDebugFileWriter::Ptr AudioDebugFileWriter::Create(
const AudioParameters& params,
- scoped_refptr<base::SequencedTaskRunner> task_runner) {
- AudioFileWriterUniquePtr file_writer(new AudioFileWriter(params),
- base::OnTaskRunnerDeleter(task_runner));
-
- // base::Unretained is safe, because destructor is called on
- // |task_runner|.
- task_runner->PostTask(
- FROM_HERE,
- base::BindOnce(&AudioFileWriter::StartRecording,
- base::Unretained(file_writer.get()), std::move(file)));
- return file_writer;
+ base::File file) {
+ return Create(params, std::move(file),
+ std::make_unique<AudioBusPoolImpl>(
+ params, kPreallocatedAudioBuses, kMaxCachedAudioBuses));
}
-AudioDebugFileWriter::AudioFileWriter::AudioFileWriter(
- const AudioParameters& params)
- : samples_(0), params_(params), interleaved_data_size_(0) {
- DETACH_FROM_SEQUENCE(sequence_checker_);
+AudioDebugFileWriter::AudioDebugFileWriter(
+ const AudioParameters& params,
+ base::File file,
+ std::unique_ptr<AudioBusPool> audio_bus_pool)
+ : params_(params),
+ file_(std::move(file)),
+ audio_bus_pool_(std::move(audio_bus_pool)) {
+ weak_this_ = weak_factory_.GetWeakPtr();
}
-AudioDebugFileWriter::AudioFileWriter::~AudioFileWriter() {
- DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- if (file_.IsValid())
- WriteHeader();
+AudioDebugFileWriter::Ptr AudioDebugFileWriter::Create(
+ const AudioParameters& params,
+ base::File file,
+ std::unique_ptr<AudioBusPool> audio_bus_pool) {
+ AudioDebugFileWriter* writer = new AudioDebugFileWriter(
+ params, std::move(file), std::move(audio_bus_pool));
+ writer->task_runner_->PostTask(
+ FROM_HERE,
+ base::BindOnce(&AudioDebugFileWriter::WriteHeader, writer->weak_this_));
+ return Ptr(writer, base::OnTaskRunnerDeleter(writer->task_runner_));
}
-void AudioDebugFileWriter::AudioFileWriter::Write(const AudioBus* data) {
- DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+void AudioDebugFileWriter::DoWrite(std::unique_ptr<AudioBus> data) {
+ DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK_EQ(params_.channels(), data->channels());
if (!file_.IsValid())
return;
@@ -235,10 +210,13 @@ void AudioDebugFileWriter::AudioFileWriter::Write(const AudioBus* data) {
file_.WriteAtCurrentPos(reinterpret_cast<char*>(interleaved_data_.get()),
data_size * sizeof(interleaved_data_[0]));
+
+ // Cache the AudioBus for later use.
+ audio_bus_pool_->InsertAudioBus(std::move(data));
}
-void AudioDebugFileWriter::AudioFileWriter::WriteHeader() {
- DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+void AudioDebugFileWriter::WriteHeader() {
+ DCHECK(task_runner_->RunsTasksInCurrentSequence());
if (!file_.IsValid())
return;
WavHeaderBuffer buf;
@@ -250,59 +228,4 @@ void AudioDebugFileWriter::AudioFileWriter::WriteHeader() {
file_.Seek(base::File::FROM_BEGIN, kWavHeaderSize);
}
-void AudioDebugFileWriter::AudioFileWriter::StartRecording(base::File file) {
- DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- DCHECK(!file_.IsValid());
-
- file_ = std::move(file);
- WriteHeader();
-}
-
-AudioDebugFileWriter::AudioDebugFileWriter(const AudioParameters& params)
- : params_(params),
- file_writer_(nullptr, base::OnTaskRunnerDeleter(nullptr)) {
- DETACH_FROM_SEQUENCE(client_sequence_checker_);
-}
-
-AudioDebugFileWriter::~AudioDebugFileWriter() {
- // |file_writer_| will be deleted on |task_runner_|.
-}
-
-void AudioDebugFileWriter::Start(base::File file) {
- DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_);
- DCHECK(!file_writer_);
- file_writer_ =
- AudioFileWriter::Create(std::move(file), params_, file_task_runner_);
-}
-
-void AudioDebugFileWriter::Stop() {
- DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_);
- // |file_writer_| is deleted on FILE thread.
- file_writer_.reset();
- DETACH_FROM_SEQUENCE(client_sequence_checker_);
-}
-
-void AudioDebugFileWriter::Write(std::unique_ptr<AudioBus> data) {
- DCHECK_CALLED_ON_VALID_SEQUENCE(client_sequence_checker_);
- if (!file_writer_)
- return;
-
- // base::Unretained for |file_writer_| is safe, see the destructor.
- file_task_runner_->PostTask(
- FROM_HERE,
- // Callback takes ownership of |data|:
- base::BindOnce(&AudioFileWriter::Write,
- base::Unretained(file_writer_.get()),
- base::Owned(data.release())));
-}
-
-bool AudioDebugFileWriter::WillWrite() {
- // Note that if this is called from any place other than
- // |client_sequence_checker_| then there is a data race here, but it's fine,
- // because Write() will check for |file_writer_|. So, we are not very precise
- // here, but it's fine: we can afford missing some data or scheduling some
- // no-op writes.
- return !!file_writer_;
-}
-
} // namespace media
diff --git a/chromium/media/audio/audio_debug_file_writer.h b/chromium/media/audio/audio_debug_file_writer.h
index aa535ac779b..d24376c2fdd 100644
--- a/chromium/media/audio/audio_debug_file_writer.h
+++ b/chromium/media/audio/audio_debug_file_writer.h
@@ -1,4 +1,4 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,6 +11,7 @@
#include "base/files/file.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
@@ -21,56 +22,79 @@ namespace media {
class AudioBus;
-// Writes audio data to a 16 bit PCM WAVE file used for debugging purposes. All
-// operations are non-blocking.
-// Functions are virtual for the purpose of test mocking.
+class AudioBusPool;
+
+// Writes audio data to a 16 bit PCM WAVE file used for debugging purposes.
+// Functions are virtual for the purpose of test mocking. This class can be
+// created and used anywhere, but must be destroyed using the
+// OnTaskRunnerDeleter provided by Create(). It starts writing on Create(), and
+// stops writing on destruction.
class MEDIA_EXPORT AudioDebugFileWriter {
public:
- // Number of channels and sample rate are used from |params|, the other
- // parameters are ignored. The number of channels in the data passed to
- // Write() must match |params|.
- explicit AudioDebugFileWriter(const AudioParameters& params);
-
AudioDebugFileWriter(const AudioDebugFileWriter&) = delete;
AudioDebugFileWriter& operator=(const AudioDebugFileWriter&) = delete;
virtual ~AudioDebugFileWriter();
- // Must be called before calling Write() for the first time after creation or
- // Stop() call. Can be called on any sequence; Write() and Stop() must be
- // called on the same sequence as Start().
- virtual void Start(base::File file);
-
- // Must be called to finish recording. Each call to Start() requires a call to
- // Stop(). Will be automatically called on destruction.
- virtual void Stop();
-
// Write |data| to file.
- virtual void Write(std::unique_ptr<AudioBus> data);
+ virtual void Write(const AudioBus& data);
- // Returns true if Write() call scheduled at this point will most likely write
- // data to the file, and false if it most likely will be a no-op. The result
- // may be ambigulous if Start() or Stop() is executed at the moment. Can be
- // called from any sequence.
- virtual bool WillWrite();
+ using Ptr = std::unique_ptr<AudioDebugFileWriter, base::OnTaskRunnerDeleter>;
+
+ // Number of channels and sample rate are used from |params|, the other
+ // parameters are ignored. The number of channels in the data passed to
+ // Write() must match |params|. Write() must be called on the sequence that
+ // task_runner belongs to.
+ static Ptr Create(const AudioParameters& params, base::File file);
protected:
- const AudioParameters params_;
+ // Protected for testing.
+ AudioDebugFileWriter(const AudioParameters& params,
+ base::File file,
+ std::unique_ptr<AudioBusPool> audio_bus_pool);
- private:
- class AudioFileWriter;
+ // Create with a custom AudioBusPool.
+ static Ptr Create(const AudioParameters& params,
+ base::File file,
+ std::unique_ptr<AudioBusPool> audio_bus_pool);
- using AudioFileWriterUniquePtr =
- std::unique_ptr<AudioFileWriter, base::OnTaskRunnerDeleter>;
+ const AudioParameters params_;
- // The task runner to do file output operations on.
- const scoped_refptr<base::SequencedTaskRunner> file_task_runner_ =
+ const scoped_refptr<base::SequencedTaskRunner> task_runner_ =
base::ThreadPool::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN});
- AudioFileWriterUniquePtr file_writer_;
- SEQUENCE_CHECKER(client_sequence_checker_);
+ private:
+ // Write wave header to file. Called twice: on Create() the size of the wave
+ // data is unknown, so the header is written with zero sizes; then on
+ // destruction it is re-written with the actual size info accumulated
+ // throughout the object lifetime.
+ void WriteHeader();
+
+ void DoWrite(std::unique_ptr<AudioBus> data);
+
+ // The file to write to.
+ base::File file_;
+
+ // Number of written samples.
+ uint64_t samples_ = 0;
+
+ // Intermediate buffer to be written to file. Interleaved 16 bit audio data.
+ std::unique_ptr<int16_t[]> interleaved_data_;
+ int interleaved_data_size_ = 0;
+
+ // Stores AudioBuses to be reused.
+ const std::unique_ptr<AudioBusPool> audio_bus_pool_;
+
+ // The number of AudioBuses that should be preallocated on creation.
+ static constexpr size_t kPreallocatedAudioBuses = 100;
+
+ // The maximum number of AudioBuses we should cache at once.
+ static constexpr size_t kMaxCachedAudioBuses = 500;
+
+ base::WeakPtr<AudioDebugFileWriter> weak_this_;
+ base::WeakPtrFactory<AudioDebugFileWriter> weak_factory_{this};
};
} // namespace media
diff --git a/chromium/media/audio/audio_debug_file_writer_unittest.cc b/chromium/media/audio/audio_debug_file_writer_unittest.cc
index 3ca19fb4a12..3d7b0208813 100644
--- a/chromium/media/audio/audio_debug_file_writer_unittest.cc
+++ b/chromium/media/audio/audio_debug_file_writer_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -15,12 +15,16 @@
#include "base/sys_byteorder.h"
#include "base/test/task_environment.h"
#include "base/threading/thread.h"
+#include "media/audio/audio_bus_pool.h"
#include "media/audio/audio_debug_file_writer.h"
#include "media/base/audio_bus.h"
+#include "media/base/audio_parameters.h"
#include "media/base/audio_sample_types.h"
#include "media/base/test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
+using testing::_;
+
namespace media {
namespace {
@@ -43,10 +47,56 @@ base::File OpenFile(const base::FilePath& file_path) {
return base::File(file_path, base::File::FLAG_OPEN | base::File::FLAG_WRITE);
}
+// Serves only to expose the protected Create method of AudioDebugFileWriter.
+class AudioDebugFileWriterUnderTest : public AudioDebugFileWriter {
+ public:
+ // Should not be instantiated
+ AudioDebugFileWriterUnderTest() = delete;
+
+ static Ptr Create(const AudioParameters& params,
+ base::File file,
+ std::unique_ptr<AudioBusPool> audio_bus_pool) {
+ return AudioDebugFileWriter::Create(params, std::move(file),
+ std::move(audio_bus_pool));
+ }
+};
+
+class MockAudioBusPool : public AudioBusPool {
+ public:
+ explicit MockAudioBusPool(const AudioParameters& params) : params_(params) {}
+
+ MockAudioBusPool(const MockAudioBusPool&) = delete;
+ MockAudioBusPool& operator=(const MockAudioBusPool&) = delete;
+ ~MockAudioBusPool() override = default;
+
+ std::unique_ptr<AudioBus> GetAudioBus() override {
+ if (audio_bus_to_return_) {
+ return std::move(audio_bus_to_return_);
+ }
+ return AudioBus::Create(params_);
+ }
+
+ MOCK_METHOD1(OnInsertAudioBus, void(AudioBus*));
+
+ void InsertAudioBus(std::unique_ptr<AudioBus> audio_bus) override {
+ OnInsertAudioBus(audio_bus.get());
+ }
+
+ void SetNextAudioBus(std::unique_ptr<AudioBus> audio_bus) {
+ audio_bus_to_return_ = std::move(audio_bus);
+ }
+
+ private:
+ const AudioParameters params_;
+
+ std::unique_ptr<AudioBus> audio_bus_to_return_;
+};
+
} // namespace
// <channel layout, sample rate, frames per buffer, number of buffer writes
-typedef std::tuple<ChannelLayout, int, int, int> AudioDebugFileWriterTestData;
+typedef std::tuple<ChannelLayoutConfig, int, int, int>
+ AudioDebugFileWriterTestData;
class AudioDebugFileWriterTest
: public testing::TestWithParam<AudioDebugFileWriterTestData> {
@@ -55,6 +105,7 @@ class AudioDebugFileWriterTest
base::test::TaskEnvironment::ThreadPoolExecutionMode execution_mode)
: task_environment_(base::test::TaskEnvironment::MainThreadType::DEFAULT,
execution_mode),
+ debug_writer_(nullptr, base::OnTaskRunnerDeleter(nullptr)),
params_(AudioParameters::Format::AUDIO_PCM_LINEAR,
std::get<0>(GetParam()),
std::get<1>(GetParam()),
@@ -169,7 +220,10 @@ class AudioDebugFileWriterTest
}
}
- void DoDebugRecording() {
+ void DoDebugRecording(bool expect_buses_returned_to_pool = true) {
+ EXPECT_CALL(*mock_audio_bus_pool_, OnInsertAudioBus(_))
+ .Times(expect_buses_returned_to_pool ? writes_ : 0);
+
for (int i = 0; i < writes_; ++i) {
std::unique_ptr<AudioBus> bus =
AudioBus::Create(params_.channels(), params_.frames_per_buffer());
@@ -179,32 +233,15 @@ class AudioDebugFileWriterTest
i * params_.channels() * params_.frames_per_buffer(),
params_.frames_per_buffer());
- debug_writer_->Write(std::move(bus));
+ debug_writer_->Write(*bus);
}
}
- void RecordAndVerifyOnce() {
- base::FilePath file_path;
- ASSERT_TRUE(base::CreateTemporaryFile(&file_path));
- base::File file = OpenFile(file_path);
- ASSERT_TRUE(file.IsValid());
-
- debug_writer_->Start(std::move(file));
-
- DoDebugRecording();
-
- debug_writer_->Stop();
-
- task_environment_.RunUntilIdle();
-
- VerifyRecording(file_path);
-
- if (::testing::Test::HasFailure()) {
- LOG(ERROR) << "Test failed; keeping recording(s) at ["
- << file_path.value().c_str() << "].";
- } else {
- ASSERT_TRUE(base::DeleteFile(file_path));
- }
+ void CreateDebugWriter(base::File file) {
+ auto audio_bus_pool = std::make_unique<MockAudioBusPool>(params_);
+ mock_audio_bus_pool_ = audio_bus_pool.get();
+ debug_writer_ = AudioDebugFileWriterUnderTest::Create(
+ params_, std::move(file), std::move(audio_bus_pool));
}
protected:
@@ -212,7 +249,10 @@ class AudioDebugFileWriterTest
base::test::TaskEnvironment task_environment_;
// Writer under test.
- std::unique_ptr<AudioDebugFileWriter> debug_writer_;
+ AudioDebugFileWriter::Ptr debug_writer_;
+
+ // Pointer to the AudioBusPool of the most recently created writer.
+ MockAudioBusPool* mock_audio_bus_pool_;
// AudioBus parameters.
AudioParameters params_;
@@ -237,25 +277,64 @@ class AudioDebugFileWriterSingleThreadTest : public AudioDebugFileWriterTest {
};
TEST_P(AudioDebugFileWriterTest, WaveRecordingTest) {
- debug_writer_ = std::make_unique<AudioDebugFileWriter>(params_);
- RecordAndVerifyOnce();
+ base::FilePath file_path;
+ ASSERT_TRUE(base::CreateTemporaryFile(&file_path));
+ base::File file = OpenFile(file_path);
+ ASSERT_TRUE(file.IsValid());
+
+ CreateDebugWriter(std::move(file));
+
+ DoDebugRecording();
+
+ debug_writer_.reset();
+ task_environment_.RunUntilIdle();
+
+ VerifyRecording(file_path);
+
+ if (::testing::Test::HasFailure()) {
+ LOG(ERROR) << "Test failed; keeping recording(s) at ["
+ << file_path.value().c_str() << "].";
+ } else {
+ ASSERT_TRUE(base::DeleteFile(file_path));
+ }
+}
+
+TEST_P(AudioDebugFileWriterBehavioralTest, ShouldReuseAudioBusesWithPool) {
+ base::FilePath file_path;
+ ASSERT_TRUE(base::CreateTemporaryFile(&file_path));
+ base::File file = OpenFile(file_path);
+ ASSERT_TRUE(file.IsValid());
+
+ CreateDebugWriter(std::move(file));
+
+ // Set a specific audio bus to be returned by the pool.
+ std::unique_ptr<AudioBus> reference_audio_bus = AudioBus::Create(params_);
+ AudioBus* reference_audio_bus_ptr = reference_audio_bus.get();
+ mock_audio_bus_pool_->SetNextAudioBus(std::move(reference_audio_bus));
+
+ // Expect that same audio bus to be returned to the pool.
+ EXPECT_CALL(*mock_audio_bus_pool_, OnInsertAudioBus(reference_audio_bus_ptr));
+
+ std::unique_ptr<AudioBus> bus = AudioBus::Create(params_);
+ bus->FromInterleaved<media::SignedInt16SampleTypeTraits>(
+ source_interleaved_.get(), params_.frames_per_buffer());
+
+ debug_writer_->Write(*bus);
+ task_environment_.RunUntilIdle();
}
TEST_P(AudioDebugFileWriterSingleThreadTest,
DeletedBeforeRecordingFinishedOnFileThread) {
- debug_writer_ = std::make_unique<AudioDebugFileWriter>(params_);
-
base::FilePath file_path;
ASSERT_TRUE(base::CreateTemporaryFile(&file_path));
base::File file = OpenFile(file_path);
ASSERT_TRUE(file.IsValid());
- debug_writer_->Start(std::move(file));
+ CreateDebugWriter(std::move(file));
DoDebugRecording();
debug_writer_.reset();
-
task_environment_.RunUntilIdle();
VerifyRecording(file_path);
@@ -269,31 +348,53 @@ TEST_P(AudioDebugFileWriterSingleThreadTest,
}
TEST_P(AudioDebugFileWriterBehavioralTest, StartWithInvalidFile) {
- debug_writer_ = std::make_unique<AudioDebugFileWriter>(params_);
base::File file; // Invalid file, recording should not crash
- debug_writer_->Start(std::move(file));
- DoDebugRecording();
+ CreateDebugWriter(std::move(file));
+
+ DoDebugRecording(/*expect_buses_returned_to_pool = */ false);
+ task_environment_.RunUntilIdle();
}
TEST_P(AudioDebugFileWriterBehavioralTest, StartStopStartStop) {
- debug_writer_ = std::make_unique<AudioDebugFileWriter>(params_);
- RecordAndVerifyOnce();
- RecordAndVerifyOnce();
-}
+ base::FilePath file_path1;
+ ASSERT_TRUE(base::CreateTemporaryFile(&file_path1));
+ base::File file1 = OpenFile(file_path1);
+ ASSERT_TRUE(file1.IsValid());
+
+ base::FilePath file_path2;
+ ASSERT_TRUE(base::CreateTemporaryFile(&file_path2));
+ base::File file2 = OpenFile(file_path2);
+ ASSERT_TRUE(file2.IsValid());
-TEST_P(AudioDebugFileWriterBehavioralTest, DestroyNotStarted) {
- debug_writer_ = std::make_unique<AudioDebugFileWriter>(params_);
+ CreateDebugWriter(std::move(file1));
+ DoDebugRecording();
+ CreateDebugWriter(std::move(file2));
+ DoDebugRecording();
debug_writer_.reset();
+ task_environment_.RunUntilIdle();
+
+ VerifyRecording(file_path1);
+ VerifyRecording(file_path2);
+
+ if (::testing::Test::HasFailure()) {
+ LOG(ERROR) << "Test failed; keeping recording(s) at ["
+ << file_path1.value().c_str() << ", "
+ << file_path2.value().c_str() << "].";
+ } else {
+ ASSERT_TRUE(base::DeleteFile(file_path1));
+ ASSERT_TRUE(base::DeleteFile(file_path2));
+ }
}
TEST_P(AudioDebugFileWriterBehavioralTest, DestroyStarted) {
- debug_writer_ = std::make_unique<AudioDebugFileWriter>(params_);
base::FilePath file_path;
ASSERT_TRUE(base::CreateTemporaryFile(&file_path));
base::File file = OpenFile(file_path);
ASSERT_TRUE(file.IsValid());
- debug_writer_->Start(std::move(file));
+ CreateDebugWriter(std::move(file));
+
debug_writer_.reset();
+ task_environment_.RunUntilIdle();
}
INSTANTIATE_TEST_SUITE_P(
@@ -302,53 +403,34 @@ INSTANTIATE_TEST_SUITE_P(
// Using 10ms frames per buffer everywhere.
testing::Values(
// No writes.
- std::make_tuple(ChannelLayout::CHANNEL_LAYOUT_MONO,
- 44100,
- 44100 / 100,
- 0),
+ std::make_tuple(ChannelLayoutConfig::Mono(), 44100, 44100 / 100, 0),
// 1 write of mono.
- std::make_tuple(ChannelLayout::CHANNEL_LAYOUT_MONO,
- 44100,
- 44100 / 100,
- 1),
+ std::make_tuple(ChannelLayoutConfig::Mono(), 44100, 44100 / 100, 1),
// 1 second of mono.
- std::make_tuple(ChannelLayout::CHANNEL_LAYOUT_MONO,
- 44100,
- 44100 / 100,
- 100),
+ std::make_tuple(ChannelLayoutConfig::Mono(), 44100, 44100 / 100, 100),
// 1 second of mono, higher rate.
- std::make_tuple(ChannelLayout::CHANNEL_LAYOUT_MONO,
- 48000,
- 48000 / 100,
- 100),
+ std::make_tuple(ChannelLayoutConfig::Mono(), 48000, 48000 / 100, 100),
// 1 second of stereo.
- std::make_tuple(ChannelLayout::CHANNEL_LAYOUT_STEREO,
- 44100,
- 44100 / 100,
- 100),
+ std::make_tuple(ChannelLayoutConfig::Stereo(), 44100, 44100 / 100, 100),
// 15 seconds of stereo, higher rate.
- std::make_tuple(ChannelLayout::CHANNEL_LAYOUT_STEREO,
+ std::make_tuple(ChannelLayoutConfig::Stereo(),
48000,
48000 / 100,
1500)));
-INSTANTIATE_TEST_SUITE_P(AudioDebugFileWriterBehavioralTest,
- AudioDebugFileWriterBehavioralTest,
- // Using 10ms frames per buffer everywhere.
- testing::Values(
- // No writes.
- std::make_tuple(ChannelLayout::CHANNEL_LAYOUT_MONO,
- 44100,
- 44100 / 100,
- 100)));
-
-INSTANTIATE_TEST_SUITE_P(AudioDebugFileWriterSingleThreadTest,
- AudioDebugFileWriterSingleThreadTest,
- // Using 10ms frames per buffer everywhere.
- testing::Values(
- // No writes.
- std::make_tuple(ChannelLayout::CHANNEL_LAYOUT_MONO,
- 44100,
- 44100 / 100,
- 100)));
+INSTANTIATE_TEST_SUITE_P(
+ AudioDebugFileWriterBehavioralTest,
+ AudioDebugFileWriterBehavioralTest,
+ // Using 10ms frames per buffer everywhere.
+ testing::Values(
+ // No writes.
+ std::make_tuple(ChannelLayoutConfig::Mono(), 44100, 44100 / 100, 100)));
+
+INSTANTIATE_TEST_SUITE_P(
+ AudioDebugFileWriterSingleThreadTest,
+ AudioDebugFileWriterSingleThreadTest,
+ // Using 10ms frames per buffer everywhere.
+ testing::Values(
+ // No writes.
+ std::make_tuple(ChannelLayoutConfig::Mono(), 44100, 44100 / 100, 100)));
} // namespace media
diff --git a/chromium/media/audio/audio_debug_recording_helper.cc b/chromium/media/audio/audio_debug_recording_helper.cc
index 24d55f9c5b9..5a284ef0801 100644
--- a/chromium/media/audio/audio_debug_recording_helper.cc
+++ b/chromium/media/audio/audio_debug_recording_helper.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,7 +11,9 @@
#include "base/files/file.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
-#include "base/task/single_thread_task_runner.h"
+#include "base/sequence_checker.h"
+#include "base/synchronization/lock.h"
+#include "base/task/bind_post_task.h"
#include "media/audio/audio_debug_file_writer.h"
#include "media/base/audio_bus.h"
@@ -19,14 +21,15 @@ namespace media {
AudioDebugRecordingHelper::AudioDebugRecordingHelper(
const AudioParameters& params,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner,
base::OnceClosure on_destruction_closure)
: params_(params),
- recording_enabled_(0),
- task_runner_(std::move(task_runner)),
- on_destruction_closure_(std::move(on_destruction_closure)) {}
+ file_writer_(nullptr, base::OnTaskRunnerDeleter(nullptr)),
+ on_destruction_closure_(std::move(on_destruction_closure)) {
+ DETACH_FROM_SEQUENCE(sequence_checker_);
+}
AudioDebugRecordingHelper::~AudioDebugRecordingHelper() {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (on_destruction_closure_)
std::move(on_destruction_closure_).Run();
}
@@ -35,10 +38,8 @@ void AudioDebugRecordingHelper::EnableDebugRecording(
AudioDebugRecordingStreamType stream_type,
uint32_t id,
CreateWavFileCallback create_file_callback) {
- DCHECK(task_runner_->BelongsToCurrentThread());
- DCHECK(!debug_writer_);
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- debug_writer_ = CreateAudioDebugFileWriter(params_);
std::move(create_file_callback)
.Run(stream_type, id,
base::BindOnce(&AudioDebugRecordingHelper::StartDebugRecordingToFile,
@@ -46,73 +47,47 @@ void AudioDebugRecordingHelper::EnableDebugRecording(
}
void AudioDebugRecordingHelper::StartDebugRecordingToFile(base::File file) {
- DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- if (!file.IsValid()) {
- PLOG(ERROR) << "Invalid debug recording file, error="
- << file.error_details();
- debug_writer_.reset();
- return;
- }
+ {
+ base::AutoLock auto_lock(file_writer_lock_);
- debug_writer_->Start(std::move(file));
+ if (!file.IsValid()) {
+ PLOG(ERROR) << "Invalid debug recording file, error="
+ << file.error_details();
+ file_writer_.reset();
+ return;
+ }
- base::subtle::NoBarrier_Store(&recording_enabled_, 1);
+ file_writer_ = CreateAudioDebugFileWriter(params_, std::move(file));
+ }
}
void AudioDebugRecordingHelper::DisableDebugRecording() {
- DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- base::subtle::NoBarrier_Store(&recording_enabled_, 0);
-
- if (debug_writer_) {
- debug_writer_->Stop();
- debug_writer_.reset();
+ {
+ base::AutoLock auto_lock(file_writer_lock_);
+ if (file_writer_) {
+ file_writer_.reset();
+ }
}
}
void AudioDebugRecordingHelper::OnData(const AudioBus* source) {
- // Check if debug recording is enabled to avoid an unecessary copy and thread
- // jump if not. Recording can be disabled between the atomic Load() here and
- // DoWrite(), but it's fine with a single unnecessary copy+jump at disable
- // time. We use an atomic operation for accessing the flag on different
- // threads. No memory barrier is needed for the same reason; a race is no
- // problem at enable and disable time. Missing one buffer of data doesn't
- // matter.
- base::subtle::Atomic32 recording_enabled =
- base::subtle::NoBarrier_Load(&recording_enabled_);
- if (!recording_enabled)
- return;
-
- // TODO(tommi): This is costly. AudioBus heap allocs and we create a new one
- // for every callback. We could instead have a pool of bus objects that get
- // returned to us somehow.
- // We should also avoid calling PostTask here since the implementation of the
- // debug writer will basically do a PostTask straight away anyway. Might
- // require some modifications to AudioDebugFileWriter though since there are
- // some threading concerns there and AudioDebugFileWriter's lifetime
- // guarantees need to be longer than that of associated active audio streams.
- std::unique_ptr<AudioBus> audio_bus_copy =
- AudioBus::Create(source->channels(), source->frames());
- source->CopyTo(audio_bus_copy.get());
-
- task_runner_->PostTask(
- FROM_HERE,
- base::BindOnce(&AudioDebugRecordingHelper::DoWrite,
- weak_factory_.GetWeakPtr(), std::move(audio_bus_copy)));
-}
-
-void AudioDebugRecordingHelper::DoWrite(std::unique_ptr<media::AudioBus> data) {
- DCHECK(task_runner_->BelongsToCurrentThread());
-
- if (debug_writer_)
- debug_writer_->Write(std::move(data));
+ if (file_writer_lock_.Try()) {
+ if (file_writer_) {
+ file_writer_->Write(*source);
+ }
+ file_writer_lock_.Release();
+ }
}
-std::unique_ptr<AudioDebugFileWriter>
-AudioDebugRecordingHelper::CreateAudioDebugFileWriter(
- const AudioParameters& params) {
- return std::make_unique<AudioDebugFileWriter>(params);
+AudioDebugFileWriter::Ptr AudioDebugRecordingHelper::CreateAudioDebugFileWriter(
+ const AudioParameters& params,
+ base::File file) {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ return AudioDebugFileWriter::Create(params, std::move(file));
}
} // namespace media
diff --git a/chromium/media/audio/audio_debug_recording_helper.h b/chromium/media/audio/audio_debug_recording_helper.h
index 86d2ed7b368..2283a95aecc 100644
--- a/chromium/media/audio/audio_debug_recording_helper.h
+++ b/chromium/media/audio/audio_debug_recording_helper.h
@@ -1,16 +1,15 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_
#define MEDIA_AUDIO_AUDIO_DEBUG_RECORDING_HELPER_H_
-#include <memory>
-
#include "base/atomicops.h"
#include "base/callback.h"
#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
+#include "base/thread_annotations.h"
#include "base/threading/thread_checker.h"
#include "media/audio/audio_debug_file_writer.h"
#include "media/base/audio_parameters.h"
@@ -18,7 +17,6 @@
namespace base {
class File;
-class SingleThreadTaskRunner;
}
namespace media {
@@ -39,16 +37,9 @@ class AudioDebugRecorder {
};
// A helper class for those who want to use AudioDebugFileWriter. It handles
-// copying AudioBus data, thread jump (OnData() can be called on any
-// thread), and creating and deleting the AudioDebugFileWriter at enable and
-// disable. All functions except OnData() must be called on the thread
-// |task_runner| belongs to.
-// TODO(grunell): When input debug recording is moved to AudioManager, it should
-// be possible to merge this class into AudioDebugFileWriter. One thread jump
-// could be skipped then. Currently we have
-// soundcard thread -> control thread -> file thread,
-// and with the merge we should be able to do
-// soundcard thread -> file thread.
+// copying AudioBus data, thread jump (OnData() can be called on any thread),
+// and creating and deleting the AudioDebugFileWriter at enable and disable. All
+// public methods except OnData() must be called on the same sequence.
class MEDIA_EXPORT AudioDebugRecordingHelper : public AudioDebugRecorder {
public:
using CreateWavFileCallback = base::OnceCallback<void(
@@ -56,10 +47,8 @@ class MEDIA_EXPORT AudioDebugRecordingHelper : public AudioDebugRecorder {
uint32_t id,
base::OnceCallback<void(base::File)> reply_callback)>;
- AudioDebugRecordingHelper(
- const AudioParameters& params,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner,
- base::OnceClosure on_destruction_closure);
+ AudioDebugRecordingHelper(const AudioParameters& params,
+ base::OnceClosure on_destruction_closure);
AudioDebugRecordingHelper(const AudioDebugRecordingHelper&) = delete;
AudioDebugRecordingHelper& operator=(const AudioDebugRecordingHelper&) =
@@ -67,13 +56,12 @@ class MEDIA_EXPORT AudioDebugRecordingHelper : public AudioDebugRecorder {
~AudioDebugRecordingHelper() override;
- // Enable debug recording. Creates |debug_writer_| and runs
- // |create_file_callback| to create debug recording file.
+ // Enable debug recording. Runs |create_file_callback| synchronously to create
+ // the debug recording file.
virtual void EnableDebugRecording(AudioDebugRecordingStreamType stream_type,
uint32_t id,
CreateWavFileCallback create_file_callback);
- // Disable debug recording. Destroys |debug_writer_|.
virtual void DisableDebugRecording();
// AudioDebugRecorder implementation. Can be called on any thread.
@@ -83,30 +71,27 @@ class MEDIA_EXPORT AudioDebugRecordingHelper : public AudioDebugRecorder {
FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingHelperTest, EnableDisable);
FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingHelperTest, OnData);
- // Writes debug data to |debug_writer_|.
- void DoWrite(std::unique_ptr<media::AudioBus> data);
-
// Creates an AudioDebugFileWriter. Overridden by test.
- virtual std::unique_ptr<AudioDebugFileWriter> CreateAudioDebugFileWriter(
- const AudioParameters& params);
+ virtual AudioDebugFileWriter::Ptr CreateAudioDebugFileWriter(
+ const AudioParameters& params,
+ base::File file);
// Passed to |create_file_callback| in EnableDebugRecording, to be called
// after debug recording file was created.
void StartDebugRecordingToFile(base::File file);
const AudioParameters params_;
- std::unique_ptr<AudioDebugFileWriter> debug_writer_;
- // Used as a flag to indicate if recording is enabled, accessed on different
- // threads.
- base::subtle::Atomic32 recording_enabled_;
+ // Locks access to the |file_writer_|.
+ base::Lock file_writer_lock_;
- // The task runner for accessing |debug_writer_|.
- scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+ AudioDebugFileWriter::Ptr file_writer_ GUARDED_BY(file_writer_lock_);
// Runs in destructor if set.
base::OnceClosure on_destruction_closure_;
+ SEQUENCE_CHECKER(sequence_checker_);
+
base::WeakPtrFactory<AudioDebugRecordingHelper> weak_factory_{this};
};
diff --git a/chromium/media/audio/audio_debug_recording_helper_unittest.cc b/chromium/media/audio/audio_debug_recording_helper_unittest.cc
index c5b4d434ac2..cea821a36ba 100644
--- a/chromium/media/audio/audio_debug_recording_helper_unittest.cc
+++ b/chromium/media/audio/audio_debug_recording_helper_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,14 +10,20 @@
#include "base/bind.h"
#include "base/callback.h"
+#include "base/check_op.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
+#include "base/functional/callback_forward.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
+#include "base/synchronization/lock.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
+#include "base/test/bind.h"
#include "base/test/task_environment.h"
+#include "media/audio/audio_bus_pool.h"
#include "media/base/audio_bus.h"
#include "media/base/audio_sample_types.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -38,36 +44,31 @@ const base::FilePath::CharType kFileName[] =
// Mock class for the audio file writer that the helper wraps.
class MockAudioDebugFileWriter : public AudioDebugFileWriter {
public:
- explicit MockAudioDebugFileWriter(const AudioParameters& params)
- : AudioDebugFileWriter(params), reference_data_(nullptr) {}
+ explicit MockAudioDebugFileWriter(const AudioParameters& params,
+ base::File file)
+ : AudioDebugFileWriter(params, std::move(file), nullptr),
+ reference_data_(nullptr) {}
MockAudioDebugFileWriter(const MockAudioDebugFileWriter&) = delete;
MockAudioDebugFileWriter& operator=(const MockAudioDebugFileWriter&) = delete;
- ~MockAudioDebugFileWriter() override = default;
+ MOCK_METHOD0(DestructorCalled, void());
+ ~MockAudioDebugFileWriter() override { DestructorCalled(); }
- MOCK_METHOD1(DoStart, void(bool));
- void Start(base::File file) override { DoStart(file.IsValid()); }
- MOCK_METHOD0(Stop, void());
-
- // Functions with move-only types as arguments can't be mocked directly, so
- // we pass on to DoWrite(). Also, we can verify the data this way.
- MOCK_METHOD1(DoWrite, void(AudioBus*));
- void Write(std::unique_ptr<AudioBus> data) override {
+ MOCK_METHOD1(DoWrite, void(const AudioBus&));
+ void Write(const AudioBus& data) override {
CHECK(reference_data_);
- EXPECT_EQ(reference_data_->channels(), data->channels());
- EXPECT_EQ(reference_data_->frames(), data->frames());
- for (int i = 0; i < data->channels(); ++i) {
- float* data_ptr = data->channel(i);
+ EXPECT_EQ(reference_data_->channels(), data.channels());
+ EXPECT_EQ(reference_data_->frames(), data.frames());
+ for (int i = 0; i < data.channels(); ++i) {
+ const float* data_ptr = data.channel(i);
float* ref_data_ptr = reference_data_->channel(i);
- for (int j = 0; j < data->frames(); ++j, ++data_ptr, ++ref_data_ptr)
+ for (int j = 0; j < data.frames(); ++j, ++data_ptr, ++ref_data_ptr)
EXPECT_EQ(*ref_data_ptr, *data_ptr);
}
- DoWrite(data.get());
+ DoWrite(data);
}
- MOCK_METHOD0(WillWrite, bool());
-
// Set reference data to compare against. Must be called before Write() is
// called.
void SetReferenceData(AudioBus* reference_data) {
@@ -76,6 +77,10 @@ class MockAudioDebugFileWriter : public AudioDebugFileWriter {
reference_data_ = reference_data;
}
+ scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() {
+ return task_runner_;
+ }
+
private:
raw_ptr<AudioBus> reference_data_;
};
@@ -84,13 +89,15 @@ class MockAudioDebugFileWriter : public AudioDebugFileWriter {
// function to create the above mock instead.
class AudioDebugRecordingHelperUnderTest : public AudioDebugRecordingHelper {
public:
+ using CreatedWriterCallback =
+ base::RepeatingCallback<void(MockAudioDebugFileWriter*)>;
+
AudioDebugRecordingHelperUnderTest(
const AudioParameters& params,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner,
- base::OnceClosure on_destruction_closure)
- : AudioDebugRecordingHelper(params,
- std::move(task_runner),
- std::move(on_destruction_closure)) {}
+ base::OnceClosure on_destruction_closure,
+ CreatedWriterCallback created_writer_callback)
+ : AudioDebugRecordingHelper(params, std::move(on_destruction_closure)),
+ created_writer_callback_(std::move(created_writer_callback)) {}
AudioDebugRecordingHelperUnderTest(
const AudioDebugRecordingHelperUnderTest&) = delete;
@@ -100,19 +107,23 @@ class AudioDebugRecordingHelperUnderTest : public AudioDebugRecordingHelper {
~AudioDebugRecordingHelperUnderTest() override = default;
private:
- // Creates the mock writer. After the mock writer is returned, we always
- // expect Start() to be called on it by the helper.
- std::unique_ptr<AudioDebugFileWriter> CreateAudioDebugFileWriter(
- const AudioParameters& params) override {
- MockAudioDebugFileWriter* writer = new MockAudioDebugFileWriter(params);
- EXPECT_CALL(*writer, DoStart(true));
- return base::WrapUnique<AudioDebugFileWriter>(writer);
+ // Creates the mock writer.
+ AudioDebugFileWriter::Ptr CreateAudioDebugFileWriter(
+ const AudioParameters& params,
+ base::File file) override {
+ MockAudioDebugFileWriter* writer =
+ new MockAudioDebugFileWriter(params, std::move(file));
+ created_writer_callback_.Run(writer);
+ return AudioDebugFileWriter::Ptr(
+ writer, base::OnTaskRunnerDeleter(writer->GetTaskRunner()));
}
+
+ CreatedWriterCallback created_writer_callback_;
};
class AudioDebugRecordingHelperTest : public ::testing::Test {
public:
- AudioDebugRecordingHelperTest() {}
+ AudioDebugRecordingHelperTest() = default;
AudioDebugRecordingHelperTest(const AudioDebugRecordingHelperTest&) = delete;
AudioDebugRecordingHelperTest& operator=(
@@ -125,8 +136,11 @@ class AudioDebugRecordingHelperTest : public ::testing::Test {
const AudioParameters& params,
base::OnceClosure on_destruction_closure) {
return std::make_unique<AudioDebugRecordingHelperUnderTest>(
- params, task_environment_.GetMainThreadTaskRunner(),
- std::move(on_destruction_closure));
+ params, std::move(on_destruction_closure),
+ base::BindLambdaForTesting(
+ [&](MockAudioDebugFileWriter* mock_audio_file_writer) {
+ mock_audio_file_writer_ = mock_audio_file_writer;
+ }));
}
MOCK_METHOD0(OnAudioDebugRecordingHelperDestruction, void());
@@ -148,9 +162,16 @@ class AudioDebugRecordingHelperTest : public ::testing::Test {
// Run |reply_callback| with a valid file for expected
// MockAudioDebugFileWriter::Start mocked call to happen.
std::move(reply_callback).Run(std::move(debug_file));
- // File can be removed right away because MockAudioDebugFileWriter::Start is
- // called synchronously.
- ASSERT_TRUE(base::DeleteFile(path));
+ paths_.push_back(std::move(path));
+ }
+
+ void VerifyAndDeleteWavFiles(size_t expected_file_count) {
+ DCHECK_EQ(expected_file_count, paths_.size());
+ task_environment_.RunUntilIdle();
+ for (base::FilePath& path : paths_) {
+ ASSERT_TRUE(base::DeleteFile(path));
+ }
+ paths_.clear();
}
protected:
@@ -160,6 +181,12 @@ class AudioDebugRecordingHelperTest : public ::testing::Test {
// The test task environment.
base::test::TaskEnvironment task_environment_;
+
+ // Used for testing to access the file writer having to go through the
+ // internal |file_writer_lock_|.
+ MockAudioDebugFileWriter* mock_audio_file_writer_;
+
+ std::vector<base::FilePath> paths_;
};
// Creates a helper with an on destruction closure, and verifies that it's run.
@@ -172,6 +199,8 @@ TEST_F(AudioDebugRecordingHelperTest, TestDestructionClosure) {
base::Unretained(this)));
EXPECT_CALL(*this, OnAudioDebugRecordingHelperDestruction());
+
+ VerifyAndDeleteWavFiles(0);
}
// Verifies that disable can be called without being enabled.
@@ -181,6 +210,8 @@ TEST_F(AudioDebugRecordingHelperTest, OnlyDisable) {
CreateRecordingHelper(params, base::OnceClosure());
recording_helper->DisableDebugRecording();
+
+ VerifyAndDeleteWavFiles(0);
}
TEST_F(AudioDebugRecordingHelperTest, EnableDisable) {
@@ -192,19 +223,17 @@ TEST_F(AudioDebugRecordingHelperTest, EnableDisable) {
stream_type_, id_,
base::BindOnce(&AudioDebugRecordingHelperTest::CreateWavFile,
base::Unretained(this)));
- EXPECT_CALL(*static_cast<MockAudioDebugFileWriter*>(
- recording_helper->debug_writer_.get()),
- Stop());
+ EXPECT_CALL(*mock_audio_file_writer_, DestructorCalled());
recording_helper->DisableDebugRecording();
recording_helper->EnableDebugRecording(
stream_type_, id_,
base::BindOnce(&AudioDebugRecordingHelperTest::CreateWavFile,
base::Unretained(this)));
- EXPECT_CALL(*static_cast<MockAudioDebugFileWriter*>(
- recording_helper->debug_writer_.get()),
- Stop());
+ EXPECT_CALL(*mock_audio_file_writer_, DestructorCalled());
recording_helper->DisableDebugRecording();
+
+ VerifyAndDeleteWavFiles(2);
}
TEST_F(AudioDebugRecordingHelperTest, OnData) {
@@ -212,7 +241,7 @@ TEST_F(AudioDebugRecordingHelperTest, OnData) {
// AudioBus, the other parameters are ignored.
const int number_of_frames = 100;
const AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
- ChannelLayout::CHANNEL_LAYOUT_STEREO, 0,
+ ChannelLayoutConfig::Stereo(), 0,
number_of_frames);
// Setup some data.
@@ -235,16 +264,13 @@ TEST_F(AudioDebugRecordingHelperTest, OnData) {
stream_type_, id_,
base::BindOnce(&AudioDebugRecordingHelperTest::CreateWavFile,
base::Unretained(this)));
- MockAudioDebugFileWriter* mock_audio_file_writer =
- static_cast<MockAudioDebugFileWriter*>(
- recording_helper->debug_writer_.get());
- mock_audio_file_writer->SetReferenceData(audio_bus.get());
+ mock_audio_file_writer_->SetReferenceData(audio_bus.get());
- EXPECT_CALL(*mock_audio_file_writer, DoWrite(_));
+ EXPECT_CALL(*mock_audio_file_writer_, DoWrite(_));
recording_helper->OnData(audio_bus.get());
base::RunLoop().RunUntilIdle();
- EXPECT_CALL(*mock_audio_file_writer, Stop());
+ EXPECT_CALL(*mock_audio_file_writer_, DestructorCalled());
recording_helper->DisableDebugRecording();
// Make sure we clear the loop before enabling again.
@@ -257,26 +283,21 @@ TEST_F(AudioDebugRecordingHelperTest, OnData) {
stream_type_, id_,
base::BindOnce(&AudioDebugRecordingHelperTest::CreateWavFile,
base::Unretained(this)));
- mock_audio_file_writer = static_cast<MockAudioDebugFileWriter*>(
- recording_helper->debug_writer_.get());
- mock_audio_file_writer->SetReferenceData(audio_bus.get());
+ mock_audio_file_writer_->SetReferenceData(audio_bus.get());
- EXPECT_CALL(*mock_audio_file_writer, DoWrite(_)).Times(2);
+ EXPECT_CALL(*mock_audio_file_writer_, DoWrite(_)).Times(2);
recording_helper->OnData(audio_bus.get());
recording_helper->OnData(audio_bus.get());
base::RunLoop().RunUntilIdle();
- // This call should not yield a DoWrite() call on the mock, since the message
- // loop isn't run until after disabling. WillWrite() is expected since
- // recording is enabled.
- recording_helper->OnData(audio_bus.get());
-
- EXPECT_CALL(*mock_audio_file_writer, Stop());
+ EXPECT_CALL(*mock_audio_file_writer_, DestructorCalled());
recording_helper->DisableDebugRecording();
- // This call should not yield a DoWrite() call on the mock either.
+ // This call should not yield a DoWrite() call on the mock.
recording_helper->OnData(audio_bus.get());
base::RunLoop().RunUntilIdle();
+
+ VerifyAndDeleteWavFiles(2);
}
} // namespace media
diff --git a/chromium/media/audio/audio_debug_recording_manager.cc b/chromium/media/audio/audio_debug_recording_manager.cc
index 10ae1a47957..9292e2d9724 100644
--- a/chromium/media/audio/audio_debug_recording_manager.cc
+++ b/chromium/media/audio/audio_debug_recording_manager.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,8 +8,7 @@
#include "base/bind.h"
#include "base/memory/ptr_util.h"
-#include "base/task/single_thread_task_runner.h"
-#include "base/task/task_runner_util.h"
+#include "base/threading/thread_checker.h"
namespace media {
@@ -18,15 +17,15 @@ namespace {
uint32_t g_next_stream_id = 1;
}
-AudioDebugRecordingManager::AudioDebugRecordingManager(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : task_runner_(std::move(task_runner)) {}
+AudioDebugRecordingManager::AudioDebugRecordingManager() {
+ DETACH_FROM_SEQUENCE(sequence_checker_);
+}
AudioDebugRecordingManager::~AudioDebugRecordingManager() = default;
void AudioDebugRecordingManager::EnableDebugRecording(
CreateWavFileCallback create_file_callback) {
- DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!create_file_callback.is_null());
create_file_callback_ = std::move(create_file_callback);
@@ -40,7 +39,7 @@ void AudioDebugRecordingManager::EnableDebugRecording(
}
void AudioDebugRecordingManager::DisableDebugRecording() {
- DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!create_file_callback_.is_null());
for (const auto& it : debug_recording_helpers_) {
AudioDebugRecordingHelper* recording_helper = it.second.first;
@@ -53,7 +52,7 @@ std::unique_ptr<AudioDebugRecorder>
AudioDebugRecordingManager::RegisterDebugRecordingSource(
AudioDebugRecordingStreamType stream_type,
const AudioParameters& params) {
- DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const uint32_t id = g_next_stream_id++;
@@ -61,7 +60,7 @@ AudioDebugRecordingManager::RegisterDebugRecordingSource(
// returned recorder. But to not require this we use a weak pointer.
std::unique_ptr<AudioDebugRecordingHelper> recording_helper =
CreateAudioDebugRecordingHelper(
- params, task_runner_,
+ params,
base::BindOnce(
&AudioDebugRecordingManager::UnregisterDebugRecordingSource,
weak_factory_.GetWeakPtr(), id));
@@ -78,7 +77,7 @@ AudioDebugRecordingManager::RegisterDebugRecordingSource(
}
void AudioDebugRecordingManager::UnregisterDebugRecordingSource(uint32_t id) {
- DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto it = debug_recording_helpers_.find(id);
DCHECK(it != debug_recording_helpers_.end());
debug_recording_helpers_.erase(id);
@@ -87,14 +86,13 @@ void AudioDebugRecordingManager::UnregisterDebugRecordingSource(uint32_t id) {
std::unique_ptr<AudioDebugRecordingHelper>
AudioDebugRecordingManager::CreateAudioDebugRecordingHelper(
const AudioParameters& params,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner,
base::OnceClosure on_destruction_closure) {
return std::make_unique<AudioDebugRecordingHelper>(
- params, task_runner, std::move(on_destruction_closure));
+ params, std::move(on_destruction_closure));
}
bool AudioDebugRecordingManager::IsDebugRecordingEnabled() {
- DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return !create_file_callback_.is_null();
}
diff --git a/chromium/media/audio/audio_debug_recording_manager.h b/chromium/media/audio/audio_debug_recording_manager.h
index 8c95c3c4694..8cf8a60194d 100644
--- a/chromium/media/audio/audio_debug_recording_manager.h
+++ b/chromium/media/audio/audio_debug_recording_manager.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -59,8 +59,7 @@ class MEDIA_EXPORT AudioDebugRecordingManager {
uint32_t id,
base::OnceCallback<void(base::File)> reply_callback)>;
- AudioDebugRecordingManager(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner);
+ AudioDebugRecordingManager();
AudioDebugRecordingManager(const AudioDebugRecordingManager&) = delete;
AudioDebugRecordingManager& operator=(const AudioDebugRecordingManager&) =
@@ -81,14 +80,8 @@ class MEDIA_EXPORT AudioDebugRecordingManager {
protected:
// Creates an AudioDebugRecordingHelper. Overridden by test.
virtual std::unique_ptr<AudioDebugRecordingHelper>
- CreateAudioDebugRecordingHelper(
- const AudioParameters& params,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner,
- base::OnceClosure on_destruction_closure);
-
- // The task runner this class lives on. Also handed to
- // AudioDebugRecordingHelpers.
- scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+ CreateAudioDebugRecordingHelper(const AudioParameters& params,
+ base::OnceClosure on_destruction_closure);
private:
FRIEND_TEST_ALL_PREFIXES(AudioDebugRecordingManagerTest,
@@ -115,6 +108,8 @@ class MEDIA_EXPORT AudioDebugRecordingManager {
// recording is enabled.
CreateWavFileCallback create_file_callback_;
+ SEQUENCE_CHECKER(sequence_checker_);
+
base::WeakPtrFactory<AudioDebugRecordingManager> weak_factory_{this};
};
diff --git a/chromium/media/audio/audio_debug_recording_manager_unittest.cc b/chromium/media/audio/audio_debug_recording_manager_unittest.cc
index 0fc61f00bd5..2afa4763792 100644
--- a/chromium/media/audio/audio_debug_recording_manager_unittest.cc
+++ b/chromium/media/audio/audio_debug_recording_manager_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,7 +9,6 @@
#include "base/bind.h"
#include "base/callback.h"
-#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "media/audio/audio_debug_recording_helper.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -53,13 +52,9 @@ void CreateWavFile(AudioDebugRecordingStreamType stream_type,
// Mock class to verify enable and disable calls.
class MockAudioDebugRecordingHelper : public AudioDebugRecordingHelper {
public:
- MockAudioDebugRecordingHelper(
- const AudioParameters& params,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner,
- base::OnceClosure on_destruction_closure)
- : AudioDebugRecordingHelper(params,
- std::move(task_runner),
- base::OnceClosure()),
+ MockAudioDebugRecordingHelper(const AudioParameters& params,
+ base::OnceClosure on_destruction_closure)
+ : AudioDebugRecordingHelper(params, base::OnceClosure()),
on_destruction_closure_in_mock_(std::move(on_destruction_closure)) {
if (g_expect_enable_after_create_helper)
EXPECT_CALL(*this, DoEnableDebugRecording(_, _));
@@ -95,9 +90,7 @@ class MockAudioDebugRecordingHelper : public AudioDebugRecordingHelper {
// function to create the above mock instead.
class AudioDebugRecordingManagerUnderTest : public AudioDebugRecordingManager {
public:
- AudioDebugRecordingManagerUnderTest(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : AudioDebugRecordingManager(std::move(task_runner)) {}
+ AudioDebugRecordingManagerUnderTest() = default;
AudioDebugRecordingManagerUnderTest(
const AudioDebugRecordingManagerUnderTest&) = delete;
@@ -109,19 +102,16 @@ class AudioDebugRecordingManagerUnderTest : public AudioDebugRecordingManager {
private:
std::unique_ptr<AudioDebugRecordingHelper> CreateAudioDebugRecordingHelper(
const AudioParameters& params,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner,
base::OnceClosure on_destruction_closure) override {
return std::make_unique<MockAudioDebugRecordingHelper>(
- params, std::move(task_runner),
- std::move(on_destruction_closure));
+ params, std::move(on_destruction_closure));
}
};
// The test fixture.
class AudioDebugRecordingManagerTest : public ::testing::Test {
public:
- AudioDebugRecordingManagerTest()
- : manager_(task_environment_.GetMainThreadTaskRunner()) {}
+ AudioDebugRecordingManagerTest() = default;
AudioDebugRecordingManagerTest(const AudioDebugRecordingManagerTest&) =
delete;
diff --git a/chromium/media/audio/audio_debug_recording_session.h b/chromium/media/audio/audio_debug_recording_session.h
index a3149b5348d..25145742faf 100644
--- a/chromium/media/audio/audio_debug_recording_session.h
+++ b/chromium/media/audio/audio_debug_recording_session.h
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_debug_recording_test.cc b/chromium/media/audio/audio_debug_recording_test.cc
index bc19e832ae1..31e5c8d69ad 100644
--- a/chromium/media/audio/audio_debug_recording_test.cc
+++ b/chromium/media/audio/audio_debug_recording_test.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_debug_recording_test.h b/chromium/media/audio/audio_debug_recording_test.h
index 48635771ae7..e0bb5ef6cac 100644
--- a/chromium/media/audio/audio_debug_recording_test.h
+++ b/chromium/media/audio/audio_debug_recording_test.h
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_device_description.cc b/chromium/media/audio/audio_device_description.cc
index a2d515b877c..a9cb921fc9c 100644
--- a/chromium/media/audio/audio_device_description.cc
+++ b/chromium/media/audio/audio_device_description.cc
@@ -1,4 +1,4 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_device_description.h b/chromium/media/audio/audio_device_description.h
index ccba18edbbb..23e8c0aff46 100644
--- a/chromium/media/audio/audio_device_description.h
+++ b/chromium/media/audio/audio_device_description.h
@@ -1,4 +1,4 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_device_info_accessor_for_tests.cc b/chromium/media/audio/audio_device_info_accessor_for_tests.cc
index 4b3eb1fc63b..9841922773b 100644
--- a/chromium/media/audio/audio_device_info_accessor_for_tests.cc
+++ b/chromium/media/audio/audio_device_info_accessor_for_tests.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_device_info_accessor_for_tests.h b/chromium/media/audio/audio_device_info_accessor_for_tests.h
index d2d7055010c..fb1d8f1e417 100644
--- a/chromium/media/audio/audio_device_info_accessor_for_tests.h
+++ b/chromium/media/audio/audio_device_info_accessor_for_tests.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_device_name.cc b/chromium/media/audio/audio_device_name.cc
index c14ba73a9b7..23d147a172b 100644
--- a/chromium/media/audio/audio_device_name.cc
+++ b/chromium/media/audio/audio_device_name.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_device_name.h b/chromium/media/audio/audio_device_name.h
index a0ecfb5d7fe..c483b27865f 100644
--- a/chromium/media/audio/audio_device_name.h
+++ b/chromium/media/audio/audio_device_name.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_device_thread.cc b/chromium/media/audio/audio_device_thread.cc
index 899740e0ab3..70eb11033fa 100644
--- a/chromium/media/audio/audio_device_thread.cc
+++ b/chromium/media/audio/audio_device_thread.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_device_thread.h b/chromium/media/audio/audio_device_thread.h
index 390afbb740f..c613f2eb454 100644
--- a/chromium/media/audio/audio_device_thread.h
+++ b/chromium/media/audio/audio_device_thread.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_encoders_unittest.cc b/chromium/media/audio/audio_encoders_unittest.cc
index d6fc72161da..c17c5053728 100644
--- a/chromium/media/audio/audio_encoders_unittest.cc
+++ b/chromium/media/audio/audio_encoders_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -532,12 +532,24 @@ TEST_P(AudioEncodersTest, Timestamps) {
int num_frames =
AudioTimestampHelper::TimeToFrames(duration, options_.sample_rate);
- size_t expected_padding = GetExpectedPadding();
+ size_t total_frames = num_frames * kCount;
+
+#if HAS_AAC_ENCODER
+ if (options_.codec == AudioCodec::kAAC &&
+ total_frames % kAacFramesPerBuffer) {
+ // We send data in chunks of kAacFramesPerBuffer to the encoder, padding
+ // it with silence when flushing.
+ // Round `total_frames` up to the nearest multiple of kAacFramesPerBuffer.
+ int chunks = (total_frames / kAacFramesPerBuffer) + 1;
+ total_frames = chunks * kAacFramesPerBuffer;
+ }
+#endif
+
+ total_frames += GetExpectedPadding();
// The encoder will have multiple outputs per input if `num_frames` is
// larger than `frames_per_buffer_`, and fewer outputs per input if it is
// smaller.
- size_t total_frames = num_frames * kCount + expected_padding;
size_t expected_outputs = total_frames / frames_per_buffer_;
// Round up if the division truncated. This is because the encoder will pad
diff --git a/chromium/media/audio/audio_features.cc b/chromium/media/audio/audio_features.cc
index 3e60bf27e33..d6235fa515d 100644
--- a/chromium/media/audio/audio_features.cc
+++ b/chromium/media/audio/audio_features.cc
@@ -1,4 +1,4 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,62 +9,65 @@
namespace features {
-// When the audio service in a separate process, kill it when a hang is
-// detected. It will be restarted when needed.
-const base::Feature kAudioServiceOutOfProcessKillAtHang{
- "AudioServiceOutOfProcessKillAtHang",
-#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
- BUILDFLAG(IS_CHROMEOS)
- base::FEATURE_ENABLED_BY_DEFAULT
-#else
- base::FEATURE_DISABLED_BY_DEFAULT
-#endif
-};
-
// If enabled, base::DumpWithoutCrashing is called whenever an audio service
// hang is detected.
-const base::Feature kDumpOnAudioServiceHang{"DumpOnAudioServiceHang",
- base::FEATURE_DISABLED_BY_DEFAULT};
+BASE_FEATURE(kDumpOnAudioServiceHang,
+ "DumpOnAudioServiceHang",
+ base::FEATURE_DISABLED_BY_DEFAULT);
#if BUILDFLAG(IS_ANDROID)
// Enables loading and using AAudio instead of OpenSLES on compatible devices,
// for audio output streams.
-const base::Feature kUseAAudioDriver{"UseAAudioDriver",
- base::FEATURE_ENABLED_BY_DEFAULT};
+BASE_FEATURE(kUseAAudioDriver,
+ "UseAAudioDriver",
+ base::FEATURE_ENABLED_BY_DEFAULT);
#endif
#if BUILDFLAG(IS_CHROMEOS)
-const base::Feature kCrOSSystemAEC{"CrOSSystemAECWithBoardTuningsAllowed",
- base::FEATURE_ENABLED_BY_DEFAULT};
-const base::Feature kCrOSSystemAECDeactivatedGroups{
- "CrOSSystemAECDeactivatedGroups", base::FEATURE_ENABLED_BY_DEFAULT};
-const base::Feature kCrOSEnforceSystemAecNsAgc{
- "CrOSEnforceSystemAecNsAgc", base::FEATURE_DISABLED_BY_DEFAULT};
-const base::Feature kCrOSEnforceSystemAecNs{"CrOSEnforceSystemAecNs",
- base::FEATURE_DISABLED_BY_DEFAULT};
-const base::Feature kCrOSEnforceSystemAecAgc{"CrOSEnforceSystemAecAgc",
- base::FEATURE_DISABLED_BY_DEFAULT};
-const base::Feature kCrOSEnforceSystemAec{"CrOSEnforceSystemAec",
- base::FEATURE_DISABLED_BY_DEFAULT};
+BASE_FEATURE(kCrOSSystemAEC,
+ "CrOSSystemAECWithBoardTuningsAllowed",
+ base::FEATURE_ENABLED_BY_DEFAULT);
+BASE_FEATURE(kCrOSSystemAECDeactivatedGroups,
+ "CrOSSystemAECDeactivatedGroups",
+ base::FEATURE_ENABLED_BY_DEFAULT);
+BASE_FEATURE(kCrOSEnforceSystemAecNsAgc,
+ "CrOSEnforceSystemAecNsAgc",
+ base::FEATURE_DISABLED_BY_DEFAULT);
+BASE_FEATURE(kCrOSEnforceSystemAecNs,
+ "CrOSEnforceSystemAecNs",
+ base::FEATURE_DISABLED_BY_DEFAULT);
+BASE_FEATURE(kCrOSEnforceSystemAecAgc,
+ "CrOSEnforceSystemAecAgc",
+ base::FEATURE_DISABLED_BY_DEFAULT);
+BASE_FEATURE(kCrOSEnforceSystemAec,
+ "CrOSEnforceSystemAec",
+ base::FEATURE_DISABLED_BY_DEFAULT);
-const base::Feature kCrOSDspBasedAecDeactivatedGroups{
- "CrOSDspBasedAecDeactivatedGroups", base::FEATURE_ENABLED_BY_DEFAULT};
-const base::Feature kCrOSDspBasedNsDeactivatedGroups{
- "CrOSDspBasedNsDeactivatedGroups", base::FEATURE_ENABLED_BY_DEFAULT};
-const base::Feature kCrOSDspBasedAgcDeactivatedGroups{
- "CrOSDspBasedAgcDeactivatedGroups", base::FEATURE_ENABLED_BY_DEFAULT};
+BASE_FEATURE(kCrOSDspBasedAecDeactivatedGroups,
+ "CrOSDspBasedAecDeactivatedGroups",
+ base::FEATURE_ENABLED_BY_DEFAULT);
+BASE_FEATURE(kCrOSDspBasedNsDeactivatedGroups,
+ "CrOSDspBasedNsDeactivatedGroups",
+ base::FEATURE_ENABLED_BY_DEFAULT);
+BASE_FEATURE(kCrOSDspBasedAgcDeactivatedGroups,
+ "CrOSDspBasedAgcDeactivatedGroups",
+ base::FEATURE_ENABLED_BY_DEFAULT);
-const base::Feature kCrOSDspBasedAecAllowed{"CrOSDspBasedAecAllowed",
- base::FEATURE_ENABLED_BY_DEFAULT};
-const base::Feature kCrOSDspBasedNsAllowed{"CrOSDspBasedNsAllowed",
- base::FEATURE_ENABLED_BY_DEFAULT};
-const base::Feature kCrOSDspBasedAgcAllowed{"CrOSDspBasedAgcAllowed",
- base::FEATURE_ENABLED_BY_DEFAULT};
+BASE_FEATURE(kCrOSDspBasedAecAllowed,
+ "CrOSDspBasedAecAllowed",
+ base::FEATURE_ENABLED_BY_DEFAULT);
+BASE_FEATURE(kCrOSDspBasedNsAllowed,
+ "CrOSDspBasedNsAllowed",
+ base::FEATURE_ENABLED_BY_DEFAULT);
+BASE_FEATURE(kCrOSDspBasedAgcAllowed,
+ "CrOSDspBasedAgcAllowed",
+ base::FEATURE_ENABLED_BY_DEFAULT);
#endif
#if BUILDFLAG(IS_WIN)
-const base::Feature kAllowIAudioClient3{"AllowIAudioClient3",
- base::FEATURE_ENABLED_BY_DEFAULT};
+BASE_FEATURE(kAllowIAudioClient3,
+ "AllowIAudioClient3",
+ base::FEATURE_ENABLED_BY_DEFAULT);
#endif
} // namespace features
diff --git a/chromium/media/audio/audio_features.h b/chromium/media/audio/audio_features.h
index 17b96b0ae0d..dadc99614ad 100644
--- a/chromium/media/audio/audio_features.h
+++ b/chromium/media/audio/audio_features.h
@@ -1,4 +1,4 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,30 +11,30 @@
namespace features {
-MEDIA_EXPORT extern const base::Feature kAudioServiceOutOfProcessKillAtHang;
-MEDIA_EXPORT extern const base::Feature kDumpOnAudioServiceHang;
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kAudioServiceOutOfProcessKillAtHang);
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kDumpOnAudioServiceHang);
#if BUILDFLAG(IS_ANDROID)
-MEDIA_EXPORT extern const base::Feature kUseAAudioDriver;
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kUseAAudioDriver);
#endif
#if BUILDFLAG(IS_CHROMEOS)
-MEDIA_EXPORT extern const base::Feature kCrOSSystemAEC;
-MEDIA_EXPORT extern const base::Feature kCrOSSystemAECDeactivatedGroups;
-MEDIA_EXPORT extern const base::Feature kCrOSEnforceSystemAecNsAgc;
-MEDIA_EXPORT extern const base::Feature kCrOSEnforceSystemAecNs;
-MEDIA_EXPORT extern const base::Feature kCrOSEnforceSystemAecAgc;
-MEDIA_EXPORT extern const base::Feature kCrOSEnforceSystemAec;
-MEDIA_EXPORT extern const base::Feature kCrOSDspBasedAecDeactivatedGroups;
-MEDIA_EXPORT extern const base::Feature kCrOSDspBasedNsDeactivatedGroups;
-MEDIA_EXPORT extern const base::Feature kCrOSDspBasedAgcDeactivatedGroups;
-MEDIA_EXPORT extern const base::Feature kCrOSDspBasedAecAllowed;
-MEDIA_EXPORT extern const base::Feature kCrOSDspBasedNsAllowed;
-MEDIA_EXPORT extern const base::Feature kCrOSDspBasedAgcAllowed;
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kCrOSSystemAEC);
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kCrOSSystemAECDeactivatedGroups);
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kCrOSEnforceSystemAecNsAgc);
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kCrOSEnforceSystemAecNs);
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kCrOSEnforceSystemAecAgc);
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kCrOSEnforceSystemAec);
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kCrOSDspBasedAecDeactivatedGroups);
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kCrOSDspBasedNsDeactivatedGroups);
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kCrOSDspBasedAgcDeactivatedGroups);
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kCrOSDspBasedAecAllowed);
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kCrOSDspBasedNsAllowed);
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kCrOSDspBasedAgcAllowed);
#endif
#if BUILDFLAG(IS_WIN)
-MEDIA_EXPORT extern const base::Feature kAllowIAudioClient3;
+MEDIA_EXPORT BASE_DECLARE_FEATURE(kAllowIAudioClient3);
#endif
} // namespace features
diff --git a/chromium/media/audio/audio_input_delegate.cc b/chromium/media/audio/audio_input_delegate.cc
index 1310c00d27f..e6cd768993e 100644
--- a/chromium/media/audio/audio_input_delegate.cc
+++ b/chromium/media/audio/audio_input_delegate.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_input_delegate.h b/chromium/media/audio/audio_input_delegate.h
index babd1b48128..6b80ad1a893 100644
--- a/chromium/media/audio/audio_input_delegate.h
+++ b/chromium/media/audio/audio_input_delegate.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_input_device.cc b/chromium/media/audio/audio_input_device.cc
index 0b46627e329..cb8760bb52f 100644
--- a/chromium/media/audio/audio_input_device.cc
+++ b/chromium/media/audio/audio_input_device.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_input_device.h b/chromium/media/audio/audio_input_device.h
index 2cb581fd597..b298970ce7a 100644
--- a/chromium/media/audio/audio_input_device.h
+++ b/chromium/media/audio/audio_input_device.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_input_device_unittest.cc b/chromium/media/audio/audio_input_device_unittest.cc
index fe09a08b237..794db512747 100644
--- a/chromium/media/audio/audio_input_device_unittest.cc
+++ b/chromium/media/audio/audio_input_device_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -86,7 +86,7 @@ ACTION_P(ReportStateChange, device) {
// Verify that we get an OnCaptureError() callback if CreateStream fails.
TEST_P(AudioInputDeviceTest, FailToCreateStream) {
AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_STEREO, 48000, 480);
+ ChannelLayoutConfig::Stereo(), 48000, 480);
MockCaptureCallback callback;
MockAudioInputIPC* input_ipc = new MockAudioInputIPC();
@@ -105,7 +105,7 @@ TEST_P(AudioInputDeviceTest, FailToCreateStream) {
TEST_P(AudioInputDeviceTest, CreateStream) {
AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_STEREO, 48000, 480);
+ ChannelLayoutConfig::Stereo(), 48000, 480);
base::MappedReadOnlyRegion shared_memory;
CancelableSyncSocket browser_socket;
CancelableSyncSocket renderer_socket;
diff --git a/chromium/media/audio/audio_input_ipc.cc b/chromium/media/audio/audio_input_ipc.cc
index e18a9b8b4b5..cce1edb3bc2 100644
--- a/chromium/media/audio/audio_input_ipc.cc
+++ b/chromium/media/audio/audio_input_ipc.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_input_ipc.h b/chromium/media/audio/audio_input_ipc.h
index 28663a98ab5..091b4f3991e 100644
--- a/chromium/media/audio/audio_input_ipc.h
+++ b/chromium/media/audio/audio_input_ipc.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_input_stream_data_interceptor.cc b/chromium/media/audio/audio_input_stream_data_interceptor.cc
index 332b3aeaf79..6ef80aba9ea 100644
--- a/chromium/media/audio/audio_input_stream_data_interceptor.cc
+++ b/chromium/media/audio/audio_input_stream_data_interceptor.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_input_stream_data_interceptor.h b/chromium/media/audio/audio_input_stream_data_interceptor.h
index c6f9d7dcb24..2f28085af92 100644
--- a/chromium/media/audio/audio_input_stream_data_interceptor.h
+++ b/chromium/media/audio/audio_input_stream_data_interceptor.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_input_stream_data_interceptor_unittest.cc b/chromium/media/audio/audio_input_stream_data_interceptor_unittest.cc
index 3a2ec62f218..0125660f32e 100644
--- a/chromium/media/audio/audio_input_stream_data_interceptor_unittest.cc
+++ b/chromium/media/audio/audio_input_stream_data_interceptor_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_input_unittest.cc b/chromium/media/audio/audio_input_unittest.cc
index 34a16e85609..5602d3de050 100644
--- a/chromium/media/audio/audio_input_unittest.cc
+++ b/chromium/media/audio/audio_input_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_io.cc b/chromium/media/audio/audio_io.cc
index 36f94b812d1..0f9a3079a97 100644
--- a/chromium/media/audio/audio_io.cc
+++ b/chromium/media/audio/audio_io.cc
@@ -1,4 +1,4 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
+// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_io.h b/chromium/media/audio/audio_io.h
index 09133b94fa9..23077877174 100644
--- a/chromium/media/audio/audio_io.h
+++ b/chromium/media/audio/audio_io.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_logging.h b/chromium/media/audio/audio_logging.h
index 764b8b2ba57..c6b1e101c63 100644
--- a/chromium/media/audio/audio_logging.h
+++ b/chromium/media/audio/audio_logging.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
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 9f219dea545..7e02e2fb988 100644
--- a/chromium/media/audio/audio_low_latency_input_output_unittest.cc
+++ b/chromium/media/audio/audio_low_latency_input_output_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -326,8 +326,10 @@ class StreamWrapper {
private:
StreamType* CreateStream() {
StreamType* stream = StreamTraits::CreateStream(
- audio_manager_, AudioParameters(format_, channel_layout_, sample_rate_,
- samples_per_packet_));
+ audio_manager_,
+ AudioParameters(format_,
+ ChannelLayoutConfig(channel_layout_, channels()),
+ sample_rate_, samples_per_packet_));
EXPECT_TRUE(stream);
return stream;
}
diff --git a/chromium/media/audio/audio_manager.cc b/chromium/media/audio/audio_manager.cc
index e543c4f7fda..6305a9a0538 100644
--- a/chromium/media/audio/audio_manager.cc
+++ b/chromium/media/audio/audio_manager.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_manager.h b/chromium/media/audio/audio_manager.h
index 708fd094871..30d590d44ce 100644
--- a/chromium/media/audio/audio_manager.h
+++ b/chromium/media/audio/audio_manager.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -28,6 +28,7 @@ class AudioManagerPowerUser;
namespace media {
+class AecdumpRecordingManager;
class AudioDebugRecordingManager;
class AudioInputStream;
class AudioManager;
@@ -170,6 +171,11 @@ class MEDIA_EXPORT AudioManager {
// thread (GetTaskRunner()).
virtual AudioDebugRecordingManager* GetAudioDebugRecordingManager() = 0;
+ // Set aecdump recording manager. This can only be called on AudioManager's
+ // thread (GetTaskRunner()).
+ virtual void SetAecDumpRecordingManager(
+ base::WeakPtr<AecdumpRecordingManager> aecdump_recording_manager) = 0;
+
// Gets the name of the audio manager (e.g., Windows, Mac, PulseAudio).
virtual const char* GetName() = 0;
diff --git a/chromium/media/audio/audio_manager_base.cc b/chromium/media/audio/audio_manager_base.cc
index 7090de5b88d..c7e11c8907a 100644
--- a/chromium/media/audio/audio_manager_base.cc
+++ b/chromium/media/audio/audio_manager_base.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -12,6 +12,7 @@
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/observer_list.h"
+#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
@@ -98,26 +99,6 @@ struct AudioManagerBase::DispatcherParams {
std::unique_ptr<AudioOutputDispatcher> dispatcher;
};
-class AudioManagerBase::CompareByParams {
- public:
- explicit CompareByParams(const DispatcherParams* dispatcher)
- : dispatcher_(dispatcher) {}
- bool operator()(
- const std::unique_ptr<DispatcherParams>& dispatcher_in) const {
- // We will reuse the existing dispatcher when:
- // 1) Unified IO is not used, input_params and output_params of the
- // existing dispatcher are the same as the requested dispatcher.
- // 2) Unified IO is used, input_params and output_params of the existing
- // dispatcher are the same as the request dispatcher.
- return (dispatcher_->input_params.Equals(dispatcher_in->input_params) &&
- dispatcher_->output_params.Equals(dispatcher_in->output_params) &&
- dispatcher_->output_device_id == dispatcher_in->output_device_id);
- }
-
- private:
- raw_ptr<const DispatcherParams> dispatcher_;
-};
-
AudioManagerBase::AudioManagerBase(std::unique_ptr<AudioThread> audio_thread,
AudioLogFactory* audio_log_factory)
: AudioManager(std::move(audio_thread)),
@@ -424,12 +405,21 @@ AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy(
NOTREACHED();
}
- std::unique_ptr<DispatcherParams> dispatcher_params =
- std::make_unique<DispatcherParams>(params, output_params,
- output_device_id);
-
- auto it = std::find_if(output_dispatchers_.begin(), output_dispatchers_.end(),
- CompareByParams(dispatcher_params.get()));
+ auto dispatcher_params = std::make_unique<DispatcherParams>(
+ params, output_params, output_device_id);
+
+ auto it = base::ranges::find_if(
+ output_dispatchers_,
+ [&](const std::unique_ptr<DispatcherParams>& dispatcher) {
+ // We will reuse the existing dispatcher when:
+ // 1) Unified IO is not used, input_params and output_params of the
+ // existing dispatcher are the same as the requested dispatcher.
+ // 2) Unified IO is used, input_params and output_params of the existing
+ // dispatcher are the same as the request dispatcher.
+ return params.Equals(dispatcher->input_params) &&
+ output_params.Equals(dispatcher->output_params) &&
+ output_device_id == dispatcher->output_device_id;
+ });
if (it != output_dispatchers_.end())
return (*it)->dispatcher->CreateStreamProxy();
@@ -620,13 +610,12 @@ void AudioManagerBase::InitializeDebugRecording() {
}
DCHECK(!debug_recording_manager_);
- debug_recording_manager_ = CreateAudioDebugRecordingManager(GetTaskRunner());
+ debug_recording_manager_ = CreateAudioDebugRecordingManager();
}
std::unique_ptr<AudioDebugRecordingManager>
-AudioManagerBase::CreateAudioDebugRecordingManager(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
- return std::make_unique<AudioDebugRecordingManager>(std::move(task_runner));
+AudioManagerBase::CreateAudioDebugRecordingManager() {
+ return std::make_unique<AudioDebugRecordingManager>();
}
AudioDebugRecordingManager* AudioManagerBase::GetAudioDebugRecordingManager() {
@@ -634,4 +623,9 @@ AudioDebugRecordingManager* AudioManagerBase::GetAudioDebugRecordingManager() {
return debug_recording_manager_.get();
}
+void AudioManagerBase::SetAecDumpRecordingManager(
+ base::WeakPtr<AecdumpRecordingManager>) {
+ // This is no-op by default.
+}
+
} // namespace media
diff --git a/chromium/media/audio/audio_manager_base.h b/chromium/media/audio/audio_manager_base.h
index 046aeef2691..ffa8637177f 100644
--- a/chromium/media/audio/audio_manager_base.h
+++ b/chromium/media/audio/audio_manager_base.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -18,6 +18,7 @@
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
+#include "media/audio/aecdump_recording_manager.h"
#include "media/audio/audio_debug_recording_manager.h"
#include "media/audio/audio_device_name.h"
#include "media/audio/audio_manager.h"
@@ -160,10 +161,12 @@ class MEDIA_EXPORT AudioManagerBase : public AudioManager {
std::string GetCommunicationsOutputDeviceID() override;
virtual std::unique_ptr<AudioDebugRecordingManager>
- CreateAudioDebugRecordingManager(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner);
+ CreateAudioDebugRecordingManager();
AudioDebugRecordingManager* GetAudioDebugRecordingManager() final;
+ void SetAecDumpRecordingManager(base::WeakPtr<AecdumpRecordingManager>
+ aecdump_recording_manager) override;
+
// These functions assign group ids to devices based on their device ids. The
// default implementation is an attempt to do this based on
// GetAssociatedOutputDeviceID. They may be overridden by subclasses that want
@@ -181,8 +184,6 @@ class MEDIA_EXPORT AudioManagerBase : public AudioManager {
struct DispatcherParams;
typedef std::vector<std::unique_ptr<DispatcherParams>> AudioOutputDispatchers;
- class CompareByParams;
-
// AudioManager:
void InitializeDebugRecording() final;
diff --git a/chromium/media/audio/audio_manager_unittest.cc b/chromium/media/audio/audio_manager_unittest.cc
index 161ab95f7b5..86f0a01accd 100644
--- a/chromium/media/audio/audio_manager_unittest.cc
+++ b/chromium/media/audio/audio_manager_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,6 +14,7 @@
#include "base/environment.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
+#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
@@ -129,18 +130,20 @@ 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,
- 0);
+const AudioNode kInternalSpeaker(
+ false,
+ kInternalSpeakerId,
+ true,
+ kInternalSpeakerStableDeviceId,
+ kInternalSpeakerStableDeviceId ^ 0xFF,
+ "Internal Speaker",
+ "INTERNAL_SPEAKER",
+ "Speaker",
+ false,
+ 0,
+ 2,
+ 0,
+ 25); // output nodes should get a valid number (>0)
const AudioNode kInternalMic(true,
kInternalMicId,
@@ -153,33 +156,38 @@ const AudioNode kInternalMic(true,
false,
0,
1,
- 1); // EFFECT_TYPE_NOISE_CANCELLATION
-
-const AudioNode kJabraSpeaker1(false,
- kJabraSpeaker1Id,
- true,
- kJabraSpeaker1StableDeviceId,
- kJabraSpeaker1StableDeviceId ^ 0xFF,
- "Jabra Speaker",
- "USB",
- "Jabra Speaker 1",
- false,
- 0,
- 2, // expects CHANNEL_LAYOUT_STEREO
- 0);
-
-const AudioNode kJabraSpeaker2(false,
- kJabraSpeaker2Id,
- true,
- kJabraSpeaker2StableDeviceId,
- kJabraSpeaker2StableDeviceId ^ 0xFF,
- "Jabra Speaker",
- "USB",
- "Jabra Speaker 2",
- false,
- 0,
- 6, // expects CHANNEL_LAYOUT_5_1
- 0);
+ 1, // EFFECT_TYPE_NOISE_CANCELLATION
+ 0); // input nodes this value is invalid (0)
+
+const AudioNode kJabraSpeaker1(
+ false,
+ kJabraSpeaker1Id,
+ true,
+ kJabraSpeaker1StableDeviceId,
+ kJabraSpeaker1StableDeviceId ^ 0xFF,
+ "Jabra Speaker",
+ "USB",
+ "Jabra Speaker 1",
+ false,
+ 0,
+ 2, // expects CHANNEL_LAYOUT_STEREO
+ 0,
+ 25); // output nodes should get a valid number (>0)
+
+const AudioNode kJabraSpeaker2(
+ false,
+ kJabraSpeaker2Id,
+ true,
+ kJabraSpeaker2StableDeviceId,
+ kJabraSpeaker2StableDeviceId ^ 0xFF,
+ "Jabra Speaker",
+ "USB",
+ "Jabra Speaker 2",
+ false,
+ 0,
+ 6, // expects CHANNEL_LAYOUT_5_1
+ 0,
+ 25); // output nodes should get a valid number (>0)
const AudioNode kHDMIOutput(false,
kHDMIOutputId,
@@ -192,7 +200,8 @@ const AudioNode kHDMIOutput(false,
false,
0,
8, // expects CHANNEL_LAYOUT_7_1
- 0);
+ 0,
+ 25); // output nodes should get a valid number (>0)
const AudioNode kJabraMic1(true,
kJabraMic1Id,
@@ -205,7 +214,8 @@ const AudioNode kJabraMic1(true,
false,
0,
1,
- 0);
+ 0,
+ 0); // input nodes this value is invalid (0)
const AudioNode kJabraMic2(true,
kJabraMic2Id,
@@ -218,7 +228,8 @@ const AudioNode kJabraMic2(true,
false,
0,
1,
- 0);
+ 0,
+ 0); // input nodes this value is invalid (0)
const AudioNode kUSBCameraMic(true,
kWebcamMicId,
@@ -231,7 +242,8 @@ const AudioNode kUSBCameraMic(true,
false,
0,
1,
- 0);
+ 0,
+ 0); // input nodes this value is invalid (0)
#endif // defined(USE_CRAS)
const char kRealDefaultInputDeviceID[] = "input2";
@@ -272,7 +284,7 @@ class AudioManagerTest : public ::testing::Test {
public:
void HandleDefaultDeviceIDsTest() {
AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_STEREO, 48000, 2048);
+ ChannelLayoutConfig::Stereo(), 48000, 2048);
// Create a stream with the default device id "".
AudioOutputStream* stream =
@@ -334,7 +346,8 @@ class AudioManagerTest : public ::testing::Test {
}
AudioParameters GetPreferredOutputStreamParameters(
- ChannelLayout channel_layout, int32_t user_buffer_size = 0) {
+ const ChannelLayoutConfig& channel_layout_config,
+ int32_t user_buffer_size = 0) {
// Generated AudioParameters should follow the same rule as in
// AudioManagerCras::GetPreferredOutputStreamParameters().
int sample_rate = kDefaultSampleRate;
@@ -342,8 +355,8 @@ class AudioManagerTest : public ::testing::Test {
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::AUDIO_PCM_LOW_LATENCY, channel_layout_config,
+ sample_rate, buffer_size,
AudioParameters::HardwareCapabilities(limits::kMinAudioBufferSize,
limits::kMaxAudioBufferSize));
}
@@ -438,11 +451,8 @@ class AudioManagerTest : public ::testing::Test {
// 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;
- });
+ AudioDeviceDescriptions::const_iterator it = base::ranges::find(
+ device_descriptions, device_id, &AudioDeviceDescription::unique_id);
EXPECT_NE(it, device_descriptions.end());
return it->group_id;
@@ -579,18 +589,18 @@ TEST_F(AudioManagerTest, CheckOutputStreamParametersCras) {
// should be reflected to the specific output device.
params = device_info_accessor_->GetOutputStreamParameters(
base::NumberToString(kJabraSpeaker1Id));
- golden_params = GetPreferredOutputStreamParameters(
- ChannelLayout::CHANNEL_LAYOUT_STEREO);
+ golden_params =
+ GetPreferredOutputStreamParameters(ChannelLayoutConfig::Stereo());
EXPECT_TRUE(params.Equals(golden_params));
params = device_info_accessor_->GetOutputStreamParameters(
base::NumberToString(kJabraSpeaker2Id));
golden_params = GetPreferredOutputStreamParameters(
- ChannelLayout::CHANNEL_LAYOUT_5_1);
+ ChannelLayoutConfig::FromLayout<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);
+ ChannelLayoutConfig::FromLayout<ChannelLayout::CHANNEL_LAYOUT_7_1>());
EXPECT_TRUE(params.Equals(golden_params));
// Set user-provided audio buffer size by command line, then check the buffer
@@ -608,26 +618,30 @@ TEST_F(AudioManagerTest, CheckOutputStreamParametersCras) {
params = device_info_accessor_->GetOutputStreamParameters(
AudioDeviceDescription::kDefaultDeviceId);
golden_params = GetPreferredOutputStreamParameters(
- ChannelLayout::CHANNEL_LAYOUT_STEREO, 2048);
+ ChannelLayoutConfig::FromLayout<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);
+ ChannelLayoutConfig::FromLayout<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);
+ ChannelLayoutConfig::FromLayout<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);
+ ChannelLayoutConfig::FromLayout<ChannelLayout::CHANNEL_LAYOUT_STEREO>(),
+ 2048);
EXPECT_TRUE(params.Equals(golden_params));
}
diff --git a/chromium/media/audio/audio_opus_encoder.cc b/chromium/media/audio/audio_opus_encoder.cc
index eff6da899d7..235a2356b6f 100644
--- a/chromium/media/audio/audio_opus_encoder.cc
+++ b/chromium/media/audio/audio_opus_encoder.cc
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -46,9 +46,8 @@ AudioParameters CreateInputParams(const AudioEncoder::Options& options) {
kOpusPreferredBufferDurationMs /
base::Time::kMillisecondsPerSecond;
AudioParameters result(media::AudioParameters::AUDIO_PCM_LINEAR,
- media::CHANNEL_LAYOUT_DISCRETE, options.sample_rate,
- frames_per_buffer);
- result.set_channels_for_discrete(options.channels);
+ {media::CHANNEL_LAYOUT_DISCRETE, options.channels},
+ options.sample_rate, frames_per_buffer);
return result;
}
@@ -68,9 +67,10 @@ AudioParameters CreateOpusCompatibleParams(const AudioParameters& params) {
const int frames_per_buffer = used_rate * kOpusPreferredBufferDurationMs /
base::Time::kMillisecondsPerSecond;
- AudioParameters result(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- GuessChannelLayout(std::min(params.channels(), 2)),
- used_rate, frames_per_buffer);
+ AudioParameters result(
+ AudioParameters::AUDIO_PCM_LOW_LATENCY,
+ ChannelLayoutConfig::Guess(std::min(params.channels(), 2)), used_rate,
+ frames_per_buffer);
return result;
}
diff --git a/chromium/media/audio/audio_opus_encoder.h b/chromium/media/audio/audio_opus_encoder.h
index d439c5bde02..846a6618e91 100644
--- a/chromium/media/audio/audio_opus_encoder.h
+++ b/chromium/media/audio/audio_opus_encoder.h
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_delegate.cc b/chromium/media/audio/audio_output_delegate.cc
index 98e11e96173..c52f6d2129a 100644
--- a/chromium/media/audio/audio_output_delegate.cc
+++ b/chromium/media/audio/audio_output_delegate.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_delegate.h b/chromium/media/audio/audio_output_delegate.h
index 607f4f8aa70..28c2f9887ec 100644
--- a/chromium/media/audio/audio_output_delegate.h
+++ b/chromium/media/audio/audio_output_delegate.h
@@ -1,4 +1,4 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_device.cc b/chromium/media/audio/audio_output_device.cc
index c1b8347018d..301bff6bd02 100644
--- a/chromium/media/audio/audio_output_device.cc
+++ b/chromium/media/audio/audio_output_device.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_device.h b/chromium/media/audio/audio_output_device.h
index a8bfc71ba20..6a72534df0a 100644
--- a/chromium/media/audio/audio_output_device.h
+++ b/chromium/media/audio/audio_output_device.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
diff --git a/chromium/media/audio/audio_output_device_thread_callback.cc b/chromium/media/audio/audio_output_device_thread_callback.cc
index 6afce2f04bf..29109fcbaa1 100644
--- a/chromium/media/audio/audio_output_device_thread_callback.cc
+++ b/chromium/media/audio/audio_output_device_thread_callback.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_device_thread_callback.h b/chromium/media/audio/audio_output_device_thread_callback.h
index b98d8b56cde..8ea3f3923d0 100644
--- a/chromium/media/audio/audio_output_device_thread_callback.h
+++ b/chromium/media/audio/audio_output_device_thread_callback.h
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_device_unittest.cc b/chromium/media/audio/audio_output_device_unittest.cc
index 3474215935b..0e1136b1e17 100644
--- a/chromium/media/audio/audio_output_device_unittest.cc
+++ b/chromium/media/audio/audio_output_device_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -123,7 +123,7 @@ class AudioOutputDeviceTest : public testing::Test {
AudioOutputDeviceTest::AudioOutputDeviceTest()
: device_status_(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL) {
default_audio_parameters_.Reset(AudioParameters::AUDIO_PCM_LINEAR,
- CHANNEL_LAYOUT_STEREO, 48000, 1024);
+ ChannelLayoutConfig::Stereo(), 48000, 1024);
SetDevice(kDefaultDeviceId);
}
diff --git a/chromium/media/audio/audio_output_dispatcher.cc b/chromium/media/audio/audio_output_dispatcher.cc
index 3d4f391795b..97655cdcc86 100644
--- a/chromium/media/audio/audio_output_dispatcher.cc
+++ b/chromium/media/audio/audio_output_dispatcher.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_dispatcher.h b/chromium/media/audio/audio_output_dispatcher.h
index 063c95bdf44..50a8b0b916e 100644
--- a/chromium/media/audio/audio_output_dispatcher.h
+++ b/chromium/media/audio/audio_output_dispatcher.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_dispatcher_impl.cc b/chromium/media/audio/audio_output_dispatcher_impl.cc
index dd9279fd6d7..231f565fb7b 100644
--- a/chromium/media/audio/audio_output_dispatcher_impl.cc
+++ b/chromium/media/audio/audio_output_dispatcher_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_dispatcher_impl.h b/chromium/media/audio/audio_output_dispatcher_impl.h
index 09decca2de4..c793a226492 100644
--- a/chromium/media/audio/audio_output_dispatcher_impl.h
+++ b/chromium/media/audio/audio_output_dispatcher_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_ipc.cc b/chromium/media/audio/audio_output_ipc.cc
index eb07d30e55a..0782da5f20d 100644
--- a/chromium/media/audio/audio_output_ipc.cc
+++ b/chromium/media/audio/audio_output_ipc.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_ipc.h b/chromium/media/audio/audio_output_ipc.h
index 7fb9898e80b..1b77a77862c 100644
--- a/chromium/media/audio/audio_output_ipc.h
+++ b/chromium/media/audio/audio_output_ipc.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_proxy.cc b/chromium/media/audio/audio_output_proxy.cc
index d205d67091e..5f17fe6f804 100644
--- a/chromium/media/audio/audio_output_proxy.cc
+++ b/chromium/media/audio/audio_output_proxy.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_proxy.h b/chromium/media/audio/audio_output_proxy.h
index 13c7fc27152..118677fa54b 100644
--- a/chromium/media/audio/audio_output_proxy.h
+++ b/chromium/media/audio/audio_output_proxy.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_proxy_unittest.cc b/chromium/media/audio/audio_output_proxy_unittest.cc
index 58ff35441a3..ac25a224306 100644
--- a/chromium/media/audio/audio_output_proxy_unittest.cc
+++ b/chromium/media/audio/audio_output_proxy_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -173,7 +173,7 @@ class AudioOutputProxyTest : public testing::Test {
// FakeAudioOutputStream will keep the message loop busy indefinitely; i.e.,
// RunUntilIdle() will never terminate.
params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
- CHANNEL_LAYOUT_STEREO, 8000, 2048);
+ ChannelLayoutConfig::Stereo(), 8000, 2048);
InitDispatcher(base::Milliseconds(kTestCloseDelayMs));
}
@@ -501,8 +501,9 @@ class AudioOutputResamplerTest : public AudioOutputProxyTest {
// Use a low sample rate and large buffer size when testing otherwise the
// FakeAudioOutputStream will keep the message loop busy indefinitely; i.e.,
// RunUntilIdle() will never terminate.
- resampler_params_ = AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_STEREO, 16000, 1024);
+ resampler_params_ =
+ AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
+ ChannelLayoutConfig::Stereo(), 16000, 1024);
resampler_ = std::make_unique<AudioOutputResampler>(
&manager(), params_, resampler_params_, std::string(), close_delay,
base::BindRepeating(&RegisterDebugRecording));
diff --git a/chromium/media/audio/audio_output_resampler.cc b/chromium/media/audio/audio_output_resampler.cc
index cd2c2baf209..fca550200fc 100644
--- a/chromium/media/audio/audio_output_resampler.cc
+++ b/chromium/media/audio/audio_output_resampler.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_resampler.h b/chromium/media/audio/audio_output_resampler.h
index f9d9c3b21b6..96aab4a95a6 100644
--- a/chromium/media/audio/audio_output_resampler.h
+++ b/chromium/media/audio/audio_output_resampler.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_stream_sink.cc b/chromium/media/audio/audio_output_stream_sink.cc
index 1dff40e1449..a8732537079 100644
--- a/chromium/media/audio/audio_output_stream_sink.cc
+++ b/chromium/media/audio/audio_output_stream_sink.cc
@@ -1,4 +1,4 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_stream_sink.h b/chromium/media/audio/audio_output_stream_sink.h
index 2589a264e4f..308033579c2 100644
--- a/chromium/media/audio/audio_output_stream_sink.h
+++ b/chromium/media/audio/audio_output_stream_sink.h
@@ -1,4 +1,4 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_output_unittest.cc b/chromium/media/audio/audio_output_unittest.cc
index 19aa1f115a7..3de3f6e5c29 100644
--- a/chromium/media/audio/audio_output_unittest.cc
+++ b/chromium/media/audio/audio_output_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_sink_parameters.cc b/chromium/media/audio/audio_sink_parameters.cc
index 8287fa07779..52d9fc42115 100644
--- a/chromium/media/audio/audio_sink_parameters.cc
+++ b/chromium/media/audio/audio_sink_parameters.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_sink_parameters.h b/chromium/media/audio/audio_sink_parameters.h
index a96679bb3f4..51939d03012 100644
--- a/chromium/media/audio/audio_sink_parameters.h
+++ b/chromium/media/audio/audio_sink_parameters.h
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_source_parameters.cc b/chromium/media/audio/audio_source_parameters.cc
index 8585904ff81..92b10a459ad 100644
--- a/chromium/media/audio/audio_source_parameters.cc
+++ b/chromium/media/audio/audio_source_parameters.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_source_parameters.h b/chromium/media/audio/audio_source_parameters.h
index d0e36fed089..2be9b2e22f2 100644
--- a/chromium/media/audio/audio_source_parameters.h
+++ b/chromium/media/audio/audio_source_parameters.h
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_system.cc b/chromium/media/audio/audio_system.cc
index 81c58aa4a3a..132cbfbf27b 100644
--- a/chromium/media/audio/audio_system.cc
+++ b/chromium/media/audio/audio_system.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_system.h b/chromium/media/audio/audio_system.h
index 9701570bb73..07811594c15 100644
--- a/chromium/media/audio/audio_system.h
+++ b/chromium/media/audio/audio_system.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_system_helper.cc b/chromium/media/audio/audio_system_helper.cc
index f30c7172073..4ea32545c38 100644
--- a/chromium/media/audio/audio_system_helper.cc
+++ b/chromium/media/audio/audio_system_helper.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,7 +22,8 @@ absl::optional<AudioParameters> TryToFixChannels(
// better to report a valid value if this is the only problem.
if (params.channels() > limits::kMaxChannels) {
DCHECK(params.channel_layout() == CHANNEL_LAYOUT_DISCRETE);
- params_copy.set_channels_for_discrete(limits::kMaxChannels);
+ params_copy.SetChannelLayoutConfig(CHANNEL_LAYOUT_DISCRETE,
+ limits::kMaxChannels);
}
return params_copy.IsValid() ? params_copy
diff --git a/chromium/media/audio/audio_system_helper.h b/chromium/media/audio/audio_system_helper.h
index d151859e0f4..35a0b6532b4 100644
--- a/chromium/media/audio/audio_system_helper.h
+++ b/chromium/media/audio/audio_system_helper.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_system_impl.cc b/chromium/media/audio/audio_system_impl.cc
index ee04c3e6e5e..905b84808c5 100644
--- a/chromium/media/audio/audio_system_impl.cc
+++ b/chromium/media/audio/audio_system_impl.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,7 +9,6 @@
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/task/single_thread_task_runner.h"
-#include "base/task/task_runner_util.h"
#include "media/audio/audio_device_description.h"
#include "media/audio/audio_manager.h"
#include "media/base/bind_to_current_loop.h"
diff --git a/chromium/media/audio/audio_system_impl.h b/chromium/media/audio/audio_system_impl.h
index b1cdfb4b40d..207b327beb1 100644
--- a/chromium/media/audio/audio_system_impl.h
+++ b/chromium/media/audio/audio_system_impl.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_system_impl_unittest.cc b/chromium/media/audio/audio_system_impl_unittest.cc
index 8375d35908c..f77fe27af26 100644
--- a/chromium/media/audio/audio_system_impl_unittest.cc
+++ b/chromium/media/audio/audio_system_impl_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_system_test_util.cc b/chromium/media/audio/audio_system_test_util.cc
index 7e31a7fff0b..afac0bb24ab 100644
--- a/chromium/media/audio/audio_system_test_util.cc
+++ b/chromium/media/audio/audio_system_test_util.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_system_test_util.h b/chromium/media/audio/audio_system_test_util.h
index 05fb3d63a5c..71ebca82992 100644
--- a/chromium/media/audio/audio_system_test_util.h
+++ b/chromium/media/audio/audio_system_test_util.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -105,18 +105,18 @@ class AudioSystemTestTemplate : public T {
void SetUp() override {
T::SetUp();
- input_params_ =
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
- AudioParameters::kTelephoneSampleRate,
- AudioParameters::kTelephoneSampleRate / 10);
- output_params_ =
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
- AudioParameters::kTelephoneSampleRate,
- AudioParameters::kTelephoneSampleRate / 20);
- default_output_params_ =
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
- AudioParameters::kTelephoneSampleRate,
- AudioParameters::kTelephoneSampleRate / 30);
+ input_params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Mono(),
+ AudioParameters::kTelephoneSampleRate,
+ AudioParameters::kTelephoneSampleRate / 10);
+ output_params_ = AudioParameters(
+ AudioParameters::AUDIO_PCM_LINEAR, ChannelLayoutConfig::Mono(),
+ AudioParameters::kTelephoneSampleRate,
+ AudioParameters::kTelephoneSampleRate / 20);
+ default_output_params_ = AudioParameters(
+ AudioParameters::AUDIO_PCM_LINEAR, ChannelLayoutConfig::Mono(),
+ AudioParameters::kTelephoneSampleRate,
+ AudioParameters::kTelephoneSampleRate / 30);
audio_manager()->SetInputStreamParameters(input_params_);
audio_manager()->SetOutputStreamParameters(output_params_);
audio_manager()->SetDefaultOutputStreamParameters(default_output_params_);
diff --git a/chromium/media/audio/audio_thread.h b/chromium/media/audio/audio_thread.h
index b014b89cfad..4b16d656e18 100644
--- a/chromium/media/audio/audio_thread.h
+++ b/chromium/media/audio/audio_thread.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_thread_hang_monitor.cc b/chromium/media/audio/audio_thread_hang_monitor.cc
index c3c7b7efe50..70080838680 100644
--- a/chromium/media/audio/audio_thread_hang_monitor.cc
+++ b/chromium/media/audio/audio_thread_hang_monitor.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_thread_hang_monitor.h b/chromium/media/audio/audio_thread_hang_monitor.h
index 70f0db692bd..b6975ac2382 100644
--- a/chromium/media/audio/audio_thread_hang_monitor.h
+++ b/chromium/media/audio/audio_thread_hang_monitor.h
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_thread_hang_monitor_unittest.cc b/chromium/media/audio/audio_thread_hang_monitor_unittest.cc
index 345975f8aac..a55a2fbf9aa 100644
--- a/chromium/media/audio/audio_thread_hang_monitor_unittest.cc
+++ b/chromium/media/audio/audio_thread_hang_monitor_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_thread_impl.cc b/chromium/media/audio/audio_thread_impl.cc
index 95a0afa5285..c8f9c5d2a4d 100644
--- a/chromium/media/audio/audio_thread_impl.cc
+++ b/chromium/media/audio/audio_thread_impl.cc
@@ -1,4 +1,4 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_thread_impl.h b/chromium/media/audio/audio_thread_impl.h
index 340b2719d44..1fbbda61308 100644
--- a/chromium/media/audio/audio_thread_impl.h
+++ b/chromium/media/audio/audio_thread_impl.h
@@ -1,4 +1,4 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_unittest_util.cc b/chromium/media/audio/audio_unittest_util.cc
index 0ddf94ad35f..a5a24f1374d 100644
--- a/chromium/media/audio/audio_unittest_util.cc
+++ b/chromium/media/audio/audio_unittest_util.cc
@@ -1,4 +1,4 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/audio_unittest_util.h b/chromium/media/audio/audio_unittest_util.h
index 3bd0dfad676..530dbfe581e 100644
--- a/chromium/media/audio/audio_unittest_util.h
+++ b/chromium/media/audio/audio_unittest_util.h
@@ -1,4 +1,4 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/clockless_audio_sink.cc b/chromium/media/audio/clockless_audio_sink.cc
index b30df2cf20d..1b121c0a31c 100644
--- a/chromium/media/audio/clockless_audio_sink.cc
+++ b/chromium/media/audio/clockless_audio_sink.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/clockless_audio_sink.h b/chromium/media/audio/clockless_audio_sink.h
index 0d0093cecb1..c865cff0ec6 100644
--- a/chromium/media/audio/clockless_audio_sink.h
+++ b/chromium/media/audio/clockless_audio_sink.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/cras/audio_manager_chromeos.cc b/chromium/media/audio/cras/audio_manager_chromeos.cc
index d3e1e96945c..fbe90b8f17b 100644
--- a/chromium/media/audio/cras/audio_manager_chromeos.cc
+++ b/chromium/media/audio/cras/audio_manager_chromeos.cc
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,7 +6,6 @@
#include <stddef.h>
-#include <algorithm>
#include <map>
#include <utility>
@@ -16,6 +15,7 @@
#include "base/environment.h"
#include "base/metrics/field_trial_params.h"
#include "base/nix/xdg_util.h"
+#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/system/sys_info.h"
@@ -294,8 +294,8 @@ std::string AudioManagerChromeOS::GetAssociatedOutputDeviceID(
return "";
// Now search for an output device with the same device name.
- auto output_device_it = std::find_if(
- devices.begin(), devices.end(), [device_name](const AudioDevice& device) {
+ auto output_device_it =
+ base::ranges::find_if(devices, [device_name](const AudioDevice& device) {
return !device.is_input && device.device_name == device_name;
});
return output_device_it == devices.end()
@@ -385,11 +385,11 @@ AudioParameters AudioManagerChromeOS::GetPreferredOutputStreamParameters(
const AudioParameters& input_params) {
DCHECK(GetTaskRunner()->BelongsToCurrentThread());
- ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
+ ChannelLayoutConfig channel_layout_config = ChannelLayoutConfig::Stereo();
int sample_rate = kDefaultSampleRate;
int buffer_size = GetUserBufferSize();
if (input_params.IsValid()) {
- channel_layout = input_params.channel_layout();
+ channel_layout_config = input_params.channel_layout_config();
sample_rate = input_params.sample_rate();
if (!buffer_size) // Not user-provided.
buffer_size =
@@ -397,8 +397,8 @@ AudioParameters AudioManagerChromeOS::GetPreferredOutputStreamParameters(
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::AUDIO_PCM_LOW_LATENCY, channel_layout_config,
+ sample_rate, buffer_size,
AudioParameters::HardwareCapabilities(limits::kMinAudioBufferSize,
limits::kMaxAudioBufferSize));
}
@@ -418,11 +418,12 @@ AudioParameters AudioManagerChromeOS::GetPreferredOutputStreamParameters(
GetAudioDevices(&devices);
const AudioDevice* device = GetDeviceFromId(devices, preferred_device_id);
if (device && device->is_input == false) {
- channel_layout =
- GuessChannelLayout(static_cast<int>(device->max_supported_channels));
+ channel_layout_config = ChannelLayoutConfig::Guess(
+ 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 (channel_layout_config.channel_layout() ==
+ CHANNEL_LAYOUT_UNSUPPORTED) {
+ channel_layout_config = ChannelLayoutConfig::Stereo();
}
}
}
@@ -431,8 +432,8 @@ AudioParameters AudioManagerChromeOS::GetPreferredOutputStreamParameters(
buffer_size = GetDefaultOutputBufferSizePerBoard();
return AudioParameters(
- AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, sample_rate,
- buffer_size,
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout_config,
+ sample_rate, buffer_size,
AudioParameters::HardwareCapabilities(limits::kMinAudioBufferSize,
limits::kMaxAudioBufferSize));
}
@@ -585,7 +586,7 @@ AudioParameters AudioManagerChromeOS::GetStreamParametersForSystem(
int user_buffer_size,
const AudioManagerChromeOS::SystemAudioProcessingInfo& system_apm_info) {
AudioParameters params(
- AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, ChannelLayoutConfig::Stereo(),
kDefaultSampleRate, user_buffer_size,
AudioParameters::HardwareCapabilities(limits::kMinAudioBufferSize,
limits::kMaxAudioBufferSize));
diff --git a/chromium/media/audio/cras/audio_manager_chromeos.h b/chromium/media/audio/cras/audio_manager_chromeos.h
index bec0fdc05af..a9071871161 100644
--- a/chromium/media/audio/cras/audio_manager_chromeos.h
+++ b/chromium/media/audio/cras/audio_manager_chromeos.h
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/cras/audio_manager_chromeos_unittest.cc b/chromium/media/audio/cras/audio_manager_chromeos_unittest.cc
index 440f790e5fa..9a100bb8b1b 100644
--- a/chromium/media/audio/cras/audio_manager_chromeos_unittest.cc
+++ b/chromium/media/audio/cras/audio_manager_chromeos_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2021 The Chromium Authors. All rights reserved.
+// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/audio/cras/audio_manager_chromeos.h"
@@ -274,8 +274,8 @@ class AllowedDspParameters
AudioManagerChromeOS::SystemAudioProcessingInfo system_apm_info_;
size_t user_buffer_size_ = kDefaultInputBufferSize;
- std::vector<base::Feature> enabled_features_;
- std::vector<base::Feature> disabled_features_;
+ std::vector<base::test::FeatureRef> enabled_features_;
+ std::vector<base::test::FeatureRef> disabled_features_;
bool aec_on_dsp_allowed_;
bool ns_on_dsp_allowed_;
bool agc_on_dsp_allowed_;
diff --git a/chromium/media/audio/cras/audio_manager_cras.cc b/chromium/media/audio/cras/audio_manager_cras.cc
index 4762e88f43b..b1717770a8d 100644
--- a/chromium/media/audio/cras/audio_manager_cras.cc
+++ b/chromium/media/audio/cras/audio_manager_cras.cc
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -183,7 +183,7 @@ void RetrieveSystemEffectFeatures(bool& enforce_system_aec,
AudioParameters AudioManagerCras::GetStreamParametersForSystem(
int user_buffer_size) {
AudioParameters params(
- AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, ChannelLayoutConfig::Stereo(),
kDefaultSampleRate, user_buffer_size,
AudioParameters::HardwareCapabilities(limits::kMinAudioBufferSize,
limits::kMaxAudioBufferSize));
@@ -313,11 +313,11 @@ AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters(
const std::string& output_device_id,
const AudioParameters& input_params) {
DCHECK(GetTaskRunner()->BelongsToCurrentThread());
- ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
+ ChannelLayoutConfig channel_layout_config = ChannelLayoutConfig::Stereo();
int sample_rate = kDefaultSampleRate;
int buffer_size = GetUserBufferSize();
if (input_params.IsValid()) {
- channel_layout = input_params.channel_layout();
+ channel_layout_config = input_params.channel_layout_config();
sample_rate = input_params.sample_rate();
if (!buffer_size) // Not user-provided.
buffer_size =
@@ -325,8 +325,8 @@ AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters(
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::AUDIO_PCM_LOW_LATENCY, channel_layout_config,
+ sample_rate, buffer_size,
AudioParameters::HardwareCapabilities(limits::kMinAudioBufferSize,
limits::kMaxAudioBufferSize));
}
@@ -344,11 +344,12 @@ AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters(
for (const auto& device :
cras_util_->CrasGetAudioDevices(DeviceType::kOutput)) {
if (device.id == preferred_device_id) {
- channel_layout =
- GuessChannelLayout(static_cast<int>(device.max_supported_channels));
+ channel_layout_config = ChannelLayoutConfig::Guess(
+ 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 (channel_layout_config.channel_layout() ==
+ CHANNEL_LAYOUT_UNSUPPORTED) {
+ channel_layout_config = ChannelLayoutConfig::Stereo();
}
break;
}
@@ -361,8 +362,8 @@ AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters(
buffer_size = kDefaultOutputBufferSize;
return AudioParameters(
- AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, sample_rate,
- buffer_size,
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout_config,
+ sample_rate, buffer_size,
AudioParameters::HardwareCapabilities(limits::kMinAudioBufferSize,
limits::kMaxAudioBufferSize));
}
diff --git a/chromium/media/audio/cras/audio_manager_cras.h b/chromium/media/audio/cras/audio_manager_cras.h
index db0426492ca..60317e985af 100644
--- a/chromium/media/audio/cras/audio_manager_cras.h
+++ b/chromium/media/audio/cras/audio_manager_cras.h
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/cras/audio_manager_cras_base.cc b/chromium/media/audio/cras/audio_manager_cras_base.cc
index b7eecf40279..dca0ed1d384 100644
--- a/chromium/media/audio/cras/audio_manager_cras_base.cc
+++ b/chromium/media/audio/cras/audio_manager_cras_base.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,6 +14,7 @@
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/environment.h"
+#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial_params.h"
#include "base/nix/xdg_util.h"
#include "base/strings/string_number_conversions.h"
@@ -92,4 +93,25 @@ AudioInputStream* AudioManagerCrasBase::MakeInputStream(
return new CrasInputStream(params, this, device_id);
}
+void AudioManagerCrasBase::RegisterSystemAecDumpSource(
+ AecdumpRecordingSource* stream) {
+ DCHECK(GetTaskRunner()->BelongsToCurrentThread());
+ if (aecdump_recording_manager_)
+ aecdump_recording_manager_->RegisterAecdumpSource(stream);
+}
+
+void AudioManagerCrasBase::DeregisterSystemAecDumpSource(
+ AecdumpRecordingSource* stream) {
+ DCHECK(GetTaskRunner()->BelongsToCurrentThread());
+ if (aecdump_recording_manager_)
+ aecdump_recording_manager_->DeregisterAecdumpSource(stream);
+}
+
+void AudioManagerCrasBase::SetAecDumpRecordingManager(
+ base::WeakPtr<AecdumpRecordingManager> aecdump_recording_manager) {
+ DCHECK(GetTaskRunner()->BelongsToCurrentThread());
+ DCHECK(!aecdump_recording_manager_);
+ aecdump_recording_manager_ = aecdump_recording_manager;
+}
+
} // namespace media
diff --git a/chromium/media/audio/cras/audio_manager_cras_base.h b/chromium/media/audio/cras/audio_manager_cras_base.h
index 6c5d84599c1..b5633d2c8f6 100644
--- a/chromium/media/audio/cras/audio_manager_cras_base.h
+++ b/chromium/media/audio/cras/audio_manager_cras_base.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -54,6 +54,16 @@ class MEDIA_EXPORT AudioManagerCrasBase : public AudioManagerBase {
// Returns CRAS client type.
virtual enum CRAS_CLIENT_TYPE GetClientType() = 0;
+ // Registers a CrasInputStream as the source of system AEC dump.
+ virtual void RegisterSystemAecDumpSource(AecdumpRecordingSource* stream);
+
+ // Unregisters system AEC dump. Virtual to mock in unittest.
+ virtual void DeregisterSystemAecDumpSource(AecdumpRecordingSource* stream);
+
+ virtual void SetAecDumpRecordingManager(
+ base::WeakPtr<AecdumpRecordingManager> aecdump_recording_manager)
+ override;
+
protected:
// Called by MakeLinearOutputStream and MakeLowLatencyOutputStream.
AudioOutputStream* MakeOutputStream(const AudioParameters& params,
@@ -62,6 +72,10 @@ class MEDIA_EXPORT AudioManagerCrasBase : public AudioManagerBase {
// Called by MakeLinearInputStream and MakeLowLatencyInputStream.
AudioInputStream* MakeInputStream(const AudioParameters& params,
const std::string& device_id);
+
+ private:
+ // Manages starting / stopping of aecdump recording.
+ base::WeakPtr<AecdumpRecordingManager> aecdump_recording_manager_;
};
} // namespace media
diff --git a/chromium/media/audio/cras/audio_manager_cras_base_unittest.cc b/chromium/media/audio/cras/audio_manager_cras_base_unittest.cc
new file mode 100644
index 00000000000..c653d087c00
--- /dev/null
+++ b/chromium/media/audio/cras/audio_manager_cras_base_unittest.cc
@@ -0,0 +1,90 @@
+// Copyright 2022 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/audio/cras/audio_manager_cras_base.h"
+
+#include "base/test/task_environment.h"
+#include "media/audio/fake_audio_log_factory.h"
+#include "media/audio/mock_aecdump_recording_manager.h"
+#include "media/audio/test_audio_thread.h"
+#include "media/base/audio_parameters.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::_;
+using testing::StrictMock;
+
+namespace media {
+
+namespace {
+
+class MockAecdumpRecordingSource : public AecdumpRecordingSource {
+ public:
+ MOCK_METHOD1(StartAecdump, void(base::File));
+ MOCK_METHOD0(StopAecdump, void());
+};
+
+class MockAudioManagerCrasBase : public AudioManagerCrasBase {
+ public:
+ MockAudioManagerCrasBase()
+ : AudioManagerCrasBase(std::make_unique<TestAudioThread>(),
+ &fake_audio_log_factory_) {}
+
+ bool HasAudioOutputDevices() { return true; }
+ bool HasAudioInputDevices() { return true; }
+ AudioParameters GetPreferredOutputStreamParameters(
+ const std::string& output_device_id,
+ const AudioParameters& input_params) {
+ return AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Stereo(), 44100, 1000);
+ }
+ bool IsDefault(const std::string& device_id, bool is_input) override {
+ return true;
+ }
+ enum CRAS_CLIENT_TYPE GetClientType() { return CRAS_CLIENT_TYPE_LACROS; }
+
+ // We need to override this function in order to skip checking the number
+ // of active output streams. It is because the number of active streams
+ // is managed inside MakeAudioInputStream, and we don't use
+ // MakeAudioInputStream to create the stream in the tests.
+ void ReleaseInputStream(AudioInputStream* stream) override {
+ DCHECK(stream);
+ delete stream;
+ }
+
+ private:
+ FakeAudioLogFactory fake_audio_log_factory_;
+};
+
+class AudioManagerCrasBaseTest : public testing::Test {
+ protected:
+ AudioManagerCrasBaseTest() {
+ mock_manager_.reset(new StrictMock<MockAudioManagerCrasBase>());
+ base::RunLoop().RunUntilIdle();
+ }
+ ~AudioManagerCrasBaseTest() override { mock_manager_->Shutdown(); }
+
+ base::test::SingleThreadTaskEnvironment task_environment_;
+ std::unique_ptr<StrictMock<MockAudioManagerCrasBase>> mock_manager_ = NULL;
+};
+
+TEST_F(AudioManagerCrasBaseTest, SetAecDumpRecordingManager) {
+ MockAecdumpRecordingManager* mock_aecdump_recording_manager =
+ new MockAecdumpRecordingManager(mock_manager_->GetTaskRunner());
+ mock_manager_->SetAecDumpRecordingManager(
+ mock_aecdump_recording_manager->AsWeakPtr());
+
+ MockAecdumpRecordingSource* source = new MockAecdumpRecordingSource();
+
+ EXPECT_CALL(*mock_aecdump_recording_manager, RegisterAecdumpSource(_));
+ EXPECT_CALL(*mock_aecdump_recording_manager, DeregisterAecdumpSource(_));
+
+ mock_manager_->RegisterSystemAecDumpSource(source);
+ mock_manager_->DeregisterSystemAecDumpSource(source);
+
+ delete mock_aecdump_recording_manager;
+}
+
+} // namespace
+} // namespace media
diff --git a/chromium/media/audio/cras/audio_manager_cras_unittest.cc b/chromium/media/audio/cras/audio_manager_cras_unittest.cc
index 434eccfef45..f05ea5a31a5 100644
--- a/chromium/media/audio/cras/audio_manager_cras_unittest.cc
+++ b/chromium/media/audio/cras/audio_manager_cras_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2021 The Chromium Authors. All rights reserved.
+// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/cras/cras_input.cc b/chromium/media/audio/cras/cras_input.cc
index 7ffca72d37c..1bf9866181a 100644
--- a/chromium/media/audio/cras/cras_input.cc
+++ b/chromium/media/audio/cras/cras_input.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,6 +8,7 @@
#include <algorithm>
+#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/string_number_conversions.h"
@@ -74,6 +75,9 @@ CrasInputStream::CrasInputStream(const AudioParameters& params,
mute_system_audio_(device_id ==
AudioDeviceDescription::kLoopbackWithMuteDeviceId),
mute_done_(false),
+#if DCHECK_IS_ON()
+ recording_enabled_(false),
+#endif
input_volume_(1.0f) {
DCHECK(audio_manager_);
audio_bus_ = AudioBus::Create(params_);
@@ -336,6 +340,8 @@ void CrasInputStream::Start(AudioInputCallback* callback) {
started_ = true;
+ audio_manager_->RegisterSystemAecDumpSource(this);
+
ReportStreamStartResult(StreamStartResult::kCallbackStartSuccess);
}
@@ -346,6 +352,8 @@ void CrasInputStream::Stop() {
if (!callback_ || !started_)
return;
+ audio_manager_->DeregisterSystemAecDumpSource(this);
+
if (mute_system_audio_ && mute_done_) {
libcras_client_set_system_mute(client_, 0);
mute_done_ = false;
@@ -464,4 +472,26 @@ void CrasInputStream::SetOutputDeviceForAec(
libcras_client_set_aec_ref(client_, stream_id_, echo_ref_id);
}
+void CrasInputStream::StartAecdump(base::File file) {
+ FILE* stream = base::FileToFILE(std::move(file), "w");
+ if (!client_)
+ return;
+#if DCHECK_IS_ON()
+ DCHECK(!recording_enabled_);
+ recording_enabled_ = true;
+#endif
+
+ libcras_client_set_aec_dump(client_, stream_id_, /*start=*/1, fileno(stream));
+}
+
+void CrasInputStream::StopAecdump() {
+ if (!client_)
+ return;
+#if DCHECK_IS_ON()
+ DCHECK(recording_enabled_);
+ recording_enabled_ = false;
+#endif
+ libcras_client_set_aec_dump(client_, stream_id_, /*start=*/0, /*fd=*/-1);
+}
+
} // namespace media
diff --git a/chromium/media/audio/cras/cras_input.h b/chromium/media/audio/cras/cras_input.h
index 994fef54c04..9f4c19599da 100644
--- a/chromium/media/audio/cras/cras_input.h
+++ b/chromium/media/audio/cras/cras_input.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -13,7 +13,9 @@
#include <string>
#include "base/compiler_specific.h"
+#include "media/audio/aecdump_recording_manager.h"
#include "media/audio/agc_audio_stream.h"
+#include "media/audio/audio_debug_recording_helper.h"
#include "media/audio/audio_io.h"
#include "media/base/audio_parameters.h"
#include "media/base/media_export.h"
@@ -25,7 +27,8 @@ class AudioManagerCrasBase;
// Provides an input stream for audio capture based on CRAS, the ChromeOS Audio
// Server. This object is not thread safe and all methods should be invoked in
// the thread that created the object.
-class MEDIA_EXPORT CrasInputStream : public AgcAudioStream<AudioInputStream> {
+class MEDIA_EXPORT CrasInputStream : public AgcAudioStream<AudioInputStream>,
+ public AecdumpRecordingSource {
public:
// The ctor takes all the usual parameters, plus |manager| which is the
// audio manager who is creating this object.
@@ -51,6 +54,10 @@ class MEDIA_EXPORT CrasInputStream : public AgcAudioStream<AudioInputStream> {
bool IsMuted() override;
void SetOutputDeviceForAec(const std::string& output_device_id) override;
+ // Implementation of AecdumpRecordingSource
+ void StartAecdump(base::File aecdump_file) override;
+ void StopAecdump() override;
+
private:
// Handles requests to get samples from the provided buffer. This will be
// called by the audio server when it has samples ready.
@@ -128,10 +135,17 @@ class MEDIA_EXPORT CrasInputStream : public AgcAudioStream<AudioInputStream> {
bool mute_system_audio_;
bool mute_done_;
+#if DCHECK_IS_ON()
+ // Flag to indicate if recording has been enabled or not.
+ bool recording_enabled_;
+#endif
+
// Value of input stream volume, between 0.0 - 1.0.
double input_volume_;
std::unique_ptr<AudioBus> audio_bus_;
+
+ base::WeakPtrFactory<CrasInputStream> weak_factory_{this};
};
} // namespace media
diff --git a/chromium/media/audio/cras/cras_input_unittest.cc b/chromium/media/audio/cras/cras_input_unittest.cc
index 76c4a8d70b6..72be910971d 100644
--- a/chromium/media/audio/cras/cras_input_unittest.cc
+++ b/chromium/media/audio/cras/cras_input_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,9 +16,10 @@
#include "chromeos/ash/components/audio/cras_audio_handler.h"
#include "chromeos/ash/components/dbus/audio/fake_cras_audio_client.h"
#include "media/audio/audio_device_description.h"
-#include "media/audio/cras/audio_manager_chromeos.h"
+#include "media/audio/cras/audio_manager_cras.h"
#include "media/audio/fake_audio_log_factory.h"
#include "media/audio/test_audio_thread.h"
+#include "media/base/audio_parameters.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -42,12 +43,29 @@ class MockAudioInputCallback : public AudioInputStream::AudioInputCallback {
MOCK_METHOD0(OnError, void());
};
-class MockAudioManagerCrasInput : public AudioManagerChromeOS {
+class MockAudioManagerCrasInput : public AudioManagerCrasBase {
public:
MockAudioManagerCrasInput()
- : AudioManagerChromeOS(std::make_unique<TestAudioThread>(),
+ : AudioManagerCrasBase(std::make_unique<TestAudioThread>(),
&fake_audio_log_factory_) {}
+ MOCK_METHOD1(RegisterSystemAecDumpSource, void(AecdumpRecordingSource*));
+
+ MOCK_METHOD1(DeregisterSystemAecDumpSource, void(AecdumpRecordingSource*));
+
+ bool HasAudioOutputDevices() { return true; }
+ bool HasAudioInputDevices() { return true; }
+ AudioParameters GetPreferredOutputStreamParameters(
+ const std::string& output_device_id,
+ const AudioParameters& input_params) {
+ return AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Stereo(), 44100, 1000);
+ }
+ bool IsDefault(const std::string& device_id, bool is_input) override {
+ return true;
+ }
+ enum CRAS_CLIENT_TYPE GetClientType() { return CRAS_CLIENT_TYPE_LACROS; }
+
// We need to override this function in order to skip checking the number
// of active output streams. It is because the number of active streams
// is managed inside MakeAudioInputStream, and we don't use
@@ -79,17 +97,17 @@ class CrasInputStreamTest : public testing::Test {
ash::CrasAudioClient::Shutdown();
}
- CrasInputStream* CreateStream(ChannelLayout layout) {
+ CrasInputStream* CreateStream(ChannelLayoutConfig layout) {
return CreateStream(layout, kTestFramesPerPacket);
}
- CrasInputStream* CreateStream(ChannelLayout layout,
+ CrasInputStream* CreateStream(ChannelLayoutConfig layout,
int32_t samples_per_packet) {
return CreateStream(layout, samples_per_packet,
AudioDeviceDescription::kDefaultDeviceId);
}
- CrasInputStream* CreateStream(ChannelLayout layout,
+ CrasInputStream* CreateStream(ChannelLayoutConfig layout,
int32_t samples_per_packet,
const std::string& device_id) {
AudioParameters params(kTestFormat,
@@ -104,6 +122,9 @@ class CrasInputStreamTest : public testing::Test {
CrasInputStream* test_stream = new CrasInputStream(
params, mock_manager_.get(), AudioDeviceDescription::kDefaultDeviceId);
+ EXPECT_CALL(*mock_manager_.get(), RegisterSystemAecDumpSource(_));
+ EXPECT_CALL(*mock_manager_.get(), DeregisterSystemAecDumpSource(_));
+
EXPECT_EQ(test_stream->Open(), AudioInputStream::OpenOutcome::kSuccess);
// Allow 8 frames variance for SRC in the callback. Different numbers of
@@ -136,7 +157,7 @@ class CrasInputStreamTest : public testing::Test {
};
const unsigned int CrasInputStreamTest::kTestCaptureDurationMs = 250;
-const ChannelLayout CrasInputStreamTest::kTestChannelLayout =
+constexpr ChannelLayout CrasInputStreamTest::kTestChannelLayout =
CHANNEL_LAYOUT_STEREO;
const AudioParameters::Format CrasInputStreamTest::kTestFormat =
AudioParameters::AUDIO_PCM_LINEAR;
@@ -144,22 +165,21 @@ const uint32_t CrasInputStreamTest::kTestFramesPerPacket = 1000;
const int CrasInputStreamTest::kTestSampleRate = 44100;
TEST_F(CrasInputStreamTest, OpenMono) {
- CrasInputStream* test_stream = CreateStream(CHANNEL_LAYOUT_MONO);
+ CrasInputStream* test_stream = CreateStream(ChannelLayoutConfig::Mono());
EXPECT_EQ(test_stream->Open(), AudioInputStream::OpenOutcome::kSuccess);
test_stream->Close();
}
TEST_F(CrasInputStreamTest, OpenStereo) {
- CrasInputStream* test_stream = CreateStream(CHANNEL_LAYOUT_STEREO);
+ CrasInputStream* test_stream = CreateStream(ChannelLayoutConfig::Stereo());
EXPECT_EQ(test_stream->Open(), AudioInputStream::OpenOutcome::kSuccess);
test_stream->Close();
}
TEST_F(CrasInputStreamTest, BadSampleRate) {
- AudioParameters bad_rate_params(kTestFormat,
- kTestChannelLayout,
- 0,
- kTestFramesPerPacket);
+ AudioParameters bad_rate_params(
+ kTestFormat, ChannelLayoutConfig::FromLayout<kTestChannelLayout>(), 0,
+ kTestFramesPerPacket);
CrasInputStream* test_stream =
new CrasInputStream(bad_rate_params, mock_manager_.get(),
AudioDeviceDescription::kDefaultDeviceId);
@@ -168,7 +188,7 @@ TEST_F(CrasInputStreamTest, BadSampleRate) {
}
TEST_F(CrasInputStreamTest, SetGetVolume) {
- CrasInputStream* test_stream = CreateStream(CHANNEL_LAYOUT_MONO);
+ CrasInputStream* test_stream = CreateStream(ChannelLayoutConfig::Mono());
EXPECT_EQ(test_stream->Open(), AudioInputStream::OpenOutcome::kSuccess);
double max_volume = test_stream->GetMaxVolume();
@@ -190,26 +210,22 @@ TEST_F(CrasInputStreamTest, CaptureFrames) {
for (unsigned int i = 0; i < ARRAY_SIZE(rates); i++) {
SCOPED_TRACE(testing::Message() << "Mono " << rates[i] << "Hz");
- AudioParameters params_mono(kTestFormat,
- CHANNEL_LAYOUT_MONO,
- rates[i],
- kTestFramesPerPacket);
+ AudioParameters params_mono(kTestFormat, ChannelLayoutConfig::Mono(),
+ rates[i], kTestFramesPerPacket);
CaptureSomeFrames(params_mono, kTestCaptureDurationMs);
}
for (unsigned int i = 0; i < ARRAY_SIZE(rates); i++) {
SCOPED_TRACE(testing::Message() << "Stereo " << rates[i] << "Hz");
- AudioParameters params_stereo(kTestFormat,
- CHANNEL_LAYOUT_STEREO,
- rates[i],
- kTestFramesPerPacket);
+ AudioParameters params_stereo(kTestFormat, ChannelLayoutConfig::Stereo(),
+ rates[i], kTestFramesPerPacket);
CaptureSomeFrames(params_stereo, kTestCaptureDurationMs);
}
}
TEST_F(CrasInputStreamTest, CaptureLoopback) {
CrasInputStream* test_stream =
- CreateStream(CHANNEL_LAYOUT_STEREO, kTestFramesPerPacket,
+ CreateStream(ChannelLayoutConfig::Stereo(), kTestFramesPerPacket,
AudioDeviceDescription::kLoopbackInputDeviceId);
EXPECT_EQ(test_stream->Open(), AudioInputStream::OpenOutcome::kSuccess);
test_stream->Close();
diff --git a/chromium/media/audio/cras/cras_unified.cc b/chromium/media/audio/cras/cras_unified.cc
index b0c4830e717..44139f9c44d 100644
--- a/chromium/media/audio/cras/cras_unified.cc
+++ b/chromium/media/audio/cras/cras_unified.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/cras/cras_unified.h b/chromium/media/audio/cras/cras_unified.h
index 6d74e6c1cff..4cd7d5b0608 100644
--- a/chromium/media/audio/cras/cras_unified.h
+++ b/chromium/media/audio/cras/cras_unified.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
diff --git a/chromium/media/audio/cras/cras_unified_unittest.cc b/chromium/media/audio/cras/cras_unified_unittest.cc
index 5c2d257e9b7..f8b9619a677 100644
--- a/chromium/media/audio/cras/cras_unified_unittest.cc
+++ b/chromium/media/audio/cras/cras_unified_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -76,11 +76,11 @@ class CrasUnifiedStreamTest : public testing::Test {
ash::CrasAudioClient::Shutdown();
}
- CrasUnifiedStream* CreateStream(ChannelLayout layout) {
+ CrasUnifiedStream* CreateStream(ChannelLayoutConfig layout) {
return CreateStream(layout, kTestFramesPerPacket);
}
- CrasUnifiedStream* CreateStream(ChannelLayout layout,
+ CrasUnifiedStream* CreateStream(ChannelLayoutConfig layout,
int32_t samples_per_packet) {
AudioParameters params(kTestFormat, layout, kTestSampleRate,
samples_per_packet);
@@ -101,7 +101,7 @@ class CrasUnifiedStreamTest : public testing::Test {
std::unique_ptr<StrictMock<MockAudioManagerCras>> mock_manager_;
};
-const ChannelLayout CrasUnifiedStreamTest::kTestChannelLayout =
+constexpr ChannelLayout CrasUnifiedStreamTest::kTestChannelLayout =
CHANNEL_LAYOUT_STEREO;
const int CrasUnifiedStreamTest::kTestSampleRate =
AudioParameters::kAudioCDSampleRate;
@@ -110,23 +110,26 @@ const AudioParameters::Format CrasUnifiedStreamTest::kTestFormat =
const uint32_t CrasUnifiedStreamTest::kTestFramesPerPacket = 1000;
TEST_F(CrasUnifiedStreamTest, ConstructedState) {
- CrasUnifiedStream* test_stream = CreateStream(kTestChannelLayout);
+ CrasUnifiedStream* test_stream =
+ CreateStream(ChannelLayoutConfig::FromLayout<kTestChannelLayout>());
EXPECT_TRUE(test_stream->Open());
test_stream->Close();
// Should support mono.
- test_stream = CreateStream(CHANNEL_LAYOUT_MONO);
+ test_stream = CreateStream(ChannelLayoutConfig::Mono());
EXPECT_TRUE(test_stream->Open());
test_stream->Close();
// Should support multi-channel.
- test_stream = CreateStream(CHANNEL_LAYOUT_SURROUND);
+ test_stream =
+ CreateStream(ChannelLayoutConfig::FromLayout<CHANNEL_LAYOUT_SURROUND>());
EXPECT_TRUE(test_stream->Open());
test_stream->Close();
// Bad sample rate.
- AudioParameters bad_rate_params(kTestFormat, kTestChannelLayout, 0,
- kTestFramesPerPacket);
+ AudioParameters bad_rate_params(
+ kTestFormat, ChannelLayoutConfig::FromLayout<kTestChannelLayout>(), 0,
+ kTestFramesPerPacket);
test_stream = new CrasUnifiedStream(bad_rate_params, mock_manager_.get(),
AudioDeviceDescription::kDefaultDeviceId);
EXPECT_FALSE(test_stream->Open());
@@ -134,7 +137,7 @@ TEST_F(CrasUnifiedStreamTest, ConstructedState) {
}
TEST_F(CrasUnifiedStreamTest, RenderFrames) {
- CrasUnifiedStream* test_stream = CreateStream(CHANNEL_LAYOUT_MONO);
+ CrasUnifiedStream* test_stream = CreateStream(ChannelLayoutConfig::Mono());
MockAudioSourceCallback mock_callback;
ASSERT_TRUE(test_stream->Open());
diff --git a/chromium/media/audio/cras/cras_util.cc b/chromium/media/audio/cras/cras_util.cc
index 9b1c7a8da93..ef825230f2a 100644
--- a/chromium/media/audio/cras/cras_util.cc
+++ b/chromium/media/audio/cras/cras_util.cc
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/cras/cras_util.h b/chromium/media/audio/cras/cras_util.h
index 0031e9d173e..2c3db02ea64 100644
--- a/chromium/media/audio/cras/cras_util.h
+++ b/chromium/media/audio/cras/cras_util.h
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/fake_audio_input_stream.cc b/chromium/media/audio/fake_audio_input_stream.cc
index 4cc30150faf..dd7e144ea21 100644
--- a/chromium/media/audio/fake_audio_input_stream.cc
+++ b/chromium/media/audio/fake_audio_input_stream.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/fake_audio_input_stream.h b/chromium/media/audio/fake_audio_input_stream.h
index e204bfa78bf..d4245553d85 100644
--- a/chromium/media/audio/fake_audio_input_stream.h
+++ b/chromium/media/audio/fake_audio_input_stream.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
diff --git a/chromium/media/audio/fake_audio_log_factory.cc b/chromium/media/audio/fake_audio_log_factory.cc
index caf08f52e3f..2ac6d2e96ff 100644
--- a/chromium/media/audio/fake_audio_log_factory.cc
+++ b/chromium/media/audio/fake_audio_log_factory.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/fake_audio_log_factory.h b/chromium/media/audio/fake_audio_log_factory.h
index 8d94e4298bc..f0ad4dcb9b7 100644
--- a/chromium/media/audio/fake_audio_log_factory.h
+++ b/chromium/media/audio/fake_audio_log_factory.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/fake_audio_manager.cc b/chromium/media/audio/fake_audio_manager.cc
index cc6ea938ca0..f2059baa3d1 100644
--- a/chromium/media/audio/fake_audio_manager.cc
+++ b/chromium/media/audio/fake_audio_manager.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,6 +6,8 @@
#include <algorithm>
#include <utility>
+#include "media/base/audio_parameters.h"
+#include "media/base/channel_layout.h"
namespace media {
@@ -64,23 +66,23 @@ AudioParameters FakeAudioManager::GetPreferredOutputStreamParameters(
const AudioParameters& input_params) {
static const int kDefaultOutputBufferSize = 2048;
static const int kDefaultSampleRate = 48000;
- ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
+ ChannelLayoutConfig channel_layout_config = ChannelLayoutConfig::Stereo();
int sample_rate = kDefaultSampleRate;
int buffer_size = kDefaultOutputBufferSize;
if (input_params.IsValid()) {
sample_rate = input_params.sample_rate();
- channel_layout = input_params.channel_layout();
+ channel_layout_config = input_params.channel_layout_config();
buffer_size = std::min(input_params.frames_per_buffer(), buffer_size);
}
- return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
- sample_rate, buffer_size);
+ return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
+ channel_layout_config, sample_rate, buffer_size);
}
AudioParameters FakeAudioManager::GetInputStreamParameters(
const std::string& device_id) {
return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_STEREO, kDefaultSampleRate,
+ ChannelLayoutConfig::Stereo(), kDefaultSampleRate,
kDefaultInputBufferSize);
}
diff --git a/chromium/media/audio/fake_audio_manager.h b/chromium/media/audio/fake_audio_manager.h
index 852740bc7a7..6d2274c74e2 100644
--- a/chromium/media/audio/fake_audio_manager.h
+++ b/chromium/media/audio/fake_audio_manager.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/fake_audio_output_stream.cc b/chromium/media/audio/fake_audio_output_stream.cc
index e6ef8a7227d..d25513d8c24 100644
--- a/chromium/media/audio/fake_audio_output_stream.cc
+++ b/chromium/media/audio/fake_audio_output_stream.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/fake_audio_output_stream.h b/chromium/media/audio/fake_audio_output_stream.h
index bdbb05588eb..6582775bd84 100644
--- a/chromium/media/audio/fake_audio_output_stream.h
+++ b/chromium/media/audio/fake_audio_output_stream.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/fuchsia/audio_input_stream_fuchsia.cc b/chromium/media/audio/fuchsia/audio_input_stream_fuchsia.cc
index 01b1c950997..8c136f51604 100644
--- a/chromium/media/audio/fuchsia/audio_input_stream_fuchsia.cc
+++ b/chromium/media/audio/fuchsia/audio_input_stream_fuchsia.cc
@@ -1,4 +1,4 @@
-// Copyright 2021 The Chromium Authors. All rights reserved.
+// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/fuchsia/audio_input_stream_fuchsia.h b/chromium/media/audio/fuchsia/audio_input_stream_fuchsia.h
index 23024d37d1c..47e5cb30ab3 100644
--- a/chromium/media/audio/fuchsia/audio_input_stream_fuchsia.h
+++ b/chromium/media/audio/fuchsia/audio_input_stream_fuchsia.h
@@ -1,4 +1,4 @@
-// Copyright 2021 The Chromium Authors. All rights reserved.
+// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/fuchsia/audio_input_stream_fuchsia_test.cc b/chromium/media/audio/fuchsia/audio_input_stream_fuchsia_test.cc
index 5d552092891..60b5e2fc1d5 100644
--- a/chromium/media/audio/fuchsia/audio_input_stream_fuchsia_test.cc
+++ b/chromium/media/audio/fuchsia/audio_input_stream_fuchsia_test.cc
@@ -1,4 +1,4 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
+// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,6 +11,7 @@
#include "base/fuchsia/test_component_context_for_process.h"
#include "base/test/task_environment.h"
#include "media/audio/audio_device_description.h"
+#include "media/base/audio_parameters.h"
#include "media/base/channel_layout.h"
#include "media/fuchsia/audio/fake_audio_capturer.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -69,14 +70,15 @@ class AudioInputStreamFuchsiaTest : public testing::Test {
base::RunLoop().RunUntilIdle();
}
- void InitializeCapturer(ChannelLayout layout) {
+ void InitializeCapturer(ChannelLayoutConfig channel_layout_config) {
base::TestComponentContextForProcess test_context;
FakeAudioCapturerFactory audio_capturer_factory(
test_context.additional_services());
input_stream_ = std::make_unique<AudioInputStreamFuchsia>(
/*manager=*/nullptr,
- AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, layout,
+ AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
+ channel_layout_config,
/*sample_rate=*/48000, kFramesPerPacket),
AudioDeviceDescription::kDefaultDeviceId);
@@ -94,12 +96,12 @@ class AudioInputStreamFuchsiaTest : public testing::Test {
ASSERT_FALSE(audio_capturer_factory.TakeCapturer());
}
- void TestCapture(ChannelLayout layout) {
- InitializeCapturer(layout);
+ void TestCapture(ChannelLayoutConfig channel_layout_config) {
+ InitializeCapturer(channel_layout_config);
input_stream_->Start(&callback_);
base::RunLoop().RunUntilIdle();
- size_t num_channels = ChannelLayoutToChannelCount(layout);
+ size_t num_channels = channel_layout_config.channels();
// Produce a packet.
std::vector<float> samples(kFramesPerPacket * num_channels);
@@ -133,14 +135,14 @@ class AudioInputStreamFuchsiaTest : public testing::Test {
TEST_F(AudioInputStreamFuchsiaTest, CreateAndDestroy) {}
TEST_F(AudioInputStreamFuchsiaTest, InitializeAndDestroy) {
- InitializeCapturer(CHANNEL_LAYOUT_MONO);
+ InitializeCapturer(ChannelLayoutConfig::Mono());
}
TEST_F(AudioInputStreamFuchsiaTest, InitializeAndStart) {
- const auto kLayout = CHANNEL_LAYOUT_MONO;
- const auto kNumChannels = ChannelLayoutToChannelCount(kLayout);
+ const auto kChannelLayoutConfig = ChannelLayoutConfig::Mono();
+ const auto kNumChannels = kChannelLayoutConfig.channels();
- InitializeCapturer(kLayout);
+ InitializeCapturer(kChannelLayoutConfig);
input_stream_->Start(&callback_);
base::RunLoop().RunUntilIdle();
@@ -152,10 +154,10 @@ TEST_F(AudioInputStreamFuchsiaTest, InitializeAndStart) {
}
TEST_F(AudioInputStreamFuchsiaTest, InitializeStereo) {
- const auto kLayout = CHANNEL_LAYOUT_STEREO;
- const auto kNumChannels = ChannelLayoutToChannelCount(kLayout);
+ const auto kChannelLayoutConfig = ChannelLayoutConfig::Stereo();
+ const auto kNumChannels = kChannelLayoutConfig.channels();
- InitializeCapturer(kLayout);
+ InitializeCapturer(kChannelLayoutConfig);
input_stream_->Start(&callback_);
base::RunLoop().RunUntilIdle();
@@ -165,7 +167,7 @@ TEST_F(AudioInputStreamFuchsiaTest, InitializeStereo) {
}
TEST_F(AudioInputStreamFuchsiaTest, StartAndStop) {
- InitializeCapturer(CHANNEL_LAYOUT_MONO);
+ InitializeCapturer(ChannelLayoutConfig::Stereo());
input_stream_->Start(&callback_);
base::RunLoop().RunUntilIdle();
@@ -176,15 +178,15 @@ TEST_F(AudioInputStreamFuchsiaTest, StartAndStop) {
}
TEST_F(AudioInputStreamFuchsiaTest, CaptureMono) {
- TestCapture(CHANNEL_LAYOUT_MONO);
+ TestCapture(ChannelLayoutConfig::Mono());
}
TEST_F(AudioInputStreamFuchsiaTest, CaptureStereo) {
- TestCapture(CHANNEL_LAYOUT_STEREO);
+ TestCapture(ChannelLayoutConfig::Stereo());
}
TEST_F(AudioInputStreamFuchsiaTest, CaptureTwoPackets) {
- InitializeCapturer(CHANNEL_LAYOUT_MONO);
+ InitializeCapturer(ChannelLayoutConfig::Mono());
input_stream_->Start(&callback_);
base::RunLoop().RunUntilIdle();
@@ -214,7 +216,7 @@ TEST_F(AudioInputStreamFuchsiaTest, CaptureTwoPackets) {
}
TEST_F(AudioInputStreamFuchsiaTest, CaptureAfterStop) {
- InitializeCapturer(CHANNEL_LAYOUT_MONO);
+ InitializeCapturer(ChannelLayoutConfig::Mono());
input_stream_->Start(&callback_);
base::RunLoop().RunUntilIdle();
input_stream_->Stop();
diff --git a/chromium/media/audio/fuchsia/audio_manager_fuchsia.cc b/chromium/media/audio/fuchsia/audio_manager_fuchsia.cc
index d52af7ab995..d0f9a051f31 100644
--- a/chromium/media/audio/fuchsia/audio_manager_fuchsia.cc
+++ b/chromium/media/audio/fuchsia/audio_manager_fuchsia.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,16 +10,22 @@
#include "base/callback.h"
#include "base/command_line.h"
+#include "base/containers/contains.h"
#include "base/fuchsia/fuchsia_logging.h"
#include "base/fuchsia/process_context.h"
#include "base/fuchsia/scheduler.h"
+#include "base/time/time.h"
#include "media/audio/fuchsia/audio_input_stream_fuchsia.h"
#include "media/audio/fuchsia/audio_output_stream_fuchsia.h"
+#include "media/base/audio_parameters.h"
#include "media/base/audio_timestamp_helper.h"
#include "media/base/media_switches.h"
namespace media {
+constexpr base::TimeDelta kMinBufferPeriod = base::kAudioSchedulingPeriod;
+constexpr base::TimeDelta kMaxBufferPeriod = base::Seconds(1);
+
AudioManagerFuchsia::AudioManagerFuchsia(
std::unique_ptr<AudioThread> audio_thread,
AudioLogFactory* audio_log_factory)
@@ -31,6 +37,16 @@ AudioManagerFuchsia::AudioManagerFuchsia(
AudioManagerFuchsia::~AudioManagerFuchsia() = default;
+void AudioManagerFuchsia::ShutdownOnAudioThread() {
+ DCHECK(GetTaskRunner()->BelongsToCurrentThread());
+
+ AudioManagerBase::ShutdownOnAudioThread();
+
+ // Teardown the AudioDeviceEnumerator channel before the audio
+ // thread, which it is bound to, stops.
+ enumerator_ = nullptr;
+}
+
bool AudioManagerFuchsia::HasAudioOutputDevices() {
return HasAudioDevice(false);
}
@@ -71,7 +87,8 @@ AudioParameters AudioManagerFuchsia::GetInputStreamParameters(
const size_t kPeriodSamples = AudioTimestampHelper::TimeToFrames(
base::kAudioSchedulingPeriod, kSampleRate);
AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_MONO, kSampleRate, kPeriodSamples);
+ ChannelLayoutConfig::Mono(), kSampleRate,
+ kPeriodSamples);
// Some AudioCapturer implementations support echo cancellation, noise
// suppression and automatic gain control, but currently there is no way to
@@ -90,14 +107,36 @@ AudioParameters AudioManagerFuchsia::GetInputStreamParameters(
AudioParameters AudioManagerFuchsia::GetPreferredOutputStreamParameters(
const std::string& output_device_id,
const AudioParameters& input_params) {
+ if (input_params.IsValid()) {
+ AudioParameters params = input_params;
+
+ base::TimeDelta period = AudioTimestampHelper::FramesToTime(
+ input_params.frames_per_buffer(), input_params.sample_rate());
+
+ // Round period to a whole number of the CPU scheduling periods.
+ period = round(period / base::kAudioSchedulingPeriod) *
+ base::kAudioSchedulingPeriod;
+ period = std::min(kMaxBufferPeriod, std::max(period, kMinBufferPeriod));
+
+ params.set_frames_per_buffer(
+ AudioTimestampHelper::TimeToFrames(period, params.sample_rate()));
+
+ return params;
+ }
+
// TODO(crbug.com/852834): Fuchsia currently doesn't provide an API to get
// device configuration. Update this method when that functionality is
// implemented.
- const size_t kSampleRate = 48000;
- const size_t kPeriodFrames = AudioTimestampHelper::TimeToFrames(
- base::kAudioSchedulingPeriod, kSampleRate);
+ const int kSampleRate = 48000;
+ const int kMinPeriodFrames =
+ AudioTimestampHelper::TimeToFrames(kMinBufferPeriod, kSampleRate);
+ const int kMaxPeriodFrames =
+ AudioTimestampHelper::TimeToFrames(kMaxBufferPeriod, kSampleRate);
return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_STEREO, kSampleRate, kPeriodFrames);
+ ChannelLayoutConfig::Stereo(), kSampleRate,
+ kMinPeriodFrames,
+ AudioParameters::HardwareCapabilities(
+ kMinPeriodFrames, kMaxPeriodFrames));
}
const char* AudioManagerFuchsia::GetName() {
@@ -215,10 +254,9 @@ void AudioManagerFuchsia::OnDeviceRemoved(uint64_t device_token) {
bool AudioManagerFuchsia::HasAudioDevice(bool is_input) {
DCHECK(GetTaskRunner()->BelongsToCurrentThread());
- return std::find_if(audio_devices_.begin(), audio_devices_.end(),
- [is_input](const auto& device) {
- return device.second.is_input == is_input;
- }) != audio_devices_.end();
+ return base::Contains(audio_devices_, is_input, [](const auto& device) {
+ return device.second.is_input;
+ });
}
void AudioManagerFuchsia::GetAudioDevices(AudioDeviceNames* device_names,
diff --git a/chromium/media/audio/fuchsia/audio_manager_fuchsia.h b/chromium/media/audio/fuchsia/audio_manager_fuchsia.h
index ed0274252b9..5b41b644c76 100644
--- a/chromium/media/audio/fuchsia/audio_manager_fuchsia.h
+++ b/chromium/media/audio/fuchsia/audio_manager_fuchsia.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -24,6 +24,7 @@ class AudioManagerFuchsia : public AudioManagerBase {
~AudioManagerFuchsia() override;
// Implementation of AudioManager.
+ void ShutdownOnAudioThread() override;
bool HasAudioOutputDevices() override;
bool HasAudioInputDevices() override;
void GetAudioInputDeviceNames(AudioDeviceNames* device_names) override;
diff --git a/chromium/media/audio/fuchsia/audio_output_stream_fuchsia.cc b/chromium/media/audio/fuchsia/audio_output_stream_fuchsia.cc
index 3ec94836325..cc582a4ffdb 100644
--- a/chromium/media/audio/fuchsia/audio_output_stream_fuchsia.cc
+++ b/chromium/media/audio/fuchsia/audio_output_stream_fuchsia.cc
@@ -1,9 +1,10 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/audio/fuchsia/audio_output_stream_fuchsia.h"
+#include <fuchsia/media/cpp/fidl.h>
#include <lib/sys/cpp/component_context.h>
#include <zircon/syscalls.h>
@@ -22,13 +23,35 @@ namespace {
const uint32_t kBufferId = 0;
-fuchsia::media::AudioRenderUsage GetStreamUsage(
+absl::optional<fuchsia::media::AudioRenderUsage> GetStreamUsage(
const AudioParameters& parameters) {
- // TODO(crbug.com/1253010) In WebEngine: use `audio_renderer_usage` from the
- // `FrameMediaSettings` for the current web frame.
- if (parameters.latency_tag() == AudioLatency::LATENCY_RTC)
- return fuchsia::media::AudioRenderUsage::COMMUNICATION;
- return fuchsia::media::AudioRenderUsage::MEDIA;
+ int usage_flags = parameters.effects() &
+ (AudioParameters::FUCHSIA_RENDER_USAGE_BACKGROUND |
+ AudioParameters::FUCHSIA_RENDER_USAGE_MEDIA |
+ AudioParameters::FUCHSIA_RENDER_USAGE_INTERRUPTION |
+ AudioParameters::FUCHSIA_RENDER_USAGE_SYSTEM_AGENT |
+ AudioParameters::FUCHSIA_RENDER_USAGE_COMMUNICATION);
+ switch (usage_flags) {
+ case AudioParameters::FUCHSIA_RENDER_USAGE_BACKGROUND:
+ return fuchsia::media::AudioRenderUsage::BACKGROUND;
+ case AudioParameters::FUCHSIA_RENDER_USAGE_MEDIA:
+ return fuchsia::media::AudioRenderUsage::MEDIA;
+ case AudioParameters::FUCHSIA_RENDER_USAGE_INTERRUPTION:
+ return fuchsia::media::AudioRenderUsage::INTERRUPTION;
+ case AudioParameters::FUCHSIA_RENDER_USAGE_SYSTEM_AGENT:
+ return fuchsia::media::AudioRenderUsage::SYSTEM_AGENT;
+ case AudioParameters::FUCHSIA_RENDER_USAGE_COMMUNICATION:
+ return fuchsia::media::AudioRenderUsage::COMMUNICATION;
+ case 0:
+ // If the usage flags are not set then use COMMUNICATION for WebRTC and
+ // MEDIA for everything else.
+ if (parameters.latency_tag() == AudioLatency::LATENCY_RTC)
+ return fuchsia::media::AudioRenderUsage::COMMUNICATION;
+ return fuchsia::media::AudioRenderUsage::MEDIA;
+ default:
+ DLOG(FATAL) << "More than one FUCHSIA_RENDER_USAGE flag is set";
+ return absl::nullopt;
+ }
}
} // namespace
@@ -57,7 +80,10 @@ bool AudioOutputStreamFuchsia::Open() {
audio_renderer_.set_error_handler(
fit::bind_member(this, &AudioOutputStreamFuchsia::OnRendererError));
- audio_renderer_->SetUsage(GetStreamUsage(parameters_));
+ auto usage = GetStreamUsage(parameters_);
+ if (!usage)
+ return false;
+ audio_renderer_->SetUsage(usage.value());
// Inform the |audio_renderer_| of the format required by the caller.
fuchsia::media::AudioStreamType format;
@@ -285,14 +311,15 @@ void AudioOutputStreamFuchsia::PumpSamples() {
payload_buffer_pos_ =
(payload_buffer_pos_ + packet_size) % payload_buffer_.size();
- SchedulePumpSamples(now);
+ SchedulePumpSamples();
}
-void AudioOutputStreamFuchsia::SchedulePumpSamples(base::TimeTicks now) {
+void AudioOutputStreamFuchsia::SchedulePumpSamples() {
base::TimeTicks next_pump_time = GetCurrentStreamTime() -
min_lead_time_.value() -
parameters_.GetBufferDuration() / 2;
- timer_.Start(FROM_HERE, next_pump_time - now,
+
+ timer_.Start(FROM_HERE, next_pump_time,
base::BindOnce(&AudioOutputStreamFuchsia::PumpSamples,
base::Unretained(this)));
}
diff --git a/chromium/media/audio/fuchsia/audio_output_stream_fuchsia.h b/chromium/media/audio/fuchsia/audio_output_stream_fuchsia.h
index 2fdba87afb8..775675ab4be 100644
--- a/chromium/media/audio/fuchsia/audio_output_stream_fuchsia.h
+++ b/chromium/media/audio/fuchsia/audio_output_stream_fuchsia.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -67,7 +67,7 @@ class AudioOutputStreamFuchsia : public AudioOutputStream {
// Schedules |timer_| to call PumpSamples() when appropriate for the next
// packet.
- void SchedulePumpSamples(base::TimeTicks now);
+ void SchedulePumpSamples();
AudioManagerFuchsia* manager_;
AudioParameters parameters_;
@@ -99,7 +99,7 @@ class AudioOutputStreamFuchsia : public AudioOutputStream {
absl::optional<base::TimeDelta> min_lead_time_;
// Timer that's scheduled to call PumpSamples().
- base::OneShotTimer timer_;
+ base::DeadlineTimer timer_;
};
} // namespace media
diff --git a/chromium/media/audio/linux/audio_manager_linux.cc b/chromium/media/audio/linux/audio_manager_linux.cc
index ed7a3962624..749897baebe 100644
--- a/chromium/media/audio/linux/audio_manager_linux.cc
+++ b/chromium/media/audio/linux/audio_manager_linux.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mac/audio_auhal_mac.cc b/chromium/media/audio/mac/audio_auhal_mac.cc
index 01dfcd621e4..e345343b075 100644
--- a/chromium/media/audio/mac/audio_auhal_mac.cc
+++ b/chromium/media/audio/mac/audio_auhal_mac.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mac/audio_auhal_mac.h b/chromium/media/audio/mac/audio_auhal_mac.h
index 24330f6aec0..5d1a51d4fab 100644
--- a/chromium/media/audio/mac/audio_auhal_mac.h
+++ b/chromium/media/audio/mac/audio_auhal_mac.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
diff --git a/chromium/media/audio/mac/audio_auhal_mac_unittest.cc b/chromium/media/audio/mac/audio_auhal_mac_unittest.cc
index 2f889ac4152..1fa433abb4b 100644
--- a/chromium/media/audio/mac/audio_auhal_mac_unittest.cc
+++ b/chromium/media/audio/mac/audio_auhal_mac_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mac/audio_device_listener_mac.cc b/chromium/media/audio/mac/audio_device_listener_mac.cc
index b7d84fd1d01..18fd2fcf181 100644
--- a/chromium/media/audio/mac/audio_device_listener_mac.cc
+++ b/chromium/media/audio/mac/audio_device_listener_mac.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mac/audio_device_listener_mac.h b/chromium/media/audio/mac/audio_device_listener_mac.h
index 8da880aff84..bf1dfc3a6e5 100644
--- a/chromium/media/audio/mac/audio_device_listener_mac.h
+++ b/chromium/media/audio/mac/audio_device_listener_mac.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mac/audio_device_listener_mac_unittest.cc b/chromium/media/audio/mac/audio_device_listener_mac_unittest.cc
index c13ac335eb3..71a0caa4815 100644
--- a/chromium/media/audio/mac/audio_device_listener_mac_unittest.cc
+++ b/chromium/media/audio/mac/audio_device_listener_mac_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -35,7 +35,7 @@ class AudioDeviceListenerMacTest : public testing::Test {
AudioDeviceListenerMacTest& operator=(const AudioDeviceListenerMacTest&) =
delete;
- virtual ~AudioDeviceListenerMacTest() {
+ ~AudioDeviceListenerMacTest() override {
// It's important to destroy the device listener from the message loop in
// order to ensure we don't end up with unbalanced TaskObserver calls.
task_environment_.GetMainThreadTaskRunner()->PostTask(
diff --git a/chromium/media/audio/mac/audio_input_mac.cc b/chromium/media/audio/mac/audio_input_mac.cc
index c125a4801c8..852a2b9cbd5 100644
--- a/chromium/media/audio/mac/audio_input_mac.cc
+++ b/chromium/media/audio/mac/audio_input_mac.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mac/audio_input_mac.h b/chromium/media/audio/mac/audio_input_mac.h
index b6b08cc34ae..93f90bb7fdb 100644
--- a/chromium/media/audio/mac/audio_input_mac.h
+++ b/chromium/media/audio/mac/audio_input_mac.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mac/audio_low_latency_input_mac.cc b/chromium/media/audio/mac/audio_low_latency_input_mac.cc
index de981fa288c..751b723388f 100644
--- a/chromium/media/audio/mac/audio_low_latency_input_mac.cc
+++ b/chromium/media/audio/mac/audio_low_latency_input_mac.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/audio/mac/audio_low_latency_input_mac.h"
diff --git a/chromium/media/audio/mac/audio_low_latency_input_mac.h b/chromium/media/audio/mac/audio_low_latency_input_mac.h
index dbd912e336d..38e4d6bc3f0 100644
--- a/chromium/media/audio/mac/audio_low_latency_input_mac.h
+++ b/chromium/media/audio/mac/audio_low_latency_input_mac.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
diff --git a/chromium/media/audio/mac/audio_low_latency_input_mac_unittest.cc b/chromium/media/audio/mac/audio_low_latency_input_mac_unittest.cc
index 9f31662515c..58d867608d7 100644
--- a/chromium/media/audio/mac/audio_low_latency_input_mac_unittest.cc
+++ b/chromium/media/audio/mac/audio_low_latency_input_mac_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -144,7 +144,7 @@ class MacAudioInputTest : public testing::Test {
int samples_per_packet = fs / 100;
AudioInputStream* ais = audio_manager_->MakeAudioInputStream(
AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_STEREO, fs, samples_per_packet),
+ ChannelLayoutConfig::Stereo(), fs, samples_per_packet),
AudioDeviceDescription::kDefaultDeviceId,
base::BindRepeating(&MacAudioInputTest::OnLogMessage,
base::Unretained(this)));
@@ -154,12 +154,13 @@ class MacAudioInputTest : public testing::Test {
// Convenience method which creates an AudioInputStream object with a
// specified channel layout.
- AudioInputStream* CreateAudioInputStream(ChannelLayout channel_layout) {
+ AudioInputStream* CreateAudioInputStream(
+ ChannelLayoutConfig channel_layout_config) {
int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate());
int samples_per_packet = fs / 100;
AudioInputStream* ais = audio_manager_->MakeAudioInputStream(
- AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
- fs, samples_per_packet),
+ AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
+ channel_layout_config, fs, samples_per_packet),
AudioDeviceDescription::kDefaultDeviceId,
base::BindRepeating(&MacAudioInputTest::OnLogMessage,
base::Unretained(this)));
@@ -217,7 +218,7 @@ TEST_F(MacAudioInputTest, AUAudioInputStreamVerifyMonoRecording) {
int count = 0;
// Create an audio input stream which records in mono.
- AudioInputStream* ais = CreateAudioInputStream(CHANNEL_LAYOUT_MONO);
+ AudioInputStream* ais = CreateAudioInputStream(ChannelLayoutConfig::Mono());
EXPECT_EQ(ais->Open(), AudioInputStream::OpenOutcome::kSuccess);
MockAudioInputCallback sink;
@@ -246,7 +247,7 @@ TEST_F(MacAudioInputTest, AUAudioInputStreamVerifyStereoRecording) {
int count = 0;
// Create an audio input stream which records in stereo.
- AudioInputStream* ais = CreateAudioInputStream(CHANNEL_LAYOUT_STEREO);
+ AudioInputStream* ais = CreateAudioInputStream(ChannelLayoutConfig::Stereo());
EXPECT_EQ(ais->Open(), AudioInputStream::OpenOutcome::kSuccess);
MockAudioInputCallback sink;
diff --git a/chromium/media/audio/mac/audio_manager_mac.cc b/chromium/media/audio/mac/audio_manager_mac.cc
index eb0aff29b2f..f2e38845218 100644
--- a/chromium/media/audio/mac/audio_manager_mac.cc
+++ b/chromium/media/audio/mac/audio_manager_mac.cc
@@ -1,10 +1,9 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/audio/mac/audio_manager_mac.h"
-#include <algorithm>
#include <limits>
#include <memory>
#include <utility>
@@ -19,6 +18,7 @@
#include "base/memory/free_deleter.h"
#include "base/power_monitor/power_monitor.h"
#include "base/power_monitor/power_observer.h"
+#include "base/ranges/algorithm.h"
#include "base/strings/sys_string_conversions.h"
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
@@ -609,14 +609,14 @@ AudioParameters AudioManagerMac::GetInputStreamParameters(
if (device == kAudioObjectUnknown) {
DLOG(ERROR) << "Invalid device " << device_id;
return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_STEREO, kFallbackSampleRate,
+ ChannelLayoutConfig::Stereo(), kFallbackSampleRate,
ChooseBufferSize(true, kFallbackSampleRate));
}
int channels = 0;
- ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
+ ChannelLayoutConfig channel_layout_config = ChannelLayoutConfig::Stereo();
if (GetDeviceChannels(device, AUElement::INPUT, &channels) && channels <= 2) {
- channel_layout = GuessChannelLayout(channels);
+ channel_layout_config = ChannelLayoutConfig::Guess(channels);
} else {
DLOG(ERROR) << "Failed to get the device channels, use stereo as default "
<< "for device " << device_id;
@@ -633,8 +633,8 @@ AudioParameters AudioManagerMac::GetInputStreamParameters(
// TODO(grunell): query the native channel layout for the specific device.
AudioParameters params(
- AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, sample_rate,
- buffer_size,
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout_config,
+ sample_rate, buffer_size,
AudioParameters::HardwareCapabilities(
GetMinAudioBufferSizeMacOS(limits::kMinAudioBufferSize, sample_rate),
limits::kMaxAudioBufferSize));
@@ -828,7 +828,8 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
return input_params.IsValid()
? input_params
: AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_STEREO, kFallbackSampleRate,
+ ChannelLayoutConfig::Stereo(),
+ kFallbackSampleRate,
ChooseBufferSize(false, kFallbackSampleRate));
}
@@ -873,13 +874,12 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
}
AudioParameters params(
- AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, {channel_layout, output_channels},
hardware_sample_rate, buffer_size,
AudioParameters::HardwareCapabilities(
GetMinAudioBufferSizeMacOS(limits::kMinAudioBufferSize,
hardware_sample_rate),
limits::kMaxAudioBufferSize));
- params.set_channels_for_discrete(output_channels);
return params;
}
@@ -1229,9 +1229,7 @@ void AudioManagerMac::ReleaseOutputStreamUsingRealDevice(
void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) {
DCHECK(GetTaskRunner()->BelongsToCurrentThread());
- auto stream_it = std::find(basic_input_streams_.begin(),
- basic_input_streams_.end(),
- stream);
+ auto stream_it = base::ranges::find(basic_input_streams_, stream);
if (stream_it == basic_input_streams_.end())
low_latency_input_streams_.remove(static_cast<AUAudioInputStream*>(stream));
else
diff --git a/chromium/media/audio/mac/audio_manager_mac.h b/chromium/media/audio/mac/audio_manager_mac.h
index 77662281466..4947d356986 100644
--- a/chromium/media/audio/mac/audio_manager_mac.h
+++ b/chromium/media/audio/mac/audio_manager_mac.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mac/core_audio_util_mac.cc b/chromium/media/audio/mac/core_audio_util_mac.cc
index b7e30eace0b..f9a969fc054 100644
--- a/chromium/media/audio/mac/core_audio_util_mac.cc
+++ b/chromium/media/audio/mac/core_audio_util_mac.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -321,7 +321,8 @@ bool IsInputDevice(AudioObjectID device_id) {
auto direction =
GetDeviceUint32Property(stream_id, kAudioStreamPropertyDirection,
kAudioObjectPropertyScopeGlobal);
- DCHECK(direction.has_value());
+ if (!direction.has_value())
+ continue;
const UInt32 kDirectionOutput = 0;
const UInt32 kDirectionInput = 1;
if (direction == kDirectionOutput) {
diff --git a/chromium/media/audio/mac/core_audio_util_mac.h b/chromium/media/audio/mac/core_audio_util_mac.h
index b46243a5167..32848cf1fd2 100644
--- a/chromium/media/audio/mac/core_audio_util_mac.h
+++ b/chromium/media/audio/mac/core_audio_util_mac.h
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mac/coreaudio_dispatch_override.cc b/chromium/media/audio/mac/coreaudio_dispatch_override.cc
index 022b3e0cc57..3a27340ea97 100644
--- a/chromium/media/audio/mac/coreaudio_dispatch_override.cc
+++ b/chromium/media/audio/mac/coreaudio_dispatch_override.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mac/coreaudio_dispatch_override.h b/chromium/media/audio/mac/coreaudio_dispatch_override.h
index efd9f8c12b2..7dbb0a3ab37 100644
--- a/chromium/media/audio/mac/coreaudio_dispatch_override.h
+++ b/chromium/media/audio/mac/coreaudio_dispatch_override.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mac/scoped_audio_unit.cc b/chromium/media/audio/mac/scoped_audio_unit.cc
index e0633460ec5..99367ddf827 100644
--- a/chromium/media/audio/mac/scoped_audio_unit.cc
+++ b/chromium/media/audio/mac/scoped_audio_unit.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mac/scoped_audio_unit.h b/chromium/media/audio/mac/scoped_audio_unit.h
index d4bc1cfe703..da074d8f705 100644
--- a/chromium/media/audio/mac/scoped_audio_unit.h
+++ b/chromium/media/audio/mac/scoped_audio_unit.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mock_aecdump_recording_manager.cc b/chromium/media/audio/mock_aecdump_recording_manager.cc
new file mode 100644
index 00000000000..64c23848d41
--- /dev/null
+++ b/chromium/media/audio/mock_aecdump_recording_manager.cc
@@ -0,0 +1,17 @@
+// Copyright 2022 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/audio/mock_aecdump_recording_manager.h"
+
+#include <utility>
+
+namespace media {
+
+MockAecdumpRecordingManager::MockAecdumpRecordingManager(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner)
+ : AecdumpRecordingManager(task_runner) {}
+
+MockAecdumpRecordingManager::~MockAecdumpRecordingManager() = default;
+
+} // namespace media
diff --git a/chromium/media/audio/mock_aecdump_recording_manager.h b/chromium/media/audio/mock_aecdump_recording_manager.h
new file mode 100644
index 00000000000..e44c63d9afe
--- /dev/null
+++ b/chromium/media/audio/mock_aecdump_recording_manager.h
@@ -0,0 +1,34 @@
+// Copyright 2022 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_AUDIO_MOCK_AECDUMP_RECORDING_MANAGER_H_
+#define MEDIA_AUDIO_MOCK_AECDUMP_RECORDING_MANAGER_H_
+
+#include "base/task/single_thread_task_runner.h"
+#include "media/audio/aecdump_recording_manager.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace media {
+
+class MockAecdumpRecordingManager : public AecdumpRecordingManager {
+ public:
+ explicit MockAecdumpRecordingManager(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner);
+
+ MockAecdumpRecordingManager(const MockAecdumpRecordingManager&) = delete;
+ MockAecdumpRecordingManager& operator=(const MockAecdumpRecordingManager&) =
+ delete;
+
+ ~MockAecdumpRecordingManager() override;
+
+ MOCK_METHOD1(RegisterAecdumpSource, void(AecdumpRecordingSource*));
+ MOCK_METHOD1(DeregisterAecdumpSource, void(AecdumpRecordingSource*));
+
+ MOCK_METHOD1(EnableDebugRecording, void(CreateFileCallback));
+ MOCK_METHOD0(DisableDebugRecording, void());
+};
+
+} // namespace media.
+
+#endif // MEDIA_AUDIO_MOCK_AECDUMP_RECORDING_MANAGER_H_
diff --git a/chromium/media/audio/mock_audio_debug_recording_manager.cc b/chromium/media/audio/mock_audio_debug_recording_manager.cc
index 1a38ba2f417..9c7b89b6734 100644
--- a/chromium/media/audio/mock_audio_debug_recording_manager.cc
+++ b/chromium/media/audio/mock_audio_debug_recording_manager.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,9 +8,7 @@
namespace media {
-MockAudioDebugRecordingManager::MockAudioDebugRecordingManager(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : AudioDebugRecordingManager(std::move(task_runner)) {}
+MockAudioDebugRecordingManager::MockAudioDebugRecordingManager() = default;
MockAudioDebugRecordingManager::~MockAudioDebugRecordingManager() = default;
diff --git a/chromium/media/audio/mock_audio_debug_recording_manager.h b/chromium/media/audio/mock_audio_debug_recording_manager.h
index 7bf2b19d79f..3a5bb07d663 100644
--- a/chromium/media/audio/mock_audio_debug_recording_manager.h
+++ b/chromium/media/audio/mock_audio_debug_recording_manager.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -13,8 +13,7 @@ namespace media {
class MockAudioDebugRecordingManager : public AudioDebugRecordingManager {
public:
- explicit MockAudioDebugRecordingManager(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner);
+ MockAudioDebugRecordingManager();
MockAudioDebugRecordingManager(const MockAudioDebugRecordingManager&) =
delete;
diff --git a/chromium/media/audio/mock_audio_manager.cc b/chromium/media/audio/mock_audio_manager.cc
index a4056b2edf7..daaef3accd9 100644
--- a/chromium/media/audio/mock_audio_manager.cc
+++ b/chromium/media/audio/mock_audio_manager.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -132,8 +132,7 @@ void MockAudioManager::InitializeDebugRecording() {
}
DCHECK(!debug_recording_manager_);
- debug_recording_manager_ =
- std::make_unique<MockAudioDebugRecordingManager>(GetTaskRunner());
+ debug_recording_manager_ = std::make_unique<MockAudioDebugRecordingManager>();
}
AudioDebugRecordingManager* MockAudioManager::GetAudioDebugRecordingManager() {
@@ -141,6 +140,12 @@ AudioDebugRecordingManager* MockAudioManager::GetAudioDebugRecordingManager() {
return debug_recording_manager_.get();
}
+void MockAudioManager::SetAecDumpRecordingManager(
+ base::WeakPtr<AecdumpRecordingManager>) {
+ DCHECK(GetTaskRunner()->BelongsToCurrentThread());
+ // This is no-op by default.
+}
+
const char* MockAudioManager::GetName() {
return nullptr;
}
diff --git a/chromium/media/audio/mock_audio_manager.h b/chromium/media/audio/mock_audio_manager.h
index e819e910ff7..2b46355000d 100644
--- a/chromium/media/audio/mock_audio_manager.h
+++ b/chromium/media/audio/mock_audio_manager.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -65,6 +65,9 @@ class MockAudioManager : public AudioManager {
void InitializeDebugRecording() override;
AudioDebugRecordingManager* GetAudioDebugRecordingManager() override;
+ void SetAecDumpRecordingManager(base::WeakPtr<AecdumpRecordingManager>
+ aecdump_recording_manager) override;
+
const char* GetName() override;
// Setters to emulate desired in-test behavior.
diff --git a/chromium/media/audio/mock_audio_source_callback.cc b/chromium/media/audio/mock_audio_source_callback.cc
index 106b7550d54..eef525d4227 100644
--- a/chromium/media/audio/mock_audio_source_callback.cc
+++ b/chromium/media/audio/mock_audio_source_callback.cc
@@ -1,4 +1,4 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/mock_audio_source_callback.h b/chromium/media/audio/mock_audio_source_callback.h
index 1a8bcad48a1..f636918959e 100644
--- a/chromium/media/audio/mock_audio_source_callback.h
+++ b/chromium/media/audio/mock_audio_source_callback.h
@@ -1,4 +1,4 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/null_audio_sink.cc b/chromium/media/audio/null_audio_sink.cc
index a6d5ca3919c..337ce19cae3 100644
--- a/chromium/media/audio/null_audio_sink.cc
+++ b/chromium/media/audio/null_audio_sink.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/null_audio_sink.h b/chromium/media/audio/null_audio_sink.h
index b6818d3140d..dd037a39d62 100644
--- a/chromium/media/audio/null_audio_sink.h
+++ b/chromium/media/audio/null_audio_sink.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/power_observer_helper.cc b/chromium/media/audio/power_observer_helper.cc
index 187ca85ceaf..16c9e982c54 100644
--- a/chromium/media/audio/power_observer_helper.cc
+++ b/chromium/media/audio/power_observer_helper.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/power_observer_helper.h b/chromium/media/audio/power_observer_helper.h
index ffc31c43639..53268ff4126 100644
--- a/chromium/media/audio/power_observer_helper.h
+++ b/chromium/media/audio/power_observer_helper.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/power_observer_helper_unittest.cc b/chromium/media/audio/power_observer_helper_unittest.cc
index 9f92044a84e..5ad44287bb3 100644
--- a/chromium/media/audio/power_observer_helper_unittest.cc
+++ b/chromium/media/audio/power_observer_helper_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/pulse/audio_manager_pulse.cc b/chromium/media/audio/pulse/audio_manager_pulse.cc
index b48b798ac76..45c62d674d1 100644
--- a/chromium/media/audio/pulse/audio_manager_pulse.cc
+++ b/chromium/media/audio/pulse/audio_manager_pulse.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -127,7 +127,7 @@ AudioParameters AudioManagerPulse::GetInputStreamParameters(
const int buffer_size =
user_buffer_size ? user_buffer_size : kDefaultInputBufferSize;
return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_STEREO,
+ ChannelLayoutConfig::Stereo(),
native_input_sample_rate_ ? native_input_sample_rate_
: kDefaultSampleRate,
buffer_size);
@@ -221,15 +221,15 @@ AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters(
UpdateNativeAudioHardwareInfo();
int sample_rate = native_input_sample_rate_ ? native_input_sample_rate_
: kDefaultSampleRate;
- ChannelLayout channel_layout =
- GuessChannelLayout(native_channel_count_ ? native_channel_count_ : 2);
+ ChannelLayoutConfig channel_layout_config = ChannelLayoutConfig::Guess(
+ native_channel_count_ ? native_channel_count_ : 2);
if (input_params.IsValid()) {
// Use the system's output channel count for the DISCRETE layout. This is to
// avoid a crash due to the lack of support on the multi-channel beyond 8 in
// the PulseAudio layer.
if (input_params.channel_layout() != CHANNEL_LAYOUT_DISCRETE)
- channel_layout = input_params.channel_layout();
+ channel_layout_config = input_params.channel_layout_config();
buffer_size =
std::min(kMaximumOutputBufferSize,
@@ -240,8 +240,8 @@ AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters(
if (user_buffer_size)
buffer_size = user_buffer_size;
- return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
- sample_rate, buffer_size);
+ return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
+ channel_layout_config, sample_rate, buffer_size);
}
AudioOutputStream* AudioManagerPulse::MakeOutputStream(
diff --git a/chromium/media/audio/pulse/audio_manager_pulse.h b/chromium/media/audio/pulse/audio_manager_pulse.h
index 78ee188c6d2..11adb3fd203 100644
--- a/chromium/media/audio/pulse/audio_manager_pulse.h
+++ b/chromium/media/audio/pulse/audio_manager_pulse.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/pulse/pulse.sigs b/chromium/media/audio/pulse/pulse.sigs
index 85ff08ab784..2c55eaca54b 100644
--- a/chromium/media/audio/pulse/pulse.sigs
+++ b/chromium/media/audio/pulse/pulse.sigs
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/pulse/pulse_input.cc b/chromium/media/audio/pulse/pulse_input.cc
index 1f7cca7388e..79a8bceaa56 100644
--- a/chromium/media/audio/pulse/pulse_input.cc
+++ b/chromium/media/audio/pulse/pulse_input.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/pulse/pulse_input.h b/chromium/media/audio/pulse/pulse_input.h
index 4c946df7628..9d2c9002392 100644
--- a/chromium/media/audio/pulse/pulse_input.h
+++ b/chromium/media/audio/pulse/pulse_input.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/pulse/pulse_output.cc b/chromium/media/audio/pulse/pulse_output.cc
index 6afe0113d6c..94a3d33f929 100644
--- a/chromium/media/audio/pulse/pulse_output.cc
+++ b/chromium/media/audio/pulse/pulse_output.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -49,7 +49,7 @@ PulseAudioOutputStream::PulseAudioOutputStream(
AudioManagerBase* manager,
AudioManager::LogCallback log_callback)
: params_(AudioParameters(params.format(),
- params.channel_layout(),
+ params.channel_layout_config(),
params.sample_rate(),
params.frames_per_buffer())),
device_id_(device_id),
diff --git a/chromium/media/audio/pulse/pulse_output.h b/chromium/media/audio/pulse/pulse_output.h
index 2529bad79bc..f88fb959287 100644
--- a/chromium/media/audio/pulse/pulse_output.h
+++ b/chromium/media/audio/pulse/pulse_output.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
diff --git a/chromium/media/audio/pulse/pulse_util.cc b/chromium/media/audio/pulse/pulse_util.cc
index 359394cce27..bc589ad6914 100644
--- a/chromium/media/audio/pulse/pulse_util.cc
+++ b/chromium/media/audio/pulse/pulse_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/pulse/pulse_util.h b/chromium/media/audio/pulse/pulse_util.h
index c3c0198f476..2e4151f19f1 100644
--- a/chromium/media/audio/pulse/pulse_util.h
+++ b/chromium/media/audio/pulse/pulse_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/scoped_task_runner_observer.cc b/chromium/media/audio/scoped_task_runner_observer.cc
index b4b7f5bab56..03cb76535a5 100644
--- a/chromium/media/audio/scoped_task_runner_observer.cc
+++ b/chromium/media/audio/scoped_task_runner_observer.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/scoped_task_runner_observer.h b/chromium/media/audio/scoped_task_runner_observer.h
index cc92ca70b93..f126fc56907 100644
--- a/chromium/media/audio/scoped_task_runner_observer.h
+++ b/chromium/media/audio/scoped_task_runner_observer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/simple_sources.cc b/chromium/media/audio/simple_sources.cc
index fefaf960d06..873793ed51a 100644
--- a/chromium/media/audio/simple_sources.cc
+++ b/chromium/media/audio/simple_sources.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -199,7 +199,7 @@ void FileSource::LoadWavFile(const base::FilePath& path_to_wav_file) {
// of it at a time and not the whole thing (like 10 ms at a time).
AudioParameters file_audio_slice(
AudioParameters::AUDIO_PCM_LOW_LATENCY,
- GuessChannelLayout(wav_audio_handler_->num_channels()),
+ ChannelLayoutConfig::Guess(wav_audio_handler_->num_channels()),
wav_audio_handler_->sample_rate(), params_.frames_per_buffer());
file_audio_converter_ =
diff --git a/chromium/media/audio/simple_sources.h b/chromium/media/audio/simple_sources.h
index f47f493ea64..84a480cb8ca 100644
--- a/chromium/media/audio/simple_sources.h
+++ b/chromium/media/audio/simple_sources.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/simple_sources_unittest.cc b/chromium/media/audio/simple_sources_unittest.cc
index 263d639242f..fff858c2d10 100644
--- a/chromium/media/audio/simple_sources_unittest.cc
+++ b/chromium/media/audio/simple_sources_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -25,7 +25,8 @@ TEST(SimpleSources, SineWaveAudioSource) {
static const uint32_t samples = 1024;
static const int freq = 200;
- AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
+ AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Mono(),
AudioParameters::kTelephoneSampleRate, samples);
SineWaveAudioSource source(1, freq, params.sample_rate());
@@ -123,7 +124,7 @@ TEST(SimpleSources, FileSourceTestDataWithoutLooping) {
// Create AudioParameters which match those in the WAV data.
AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
- CHANNEL_LAYOUT_STEREO, 48000, kNumFrames);
+ ChannelLayoutConfig::Stereo(), 48000, kNumFrames);
std::unique_ptr<AudioBus> audio_bus = AudioBus::Create(2, kNumFrames);
audio_bus->Zero();
@@ -161,7 +162,7 @@ TEST(SimpleSources, FileSourceTestDataWithLooping) {
// Create AudioParameters which match those in the WAV data.
AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
- CHANNEL_LAYOUT_STEREO, 48000, kNumFrames);
+ ChannelLayoutConfig::Stereo(), 48000, kNumFrames);
std::unique_ptr<AudioBus> audio_bus = AudioBus::Create(2, kNumFrames);
audio_bus->Zero();
@@ -180,7 +181,7 @@ TEST(SimpleSources, FileSourceTestDataWithLooping) {
TEST(SimpleSources, BadFilePathFails) {
AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
- CHANNEL_LAYOUT_STEREO, 48000, 10);
+ ChannelLayoutConfig::Stereo(), 48000, 10);
std::unique_ptr<AudioBus> audio_bus = AudioBus::Create(2, 10);
audio_bus->Zero();
@@ -220,7 +221,7 @@ TEST(SimpleSources, FileSourceCorruptTestDataFails) {
// Create AudioParameters which match those in the WAV data.
AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
- CHANNEL_LAYOUT_STEREO, 48000, kNumFrames);
+ ChannelLayoutConfig::Stereo(), 48000, kNumFrames);
std::unique_ptr<AudioBus> audio_bus = AudioBus::Create(2, kNumFrames);
audio_bus->Zero();
diff --git a/chromium/media/audio/system_glitch_reporter.cc b/chromium/media/audio/system_glitch_reporter.cc
index fea682ccb61..a32a51dccf4 100644
--- a/chromium/media/audio/system_glitch_reporter.cc
+++ b/chromium/media/audio/system_glitch_reporter.cc
@@ -1,4 +1,4 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
+// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/system_glitch_reporter.h b/chromium/media/audio/system_glitch_reporter.h
index 02cddf84c30..4a516cbabd1 100644
--- a/chromium/media/audio/system_glitch_reporter.h
+++ b/chromium/media/audio/system_glitch_reporter.h
@@ -1,4 +1,4 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
+// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/test_audio_thread.cc b/chromium/media/audio/test_audio_thread.cc
index f0cff7359d2..7bc70d3bfd1 100644
--- a/chromium/media/audio/test_audio_thread.cc
+++ b/chromium/media/audio/test_audio_thread.cc
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/test_audio_thread.h b/chromium/media/audio/test_audio_thread.h
index db7acf5a23b..c8b3b6622aa 100644
--- a/chromium/media/audio/test_audio_thread.h
+++ b/chromium/media/audio/test_audio_thread.h
@@ -1,4 +1,4 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/test_data.h b/chromium/media/audio/test_data.h
index c17a1267465..3ab9a93da19 100644
--- a/chromium/media/audio/test_data.h
+++ b/chromium/media/audio/test_data.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/wav_audio_handler.cc b/chromium/media/audio/wav_audio_handler.cc
index d2fa51b1941..d5ec1e3db92 100644
--- a/chromium/media/audio/wav_audio_handler.cc
+++ b/chromium/media/audio/wav_audio_handler.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/wav_audio_handler.h b/chromium/media/audio/wav_audio_handler.h
index fc6acab0f6c..43fcd710f4f 100644
--- a/chromium/media/audio/wav_audio_handler.h
+++ b/chromium/media/audio/wav_audio_handler.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/wav_audio_handler_fuzzer.cc b/chromium/media/audio/wav_audio_handler_fuzzer.cc
index ee3defb924f..6fbe07f1131 100644
--- a/chromium/media/audio/wav_audio_handler_fuzzer.cc
+++ b/chromium/media/audio/wav_audio_handler_fuzzer.cc
@@ -1,4 +1,4 @@
-// Copyright 2020 The Chromium Authors. All rights reserved.
+// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/wav_audio_handler_unittest.cc b/chromium/media/audio/wav_audio_handler_unittest.cc
index b9e1893ab2d..0646471c5eb 100644
--- a/chromium/media/audio/wav_audio_handler_unittest.cc
+++ b/chromium/media/audio/wav_audio_handler_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/audio_device_listener_win.cc b/chromium/media/audio/win/audio_device_listener_win.cc
index cdf7bec9061..c83f2128968 100644
--- a/chromium/media/audio/win/audio_device_listener_win.cc
+++ b/chromium/media/audio/win/audio_device_listener_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/audio_device_listener_win.h b/chromium/media/audio/win/audio_device_listener_win.h
index 5d6b3b490c2..f605959f37f 100644
--- a/chromium/media/audio/win/audio_device_listener_win.h
+++ b/chromium/media/audio/win/audio_device_listener_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/audio_device_listener_win_unittest.cc b/chromium/media/audio/win/audio_device_listener_win_unittest.cc
index 92adc71f2c9..964e7263ec7 100644
--- a/chromium/media/audio/win/audio_device_listener_win_unittest.cc
+++ b/chromium/media/audio/win/audio_device_listener_win_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/audio_edid_scan_win.cc b/chromium/media/audio/win/audio_edid_scan_win.cc
new file mode 100644
index 00000000000..9527596f8ce
--- /dev/null
+++ b/chromium/media/audio/win/audio_edid_scan_win.cc
@@ -0,0 +1,185 @@
+// Copyright 2022 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/audio/win/audio_edid_scan_win.h"
+
+#include <objbase.h>
+#include <oleauto.h>
+#include <string.h>
+
+#include "base/logging.h"
+#include "base/win/scoped_bstr.h"
+#include "base/win/scoped_variant.h"
+#include "base/win/wmi.h"
+
+namespace media {
+
+// Short Audio Descriptor values defined in ANSI/CEA-861
+enum {
+ kEdidAudioLpcm = 1,
+ kEdidAudioDts = 7,
+ kEdidAudioDtsHd = 11,
+};
+
+namespace {
+
+uint32_t EdidParseBlocks(const uint8_t* data, int data_size) {
+ const uint8_t *block = data, *block_end = data + data_size;
+ static constexpr uint8_t kBaseHeader[] = {0, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0};
+ constexpr uint8_t kEdidAudio = 1;
+ constexpr uint8_t kExtensionTagCea = 2;
+ constexpr int kBlockSize = 128;
+ constexpr uint8_t kSadSize = 3;
+ uint32_t bitstream_mask = 0;
+
+ // http://crbug.com/1371473
+ // TODO(dcheng): Use base::BufferIterator to parse EDID block
+ // Skip base EDID structure if present
+ if (block + kBlockSize <= block_end &&
+ (memcmp(block, kBaseHeader, sizeof(kBaseHeader)) == 0)) {
+ block += kBlockSize;
+ }
+
+ // Process CEA EDID (tag 2) extension blocks
+ for (; block + kBlockSize <= block_end; block += kBlockSize) {
+ if (block[0] != kExtensionTagCea)
+ continue;
+
+ // Process the audio data blocks containing Short Audio Descriptors (SADs),
+ // which are three bytes each. SADs start at byte 4 and end before the
+ // byte specified in block[2].
+ const uint8_t *db = block + 4, *db_end = block + block[2];
+ if (db_end > block_end)
+ continue;
+ for (; db + kSadSize <= db_end && db[0]; db += (db[0] & 0x1F) + 1) {
+ if ((db[0] >> 5) != kEdidAudio)
+ continue;
+
+ const int len = 1 + (db[0] & 0x1F);
+ if (db + len > db_end)
+ continue;
+
+ for (int i = 1; i < len; i += 3) {
+ switch ((db[i] >> 3) & 15) {
+ case kEdidAudioLpcm:
+ bitstream_mask |= kAudioBitstreamPcmLinear;
+ break;
+ case kEdidAudioDts:
+ bitstream_mask |= kAudioBitstreamDts;
+ break;
+ case kEdidAudioDtsHd:
+ bitstream_mask |= kAudioBitstreamDts;
+ bitstream_mask |= kAudioBitstreamDtsHd;
+ break;
+ }
+ }
+ }
+ }
+
+ DVLOG(1) << "SERVICE: EdidParseBlocks bitstream mask " << bitstream_mask;
+ return bitstream_mask;
+}
+
+} // namespace
+
+uint32_t ScanEdidBitstreams() {
+ // The WMI service allows the querying of monitor-type devices which report
+ // Extended Display Identification Data (EDID). The WMI service can be
+ // queried for a list of COM objects which represent the "paths" which
+ // are associated with individual EDID devices. Querying each of those
+ // paths using the WmiGetMonitorRawEEdidV1Block method returns the EDID
+ // blocks for those devices. We query the extended blocks which contain
+ // the Short Audio Descriptor (SAD), and parse them to obtain a bitmask
+ // indicating which audio content is supported. The mask consists of
+ // AudioParameters::Format flags. If multiple EDID devices are present,
+ // the intersection of flags is reported.
+ Microsoft::WRL::ComPtr<IWbemServices> wmi_services =
+ base::win::CreateWmiConnection(true, L"ROOT\\WMI");
+ if (!wmi_services)
+ return 0;
+
+ Microsoft::WRL::ComPtr<IWbemClassObject> get_edid_block;
+ if (!base::win::CreateWmiClassMethodObject(
+ wmi_services.Get(), L"WmiMonitorDescriptorMethods",
+ L"WmiGetMonitorRawEEdidV1Block", &get_edid_block)) {
+ return 0;
+ }
+
+ Microsoft::WRL::ComPtr<IEnumWbemClassObject> wmi_enumerator;
+ HRESULT hr = wmi_services->CreateInstanceEnum(
+ base::win::ScopedBstr(L"WmiMonitorDescriptorMethods").Get(),
+ WBEM_FLAG_FORWARD_ONLY, nullptr, &wmi_enumerator);
+ if (FAILED(hr))
+ return 0;
+
+ base::win::ScopedVariant block_id(1);
+ bool first = true;
+ uint32_t bitstream_mask = 0;
+
+ while (true) {
+ Microsoft::WRL::ComPtr<IWbemClassObject> class_object;
+ ULONG items_returned = 0;
+ hr = wmi_enumerator->Next(WBEM_INFINITE, 1, &class_object, &items_returned);
+ if (FAILED(hr) || hr == WBEM_S_FALSE || items_returned == 0)
+ break;
+
+ base::win::ScopedVariant path;
+ class_object->Get(L"__PATH", 0, path.Receive(), nullptr, nullptr);
+
+ if (FAILED(get_edid_block->Put(L"BlockId", 0, block_id.AsInput(), 0)))
+ break;
+
+ Microsoft::WRL::ComPtr<IWbemClassObject> out_params;
+ hr = wmi_services->ExecMethod(
+ V_BSTR(path.ptr()),
+ base::win::ScopedBstr(L"WmiGetMonitorRawEEdidV1Block").Get(), 0,
+ nullptr, get_edid_block.Get(), &out_params, nullptr);
+ if (FAILED(hr))
+ break;
+
+ base::win::ScopedVariant block_type;
+ if (FAILED(out_params->Get(L"BlockType", 0, block_type.Receive(), nullptr,
+ 0))) {
+ continue;
+ }
+
+ base::win::ScopedVariant block_content;
+ if (FAILED(out_params->Get(L"BlockContent", 0, block_content.Receive(),
+ nullptr, 0))) {
+ continue;
+ }
+
+ if (V_I4(block_type.ptr()) != 255)
+ continue;
+
+ if (block_content.type() != (VT_ARRAY | VT_UI1))
+ continue;
+
+ SAFEARRAY* array = V_ARRAY(block_content.ptr());
+ if (SafeArrayGetDim(array) != 1)
+ continue;
+
+ long lower_bound = 0;
+ long upper_bound = 0;
+ SafeArrayGetLBound(array, 1, &lower_bound);
+ SafeArrayGetUBound(array, 1, &upper_bound);
+ if (lower_bound || upper_bound <= lower_bound)
+ continue;
+
+ uint8_t* block = nullptr;
+ SafeArrayAccessData(array, reinterpret_cast<void**>(&block));
+ if (first) {
+ first = false;
+ bitstream_mask = EdidParseBlocks(block, upper_bound + 1);
+ } else {
+ bitstream_mask &= EdidParseBlocks(block, upper_bound + 1);
+ }
+ SafeArrayUnaccessData(array);
+ }
+
+ return bitstream_mask;
+}
+
+} // namespace media
diff --git a/chromium/media/audio/win/audio_edid_scan_win.h b/chromium/media/audio/win/audio_edid_scan_win.h
new file mode 100644
index 00000000000..f57275e6ea2
--- /dev/null
+++ b/chromium/media/audio/win/audio_edid_scan_win.h
@@ -0,0 +1,36 @@
+// Copyright 2022 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_AUDIO_WIN_AUDIO_EDID_SCAN_WIN_H_
+#define MEDIA_AUDIO_WIN_AUDIO_EDID_SCAN_WIN_H_
+
+#include <stdint.h>
+
+#include "media/base/media_export.h"
+
+namespace media {
+
+// The WMI service allows the querying of monitor-type devices which report
+// Extended Display Identification Data (EDID). The WMI service can be
+// queried for a list of COM objects which represent the "paths" which
+// are associated with individual EDID devices. Querying each of those
+// paths using the WmiGetMonitorRawEEdidV1Block method returns the EDID
+// blocks for those devices. We query the extended blocks which contain
+// the Short Audio Descriptor (SAD), and parse them to obtain a bitmask
+// indicating which audio content is supported. The mask consists of
+// AudioParameters::Format flags. If multiple EDID devices are present,
+// the intersection of flags is reported.
+MEDIA_EXPORT uint32_t ScanEdidBitstreams();
+
+// Bitmask returned by ScanEdidBitstreams. Set bits indicate detected
+// audio passthrough support.
+enum : uint32_t {
+ kAudioBitstreamPcmLinear = 0x001, // PCM is 'raw' amplitude samples.
+ kAudioBitstreamDts = 0x002, // Compressed DTS bitstream.
+ kAudioBitstreamDtsHd = 0x004, // Compressed DTS-HD bitstream.
+};
+
+} // namespace media
+
+#endif // MEDIA_AUDIO_WIN_AUDIO_EDID_SCAN_WIN_H_
diff --git a/chromium/media/audio/win/audio_low_latency_input_win.cc b/chromium/media/audio/win/audio_low_latency_input_win.cc
index b95f1b5319c..23372ebe4e4 100644
--- a/chromium/media/audio/win/audio_low_latency_input_win.cc
+++ b/chromium/media/audio/win/audio_low_latency_input_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,7 +14,6 @@
#include <memory>
#include <utility>
-#include "base/command_line.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
@@ -424,9 +423,8 @@ AudioInputStream::OpenOutcome WASAPIAudioInputStream::Open() {
}
}
- const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
use_fake_audio_capture_timestamps_ =
- cmd_line->HasSwitch(switches::kUseFakeAudioCaptureTimestamps);
+ base::FeatureList::IsEnabled(media::kUseFakeAudioCaptureTimestamps);
if (use_fake_audio_capture_timestamps_) {
SendLogMessage("%s => (WARNING: capture timestamps will be fake)",
__func__);
@@ -651,15 +649,13 @@ void WASAPIAudioInputStream::Close() {
base::UmaHistogramBoolean("Media.Audio.RawProcessingSupportedWin",
raw_processing_supported_);
+ // These UMAs are deprecated but keep adding the information as text logs
+ // for debugging purposes.
for (auto const& type : default_effect_types_) {
- base::UmaHistogramSparse("Media.Audio.Capture.Win.DefaultEffectType",
- type);
SendLogMessage("%s => (Media.Audio.Capture.Win.DefaultEffectType=%s)",
__func__, EffectTypeToString(type));
}
-
for (auto const& type : raw_effect_types_) {
- base::UmaHistogramSparse("Media.Audio.Capture.Win.RawEffectType", type);
SendLogMessage("%s => (Media.Audio.Capture.Win.RawEffectType=%s)",
__func__, EffectTypeToString(type));
}
@@ -1464,10 +1460,12 @@ void WASAPIAudioInputStream::SetupConverterAndStoreFormatInfo() {
double new_frames_per_buffer =
input_format_.Format.nSamplesPerSec / buffer_ratio;
- const auto input_layout = GuessChannelLayout(input_format_.Format.nChannels);
- DCHECK_NE(CHANNEL_LAYOUT_UNSUPPORTED, input_layout);
- const auto output_layout = GuessChannelLayout(output_format_.nChannels);
- DCHECK_NE(CHANNEL_LAYOUT_UNSUPPORTED, output_layout);
+ const auto input_layout =
+ ChannelLayoutConfig::Guess(input_format_.Format.nChannels);
+ DCHECK_NE(CHANNEL_LAYOUT_UNSUPPORTED, input_layout.channel_layout());
+ const auto output_layout =
+ ChannelLayoutConfig::Guess(output_format_.nChannels);
+ DCHECK_NE(CHANNEL_LAYOUT_UNSUPPORTED, output_layout.channel_layout());
const AudioParameters input(AudioParameters::AUDIO_PCM_LOW_LATENCY,
input_layout, input_format_.Format.nSamplesPerSec,
diff --git a/chromium/media/audio/win/audio_low_latency_input_win.h b/chromium/media/audio/win/audio_low_latency_input_win.h
index 26c7e379473..3357e5b7bb7 100644
--- a/chromium/media/audio/win/audio_low_latency_input_win.h
+++ b/chromium/media/audio/win/audio_low_latency_input_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
diff --git a/chromium/media/audio/win/audio_low_latency_input_win_unittest.cc b/chromium/media/audio/win/audio_low_latency_input_win_unittest.cc
index 6553abc1336..a4daa049897 100644
--- a/chromium/media/audio/win/audio_low_latency_input_win_unittest.cc
+++ b/chromium/media/audio/win/audio_low_latency_input_win_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -615,12 +615,12 @@ TEST_F(WinAudioInputTest, DISABLED_WASAPIAudioInputStreamResampleToFile) {
struct TestData {
const int rate;
const int frames;
- ChannelLayout layout;
+ ChannelLayoutConfig layout;
} tests[] = {
- {8000, 80, CHANNEL_LAYOUT_MONO},
- {8000, 80, CHANNEL_LAYOUT_STEREO},
- {44100, 441, CHANNEL_LAYOUT_MONO},
- {44100, 1024, CHANNEL_LAYOUT_STEREO},
+ {8000, 80, media::ChannelLayoutConfig::Mono()},
+ {8000, 80, media::ChannelLayoutConfig::Stereo()},
+ {44100, 441, media::ChannelLayoutConfig::Mono()},
+ {44100, 1024, media::ChannelLayoutConfig::Stereo()},
};
for (const auto& test : tests) {
diff --git a/chromium/media/audio/win/audio_low_latency_output_win.cc b/chromium/media/audio/win/audio_low_latency_output_win.cc
index c3a4facf84d..5767a6bafa1 100644
--- a/chromium/media/audio/win/audio_low_latency_output_win.cc
+++ b/chromium/media/audio/win/audio_low_latency_output_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -89,6 +89,7 @@ WASAPIAudioOutputStream::WASAPIAudioOutputStream(
manager_(manager),
glitch_reporter_(SystemGlitchReporter::StreamType::kRender),
format_(),
+ params_(params),
opened_(false),
volume_(1.0),
packet_size_frames_(0),
@@ -102,6 +103,10 @@ WASAPIAudioOutputStream::WASAPIAudioOutputStream(
source_(nullptr),
log_callback_(std::move(log_callback)) {
DCHECK(manager_);
+#if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+ if (params.format() == AudioParameters::AUDIO_BITSTREAM_DTS)
+ DCHECK_EQ(GetShareMode(), AUDCLNT_SHAREMODE_EXCLUSIVE);
+#endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
// The empty string is used to indicate a default device and the
// |device_role_| member controls whether that's the default or default
@@ -138,13 +143,28 @@ WASAPIAudioOutputStream::WASAPIAudioOutputStream(
format_.Samples.wValidBitsPerSample = format->wBitsPerSample;
format_.dwChannelMask = CoreAudioUtil::GetChannelConfig(device_id, eRender);
format_.SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
- SendLogMessage("%s => (audio engine format=[%s])", __func__,
- CoreAudioUtil::WaveFormatToString(&format_).c_str());
// Store size (in different units) of audio packets which we expect to
// get from the audio endpoint device in each render event.
packet_size_frames_ = params.frames_per_buffer();
packet_size_bytes_ = params.GetBytesPerBuffer(kSampleFormatF32);
+
+#if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+ if (params.format() == AudioParameters::AUDIO_BITSTREAM_DTS) {
+ format_.SubFormat = KSDATAFORMAT_SUBTYPE_IEC61937_DTS;
+ format->wBitsPerSample = 16;
+ format->nChannels = 2;
+ format_.dwChannelMask = KSAUDIO_SPEAKER_STEREO;
+ format_.Samples.wValidBitsPerSample = format->wBitsPerSample;
+ format->nBlockAlign = (format->wBitsPerSample / 8) * format->nChannels;
+ format->nAvgBytesPerSec = format->nSamplesPerSec * format->nBlockAlign;
+ packet_size_frames_ = 512;
+ packet_size_bytes_ = params.GetBytesPerBuffer(kSampleFormatS16);
+ }
+#endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+ SendLogMessage("%s => (audio engine format=[%s])", __func__,
+ CoreAudioUtil::WaveFormatToString(&format_).c_str());
+
SendLogMessage("%s => (packet size=[%zu bytes/%zu audio frames/%.3f ms])",
__func__, packet_size_bytes_, packet_size_frames_,
params.GetBufferDuration().InMillisecondsF());
@@ -462,6 +482,10 @@ void WASAPIAudioOutputStream::Close() {
void WASAPIAudioOutputStream::Flush() {}
void WASAPIAudioOutputStream::SetVolume(double volume) {
+#if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+ if (params_.format() == AudioParameters::AUDIO_BITSTREAM_DTS)
+ return;
+#endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
SendLogMessage("%s({volume=%.2f})", __func__, volume);
float volume_float = static_cast<float>(volume);
if (volume_float < 0.0f || volume_float > 1.0f) {
@@ -707,11 +731,29 @@ bool WASAPIAudioOutputStream::RenderAudioFromSource(UINT64 device_frequency) {
// Read a data packet from the registered client source and
// deliver a delay estimate in the same callback to the client.
+#if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+ if (params_.format() == AudioParameters::AUDIO_BITSTREAM_DTS) {
+ std::unique_ptr<AudioBus> audio_bus(
+ AudioBus::WrapMemory(params_, audio_data));
+ audio_bus_->set_is_bitstream_format(true);
+ int frames_filled =
+ source_->OnMoreData(delay, delay_timestamp, 0, audio_bus.get());
+
+ // During pause/seek, keep the pipeline filled with zero'ed frames.
+ if (!frames_filled)
+ memset(audio_data, 0, packet_size_frames_);
+
+ // Release the buffer space acquired in the GetBuffer() call.
+ // Render silence if we were not able to fill up the buffer totally.
+ audio_render_client_->ReleaseBuffer(packet_size_frames_, 0);
+ num_written_frames_ += packet_size_frames_;
+ return true;
+ }
+#endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
int frames_filled =
source_->OnMoreData(delay, delay_timestamp, 0, audio_bus_.get());
uint32_t num_filled_bytes = frames_filled * format_.Format.nBlockAlign;
DCHECK_LE(num_filled_bytes, packet_size_bytes_);
-
audio_bus_->Scale(volume_);
// We skip clipping since that occurs at the shared memory boundary.
diff --git a/chromium/media/audio/win/audio_low_latency_output_win.h b/chromium/media/audio/win/audio_low_latency_output_win.h
index 27c9b1ea79c..19950f18971 100644
--- a/chromium/media/audio/win/audio_low_latency_output_win.h
+++ b/chromium/media/audio/win/audio_low_latency_output_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -207,6 +207,9 @@ class MEDIA_EXPORT WASAPIAudioOutputStream
// Use this for multiple channel and hi-resolution PCM data.
WAVEFORMATPCMEX format_;
+ // AudioParameters from the constructor.
+ const AudioParameters params_;
+
// Set to true when stream is successfully opened.
bool opened_;
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 b91239aceeb..e1495c783aa 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
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -204,11 +204,8 @@ class AudioOutputStreamWrapper {
private:
AudioOutputStream* CreateOutputStream() {
- AudioParameters params(format_, channel_layout_, sample_rate_,
+ AudioParameters params(format_, {channel_layout_, channels_}, sample_rate_,
samples_per_packet_);
- if (channel_layout_ == CHANNEL_LAYOUT_DISCRETE) {
- params.set_channels_for_discrete(channels_);
- }
DVLOG(1) << params.AsHumanReadableString();
AudioOutputStream* aos = audio_man_->MakeAudioOutputStream(
params, std::string(), AudioManager::LogCallback());
diff --git a/chromium/media/audio/win/audio_manager_win.cc b/chromium/media/audio/win/audio_manager_win.cc
index 370edec9e9f..611e3006d4a 100644
--- a/chromium/media/audio/win/audio_manager_win.cc
+++ b/chromium/media/audio/win/audio_manager_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -13,7 +13,6 @@
#include <setupapi.h>
#include <stddef.h>
-#include <memory>
#include <utility>
#include "base/bind.h"
@@ -35,6 +34,10 @@
#include "media/base/limits.h"
#include "media/base/media_switches.h"
+#if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+#include "media/audio/win/audio_edid_scan_win.h"
+#endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+
// The following are defined in various DDK headers, and we (re)define them here
// to avoid adding the DDK as a chrome dependency.
#define DRV_QUERYDEVICEINTERFACE 0x80c
@@ -66,7 +69,26 @@ constexpr int kWinMaxChannels = 8;
// determined from the system
constexpr int kFallbackBufferSize = 2048;
-static int NumberOfWaveOutBuffers() {
+namespace {
+
+#if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+// Passthrough flags as defined in audio_edid_scan_win.h
+uint32_t bitstream_passthrough_bitmask_;
+
+// Convert result from ScanEdidBitstreams to AudioParameters::Format values
+uint32_t ConvertEdidScanToAudioBitstreamFlags(uint32_t edid_scan) {
+ uint32_t bitstream_codecs = 0;
+ if (edid_scan & kAudioBitstreamPcmLinear)
+ bitstream_codecs |= AudioParameters::AUDIO_PCM_LINEAR;
+ if (edid_scan & kAudioBitstreamDts)
+ bitstream_codecs |= AudioParameters::AUDIO_BITSTREAM_DTS;
+ if (edid_scan & kAudioBitstreamDtsHd)
+ bitstream_codecs |= AudioParameters::AUDIO_BITSTREAM_DTS_HD;
+ return bitstream_codecs;
+}
+#endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+
+int NumberOfWaveOutBuffers() {
// Use the user provided buffer count if provided.
int buffers = 0;
std::string buffers_str(
@@ -79,6 +101,8 @@ static int NumberOfWaveOutBuffers() {
return 3;
}
+} // namespace
+
AudioManagerWin::AudioManagerWin(std::unique_ptr<AudioThread> audio_thread,
AudioLogFactory* audio_log_factory)
: AudioManagerBase(std::move(audio_thread), audio_log_factory) {
@@ -183,9 +207,9 @@ AudioParameters AudioManagerWin::GetInputStreamParameters(
// unavailable device. We should track down those code paths (it is likely
// that they actually don't need a real device but depend on the audio
// code path somehow for a configuration - e.g. tab capture).
- parameters =
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
- CHANNEL_LAYOUT_STEREO, 48000, kFallbackBufferSize);
+ parameters = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Stereo(), 48000,
+ kFallbackBufferSize);
}
int user_buffer_size = GetUserBufferSize();
@@ -218,6 +242,17 @@ AudioOutputStream* AudioManagerWin::MakeLinearOutputStream(
WAVE_MAPPER);
}
+AudioOutputStream* AudioManagerWin::MakeBitstreamOutputStream(
+ const AudioParameters& params,
+ const std::string& device_id,
+ const LogCallback& log_callback) {
+#if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+ return MakeLowLatencyOutputStream(params, device_id, log_callback);
+#else // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+ return nullptr;
+#endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+}
+
// Factory for the implementations of AudioOutputStream for
// AUDIO_PCM_LOW_LATENCY mode. Two implementations should suffice most
// windows user's needs.
@@ -227,7 +262,14 @@ AudioOutputStream* AudioManagerWin::MakeLowLatencyOutputStream(
const AudioParameters& params,
const std::string& device_id,
const LogCallback& log_callback) {
- DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
+#if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+ DCHECK(params.format() == AudioParameters::AUDIO_BITSTREAM_DTS ||
+ params.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY)
+ << params.format();
+#else
+ DCHECK_EQ(params.format(), AudioParameters::AUDIO_PCM_LOW_LATENCY);
+#endif
+
if (params.channels() > kWinMaxChannels)
return nullptr;
@@ -290,16 +332,13 @@ AudioParameters AudioManagerWin::GetPreferredOutputStreamParameters(
const std::string& output_device_id,
const AudioParameters& input_params) {
const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
- int channels = 0;
- ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
+ ChannelLayoutConfig channel_layout_config = ChannelLayoutConfig::Stereo();
int sample_rate = 48000;
int buffer_size = kFallbackBufferSize;
int effects = AudioParameters::NO_EFFECTS;
int min_buffer_size = 0;
int max_buffer_size = 0;
- // TODO(henrika): Remove kEnableExclusiveAudio and related code. It doesn't
- // look like it's used.
if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) {
// TODO(rtoy): tune these values for best possible WebAudio
// performance. WebRTC works well at 48kHz and a buffer size of 480
@@ -309,7 +348,7 @@ AudioParameters AudioManagerWin::GetPreferredOutputStreamParameters(
sample_rate = 48000;
buffer_size = 256;
if (input_params.IsValid())
- channel_layout = input_params.channel_layout();
+ channel_layout_config = input_params.channel_layout_config();
} else {
AudioParameters params;
HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(
@@ -329,9 +368,8 @@ AudioParameters AudioManagerWin::GetPreferredOutputStreamParameters(
DVLOG(1) << params.AsHumanReadableString();
DCHECK(params.IsValid());
- channels = params.channels();
+ channel_layout_config = params.channel_layout_config();
buffer_size = params.frames_per_buffer();
- channel_layout = params.channel_layout();
sample_rate = params.sample_rate();
effects = params.effects();
@@ -347,12 +385,13 @@ AudioParameters AudioManagerWin::GetPreferredOutputStreamParameters(
// have a valid channel layout yet, try to use the input layout. See bugs
// http://crbug.com/259165 and http://crbug.com/311906 for more details.
if (cmd_line->HasSwitch(switches::kTrySupportedChannelLayouts) ||
- channel_layout == CHANNEL_LAYOUT_UNSUPPORTED) {
+ channel_layout_config.channel_layout() == CHANNEL_LAYOUT_UNSUPPORTED) {
// Check if it is possible to open up at the specified input channel
// layout but avoid checking if the specified layout is the same as the
// hardware (preferred) layout. We do this extra check to avoid the
// CoreAudioUtil::IsChannelLayoutSupported() overhead in most cases.
- if (input_params.channel_layout() != channel_layout) {
+ if (input_params.channel_layout() !=
+ channel_layout_config.channel_layout()) {
// TODO(henrika): Internally, IsChannelLayoutSupported does many of the
// operations that have already been done such as opening up a client
// and fetching the WAVEFORMATPCMEX format. Ideally we should only do
@@ -363,9 +402,10 @@ AudioParameters AudioManagerWin::GetPreferredOutputStreamParameters(
input_params.channel_layout())) {
// Open up using the same channel layout as the source if it is
// supported by the hardware.
- channel_layout = input_params.channel_layout();
+ channel_layout_config = input_params.channel_layout_config();
DVLOG(1) << "Hardware channel layout is not used; using same layout"
- << " as the source instead (" << channel_layout << ")";
+ << " as the source instead ("
+ << channel_layout_config.channel_layout() << ")";
}
}
}
@@ -384,14 +424,21 @@ AudioParameters AudioManagerWin::GetPreferredOutputStreamParameters(
if (user_buffer_size)
buffer_size = user_buffer_size;
- AudioParameters params(
- AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, sample_rate,
- buffer_size,
- AudioParameters::HardwareCapabilities(min_buffer_size, max_buffer_size));
- params.set_effects(effects);
- if (channel_layout == CHANNEL_LAYOUT_DISCRETE) {
- params.set_channels_for_discrete(channels);
+ AudioParameters::HardwareCapabilities hardware_capabilities(min_buffer_size,
+ max_buffer_size);
+#if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+ hardware_capabilities.bitstream_formats = 0;
+ hardware_capabilities.require_encapsulation = false;
+ if (WASAPIAudioOutputStream::GetShareMode() == AUDCLNT_SHAREMODE_EXCLUSIVE) {
+ hardware_capabilities.bitstream_formats =
+ ConvertEdidScanToAudioBitstreamFlags(bitstream_passthrough_bitmask_);
+ hardware_capabilities.require_encapsulation = true;
}
+#endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+ AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY,
+ channel_layout_config, sample_rate, buffer_size,
+ hardware_capabilities);
+ params.set_effects(effects);
DCHECK(params.IsValid());
return params;
}
@@ -404,4 +451,10 @@ std::unique_ptr<AudioManager> CreateAudioManager(
audio_log_factory);
}
+#if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+void AudioManagerWin::SetBitstreamPassthroughBitmask(uint32_t bitmask) {
+ bitstream_passthrough_bitmask_ = bitmask;
+}
+#endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+
} // namespace media
diff --git a/chromium/media/audio/win/audio_manager_win.h b/chromium/media/audio/win/audio_manager_win.h
index d6b0774307d..2f6bf87907d 100644
--- a/chromium/media/audio/win/audio_manager_win.h
+++ b/chromium/media/audio/win/audio_manager_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,6 +9,7 @@
#include <string>
#include "media/audio/audio_manager_base.h"
+#include "media/media_buildflags.h"
namespace media {
@@ -54,11 +55,20 @@ class MEDIA_EXPORT AudioManagerWin : public AudioManagerBase {
const AudioParameters& params,
const std::string& device_id,
const LogCallback& log_callback) override;
+ AudioOutputStream* MakeBitstreamOutputStream(
+ const AudioParameters& params,
+ const std::string& device_id,
+ const LogCallback& log_callback) override;
std::string GetDefaultInputDeviceID() override;
std::string GetDefaultOutputDeviceID() override;
std::string GetCommunicationsInputDeviceID() override;
std::string GetCommunicationsOutputDeviceID() override;
+#if BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+ // Bitmask indicating which audio codecs are playable using passthrough.
+ static void SetBitstreamPassthroughBitmask(uint32_t bitmask);
+#endif // BUILDFLAG(ENABLE_PLATFORM_DTS_AUDIO)
+
protected:
void ShutdownOnAudioThread() override;
AudioParameters GetPreferredOutputStreamParameters(
@@ -75,6 +85,10 @@ class MEDIA_EXPORT AudioManagerWin : public AudioManagerBase {
void GetAudioDeviceNamesImpl(bool input, AudioDeviceNames* device_names);
+ AudioOutputStream* MakeOutputStream(const AudioParameters& params,
+ const std::string& device_id,
+ const LogCallback& log_callback);
+
// Listen for output device changes.
std::unique_ptr<AudioDeviceListenerWin> output_device_listener_;
};
diff --git a/chromium/media/audio/win/audio_output_win_unittest.cc b/chromium/media/audio/win/audio_output_win_unittest.cc
index fa193d5aa8d..9b537b97cce 100644
--- a/chromium/media/audio/win/audio_output_win_unittest.cc
+++ b/chromium/media/audio/win/audio_output_win_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -184,8 +184,8 @@ TEST_F(WinAudioTest, PCMWaveStreamGetAndClose) {
ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices());
AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
- 8000, 256),
+ AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Stereo(), 8000, 256),
std::string(), AudioManager::LogCallback());
ASSERT_TRUE(NULL != oas);
oas->Close();
@@ -196,8 +196,8 @@ TEST_F(WinAudioTest, PCMWaveStreamOpenAndClose) {
ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices());
AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
- 8000, 256),
+ AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Stereo(), 8000, 256),
std::string(), AudioManager::LogCallback());
ASSERT_TRUE(NULL != oas);
EXPECT_TRUE(oas->Open());
@@ -211,8 +211,8 @@ TEST_F(WinAudioTest, PCMWaveSlowSource) {
ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices());
AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
- 16000, 256),
+ AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Mono(), 16000, 256),
std::string(), AudioManager::LogCallback());
ASSERT_TRUE(NULL != oas);
TestSourceLaggy test_laggy(90);
@@ -236,7 +236,8 @@ TEST_F(WinAudioTest, PCMWaveStreamPlaySlowLoop) {
uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10;
AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
+ AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Mono(),
AudioParameters::kAudioCDSampleRate, samples_100_ms),
std::string(), AudioManager::LogCallback());
ASSERT_TRUE(NULL != oas);
@@ -266,7 +267,8 @@ TEST_F(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) {
uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10;
AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
+ AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Mono(),
AudioParameters::kAudioCDSampleRate, samples_100_ms),
std::string(), AudioManager::LogCallback());
ASSERT_TRUE(NULL != oas);
@@ -290,7 +292,8 @@ TEST_F(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) {
uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 20;
AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
+ AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Mono(),
AudioParameters::kAudioCDSampleRate / 2, samples_100_ms),
std::string(), AudioManager::LogCallback());
ASSERT_TRUE(NULL != oas);
@@ -326,8 +329,8 @@ TEST_F(WinAudioTest, PushSourceFile16KHz) {
source.CapSamples(kSamples100ms);
AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
- kSampleRate, kSamples100ms),
+ AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Mono(), kSampleRate, kSamples100ms),
std::string(), AudioManager::LogCallback());
ASSERT_TRUE(NULL != oas);
@@ -359,7 +362,8 @@ TEST_F(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) {
uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10;
AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
+ AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Mono(),
AudioParameters::kAudioCDSampleRate, samples_100_ms),
std::string(), AudioManager::LogCallback());
ASSERT_TRUE(NULL != oas);
@@ -398,7 +402,7 @@ TEST_F(WinAudioTest, PCMWaveStreamPlay200HzToneLowLatency) {
uint32_t samples_10_ms = sample_rate / 100;
AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
- CHANNEL_LAYOUT_MONO, sample_rate, samples_10_ms),
+ ChannelLayoutConfig::Mono(), sample_rate, samples_10_ms),
std::string(), AudioManager::LogCallback());
ASSERT_TRUE(NULL != oas);
@@ -427,7 +431,8 @@ TEST_F(WinAudioTest, PCMWaveStreamPendingBytes) {
uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10;
AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
- AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
+ AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Mono(),
AudioParameters::kAudioCDSampleRate, samples_100_ms),
std::string(), AudioManager::LogCallback());
ASSERT_TRUE(NULL != oas);
@@ -599,8 +604,9 @@ TEST_F(WinAudioTest, SyncSocketBasic) {
// We want 2 seconds of audio, which means we need 100 packets as each packet
// contains 20ms worth of audio samples.
static const int kPackets2s = 100;
- AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
- sample_rate, kSamples20ms);
+ AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
+ ChannelLayoutConfig::Mono(), sample_rate,
+ kSamples20ms);
AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
params, std::string(), AudioManager::LogCallback());
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 d344295c077..35f6fe3abb4 100644
--- a/chromium/media/audio/win/audio_session_event_listener_win.cc
+++ b/chromium/media/audio/win/audio_session_event_listener_win.cc
@@ -1,4 +1,4 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
+// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/audio_session_event_listener_win.h b/chromium/media/audio/win/audio_session_event_listener_win.h
index b3d9ec4ba14..753ee3dee1a 100644
--- a/chromium/media/audio/win/audio_session_event_listener_win.h
+++ b/chromium/media/audio/win/audio_session_event_listener_win.h
@@ -1,4 +1,4 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
+// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/audio_session_event_listener_win_unittest.cc b/chromium/media/audio/win/audio_session_event_listener_win_unittest.cc
index 8ee545e808f..7723fc01860 100644
--- a/chromium/media/audio/win/audio_session_event_listener_win_unittest.cc
+++ b/chromium/media/audio/win/audio_session_event_listener_win_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
+// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/avrt_wrapper_win.cc b/chromium/media/audio/win/avrt_wrapper_win.cc
index bde2f462eac..13956d330d7 100644
--- a/chromium/media/audio/win/avrt_wrapper_win.cc
+++ b/chromium/media/audio/win/avrt_wrapper_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/avrt_wrapper_win.h b/chromium/media/audio/win/avrt_wrapper_win.h
index 0b3462a8556..7a95f8603ab 100644
--- a/chromium/media/audio/win/avrt_wrapper_win.h
+++ b/chromium/media/audio/win/avrt_wrapper_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
diff --git a/chromium/media/audio/win/core_audio_util_win.cc b/chromium/media/audio/win/core_audio_util_win.cc
index 6bd66dec2fc..7ee461a911e 100644
--- a/chromium/media/audio/win/core_audio_util_win.cc
+++ b/chromium/media/audio/win/core_audio_util_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -25,6 +25,7 @@
#include "base/win/windows_version.h"
#include "media/audio/audio_device_description.h"
#include "media/audio/audio_features.h"
+#include "media/base/channel_layout.h"
#include "media/base/media_switches.h"
#include "media/base/win/mf_helpers.h"
@@ -564,14 +565,8 @@ HRESULT GetPreferredAudioParametersInternal(IAudioClient* client,
// Retrieve the current channel configuration (e.g. CHANNEL_LAYOUT_STEREO).
ChannelLayout channel_layout = GetChannelLayout(format);
-
- AudioParameters audio_params(
- AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, sample_rate,
- frames_per_buffer,
- AudioParameters::HardwareCapabilities(min_frames_per_buffer,
- max_frames_per_buffer));
-
- if (audio_params.channel_layout() == CHANNEL_LAYOUT_DISCRETE) {
+ int channels = ChannelLayoutToChannelCount(channel_layout);
+ if (channel_layout == CHANNEL_LAYOUT_DISCRETE) {
if (!is_output_device) {
// Set the number of channels explicitly to two for input devices if
// the channel layout is discrete to ensure that the parameters are valid
@@ -580,7 +575,7 @@ HRESULT GetPreferredAudioParametersInternal(IAudioClient* client,
// input stream implementation instead.
// See crbug.com/868026 for examples where this approach is needed.
DVLOG(1) << "Forcing number of channels to 2 for CHANNEL_LAYOUT_DISCRETE";
- audio_params.set_channels_for_discrete(2);
+ channels = 2;
} else {
// Some output devices return CHANNEL_LAYOUT_DISCRETE. Keep this channel
// format but update the number of channels with the correct value. The
@@ -588,9 +583,16 @@ HRESULT GetPreferredAudioParametersInternal(IAudioClient* client,
// See crbug.com/957886 for more details.
DVLOG(1) << "Setting number of channels to " << format->nChannels
<< " for CHANNEL_LAYOUT_DISCRETE";
- audio_params.set_channels_for_discrete(format->nChannels);
+ channels = format->nChannels;
}
}
+
+ AudioParameters audio_params(
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, {channel_layout, channels},
+ sample_rate, frames_per_buffer,
+ AudioParameters::HardwareCapabilities(min_frames_per_buffer,
+ max_frames_per_buffer));
+
DVLOG(1) << audio_params.AsHumanReadableString();
DCHECK(audio_params.IsValid());
*params = audio_params;
@@ -1086,7 +1088,7 @@ HRESULT CoreAudioUtil::GetPreferredAudioParameters(const std::string& device_id,
params->channel_layout() != CHANNEL_LAYOUT_DISCRETE) {
DLOG(WARNING)
<< "Replacing existing audio parameter with predefined version";
- params->Reset(params->format(), CHANNEL_LAYOUT_STEREO,
+ params->Reset(params->format(), media::ChannelLayoutConfig::Stereo(),
params->sample_rate(), params->frames_per_buffer());
}
diff --git a/chromium/media/audio/win/core_audio_util_win.h b/chromium/media/audio/win/core_audio_util_win.h
index 0e9a55e6059..441678f9edc 100644
--- a/chromium/media/audio/win/core_audio_util_win.h
+++ b/chromium/media/audio/win/core_audio_util_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/core_audio_util_win_unittest.cc b/chromium/media/audio/win/core_audio_util_win_unittest.cc
index 61f74af3404..3d095ddbfd4 100644
--- a/chromium/media/audio/win/core_audio_util_win_unittest.cc
+++ b/chromium/media/audio/win/core_audio_util_win_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/device_enumeration_win.cc b/chromium/media/audio/win/device_enumeration_win.cc
index df2ad518c86..11b1678768a 100644
--- a/chromium/media/audio/win/device_enumeration_win.cc
+++ b/chromium/media/audio/win/device_enumeration_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/device_enumeration_win.h b/chromium/media/audio/win/device_enumeration_win.h
index 25c162b96ea..d6f73a84244 100644
--- a/chromium/media/audio/win/device_enumeration_win.h
+++ b/chromium/media/audio/win/device_enumeration_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/device_enumeration_win_unittest.cc b/chromium/media/audio/win/device_enumeration_win_unittest.cc
index 0585df46e4b..4de39f7244b 100644
--- a/chromium/media/audio/win/device_enumeration_win_unittest.cc
+++ b/chromium/media/audio/win/device_enumeration_win_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/volume_range_util.cc b/chromium/media/audio/win/volume_range_util.cc
index 086660309c9..06af2063d38 100644
--- a/chromium/media/audio/win/volume_range_util.cc
+++ b/chromium/media/audio/win/volume_range_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2021 The Chromium Authors. All rights reserved.
+// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/volume_range_util.h b/chromium/media/audio/win/volume_range_util.h
index 29d0d62c1fa..5dfb07e3215 100644
--- a/chromium/media/audio/win/volume_range_util.h
+++ b/chromium/media/audio/win/volume_range_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2021 The Chromium Authors. All rights reserved.
+// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
diff --git a/chromium/media/audio/win/volume_range_util_unittest.cc b/chromium/media/audio/win/volume_range_util_unittest.cc
index cc3098eb69f..ce92863f140 100644
--- a/chromium/media/audio/win/volume_range_util_unittest.cc
+++ b/chromium/media/audio/win/volume_range_util_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2021 The Chromium Authors. All rights reserved.
+// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/waveout_output_win.cc b/chromium/media/audio/win/waveout_output_win.cc
index 09d65e73d31..81222be288a 100644
--- a/chromium/media/audio/win/waveout_output_win.cc
+++ b/chromium/media/audio/win/waveout_output_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/chromium/media/audio/win/waveout_output_win.h b/chromium/media/audio/win/waveout_output_win.h
index d99b2757eae..644de74a455 100644
--- a/chromium/media/audio/win/waveout_output_win.h
+++ b/chromium/media/audio/win/waveout_output_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.