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 | |
| 16 | #include <stdio.h> |
| 17 | |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 18 | #include "gflags/gflags.h" |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 19 | #include "webrtc/audio_processing/debug.pb.h" |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 20 | #include "webrtc/modules/audio_processing/test/test_utils.h" |
pbos@webrtc.org | 7fad4b8 | 2013-05-28 08:11:59 +0000 | [diff] [blame] | 21 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 22 | #include "webrtc/typedefs.h" |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 23 | |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 24 | // TODO(andrew): unpack more of the data. |
| 25 | DEFINE_string(input_file, "input.pcm", "The name of the input stream file."); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 26 | DEFINE_string(float_input_file, "input.float", |
| 27 | "The name of the float input stream file."); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 28 | DEFINE_string(output_file, "ref_out.pcm", |
| 29 | "The name of the reference output stream file."); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 30 | DEFINE_string(float_output_file, "ref_out.float", |
| 31 | "The name of the float reference output stream file."); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 32 | DEFINE_string(reverse_file, "reverse.pcm", |
| 33 | "The name of the reverse input stream file."); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 34 | DEFINE_string(float_reverse_file, "reverse.float", |
| 35 | "The name of the float reverse input stream file."); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 36 | DEFINE_string(delay_file, "delay.int32", "The name of the delay file."); |
| 37 | DEFINE_string(drift_file, "drift.int32", "The name of the drift file."); |
| 38 | DEFINE_string(level_file, "level.int32", "The name of the level file."); |
andrew@webrtc.org | ce8e077 | 2014-02-12 15:28:30 +0000 | [diff] [blame] | 39 | DEFINE_string(keypress_file, "keypress.bool", "The name of the keypress file."); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 40 | DEFINE_string(settings_file, "settings.txt", "The name of the settings file."); |
| 41 | DEFINE_bool(full, false, |
| 42 | "Unpack the full set of files (normally not needed)."); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 43 | |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 44 | namespace webrtc { |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 45 | |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 46 | using audioproc::Event; |
| 47 | using audioproc::ReverseStream; |
| 48 | using audioproc::Stream; |
| 49 | using audioproc::Init; |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 50 | |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 51 | void 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.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 57 | } |
| 58 | |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 59 | int do_main(int argc, char* argv[]) { |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 60 | 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.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 71 | FILE* debug_file = OpenFile(argv[1], "rb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 72 | |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 73 | Event event_msg; |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 74 | int frame_count = 0; |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 75 | while (ReadMessageFromFile(debug_file, &event_msg)) { |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 76 | if (event_msg.type() == Event::REVERSE_STREAM) { |
| 77 | if (!event_msg.has_reverse_stream()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 78 | printf("Corrupt input file: ReverseStream missing.\n"); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 79 | return 1; |
| 80 | } |
| 81 | |
| 82 | const ReverseStream msg = event_msg.reverse_stream(); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 83 | if (msg.has_data()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 84 | 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.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 95 | } |
| 96 | } else if (event_msg.type() == Event::STREAM) { |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 97 | frame_count++; |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 98 | if (!event_msg.has_stream()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 99 | printf("Corrupt input file: Stream missing.\n"); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 100 | return 1; |
| 101 | } |
| 102 | |
| 103 | const Stream msg = event_msg.stream(); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 104 | if (msg.has_input_data()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 105 | 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.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 115 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 116 | |
| 117 | if (msg.has_output_data()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 118 | 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.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | if (FLAGS_full) { |
| 132 | if (msg.has_delay()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 133 | static FILE* delay_file = OpenFile(FLAGS_delay_file, "wb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 134 | int32_t delay = msg.delay(); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 135 | WriteData(&delay, sizeof(delay), delay_file, FLAGS_delay_file); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | if (msg.has_drift()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 139 | static FILE* drift_file = OpenFile(FLAGS_drift_file, "wb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 140 | int32_t drift = msg.drift(); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 141 | WriteData(&drift, sizeof(drift), drift_file, FLAGS_drift_file); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | if (msg.has_level()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 145 | static FILE* level_file = OpenFile(FLAGS_level_file, "wb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 146 | int32_t level = msg.level(); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 147 | WriteData(&level, sizeof(level), level_file, FLAGS_level_file); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 148 | } |
andrew@webrtc.org | ce8e077 | 2014-02-12 15:28:30 +0000 | [diff] [blame] | 149 | |
| 150 | if (msg.has_keypress()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 151 | static FILE* keypress_file = OpenFile(FLAGS_keypress_file, "wb"); |
andrew@webrtc.org | ce8e077 | 2014-02-12 15:28:30 +0000 | [diff] [blame] | 152 | bool keypress = msg.keypress(); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 153 | WriteData(&keypress, sizeof(keypress), keypress_file, |
| 154 | FLAGS_keypress_file); |
andrew@webrtc.org | ce8e077 | 2014-02-12 15:28:30 +0000 | [diff] [blame] | 155 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 156 | } |
| 157 | } else if (event_msg.type() == Event::INIT) { |
| 158 | if (!event_msg.has_init()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 159 | printf("Corrupt input file: Init missing.\n"); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 160 | return 1; |
| 161 | } |
| 162 | |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 163 | static FILE* settings_file = OpenFile(FLAGS_settings_file, "wb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 164 | 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.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 168 | 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.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | return 0; |
| 180 | } |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 181 | |
| 182 | } // namespace webrtc |
| 183 | |
| 184 | int main(int argc, char* argv[]) { |
| 185 | return webrtc::do_main(argc, argv); |
| 186 | } |