blob: 88593fb44f8a7e45796581837da53d5624917c9b [file] [log] [blame]
andrew@webrtc.orgcb181212011-10-26 00:27:17 +00001/*
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 Gerey3e707812018-11-28 16:47:49 +010016#include <inttypes.h>
17#include <stdint.h>
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000018#include <stdio.h>
Yves Gerey3e707812018-11-28 16:47:49 +010019#include <stdlib.h>
kwiberg62eaacf2016-02-17 06:39:05 -080020#include <memory>
Yves Gerey3e707812018-11-28 16:47:49 +010021#include <string>
Fredrik Hernqvist3be9da32019-05-21 12:23:31 +020022#include <vector>
kwiberg62eaacf2016-02-17 06:39:05 -080023
Fredrik Hernqvist3be9da32019-05-21 12:23:31 +020024#include "api/function_view.h"
Yves Gerey3e707812018-11-28 16:47:49 +010025#include "common_audio/wav_file.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "modules/audio_processing/test/protobuf_utils.h"
27#include "modules/audio_processing/test/test_utils.h"
28#include "rtc_base/flags.h"
29#include "rtc_base/format_macros.h"
30#include "rtc_base/ignore_wundef.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020031#include "rtc_base/strings/string_builder.h"
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000032
kwiberg77eab702016-09-28 17:42:01 -070033RTC_PUSH_IGNORING_WUNDEF()
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020034#include "modules/audio_processing/debug.pb.h"
Yves Gerey3e707812018-11-28 16:47:49 +010035
kwiberg77eab702016-09-28 17:42:01 -070036RTC_POP_IGNORING_WUNDEF()
37
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000038// TODO(andrew): unpack more of the data.
Mirko Bonadei2dfa9982018-10-18 11:35:32 +020039WEBRTC_DEFINE_string(input_file, "input", "The name of the input stream file.");
40WEBRTC_DEFINE_string(output_file,
41 "ref_out",
42 "The name of the reference output stream file.");
43WEBRTC_DEFINE_string(reverse_file,
44 "reverse",
45 "The name of the reverse input stream file.");
46WEBRTC_DEFINE_string(delay_file, "delay.int32", "The name of the delay file.");
47WEBRTC_DEFINE_string(drift_file, "drift.int32", "The name of the drift file.");
48WEBRTC_DEFINE_string(level_file, "level.int32", "The name of the level file.");
49WEBRTC_DEFINE_string(keypress_file,
50 "keypress.bool",
51 "The name of the keypress file.");
52WEBRTC_DEFINE_string(callorder_file,
53 "callorder",
54 "The name of the render/capture call order file.");
55WEBRTC_DEFINE_string(settings_file,
56 "settings.txt",
57 "The name of the settings file.");
58WEBRTC_DEFINE_bool(full,
59 false,
60 "Unpack the full set of files (normally not needed).");
61WEBRTC_DEFINE_bool(raw, false, "Write raw data instead of a WAV file.");
62WEBRTC_DEFINE_bool(
63 text,
64 false,
65 "Write non-audio files as text files instead of binary files.");
66WEBRTC_DEFINE_bool(help, false, "Print this message.");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000067
Yves Gerey665174f2018-06-19 15:03:05 +020068#define PRINT_CONFIG(field_name) \
69 if (msg.has_##field_name()) { \
Minyue13b96ba2015-10-03 00:39:14 +020070 fprintf(settings_file, " " #field_name ": %d\n", msg.field_name()); \
71 }
72
Alex Loiko5feb30e2018-04-16 13:52:32 +020073#define PRINT_CONFIG_FLOAT(field_name) \
74 if (msg.has_##field_name()) { \
75 fprintf(settings_file, " " #field_name ": %f\n", msg.field_name()); \
76 }
77
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000078namespace webrtc {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000079
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000080using audioproc::Event;
81using audioproc::ReverseStream;
82using audioproc::Stream;
83using audioproc::Init;
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000084
Sam Zackrissonf61475d2018-05-11 11:34:49 +020085namespace {
86
Yves Gerey665174f2018-06-19 15:03:05 +020087void WriteData(const void* data,
88 size_t size,
89 FILE* file,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000090 const std::string& filename) {
91 if (fwrite(data, size, 1, file) != 1) {
92 printf("Error when writing to %s\n", filename.c_str());
93 exit(1);
94 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000095}
96
Sam Zackrissonf61475d2018-05-11 11:34:49 +020097void WriteCallOrderData(const bool render_call,
98 FILE* file,
99 const std::string& filename) {
100 const char call_type = render_call ? 'r' : 'c';
101 WriteData(&call_type, sizeof(call_type), file, filename.c_str());
102}
103
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200104bool WritingCallOrderFile() {
105 return FLAG_full;
106}
107
Fredrik Hernqvist3be9da32019-05-21 12:23:31 +0200108bool WritingRuntimeSettingFiles() {
109 return FLAG_full;
110}
111
112// Exports RuntimeSetting AEC dump events to Audacity-readable files.
113// This class is not RAII compliant.
114class RuntimeSettingWriter {
115 public:
116 RuntimeSettingWriter(
117 std::string name,
118 rtc::FunctionView<bool(const Event)> is_exporter_for,
119 rtc::FunctionView<std::string(const Event)> get_timeline_label)
120 : setting_name_(std::move(name)),
121 is_exporter_for_(is_exporter_for),
122 get_timeline_label_(get_timeline_label) {}
123 ~RuntimeSettingWriter() { Flush(); }
124
125 bool IsExporterFor(const Event& event) const {
126 return is_exporter_for_(event);
127 }
128
129 // Writes to file the payload of |event| using |frame_count| to calculate
130 // timestamp.
131 void WriteEvent(const Event& event, int frame_count) {
132 RTC_DCHECK(is_exporter_for_(event));
133 if (file_ == nullptr) {
134 rtc::StringBuilder file_name;
135 file_name << setting_name_ << frame_offset_ << ".txt";
136 file_ = OpenFile(file_name.str(), "wb");
137 }
138
139 // Time in the current WAV file, in seconds.
140 double time = (frame_count - frame_offset_) / 100.0;
141 std::string label = get_timeline_label_(event);
142 // In Audacity, all annotations are encoded as intervals.
143 fprintf(file_, "%.6f\t%.6f\t%s \n", time, time, label.c_str());
144 }
145
146 // Handles an AEC dump initialization event, occurring at frame
147 // |frame_offset|.
148 void HandleInitEvent(int frame_offset) {
149 Flush();
150 frame_offset_ = frame_offset;
151 }
152
153 private:
154 void Flush() {
155 if (file_ != nullptr) {
156 fclose(file_);
157 file_ = nullptr;
158 }
159 }
160
161 FILE* file_ = nullptr;
162 int frame_offset_ = 0;
163 const std::string setting_name_;
164 const rtc::FunctionView<bool(Event)> is_exporter_for_;
165 const rtc::FunctionView<std::string(Event)> get_timeline_label_;
166};
167
168// Returns RuntimeSetting exporters for runtime setting types defined in
169// debug.proto.
170std::vector<RuntimeSettingWriter> RuntimeSettingWriters() {
171 return {
172 RuntimeSettingWriter(
173 "CapturePreGain",
174 [](const Event& event) -> bool {
175 return event.runtime_setting().has_capture_pre_gain();
176 },
177 [](const Event& event) -> std::string {
178 return std::to_string(event.runtime_setting().capture_pre_gain());
179 }),
180 RuntimeSettingWriter(
181 "CustomRenderProcessingRuntimeSetting",
182 [](const Event& event) -> bool {
183 return event.runtime_setting()
184 .has_custom_render_processing_setting();
185 },
186 [](const Event& event) -> std::string {
187 return std::to_string(
188 event.runtime_setting().custom_render_processing_setting());
189 }),
190 RuntimeSettingWriter(
191 "CaptureFixedPostGain",
192 [](const Event& event) -> bool {
193 return event.runtime_setting().has_capture_fixed_post_gain();
194 },
195 [](const Event& event) -> std::string {
196 return std::to_string(
197 event.runtime_setting().capture_fixed_post_gain());
198 }),
199 RuntimeSettingWriter(
200 "PlayoutVolumeChange",
201 [](const Event& event) -> bool {
202 return event.runtime_setting().has_playout_volume_change();
203 },
204 [](const Event& event) -> std::string {
205 return std::to_string(
206 event.runtime_setting().playout_volume_change());
207 })};
208}
209
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200210} // namespace
211
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000212int do_main(int argc, char* argv[]) {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000213 std::string program_name = argv[0];
Yves Gerey665174f2018-06-19 15:03:05 +0200214 std::string usage =
215 "Commandline tool to unpack audioproc debug files.\n"
216 "Example usage:\n" +
217 program_name + " debug_dump.pb\n";
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000218
Yves Gerey665174f2018-06-19 15:03:05 +0200219 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || FLAG_help ||
220 argc < 2) {
oprypin6e09d872017-08-31 03:21:39 -0700221 printf("%s", usage.c_str());
222 if (FLAG_help) {
223 rtc::FlagList::Print(nullptr, false);
224 return 0;
225 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000226 return 1;
227 }
228
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000229 FILE* debug_file = OpenFile(argv[1], "rb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000230
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000231 Event event_msg;
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000232 int frame_count = 0;
pkasting25702cb2016-01-08 13:50:27 -0800233 size_t reverse_samples_per_channel = 0;
234 size_t input_samples_per_channel = 0;
235 size_t output_samples_per_channel = 0;
Peter Kasting69558702016-01-12 16:26:35 -0800236 size_t num_reverse_channels = 0;
237 size_t num_input_channels = 0;
238 size_t num_output_channels = 0;
kwiberg62eaacf2016-02-17 06:39:05 -0800239 std::unique_ptr<WavWriter> reverse_wav_file;
240 std::unique_ptr<WavWriter> input_wav_file;
241 std::unique_ptr<WavWriter> output_wav_file;
242 std::unique_ptr<RawFile> reverse_raw_file;
243 std::unique_ptr<RawFile> input_raw_file;
244 std::unique_ptr<RawFile> output_raw_file;
Minyue13b96ba2015-10-03 00:39:14 +0200245
Jonas Olsson366a50c2018-09-06 13:41:30 +0200246 rtc::StringBuilder callorder_raw_name;
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200247 callorder_raw_name << FLAG_callorder_file << ".char";
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200248 FILE* callorder_char_file = WritingCallOrderFile()
249 ? OpenFile(callorder_raw_name.str(), "wb")
250 : nullptr;
oprypin6e09d872017-08-31 03:21:39 -0700251 FILE* settings_file = OpenFile(FLAG_settings_file, "wb");
Minyue13b96ba2015-10-03 00:39:14 +0200252
Fredrik Hernqvist3be9da32019-05-21 12:23:31 +0200253 std::vector<RuntimeSettingWriter> runtime_setting_writers =
254 RuntimeSettingWriters();
255
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000256 while (ReadMessageFromFile(debug_file, &event_msg)) {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000257 if (event_msg.type() == Event::REVERSE_STREAM) {
258 if (!event_msg.has_reverse_stream()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000259 printf("Corrupt input file: ReverseStream missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000260 return 1;
261 }
262
263 const ReverseStream msg = event_msg.reverse_stream();
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000264 if (msg.has_data()) {
oprypin6e09d872017-08-31 03:21:39 -0700265 if (FLAG_raw && !reverse_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200266 reverse_raw_file.reset(
267 new RawFile(std::string(FLAG_reverse_file) + ".pcm"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000268 }
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000269 // TODO(aluebs): Replace "num_reverse_channels *
270 // reverse_samples_per_channel" with "msg.data().size() /
271 // sizeof(int16_t)" and so on when this fix in audio_processing has made
272 // it into stable: https://webrtc-codereview.appspot.com/15299004/
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000273 WriteIntData(reinterpret_cast<const int16_t*>(msg.data().data()),
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000274 num_reverse_channels * reverse_samples_per_channel,
Yves Gerey665174f2018-06-19 15:03:05 +0200275 reverse_wav_file.get(), reverse_raw_file.get());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000276 } else if (msg.channel_size() > 0) {
oprypin6e09d872017-08-31 03:21:39 -0700277 if (FLAG_raw && !reverse_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200278 reverse_raw_file.reset(
279 new RawFile(std::string(FLAG_reverse_file) + ".float"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000280 }
kwiberg62eaacf2016-02-17 06:39:05 -0800281 std::unique_ptr<const float* []> data(
Yves Gerey665174f2018-06-19 15:03:05 +0200282 new const float*[num_reverse_channels]);
Peter Kasting69558702016-01-12 16:26:35 -0800283 for (size_t i = 0; i < num_reverse_channels; ++i) {
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000284 data[i] = reinterpret_cast<const float*>(msg.channel(i).data());
285 }
Yves Gerey665174f2018-06-19 15:03:05 +0200286 WriteFloatData(data.get(), reverse_samples_per_channel,
287 num_reverse_channels, reverse_wav_file.get(),
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000288 reverse_raw_file.get());
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000289 }
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200290 if (FLAG_full) {
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200291 if (WritingCallOrderFile()) {
292 WriteCallOrderData(true /* render_call */, callorder_char_file,
293 FLAG_callorder_file);
294 }
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200295 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000296 } else if (event_msg.type() == Event::STREAM) {
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000297 frame_count++;
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000298 if (!event_msg.has_stream()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000299 printf("Corrupt input file: Stream missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000300 return 1;
301 }
302
303 const Stream msg = event_msg.stream();
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000304 if (msg.has_input_data()) {
oprypin6e09d872017-08-31 03:21:39 -0700305 if (FLAG_raw && !input_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200306 input_raw_file.reset(
307 new RawFile(std::string(FLAG_input_file) + ".pcm"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000308 }
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000309 WriteIntData(reinterpret_cast<const int16_t*>(msg.input_data().data()),
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000310 num_input_channels * input_samples_per_channel,
Yves Gerey665174f2018-06-19 15:03:05 +0200311 input_wav_file.get(), input_raw_file.get());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000312 } else if (msg.input_channel_size() > 0) {
oprypin6e09d872017-08-31 03:21:39 -0700313 if (FLAG_raw && !input_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200314 input_raw_file.reset(
315 new RawFile(std::string(FLAG_input_file) + ".float"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000316 }
kwiberg62eaacf2016-02-17 06:39:05 -0800317 std::unique_ptr<const float* []> data(
Yves Gerey665174f2018-06-19 15:03:05 +0200318 new const float*[num_input_channels]);
Peter Kasting69558702016-01-12 16:26:35 -0800319 for (size_t i = 0; i < num_input_channels; ++i) {
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000320 data[i] = reinterpret_cast<const float*>(msg.input_channel(i).data());
321 }
Yves Gerey665174f2018-06-19 15:03:05 +0200322 WriteFloatData(data.get(), input_samples_per_channel,
323 num_input_channels, input_wav_file.get(),
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000324 input_raw_file.get());
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000325 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000326
327 if (msg.has_output_data()) {
oprypin6e09d872017-08-31 03:21:39 -0700328 if (FLAG_raw && !output_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200329 output_raw_file.reset(
330 new RawFile(std::string(FLAG_output_file) + ".pcm"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000331 }
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000332 WriteIntData(reinterpret_cast<const int16_t*>(msg.output_data().data()),
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000333 num_output_channels * output_samples_per_channel,
Yves Gerey665174f2018-06-19 15:03:05 +0200334 output_wav_file.get(), output_raw_file.get());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000335 } else if (msg.output_channel_size() > 0) {
oprypin6e09d872017-08-31 03:21:39 -0700336 if (FLAG_raw && !output_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200337 output_raw_file.reset(
338 new RawFile(std::string(FLAG_output_file) + ".float"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000339 }
kwiberg62eaacf2016-02-17 06:39:05 -0800340 std::unique_ptr<const float* []> data(
Yves Gerey665174f2018-06-19 15:03:05 +0200341 new const float*[num_output_channels]);
Peter Kasting69558702016-01-12 16:26:35 -0800342 for (size_t i = 0; i < num_output_channels; ++i) {
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000343 data[i] =
344 reinterpret_cast<const float*>(msg.output_channel(i).data());
345 }
Yves Gerey665174f2018-06-19 15:03:05 +0200346 WriteFloatData(data.get(), output_samples_per_channel,
347 num_output_channels, output_wav_file.get(),
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000348 output_raw_file.get());
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000349 }
350
oprypin6e09d872017-08-31 03:21:39 -0700351 if (FLAG_full) {
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200352 if (WritingCallOrderFile()) {
353 WriteCallOrderData(false /* render_call */, callorder_char_file,
354 FLAG_callorder_file);
355 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000356 if (msg.has_delay()) {
oprypin6e09d872017-08-31 03:21:39 -0700357 static FILE* delay_file = OpenFile(FLAG_delay_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000358 int32_t delay = msg.delay();
oprypin6e09d872017-08-31 03:21:39 -0700359 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200360 fprintf(delay_file, "%d\n", delay);
361 } else {
oprypin6e09d872017-08-31 03:21:39 -0700362 WriteData(&delay, sizeof(delay), delay_file, FLAG_delay_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200363 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000364 }
365
366 if (msg.has_drift()) {
oprypin6e09d872017-08-31 03:21:39 -0700367 static FILE* drift_file = OpenFile(FLAG_drift_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000368 int32_t drift = msg.drift();
oprypin6e09d872017-08-31 03:21:39 -0700369 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200370 fprintf(drift_file, "%d\n", drift);
371 } else {
oprypin6e09d872017-08-31 03:21:39 -0700372 WriteData(&drift, sizeof(drift), drift_file, FLAG_drift_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200373 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000374 }
375
376 if (msg.has_level()) {
oprypin6e09d872017-08-31 03:21:39 -0700377 static FILE* level_file = OpenFile(FLAG_level_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000378 int32_t level = msg.level();
oprypin6e09d872017-08-31 03:21:39 -0700379 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200380 fprintf(level_file, "%d\n", level);
381 } else {
oprypin6e09d872017-08-31 03:21:39 -0700382 WriteData(&level, sizeof(level), level_file, FLAG_level_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200383 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000384 }
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000385
386 if (msg.has_keypress()) {
oprypin6e09d872017-08-31 03:21:39 -0700387 static FILE* keypress_file = OpenFile(FLAG_keypress_file, "wb");
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000388 bool keypress = msg.keypress();
oprypin6e09d872017-08-31 03:21:39 -0700389 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200390 fprintf(keypress_file, "%d\n", keypress);
391 } else {
392 WriteData(&keypress, sizeof(keypress), keypress_file,
oprypin6e09d872017-08-31 03:21:39 -0700393 FLAG_keypress_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200394 }
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000395 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000396 }
Minyue13b96ba2015-10-03 00:39:14 +0200397 } else if (event_msg.type() == Event::CONFIG) {
398 if (!event_msg.has_config()) {
399 printf("Corrupt input file: Config missing.\n");
400 return 1;
401 }
402 const audioproc::Config msg = event_msg.config();
403
404 fprintf(settings_file, "APM re-config at frame: %d\n", frame_count);
405
406 PRINT_CONFIG(aec_enabled);
407 PRINT_CONFIG(aec_delay_agnostic_enabled);
408 PRINT_CONFIG(aec_drift_compensation_enabled);
409 PRINT_CONFIG(aec_extended_filter_enabled);
410 PRINT_CONFIG(aec_suppression_level);
411 PRINT_CONFIG(aecm_enabled);
412 PRINT_CONFIG(aecm_comfort_noise_enabled);
413 PRINT_CONFIG(aecm_routing_mode);
414 PRINT_CONFIG(agc_enabled);
415 PRINT_CONFIG(agc_mode);
416 PRINT_CONFIG(agc_limiter_enabled);
417 PRINT_CONFIG(noise_robust_agc_enabled);
418 PRINT_CONFIG(hpf_enabled);
419 PRINT_CONFIG(ns_enabled);
420 PRINT_CONFIG(ns_level);
421 PRINT_CONFIG(transient_suppression_enabled);
Alex Loiko5feb30e2018-04-16 13:52:32 +0200422 PRINT_CONFIG(pre_amplifier_enabled);
423 PRINT_CONFIG_FLOAT(pre_amplifier_fixed_gain_factor);
424
peah7789fe72016-04-15 01:19:44 -0700425 if (msg.has_experiments_description()) {
426 fprintf(settings_file, " experiments_description: %s\n",
427 msg.experiments_description().c_str());
428 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000429 } else if (event_msg.type() == Event::INIT) {
430 if (!event_msg.has_init()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000431 printf("Corrupt input file: Init missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000432 return 1;
433 }
434
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000435 const Init msg = event_msg.init();
436 // These should print out zeros if they're missing.
437 fprintf(settings_file, "Init at frame: %d\n", frame_count);
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000438 int input_sample_rate = msg.sample_rate();
439 fprintf(settings_file, " Input sample rate: %d\n", input_sample_rate);
440 int output_sample_rate = msg.output_sample_rate();
441 fprintf(settings_file, " Output sample rate: %d\n", output_sample_rate);
442 int reverse_sample_rate = msg.reverse_sample_rate();
Yves Gerey665174f2018-06-19 15:03:05 +0200443 fprintf(settings_file, " Reverse sample rate: %d\n",
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000444 reverse_sample_rate);
445 num_input_channels = msg.num_input_channels();
Peter Kasting69558702016-01-12 16:26:35 -0800446 fprintf(settings_file, " Input channels: %" PRIuS "\n",
447 num_input_channels);
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000448 num_output_channels = msg.num_output_channels();
Peter Kasting69558702016-01-12 16:26:35 -0800449 fprintf(settings_file, " Output channels: %" PRIuS "\n",
450 num_output_channels);
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000451 num_reverse_channels = msg.num_reverse_channels();
Peter Kasting69558702016-01-12 16:26:35 -0800452 fprintf(settings_file, " Reverse channels: %" PRIuS "\n",
453 num_reverse_channels);
Minyue Li656d6092018-08-10 15:38:52 +0200454 if (msg.has_timestamp_ms()) {
455 const int64_t timestamp = msg.timestamp_ms();
456 fprintf(settings_file, " Timestamp in millisecond: %" PRId64 "\n",
457 timestamp);
458 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000459
460 fprintf(settings_file, "\n");
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000461
462 if (reverse_sample_rate == 0) {
463 reverse_sample_rate = input_sample_rate;
464 }
465 if (output_sample_rate == 0) {
466 output_sample_rate = input_sample_rate;
467 }
468
pkasting25702cb2016-01-08 13:50:27 -0800469 reverse_samples_per_channel =
470 static_cast<size_t>(reverse_sample_rate / 100);
Yves Gerey665174f2018-06-19 15:03:05 +0200471 input_samples_per_channel = static_cast<size_t>(input_sample_rate / 100);
pkasting25702cb2016-01-08 13:50:27 -0800472 output_samples_per_channel =
473 static_cast<size_t>(output_sample_rate / 100);
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000474
oprypin6e09d872017-08-31 03:21:39 -0700475 if (!FLAG_raw) {
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000476 // The WAV files need to be reset every time, because they cant change
477 // their sample rate or number of channels.
Jonas Olsson366a50c2018-09-06 13:41:30 +0200478 rtc::StringBuilder reverse_name;
oprypin6e09d872017-08-31 03:21:39 -0700479 reverse_name << FLAG_reverse_file << frame_count << ".wav";
Yves Gerey665174f2018-06-19 15:03:05 +0200480 reverse_wav_file.reset(new WavWriter(
481 reverse_name.str(), reverse_sample_rate, num_reverse_channels));
Jonas Olsson366a50c2018-09-06 13:41:30 +0200482 rtc::StringBuilder input_name;
oprypin6e09d872017-08-31 03:21:39 -0700483 input_name << FLAG_input_file << frame_count << ".wav";
Yves Gerey665174f2018-06-19 15:03:05 +0200484 input_wav_file.reset(new WavWriter(input_name.str(), input_sample_rate,
andrew@webrtc.orga3ed7132014-10-31 21:51:03 +0000485 num_input_channels));
Jonas Olsson366a50c2018-09-06 13:41:30 +0200486 rtc::StringBuilder output_name;
oprypin6e09d872017-08-31 03:21:39 -0700487 output_name << FLAG_output_file << frame_count << ".wav";
Yves Gerey665174f2018-06-19 15:03:05 +0200488 output_wav_file.reset(new WavWriter(
489 output_name.str(), output_sample_rate, num_output_channels));
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200490
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200491 if (WritingCallOrderFile()) {
492 rtc::StringBuilder callorder_name;
493 callorder_name << FLAG_callorder_file << frame_count << ".char";
494 callorder_char_file = OpenFile(callorder_name.str(), "wb");
495 }
Fredrik Hernqvist3be9da32019-05-21 12:23:31 +0200496
497 if (WritingRuntimeSettingFiles()) {
498 for (RuntimeSettingWriter& writer : runtime_setting_writers) {
499 writer.HandleInitEvent(frame_count);
500 }
501 }
502 }
503 } else if (event_msg.type() == Event::RUNTIME_SETTING) {
504 if (WritingRuntimeSettingFiles()) {
505 for (RuntimeSettingWriter& writer : runtime_setting_writers) {
506 if (writer.IsExporterFor(event_msg)) {
507 writer.WriteEvent(event_msg, frame_count);
508 }
509 }
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000510 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000511 }
512 }
513
514 return 0;
515}
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000516
517} // namespace webrtc
518
519int main(int argc, char* argv[]) {
520 return webrtc::do_main(argc, argv);
521}