| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_LOGGING_APM_DATA_DUMPER_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_LOGGING_APM_DATA_DUMPER_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_LOGGING_APM_DATA_DUMPER_H_ | 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_LOGGING_APM_DATA_DUMPER_H_ |
| 13 | 13 |
| 14 #include <stdio.h> | 14 #include <stdio.h> |
| 15 | 15 |
| 16 #include <memory> | 16 #include <memory> |
| 17 #include <string> | 17 #include <string> |
| 18 #include <unordered_map> | 18 #include <unordered_map> |
| 19 | 19 |
| 20 #include "webrtc/base/array_view.h" | 20 #include "webrtc/base/array_view.h" |
| 21 #include "webrtc/base/constructormagic.h" | 21 #include "webrtc/base/constructormagic.h" |
| 22 #include "webrtc/common_audio/wav_file.h" | 22 #include "webrtc/common_audio/wav_file.h" |
| 23 | 23 |
| 24 // Check to verify that the define is properly set. | 24 // Check to verify that the define is properly set. |
| 25 #if !defined(WEBRTC_AEC_DEBUG_DUMP) || \ | 25 #if !defined(WEBRTC_APM_DEBUG_DUMP) || \ |
| 26 (WEBRTC_AEC_DEBUG_DUMP != 0 && WEBRTC_AEC_DEBUG_DUMP != 1) | 26 (WEBRTC_APM_DEBUG_DUMP != 0 && WEBRTC_APM_DEBUG_DUMP != 1) |
| 27 #error "Set WEBRTC_AEC_DEBUG_DUMP to either 0 or 1" | 27 #error "Set WEBRTC_APM_DEBUG_DUMP to either 0 or 1" |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 namespace webrtc { | 30 namespace webrtc { |
| 31 | 31 |
| 32 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 32 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 33 // Functor used to use as a custom deleter in the map of file pointers to raw | 33 // Functor used to use as a custom deleter in the map of file pointers to raw |
| 34 // files. | 34 // files. |
| 35 struct RawFileCloseFunctor { | 35 struct RawFileCloseFunctor { |
| 36 void operator()(FILE* f) const { fclose(f); } | 36 void operator()(FILE* f) const { fclose(f); } |
| 37 }; | 37 }; |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 // Class that handles dumping of variables into files. | 40 // Class that handles dumping of variables into files. |
| 41 class ApmDataDumper { | 41 class ApmDataDumper { |
| 42 public: | 42 public: |
| 43 // Constructor that takes an instance index that may | 43 // Constructor that takes an instance index that may |
| 44 // be used to distinguish data dumped from different | 44 // be used to distinguish data dumped from different |
| 45 // instances of the code. | 45 // instances of the code. |
| 46 explicit ApmDataDumper(int instance_index); | 46 explicit ApmDataDumper(int instance_index); |
| 47 | 47 |
| 48 ~ApmDataDumper(); | 48 ~ApmDataDumper(); |
| 49 | 49 |
| 50 // Reinitializes the data dumping such that new versions | 50 // Reinitializes the data dumping such that new versions |
| 51 // of all files being dumped to are created. | 51 // of all files being dumped to are created. |
| 52 void InitiateNewSetOfRecordings() { | 52 void InitiateNewSetOfRecordings() { |
| 53 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 53 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 54 ++recording_set_index_; | 54 ++recording_set_index_; |
| 55 #endif | 55 #endif |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Methods for performing dumping of data of various types into | 58 // Methods for performing dumping of data of various types into |
| 59 // various formats. | 59 // various formats. |
| 60 void DumpRaw(const char* name, int v_length, const float* v) { | 60 void DumpRaw(const char* name, int v_length, const float* v) { |
| 61 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 61 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 62 FILE* file = GetRawFile(name); | 62 FILE* file = GetRawFile(name); |
| 63 fwrite(v, sizeof(v[0]), v_length, file); | 63 fwrite(v, sizeof(v[0]), v_length, file); |
| 64 #endif | 64 #endif |
| 65 } | 65 } |
| 66 | 66 |
| 67 void DumpRaw(const char* name, rtc::ArrayView<const float> v) { | 67 void DumpRaw(const char* name, rtc::ArrayView<const float> v) { |
| 68 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 68 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 69 DumpRaw(name, v.size(), v.data()); | 69 DumpRaw(name, v.size(), v.data()); |
| 70 #endif | 70 #endif |
| 71 } | 71 } |
| 72 | 72 |
| 73 void DumpRaw(const char* name, int v_length, const bool* v) { | 73 void DumpRaw(const char* name, int v_length, const bool* v) { |
| 74 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 74 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 75 FILE* file = GetRawFile(name); | 75 FILE* file = GetRawFile(name); |
| 76 for (int k = 0; k < v_length; ++k) { | 76 for (int k = 0; k < v_length; ++k) { |
| 77 int16_t value = static_cast<int16_t>(v[k]); | 77 int16_t value = static_cast<int16_t>(v[k]); |
| 78 fwrite(&value, sizeof(value), 1, file); | 78 fwrite(&value, sizeof(value), 1, file); |
| 79 } | 79 } |
| 80 #endif | 80 #endif |
| 81 } | 81 } |
| 82 | 82 |
| 83 void DumpRaw(const char* name, rtc::ArrayView<const bool> v) { | 83 void DumpRaw(const char* name, rtc::ArrayView<const bool> v) { |
| 84 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 84 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 85 DumpRaw(name, v.size(), v.data()); | 85 DumpRaw(name, v.size(), v.data()); |
| 86 #endif | 86 #endif |
| 87 } | 87 } |
| 88 | 88 |
| 89 void DumpRaw(const char* name, int v_length, const int16_t* v) { | 89 void DumpRaw(const char* name, int v_length, const int16_t* v) { |
| 90 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 90 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 91 FILE* file = GetRawFile(name); | 91 FILE* file = GetRawFile(name); |
| 92 fwrite(v, sizeof(v[0]), v_length, file); | 92 fwrite(v, sizeof(v[0]), v_length, file); |
| 93 #endif | 93 #endif |
| 94 } | 94 } |
| 95 | 95 |
| 96 void DumpRaw(const char* name, rtc::ArrayView<const int16_t> v) { | 96 void DumpRaw(const char* name, rtc::ArrayView<const int16_t> v) { |
| 97 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 97 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 98 DumpRaw(name, v.size(), v.data()); | 98 DumpRaw(name, v.size(), v.data()); |
| 99 #endif | 99 #endif |
| 100 } | 100 } |
| 101 | 101 |
| 102 void DumpRaw(const char* name, int v_length, const int32_t* v) { | 102 void DumpRaw(const char* name, int v_length, const int32_t* v) { |
| 103 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 103 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 104 FILE* file = GetRawFile(name); | 104 FILE* file = GetRawFile(name); |
| 105 fwrite(v, sizeof(v[0]), v_length, file); | 105 fwrite(v, sizeof(v[0]), v_length, file); |
| 106 #endif | 106 #endif |
| 107 } | 107 } |
| 108 | 108 |
| 109 void DumpRaw(const char* name, rtc::ArrayView<const int32_t> v) { | 109 void DumpRaw(const char* name, rtc::ArrayView<const int32_t> v) { |
| 110 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 110 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 111 DumpRaw(name, v.size(), v.data()); | 111 DumpRaw(name, v.size(), v.data()); |
| 112 #endif | 112 #endif |
| 113 } | 113 } |
| 114 | 114 |
| 115 void DumpWav(const char* name, | 115 void DumpWav(const char* name, |
| 116 int v_length, | 116 int v_length, |
| 117 const float* v, | 117 const float* v, |
| 118 int sample_rate_hz, | 118 int sample_rate_hz, |
| 119 int num_channels) { | 119 int num_channels) { |
| 120 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 120 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 121 WavWriter* file = GetWavFile(name, sample_rate_hz, num_channels); | 121 WavWriter* file = GetWavFile(name, sample_rate_hz, num_channels); |
| 122 file->WriteSamples(v, v_length); | 122 file->WriteSamples(v, v_length); |
| 123 #endif | 123 #endif |
| 124 } | 124 } |
| 125 | 125 |
| 126 void DumpWav(const char* name, | 126 void DumpWav(const char* name, |
| 127 rtc::ArrayView<const float> v, | 127 rtc::ArrayView<const float> v, |
| 128 int sample_rate_hz, | 128 int sample_rate_hz, |
| 129 int num_channels) { | 129 int num_channels) { |
| 130 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 130 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 131 DumpWav(name, v.size(), v.data(), sample_rate_hz, num_channels); | 131 DumpWav(name, v.size(), v.data(), sample_rate_hz, num_channels); |
| 132 #endif | 132 #endif |
| 133 } | 133 } |
| 134 | 134 |
| 135 private: | 135 private: |
| 136 #if WEBRTC_AEC_DEBUG_DUMP == 1 | 136 #if WEBRTC_APM_DEBUG_DUMP == 1 |
| 137 const int instance_index_; | 137 const int instance_index_; |
| 138 int recording_set_index_ = 0; | 138 int recording_set_index_ = 0; |
| 139 std::unordered_map<std::string, std::unique_ptr<FILE, RawFileCloseFunctor>> | 139 std::unordered_map<std::string, std::unique_ptr<FILE, RawFileCloseFunctor>> |
| 140 raw_files_; | 140 raw_files_; |
| 141 std::unordered_map<std::string, std::unique_ptr<WavWriter>> wav_files_; | 141 std::unordered_map<std::string, std::unique_ptr<WavWriter>> wav_files_; |
| 142 | 142 |
| 143 FILE* GetRawFile(const char* name); | 143 FILE* GetRawFile(const char* name); |
| 144 WavWriter* GetWavFile(const char* name, int sample_rate_hz, int num_channels); | 144 WavWriter* GetWavFile(const char* name, int sample_rate_hz, int num_channels); |
| 145 #endif | 145 #endif |
| 146 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(ApmDataDumper); | 146 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(ApmDataDumper); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 } // namespace webrtc | 149 } // namespace webrtc |
| 150 | 150 |
| 151 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_LOGGING_APM_DATA_DUMPER_H_ | 151 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_LOGGING_APM_DATA_DUMPER_H_ |
| OLD | NEW |