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