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

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

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: Updated the buildfile according to reviewer comments Created 4 years, 8 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 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
12
13 #include "webrtc/base/stringutils.h"
14
15 // Check to verify that the define is properly set.
16 #if !defined(WEBRTC_AEC_DEBUG_DUMP) || \
17 (WEBRTC_AEC_DEBUG_DUMP != 0 && WEBRTC_AEC_DEBUG_DUMP != 1)
18 #error "Set WEBRTC_AEC_DEBUG_DUMP to either 0 or 1"
19 #endif
20
21 namespace webrtc {
22
23 namespace {
24
25 #if WEBRTC_AEC_DEBUG_DUMP == 1
26 std::string FormFileName(const std::string& name,
27 int instance_index,
28 int reinit_index,
29 const std::string& suffix) {
30 char instance_index_string[10];
hlundin-webrtc 2016/04/25 11:29:59 I think the C++ way of doing this (in the absence
peah-webrtc 2016/04/25 11:46:40 Great! Thanks!! With that the code became much nic
31 rtc::sprintfn(instance_index_string, sizeof(instance_index_string), "%d",
32 instance_index);
33 char reinit_index_string[10];
34 rtc::sprintfn(reinit_index_string, sizeof(reinit_index_string), "%d",
35 reinit_index);
36 return name + "_" + instance_index_string + "-" +
37 std::to_string(reinit_index) + suffix;
38 }
39 #endif
40
41 } // namespace
42
43 ApmDataDumper::~ApmDataDumper() {
44 #if WEBRTC_AEC_DEBUG_DUMP == 1
45 for (auto& raw_files_element : raw_files_) {
46 fclose(raw_files_element.second);
47 }
48
49 // Deleting the wav files implicitly causes the files to be closed.
50 for (auto& wav_files_element : wav_files_) {
51 delete wav_files_element.second;
52 }
53 #endif
54 }
55
56 #if WEBRTC_AEC_DEBUG_DUMP == 1
57 FILE* ApmDataDumper::GetRawFile(const std::string& name) {
58 std::string filename =
59 FormFileName(name, instance_index_, recording_set_index_, ".dat");
60 auto search = raw_files_.find(filename);
61 if (search != raw_files_.end()) {
62 return search->second;
63 }
64 FILE* file = fopen(filename.c_str(), "wb");
65 raw_files_[filename] = file;
66 return file;
67 }
68
69 WavWriter* ApmDataDumper::GetWavFile(const std::string& name,
70 int sample_rate_hz,
71 int num_channels) {
72 std::string filename =
73 FormFileName(name, instance_index_, recording_set_index_, ".wav");
74 auto search = wav_files_.find(filename);
75 if (search != wav_files_.end()) {
76 return search->second;
77 }
78 WavWriter* file =
79 new WavWriter(filename.c_str(), sample_rate_hz, num_channels);
80 wav_files_[filename] = file;
81 return file;
82 }
83 #endif
84
85 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698