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" |
| 34 | #include "test/testsupport/fileutils.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 35 | #include "typedefs.h" // NOLINT(build/include) |
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"); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 136 | |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 137 | // Maps a codec type to a printable name string. |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 138 | std::string CodecName(NetEqDecoder codec) { |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 139 | switch (codec) { |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 140 | case NetEqDecoder::kDecoderPCMu: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 141 | return "PCM-u"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 142 | case NetEqDecoder::kDecoderPCMa: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 143 | return "PCM-a"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 144 | case NetEqDecoder::kDecoderILBC: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 145 | return "iLBC"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 146 | case NetEqDecoder::kDecoderISAC: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 147 | return "iSAC"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 148 | case NetEqDecoder::kDecoderISACswb: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 149 | return "iSAC-swb (32 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 150 | case NetEqDecoder::kDecoderOpus: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 151 | return "Opus"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 152 | case NetEqDecoder::kDecoderPCM16B: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 153 | return "PCM16b-nb (8 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 154 | case NetEqDecoder::kDecoderPCM16Bwb: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 155 | return "PCM16b-wb (16 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 156 | case NetEqDecoder::kDecoderPCM16Bswb32kHz: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 157 | return "PCM16b-swb32 (32 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 158 | case NetEqDecoder::kDecoderPCM16Bswb48kHz: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 159 | return "PCM16b-swb48 (48 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 160 | case NetEqDecoder::kDecoderG722: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 161 | return "G.722"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 162 | case NetEqDecoder::kDecoderRED: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 163 | return "redundant audio (RED)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 164 | case NetEqDecoder::kDecoderAVT: |
solenberg | 2779bab | 2016-11-17 04:45:19 -0800 | [diff] [blame] | 165 | return "AVT/DTMF (8 kHz)"; |
| 166 | case NetEqDecoder::kDecoderAVT16kHz: |
| 167 | return "AVT/DTMF (16 kHz)"; |
| 168 | case NetEqDecoder::kDecoderAVT32kHz: |
| 169 | return "AVT/DTMF (32 kHz)"; |
| 170 | case NetEqDecoder::kDecoderAVT48kHz: |
| 171 | return "AVT/DTMF (48 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 172 | case NetEqDecoder::kDecoderCNGnb: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 173 | return "comfort noise (8 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 174 | case NetEqDecoder::kDecoderCNGwb: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 175 | return "comfort noise (16 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 176 | case NetEqDecoder::kDecoderCNGswb32kHz: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 177 | return "comfort noise (32 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 178 | case NetEqDecoder::kDecoderCNGswb48kHz: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 179 | return "comfort noise (48 kHz)"; |
| 180 | default: |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 181 | FATAL(); |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 182 | return "undefined"; |
| 183 | } |
| 184 | } |
| 185 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 186 | void PrintCodecMappingEntry(NetEqDecoder codec, int flag) { |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 187 | std::cout << CodecName(codec) << ": " << flag << std::endl; |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void PrintCodecMapping() { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 191 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMu, FLAG_pcmu); |
| 192 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMa, FLAG_pcma); |
| 193 | PrintCodecMappingEntry(NetEqDecoder::kDecoderILBC, FLAG_ilbc); |
| 194 | PrintCodecMappingEntry(NetEqDecoder::kDecoderISAC, FLAG_isac); |
| 195 | PrintCodecMappingEntry(NetEqDecoder::kDecoderISACswb, FLAG_isac_swb); |
| 196 | PrintCodecMappingEntry(NetEqDecoder::kDecoderOpus, FLAG_opus); |
| 197 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16B, FLAG_pcm16b); |
| 198 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bwb, FLAG_pcm16b_wb); |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 199 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb32kHz, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 200 | FLAG_pcm16b_swb32); |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 201 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb48kHz, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 202 | FLAG_pcm16b_swb48); |
| 203 | PrintCodecMappingEntry(NetEqDecoder::kDecoderG722, FLAG_g722); |
| 204 | PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT, FLAG_avt); |
| 205 | PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT16kHz, FLAG_avt_16); |
| 206 | PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT32kHz, FLAG_avt_32); |
| 207 | PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT48kHz, FLAG_avt_48); |
| 208 | PrintCodecMappingEntry(NetEqDecoder::kDecoderRED, FLAG_red); |
| 209 | PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGnb, FLAG_cn_nb); |
| 210 | PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGwb, FLAG_cn_wb); |
| 211 | PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb32kHz, FLAG_cn_swb32); |
| 212 | PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb48kHz, FLAG_cn_swb48); |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 215 | absl::optional<int> CodecSampleRate(uint8_t payload_type) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 216 | if (payload_type == FLAG_pcmu || payload_type == FLAG_pcma || |
| 217 | payload_type == FLAG_ilbc || payload_type == FLAG_pcm16b || |
| 218 | payload_type == FLAG_cn_nb || payload_type == FLAG_avt) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 219 | return 8000; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 220 | if (payload_type == FLAG_isac || payload_type == FLAG_pcm16b_wb || |
| 221 | payload_type == FLAG_g722 || payload_type == FLAG_cn_wb || |
| 222 | payload_type == FLAG_avt_16) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 223 | return 16000; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 224 | if (payload_type == FLAG_isac_swb || payload_type == FLAG_pcm16b_swb32 || |
| 225 | payload_type == FLAG_cn_swb32 || payload_type == FLAG_avt_32) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 226 | return 32000; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 227 | if (payload_type == FLAG_opus || payload_type == FLAG_pcm16b_swb48 || |
| 228 | payload_type == FLAG_cn_swb48 || payload_type == FLAG_avt_48) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 229 | return 48000; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 230 | if (payload_type == FLAG_red) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 231 | return 0; |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 232 | return absl::nullopt; |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 235 | // A callback class which prints whenver the inserted packet stream changes |
| 236 | // the SSRC. |
| 237 | class SsrcSwitchDetector : public NetEqPostInsertPacket { |
| 238 | public: |
| 239 | // Takes a pointer to another callback object, which will be invoked after |
| 240 | // this object finishes. This does not transfer ownership, and null is a |
| 241 | // valid value. |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 242 | explicit SsrcSwitchDetector(NetEqPostInsertPacket* other_callback) |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 243 | : other_callback_(other_callback) {} |
| 244 | |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 245 | void AfterInsertPacket(const NetEqInput::PacketData& packet, |
| 246 | NetEq* neteq) override { |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 247 | if (last_ssrc_ && packet.header.ssrc != *last_ssrc_) { |
| 248 | std::cout << "Changing streams from 0x" << std::hex << *last_ssrc_ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 249 | << " to 0x" << std::hex << packet.header.ssrc << std::dec |
| 250 | << " (payload type " |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 251 | << static_cast<int>(packet.header.payloadType) << ")" |
| 252 | << std::endl; |
| 253 | } |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 254 | last_ssrc_ = packet.header.ssrc; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 255 | if (other_callback_) { |
| 256 | other_callback_->AfterInsertPacket(packet, neteq); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | private: |
| 261 | NetEqPostInsertPacket* other_callback_; |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 262 | absl::optional<uint32_t> last_ssrc_; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 263 | }; |
| 264 | |
henrik.lundin | 303d3e1 | 2016-05-26 05:56:03 -0700 | [diff] [blame] | 265 | int RunTest(int argc, char* argv[]) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 266 | std::string program_name = argv[0]; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 267 | std::string usage = |
| 268 | "Tool for decoding an RTP dump file using NetEq.\n" |
| 269 | "Run " + |
| 270 | program_name + |
| 271 | " --help for usage.\n" |
| 272 | "Example usage:\n" + |
| 273 | program_name + " input.rtp output.{pcm, wav}\n"; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 274 | if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) { |
| 275 | return 1; |
| 276 | } |
| 277 | if (FLAG_help) { |
| 278 | std::cout << usage; |
| 279 | rtc::FlagList::Print(nullptr, false); |
| 280 | return 0; |
| 281 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 282 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 283 | if (FLAG_codec_map) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 284 | PrintCodecMapping(); |
| 285 | } |
| 286 | |
| 287 | if (argc != 3) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 288 | if (FLAG_codec_map) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 289 | // We have already printed the codec map. Just end the program. |
| 290 | return 0; |
| 291 | } |
| 292 | // Print usage information. |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 293 | std::cout << usage; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 294 | return 0; |
| 295 | } |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 296 | RTC_CHECK(ValidatePayloadType(FLAG_pcmu)); |
| 297 | RTC_CHECK(ValidatePayloadType(FLAG_pcma)); |
| 298 | RTC_CHECK(ValidatePayloadType(FLAG_ilbc)); |
| 299 | RTC_CHECK(ValidatePayloadType(FLAG_isac)); |
| 300 | RTC_CHECK(ValidatePayloadType(FLAG_isac_swb)); |
| 301 | RTC_CHECK(ValidatePayloadType(FLAG_opus)); |
| 302 | RTC_CHECK(ValidatePayloadType(FLAG_pcm16b)); |
| 303 | RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_wb)); |
| 304 | RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb32)); |
| 305 | RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb48)); |
| 306 | RTC_CHECK(ValidatePayloadType(FLAG_g722)); |
| 307 | RTC_CHECK(ValidatePayloadType(FLAG_avt)); |
| 308 | RTC_CHECK(ValidatePayloadType(FLAG_avt_16)); |
| 309 | RTC_CHECK(ValidatePayloadType(FLAG_avt_32)); |
| 310 | RTC_CHECK(ValidatePayloadType(FLAG_avt_48)); |
| 311 | RTC_CHECK(ValidatePayloadType(FLAG_red)); |
| 312 | RTC_CHECK(ValidatePayloadType(FLAG_cn_nb)); |
| 313 | RTC_CHECK(ValidatePayloadType(FLAG_cn_wb)); |
| 314 | RTC_CHECK(ValidatePayloadType(FLAG_cn_swb32)); |
| 315 | RTC_CHECK(ValidatePayloadType(FLAG_cn_swb48)); |
| 316 | RTC_CHECK(ValidateSsrcValue(FLAG_ssrc)); |
| 317 | RTC_CHECK(ValidateExtensionId(FLAG_audio_level)); |
| 318 | RTC_CHECK(ValidateExtensionId(FLAG_abs_send_time)); |
| 319 | RTC_CHECK(ValidateExtensionId(FLAG_transport_seq_no)); |
Henrik Lundin | 4e268ed | 2018-05-08 16:36:33 +0200 | [diff] [blame] | 320 | RTC_CHECK(ValidateExtensionId(FLAG_video_content_type)); |
| 321 | RTC_CHECK(ValidateExtensionId(FLAG_video_timing)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 322 | |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 323 | // Gather RTP header extensions in a map. |
| 324 | NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 325 | {FLAG_audio_level, kRtpExtensionAudioLevel}, |
| 326 | {FLAG_abs_send_time, kRtpExtensionAbsoluteSendTime}, |
Henrik Lundin | 4e268ed | 2018-05-08 16:36:33 +0200 | [diff] [blame] | 327 | {FLAG_transport_seq_no, kRtpExtensionTransportSequenceNumber}, |
| 328 | {FLAG_video_content_type, kRtpExtensionVideoContentType}, |
| 329 | {FLAG_video_timing, kRtpExtensionVideoTiming}}; |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 330 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 331 | const std::string input_file_name = argv[1]; |
| 332 | std::unique_ptr<NetEqInput> input; |
| 333 | if (RtpFileSource::ValidRtpDump(input_file_name) || |
| 334 | RtpFileSource::ValidPcap(input_file_name)) { |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 335 | input.reset(new NetEqRtpDumpInput(input_file_name, rtp_ext_map)); |
ivoc | caa5f4b | 2015-09-08 03:28:46 -0700 | [diff] [blame] | 336 | } else { |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 337 | input.reset(new NetEqEventLogInput(input_file_name, rtp_ext_map)); |
ivoc | caa5f4b | 2015-09-08 03:28:46 -0700 | [diff] [blame] | 338 | } |
| 339 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 340 | std::cout << "Input file: " << input_file_name << std::endl; |
| 341 | RTC_CHECK(input) << "Cannot open input file"; |
| 342 | RTC_CHECK(!input->ended()) << "Input file is empty"; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 343 | |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 344 | // Check if an SSRC value was provided. |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 345 | if (strlen(FLAG_ssrc) > 0) { |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 346 | uint32_t ssrc; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 347 | RTC_CHECK(ParseSsrc(FLAG_ssrc, &ssrc)) << "Flag verification has failed."; |
Minyue Li | b563f3d | 2018-05-11 16:49:38 +0200 | [diff] [blame] | 348 | static_cast<NetEqPacketSourceInput*>(input.get())->SelectSsrc(ssrc); |
ivoc | caa5f4b | 2015-09-08 03:28:46 -0700 | [diff] [blame] | 349 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 350 | |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 351 | // Check the sample rate. |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 352 | absl::optional<int> sample_rate_hz; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 353 | std::set<std::pair<int, uint32_t>> discarded_pt_and_ssrc; |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 354 | while (absl::optional<RTPHeader> first_rtp_header = input->NextHeader()) { |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 355 | RTC_DCHECK(first_rtp_header); |
| 356 | sample_rate_hz = CodecSampleRate(first_rtp_header->payloadType); |
| 357 | if (sample_rate_hz) { |
| 358 | std::cout << "Found valid packet with payload type " |
| 359 | << static_cast<int>(first_rtp_header->payloadType) |
| 360 | << " and SSRC 0x" << std::hex << first_rtp_header->ssrc |
| 361 | << std::dec << std::endl; |
| 362 | break; |
| 363 | } |
| 364 | // Discard this packet and move to the next. Keep track of discarded payload |
| 365 | // types and SSRCs. |
| 366 | discarded_pt_and_ssrc.emplace(first_rtp_header->payloadType, |
| 367 | first_rtp_header->ssrc); |
| 368 | input->PopPacket(); |
| 369 | } |
| 370 | if (!discarded_pt_and_ssrc.empty()) { |
| 371 | std::cout << "Discarded initial packets with the following payload types " |
| 372 | "and SSRCs:" |
| 373 | << std::endl; |
| 374 | for (const auto& d : discarded_pt_and_ssrc) { |
| 375 | std::cout << "PT " << d.first << "; SSRC 0x" << std::hex |
| 376 | << static_cast<int>(d.second) << std::dec << std::endl; |
| 377 | } |
| 378 | } |
| 379 | if (!sample_rate_hz) { |
| 380 | std::cout << "Cannot find any packets with known payload types" |
| 381 | << std::endl; |
| 382 | RTC_NOTREACHED(); |
| 383 | } |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 384 | |
| 385 | // Open the output file now that we know the sample rate. (Rate is only needed |
| 386 | // for wav files.) |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 387 | const std::string output_file_name = argv[2]; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 388 | std::unique_ptr<AudioSink> output; |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 389 | if (output_file_name.size() >= 4 && |
| 390 | output_file_name.substr(output_file_name.size() - 4) == ".wav") { |
| 391 | // Open a wav file. |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 392 | output.reset(new OutputWavFile(output_file_name, *sample_rate_hz)); |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 393 | } else { |
| 394 | // Open a pcm file. |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 395 | output.reset(new OutputAudioFile(output_file_name)); |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 396 | } |
| 397 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 398 | std::cout << "Output file: " << output_file_name << std::endl; |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 399 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 400 | NetEqTest::DecoderMap codecs = { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 401 | {FLAG_pcmu, std::make_pair(NetEqDecoder::kDecoderPCMu, "pcmu")}, |
| 402 | {FLAG_pcma, std::make_pair(NetEqDecoder::kDecoderPCMa, "pcma")}, |
| 403 | {FLAG_ilbc, std::make_pair(NetEqDecoder::kDecoderILBC, "ilbc")}, |
| 404 | {FLAG_isac, std::make_pair(NetEqDecoder::kDecoderISAC, "isac")}, |
| 405 | {FLAG_isac_swb, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 406 | std::make_pair(NetEqDecoder::kDecoderISACswb, "isac-swb")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 407 | {FLAG_opus, std::make_pair(NetEqDecoder::kDecoderOpus, "opus")}, |
| 408 | {FLAG_pcm16b, std::make_pair(NetEqDecoder::kDecoderPCM16B, "pcm16-nb")}, |
| 409 | {FLAG_pcm16b_wb, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 410 | std::make_pair(NetEqDecoder::kDecoderPCM16Bwb, "pcm16-wb")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 411 | {FLAG_pcm16b_swb32, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 412 | std::make_pair(NetEqDecoder::kDecoderPCM16Bswb32kHz, "pcm16-swb32")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 413 | {FLAG_pcm16b_swb48, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 414 | std::make_pair(NetEqDecoder::kDecoderPCM16Bswb48kHz, "pcm16-swb48")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 415 | {FLAG_g722, std::make_pair(NetEqDecoder::kDecoderG722, "g722")}, |
| 416 | {FLAG_avt, std::make_pair(NetEqDecoder::kDecoderAVT, "avt")}, |
| 417 | {FLAG_avt_16, std::make_pair(NetEqDecoder::kDecoderAVT16kHz, "avt-16")}, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 418 | {FLAG_avt_32, std::make_pair(NetEqDecoder::kDecoderAVT32kHz, "avt-32")}, |
| 419 | {FLAG_avt_48, std::make_pair(NetEqDecoder::kDecoderAVT48kHz, "avt-48")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 420 | {FLAG_red, std::make_pair(NetEqDecoder::kDecoderRED, "red")}, |
| 421 | {FLAG_cn_nb, std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb")}, |
| 422 | {FLAG_cn_wb, std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb")}, |
| 423 | {FLAG_cn_swb32, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 424 | std::make_pair(NetEqDecoder::kDecoderCNGswb32kHz, "cng-swb32")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 425 | {FLAG_cn_swb48, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 426 | std::make_pair(NetEqDecoder::kDecoderCNGswb48kHz, "cng-swb48")}}; |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 427 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 428 | // Check if a replacement audio file was provided. |
| 429 | std::unique_ptr<AudioDecoder> replacement_decoder; |
| 430 | NetEqTest::ExtDecoderMap ext_codecs; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 431 | if (strlen(FLAG_replacement_audio_file) > 0) { |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 432 | // Find largest unused payload type. |
| 433 | int replacement_pt = 127; |
| 434 | while (!(codecs.find(replacement_pt) == codecs.end() && |
| 435 | ext_codecs.find(replacement_pt) == ext_codecs.end())) { |
| 436 | --replacement_pt; |
| 437 | RTC_CHECK_GE(replacement_pt, 0); |
| 438 | } |
| 439 | |
| 440 | auto std_set_int32_to_uint8 = [](const std::set<int32_t>& a) { |
| 441 | std::set<uint8_t> b; |
| 442 | for (auto& x : a) { |
| 443 | b.insert(static_cast<uint8_t>(x)); |
| 444 | } |
| 445 | return b; |
| 446 | }; |
| 447 | |
| 448 | std::set<uint8_t> cn_types = std_set_int32_to_uint8( |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 449 | {FLAG_cn_nb, FLAG_cn_wb, FLAG_cn_swb32, FLAG_cn_swb48}); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 450 | std::set<uint8_t> forbidden_types = std_set_int32_to_uint8( |
| 451 | {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] | 452 | input.reset(new NetEqReplacementInput(std::move(input), replacement_pt, |
| 453 | cn_types, forbidden_types)); |
| 454 | |
| 455 | replacement_decoder.reset(new FakeDecodeFromFile( |
| 456 | std::unique_ptr<InputAudioFile>( |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 457 | new InputAudioFile(FLAG_replacement_audio_file)), |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 458 | 48000, false)); |
| 459 | NetEqTest::ExternalDecoderInfo ext_dec_info = { |
| 460 | replacement_decoder.get(), NetEqDecoder::kDecoderArbitrary, |
| 461 | "replacement codec"}; |
| 462 | ext_codecs[replacement_pt] = ext_dec_info; |
| 463 | } |
| 464 | |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 465 | NetEqTest::Callbacks callbacks; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 466 | std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer; |
Ivo Creusen | d1d8dfb | 2017-12-06 10:48:10 +0100 | [diff] [blame] | 467 | if (FLAG_matlabplot || FLAG_pythonplot) { |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 468 | delay_analyzer.reset(new NetEqDelayAnalyzer); |
| 469 | } |
| 470 | |
| 471 | SsrcSwitchDetector ssrc_switch_detector(delay_analyzer.get()); |
| 472 | callbacks.post_insert_packet = &ssrc_switch_detector; |
Minyue Li | 2b415da | 2018-04-16 14:33:53 +0200 | [diff] [blame] | 473 | NetEqStatsGetter stats_getter(std::move(delay_analyzer)); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 474 | callbacks.get_audio_callback = &stats_getter; |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 475 | NetEq::Config config; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 476 | config.sample_rate_hz = *sample_rate_hz; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 477 | NetEqTest test(config, codecs, ext_codecs, std::move(input), |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 478 | std::move(output), callbacks); |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 479 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 480 | int64_t test_duration_ms = test.Run(); |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 481 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 482 | if (FLAG_matlabplot) { |
henrik.lundin | f09c904 | 2017-08-29 09:14:08 -0700 | [diff] [blame] | 483 | auto matlab_script_name = output_file_name; |
| 484 | std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.', |
| 485 | '_'); |
| 486 | std::cout << "Creating Matlab plot script " << matlab_script_name + ".m" |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 487 | << std::endl; |
Minyue Li | 5ebb416 | 2018-05-08 22:42:00 +0200 | [diff] [blame] | 488 | stats_getter.delay_analyzer()->CreateMatlabScript(matlab_script_name + |
| 489 | ".m"); |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 490 | } |
Ivo Creusen | d1d8dfb | 2017-12-06 10:48:10 +0100 | [diff] [blame] | 491 | if (FLAG_pythonplot) { |
| 492 | auto python_script_name = output_file_name; |
| 493 | std::replace(python_script_name.begin(), python_script_name.end(), '.', |
| 494 | '_'); |
| 495 | std::cout << "Creating Python plot script " << python_script_name + ".py" |
| 496 | << std::endl; |
Minyue Li | 5ebb416 | 2018-05-08 22:42:00 +0200 | [diff] [blame] | 497 | stats_getter.delay_analyzer()->CreatePythonScript(python_script_name + |
| 498 | ".py"); |
Ivo Creusen | d1d8dfb | 2017-12-06 10:48:10 +0100 | [diff] [blame] | 499 | } |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 500 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 501 | printf("Simulation statistics:\n"); |
| 502 | printf(" output duration: %" PRId64 " ms\n", test_duration_ms); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 503 | auto stats = stats_getter.AverageStats(); |
| 504 | printf(" packet_loss_rate: %f %%\n", 100.0 * stats.packet_loss_rate); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 505 | printf(" expand_rate: %f %%\n", 100.0 * stats.expand_rate); |
| 506 | printf(" speech_expand_rate: %f %%\n", 100.0 * stats.speech_expand_rate); |
| 507 | printf(" preemptive_rate: %f %%\n", 100.0 * stats.preemptive_rate); |
| 508 | printf(" accelerate_rate: %f %%\n", 100.0 * stats.accelerate_rate); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 509 | printf(" secondary_decoded_rate: %f %%\n", |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 510 | 100.0 * stats.secondary_decoded_rate); |
minyue-webrtc | 0c3ca75 | 2017-08-23 15:59:38 +0200 | [diff] [blame] | 511 | printf(" secondary_discarded_rate: %f %%\n", |
| 512 | 100.0 * stats.secondary_discarded_rate); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 513 | printf(" clockdrift_ppm: %f ppm\n", stats.clockdrift_ppm); |
| 514 | printf(" mean_waiting_time_ms: %f ms\n", stats.mean_waiting_time_ms); |
| 515 | printf(" median_waiting_time_ms: %f ms\n", stats.median_waiting_time_ms); |
| 516 | printf(" min_waiting_time_ms: %f ms\n", stats.min_waiting_time_ms); |
| 517 | 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] | 518 | printf(" current_buffer_size_ms: %f ms\n", stats.current_buffer_size_ms); |
| 519 | 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] | 520 | if (FLAG_concealment_events) { |
Minyue Li | 2b415da | 2018-04-16 14:33:53 +0200 | [diff] [blame] | 521 | std::cout << " concealment_events_ms:" << std::endl; |
Alex Narest | 7ff6ca5 | 2018-02-07 18:46:33 +0100 | [diff] [blame] | 522 | for (auto concealment_event : stats_getter.concealment_events()) |
Minyue Li | 2b415da | 2018-04-16 14:33:53 +0200 | [diff] [blame] | 523 | std::cout << concealment_event.ToString() << std::endl; |
| 524 | std::cout << " end of concealment_events_ms" << std::endl; |
Alex Narest | 7ff6ca5 | 2018-02-07 18:46:33 +0100 | [diff] [blame] | 525 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 526 | return 0; |
| 527 | } |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 528 | |
henrik.lundin | 303d3e1 | 2016-05-26 05:56:03 -0700 | [diff] [blame] | 529 | } // namespace |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 530 | } // namespace test |
| 531 | } // namespace webrtc |
henrik.lundin | 303d3e1 | 2016-05-26 05:56:03 -0700 | [diff] [blame] | 532 | |
| 533 | int main(int argc, char* argv[]) { |
Robin Raymond | 1c62ffa | 2017-12-03 16:45:56 -0500 | [diff] [blame] | 534 | return webrtc::test::RunTest(argc, argv); |
henrik.lundin | 303d3e1 | 2016-05-26 05:56:03 -0700 | [diff] [blame] | 535 | } |