blob: c90ba827486e1bb6152aad33f6aaeb2b9b2904e2 [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
16#include <stdio.h>
17
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000018#include "gflags/gflags.h"
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000019#include "webrtc/audio_processing/debug.pb.h"
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000020#include "webrtc/modules/audio_processing/test/test_utils.h"
pbos@webrtc.org7fad4b82013-05-28 08:11:59 +000021#include "webrtc/system_wrappers/interface/scoped_ptr.h"
22#include "webrtc/typedefs.h"
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000023
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000024// TODO(andrew): unpack more of the data.
25DEFINE_string(input_file, "input.pcm", "The name of the input stream file.");
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000026DEFINE_string(float_input_file, "input.float",
27 "The name of the float input stream file.");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +000028DEFINE_string(output_file, "ref_out.pcm",
29 "The name of the reference output stream file.");
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000030DEFINE_string(float_output_file, "ref_out.float",
31 "The name of the float reference output stream file.");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +000032DEFINE_string(reverse_file, "reverse.pcm",
33 "The name of the reverse input stream file.");
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000034DEFINE_string(float_reverse_file, "reverse.float",
35 "The name of the float reverse input stream file.");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +000036DEFINE_string(delay_file, "delay.int32", "The name of the delay file.");
37DEFINE_string(drift_file, "drift.int32", "The name of the drift file.");
38DEFINE_string(level_file, "level.int32", "The name of the level file.");
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +000039DEFINE_string(keypress_file, "keypress.bool", "The name of the keypress file.");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +000040DEFINE_string(settings_file, "settings.txt", "The name of the settings file.");
41DEFINE_bool(full, false,
42 "Unpack the full set of files (normally not needed).");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000043
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000044namespace webrtc {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000045
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000046using audioproc::Event;
47using audioproc::ReverseStream;
48using audioproc::Stream;
49using audioproc::Init;
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000050
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000051void WriteData(const void* data, size_t size, FILE* file,
52 const std::string& filename) {
53 if (fwrite(data, size, 1, file) != 1) {
54 printf("Error when writing to %s\n", filename.c_str());
55 exit(1);
56 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000057}
58
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000059int do_main(int argc, char* argv[]) {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000060 std::string program_name = argv[0];
61 std::string usage = "Commandline tool to unpack audioproc debug files.\n"
62 "Example usage:\n" + program_name + " debug_dump.pb\n";
63 google::SetUsageMessage(usage);
64 google::ParseCommandLineFlags(&argc, &argv, true);
65
66 if (argc < 2) {
67 printf("%s", google::ProgramUsage());
68 return 1;
69 }
70
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000071 FILE* debug_file = OpenFile(argv[1], "rb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +000072
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000073 Event event_msg;
andrew@webrtc.orgcd824382011-11-11 19:13:36 +000074 int frame_count = 0;
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000075while (ReadMessageFromFile(debug_file, &event_msg)) {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000076 if (event_msg.type() == Event::REVERSE_STREAM) {
77 if (!event_msg.has_reverse_stream()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000078 printf("Corrupt input file: ReverseStream missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000079 return 1;
80 }
81
82 const ReverseStream msg = event_msg.reverse_stream();
andrew@webrtc.orgcd824382011-11-11 19:13:36 +000083 if (msg.has_data()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000084 static FILE* reverse_file = OpenFile(FLAGS_reverse_file, "wb");
85 WriteData(msg.data().data(), msg.data().size(), reverse_file,
86 FLAGS_reverse_file);
87
88 } else if (msg.channel_size() > 0) {
89 static FILE* float_reverse_file = OpenFile(FLAGS_float_reverse_file,
90 "wb");
91 // TODO(ajm): Interleave multiple channels.
92 assert(msg.channel_size() == 1);
93 WriteData(msg.channel(0).data(), msg.channel(0).size(),
94 float_reverse_file, FLAGS_reverse_file);
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000095 }
96 } else if (event_msg.type() == Event::STREAM) {
andrew@webrtc.orgcd824382011-11-11 19:13:36 +000097 frame_count++;
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000098 if (!event_msg.has_stream()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000099 printf("Corrupt input file: Stream missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000100 return 1;
101 }
102
103 const Stream msg = event_msg.stream();
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000104 if (msg.has_input_data()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000105 static FILE* input_file = OpenFile(FLAGS_input_file, "wb");
106 WriteData(msg.input_data().data(), msg.input_data().size(),
107 input_file, FLAGS_input_file);
108
109 } else if (msg.input_channel_size() > 0) {
110 static FILE* float_input_file = OpenFile(FLAGS_float_input_file, "wb");
111 // TODO(ajm): Interleave multiple channels.
112 assert(msg.input_channel_size() == 1);
113 WriteData(msg.input_channel(0).data(), msg.input_channel(0).size(),
114 float_input_file, FLAGS_float_input_file);
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000115 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000116
117 if (msg.has_output_data()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000118 static FILE* output_file = OpenFile(FLAGS_output_file, "wb");
119 WriteData(msg.output_data().data(), msg.output_data().size(),
120 output_file, FLAGS_output_file);
121
122 } else if (msg.output_channel_size() > 0) {
123 static FILE* float_output_file = OpenFile(FLAGS_float_output_file,
124 "wb");
125 // TODO(ajm): Interleave multiple channels.
126 assert(msg.output_channel_size() == 1);
127 WriteData(msg.output_channel(0).data(), msg.output_channel(0).size(),
128 float_output_file, FLAGS_float_output_file);
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000129 }
130
131 if (FLAGS_full) {
132 if (msg.has_delay()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000133 static FILE* delay_file = OpenFile(FLAGS_delay_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000134 int32_t delay = msg.delay();
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000135 WriteData(&delay, sizeof(delay), delay_file, FLAGS_delay_file);
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000136 }
137
138 if (msg.has_drift()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000139 static FILE* drift_file = OpenFile(FLAGS_drift_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000140 int32_t drift = msg.drift();
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000141 WriteData(&drift, sizeof(drift), drift_file, FLAGS_drift_file);
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000142 }
143
144 if (msg.has_level()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000145 static FILE* level_file = OpenFile(FLAGS_level_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000146 int32_t level = msg.level();
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000147 WriteData(&level, sizeof(level), level_file, FLAGS_level_file);
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000148 }
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000149
150 if (msg.has_keypress()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000151 static FILE* keypress_file = OpenFile(FLAGS_keypress_file, "wb");
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000152 bool keypress = msg.keypress();
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000153 WriteData(&keypress, sizeof(keypress), keypress_file,
154 FLAGS_keypress_file);
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000155 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000156 }
157 } else if (event_msg.type() == Event::INIT) {
158 if (!event_msg.has_init()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000159 printf("Corrupt input file: Init missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000160 return 1;
161 }
162
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000163 static FILE* settings_file = OpenFile(FLAGS_settings_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000164 const Init msg = event_msg.init();
165 // These should print out zeros if they're missing.
166 fprintf(settings_file, "Init at frame: %d\n", frame_count);
167 fprintf(settings_file, " Sample rate: %d\n", msg.sample_rate());
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000168 fprintf(settings_file, " Input channels: %d\n",
169 msg.num_input_channels());
170 fprintf(settings_file, " Output channels: %d\n",
171 msg.num_output_channels());
172 fprintf(settings_file, " Reverse channels: %d\n",
173 msg.num_reverse_channels());
174
175 fprintf(settings_file, "\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000176 }
177 }
178
179 return 0;
180}
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000181
182} // namespace webrtc
183
184int main(int argc, char* argv[]) {
185 return webrtc::do_main(argc, argv);
186}