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. |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 16 | #include <string.h> |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 17 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 18 | #include <algorithm> |
henrik.lundin | d4ec970 | 2016-09-06 01:22:45 -0700 | [diff] [blame] | 19 | #include <ios> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 20 | #include <iostream> |
kwiberg | 2d0c332 | 2016-02-14 09:28:33 -0800 | [diff] [blame] | 21 | #include <memory> |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 22 | #include <numeric> |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 23 | #include <string> |
| 24 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "modules/audio_coding/neteq/include/neteq.h" |
| 26 | #include "modules/audio_coding/neteq/tools/fake_decode_from_file.h" |
| 27 | #include "modules/audio_coding/neteq/tools/input_audio_file.h" |
| 28 | #include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h" |
| 29 | #include "modules/audio_coding/neteq/tools/neteq_packet_source_input.h" |
| 30 | #include "modules/audio_coding/neteq/tools/neteq_replacement_input.h" |
| 31 | #include "modules/audio_coding/neteq/tools/neteq_test.h" |
| 32 | #include "modules/audio_coding/neteq/tools/output_audio_file.h" |
| 33 | #include "modules/audio_coding/neteq/tools/output_wav_file.h" |
| 34 | #include "modules/audio_coding/neteq/tools/rtp_file_source.h" |
| 35 | #include "modules/include/module_common_types.h" |
| 36 | #include "rtc_base/checks.h" |
| 37 | #include "rtc_base/flags.h" |
| 38 | #include "test/testsupport/fileutils.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 39 | #include "typedefs.h" // NOLINT(build/include) |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 40 | |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 41 | namespace webrtc { |
| 42 | namespace test { |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 43 | namespace { |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 44 | |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 45 | // Parses the input string for a valid SSRC (at the start of the string). If a |
| 46 | // valid SSRC is found, it is written to the output variable |ssrc|, and true is |
| 47 | // returned. Otherwise, false is returned. |
| 48 | bool ParseSsrc(const std::string& str, uint32_t* ssrc) { |
| 49 | if (str.empty()) |
henrik.lundin@webrtc.org | 9103953 | 2014-10-07 07:18:36 +0000 | [diff] [blame] | 50 | return true; |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 51 | int base = 10; |
| 52 | // Look for "0x" or "0X" at the start and change base to 16 if found. |
| 53 | if ((str.compare(0, 2, "0x") == 0) || (str.compare(0, 2, "0X") == 0)) |
| 54 | base = 16; |
| 55 | errno = 0; |
| 56 | char* end_ptr; |
| 57 | unsigned long value = strtoul(str.c_str(), &end_ptr, base); |
| 58 | if (value == ULONG_MAX && errno == ERANGE) |
| 59 | return false; // Value out of range for unsigned long. |
| 60 | if (sizeof(unsigned long) > sizeof(uint32_t) && value > 0xFFFFFFFF) |
| 61 | return false; // Value out of range for uint32_t. |
| 62 | if (end_ptr - str.c_str() < static_cast<ptrdiff_t>(str.length())) |
| 63 | return false; // Part of the string was not parsed. |
| 64 | *ssrc = static_cast<uint32_t>(value); |
| 65 | return true; |
| 66 | } |
| 67 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 68 | // Flag validators. |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 69 | bool ValidatePayloadType(int value) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 70 | if (value >= 0 && value <= 127) // Value is ok. |
| 71 | return true; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 72 | printf("Payload type must be between 0 and 127, not %d\n", |
| 73 | static_cast<int>(value)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 74 | return false; |
| 75 | } |
| 76 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 77 | bool ValidateSsrcValue(const std::string& str) { |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 78 | uint32_t dummy_ssrc; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 79 | if (ParseSsrc(str, &dummy_ssrc)) // Value is ok. |
| 80 | return true; |
| 81 | printf("Invalid SSRC: %s\n", str.c_str()); |
| 82 | return false; |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 83 | } |
| 84 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 85 | static bool ValidateExtensionId(int value) { |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 86 | if (value > 0 && value <= 255) // Value is ok. |
| 87 | return true; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 88 | printf("Extension ID must be between 1 and 255, not %d\n", |
| 89 | static_cast<int>(value)); |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 90 | return false; |
| 91 | } |
| 92 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 93 | // Define command line flags. |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 94 | DEFINE_int(pcmu, 0, "RTP payload type for PCM-u"); |
| 95 | DEFINE_int(pcma, 8, "RTP payload type for PCM-a"); |
| 96 | DEFINE_int(ilbc, 102, "RTP payload type for iLBC"); |
| 97 | DEFINE_int(isac, 103, "RTP payload type for iSAC"); |
| 98 | DEFINE_int(isac_swb, 104, "RTP payload type for iSAC-swb (32 kHz)"); |
| 99 | DEFINE_int(opus, 111, "RTP payload type for Opus"); |
| 100 | DEFINE_int(pcm16b, 93, "RTP payload type for PCM16b-nb (8 kHz)"); |
| 101 | DEFINE_int(pcm16b_wb, 94, "RTP payload type for PCM16b-wb (16 kHz)"); |
| 102 | DEFINE_int(pcm16b_swb32, 95, "RTP payload type for PCM16b-swb32 (32 kHz)"); |
| 103 | DEFINE_int(pcm16b_swb48, 96, "RTP payload type for PCM16b-swb48 (48 kHz)"); |
| 104 | DEFINE_int(g722, 9, "RTP payload type for G.722"); |
| 105 | DEFINE_int(avt, 106, "RTP payload type for AVT/DTMF (8 kHz)"); |
| 106 | DEFINE_int(avt_16, 114, "RTP payload type for AVT/DTMF (16 kHz)"); |
| 107 | DEFINE_int(avt_32, 115, "RTP payload type for AVT/DTMF (32 kHz)"); |
| 108 | DEFINE_int(avt_48, 116, "RTP payload type for AVT/DTMF (48 kHz)"); |
| 109 | DEFINE_int(red, 117, "RTP payload type for redundant audio (RED)"); |
| 110 | DEFINE_int(cn_nb, 13, "RTP payload type for comfort noise (8 kHz)"); |
| 111 | DEFINE_int(cn_wb, 98, "RTP payload type for comfort noise (16 kHz)"); |
| 112 | DEFINE_int(cn_swb32, 99, "RTP payload type for comfort noise (32 kHz)"); |
| 113 | DEFINE_int(cn_swb48, 100, "RTP payload type for comfort noise (48 kHz)"); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 114 | DEFINE_bool(codec_map, false, "Prints the mapping between RTP payload type and " |
| 115 | "codec"); |
henrik.lundin@webrtc.org | 75642fc | 2014-02-05 08:49:13 +0000 | [diff] [blame] | 116 | DEFINE_string(replacement_audio_file, "", |
| 117 | "A PCM file that will be used to populate ""dummy"" RTP packets"); |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 118 | DEFINE_string(ssrc, |
| 119 | "", |
| 120 | "Only use packets with this SSRC (decimal or hex, the latter " |
| 121 | "starting with 0x)"); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 122 | DEFINE_int(audio_level, 1, "Extension ID for audio level (RFC 6464)"); |
| 123 | DEFINE_int(abs_send_time, 3, "Extension ID for absolute sender time"); |
| 124 | DEFINE_int(transport_seq_no, 5, "Extension ID for transport sequence number"); |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 125 | DEFINE_bool(matlabplot, |
| 126 | false, |
| 127 | "Generates a matlab script for plotting the delay profile"); |
Ivo Creusen | d1d8dfb | 2017-12-06 10:48:10 +0100 | [diff] [blame] | 128 | DEFINE_bool(pythonplot, |
| 129 | false, |
| 130 | "Generates a python script for plotting the delay profile"); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 131 | DEFINE_bool(help, false, "Prints this message"); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 132 | |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 133 | // Maps a codec type to a printable name string. |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 134 | std::string CodecName(NetEqDecoder codec) { |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 135 | switch (codec) { |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 136 | case NetEqDecoder::kDecoderPCMu: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 137 | return "PCM-u"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 138 | case NetEqDecoder::kDecoderPCMa: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 139 | return "PCM-a"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 140 | case NetEqDecoder::kDecoderILBC: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 141 | return "iLBC"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 142 | case NetEqDecoder::kDecoderISAC: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 143 | return "iSAC"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 144 | case NetEqDecoder::kDecoderISACswb: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 145 | return "iSAC-swb (32 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 146 | case NetEqDecoder::kDecoderOpus: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 147 | return "Opus"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 148 | case NetEqDecoder::kDecoderPCM16B: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 149 | return "PCM16b-nb (8 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 150 | case NetEqDecoder::kDecoderPCM16Bwb: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 151 | return "PCM16b-wb (16 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 152 | case NetEqDecoder::kDecoderPCM16Bswb32kHz: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 153 | return "PCM16b-swb32 (32 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 154 | case NetEqDecoder::kDecoderPCM16Bswb48kHz: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 155 | return "PCM16b-swb48 (48 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 156 | case NetEqDecoder::kDecoderG722: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 157 | return "G.722"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 158 | case NetEqDecoder::kDecoderRED: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 159 | return "redundant audio (RED)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 160 | case NetEqDecoder::kDecoderAVT: |
solenberg | 2779bab | 2016-11-17 04:45:19 -0800 | [diff] [blame] | 161 | return "AVT/DTMF (8 kHz)"; |
| 162 | case NetEqDecoder::kDecoderAVT16kHz: |
| 163 | return "AVT/DTMF (16 kHz)"; |
| 164 | case NetEqDecoder::kDecoderAVT32kHz: |
| 165 | return "AVT/DTMF (32 kHz)"; |
| 166 | case NetEqDecoder::kDecoderAVT48kHz: |
| 167 | return "AVT/DTMF (48 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 168 | case NetEqDecoder::kDecoderCNGnb: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 169 | return "comfort noise (8 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 170 | case NetEqDecoder::kDecoderCNGwb: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 171 | return "comfort noise (16 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 172 | case NetEqDecoder::kDecoderCNGswb32kHz: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 173 | return "comfort noise (32 kHz)"; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 174 | case NetEqDecoder::kDecoderCNGswb48kHz: |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 175 | return "comfort noise (48 kHz)"; |
| 176 | default: |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 177 | FATAL(); |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 178 | return "undefined"; |
| 179 | } |
| 180 | } |
| 181 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 182 | void PrintCodecMappingEntry(NetEqDecoder codec, int flag) { |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 183 | std::cout << CodecName(codec) << ": " << flag << std::endl; |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void PrintCodecMapping() { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 187 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMu, FLAG_pcmu); |
| 188 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMa, FLAG_pcma); |
| 189 | PrintCodecMappingEntry(NetEqDecoder::kDecoderILBC, FLAG_ilbc); |
| 190 | PrintCodecMappingEntry(NetEqDecoder::kDecoderISAC, FLAG_isac); |
| 191 | PrintCodecMappingEntry(NetEqDecoder::kDecoderISACswb, FLAG_isac_swb); |
| 192 | PrintCodecMappingEntry(NetEqDecoder::kDecoderOpus, FLAG_opus); |
| 193 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16B, FLAG_pcm16b); |
| 194 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bwb, FLAG_pcm16b_wb); |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 195 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb32kHz, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 196 | FLAG_pcm16b_swb32); |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 197 | PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb48kHz, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 198 | FLAG_pcm16b_swb48); |
| 199 | PrintCodecMappingEntry(NetEqDecoder::kDecoderG722, FLAG_g722); |
| 200 | PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT, FLAG_avt); |
| 201 | PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT16kHz, FLAG_avt_16); |
| 202 | PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT32kHz, FLAG_avt_32); |
| 203 | PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT48kHz, FLAG_avt_48); |
| 204 | PrintCodecMappingEntry(NetEqDecoder::kDecoderRED, FLAG_red); |
| 205 | PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGnb, FLAG_cn_nb); |
| 206 | PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGwb, FLAG_cn_wb); |
| 207 | PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb32kHz, FLAG_cn_swb32); |
| 208 | PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb48kHz, FLAG_cn_swb48); |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 211 | rtc::Optional<int> CodecSampleRate(uint8_t payload_type) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 212 | if (payload_type == FLAG_pcmu || payload_type == FLAG_pcma || |
| 213 | payload_type == FLAG_ilbc || payload_type == FLAG_pcm16b || |
| 214 | payload_type == FLAG_cn_nb || payload_type == FLAG_avt) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 215 | return 8000; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 216 | if (payload_type == FLAG_isac || payload_type == FLAG_pcm16b_wb || |
| 217 | payload_type == FLAG_g722 || payload_type == FLAG_cn_wb || |
| 218 | payload_type == FLAG_avt_16) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 219 | return 16000; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 220 | if (payload_type == FLAG_isac_swb || payload_type == FLAG_pcm16b_swb32 || |
| 221 | payload_type == FLAG_cn_swb32 || payload_type == FLAG_avt_32) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 222 | return 32000; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 223 | if (payload_type == FLAG_opus || payload_type == FLAG_pcm16b_swb48 || |
| 224 | payload_type == FLAG_cn_swb48 || payload_type == FLAG_avt_48) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 225 | return 48000; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 226 | if (payload_type == FLAG_red) |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 227 | return 0; |
| 228 | return rtc::nullopt; |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 229 | } |
| 230 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 231 | // Class to let through only the packets with a given SSRC. Should be used as an |
| 232 | // outer layer on another NetEqInput object. |
| 233 | class FilterSsrcInput : public NetEqInput { |
| 234 | public: |
| 235 | FilterSsrcInput(std::unique_ptr<NetEqInput> source, uint32_t ssrc) |
| 236 | : source_(std::move(source)), ssrc_(ssrc) { |
| 237 | FindNextWithCorrectSsrc(); |
henrik.lundin | d4ec970 | 2016-09-06 01:22:45 -0700 | [diff] [blame] | 238 | RTC_CHECK(source_->NextHeader()) << "Found no packet with SSRC = 0x" |
| 239 | << std::hex << ssrc_; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 240 | } |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 241 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 242 | // All methods but PopPacket() simply relay to the |source_| object. |
| 243 | rtc::Optional<int64_t> NextPacketTime() const override { |
| 244 | return source_->NextPacketTime(); |
| 245 | } |
| 246 | rtc::Optional<int64_t> NextOutputEventTime() const override { |
| 247 | return source_->NextOutputEventTime(); |
| 248 | } |
| 249 | |
| 250 | // Returns the next packet, and throws away upcoming packets that do not match |
| 251 | // the desired SSRC. |
| 252 | std::unique_ptr<PacketData> PopPacket() override { |
| 253 | std::unique_ptr<PacketData> packet_to_return = source_->PopPacket(); |
henrik.lundin | 246ef3e | 2017-04-24 09:14:32 -0700 | [diff] [blame] | 254 | RTC_DCHECK(!packet_to_return || packet_to_return->header.ssrc == ssrc_); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 255 | // Pre-fetch the next packet with correct SSRC. Hence, |source_| will always |
| 256 | // be have a valid packet (or empty if no more packets are available) when |
| 257 | // this method returns. |
| 258 | FindNextWithCorrectSsrc(); |
| 259 | return packet_to_return; |
| 260 | } |
| 261 | |
| 262 | void AdvanceOutputEvent() override { source_->AdvanceOutputEvent(); } |
| 263 | |
| 264 | bool ended() const override { return source_->ended(); } |
| 265 | |
| 266 | rtc::Optional<RTPHeader> NextHeader() const override { |
| 267 | return source_->NextHeader(); |
| 268 | } |
| 269 | |
| 270 | private: |
| 271 | void FindNextWithCorrectSsrc() { |
| 272 | while (source_->NextHeader() && source_->NextHeader()->ssrc != ssrc_) { |
| 273 | source_->PopPacket(); |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 274 | } |
| 275 | } |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 276 | |
| 277 | std::unique_ptr<NetEqInput> source_; |
| 278 | uint32_t ssrc_; |
| 279 | }; |
pkasting@chromium.org | 4dba2e9 | 2015-01-26 19:59:32 +0000 | [diff] [blame] | 280 | |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 281 | // A callback class which prints whenver the inserted packet stream changes |
| 282 | // the SSRC. |
| 283 | class SsrcSwitchDetector : public NetEqPostInsertPacket { |
| 284 | public: |
| 285 | // Takes a pointer to another callback object, which will be invoked after |
| 286 | // this object finishes. This does not transfer ownership, and null is a |
| 287 | // valid value. |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 288 | explicit SsrcSwitchDetector(NetEqPostInsertPacket* other_callback) |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 289 | : other_callback_(other_callback) {} |
| 290 | |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 291 | void AfterInsertPacket(const NetEqInput::PacketData& packet, |
| 292 | NetEq* neteq) override { |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 293 | if (last_ssrc_ && packet.header.ssrc != *last_ssrc_) { |
| 294 | std::cout << "Changing streams from 0x" << std::hex << *last_ssrc_ |
| 295 | << " to 0x" << std::hex << packet.header.ssrc |
| 296 | << std::dec << " (payload type " |
| 297 | << static_cast<int>(packet.header.payloadType) << ")" |
| 298 | << std::endl; |
| 299 | } |
Oskar Sundbom | 12ab00b | 2017-11-16 15:31:38 +0100 | [diff] [blame] | 300 | last_ssrc_ = packet.header.ssrc; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 301 | if (other_callback_) { |
| 302 | other_callback_->AfterInsertPacket(packet, neteq); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | private: |
| 307 | NetEqPostInsertPacket* other_callback_; |
| 308 | rtc::Optional<uint32_t> last_ssrc_; |
| 309 | }; |
| 310 | |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 311 | class StatsGetter : public NetEqGetAudioCallback { |
| 312 | public: |
| 313 | // This struct is a replica of webrtc::NetEqNetworkStatistics, but with all |
| 314 | // values stored in double precision. |
| 315 | struct Stats { |
| 316 | double current_buffer_size_ms = 0.0; |
| 317 | double preferred_buffer_size_ms = 0.0; |
| 318 | double jitter_peaks_found = 0.0; |
| 319 | double packet_loss_rate = 0.0; |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 320 | double expand_rate = 0.0; |
| 321 | double speech_expand_rate = 0.0; |
| 322 | double preemptive_rate = 0.0; |
| 323 | double accelerate_rate = 0.0; |
| 324 | double secondary_decoded_rate = 0.0; |
minyue-webrtc | 0c3ca75 | 2017-08-23 15:59:38 +0200 | [diff] [blame] | 325 | double secondary_discarded_rate = 0.0; |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 326 | double clockdrift_ppm = 0.0; |
| 327 | double added_zero_samples = 0.0; |
| 328 | double mean_waiting_time_ms = 0.0; |
| 329 | double median_waiting_time_ms = 0.0; |
| 330 | double min_waiting_time_ms = 0.0; |
| 331 | double max_waiting_time_ms = 0.0; |
| 332 | }; |
| 333 | |
| 334 | // Takes a pointer to another callback object, which will be invoked after |
| 335 | // this object finishes. This does not transfer ownership, and null is a |
| 336 | // valid value. |
| 337 | explicit StatsGetter(NetEqGetAudioCallback* other_callback) |
| 338 | : other_callback_(other_callback) {} |
| 339 | |
| 340 | void BeforeGetAudio(NetEq* neteq) override { |
| 341 | if (other_callback_) { |
| 342 | other_callback_->BeforeGetAudio(neteq); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | void AfterGetAudio(int64_t time_now_ms, |
| 347 | const AudioFrame& audio_frame, |
| 348 | bool muted, |
| 349 | NetEq* neteq) override { |
| 350 | if (++counter_ >= 100) { |
| 351 | counter_ = 0; |
| 352 | NetEqNetworkStatistics stats; |
| 353 | RTC_CHECK_EQ(neteq->NetworkStatistics(&stats), 0); |
| 354 | stats_.push_back(stats); |
| 355 | } |
| 356 | if (other_callback_) { |
henrik.lundin | f09c904 | 2017-08-29 09:14:08 -0700 | [diff] [blame] | 357 | other_callback_->AfterGetAudio(time_now_ms, audio_frame, muted, neteq); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
| 361 | double AverageSpeechExpandRate() const { |
| 362 | double sum_speech_expand = |
| 363 | std::accumulate(stats_.begin(), stats_.end(), double{0.0}, |
| 364 | [](double a, NetEqNetworkStatistics b) { |
| 365 | return a + static_cast<double>(b.speech_expand_rate); |
| 366 | }); |
| 367 | return sum_speech_expand / 16384.0 / stats_.size(); |
| 368 | } |
| 369 | |
| 370 | Stats AverageStats() const { |
| 371 | Stats sum_stats = std::accumulate( |
| 372 | stats_.begin(), stats_.end(), Stats(), |
| 373 | [](Stats a, NetEqNetworkStatistics b) { |
| 374 | a.current_buffer_size_ms += b.current_buffer_size_ms; |
| 375 | a.preferred_buffer_size_ms += b.preferred_buffer_size_ms; |
| 376 | a.jitter_peaks_found += b.jitter_peaks_found; |
| 377 | a.packet_loss_rate += b.packet_loss_rate / 16384.0; |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 378 | a.expand_rate += b.expand_rate / 16384.0; |
| 379 | a.speech_expand_rate += b.speech_expand_rate / 16384.0; |
| 380 | a.preemptive_rate += b.preemptive_rate / 16384.0; |
| 381 | a.accelerate_rate += b.accelerate_rate / 16384.0; |
| 382 | a.secondary_decoded_rate += b.secondary_decoded_rate / 16384.0; |
minyue-webrtc | 0c3ca75 | 2017-08-23 15:59:38 +0200 | [diff] [blame] | 383 | a.secondary_discarded_rate += b.secondary_discarded_rate / 16384.0; |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 384 | a.clockdrift_ppm += b.clockdrift_ppm; |
| 385 | a.added_zero_samples += b.added_zero_samples; |
| 386 | a.mean_waiting_time_ms += b.mean_waiting_time_ms; |
| 387 | a.median_waiting_time_ms += b.median_waiting_time_ms; |
henrik.lundin | 9657172 | 2017-08-30 00:41:30 -0700 | [diff] [blame] | 388 | a.min_waiting_time_ms = |
| 389 | std::min(a.min_waiting_time_ms, |
| 390 | static_cast<double>(b.min_waiting_time_ms)); |
| 391 | a.max_waiting_time_ms = |
| 392 | std::max(a.max_waiting_time_ms, |
| 393 | static_cast<double>(b.max_waiting_time_ms)); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 394 | return a; |
| 395 | }); |
| 396 | |
| 397 | sum_stats.current_buffer_size_ms /= stats_.size(); |
| 398 | sum_stats.preferred_buffer_size_ms /= stats_.size(); |
| 399 | sum_stats.jitter_peaks_found /= stats_.size(); |
| 400 | sum_stats.packet_loss_rate /= stats_.size(); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 401 | sum_stats.expand_rate /= stats_.size(); |
| 402 | sum_stats.speech_expand_rate /= stats_.size(); |
| 403 | sum_stats.preemptive_rate /= stats_.size(); |
| 404 | sum_stats.accelerate_rate /= stats_.size(); |
| 405 | sum_stats.secondary_decoded_rate /= stats_.size(); |
minyue-webrtc | 0c3ca75 | 2017-08-23 15:59:38 +0200 | [diff] [blame] | 406 | sum_stats.secondary_discarded_rate /= stats_.size(); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 407 | sum_stats.clockdrift_ppm /= stats_.size(); |
| 408 | sum_stats.added_zero_samples /= stats_.size(); |
| 409 | sum_stats.mean_waiting_time_ms /= stats_.size(); |
| 410 | sum_stats.median_waiting_time_ms /= stats_.size(); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 411 | |
| 412 | return sum_stats; |
| 413 | } |
| 414 | |
| 415 | private: |
| 416 | NetEqGetAudioCallback* other_callback_; |
| 417 | size_t counter_ = 0; |
| 418 | std::vector<NetEqNetworkStatistics> stats_; |
| 419 | }; |
| 420 | |
henrik.lundin | 303d3e1 | 2016-05-26 05:56:03 -0700 | [diff] [blame] | 421 | int RunTest(int argc, char* argv[]) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 422 | std::string program_name = argv[0]; |
| 423 | std::string usage = "Tool for decoding an RTP dump file using NetEq.\n" |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 424 | "Run " + program_name + " --help for usage.\n" |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 425 | "Example usage:\n" + program_name + |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 426 | " input.rtp output.{pcm, wav}\n"; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 427 | if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) { |
| 428 | return 1; |
| 429 | } |
| 430 | if (FLAG_help) { |
| 431 | std::cout << usage; |
| 432 | rtc::FlagList::Print(nullptr, false); |
| 433 | return 0; |
| 434 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 435 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 436 | if (FLAG_codec_map) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 437 | PrintCodecMapping(); |
| 438 | } |
| 439 | |
| 440 | if (argc != 3) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 441 | if (FLAG_codec_map) { |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 442 | // We have already printed the codec map. Just end the program. |
| 443 | return 0; |
| 444 | } |
| 445 | // Print usage information. |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 446 | std::cout << usage; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 447 | return 0; |
| 448 | } |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 449 | RTC_CHECK(ValidatePayloadType(FLAG_pcmu)); |
| 450 | RTC_CHECK(ValidatePayloadType(FLAG_pcma)); |
| 451 | RTC_CHECK(ValidatePayloadType(FLAG_ilbc)); |
| 452 | RTC_CHECK(ValidatePayloadType(FLAG_isac)); |
| 453 | RTC_CHECK(ValidatePayloadType(FLAG_isac_swb)); |
| 454 | RTC_CHECK(ValidatePayloadType(FLAG_opus)); |
| 455 | RTC_CHECK(ValidatePayloadType(FLAG_pcm16b)); |
| 456 | RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_wb)); |
| 457 | RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb32)); |
| 458 | RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb48)); |
| 459 | RTC_CHECK(ValidatePayloadType(FLAG_g722)); |
| 460 | RTC_CHECK(ValidatePayloadType(FLAG_avt)); |
| 461 | RTC_CHECK(ValidatePayloadType(FLAG_avt_16)); |
| 462 | RTC_CHECK(ValidatePayloadType(FLAG_avt_32)); |
| 463 | RTC_CHECK(ValidatePayloadType(FLAG_avt_48)); |
| 464 | RTC_CHECK(ValidatePayloadType(FLAG_red)); |
| 465 | RTC_CHECK(ValidatePayloadType(FLAG_cn_nb)); |
| 466 | RTC_CHECK(ValidatePayloadType(FLAG_cn_wb)); |
| 467 | RTC_CHECK(ValidatePayloadType(FLAG_cn_swb32)); |
| 468 | RTC_CHECK(ValidatePayloadType(FLAG_cn_swb48)); |
| 469 | RTC_CHECK(ValidateSsrcValue(FLAG_ssrc)); |
| 470 | RTC_CHECK(ValidateExtensionId(FLAG_audio_level)); |
| 471 | RTC_CHECK(ValidateExtensionId(FLAG_abs_send_time)); |
| 472 | RTC_CHECK(ValidateExtensionId(FLAG_transport_seq_no)); |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 473 | |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 474 | // Gather RTP header extensions in a map. |
| 475 | NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 476 | {FLAG_audio_level, kRtpExtensionAudioLevel}, |
| 477 | {FLAG_abs_send_time, kRtpExtensionAbsoluteSendTime}, |
| 478 | {FLAG_transport_seq_no, kRtpExtensionTransportSequenceNumber}}; |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 479 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 480 | const std::string input_file_name = argv[1]; |
| 481 | std::unique_ptr<NetEqInput> input; |
| 482 | if (RtpFileSource::ValidRtpDump(input_file_name) || |
| 483 | RtpFileSource::ValidPcap(input_file_name)) { |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 484 | input.reset(new NetEqRtpDumpInput(input_file_name, rtp_ext_map)); |
ivoc | caa5f4b | 2015-09-08 03:28:46 -0700 | [diff] [blame] | 485 | } else { |
henrik.lundin | 8a6a600 | 2016-08-25 00:46:36 -0700 | [diff] [blame] | 486 | input.reset(new NetEqEventLogInput(input_file_name, rtp_ext_map)); |
ivoc | caa5f4b | 2015-09-08 03:28:46 -0700 | [diff] [blame] | 487 | } |
| 488 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 489 | std::cout << "Input file: " << input_file_name << std::endl; |
| 490 | RTC_CHECK(input) << "Cannot open input file"; |
| 491 | RTC_CHECK(!input->ended()) << "Input file is empty"; |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 492 | |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 493 | // Check if an SSRC value was provided. |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 494 | if (strlen(FLAG_ssrc) > 0) { |
henrik.lundin@webrtc.org | 8b65d51 | 2014-10-07 05:30:04 +0000 | [diff] [blame] | 495 | uint32_t ssrc; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 496 | RTC_CHECK(ParseSsrc(FLAG_ssrc, &ssrc)) << "Flag verification has failed."; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 497 | input.reset(new FilterSsrcInput(std::move(input), ssrc)); |
ivoc | caa5f4b | 2015-09-08 03:28:46 -0700 | [diff] [blame] | 498 | } |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 499 | |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 500 | // Check the sample rate. |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 501 | rtc::Optional<int> sample_rate_hz; |
| 502 | std::set<std::pair<int, uint32_t>> discarded_pt_and_ssrc; |
| 503 | while (input->NextHeader()) { |
| 504 | rtc::Optional<RTPHeader> first_rtp_header = input->NextHeader(); |
| 505 | RTC_DCHECK(first_rtp_header); |
| 506 | sample_rate_hz = CodecSampleRate(first_rtp_header->payloadType); |
| 507 | if (sample_rate_hz) { |
| 508 | std::cout << "Found valid packet with payload type " |
| 509 | << static_cast<int>(first_rtp_header->payloadType) |
| 510 | << " and SSRC 0x" << std::hex << first_rtp_header->ssrc |
| 511 | << std::dec << std::endl; |
| 512 | break; |
| 513 | } |
| 514 | // Discard this packet and move to the next. Keep track of discarded payload |
| 515 | // types and SSRCs. |
| 516 | discarded_pt_and_ssrc.emplace(first_rtp_header->payloadType, |
| 517 | first_rtp_header->ssrc); |
| 518 | input->PopPacket(); |
| 519 | } |
| 520 | if (!discarded_pt_and_ssrc.empty()) { |
| 521 | std::cout << "Discarded initial packets with the following payload types " |
| 522 | "and SSRCs:" |
| 523 | << std::endl; |
| 524 | for (const auto& d : discarded_pt_and_ssrc) { |
| 525 | std::cout << "PT " << d.first << "; SSRC 0x" << std::hex |
| 526 | << static_cast<int>(d.second) << std::dec << std::endl; |
| 527 | } |
| 528 | } |
| 529 | if (!sample_rate_hz) { |
| 530 | std::cout << "Cannot find any packets with known payload types" |
| 531 | << std::endl; |
| 532 | RTC_NOTREACHED(); |
| 533 | } |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 534 | |
| 535 | // Open the output file now that we know the sample rate. (Rate is only needed |
| 536 | // for wav files.) |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 537 | const std::string output_file_name = argv[2]; |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 538 | std::unique_ptr<AudioSink> output; |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 539 | if (output_file_name.size() >= 4 && |
| 540 | output_file_name.substr(output_file_name.size() - 4) == ".wav") { |
| 541 | // Open a wav file. |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 542 | output.reset(new OutputWavFile(output_file_name, *sample_rate_hz)); |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 543 | } else { |
| 544 | // Open a pcm file. |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 545 | output.reset(new OutputAudioFile(output_file_name)); |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 546 | } |
| 547 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 548 | std::cout << "Output file: " << output_file_name << std::endl; |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 549 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 550 | NetEqTest::DecoderMap codecs = { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 551 | {FLAG_pcmu, std::make_pair(NetEqDecoder::kDecoderPCMu, "pcmu")}, |
| 552 | {FLAG_pcma, std::make_pair(NetEqDecoder::kDecoderPCMa, "pcma")}, |
| 553 | {FLAG_ilbc, std::make_pair(NetEqDecoder::kDecoderILBC, "ilbc")}, |
| 554 | {FLAG_isac, std::make_pair(NetEqDecoder::kDecoderISAC, "isac")}, |
| 555 | {FLAG_isac_swb, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 556 | std::make_pair(NetEqDecoder::kDecoderISACswb, "isac-swb")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 557 | {FLAG_opus, std::make_pair(NetEqDecoder::kDecoderOpus, "opus")}, |
| 558 | {FLAG_pcm16b, std::make_pair(NetEqDecoder::kDecoderPCM16B, "pcm16-nb")}, |
| 559 | {FLAG_pcm16b_wb, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 560 | std::make_pair(NetEqDecoder::kDecoderPCM16Bwb, "pcm16-wb")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 561 | {FLAG_pcm16b_swb32, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 562 | std::make_pair(NetEqDecoder::kDecoderPCM16Bswb32kHz, "pcm16-swb32")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 563 | {FLAG_pcm16b_swb48, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 564 | std::make_pair(NetEqDecoder::kDecoderPCM16Bswb48kHz, "pcm16-swb48")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 565 | {FLAG_g722, std::make_pair(NetEqDecoder::kDecoderG722, "g722")}, |
| 566 | {FLAG_avt, std::make_pair(NetEqDecoder::kDecoderAVT, "avt")}, |
| 567 | {FLAG_avt_16, std::make_pair(NetEqDecoder::kDecoderAVT16kHz, "avt-16")}, |
| 568 | {FLAG_avt_32, |
solenberg | 2779bab | 2016-11-17 04:45:19 -0800 | [diff] [blame] | 569 | std::make_pair(NetEqDecoder::kDecoderAVT32kHz, "avt-32")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 570 | {FLAG_avt_48, |
solenberg | 2779bab | 2016-11-17 04:45:19 -0800 | [diff] [blame] | 571 | std::make_pair(NetEqDecoder::kDecoderAVT48kHz, "avt-48")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 572 | {FLAG_red, std::make_pair(NetEqDecoder::kDecoderRED, "red")}, |
| 573 | {FLAG_cn_nb, std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb")}, |
| 574 | {FLAG_cn_wb, std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb")}, |
| 575 | {FLAG_cn_swb32, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 576 | std::make_pair(NetEqDecoder::kDecoderCNGswb32kHz, "cng-swb32")}, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 577 | {FLAG_cn_swb48, |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 578 | std::make_pair(NetEqDecoder::kDecoderCNGswb48kHz, "cng-swb48")}}; |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 579 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 580 | // Check if a replacement audio file was provided. |
| 581 | std::unique_ptr<AudioDecoder> replacement_decoder; |
| 582 | NetEqTest::ExtDecoderMap ext_codecs; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 583 | if (strlen(FLAG_replacement_audio_file) > 0) { |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 584 | // Find largest unused payload type. |
| 585 | int replacement_pt = 127; |
| 586 | while (!(codecs.find(replacement_pt) == codecs.end() && |
| 587 | ext_codecs.find(replacement_pt) == ext_codecs.end())) { |
| 588 | --replacement_pt; |
| 589 | RTC_CHECK_GE(replacement_pt, 0); |
| 590 | } |
| 591 | |
| 592 | auto std_set_int32_to_uint8 = [](const std::set<int32_t>& a) { |
| 593 | std::set<uint8_t> b; |
| 594 | for (auto& x : a) { |
| 595 | b.insert(static_cast<uint8_t>(x)); |
| 596 | } |
| 597 | return b; |
| 598 | }; |
| 599 | |
| 600 | std::set<uint8_t> cn_types = std_set_int32_to_uint8( |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 601 | {FLAG_cn_nb, FLAG_cn_wb, FLAG_cn_swb32, FLAG_cn_swb48}); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 602 | std::set<uint8_t> forbidden_types = |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 603 | std_set_int32_to_uint8({FLAG_g722, FLAG_red, FLAG_avt, |
| 604 | FLAG_avt_16, FLAG_avt_32, FLAG_avt_48}); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 605 | input.reset(new NetEqReplacementInput(std::move(input), replacement_pt, |
| 606 | cn_types, forbidden_types)); |
| 607 | |
| 608 | replacement_decoder.reset(new FakeDecodeFromFile( |
| 609 | std::unique_ptr<InputAudioFile>( |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 610 | new InputAudioFile(FLAG_replacement_audio_file)), |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 611 | 48000, false)); |
| 612 | NetEqTest::ExternalDecoderInfo ext_dec_info = { |
| 613 | replacement_decoder.get(), NetEqDecoder::kDecoderArbitrary, |
| 614 | "replacement codec"}; |
| 615 | ext_codecs[replacement_pt] = ext_dec_info; |
| 616 | } |
| 617 | |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 618 | NetEqTest::Callbacks callbacks; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 619 | std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer; |
Ivo Creusen | d1d8dfb | 2017-12-06 10:48:10 +0100 | [diff] [blame] | 620 | if (FLAG_matlabplot || FLAG_pythonplot) { |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 621 | delay_analyzer.reset(new NetEqDelayAnalyzer); |
| 622 | } |
| 623 | |
| 624 | SsrcSwitchDetector ssrc_switch_detector(delay_analyzer.get()); |
| 625 | callbacks.post_insert_packet = &ssrc_switch_detector; |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 626 | StatsGetter stats_getter(delay_analyzer.get()); |
| 627 | callbacks.get_audio_callback = &stats_getter; |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 628 | NetEq::Config config; |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 629 | config.sample_rate_hz = *sample_rate_hz; |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 630 | NetEqTest test(config, codecs, ext_codecs, std::move(input), |
henrik.lundin | 02739d9 | 2017-05-04 06:09:06 -0700 | [diff] [blame] | 631 | std::move(output), callbacks); |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 632 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 633 | int64_t test_duration_ms = test.Run(); |
henrik.lundin@webrtc.org | 03499a0 | 2014-11-24 14:50:53 +0000 | [diff] [blame] | 634 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 635 | if (FLAG_matlabplot) { |
henrik.lundin | f09c904 | 2017-08-29 09:14:08 -0700 | [diff] [blame] | 636 | auto matlab_script_name = output_file_name; |
| 637 | std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.', |
| 638 | '_'); |
| 639 | std::cout << "Creating Matlab plot script " << matlab_script_name + ".m" |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 640 | << std::endl; |
henrik.lundin | f09c904 | 2017-08-29 09:14:08 -0700 | [diff] [blame] | 641 | delay_analyzer->CreateMatlabScript(matlab_script_name + ".m"); |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 642 | } |
Ivo Creusen | d1d8dfb | 2017-12-06 10:48:10 +0100 | [diff] [blame] | 643 | if (FLAG_pythonplot) { |
| 644 | auto python_script_name = output_file_name; |
| 645 | std::replace(python_script_name.begin(), python_script_name.end(), '.', |
| 646 | '_'); |
| 647 | std::cout << "Creating Python plot script " << python_script_name + ".py" |
| 648 | << std::endl; |
| 649 | delay_analyzer->CreatePythonScript(python_script_name + ".py"); |
| 650 | } |
Henrik Lundin | 0bc0ccd | 2017-06-20 14:48:50 +0200 | [diff] [blame] | 651 | |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 652 | printf("Simulation statistics:\n"); |
| 653 | printf(" output duration: %" PRId64 " ms\n", test_duration_ms); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 654 | auto stats = stats_getter.AverageStats(); |
| 655 | printf(" packet_loss_rate: %f %%\n", 100.0 * stats.packet_loss_rate); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 656 | printf(" expand_rate: %f %%\n", 100.0 * stats.expand_rate); |
| 657 | printf(" speech_expand_rate: %f %%\n", 100.0 * stats.speech_expand_rate); |
| 658 | printf(" preemptive_rate: %f %%\n", 100.0 * stats.preemptive_rate); |
| 659 | printf(" accelerate_rate: %f %%\n", 100.0 * stats.accelerate_rate); |
henrik.lundin | e8a77e3 | 2016-06-22 06:34:03 -0700 | [diff] [blame] | 660 | printf(" secondary_decoded_rate: %f %%\n", |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 661 | 100.0 * stats.secondary_decoded_rate); |
minyue-webrtc | 0c3ca75 | 2017-08-23 15:59:38 +0200 | [diff] [blame] | 662 | printf(" secondary_discarded_rate: %f %%\n", |
| 663 | 100.0 * stats.secondary_discarded_rate); |
Henrik Lundin | a2af000 | 2017-06-20 16:54:39 +0200 | [diff] [blame] | 664 | printf(" clockdrift_ppm: %f ppm\n", stats.clockdrift_ppm); |
| 665 | printf(" mean_waiting_time_ms: %f ms\n", stats.mean_waiting_time_ms); |
| 666 | printf(" median_waiting_time_ms: %f ms\n", stats.median_waiting_time_ms); |
| 667 | printf(" min_waiting_time_ms: %f ms\n", stats.min_waiting_time_ms); |
| 668 | 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] | 669 | printf(" current_buffer_size_ms: %f ms\n", stats.current_buffer_size_ms); |
| 670 | printf(" preferred_buffer_size_ms: %f ms\n", stats.preferred_buffer_size_ms); |
henrik.lundin@webrtc.org | 75642fc | 2014-02-05 08:49:13 +0000 | [diff] [blame] | 671 | |
henrik.lundin@webrtc.org | d94659d | 2013-01-29 12:09:21 +0000 | [diff] [blame] | 672 | return 0; |
| 673 | } |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 674 | |
henrik.lundin | 303d3e1 | 2016-05-26 05:56:03 -0700 | [diff] [blame] | 675 | } // namespace |
henrik.lundin | ce5570e | 2016-05-24 06:14:57 -0700 | [diff] [blame] | 676 | } // namespace test |
| 677 | } // namespace webrtc |
henrik.lundin | 303d3e1 | 2016-05-26 05:56:03 -0700 | [diff] [blame] | 678 | |
| 679 | int main(int argc, char* argv[]) { |
| 680 | webrtc::test::RunTest(argc, argv); |
| 681 | } |