henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 11 | #include <errno.h> |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 12 | #include <inttypes.h> |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 13 | #include <limits.h> // For ULONG_MAX returned by strtoul. |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 15 | #include <stdlib.h> // For strtoul. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 16 | #include <iostream> |
| 17 | #include <memory> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 18 | #include <string> |
| 19 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/audio_coding/neteq/include/neteq.h" |
| 21 | #include "modules/audio_coding/neteq/tools/fake_decode_from_file.h" |
| 22 | #include "modules/audio_coding/neteq/tools/input_audio_file.h" |
| 23 | #include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h" |
Henrik Lundin | 9f2e624 | 2018-07-02 14:05:37 +0200 | [diff] [blame] | 24 | #include "modules/audio_coding/neteq/tools/neteq_event_log_input.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "modules/audio_coding/neteq/tools/neteq_packet_source_input.h" |
| 26 | #include "modules/audio_coding/neteq/tools/neteq_replacement_input.h" |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 27 | #include "modules/audio_coding/neteq/tools/neteq_stats_getter.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "modules/audio_coding/neteq/tools/neteq_test.h" |
| 29 | #include "modules/audio_coding/neteq/tools/output_audio_file.h" |
| 30 | #include "modules/audio_coding/neteq/tools/output_wav_file.h" |
| 31 | #include "modules/audio_coding/neteq/tools/rtp_file_source.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 32 | #include "rtc_base/checks.h" |
| 33 | #include "rtc_base/flags.h" |
Ivo Creusen | 80006b9 | 2018-08-10 11:19:21 +0200 | [diff] [blame] | 34 | #include "test/field_trial.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 35 | #include "test/testsupport/fileutils.h" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 36 | |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 37 | namespace webrtc { |
| 38 | namespace test { |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 39 | namespace { |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 40 | |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 41 | // Parses the input string for a valid SSRC (at the start of the string). If a |
| 42 | // valid SSRC is found, it is written to the output variable |ssrc|, and true is |
| 43 | // returned. Otherwise, false is returned. |
| 44 | bool ParseSsrc(const std::string& str, uint32_t* ssrc) { |
| 45 | if (str.empty()) |
henrik.lundin@webrtc.org | 9103953 | 2014-10-07 07:18:36 +0000 | [diff] [blame] | 46 | return true; |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 47 | int base = 10; |
| 48 | // Look for "0x" or "0X" at the start and change base to 16 if found. |
| 49 | if ((str.compare(0, 2, "0x") == 0) || (str.compare(0, 2, "0X") == 0)) |
| 50 | base = 16; |
| 51 | errno = 0; |
| 52 | char* end_ptr; |
| 53 | unsigned long value = strtoul(str.c_str(), &end_ptr, base); |
| 54 | if (value == ULONG_MAX && errno == ERANGE) |
| 55 | return false; // Value out of range for unsigned long. |
| 56 | if (sizeof(unsigned long) > sizeof(uint32_t) && value > 0xFFFFFFFF) |
| 57 | return false; // Value out of range for uint32_t. |
| 58 | if (end_ptr - str.c_str() < static_cast<ptrdiff_t>(str.length())) |
| 59 | return false; // Part of the string was not parsed. |
| 60 | *ssrc = static_cast<uint32_t>(value); |
| 61 | return true; |
| 62 | } |
| 63 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 64 | // Flag validators. |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 65 | bool ValidatePayloadType(int value) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 66 | if (value >= 0 && value <= 127) // Value is ok. |
| 67 | return true; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 68 | printf("Payload type must be between 0 and 127, not %d\n", |
| 69 | static_cast<int>(value)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 70 | return false; |
| 71 | } |
| 72 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 73 | bool ValidateSsrcValue(const std::string& str) { |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 74 | uint32_t dummy_ssrc; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 75 | if (ParseSsrc(str, &dummy_ssrc)) // Value is ok. |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 76 | return true; |
| 77 | printf("Invalid SSRC: %s\n", str.c_str()); |
| 78 | return false; |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 79 | } |
| 80 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 81 | static bool ValidateExtensionId(int value) { |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 82 | if (value > 0 && value <= 255) // Value is ok. |
| 83 | return true; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 84 | printf("Extension ID must be between 1 and 255, not %d\n", |
| 85 | static_cast<int>(value)); |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 86 | return false; |
| 87 | } |
| 88 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 89 | // Define command line flags. |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 90 | DEFINE_int(pcmu, 0, "RTP payload type for PCM-u"); |
| 91 | DEFINE_int(pcma, 8, "RTP payload type for PCM-a"); |
| 92 | DEFINE_int(ilbc, 102, "RTP payload type for iLBC"); |
| 93 | DEFINE_int(isac, 103, "RTP payload type for iSAC"); |
| 94 | DEFINE_int(isac_swb, 104, "RTP payload type for iSAC-swb (32 kHz)"); |
| 95 | DEFINE_int(opus, 111, "RTP payload type for Opus"); |
| 96 | DEFINE_int(pcm16b, 93, "RTP payload type for PCM16b-nb (8 kHz)"); |
| 97 | DEFINE_int(pcm16b_wb, 94, "RTP payload type for PCM16b-wb (16 kHz)"); |
| 98 | DEFINE_int(pcm16b_swb32, 95, "RTP payload type for PCM16b-swb32 (32 kHz)"); |
| 99 | DEFINE_int(pcm16b_swb48, 96, "RTP payload type for PCM16b-swb48 (48 kHz)"); |
| 100 | DEFINE_int(g722, 9, "RTP payload type for G.722"); |
| 101 | DEFINE_int(avt, 106, "RTP payload type for AVT/DTMF (8 kHz)"); |
| 102 | DEFINE_int(avt_16, 114, "RTP payload type for AVT/DTMF (16 kHz)"); |
| 103 | DEFINE_int(avt_32, 115, "RTP payload type for AVT/DTMF (32 kHz)"); |
| 104 | DEFINE_int(avt_48, 116, "RTP payload type for AVT/DTMF (48 kHz)"); |
| 105 | DEFINE_int(red, 117, "RTP payload type for redundant audio (RED)"); |
| 106 | DEFINE_int(cn_nb, 13, "RTP payload type for comfort noise (8 kHz)"); |
| 107 | DEFINE_int(cn_wb, 98, "RTP payload type for comfort noise (16 kHz)"); |
| 108 | DEFINE_int(cn_swb32, 99, "RTP payload type for comfort noise (32 kHz)"); |
| 109 | DEFINE_int(cn_swb48, 100, "RTP payload type for comfort noise (48 kHz)"); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 110 | DEFINE_bool(codec_map, |
| 111 | false, |
| 112 | "Prints the mapping between RTP payload type and " |
| 113 | "codec"); |
| 114 | DEFINE_string(replacement_audio_file, |
| 115 | "", |
| 116 | "A PCM file that will be used to populate " |
| 117 | "dummy" |
| 118 | " RTP packets"); |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 119 | DEFINE_string(ssrc, |
| 120 | "", |
| 121 | "Only use packets with this SSRC (decimal or hex, the latter " |
| 122 | "starting with 0x)"); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 123 | DEFINE_int(audio_level, 1, "Extension ID for audio level (RFC 6464)"); |
| 124 | DEFINE_int(abs_send_time, 3, "Extension ID for absolute sender time"); |
| 125 | DEFINE_int(transport_seq_no, 5, "Extension ID for transport sequence number"); |
Henrik Lundin | 4e268ed | 2018-05-08 16:36:33 +0200 | [diff] [blame] | 126 | DEFINE_int(video_content_type, 7, "Extension ID for video content type"); |
| 127 | DEFINE_int(video_timing, 8, "Extension ID for video timing"); |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 128 | DEFINE_bool(matlabplot, |
| 129 | false, |
| 130 | "Generates a matlab script for plotting the delay profile"); |
Ivo Creusen | d1d8dfb | 2017-12-06 10:48:10 +0100 | [diff] [blame] | 131 | DEFINE_bool(pythonplot, |
| 132 | false, |
| 133 | "Generates a python script for plotting the delay profile"); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 134 | DEFINE_bool(help, false, "Prints this message"); |
Alex Narest | 7ff6ca5 | 2018-02-07 18:46:33 +0100 | [diff] [blame] | 135 | DEFINE_bool(concealment_events, false, "Prints concealment events"); |
Ivo Creusen | 80006b9 | 2018-08-10 11:19:21 +0200 | [diff] [blame] | 136 | DEFINE_string( |
| 137 | force_fieldtrials, |
| 138 | "", |
| 139 | "Field trials control experimental feature code which can be forced. " |
| 140 | "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/" |
| 141 | " will assign the group Enable to field trial WebRTC-FooFeature."); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 142 | |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 143 | // Maps a codec type to a printable name string. |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 144 | std::string CodecName(NetEqDecoder codec) { |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 145 | switch (codec) { |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 146 | case NetEqDecoder::kDecoderPCMu: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 147 | return "PCM-u"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 148 | case NetEqDecoder::kDecoderPCMa: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 149 | return "PCM-a"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 150 | case NetEqDecoder::kDecoderILBC: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 151 | return "iLBC"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 152 | case NetEqDecoder::kDecoderISAC: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 153 | return "iSAC"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 154 | case NetEqDecoder::kDecoderISACswb: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 155 | return "iSAC-swb (32 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 156 | case NetEqDecoder::kDecoderOpus: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 157 | return "Opus"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 158 | case NetEqDecoder::kDecoderPCM16B: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 159 | return "PCM16b-nb (8 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 160 | case NetEqDecoder::kDecoderPCM16Bwb: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 161 | return "PCM16b-wb (16 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 162 | case NetEqDecoder::kDecoderPCM16Bswb32kHz: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 163 | return "PCM16b-swb32 (32 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 164 | case NetEqDecoder::kDecoderPCM16Bswb48kHz: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 165 | return "PCM16b-swb48 (48 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 166 | case NetEqDecoder::kDecoderG722: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 167 | return "G.722"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 168 | case NetEqDecoder::kDecoderRED: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 169 | return "redundant audio (RED)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 170 | case NetEqDecoder::kDecoderAVT: |
solenberg | 2779bab | 2016-11-17 04:45:19 -0800 | [diff] [blame] | 171 | return "AVT/DTMF (8 kHz)"; |
| 172 | case NetEqDecoder::kDecoderAVT16kHz: |
| 173 | return "AVT/DTMF (16 kHz)"; |
| 174 | case NetEqDecoder::kDecoderAVT32kHz: |
| 175 | return "AVT/DTMF (32 kHz)"; |
| 176 | case NetEqDecoder::kDecoderAVT48kHz: |
| 177 | return "AVT/DTMF (48 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 178 | case NetEqDecoder::kDecoderCNGnb: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 179 | return "comfort noise (8 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 180 | case NetEqDecoder::kDecoderCNGwb: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 181 | return "comfort noise (16 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 182 | case NetEqDecoder::kDecoderCNGswb32kHz: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 183 | return "comfort noise (32 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 184 | case NetEqDecoder::kDecoderCNGswb48kHz: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 185 | return "comfort noise (48 kHz)"; |
| 186 | default: |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 187 | FATAL(); |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 188 | return "undefined"; |
| 189 | } |
| 190 | } |
| 191 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 192 | void PrintCodecMappingEntry(NetEqDecoder codec, int flag) { |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 193 | std::cout << CodecName(codec) << ": " << flag << std::endl; |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | void PrintCodecMapping() { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 197 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMu, FLAG_pcmu); |
| 198 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMa, FLAG_pcma); |
| 199 | PrintCodecMappingEntry(NetEqDecoder::kDecoderILBC, FLAG_ilbc); |
| 200 | PrintCodecMappingEntry(NetEqDecoder::kDecoderISAC, FLAG_isac); |
| 201 | PrintCodecMappingEntry(NetEqDecoder::kDecoderISACswb, FLAG_isac_swb); |
| 202 | PrintCodecMappingEntry(NetEqDecoder::kDecoderOpus, FLAG_opus); |
| 203 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16B, FLAG_pcm16b); |
| 204 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bwb, FLAG_pcm16b_wb); |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 205 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb32kHz, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 206 | FLAG_pcm16b_swb32); |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 207 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb48kHz, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 208 | FLAG_pcm16b_swb48); |
| 209 | PrintCodecMappingEntry(NetEqDecoder::kDecoderG722, FLAG_g722); |
| 210 | PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT, FLAG_avt); |
| 211 | PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT16kHz, FLAG_avt_16); |
| 212 | PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT32kHz, FLAG_avt_32); |
| 213 | PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT48kHz, FLAG_avt_48); |
| 214 | PrintCodecMappingEntry(NetEqDecoder::kDecoderRED, FLAG_red); |
| 215 | PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGnb, FLAG_cn_nb); |
| 216 | PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGwb, FLAG_cn_wb); |
| 217 | PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb32kHz, FLAG_cn_swb32); |
| 218 | PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb48kHz, FLAG_cn_swb48); |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 221 | absl::optional<int> CodecSampleRate(uint8_t payload_type) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 222 | if (payload_type == FLAG_pcmu || payload_type == FLAG_pcma || |
| 223 | payload_type == FLAG_ilbc || payload_type == FLAG_pcm16b || |
| 224 | payload_type == FLAG_cn_nb || payload_type == FLAG_avt) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 225 | return 8000; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 226 | if (payload_type == FLAG_isac || payload_type == FLAG_pcm16b_wb || |
| 227 | payload_type == FLAG_g722 || payload_type == FLAG_cn_wb || |
| 228 | payload_type == FLAG_avt_16) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 229 | return 16000; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 230 | if (payload_type == FLAG_isac_swb || payload_type == FLAG_pcm16b_swb32 || |
| 231 | payload_type == FLAG_cn_swb32 || payload_type == FLAG_avt_32) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 232 | return 32000; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 233 | if (payload_type == FLAG_opus || payload_type == FLAG_pcm16b_swb48 || |
| 234 | payload_type == FLAG_cn_swb48 || payload_type == FLAG_avt_48) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 235 | return 48000; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 236 | if (payload_type == FLAG_red) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 237 | return 0; |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 238 | return absl::nullopt; |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 241 | // A callback class which prints whenver the inserted packet stream changes |
| 242 | // the SSRC. |
| 243 | class SsrcSwitchDetector : public NetEqPostInsertPacket { |
| 244 | public: |
| 245 | // Takes a pointer to another callback object, which will be invoked after |
| 246 | // this object finishes. This does not transfer ownership, and null is a |
| 247 | // valid value. |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 248 | explicit SsrcSwitchDetector(NetEqPostInsertPacket* other_callback) |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 249 | : other_callback_(other_callback) {} |
| 250 | |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 251 | void AfterInsertPacket(const NetEqInput::PacketData& packet, |
| 252 | NetEq* neteq) override { |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 253 | if (last_ssrc_ && packet.header.ssrc != *last_ssrc_) { |
| 254 | std::cout << "Changing streams from 0x" << std::hex << *last_ssrc_ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 255 | << " to 0x" << std::hex << packet.header.ssrc << std::dec |
| 256 | << " (payload type " |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 257 | << static_cast<int>(packet.header.payloadType) << ")" |
| 258 | << std::endl; |
| 259 | } |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 260 | last_ssrc_ = packet.header.ssrc; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 261 | if (other_callback_) { |
| 262 | other_callback_->AfterInsertPacket(packet, neteq); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | private: |
| 267 | NetEqPostInsertPacket* other_callback_; |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 268 | absl::optional<uint32_t> last_ssrc_; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 269 | }; |
| 270 | |
henrik.lundin | 303d3e1 | 2016-05-26 05:56:03 -0700 | [diff] [blame] | 271 | int RunTest(int argc, char* argv[]) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 272 | std::string program_name = argv[0]; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 273 | std::string usage = |
| 274 | "Tool for decoding an RTP dump file using NetEq.\n" |
| 275 | "Run " + |
| 276 | program_name + |
| 277 | " --help for usage.\n" |
| 278 | "Example usage:\n" + |
| 279 | program_name + " input.rtp output.{pcm, wav}\n"; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 280 | if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) { |
| 281 | return 1; |
| 282 | } |
| 283 | if (FLAG_help) { |
| 284 | std::cout << usage; |
| 285 | rtc::FlagList::Print(nullptr, false); |
| 286 | return 0; |
| 287 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 288 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 289 | if (FLAG_codec_map) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 290 | PrintCodecMapping(); |
| 291 | } |
| 292 | |
| 293 | if (argc != 3) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 294 | if (FLAG_codec_map) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 295 | // We have already printed the codec map. Just end the program. |
| 296 | return 0; |
| 297 | } |
| 298 | // Print usage information. |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 299 | std::cout << usage; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 300 | return 0; |
| 301 | } |
Ivo Creusen | 80006b9 | 2018-08-10 11:19:21 +0200 | [diff] [blame] | 302 | |
| 303 | ValidateFieldTrialsStringOrDie(FLAG_force_fieldtrials); |
| 304 | ScopedFieldTrials field_trials(FLAG_force_fieldtrials); |
| 305 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 306 | RTC_CHECK(ValidatePayloadType(FLAG_pcmu)); |
| 307 | RTC_CHECK(ValidatePayloadType(FLAG_pcma)); |
| 308 | RTC_CHECK(ValidatePayloadType(FLAG_ilbc)); |
| 309 | RTC_CHECK(ValidatePayloadType(FLAG_isac)); |
| 310 | RTC_CHECK(ValidatePayloadType(FLAG_isac_swb)); |
| 311 | RTC_CHECK(ValidatePayloadType(FLAG_opus)); |
| 312 | RTC_CHECK(ValidatePayloadType(FLAG_pcm16b)); |
| 313 | RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_wb)); |
| 314 | RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb32)); |
| 315 | RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb48)); |
| 316 | RTC_CHECK(ValidatePayloadType(FLAG_g722)); |
| 317 | RTC_CHECK(ValidatePayloadType(FLAG_avt)); |
| 318 | RTC_CHECK(ValidatePayloadType(FLAG_avt_16)); |
| 319 | RTC_CHECK(ValidatePayloadType(FLAG_avt_32)); |
| 320 | RTC_CHECK(ValidatePayloadType(FLAG_avt_48)); |
| 321 | RTC_CHECK(ValidatePayloadType(FLAG_red)); |
| 322 | RTC_CHECK(ValidatePayloadType(FLAG_cn_nb)); |
| 323 | RTC_CHECK(ValidatePayloadType(FLAG_cn_wb)); |
| 324 | RTC_CHECK(ValidatePayloadType(FLAG_cn_swb32)); |
| 325 | RTC_CHECK(ValidatePayloadType(FLAG_cn_swb48)); |
| 326 | RTC_CHECK(ValidateSsrcValue(FLAG_ssrc)); |
| 327 | RTC_CHECK(ValidateExtensionId(FLAG_audio_level)); |
| 328 | RTC_CHECK(ValidateExtensionId(FLAG_abs_send_time)); |
| 329 | RTC_CHECK(ValidateExtensionId(FLAG_transport_seq_no)); |
Henrik Lundin | 4e268ed | 2018-05-08 16:36:33 +0200 | [diff] [blame] | 330 | RTC_CHECK(ValidateExtensionId(FLAG_video_content_type)); |
| 331 | RTC_CHECK(ValidateExtensionId(FLAG_video_timing)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 332 | |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 333 | // Gather RTP header extensions in a map. |
| 334 | NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 335 | {FLAG_audio_level, kRtpExtensionAudioLevel}, |
| 336 | {FLAG_abs_send_time, kRtpExtensionAbsoluteSendTime}, |
Henrik Lundin | 4e268ed | 2018-05-08 16:36:33 +0200 | [diff] [blame] | 337 | {FLAG_transport_seq_no, kRtpExtensionTransportSequenceNumber}, |
| 338 | {FLAG_video_content_type, kRtpExtensionVideoContentType}, |
| 339 | {FLAG_video_timing, kRtpExtensionVideoTiming}}; |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 340 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 341 | const std::string input_file_name = argv[1]; |
| 342 | std::unique_ptr<NetEqInput> input; |
| 343 | if (RtpFileSource::ValidRtpDump(input_file_name) || |
| 344 | RtpFileSource::ValidPcap(input_file_name)) { |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 345 | input.reset(new NetEqRtpDumpInput(input_file_name, rtp_ext_map)); |
ivoc | caa5f4b | 2015-09-08 03:28:46 -0700 | [diff] [blame] | 346 | } else { |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 347 | input.reset(new NetEqEventLogInput(input_file_name, rtp_ext_map)); |
ivoc | caa5f4b | 2015-09-08 03:28:46 -0700 | [diff] [blame] | 348 | } |
| 349 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 350 | std::cout << "Input file: " << input_file_name << std::endl; |
| 351 | RTC_CHECK(input) << "Cannot open input file"; |
| 352 | RTC_CHECK(!input->ended()) << "Input file is empty"; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 353 | |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 354 | // Check if an SSRC value was provided. |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 355 | if (strlen(FLAG_ssrc) > 0) { |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 356 | uint32_t ssrc; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 357 | RTC_CHECK(ParseSsrc(FLAG_ssrc, &ssrc)) << "Flag verification has failed."; |
Minyue Li | b563f3d | 2018-05-11 16:49:38 +0200 | [diff] [blame] | 358 | static_cast<NetEqPacketSourceInput*>(input.get())->SelectSsrc(ssrc); |
ivoc | caa5f4b | 2015-09-08 03:28:46 -0700 | [diff] [blame] | 359 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 360 | |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 361 | // Check the sample rate. |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 362 | absl::optional<int> sample_rate_hz; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 363 | std::set<std::pair<int, uint32_t>> discarded_pt_and_ssrc; |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 364 | while (absl::optional<RTPHeader> first_rtp_header = input->NextHeader()) { |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 365 | RTC_DCHECK(first_rtp_header); |
| 366 | sample_rate_hz = CodecSampleRate(first_rtp_header->payloadType); |
| 367 | if (sample_rate_hz) { |
| 368 | std::cout << "Found valid packet with payload type " |
| 369 | << static_cast<int>(first_rtp_header->payloadType) |
| 370 | << " and SSRC 0x" << std::hex << first_rtp_header->ssrc |
| 371 | << std::dec << std::endl; |
| 372 | break; |
| 373 | } |
| 374 | // Discard this packet and move to the next. Keep track of discarded payload |
| 375 | // types and SSRCs. |
| 376 | discarded_pt_and_ssrc.emplace(first_rtp_header->payloadType, |
| 377 | first_rtp_header->ssrc); |
| 378 | input->PopPacket(); |
| 379 | } |
| 380 | if (!discarded_pt_and_ssrc.empty()) { |
| 381 | std::cout << "Discarded initial packets with the following payload types " |
| 382 | "and SSRCs:" |
| 383 | << std::endl; |
| 384 | for (const auto& d : discarded_pt_and_ssrc) { |
| 385 | std::cout << "PT " << d.first << "; SSRC 0x" << std::hex |
| 386 | << static_cast<int>(d.second) << std::dec << std::endl; |
| 387 | } |
| 388 | } |
| 389 | if (!sample_rate_hz) { |
| 390 | std::cout << "Cannot find any packets with known payload types" |
| 391 | << std::endl; |
| 392 | RTC_NOTREACHED(); |
| 393 | } |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 394 | |
| 395 | // Open the output file now that we know the sample rate. (Rate is only needed |
| 396 | // for wav files.) |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 397 | const std::string output_file_name = argv[2]; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 398 | std::unique_ptr<AudioSink> output; |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 399 | if (output_file_name.size() >= 4 && |
| 400 | output_file_name.substr(output_file_name.size() - 4) == ".wav") { |
| 401 | // Open a wav file. |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 402 | output.reset(new OutputWavFile(output_file_name, *sample_rate_hz)); |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 403 | } else { |
| 404 | // Open a pcm file. |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 405 | output.reset(new OutputAudioFile(output_file_name)); |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 406 | } |
| 407 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 408 | std::cout << "Output file: " << output_file_name << std::endl; |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 409 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 410 | NetEqTest::DecoderMap codecs = { |
Ivo Creusen | 80006b9 | 2018-08-10 11:19:21 +0200 | [diff] [blame] | 411 | {FLAG_pcmu, std::make_pair(NetEqDecoder::kDecoderPCMu, "pcmu")}, |
| 412 | {FLAG_pcma, std::make_pair(NetEqDecoder::kDecoderPCMa, "pcma")}, |
| 413 | #ifdef WEBRTC_CODEC_ILBC |
| 414 | {FLAG_ilbc, std::make_pair(NetEqDecoder::kDecoderILBC, "ilbc")}, |
| 415 | #endif |
| 416 | {FLAG_isac, std::make_pair(NetEqDecoder::kDecoderISAC, "isac")}, |
| 417 | #if !defined(WEBRTC_ANDROID) |
| 418 | {FLAG_isac_swb, std::make_pair(NetEqDecoder::kDecoderISACswb, "isac-swb")}, |
| 419 | #endif |
| 420 | #ifdef WEBRTC_CODEC_OPUS |
| 421 | {FLAG_opus, std::make_pair(NetEqDecoder::kDecoderOpus, "opus")}, |
| 422 | #endif |
| 423 | {FLAG_pcm16b, std::make_pair(NetEqDecoder::kDecoderPCM16B, "pcm16-nb")}, |
| 424 | {FLAG_pcm16b_wb, |
| 425 | std::make_pair(NetEqDecoder::kDecoderPCM16Bwb, "pcm16-wb")}, |
| 426 | {FLAG_pcm16b_swb32, |
| 427 | std::make_pair(NetEqDecoder::kDecoderPCM16Bswb32kHz, "pcm16-swb32")}, |
| 428 | {FLAG_pcm16b_swb48, |
| 429 | std::make_pair(NetEqDecoder::kDecoderPCM16Bswb48kHz, "pcm16-swb48")}, |
| 430 | {FLAG_g722, std::make_pair(NetEqDecoder::kDecoderG722, "g722")}, |
| 431 | {FLAG_avt, std::make_pair(NetEqDecoder::kDecoderAVT, "avt")}, |
| 432 | {FLAG_avt_16, std::make_pair(NetEqDecoder::kDecoderAVT16kHz, "avt-16")}, |
| 433 | {FLAG_avt_32, std::make_pair(NetEqDecoder::kDecoderAVT32kHz, "avt-32")}, |
| 434 | {FLAG_avt_48, std::make_pair(NetEqDecoder::kDecoderAVT48kHz, "avt-48")}, |
| 435 | {FLAG_red, std::make_pair(NetEqDecoder::kDecoderRED, "red")}, |
| 436 | {FLAG_cn_nb, std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb")}, |
| 437 | {FLAG_cn_wb, std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb")}, |
| 438 | {FLAG_cn_swb32, |
| 439 | std::make_pair(NetEqDecoder::kDecoderCNGswb32kHz, "cng-swb32")}, |
| 440 | {FLAG_cn_swb48, |
| 441 | std::make_pair(NetEqDecoder::kDecoderCNGswb48kHz, "cng-swb48")} |
| 442 | }; |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 443 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 444 | // Check if a replacement audio file was provided. |
| 445 | std::unique_ptr<AudioDecoder> replacement_decoder; |
| 446 | NetEqTest::ExtDecoderMap ext_codecs; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 447 | if (strlen(FLAG_replacement_audio_file) > 0) { |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 448 | // Find largest unused payload type. |
| 449 | int replacement_pt = 127; |
| 450 | while (!(codecs.find(replacement_pt) == codecs.end() && |
| 451 | ext_codecs.find(replacement_pt) == ext_codecs.end())) { |
| 452 | --replacement_pt; |
| 453 | RTC_CHECK_GE(replacement_pt, 0); |
| 454 | } |
| 455 | |
| 456 | auto std_set_int32_to_uint8 = [](const std::set<int32_t>& a) { |
| 457 | std::set<uint8_t> b; |
| 458 | for (auto& x : a) { |
| 459 | b.insert(static_cast<uint8_t>(x)); |
| 460 | } |
| 461 | return b; |
| 462 | }; |
| 463 | |
| 464 | std::set<uint8_t> cn_types = std_set_int32_to_uint8( |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 465 | {FLAG_cn_nb, FLAG_cn_wb, FLAG_cn_swb32, FLAG_cn_swb48}); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 466 | std::set<uint8_t> forbidden_types = std_set_int32_to_uint8( |
| 467 | {FLAG_g722, FLAG_red, FLAG_avt, FLAG_avt_16, FLAG_avt_32, FLAG_avt_48}); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 468 | input.reset(new NetEqReplacementInput(std::move(input), replacement_pt, |
| 469 | cn_types, forbidden_types)); |
| 470 | |
| 471 | replacement_decoder.reset(new FakeDecodeFromFile( |
| 472 | std::unique_ptr<InputAudioFile>( |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 473 | new InputAudioFile(FLAG_replacement_audio_file)), |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 474 | 48000, false)); |
| 475 | NetEqTest::ExternalDecoderInfo ext_dec_info = { |
| 476 | replacement_decoder.get(), NetEqDecoder::kDecoderArbitrary, |
| 477 | "replacement codec"}; |
| 478 | ext_codecs[replacement_pt] = ext_dec_info; |
| 479 | } |
| 480 | |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 481 | NetEqTest::Callbacks callbacks; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 482 | std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer; |
Ivo Creusen | d1d8dfb | 2017-12-06 10:48:10 +0100 | [diff] [blame] | 483 | if (FLAG_matlabplot || FLAG_pythonplot) { |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 484 | delay_analyzer.reset(new NetEqDelayAnalyzer); |
| 485 | } |
| 486 | |
| 487 | SsrcSwitchDetector ssrc_switch_detector(delay_analyzer.get()); |
| 488 | callbacks.post_insert_packet = &ssrc_switch_detector; |
Minyue Li | 2b415da | 2018-04-16 14:33:53 +0200 | [diff] [blame] | 489 | NetEqStatsGetter stats_getter(std::move(delay_analyzer)); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 490 | callbacks.get_audio_callback = &stats_getter; |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 491 | NetEq::Config config; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 492 | config.sample_rate_hz = *sample_rate_hz; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 493 | NetEqTest test(config, codecs, ext_codecs, std::move(input), |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 494 | std::move(output), callbacks); |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 495 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 496 | int64_t test_duration_ms = test.Run(); |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 497 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 498 | if (FLAG_matlabplot) { |
henrik.lundin | f09c904 | 2017-08-29 09:14:08 -0700 | [diff] [blame] | 499 | auto matlab_script_name = output_file_name; |
| 500 | std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.', |
| 501 | '_'); |
| 502 | std::cout << "Creating Matlab plot script " << matlab_script_name + ".m" |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 503 | << std::endl; |
Minyue Li | 5ebb416 | 2018-05-08 22:42:00 +0200 | [diff] [blame] | 504 | stats_getter.delay_analyzer()->CreateMatlabScript(matlab_script_name + |
| 505 | ".m"); |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 506 | } |
Ivo Creusen | d1d8dfb | 2017-12-06 10:48:10 +0100 | [diff] [blame] | 507 | if (FLAG_pythonplot) { |
| 508 | auto python_script_name = output_file_name; |
| 509 | std::replace(python_script_name.begin(), python_script_name.end(), '.', |
| 510 | '_'); |
| 511 | std::cout << "Creating Python plot script " << python_script_name + ".py" |
| 512 | << std::endl; |
Minyue Li | 5ebb416 | 2018-05-08 22:42:00 +0200 | [diff] [blame] | 513 | stats_getter.delay_analyzer()->CreatePythonScript(python_script_name + |
| 514 | ".py"); |
Ivo Creusen | d1d8dfb | 2017-12-06 10:48:10 +0100 | [diff] [blame] | 515 | } |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 516 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 517 | printf("Simulation statistics:\n"); |
| 518 | printf(" output duration: %" PRId64 " ms\n", test_duration_ms); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 519 | auto stats = stats_getter.AverageStats(); |
| 520 | printf(" packet_loss_rate: %f %%\n", 100.0 * stats.packet_loss_rate); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 521 | printf(" expand_rate: %f %%\n", 100.0 * stats.expand_rate); |
| 522 | printf(" speech_expand_rate: %f %%\n", 100.0 * stats.speech_expand_rate); |
| 523 | printf(" preemptive_rate: %f %%\n", 100.0 * stats.preemptive_rate); |
| 524 | printf(" accelerate_rate: %f %%\n", 100.0 * stats.accelerate_rate); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 525 | printf(" secondary_decoded_rate: %f %%\n", |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 526 | 100.0 * stats.secondary_decoded_rate); |
minyue-webrtc | 0c3ca75 | 2017-08-23 15:59:38 +0200 | [diff] [blame] | 527 | printf(" secondary_discarded_rate: %f %%\n", |
| 528 | 100.0 * stats.secondary_discarded_rate); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 529 | printf(" clockdrift_ppm: %f ppm\n", stats.clockdrift_ppm); |
| 530 | printf(" mean_waiting_time_ms: %f ms\n", stats.mean_waiting_time_ms); |
| 531 | printf(" median_waiting_time_ms: %f ms\n", stats.median_waiting_time_ms); |
| 532 | printf(" min_waiting_time_ms: %f ms\n", stats.min_waiting_time_ms); |
| 533 | printf(" max_waiting_time_ms: %f ms\n", stats.max_waiting_time_ms); |
Henrik Lundin | 156af4a | 2017-11-17 16:46:18 +0100 | [diff] [blame] | 534 | printf(" current_buffer_size_ms: %f ms\n", stats.current_buffer_size_ms); |
| 535 | printf(" preferred_buffer_size_ms: %f ms\n", stats.preferred_buffer_size_ms); |
Alex Narest | 7ff6ca5 | 2018-02-07 18:46:33 +0100 | [diff] [blame] | 536 | if (FLAG_concealment_events) { |
Minyue Li | 2b415da | 2018-04-16 14:33:53 +0200 | [diff] [blame] | 537 | std::cout << " concealment_events_ms:" << std::endl; |
Alex Narest | 7ff6ca5 | 2018-02-07 18:46:33 +0100 | [diff] [blame] | 538 | for (auto concealment_event : stats_getter.concealment_events()) |
Minyue Li | 2b415da | 2018-04-16 14:33:53 +0200 | [diff] [blame] | 539 | std::cout << concealment_event.ToString() << std::endl; |
| 540 | std::cout << " end of concealment_events_ms" << std::endl; |
Alex Narest | 7ff6ca5 | 2018-02-07 18:46:33 +0100 | [diff] [blame] | 541 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 542 | return 0; |
| 543 | } |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 544 | |
henrik.lundin | 303d3e1 | 2016-05-26 05:56:03 -0700 | [diff] [blame] | 545 | } // namespace |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 546 | } // namespace test |
| 547 | } // namespace webrtc |
henrik.lundin | 303d3e1 | 2016-05-26 05:56:03 -0700 | [diff] [blame] | 548 | |
| 549 | int main(int argc, char* argv[]) { |
Robin Raymond | 1c62ffa | 2017-12-03 16:45:56 -0500 | [diff] [blame] | 550 | return webrtc::test::RunTest(argc, argv); |
henrik.lundin | 303d3e1 | 2016-05-26 05:56:03 -0700 | [diff] [blame] | 551 | } |