summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/modules/async_audio_processing
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libwebrtc/modules/async_audio_processing')
-rw-r--r--third_party/libwebrtc/modules/async_audio_processing/BUILD.gn43
-rw-r--r--third_party/libwebrtc/modules/async_audio_processing/async_audio_processing.cc101
-rw-r--r--third_party/libwebrtc/modules/async_audio_processing/async_audio_processing.h109
-rw-r--r--third_party/libwebrtc/modules/async_audio_processing/async_audio_processing_gn/moz.build232
4 files changed, 485 insertions, 0 deletions
diff --git a/third_party/libwebrtc/modules/async_audio_processing/BUILD.gn b/third_party/libwebrtc/modules/async_audio_processing/BUILD.gn
new file mode 100644
index 0000000000..7a7ca20df1
--- /dev/null
+++ b/third_party/libwebrtc/modules/async_audio_processing/BUILD.gn
@@ -0,0 +1,43 @@
+# Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS. All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+import("../../webrtc.gni")
+
+rtc_library("async_audio_processing") {
+ sources = [
+ "async_audio_processing.cc",
+ "async_audio_processing.h",
+ ]
+
+ public = [ "async_audio_processing.h" ]
+
+ deps = [
+ "../../api:scoped_refptr",
+ "../../api:sequence_checker",
+ "../../api/audio:audio_frame_api",
+ "../../api/audio:audio_frame_processor",
+ "../../api/task_queue:task_queue",
+ "../../rtc_base:checks",
+ "../../rtc_base:refcount",
+ "../../rtc_base:rtc_task_queue",
+ ]
+}
+
+if (rtc_include_tests) {
+ rtc_library("async_audio_processing_test") {
+ testonly = true
+
+ sources = []
+
+ deps = [
+ ":async_audio_processing",
+ "../../api/audio:audio_frame_api",
+ "../../rtc_base:checks",
+ ]
+ }
+}
diff --git a/third_party/libwebrtc/modules/async_audio_processing/async_audio_processing.cc b/third_party/libwebrtc/modules/async_audio_processing/async_audio_processing.cc
new file mode 100644
index 0000000000..19c08dc3e5
--- /dev/null
+++ b/third_party/libwebrtc/modules/async_audio_processing/async_audio_processing.cc
@@ -0,0 +1,101 @@
+
+/*
+ * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "modules/async_audio_processing/async_audio_processing.h"
+
+#include <utility>
+
+#include "api/audio/audio_frame.h"
+#include "api/task_queue/task_queue_factory.h"
+#include "rtc_base/checks.h"
+
+namespace webrtc {
+
+AsyncAudioProcessing::Factory::~Factory() = default;
+AsyncAudioProcessing::Factory::Factory(AudioFrameProcessor& frame_processor,
+ TaskQueueFactory& task_queue_factory)
+ : frame_processor_(frame_processor),
+ task_queue_factory_(task_queue_factory) {}
+
+AsyncAudioProcessing::Factory::Factory(
+ std::unique_ptr<AudioFrameProcessor> frame_processor,
+ TaskQueueFactory& task_queue_factory)
+ : frame_processor_(*frame_processor),
+ owned_frame_processor_(std::move(frame_processor)),
+ task_queue_factory_(task_queue_factory) {}
+
+std::unique_ptr<AsyncAudioProcessing>
+AsyncAudioProcessing::Factory::CreateAsyncAudioProcessing(
+ AudioFrameProcessor::OnAudioFrameCallback on_frame_processed_callback) {
+ if (owned_frame_processor_) {
+ return std::make_unique<AsyncAudioProcessing>(
+ std::move(owned_frame_processor_), task_queue_factory_,
+ std::move(on_frame_processed_callback));
+ } else {
+ return std::make_unique<AsyncAudioProcessing>(
+ frame_processor_, task_queue_factory_,
+ std::move(on_frame_processed_callback));
+ }
+}
+
+AsyncAudioProcessing::~AsyncAudioProcessing() {
+ if (owned_frame_processor_) {
+ owned_frame_processor_->SetSink(nullptr);
+ } else {
+ frame_processor_.SetSink(nullptr);
+ }
+}
+
+AsyncAudioProcessing::AsyncAudioProcessing(
+ AudioFrameProcessor& frame_processor,
+ TaskQueueFactory& task_queue_factory,
+ AudioFrameProcessor::OnAudioFrameCallback on_frame_processed_callback)
+ : on_frame_processed_callback_(std::move(on_frame_processed_callback)),
+ frame_processor_(frame_processor),
+ task_queue_(task_queue_factory.CreateTaskQueue(
+ "AsyncAudioProcessing",
+ TaskQueueFactory::Priority::NORMAL)) {
+ frame_processor_.SetSink([this](std::unique_ptr<AudioFrame> frame) {
+ task_queue_.PostTask([this, frame = std::move(frame)]() mutable {
+ on_frame_processed_callback_(std::move(frame));
+ });
+ });
+}
+
+AsyncAudioProcessing::AsyncAudioProcessing(
+ std::unique_ptr<AudioFrameProcessor> frame_processor,
+ TaskQueueFactory& task_queue_factory,
+ AudioFrameProcessor::OnAudioFrameCallback on_frame_processed_callback)
+ : on_frame_processed_callback_(std::move(on_frame_processed_callback)),
+ frame_processor_(*frame_processor),
+ owned_frame_processor_(std::move(frame_processor)),
+ task_queue_(task_queue_factory.CreateTaskQueue(
+ "AsyncAudioProcessing",
+ TaskQueueFactory::Priority::NORMAL)) {
+ owned_frame_processor_->SetSink([this](std::unique_ptr<AudioFrame> frame) {
+ task_queue_.PostTask([this, frame = std::move(frame)]() mutable {
+ on_frame_processed_callback_(std::move(frame));
+ });
+ });
+}
+
+void AsyncAudioProcessing::Process(std::unique_ptr<AudioFrame> frame) {
+ if (owned_frame_processor_) {
+ task_queue_.PostTask([this, frame = std::move(frame)]() mutable {
+ owned_frame_processor_->Process(std::move(frame));
+ });
+ } else {
+ task_queue_.PostTask([this, frame = std::move(frame)]() mutable {
+ frame_processor_.Process(std::move(frame));
+ });
+ }
+}
+
+} // namespace webrtc
diff --git a/third_party/libwebrtc/modules/async_audio_processing/async_audio_processing.h b/third_party/libwebrtc/modules/async_audio_processing/async_audio_processing.h
new file mode 100644
index 0000000000..f3ed96959b
--- /dev/null
+++ b/third_party/libwebrtc/modules/async_audio_processing/async_audio_processing.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef MODULES_ASYNC_AUDIO_PROCESSING_ASYNC_AUDIO_PROCESSING_H_
+#define MODULES_ASYNC_AUDIO_PROCESSING_ASYNC_AUDIO_PROCESSING_H_
+
+#include <memory>
+
+#include "api/audio/audio_frame_processor.h"
+#include "rtc_base/ref_count.h"
+#include "rtc_base/task_queue.h"
+
+namespace webrtc {
+
+class AudioFrame;
+class TaskQueueFactory;
+
+// Helper class taking care of interactions with AudioFrameProcessor
+// in asynchronous manner. Offloads AudioFrameProcessor::Process calls
+// to a dedicated task queue. Makes sure that it's always safe for
+// AudioFrameProcessor to pass processed frames back to its sink.
+class AsyncAudioProcessing final {
+ public:
+ // Helper class passing AudioFrameProcessor and TaskQueueFactory into
+ // AsyncAudioProcessing constructor.
+ class Factory : public rtc::RefCountInterface {
+ public:
+ Factory(const Factory&) = delete;
+ Factory& operator=(const Factory&) = delete;
+
+ ~Factory();
+ Factory(AudioFrameProcessor& frame_processor,
+ TaskQueueFactory& task_queue_factory);
+ Factory(std::unique_ptr<AudioFrameProcessor> frame_processor,
+ TaskQueueFactory& task_queue_factory);
+
+ std::unique_ptr<AsyncAudioProcessing> CreateAsyncAudioProcessing(
+ AudioFrameProcessor::OnAudioFrameCallback on_frame_processed_callback);
+
+ private:
+ // TODO(bugs.webrtc.org/15111):
+ // Remove 'AudioFrameProcessor& frame_processor_' in favour of
+ // std::unique_ptr in the follow-up.
+ // While transitioning this API from using AudioFrameProcessor& to using
+ // std::unique_ptr<AudioFrameProcessor>, we have two member variable both
+ // referencing the same object. Throughout the lifetime of the Factory
+ // only one of the variables is used, depending on which constructor was
+ // called.
+ AudioFrameProcessor& frame_processor_;
+ std::unique_ptr<AudioFrameProcessor> owned_frame_processor_;
+ TaskQueueFactory& task_queue_factory_;
+ };
+
+ AsyncAudioProcessing(const AsyncAudioProcessing&) = delete;
+ AsyncAudioProcessing& operator=(const AsyncAudioProcessing&) = delete;
+
+ ~AsyncAudioProcessing();
+
+ // Creates AsyncAudioProcessing which will pass audio frames to
+ // `frame_processor` on `task_queue_` and reply with processed frames passed
+ // into `on_frame_processed_callback`, which is posted back onto
+ // `task_queue_`. `task_queue_` is created using the provided
+ // `task_queue_factory`.
+ // TODO(bugs.webrtc.org/15111):
+ // Remove this method in favour of the method taking the
+ // unique_ptr<AudioFrameProcessor> in the follow-up.
+ AsyncAudioProcessing(
+ AudioFrameProcessor& frame_processor,
+ TaskQueueFactory& task_queue_factory,
+ AudioFrameProcessor::OnAudioFrameCallback on_frame_processed_callback);
+
+ // Creates AsyncAudioProcessing which will pass audio frames to
+ // `frame_processor` on `task_queue_` and reply with processed frames passed
+ // into `on_frame_processed_callback`, which is posted back onto
+ // `task_queue_`. `task_queue_` is created using the provided
+ // `task_queue_factory`.
+ AsyncAudioProcessing(
+ std::unique_ptr<AudioFrameProcessor> frame_processor,
+ TaskQueueFactory& task_queue_factory,
+ AudioFrameProcessor::OnAudioFrameCallback on_frame_processed_callback);
+
+ // Accepts `frame` for asynchronous processing. Thread-safe.
+ void Process(std::unique_ptr<AudioFrame> frame);
+
+ private:
+ AudioFrameProcessor::OnAudioFrameCallback on_frame_processed_callback_;
+ // TODO(bugs.webrtc.org/15111):
+ // Remove 'AudioFrameProcessor& frame_processor_' in favour of
+ // std::unique_ptr in the follow-up.
+ // While transitioning this API from using AudioFrameProcessor& to using
+ // std::unique_ptr<AudioFrameProcessor>, we have two member variable both
+ // referencing the same object. Throughout the lifetime of the Factory
+ // only one of the variables is used, depending on which constructor was
+ // called.
+ AudioFrameProcessor& frame_processor_;
+ std::unique_ptr<AudioFrameProcessor> owned_frame_processor_;
+ rtc::TaskQueue task_queue_;
+};
+
+} // namespace webrtc
+
+#endif // MODULES_ASYNC_AUDIO_PROCESSING_ASYNC_AUDIO_PROCESSING_H_
diff --git a/third_party/libwebrtc/modules/async_audio_processing/async_audio_processing_gn/moz.build b/third_party/libwebrtc/modules/async_audio_processing/async_audio_processing_gn/moz.build
new file mode 100644
index 0000000000..347559a342
--- /dev/null
+++ b/third_party/libwebrtc/modules/async_audio_processing/async_audio_processing_gn/moz.build
@@ -0,0 +1,232 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+ ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ###
+ ### DO NOT edit it by hand. ###
+
+COMPILE_FLAGS["OS_INCLUDES"] = []
+AllowCompilerWarnings()
+
+DEFINES["ABSL_ALLOCATOR_NOTHROW"] = "1"
+DEFINES["RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY"] = True
+DEFINES["RTC_ENABLE_VP9"] = True
+DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0"
+DEFINES["WEBRTC_LIBRARY_IMPL"] = True
+DEFINES["WEBRTC_MOZILLA_BUILD"] = True
+DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0"
+DEFINES["WEBRTC_STRICT_FIELD_TRIALS"] = "0"
+
+FINAL_LIBRARY = "webrtc"
+
+
+LOCAL_INCLUDES += [
+ "!/ipc/ipdl/_ipdlheaders",
+ "!/third_party/libwebrtc/gen",
+ "/ipc/chromium/src",
+ "/third_party/libwebrtc/",
+ "/third_party/libwebrtc/third_party/abseil-cpp/",
+ "/tools/profiler/public"
+]
+
+UNIFIED_SOURCES += [
+ "/third_party/libwebrtc/modules/async_audio_processing/async_audio_processing.cc"
+]
+
+if not CONFIG["MOZ_DEBUG"]:
+
+ DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0"
+ DEFINES["NDEBUG"] = True
+ DEFINES["NVALGRIND"] = True
+
+if CONFIG["MOZ_DEBUG"] == "1":
+
+ DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1"
+
+if CONFIG["OS_TARGET"] == "Android":
+
+ DEFINES["ANDROID"] = True
+ DEFINES["ANDROID_NDK_VERSION_ROLL"] = "r22_1"
+ DEFINES["HAVE_SYS_UIO_H"] = True
+ DEFINES["WEBRTC_ANDROID"] = True
+ DEFINES["WEBRTC_ANDROID_OPENSLES"] = True
+ DEFINES["WEBRTC_ENABLE_LIBEVENT"] = True
+ DEFINES["WEBRTC_LINUX"] = True
+ DEFINES["WEBRTC_POSIX"] = True
+ DEFINES["_GNU_SOURCE"] = True
+ DEFINES["__STDC_CONSTANT_MACROS"] = True
+ DEFINES["__STDC_FORMAT_MACROS"] = True
+
+ OS_LIBS += [
+ "log"
+ ]
+
+if CONFIG["OS_TARGET"] == "Darwin":
+
+ DEFINES["WEBRTC_MAC"] = True
+ DEFINES["WEBRTC_POSIX"] = True
+ DEFINES["_LIBCPP_HAS_NO_ALIGNED_ALLOCATION"] = True
+ DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES"] = "0"
+ DEFINES["__STDC_CONSTANT_MACROS"] = True
+ DEFINES["__STDC_FORMAT_MACROS"] = True
+
+if CONFIG["OS_TARGET"] == "Linux":
+
+ DEFINES["USE_AURA"] = "1"
+ DEFINES["USE_GLIB"] = "1"
+ DEFINES["USE_NSS_CERTS"] = "1"
+ DEFINES["USE_OZONE"] = "1"
+ DEFINES["USE_UDEV"] = True
+ DEFINES["WEBRTC_ENABLE_LIBEVENT"] = True
+ DEFINES["WEBRTC_LINUX"] = True
+ DEFINES["WEBRTC_POSIX"] = True
+ DEFINES["_FILE_OFFSET_BITS"] = "64"
+ DEFINES["_LARGEFILE64_SOURCE"] = True
+ DEFINES["_LARGEFILE_SOURCE"] = True
+ DEFINES["__STDC_CONSTANT_MACROS"] = True
+ DEFINES["__STDC_FORMAT_MACROS"] = True
+
+if CONFIG["OS_TARGET"] == "OpenBSD":
+
+ DEFINES["USE_GLIB"] = "1"
+ DEFINES["USE_OZONE"] = "1"
+ DEFINES["USE_X11"] = "1"
+ DEFINES["WEBRTC_BSD"] = True
+ DEFINES["WEBRTC_ENABLE_LIBEVENT"] = True
+ DEFINES["WEBRTC_POSIX"] = True
+ DEFINES["_FILE_OFFSET_BITS"] = "64"
+ DEFINES["_LARGEFILE64_SOURCE"] = True
+ DEFINES["_LARGEFILE_SOURCE"] = True
+ DEFINES["__STDC_CONSTANT_MACROS"] = True
+ DEFINES["__STDC_FORMAT_MACROS"] = True
+
+if CONFIG["OS_TARGET"] == "WINNT":
+
+ DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True
+ DEFINES["NOMINMAX"] = True
+ DEFINES["NTDDI_VERSION"] = "0x0A000000"
+ DEFINES["PSAPI_VERSION"] = "2"
+ DEFINES["RTC_ENABLE_WIN_WGC"] = True
+ DEFINES["UNICODE"] = True
+ DEFINES["USE_AURA"] = "1"
+ DEFINES["WEBRTC_WIN"] = True
+ DEFINES["WIN32"] = True
+ DEFINES["WIN32_LEAN_AND_MEAN"] = True
+ DEFINES["WINAPI_FAMILY"] = "WINAPI_FAMILY_DESKTOP_APP"
+ DEFINES["WINVER"] = "0x0A00"
+ DEFINES["_ATL_NO_OPENGL"] = True
+ DEFINES["_CRT_RAND_S"] = True
+ DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True
+ DEFINES["_ENABLE_EXTENDED_ALIGNED_STORAGE"] = True
+ DEFINES["_HAS_EXCEPTIONS"] = "0"
+ DEFINES["_HAS_NODISCARD"] = True
+ DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True
+ DEFINES["_SECURE_ATL"] = True
+ DEFINES["_UNICODE"] = True
+ DEFINES["_WIN32_WINNT"] = "0x0A00"
+ DEFINES["_WINDOWS"] = True
+ DEFINES["__STD_C"] = True
+
+ OS_LIBS += [
+ "crypt32",
+ "iphlpapi",
+ "secur32",
+ "winmm"
+ ]
+
+if CONFIG["TARGET_CPU"] == "aarch64":
+
+ DEFINES["WEBRTC_ARCH_ARM64"] = True
+ DEFINES["WEBRTC_HAS_NEON"] = True
+
+if CONFIG["TARGET_CPU"] == "arm":
+
+ CXXFLAGS += [
+ "-mfpu=neon"
+ ]
+
+ DEFINES["WEBRTC_ARCH_ARM"] = True
+ DEFINES["WEBRTC_ARCH_ARM_V7"] = True
+ DEFINES["WEBRTC_HAS_NEON"] = True
+
+if CONFIG["TARGET_CPU"] == "mips32":
+
+ DEFINES["MIPS32_LE"] = True
+ DEFINES["MIPS_FPU_LE"] = True
+ DEFINES["_GNU_SOURCE"] = True
+
+if CONFIG["TARGET_CPU"] == "mips64":
+
+ DEFINES["_GNU_SOURCE"] = True
+
+if CONFIG["TARGET_CPU"] == "x86":
+
+ DEFINES["WEBRTC_ENABLE_AVX2"] = True
+
+if CONFIG["TARGET_CPU"] == "x86_64":
+
+ DEFINES["WEBRTC_ENABLE_AVX2"] = True
+
+if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Android":
+
+ DEFINES["_DEBUG"] = True
+
+if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Darwin":
+
+ DEFINES["_DEBUG"] = True
+
+if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "Linux":
+
+ DEFINES["_DEBUG"] = True
+
+if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "OpenBSD":
+
+ DEFINES["_DEBUG"] = True
+
+if CONFIG["MOZ_DEBUG"] == "1" and CONFIG["OS_TARGET"] == "WINNT":
+
+ DEFINES["_HAS_ITERATOR_DEBUGGING"] = "0"
+
+if CONFIG["MOZ_X11"] == "1" and CONFIG["OS_TARGET"] == "Linux":
+
+ DEFINES["USE_X11"] = "1"
+
+if CONFIG["OS_TARGET"] == "Android" and CONFIG["TARGET_CPU"] == "arm":
+
+ OS_LIBS += [
+ "android_support",
+ "unwind"
+ ]
+
+if CONFIG["OS_TARGET"] == "Android" and CONFIG["TARGET_CPU"] == "x86":
+
+ CXXFLAGS += [
+ "-msse2"
+ ]
+
+ OS_LIBS += [
+ "android_support"
+ ]
+
+if CONFIG["OS_TARGET"] == "Linux" and CONFIG["TARGET_CPU"] == "aarch64":
+
+ DEFINES["_GNU_SOURCE"] = True
+
+if CONFIG["OS_TARGET"] == "Linux" and CONFIG["TARGET_CPU"] == "arm":
+
+ DEFINES["_GNU_SOURCE"] = True
+
+if CONFIG["OS_TARGET"] == "Linux" and CONFIG["TARGET_CPU"] == "x86":
+
+ CXXFLAGS += [
+ "-msse2"
+ ]
+
+ DEFINES["_GNU_SOURCE"] = True
+
+if CONFIG["OS_TARGET"] == "Linux" and CONFIG["TARGET_CPU"] == "x86_64":
+
+ DEFINES["_GNU_SOURCE"] = True
+
+Library("async_audio_processing_gn")