xref: /aosp_15_r20/external/webrtc/rtc_tools/unpack_aecdump/unpack.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 
16 #include <inttypes.h>
17 #include <stdint.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include "absl/flags/flag.h"
26 #include "absl/flags/parse.h"
27 #include "api/function_view.h"
28 #include "common_audio/include/audio_util.h"
29 #include "common_audio/wav_file.h"
30 #include "modules/audio_processing/test/protobuf_utils.h"
31 #include "rtc_base/checks.h"
32 #include "rtc_base/ignore_wundef.h"
33 #include "rtc_base/strings/string_builder.h"
34 #include "rtc_base/system/arch.h"
35 
36 RTC_PUSH_IGNORING_WUNDEF()
37 #include "modules/audio_processing/debug.pb.h"
38 RTC_POP_IGNORING_WUNDEF()
39 
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 applied input volume 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.");
85 ABSL_FLAG(bool,
86           use_init_suffix,
87           false,
88           "Use init index instead of capture frame count as file name suffix.");
89 
90 #define PRINT_CONFIG(field_name)                                         \
91   if (msg.has_##field_name()) {                                          \
92     fprintf(settings_file, "  " #field_name ": %d\n", msg.field_name()); \
93   }
94 
95 #define PRINT_CONFIG_FLOAT(field_name)                                   \
96   if (msg.has_##field_name()) {                                          \
97     fprintf(settings_file, "  " #field_name ": %f\n", msg.field_name()); \
98   }
99 
100 namespace webrtc {
101 
102 using audioproc::Event;
103 using audioproc::Init;
104 using audioproc::ReverseStream;
105 using audioproc::Stream;
106 
107 namespace {
108 class RawFile final {
109  public:
RawFile(const std::string & filename)110   explicit RawFile(const std::string& filename)
111       : file_handle_(fopen(filename.c_str(), "wb")) {}
~RawFile()112   ~RawFile() { fclose(file_handle_); }
113 
114   RawFile(const RawFile&) = delete;
115   RawFile& operator=(const RawFile&) = delete;
116 
WriteSamples(const int16_t * samples,size_t num_samples)117   void WriteSamples(const int16_t* samples, size_t num_samples) {
118 #ifndef WEBRTC_ARCH_LITTLE_ENDIAN
119 #error "Need to convert samples to little-endian when writing to PCM file"
120 #endif
121     fwrite(samples, sizeof(*samples), num_samples, file_handle_);
122   }
123 
WriteSamples(const float * samples,size_t num_samples)124   void WriteSamples(const float* samples, size_t num_samples) {
125     fwrite(samples, sizeof(*samples), num_samples, file_handle_);
126   }
127 
128  private:
129   FILE* file_handle_;
130 };
131 
WriteIntData(const int16_t * data,size_t length,WavWriter * wav_file,RawFile * raw_file)132 void WriteIntData(const int16_t* data,
133                   size_t length,
134                   WavWriter* wav_file,
135                   RawFile* raw_file) {
136   if (wav_file) {
137     wav_file->WriteSamples(data, length);
138   }
139   if (raw_file) {
140     raw_file->WriteSamples(data, length);
141   }
142 }
143 
WriteFloatData(const float * const * data,size_t samples_per_channel,size_t num_channels,WavWriter * wav_file,RawFile * raw_file)144 void WriteFloatData(const float* const* data,
145                     size_t samples_per_channel,
146                     size_t num_channels,
147                     WavWriter* wav_file,
148                     RawFile* raw_file) {
149   size_t length = num_channels * samples_per_channel;
150   std::unique_ptr<float[]> buffer(new float[length]);
151   Interleave(data, samples_per_channel, num_channels, buffer.get());
152   if (raw_file) {
153     raw_file->WriteSamples(buffer.get(), length);
154   }
155   // TODO(aluebs): Use ScaleToInt16Range() from audio_util
156   for (size_t i = 0; i < length; ++i) {
157     buffer[i] = buffer[i] > 0
158                     ? buffer[i] * std::numeric_limits<int16_t>::max()
159                     : -buffer[i] * std::numeric_limits<int16_t>::min();
160   }
161   if (wav_file) {
162     wav_file->WriteSamples(buffer.get(), length);
163   }
164 }
165 
166 // Exits on failure; do not use in unit tests.
OpenFile(const std::string & filename,const char * mode)167 FILE* OpenFile(const std::string& filename, const char* mode) {
168   FILE* file = fopen(filename.c_str(), mode);
169   RTC_CHECK(file) << "Unable to open file " << filename;
170   return file;
171 }
172 
WriteData(const void * data,size_t size,FILE * file,const std::string & filename)173 void WriteData(const void* data,
174                size_t size,
175                FILE* file,
176                const std::string& filename) {
177   RTC_CHECK_EQ(fwrite(data, size, 1, file), 1)
178       << "Error when writing to " << filename.c_str();
179 }
180 
WriteCallOrderData(const bool render_call,FILE * file,const std::string & filename)181 void WriteCallOrderData(const bool render_call,
182                         FILE* file,
183                         const std::string& filename) {
184   const char call_type = render_call ? 'r' : 'c';
185   WriteData(&call_type, sizeof(call_type), file, filename.c_str());
186 }
187 
WritingCallOrderFile()188 bool WritingCallOrderFile() {
189   return absl::GetFlag(FLAGS_full);
190 }
191 
WritingRuntimeSettingFiles()192 bool WritingRuntimeSettingFiles() {
193   return absl::GetFlag(FLAGS_full);
194 }
195 
196 // Exports RuntimeSetting AEC dump events to Audacity-readable files.
197 // This class is not RAII compliant.
198 class RuntimeSettingWriter {
199  public:
RuntimeSettingWriter(std::string name,rtc::FunctionView<bool (const Event)> is_exporter_for,rtc::FunctionView<std::string (const Event)> get_timeline_label)200   RuntimeSettingWriter(
201       std::string name,
202       rtc::FunctionView<bool(const Event)> is_exporter_for,
203       rtc::FunctionView<std::string(const Event)> get_timeline_label)
204       : setting_name_(std::move(name)),
205         is_exporter_for_(is_exporter_for),
206         get_timeline_label_(get_timeline_label) {}
~RuntimeSettingWriter()207   ~RuntimeSettingWriter() { Flush(); }
208 
IsExporterFor(const Event & event) const209   bool IsExporterFor(const Event& event) const {
210     return is_exporter_for_(event);
211   }
212 
213   // Writes to file the payload of `event` using `frame_count` to calculate
214   // timestamp.
WriteEvent(const Event & event,int frame_count)215   void WriteEvent(const Event& event, int frame_count) {
216     RTC_DCHECK(is_exporter_for_(event));
217     if (file_ == nullptr) {
218       rtc::StringBuilder file_name;
219       file_name << setting_name_ << frame_offset_ << ".txt";
220       file_ = OpenFile(file_name.str(), "wb");
221     }
222 
223     // Time in the current WAV file, in seconds.
224     double time = (frame_count - frame_offset_) / 100.0;
225     std::string label = get_timeline_label_(event);
226     // In Audacity, all annotations are encoded as intervals.
227     fprintf(file_, "%.6f\t%.6f\t%s \n", time, time, label.c_str());
228   }
229 
230   // Handles an AEC dump initialization event, occurring at frame
231   // `frame_offset`.
HandleInitEvent(int frame_offset)232   void HandleInitEvent(int frame_offset) {
233     Flush();
234     frame_offset_ = frame_offset;
235   }
236 
237  private:
Flush()238   void Flush() {
239     if (file_ != nullptr) {
240       fclose(file_);
241       file_ = nullptr;
242     }
243   }
244 
245   FILE* file_ = nullptr;
246   int frame_offset_ = 0;
247   const std::string setting_name_;
248   const rtc::FunctionView<bool(Event)> is_exporter_for_;
249   const rtc::FunctionView<std::string(Event)> get_timeline_label_;
250 };
251 
252 // Returns RuntimeSetting exporters for runtime setting types defined in
253 // debug.proto.
RuntimeSettingWriters()254 std::vector<RuntimeSettingWriter> RuntimeSettingWriters() {
255   return {
256       RuntimeSettingWriter(
257           "CapturePreGain",
258           [](const Event& event) -> bool {
259             return event.runtime_setting().has_capture_pre_gain();
260           },
261           [](const Event& event) -> std::string {
262             return std::to_string(event.runtime_setting().capture_pre_gain());
263           }),
264       RuntimeSettingWriter(
265           "CustomRenderProcessingRuntimeSetting",
266           [](const Event& event) -> bool {
267             return event.runtime_setting()
268                 .has_custom_render_processing_setting();
269           },
270           [](const Event& event) -> std::string {
271             return std::to_string(
272                 event.runtime_setting().custom_render_processing_setting());
273           }),
274       RuntimeSettingWriter(
275           "CaptureFixedPostGain",
276           [](const Event& event) -> bool {
277             return event.runtime_setting().has_capture_fixed_post_gain();
278           },
279           [](const Event& event) -> std::string {
280             return std::to_string(
281                 event.runtime_setting().capture_fixed_post_gain());
282           }),
283       RuntimeSettingWriter(
284           "PlayoutVolumeChange",
285           [](const Event& event) -> bool {
286             return event.runtime_setting().has_playout_volume_change();
287           },
288           [](const Event& event) -> std::string {
289             return std::to_string(
290                 event.runtime_setting().playout_volume_change());
291           })};
292 }
293 
GetWavFileIndex(int init_index,int frame_count)294 std::string GetWavFileIndex(int init_index, int frame_count) {
295   rtc::StringBuilder suffix;
296   if (absl::GetFlag(FLAGS_use_init_suffix)) {
297     suffix << "_" << init_index;
298   } else {
299     suffix << frame_count;
300   }
301   return suffix.str();
302 }
303 
304 }  // namespace
305 
do_main(int argc,char * argv[])306 int do_main(int argc, char* argv[]) {
307   std::vector<char*> args = absl::ParseCommandLine(argc, argv);
308   std::string program_name = args[0];
309   std::string usage =
310       "Commandline tool to unpack audioproc debug files.\n"
311       "Example usage:\n" +
312       program_name + " debug_dump.pb\n";
313 
314   if (args.size() < 2) {
315     printf("%s", usage.c_str());
316     return 1;
317   }
318 
319   FILE* debug_file = OpenFile(args[1], "rb");
320 
321   Event event_msg;
322   int frame_count = 0;
323   int init_count = 0;
324   size_t reverse_samples_per_channel = 0;
325   size_t input_samples_per_channel = 0;
326   size_t output_samples_per_channel = 0;
327   size_t num_reverse_channels = 0;
328   size_t num_input_channels = 0;
329   size_t num_output_channels = 0;
330   std::unique_ptr<WavWriter> reverse_wav_file;
331   std::unique_ptr<WavWriter> input_wav_file;
332   std::unique_ptr<WavWriter> output_wav_file;
333   std::unique_ptr<RawFile> reverse_raw_file;
334   std::unique_ptr<RawFile> input_raw_file;
335   std::unique_ptr<RawFile> output_raw_file;
336 
337   rtc::StringBuilder callorder_raw_name;
338   callorder_raw_name << absl::GetFlag(FLAGS_callorder_file) << ".char";
339   FILE* callorder_char_file = WritingCallOrderFile()
340                                   ? OpenFile(callorder_raw_name.str(), "wb")
341                                   : nullptr;
342   FILE* settings_file = OpenFile(absl::GetFlag(FLAGS_settings_file), "wb");
343 
344   std::vector<RuntimeSettingWriter> runtime_setting_writers =
345       RuntimeSettingWriters();
346 
347   while (ReadMessageFromFile(debug_file, &event_msg)) {
348     if (event_msg.type() == Event::REVERSE_STREAM) {
349       if (!event_msg.has_reverse_stream()) {
350         printf("Corrupt input file: ReverseStream missing.\n");
351         return 1;
352       }
353 
354       const ReverseStream msg = event_msg.reverse_stream();
355       if (msg.has_data()) {
356         if (absl::GetFlag(FLAGS_raw) && !reverse_raw_file) {
357           reverse_raw_file.reset(
358               new RawFile(absl::GetFlag(FLAGS_reverse_file) + ".pcm"));
359         }
360         // TODO(aluebs): Replace "num_reverse_channels *
361         // reverse_samples_per_channel" with "msg.data().size() /
362         // sizeof(int16_t)" and so on when this fix in audio_processing has made
363         // it into stable: https://webrtc-codereview.appspot.com/15299004/
364         WriteIntData(reinterpret_cast<const int16_t*>(msg.data().data()),
365                      num_reverse_channels * reverse_samples_per_channel,
366                      reverse_wav_file.get(), reverse_raw_file.get());
367       } else if (msg.channel_size() > 0) {
368         if (absl::GetFlag(FLAGS_raw) && !reverse_raw_file) {
369           reverse_raw_file.reset(
370               new RawFile(absl::GetFlag(FLAGS_reverse_file) + ".float"));
371         }
372         std::unique_ptr<const float*[]> data(
373             new const float*[num_reverse_channels]);
374         for (size_t i = 0; i < num_reverse_channels; ++i) {
375           data[i] = reinterpret_cast<const float*>(msg.channel(i).data());
376         }
377         WriteFloatData(data.get(), reverse_samples_per_channel,
378                        num_reverse_channels, reverse_wav_file.get(),
379                        reverse_raw_file.get());
380       }
381       if (absl::GetFlag(FLAGS_full)) {
382         if (WritingCallOrderFile()) {
383           WriteCallOrderData(true /* render_call */, callorder_char_file,
384                              absl::GetFlag(FLAGS_callorder_file));
385         }
386       }
387     } else if (event_msg.type() == Event::STREAM) {
388       frame_count++;
389       if (!event_msg.has_stream()) {
390         printf("Corrupt input file: Stream missing.\n");
391         return 1;
392       }
393 
394       const Stream msg = event_msg.stream();
395       if (msg.has_input_data()) {
396         if (absl::GetFlag(FLAGS_raw) && !input_raw_file) {
397           input_raw_file.reset(
398               new RawFile(absl::GetFlag(FLAGS_input_file) + ".pcm"));
399         }
400         WriteIntData(reinterpret_cast<const int16_t*>(msg.input_data().data()),
401                      num_input_channels * input_samples_per_channel,
402                      input_wav_file.get(), input_raw_file.get());
403       } else if (msg.input_channel_size() > 0) {
404         if (absl::GetFlag(FLAGS_raw) && !input_raw_file) {
405           input_raw_file.reset(
406               new RawFile(absl::GetFlag(FLAGS_input_file) + ".float"));
407         }
408         std::unique_ptr<const float*[]> data(
409             new const float*[num_input_channels]);
410         for (size_t i = 0; i < num_input_channels; ++i) {
411           data[i] = reinterpret_cast<const float*>(msg.input_channel(i).data());
412         }
413         WriteFloatData(data.get(), input_samples_per_channel,
414                        num_input_channels, input_wav_file.get(),
415                        input_raw_file.get());
416       }
417 
418       if (msg.has_output_data()) {
419         if (absl::GetFlag(FLAGS_raw) && !output_raw_file) {
420           output_raw_file.reset(
421               new RawFile(absl::GetFlag(FLAGS_output_file) + ".pcm"));
422         }
423         WriteIntData(reinterpret_cast<const int16_t*>(msg.output_data().data()),
424                      num_output_channels * output_samples_per_channel,
425                      output_wav_file.get(), output_raw_file.get());
426       } else if (msg.output_channel_size() > 0) {
427         if (absl::GetFlag(FLAGS_raw) && !output_raw_file) {
428           output_raw_file.reset(
429               new RawFile(absl::GetFlag(FLAGS_output_file) + ".float"));
430         }
431         std::unique_ptr<const float*[]> data(
432             new const float*[num_output_channels]);
433         for (size_t i = 0; i < num_output_channels; ++i) {
434           data[i] =
435               reinterpret_cast<const float*>(msg.output_channel(i).data());
436         }
437         WriteFloatData(data.get(), output_samples_per_channel,
438                        num_output_channels, output_wav_file.get(),
439                        output_raw_file.get());
440       }
441 
442       if (absl::GetFlag(FLAGS_full)) {
443         if (WritingCallOrderFile()) {
444           WriteCallOrderData(false /* render_call */, callorder_char_file,
445                              absl::GetFlag(FLAGS_callorder_file));
446         }
447         if (msg.has_delay()) {
448           static FILE* delay_file =
449               OpenFile(absl::GetFlag(FLAGS_delay_file), "wb");
450           int32_t delay = msg.delay();
451           if (absl::GetFlag(FLAGS_text)) {
452             fprintf(delay_file, "%d\n", delay);
453           } else {
454             WriteData(&delay, sizeof(delay), delay_file,
455                       absl::GetFlag(FLAGS_delay_file));
456           }
457         }
458 
459         if (msg.has_drift()) {
460           static FILE* drift_file =
461               OpenFile(absl::GetFlag(FLAGS_drift_file), "wb");
462           int32_t drift = msg.drift();
463           if (absl::GetFlag(FLAGS_text)) {
464             fprintf(drift_file, "%d\n", drift);
465           } else {
466             WriteData(&drift, sizeof(drift), drift_file,
467                       absl::GetFlag(FLAGS_drift_file));
468           }
469         }
470 
471         if (msg.has_applied_input_volume()) {
472           static FILE* level_file =
473               OpenFile(absl::GetFlag(FLAGS_level_file), "wb");
474           int32_t level = msg.applied_input_volume();
475           if (absl::GetFlag(FLAGS_text)) {
476             fprintf(level_file, "%d\n", level);
477           } else {
478             WriteData(&level, sizeof(level), level_file,
479                       absl::GetFlag(FLAGS_level_file));
480           }
481         }
482 
483         if (msg.has_keypress()) {
484           static FILE* keypress_file =
485               OpenFile(absl::GetFlag(FLAGS_keypress_file), "wb");
486           bool keypress = msg.keypress();
487           if (absl::GetFlag(FLAGS_text)) {
488             fprintf(keypress_file, "%d\n", keypress);
489           } else {
490             WriteData(&keypress, sizeof(keypress), keypress_file,
491                       absl::GetFlag(FLAGS_keypress_file));
492           }
493         }
494       }
495     } else if (event_msg.type() == Event::CONFIG) {
496       if (!event_msg.has_config()) {
497         printf("Corrupt input file: Config missing.\n");
498         return 1;
499       }
500       const audioproc::Config msg = event_msg.config();
501 
502       fprintf(settings_file, "APM re-config at frame: %d\n", frame_count);
503 
504       PRINT_CONFIG(aec_enabled);
505       PRINT_CONFIG(aec_delay_agnostic_enabled);
506       PRINT_CONFIG(aec_drift_compensation_enabled);
507       PRINT_CONFIG(aec_extended_filter_enabled);
508       PRINT_CONFIG(aec_suppression_level);
509       PRINT_CONFIG(aecm_enabled);
510       PRINT_CONFIG(aecm_comfort_noise_enabled);
511       PRINT_CONFIG(aecm_routing_mode);
512       PRINT_CONFIG(agc_enabled);
513       PRINT_CONFIG(agc_mode);
514       PRINT_CONFIG(agc_limiter_enabled);
515       PRINT_CONFIG(noise_robust_agc_enabled);
516       PRINT_CONFIG(hpf_enabled);
517       PRINT_CONFIG(ns_enabled);
518       PRINT_CONFIG(ns_level);
519       PRINT_CONFIG(transient_suppression_enabled);
520       PRINT_CONFIG(pre_amplifier_enabled);
521       PRINT_CONFIG_FLOAT(pre_amplifier_fixed_gain_factor);
522 
523       if (msg.has_experiments_description()) {
524         fprintf(settings_file, "  experiments_description: %s\n",
525                 msg.experiments_description().c_str());
526       }
527     } else if (event_msg.type() == Event::INIT) {
528       if (!event_msg.has_init()) {
529         printf("Corrupt input file: Init missing.\n");
530         return 1;
531       }
532 
533       ++init_count;
534       const Init msg = event_msg.init();
535       // These should print out zeros if they're missing.
536       fprintf(settings_file, "Init #%d at frame: %d\n", init_count,
537               frame_count);
538       int input_sample_rate = msg.sample_rate();
539       fprintf(settings_file, "  Input sample rate: %d\n", input_sample_rate);
540       int output_sample_rate = msg.output_sample_rate();
541       fprintf(settings_file, "  Output sample rate: %d\n", output_sample_rate);
542       int reverse_sample_rate = msg.reverse_sample_rate();
543       fprintf(settings_file, "  Reverse sample rate: %d\n",
544               reverse_sample_rate);
545       num_input_channels = msg.num_input_channels();
546       fprintf(settings_file, "  Input channels: %zu\n", num_input_channels);
547       num_output_channels = msg.num_output_channels();
548       fprintf(settings_file, "  Output channels: %zu\n", num_output_channels);
549       num_reverse_channels = msg.num_reverse_channels();
550       fprintf(settings_file, "  Reverse channels: %zu\n", num_reverse_channels);
551       if (msg.has_timestamp_ms()) {
552         const int64_t timestamp = msg.timestamp_ms();
553         fprintf(settings_file, "  Timestamp in millisecond: %" PRId64 "\n",
554                 timestamp);
555       }
556 
557       fprintf(settings_file, "\n");
558 
559       if (reverse_sample_rate == 0) {
560         reverse_sample_rate = input_sample_rate;
561       }
562       if (output_sample_rate == 0) {
563         output_sample_rate = input_sample_rate;
564       }
565 
566       reverse_samples_per_channel =
567           static_cast<size_t>(reverse_sample_rate / 100);
568       input_samples_per_channel = static_cast<size_t>(input_sample_rate / 100);
569       output_samples_per_channel =
570           static_cast<size_t>(output_sample_rate / 100);
571 
572       if (!absl::GetFlag(FLAGS_raw)) {
573         // The WAV files need to be reset every time, because they cant change
574         // their sample rate or number of channels.
575 
576         std::string suffix = GetWavFileIndex(init_count, frame_count);
577         rtc::StringBuilder reverse_name;
578         reverse_name << absl::GetFlag(FLAGS_reverse_file) << suffix << ".wav";
579         reverse_wav_file.reset(new WavWriter(
580             reverse_name.str(), reverse_sample_rate, num_reverse_channels));
581         rtc::StringBuilder input_name;
582         input_name << absl::GetFlag(FLAGS_input_file) << suffix << ".wav";
583         input_wav_file.reset(new WavWriter(input_name.str(), input_sample_rate,
584                                            num_input_channels));
585         rtc::StringBuilder output_name;
586         output_name << absl::GetFlag(FLAGS_output_file) << suffix << ".wav";
587         output_wav_file.reset(new WavWriter(
588             output_name.str(), output_sample_rate, num_output_channels));
589 
590         if (WritingCallOrderFile()) {
591           rtc::StringBuilder callorder_name;
592           callorder_name << absl::GetFlag(FLAGS_callorder_file) << suffix
593                          << ".char";
594           callorder_char_file = OpenFile(callorder_name.str(), "wb");
595         }
596 
597         if (WritingRuntimeSettingFiles()) {
598           for (RuntimeSettingWriter& writer : runtime_setting_writers) {
599             writer.HandleInitEvent(frame_count);
600           }
601         }
602       }
603     } else if (event_msg.type() == Event::RUNTIME_SETTING) {
604       if (WritingRuntimeSettingFiles()) {
605         for (RuntimeSettingWriter& writer : runtime_setting_writers) {
606           if (writer.IsExporterFor(event_msg)) {
607             writer.WriteEvent(event_msg, frame_count);
608           }
609         }
610       }
611     }
612   }
613 
614   return 0;
615 }
616 
617 }  // namespace webrtc
618 
main(int argc,char * argv[])619 int main(int argc, char* argv[]) {
620   return webrtc::do_main(argc, argv);
621 }
622