OLD | NEW |
---|---|
(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 <sstream> | |
14 | |
15 #include "webrtc/base/stringutils.h" | |
16 | |
17 // Check to verify that the define is properly set. | |
18 #if !defined(WEBRTC_AEC_DEBUG_DUMP) || \ | |
19 (WEBRTC_AEC_DEBUG_DUMP != 0 && WEBRTC_AEC_DEBUG_DUMP != 1) | |
20 #error "Set WEBRTC_AEC_DEBUG_DUMP to either 0 or 1" | |
21 #endif | |
22 | |
23 namespace webrtc { | |
24 | |
25 namespace { | |
26 | |
27 #if WEBRTC_AEC_DEBUG_DUMP == 1 | |
28 std::string FormFileName(const std::string& name, | |
29 int instance_index, | |
30 int reinit_index, | |
31 const std::string& suffix) { | |
32 std::stringstream ss; | |
33 ss << name << "_" << instance_index << "-" << reinit_index << suffix; | |
34 return ss.str(); | |
35 } | |
36 #endif | |
37 | |
38 } // namespace | |
39 | |
40 ApmDataDumper::~ApmDataDumper() { | |
41 #if WEBRTC_AEC_DEBUG_DUMP == 1 | |
42 for (auto& raw_files_element : raw_files_) { | |
43 fclose(raw_files_element.second); | |
44 } | |
45 | |
46 // Deleting the wav files implicitly causes the files to be closed. | |
47 for (auto& wav_files_element : wav_files_) { | |
48 delete wav_files_element.second; | |
49 } | |
50 #endif | |
kwiberg-webrtc
2016/05/03 00:53:01
If you use unique_ptrs, the manual destructor won'
peah-webrtc
2016/05/03 06:29:22
Thanks!
The change allowed removing the constructo
| |
51 } | |
52 | |
53 #if WEBRTC_AEC_DEBUG_DUMP == 1 | |
54 FILE* ApmDataDumper::GetRawFile(const std::string& name) { | |
55 std::string filename = | |
56 FormFileName(name, instance_index_, recording_set_index_, ".dat"); | |
57 auto search = raw_files_.find(filename); | |
58 if (search != raw_files_.end()) { | |
59 return search->second; | |
60 } | |
61 FILE* file = fopen(filename.c_str(), "wb"); | |
62 raw_files_[filename] = file; | |
63 return file; | |
64 } | |
65 | |
66 WavWriter* ApmDataDumper::GetWavFile(const std::string& name, | |
67 int sample_rate_hz, | |
68 int num_channels) { | |
69 std::string filename = | |
70 FormFileName(name, instance_index_, recording_set_index_, ".wav"); | |
71 auto search = wav_files_.find(filename); | |
72 if (search != wav_files_.end()) { | |
73 return search->second; | |
74 } | |
75 WavWriter* file = | |
76 new WavWriter(filename.c_str(), sample_rate_hz, num_channels); | |
77 wav_files_[filename] = file; | |
78 return file; | |
79 } | |
80 #endif | |
81 | |
82 } // namespace webrtc | |
OLD | NEW |