Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: webrtc/modules/audio_processing/logging/apm_data_dumper.h

Issue 1877713002: Replaced the data logging functionality in the AEC with a generic logging functionality (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase with latest master Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 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 WEBRTC_MODULES_AUDIO_PROCESSING_LOGGING_APM_DATA_DUMPER_H_
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_LOGGING_APM_DATA_DUMPER_H_
13
14 #include <stdio.h>
15
16 #include <memory>
17 #include <string>
18 #include <unordered_map>
19
20 #include "webrtc/base/array_view.h"
21 #include "webrtc/base/constructormagic.h"
22 #include "webrtc/common_audio/wav_file.h"
23
24 // Check to verify that the define is properly set.
25 #if !defined(WEBRTC_AEC_DEBUG_DUMP) || \
26 (WEBRTC_AEC_DEBUG_DUMP != 0 && WEBRTC_AEC_DEBUG_DUMP != 1)
27 #error "Set WEBRTC_AEC_DEBUG_DUMP to either 0 or 1"
28 #endif
29
30 namespace webrtc {
31
32 #if WEBRTC_AEC_DEBUG_DUMP == 1
33 // Functor used to use as a custom deleter in the map of file pointers to raw
34 // files.
35 struct RawFileCloseFunctor {
36 void operator()(FILE* f) const { fclose(f); }
37 };
38 #endif
39
40 // Class that handles dumping of variables into files.
41 class ApmDataDumper {
42 public:
43 // Constructor that takes an instance index that may
44 // be used to distinguish data dumped from different
45 // instances of the code.
46 #if WEBRTC_AEC_DEBUG_DUMP == 1
47 explicit ApmDataDumper(int instance_index)
48 : instance_index_(instance_index) {}
49 #else
50 explicit ApmDataDumper(int instance_index) {}
51 #endif
52
53 // Reinitializes the data dumping such that new versions
54 // of all files being dumped to are created.
55 void InitiateNewSetOfRecordings() {
56 #if WEBRTC_AEC_DEBUG_DUMP == 1
57 ++recording_set_index_;
58 #endif
59 }
60
61 // Methods for performing dumping of data of various types into
62 // various formats.
63 void DumpRaw(const char* name, int v_length, const float* v) {
64 #if WEBRTC_AEC_DEBUG_DUMP == 1
65 FILE* file = GetRawFile(name);
66 fwrite(v, sizeof(v[0]), v_length, file);
67 #endif
68 }
69
70 void DumpRaw(const char* name, rtc::ArrayView<const float> v) {
71 #if WEBRTC_AEC_DEBUG_DUMP == 1
72 DumpRaw(name, v.size(), v.data());
73 #endif
74 }
75
76 void DumpWav(const char* name,
77 int v_length,
78 const float* v,
79 int sample_rate_hz,
80 int num_channels) {
81 #if WEBRTC_AEC_DEBUG_DUMP == 1
82 WavWriter* file = GetWavFile(name, sample_rate_hz, num_channels);
83 file->WriteSamples(v, v_length);
84 #endif
85 }
86
87 private:
88 #if WEBRTC_AEC_DEBUG_DUMP == 1
89 const int instance_index_;
90 int recording_set_index_ = 0;
91 std::unordered_map<std::string, std::unique_ptr<FILE, RawFileCloseFunctor>>
92 raw_files_;
93 std::unordered_map<std::string, std::unique_ptr<WavWriter>> wav_files_;
94
95 FILE* GetRawFile(const char* name);
96 WavWriter* GetWavFile(const char* name, int sample_rate_hz, int num_channels);
97 #endif
98 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(ApmDataDumper);
99 };
100
101 } // namespace webrtc
102
103 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_LOGGING_APM_DATA_DUMPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698