blob: 9452f3bcf9e055444992cb3daf11bb3a5ebebc69 [file] [log] [blame]
Olga Sharonova09ceed22020-09-30 18:27:39 +02001
2/*
3 * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
4 *
5 * Use of this source code is governed by a BSD-style license
6 * that can be found in the LICENSE file in the root of the source
7 * tree. An additional intellectual property rights grant can be found
8 * in the file PATENTS. All contributing project authors may
9 * be found in the AUTHORS file in the root of the source tree.
10 */
11#include "modules/async_audio_processing/async_audio_processing.h"
12
13#include <utility>
14
15#include "api/audio/audio_frame.h"
16#include "api/task_queue/task_queue_factory.h"
17#include "rtc_base/checks.h"
18
19namespace webrtc {
20
21AsyncAudioProcessing::Factory::~Factory() = default;
22AsyncAudioProcessing::Factory::Factory(AudioFrameProcessor& frame_processor,
23 TaskQueueFactory& task_queue_factory)
24 : frame_processor_(frame_processor),
25 task_queue_factory_(task_queue_factory) {}
26
27std::unique_ptr<AsyncAudioProcessing>
28AsyncAudioProcessing::Factory::CreateAsyncAudioProcessing(
29 AudioFrameProcessor::OnAudioFrameCallback on_frame_processed_callback) {
30 return std::make_unique<AsyncAudioProcessing>(
31 frame_processor_, task_queue_factory_,
32 std::move(on_frame_processed_callback));
33}
34
35AsyncAudioProcessing::~AsyncAudioProcessing() {
36 frame_processor_.SetSink(nullptr);
37}
38
39AsyncAudioProcessing::AsyncAudioProcessing(
40 AudioFrameProcessor& frame_processor,
41 TaskQueueFactory& task_queue_factory,
42 AudioFrameProcessor::OnAudioFrameCallback on_frame_processed_callback)
43 : on_frame_processed_callback_(std::move(on_frame_processed_callback)),
44 frame_processor_(frame_processor),
45 task_queue_(task_queue_factory.CreateTaskQueue(
46 "AsyncAudioProcessing",
47 TaskQueueFactory::Priority::NORMAL)) {
48 frame_processor_.SetSink([this](std::unique_ptr<AudioFrame> frame) {
49 task_queue_.PostTask([this, frame = std::move(frame)]() mutable {
50 on_frame_processed_callback_(std::move(frame));
51 });
52 });
53}
54
55void AsyncAudioProcessing::Process(std::unique_ptr<AudioFrame> frame) {
56 task_queue_.PostTask([this, frame = std::move(frame)]() mutable {
57 frame_processor_.Process(std::move(frame));
58 });
59}
60
61} // namespace webrtc