1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef MODULES_AUDIO_PROCESSING_AEC_DUMP_AEC_DUMP_IMPL_H_
12 #define MODULES_AUDIO_PROCESSING_AEC_DUMP_AEC_DUMP_IMPL_H_
13
14 #include <memory>
15 #include <string>
16 #include <vector>
17
18 #include "modules/audio_processing/aec_dump/capture_stream_info.h"
19 #include "modules/audio_processing/include/aec_dump.h"
20 #include "rtc_base/ignore_wundef.h"
21 #include "rtc_base/race_checker.h"
22 #include "rtc_base/system/file_wrapper.h"
23 #include "rtc_base/task_queue.h"
24 #include "rtc_base/thread_annotations.h"
25
26 // Files generated at build-time by the protobuf compiler.
27 RTC_PUSH_IGNORING_WUNDEF()
28 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD
29 #include "external/webrtc/webrtc/modules/audio_processing/debug.pb.h"
30 #else
31 #include "modules/audio_processing/debug.pb.h"
32 #endif
RTC_POP_IGNORING_WUNDEF()33 RTC_POP_IGNORING_WUNDEF()
34
35 namespace webrtc {
36
37 // Task-queue based implementation of AecDump. It is thread safe by
38 // relying on locks in TaskQueue.
39 class AecDumpImpl : public AecDump {
40 public:
41 // `max_log_size_bytes` - maximum number of bytes to write to the debug file,
42 // `max_log_size_bytes == -1` means the log size will be unlimited.
43 AecDumpImpl(FileWrapper debug_file,
44 int64_t max_log_size_bytes,
45 rtc::TaskQueue* worker_queue);
46 AecDumpImpl(const AecDumpImpl&) = delete;
47 AecDumpImpl& operator=(const AecDumpImpl&) = delete;
48 ~AecDumpImpl() override;
49
50 void WriteInitMessage(const ProcessingConfig& api_format,
51 int64_t time_now_ms) override;
52 void AddCaptureStreamInput(const AudioFrameView<const float>& src) override;
53 void AddCaptureStreamOutput(const AudioFrameView<const float>& src) override;
54 void AddCaptureStreamInput(const int16_t* const data,
55 int num_channels,
56 int samples_per_channel) override;
57 void AddCaptureStreamOutput(const int16_t* const data,
58 int num_channels,
59 int samples_per_channel) override;
60 void AddAudioProcessingState(const AudioProcessingState& state) override;
61 void WriteCaptureStreamMessage() override;
62
63 void WriteRenderStreamMessage(const int16_t* const data,
64 int num_channels,
65 int samples_per_channel) override;
66 void WriteRenderStreamMessage(
67 const AudioFrameView<const float>& src) override;
68
69 void WriteConfig(const InternalAPMConfig& config) override;
70
71 void WriteRuntimeSetting(
72 const AudioProcessing::RuntimeSetting& runtime_setting) override;
73
74 private:
75 void PostWriteToFileTask(std::unique_ptr<audioproc::Event> event);
76
77 FileWrapper debug_file_;
78 int64_t num_bytes_left_for_log_ = 0;
79 rtc::RaceChecker race_checker_;
80 rtc::TaskQueue* worker_queue_;
81 CaptureStreamInfo capture_stream_info_;
82 };
83 } // namespace webrtc
84
85 #endif // MODULES_AUDIO_PROCESSING_AEC_DUMP_AEC_DUMP_IMPL_H_
86