Line data Source code
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_APM_DEBUG_DUMP) || \
19 : (WEBRTC_APM_DEBUG_DUMP != 0 && WEBRTC_APM_DEBUG_DUMP != 1)
20 : #error "Set WEBRTC_APM_DEBUG_DUMP to either 0 or 1"
21 : #endif
22 :
23 : namespace webrtc {
24 :
25 : namespace {
26 :
27 : #if WEBRTC_APM_DEBUG_DUMP == 1
28 : std::string FormFileName(const char* name,
29 : int instance_index,
30 : int reinit_index,
31 : const std::string& suffix) {
32 : char path[1024];
33 : AECDebugFilenameBase(path, sizeof(path));
34 :
35 : char* end = path + strlen(path) - 1;
36 :
37 : #ifdef WEBRTC_WIN
38 : char sep = '\\';
39 : #else
40 : char sep = '/';
41 : #endif
42 :
43 : std::stringstream ss;
44 : ss << path;
45 : if (*end != sep) {
46 : ss << sep;
47 : }
48 : ss << name << "_" << instance_index << "-" << reinit_index << suffix;
49 : return ss.str();
50 : }
51 : #endif
52 :
53 : } // namespace
54 :
55 : #if WEBRTC_APM_DEBUG_DUMP == 1
56 : ApmDataDumper::ApmDataDumper(int instance_index)
57 : : instance_index_(instance_index)
58 : , debug_written_(0) {}
59 : #else
60 0 : ApmDataDumper::ApmDataDumper(int instance_index) {}
61 : #endif
62 :
63 0 : ApmDataDumper::~ApmDataDumper() {}
64 :
65 : #if WEBRTC_APM_DEBUG_DUMP == 1
66 : FILE* ApmDataDumper::GetRawFile(const char* name) {
67 : std::string filename =
68 : FormFileName(name, instance_index_, recording_set_index_, ".dat");
69 : auto& f = raw_files_[filename];
70 : if (!f) {
71 : f.reset(fopen(filename.c_str(), "wb"));
72 : }
73 : return f.get();
74 : }
75 :
76 : WavWriter* ApmDataDumper::GetWavFile(const char* name,
77 : int sample_rate_hz,
78 : int num_channels) {
79 : std::string filename =
80 : FormFileName(name, instance_index_, recording_set_index_, ".wav");
81 : auto& f = wav_files_[filename];
82 : if (!f) {
83 : f.reset(new WavWriter(filename.c_str(), sample_rate_hz, num_channels));
84 : }
85 : return f.get();
86 : }
87 :
88 : #endif
89 :
90 : } // namespace webrtc
|