andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 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 | // Commandline tool to unpack audioproc debug files. |
| 12 | // |
| 13 | // The debug files are dumped as protobuf blobs. For analysis, it's necessary |
| 14 | // to unpack the file into its component parts: audio and other data. |
| 15 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 16 | #include <inttypes.h> |
| 17 | #include <stdint.h> |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 18 | #include <stdio.h> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 19 | #include <stdlib.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame^] | 20 | |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 21 | #include <memory> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 22 | #include <string> |
Fredrik Hernqvist | 3be9da3 | 2019-05-21 12:23:31 +0200 | [diff] [blame] | 23 | #include <vector> |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 24 | |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 25 | #include "absl/flags/flag.h" |
| 26 | #include "absl/flags/parse.h" |
Fredrik Hernqvist | 3be9da3 | 2019-05-21 12:23:31 +0200 | [diff] [blame] | 27 | #include "api/function_view.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 28 | #include "common_audio/wav_file.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "modules/audio_processing/test/protobuf_utils.h" |
| 30 | #include "modules/audio_processing/test/test_utils.h" |
| 31 | #include "rtc_base/flags.h" |
| 32 | #include "rtc_base/format_macros.h" |
| 33 | #include "rtc_base/ignore_wundef.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 34 | #include "rtc_base/strings/string_builder.h" |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 35 | |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 36 | RTC_PUSH_IGNORING_WUNDEF() |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 37 | #include "modules/audio_processing/debug.pb.h" |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 38 | RTC_POP_IGNORING_WUNDEF() |
| 39 | |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 40 | ABSL_FLAG(std::string, |
| 41 | input_file, |
| 42 | "input", |
| 43 | "The name of the input stream file."); |
| 44 | ABSL_FLAG(std::string, |
| 45 | output_file, |
| 46 | "ref_out", |
| 47 | "The name of the reference output stream file."); |
| 48 | ABSL_FLAG(std::string, |
| 49 | reverse_file, |
| 50 | "reverse", |
| 51 | "The name of the reverse input stream file."); |
| 52 | ABSL_FLAG(std::string, |
| 53 | delay_file, |
| 54 | "delay.int32", |
| 55 | "The name of the delay file."); |
| 56 | ABSL_FLAG(std::string, |
| 57 | drift_file, |
| 58 | "drift.int32", |
| 59 | "The name of the drift file."); |
| 60 | ABSL_FLAG(std::string, |
| 61 | level_file, |
| 62 | "level.int32", |
| 63 | "The name of the level file."); |
| 64 | ABSL_FLAG(std::string, |
| 65 | keypress_file, |
| 66 | "keypress.bool", |
| 67 | "The name of the keypress file."); |
| 68 | ABSL_FLAG(std::string, |
| 69 | callorder_file, |
| 70 | "callorder", |
| 71 | "The name of the render/capture call order file."); |
| 72 | ABSL_FLAG(std::string, |
| 73 | settings_file, |
| 74 | "settings.txt", |
| 75 | "The name of the settings file."); |
| 76 | ABSL_FLAG(bool, |
| 77 | full, |
| 78 | false, |
| 79 | "Unpack the full set of files (normally not needed)."); |
| 80 | ABSL_FLAG(bool, raw, false, "Write raw data instead of a WAV file."); |
| 81 | ABSL_FLAG(bool, |
| 82 | text, |
| 83 | false, |
| 84 | "Write non-audio files as text files instead of binary files."); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 85 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 86 | #define PRINT_CONFIG(field_name) \ |
| 87 | if (msg.has_##field_name()) { \ |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 88 | fprintf(settings_file, " " #field_name ": %d\n", msg.field_name()); \ |
| 89 | } |
| 90 | |
Alex Loiko | 5feb30e | 2018-04-16 13:52:32 +0200 | [diff] [blame] | 91 | #define PRINT_CONFIG_FLOAT(field_name) \ |
| 92 | if (msg.has_##field_name()) { \ |
| 93 | fprintf(settings_file, " " #field_name ": %f\n", msg.field_name()); \ |
| 94 | } |
| 95 | |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 96 | namespace webrtc { |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 97 | |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 98 | using audioproc::Event; |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame^] | 99 | using audioproc::Init; |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 100 | using audioproc::ReverseStream; |
| 101 | using audioproc::Stream; |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 102 | |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 103 | namespace { |
| 104 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 105 | void WriteData(const void* data, |
| 106 | size_t size, |
| 107 | FILE* file, |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 108 | const std::string& filename) { |
| 109 | if (fwrite(data, size, 1, file) != 1) { |
| 110 | printf("Error when writing to %s\n", filename.c_str()); |
| 111 | exit(1); |
| 112 | } |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 115 | void WriteCallOrderData(const bool render_call, |
| 116 | FILE* file, |
| 117 | const std::string& filename) { |
| 118 | const char call_type = render_call ? 'r' : 'c'; |
| 119 | WriteData(&call_type, sizeof(call_type), file, filename.c_str()); |
| 120 | } |
| 121 | |
Per Åhgren | c1bfe1a | 2018-09-21 16:23:50 +0200 | [diff] [blame] | 122 | bool WritingCallOrderFile() { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 123 | return absl::GetFlag(FLAGS_full); |
Per Åhgren | c1bfe1a | 2018-09-21 16:23:50 +0200 | [diff] [blame] | 124 | } |
| 125 | |
Fredrik Hernqvist | 3be9da3 | 2019-05-21 12:23:31 +0200 | [diff] [blame] | 126 | bool WritingRuntimeSettingFiles() { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 127 | return absl::GetFlag(FLAGS_full); |
Fredrik Hernqvist | 3be9da3 | 2019-05-21 12:23:31 +0200 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | // Exports RuntimeSetting AEC dump events to Audacity-readable files. |
| 131 | // This class is not RAII compliant. |
| 132 | class RuntimeSettingWriter { |
| 133 | public: |
| 134 | RuntimeSettingWriter( |
| 135 | std::string name, |
| 136 | rtc::FunctionView<bool(const Event)> is_exporter_for, |
| 137 | rtc::FunctionView<std::string(const Event)> get_timeline_label) |
| 138 | : setting_name_(std::move(name)), |
| 139 | is_exporter_for_(is_exporter_for), |
| 140 | get_timeline_label_(get_timeline_label) {} |
| 141 | ~RuntimeSettingWriter() { Flush(); } |
| 142 | |
| 143 | bool IsExporterFor(const Event& event) const { |
| 144 | return is_exporter_for_(event); |
| 145 | } |
| 146 | |
| 147 | // Writes to file the payload of |event| using |frame_count| to calculate |
| 148 | // timestamp. |
| 149 | void WriteEvent(const Event& event, int frame_count) { |
| 150 | RTC_DCHECK(is_exporter_for_(event)); |
| 151 | if (file_ == nullptr) { |
| 152 | rtc::StringBuilder file_name; |
| 153 | file_name << setting_name_ << frame_offset_ << ".txt"; |
| 154 | file_ = OpenFile(file_name.str(), "wb"); |
| 155 | } |
| 156 | |
| 157 | // Time in the current WAV file, in seconds. |
| 158 | double time = (frame_count - frame_offset_) / 100.0; |
| 159 | std::string label = get_timeline_label_(event); |
| 160 | // In Audacity, all annotations are encoded as intervals. |
| 161 | fprintf(file_, "%.6f\t%.6f\t%s \n", time, time, label.c_str()); |
| 162 | } |
| 163 | |
| 164 | // Handles an AEC dump initialization event, occurring at frame |
| 165 | // |frame_offset|. |
| 166 | void HandleInitEvent(int frame_offset) { |
| 167 | Flush(); |
| 168 | frame_offset_ = frame_offset; |
| 169 | } |
| 170 | |
| 171 | private: |
| 172 | void Flush() { |
| 173 | if (file_ != nullptr) { |
| 174 | fclose(file_); |
| 175 | file_ = nullptr; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | FILE* file_ = nullptr; |
| 180 | int frame_offset_ = 0; |
| 181 | const std::string setting_name_; |
| 182 | const rtc::FunctionView<bool(Event)> is_exporter_for_; |
| 183 | const rtc::FunctionView<std::string(Event)> get_timeline_label_; |
| 184 | }; |
| 185 | |
| 186 | // Returns RuntimeSetting exporters for runtime setting types defined in |
| 187 | // debug.proto. |
| 188 | std::vector<RuntimeSettingWriter> RuntimeSettingWriters() { |
| 189 | return { |
| 190 | RuntimeSettingWriter( |
| 191 | "CapturePreGain", |
| 192 | [](const Event& event) -> bool { |
| 193 | return event.runtime_setting().has_capture_pre_gain(); |
| 194 | }, |
| 195 | [](const Event& event) -> std::string { |
| 196 | return std::to_string(event.runtime_setting().capture_pre_gain()); |
| 197 | }), |
| 198 | RuntimeSettingWriter( |
| 199 | "CustomRenderProcessingRuntimeSetting", |
| 200 | [](const Event& event) -> bool { |
| 201 | return event.runtime_setting() |
| 202 | .has_custom_render_processing_setting(); |
| 203 | }, |
| 204 | [](const Event& event) -> std::string { |
| 205 | return std::to_string( |
| 206 | event.runtime_setting().custom_render_processing_setting()); |
| 207 | }), |
| 208 | RuntimeSettingWriter( |
| 209 | "CaptureFixedPostGain", |
| 210 | [](const Event& event) -> bool { |
| 211 | return event.runtime_setting().has_capture_fixed_post_gain(); |
| 212 | }, |
| 213 | [](const Event& event) -> std::string { |
| 214 | return std::to_string( |
| 215 | event.runtime_setting().capture_fixed_post_gain()); |
| 216 | }), |
| 217 | RuntimeSettingWriter( |
| 218 | "PlayoutVolumeChange", |
| 219 | [](const Event& event) -> bool { |
| 220 | return event.runtime_setting().has_playout_volume_change(); |
| 221 | }, |
| 222 | [](const Event& event) -> std::string { |
| 223 | return std::to_string( |
| 224 | event.runtime_setting().playout_volume_change()); |
| 225 | })}; |
| 226 | } |
| 227 | |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 228 | } // namespace |
| 229 | |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 230 | int do_main(int argc, char* argv[]) { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 231 | std::vector<char*> args = absl::ParseCommandLine(argc, argv); |
| 232 | std::string program_name = args[0]; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 233 | std::string usage = |
| 234 | "Commandline tool to unpack audioproc debug files.\n" |
| 235 | "Example usage:\n" + |
| 236 | program_name + " debug_dump.pb\n"; |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 237 | |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 238 | if (args.size() < 2) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 239 | printf("%s", usage.c_str()); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 240 | return 1; |
| 241 | } |
| 242 | |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 243 | FILE* debug_file = OpenFile(args[1], "rb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 244 | |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 245 | Event event_msg; |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 246 | int frame_count = 0; |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 247 | size_t reverse_samples_per_channel = 0; |
| 248 | size_t input_samples_per_channel = 0; |
| 249 | size_t output_samples_per_channel = 0; |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 250 | size_t num_reverse_channels = 0; |
| 251 | size_t num_input_channels = 0; |
| 252 | size_t num_output_channels = 0; |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 253 | std::unique_ptr<WavWriter> reverse_wav_file; |
| 254 | std::unique_ptr<WavWriter> input_wav_file; |
| 255 | std::unique_ptr<WavWriter> output_wav_file; |
| 256 | std::unique_ptr<RawFile> reverse_raw_file; |
| 257 | std::unique_ptr<RawFile> input_raw_file; |
| 258 | std::unique_ptr<RawFile> output_raw_file; |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 259 | |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 260 | rtc::StringBuilder callorder_raw_name; |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 261 | callorder_raw_name << absl::GetFlag(FLAGS_callorder_file) << ".char"; |
Per Åhgren | c1bfe1a | 2018-09-21 16:23:50 +0200 | [diff] [blame] | 262 | FILE* callorder_char_file = WritingCallOrderFile() |
| 263 | ? OpenFile(callorder_raw_name.str(), "wb") |
| 264 | : nullptr; |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 265 | FILE* settings_file = OpenFile(absl::GetFlag(FLAGS_settings_file), "wb"); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 266 | |
Fredrik Hernqvist | 3be9da3 | 2019-05-21 12:23:31 +0200 | [diff] [blame] | 267 | std::vector<RuntimeSettingWriter> runtime_setting_writers = |
| 268 | RuntimeSettingWriters(); |
| 269 | |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 270 | while (ReadMessageFromFile(debug_file, &event_msg)) { |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 271 | if (event_msg.type() == Event::REVERSE_STREAM) { |
| 272 | if (!event_msg.has_reverse_stream()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 273 | printf("Corrupt input file: ReverseStream missing.\n"); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 274 | return 1; |
| 275 | } |
| 276 | |
| 277 | const ReverseStream msg = event_msg.reverse_stream(); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 278 | if (msg.has_data()) { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 279 | if (absl::GetFlag(FLAGS_raw) && !reverse_raw_file) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 280 | reverse_raw_file.reset( |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 281 | new RawFile(absl::GetFlag(FLAGS_reverse_file) + ".pcm")); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 282 | } |
aluebs@webrtc.org | bac0726 | 2014-09-03 13:39:01 +0000 | [diff] [blame] | 283 | // TODO(aluebs): Replace "num_reverse_channels * |
| 284 | // reverse_samples_per_channel" with "msg.data().size() / |
| 285 | // sizeof(int16_t)" and so on when this fix in audio_processing has made |
| 286 | // it into stable: https://webrtc-codereview.appspot.com/15299004/ |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 287 | WriteIntData(reinterpret_cast<const int16_t*>(msg.data().data()), |
aluebs@webrtc.org | bac0726 | 2014-09-03 13:39:01 +0000 | [diff] [blame] | 288 | num_reverse_channels * reverse_samples_per_channel, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 289 | reverse_wav_file.get(), reverse_raw_file.get()); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 290 | } else if (msg.channel_size() > 0) { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 291 | if (absl::GetFlag(FLAGS_raw) && !reverse_raw_file) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 292 | reverse_raw_file.reset( |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 293 | new RawFile(absl::GetFlag(FLAGS_reverse_file) + ".float")); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 294 | } |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame^] | 295 | std::unique_ptr<const float*[]> data( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 296 | new const float*[num_reverse_channels]); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 297 | for (size_t i = 0; i < num_reverse_channels; ++i) { |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 298 | data[i] = reinterpret_cast<const float*>(msg.channel(i).data()); |
| 299 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 300 | WriteFloatData(data.get(), reverse_samples_per_channel, |
| 301 | num_reverse_channels, reverse_wav_file.get(), |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 302 | reverse_raw_file.get()); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 303 | } |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 304 | if (absl::GetFlag(FLAGS_full)) { |
Per Åhgren | c1bfe1a | 2018-09-21 16:23:50 +0200 | [diff] [blame] | 305 | if (WritingCallOrderFile()) { |
| 306 | WriteCallOrderData(true /* render_call */, callorder_char_file, |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 307 | absl::GetFlag(FLAGS_callorder_file)); |
Per Åhgren | c1bfe1a | 2018-09-21 16:23:50 +0200 | [diff] [blame] | 308 | } |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 309 | } |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 310 | } else if (event_msg.type() == Event::STREAM) { |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 311 | frame_count++; |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 312 | if (!event_msg.has_stream()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 313 | printf("Corrupt input file: Stream missing.\n"); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 314 | return 1; |
| 315 | } |
| 316 | |
| 317 | const Stream msg = event_msg.stream(); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 318 | if (msg.has_input_data()) { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 319 | if (absl::GetFlag(FLAGS_raw) && !input_raw_file) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 320 | input_raw_file.reset( |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 321 | new RawFile(absl::GetFlag(FLAGS_input_file) + ".pcm")); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 322 | } |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 323 | WriteIntData(reinterpret_cast<const int16_t*>(msg.input_data().data()), |
aluebs@webrtc.org | bac0726 | 2014-09-03 13:39:01 +0000 | [diff] [blame] | 324 | num_input_channels * input_samples_per_channel, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 325 | input_wav_file.get(), input_raw_file.get()); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 326 | } else if (msg.input_channel_size() > 0) { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 327 | if (absl::GetFlag(FLAGS_raw) && !input_raw_file) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 328 | input_raw_file.reset( |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 329 | new RawFile(absl::GetFlag(FLAGS_input_file) + ".float")); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 330 | } |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame^] | 331 | std::unique_ptr<const float*[]> data( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 332 | new const float*[num_input_channels]); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 333 | for (size_t i = 0; i < num_input_channels; ++i) { |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 334 | data[i] = reinterpret_cast<const float*>(msg.input_channel(i).data()); |
| 335 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 336 | WriteFloatData(data.get(), input_samples_per_channel, |
| 337 | num_input_channels, input_wav_file.get(), |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 338 | input_raw_file.get()); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 339 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 340 | |
| 341 | if (msg.has_output_data()) { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 342 | if (absl::GetFlag(FLAGS_raw) && !output_raw_file) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 343 | output_raw_file.reset( |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 344 | new RawFile(absl::GetFlag(FLAGS_output_file) + ".pcm")); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 345 | } |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 346 | WriteIntData(reinterpret_cast<const int16_t*>(msg.output_data().data()), |
aluebs@webrtc.org | bac0726 | 2014-09-03 13:39:01 +0000 | [diff] [blame] | 347 | num_output_channels * output_samples_per_channel, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 348 | output_wav_file.get(), output_raw_file.get()); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 349 | } else if (msg.output_channel_size() > 0) { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 350 | if (absl::GetFlag(FLAGS_raw) && !output_raw_file) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 351 | output_raw_file.reset( |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 352 | new RawFile(absl::GetFlag(FLAGS_output_file) + ".float")); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 353 | } |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame^] | 354 | std::unique_ptr<const float*[]> data( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 355 | new const float*[num_output_channels]); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 356 | for (size_t i = 0; i < num_output_channels; ++i) { |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 357 | data[i] = |
| 358 | reinterpret_cast<const float*>(msg.output_channel(i).data()); |
| 359 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 360 | WriteFloatData(data.get(), output_samples_per_channel, |
| 361 | num_output_channels, output_wav_file.get(), |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 362 | output_raw_file.get()); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 365 | if (absl::GetFlag(FLAGS_full)) { |
Per Åhgren | c1bfe1a | 2018-09-21 16:23:50 +0200 | [diff] [blame] | 366 | if (WritingCallOrderFile()) { |
| 367 | WriteCallOrderData(false /* render_call */, callorder_char_file, |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 368 | absl::GetFlag(FLAGS_callorder_file)); |
Per Åhgren | c1bfe1a | 2018-09-21 16:23:50 +0200 | [diff] [blame] | 369 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 370 | if (msg.has_delay()) { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 371 | static FILE* delay_file = |
| 372 | OpenFile(absl::GetFlag(FLAGS_delay_file), "wb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 373 | int32_t delay = msg.delay(); |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 374 | if (absl::GetFlag(FLAGS_text)) { |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 375 | fprintf(delay_file, "%d\n", delay); |
| 376 | } else { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 377 | WriteData(&delay, sizeof(delay), delay_file, |
| 378 | absl::GetFlag(FLAGS_delay_file)); |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 379 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | if (msg.has_drift()) { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 383 | static FILE* drift_file = |
| 384 | OpenFile(absl::GetFlag(FLAGS_drift_file), "wb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 385 | int32_t drift = msg.drift(); |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 386 | if (absl::GetFlag(FLAGS_text)) { |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 387 | fprintf(drift_file, "%d\n", drift); |
| 388 | } else { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 389 | WriteData(&drift, sizeof(drift), drift_file, |
| 390 | absl::GetFlag(FLAGS_drift_file)); |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 391 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | if (msg.has_level()) { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 395 | static FILE* level_file = |
| 396 | OpenFile(absl::GetFlag(FLAGS_level_file), "wb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 397 | int32_t level = msg.level(); |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 398 | if (absl::GetFlag(FLAGS_text)) { |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 399 | fprintf(level_file, "%d\n", level); |
| 400 | } else { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 401 | WriteData(&level, sizeof(level), level_file, |
| 402 | absl::GetFlag(FLAGS_level_file)); |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 403 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 404 | } |
andrew@webrtc.org | ce8e077 | 2014-02-12 15:28:30 +0000 | [diff] [blame] | 405 | |
| 406 | if (msg.has_keypress()) { |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 407 | static FILE* keypress_file = |
| 408 | OpenFile(absl::GetFlag(FLAGS_keypress_file), "wb"); |
andrew@webrtc.org | ce8e077 | 2014-02-12 15:28:30 +0000 | [diff] [blame] | 409 | bool keypress = msg.keypress(); |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 410 | if (absl::GetFlag(FLAGS_text)) { |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 411 | fprintf(keypress_file, "%d\n", keypress); |
| 412 | } else { |
| 413 | WriteData(&keypress, sizeof(keypress), keypress_file, |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 414 | absl::GetFlag(FLAGS_keypress_file)); |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 415 | } |
andrew@webrtc.org | ce8e077 | 2014-02-12 15:28:30 +0000 | [diff] [blame] | 416 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 417 | } |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 418 | } else if (event_msg.type() == Event::CONFIG) { |
| 419 | if (!event_msg.has_config()) { |
| 420 | printf("Corrupt input file: Config missing.\n"); |
| 421 | return 1; |
| 422 | } |
| 423 | const audioproc::Config msg = event_msg.config(); |
| 424 | |
| 425 | fprintf(settings_file, "APM re-config at frame: %d\n", frame_count); |
| 426 | |
| 427 | PRINT_CONFIG(aec_enabled); |
| 428 | PRINT_CONFIG(aec_delay_agnostic_enabled); |
| 429 | PRINT_CONFIG(aec_drift_compensation_enabled); |
| 430 | PRINT_CONFIG(aec_extended_filter_enabled); |
| 431 | PRINT_CONFIG(aec_suppression_level); |
| 432 | PRINT_CONFIG(aecm_enabled); |
| 433 | PRINT_CONFIG(aecm_comfort_noise_enabled); |
| 434 | PRINT_CONFIG(aecm_routing_mode); |
| 435 | PRINT_CONFIG(agc_enabled); |
| 436 | PRINT_CONFIG(agc_mode); |
| 437 | PRINT_CONFIG(agc_limiter_enabled); |
| 438 | PRINT_CONFIG(noise_robust_agc_enabled); |
| 439 | PRINT_CONFIG(hpf_enabled); |
| 440 | PRINT_CONFIG(ns_enabled); |
| 441 | PRINT_CONFIG(ns_level); |
| 442 | PRINT_CONFIG(transient_suppression_enabled); |
Alex Loiko | 5feb30e | 2018-04-16 13:52:32 +0200 | [diff] [blame] | 443 | PRINT_CONFIG(pre_amplifier_enabled); |
| 444 | PRINT_CONFIG_FLOAT(pre_amplifier_fixed_gain_factor); |
| 445 | |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 446 | if (msg.has_experiments_description()) { |
| 447 | fprintf(settings_file, " experiments_description: %s\n", |
| 448 | msg.experiments_description().c_str()); |
| 449 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 450 | } else if (event_msg.type() == Event::INIT) { |
| 451 | if (!event_msg.has_init()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 452 | printf("Corrupt input file: Init missing.\n"); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 453 | return 1; |
| 454 | } |
| 455 | |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 456 | const Init msg = event_msg.init(); |
| 457 | // These should print out zeros if they're missing. |
| 458 | fprintf(settings_file, "Init at frame: %d\n", frame_count); |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 459 | int input_sample_rate = msg.sample_rate(); |
| 460 | fprintf(settings_file, " Input sample rate: %d\n", input_sample_rate); |
| 461 | int output_sample_rate = msg.output_sample_rate(); |
| 462 | fprintf(settings_file, " Output sample rate: %d\n", output_sample_rate); |
| 463 | int reverse_sample_rate = msg.reverse_sample_rate(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 464 | fprintf(settings_file, " Reverse sample rate: %d\n", |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 465 | reverse_sample_rate); |
| 466 | num_input_channels = msg.num_input_channels(); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 467 | fprintf(settings_file, " Input channels: %" PRIuS "\n", |
| 468 | num_input_channels); |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 469 | num_output_channels = msg.num_output_channels(); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 470 | fprintf(settings_file, " Output channels: %" PRIuS "\n", |
| 471 | num_output_channels); |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 472 | num_reverse_channels = msg.num_reverse_channels(); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 473 | fprintf(settings_file, " Reverse channels: %" PRIuS "\n", |
| 474 | num_reverse_channels); |
Minyue Li | 656d609 | 2018-08-10 15:38:52 +0200 | [diff] [blame] | 475 | if (msg.has_timestamp_ms()) { |
| 476 | const int64_t timestamp = msg.timestamp_ms(); |
| 477 | fprintf(settings_file, " Timestamp in millisecond: %" PRId64 "\n", |
| 478 | timestamp); |
| 479 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 480 | |
| 481 | fprintf(settings_file, "\n"); |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 482 | |
| 483 | if (reverse_sample_rate == 0) { |
| 484 | reverse_sample_rate = input_sample_rate; |
| 485 | } |
| 486 | if (output_sample_rate == 0) { |
| 487 | output_sample_rate = input_sample_rate; |
| 488 | } |
| 489 | |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 490 | reverse_samples_per_channel = |
| 491 | static_cast<size_t>(reverse_sample_rate / 100); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 492 | input_samples_per_channel = static_cast<size_t>(input_sample_rate / 100); |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 493 | output_samples_per_channel = |
| 494 | static_cast<size_t>(output_sample_rate / 100); |
aluebs@webrtc.org | bac0726 | 2014-09-03 13:39:01 +0000 | [diff] [blame] | 495 | |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 496 | if (!absl::GetFlag(FLAGS_raw)) { |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 497 | // The WAV files need to be reset every time, because they cant change |
| 498 | // their sample rate or number of channels. |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 499 | rtc::StringBuilder reverse_name; |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 500 | reverse_name << absl::GetFlag(FLAGS_reverse_file) << frame_count |
| 501 | << ".wav"; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 502 | reverse_wav_file.reset(new WavWriter( |
| 503 | reverse_name.str(), reverse_sample_rate, num_reverse_channels)); |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 504 | rtc::StringBuilder input_name; |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 505 | input_name << absl::GetFlag(FLAGS_input_file) << frame_count << ".wav"; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 506 | input_wav_file.reset(new WavWriter(input_name.str(), input_sample_rate, |
andrew@webrtc.org | a3ed713 | 2014-10-31 21:51:03 +0000 | [diff] [blame] | 507 | num_input_channels)); |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 508 | rtc::StringBuilder output_name; |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 509 | output_name << absl::GetFlag(FLAGS_output_file) << frame_count |
| 510 | << ".wav"; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 511 | output_wav_file.reset(new WavWriter( |
| 512 | output_name.str(), output_sample_rate, num_output_channels)); |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 513 | |
Per Åhgren | c1bfe1a | 2018-09-21 16:23:50 +0200 | [diff] [blame] | 514 | if (WritingCallOrderFile()) { |
| 515 | rtc::StringBuilder callorder_name; |
Mirko Bonadei | 9d96209 | 2019-07-04 10:19:10 +0200 | [diff] [blame] | 516 | callorder_name << absl::GetFlag(FLAGS_callorder_file) << frame_count |
| 517 | << ".char"; |
Per Åhgren | c1bfe1a | 2018-09-21 16:23:50 +0200 | [diff] [blame] | 518 | callorder_char_file = OpenFile(callorder_name.str(), "wb"); |
| 519 | } |
Fredrik Hernqvist | 3be9da3 | 2019-05-21 12:23:31 +0200 | [diff] [blame] | 520 | |
| 521 | if (WritingRuntimeSettingFiles()) { |
| 522 | for (RuntimeSettingWriter& writer : runtime_setting_writers) { |
| 523 | writer.HandleInitEvent(frame_count); |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | } else if (event_msg.type() == Event::RUNTIME_SETTING) { |
| 528 | if (WritingRuntimeSettingFiles()) { |
| 529 | for (RuntimeSettingWriter& writer : runtime_setting_writers) { |
| 530 | if (writer.IsExporterFor(event_msg)) { |
| 531 | writer.WriteEvent(event_msg, frame_count); |
| 532 | } |
| 533 | } |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 534 | } |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
| 538 | return 0; |
| 539 | } |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 540 | |
| 541 | } // namespace webrtc |
| 542 | |
| 543 | int main(int argc, char* argv[]) { |
| 544 | return webrtc::do_main(argc, argv); |
| 545 | } |