blob: fb937cd707e6e0103a73442c22f1db1b7b92ac53 [file] [log] [blame]
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +00001/*
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.org8b65d512014-10-07 05:30:04 +000011#include <errno.h>
henrik.lundine8a77e32016-06-22 06:34:03 -070012#include <inttypes.h>
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +000013#include <limits.h> // For ULONG_MAX returned by strtoul.
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000014#include <stdio.h>
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +000015#include <stdlib.h> // For strtoul.
oprypin6e09d872017-08-31 03:21:39 -070016#include <string.h>
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000017
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000018#include <algorithm>
henrik.lundind4ec9702016-09-06 01:22:45 -070019#include <ios>
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000020#include <iostream>
kwiberg2d0c3322016-02-14 09:28:33 -080021#include <memory>
Henrik Lundina2af0002017-06-20 16:54:39 +020022#include <numeric>
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000023#include <string>
24
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#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"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020035#include "rtc_base/checks.h"
36#include "rtc_base/flags.h"
37#include "test/testsupport/fileutils.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020038#include "typedefs.h" // NOLINT(build/include)
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000039
henrik.lundince5570e2016-05-24 06:14:57 -070040namespace webrtc {
41namespace test {
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +000042namespace {
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +000043
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +000044// Parses the input string for a valid SSRC (at the start of the string). If a
45// valid SSRC is found, it is written to the output variable |ssrc|, and true is
46// returned. Otherwise, false is returned.
47bool ParseSsrc(const std::string& str, uint32_t* ssrc) {
48 if (str.empty())
henrik.lundin@webrtc.org91039532014-10-07 07:18:36 +000049 return true;
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +000050 int base = 10;
51 // Look for "0x" or "0X" at the start and change base to 16 if found.
52 if ((str.compare(0, 2, "0x") == 0) || (str.compare(0, 2, "0X") == 0))
53 base = 16;
54 errno = 0;
55 char* end_ptr;
56 unsigned long value = strtoul(str.c_str(), &end_ptr, base);
57 if (value == ULONG_MAX && errno == ERANGE)
58 return false; // Value out of range for unsigned long.
59 if (sizeof(unsigned long) > sizeof(uint32_t) && value > 0xFFFFFFFF)
60 return false; // Value out of range for uint32_t.
61 if (end_ptr - str.c_str() < static_cast<ptrdiff_t>(str.length()))
62 return false; // Part of the string was not parsed.
63 *ssrc = static_cast<uint32_t>(value);
64 return true;
65}
66
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000067// Flag validators.
oprypin6e09d872017-08-31 03:21:39 -070068bool ValidatePayloadType(int value) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000069 if (value >= 0 && value <= 127) // Value is ok.
70 return true;
oprypin6e09d872017-08-31 03:21:39 -070071 printf("Payload type must be between 0 and 127, not %d\n",
72 static_cast<int>(value));
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000073 return false;
74}
75
oprypin6e09d872017-08-31 03:21:39 -070076bool ValidateSsrcValue(const std::string& str) {
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +000077 uint32_t dummy_ssrc;
oprypin6e09d872017-08-31 03:21:39 -070078 if (ParseSsrc(str, &dummy_ssrc)) // Value is ok.
79 return true;
80 printf("Invalid SSRC: %s\n", str.c_str());
81 return false;
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +000082}
83
oprypin6e09d872017-08-31 03:21:39 -070084static bool ValidateExtensionId(int value) {
henrik.lundin8a6a6002016-08-25 00:46:36 -070085 if (value > 0 && value <= 255) // Value is ok.
86 return true;
oprypin6e09d872017-08-31 03:21:39 -070087 printf("Extension ID must be between 1 and 255, not %d\n",
88 static_cast<int>(value));
henrik.lundin8a6a6002016-08-25 00:46:36 -070089 return false;
90}
91
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000092// Define command line flags.
oprypin6e09d872017-08-31 03:21:39 -070093DEFINE_int(pcmu, 0, "RTP payload type for PCM-u");
94DEFINE_int(pcma, 8, "RTP payload type for PCM-a");
95DEFINE_int(ilbc, 102, "RTP payload type for iLBC");
96DEFINE_int(isac, 103, "RTP payload type for iSAC");
97DEFINE_int(isac_swb, 104, "RTP payload type for iSAC-swb (32 kHz)");
98DEFINE_int(opus, 111, "RTP payload type for Opus");
99DEFINE_int(pcm16b, 93, "RTP payload type for PCM16b-nb (8 kHz)");
100DEFINE_int(pcm16b_wb, 94, "RTP payload type for PCM16b-wb (16 kHz)");
101DEFINE_int(pcm16b_swb32, 95, "RTP payload type for PCM16b-swb32 (32 kHz)");
102DEFINE_int(pcm16b_swb48, 96, "RTP payload type for PCM16b-swb48 (48 kHz)");
103DEFINE_int(g722, 9, "RTP payload type for G.722");
104DEFINE_int(avt, 106, "RTP payload type for AVT/DTMF (8 kHz)");
105DEFINE_int(avt_16, 114, "RTP payload type for AVT/DTMF (16 kHz)");
106DEFINE_int(avt_32, 115, "RTP payload type for AVT/DTMF (32 kHz)");
107DEFINE_int(avt_48, 116, "RTP payload type for AVT/DTMF (48 kHz)");
108DEFINE_int(red, 117, "RTP payload type for redundant audio (RED)");
109DEFINE_int(cn_nb, 13, "RTP payload type for comfort noise (8 kHz)");
110DEFINE_int(cn_wb, 98, "RTP payload type for comfort noise (16 kHz)");
111DEFINE_int(cn_swb32, 99, "RTP payload type for comfort noise (32 kHz)");
112DEFINE_int(cn_swb48, 100, "RTP payload type for comfort noise (48 kHz)");
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000113DEFINE_bool(codec_map, false, "Prints the mapping between RTP payload type and "
114 "codec");
henrik.lundin@webrtc.org75642fc2014-02-05 08:49:13 +0000115DEFINE_string(replacement_audio_file, "",
116 "A PCM file that will be used to populate ""dummy"" RTP packets");
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +0000117DEFINE_string(ssrc,
118 "",
119 "Only use packets with this SSRC (decimal or hex, the latter "
120 "starting with 0x)");
oprypin6e09d872017-08-31 03:21:39 -0700121DEFINE_int(audio_level, 1, "Extension ID for audio level (RFC 6464)");
122DEFINE_int(abs_send_time, 3, "Extension ID for absolute sender time");
123DEFINE_int(transport_seq_no, 5, "Extension ID for transport sequence number");
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200124DEFINE_bool(matlabplot,
125 false,
126 "Generates a matlab script for plotting the delay profile");
Ivo Creusend1d8dfb2017-12-06 10:48:10 +0100127DEFINE_bool(pythonplot,
128 false,
129 "Generates a python script for plotting the delay profile");
oprypin6e09d872017-08-31 03:21:39 -0700130DEFINE_bool(help, false, "Prints this message");
Alex Narest7ff6ca52018-02-07 18:46:33 +0100131DEFINE_bool(concealment_events, false, "Prints concealment events");
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000132
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000133// Maps a codec type to a printable name string.
henrik.lundince5570e2016-05-24 06:14:57 -0700134std::string CodecName(NetEqDecoder codec) {
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000135 switch (codec) {
henrik.lundince5570e2016-05-24 06:14:57 -0700136 case NetEqDecoder::kDecoderPCMu:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000137 return "PCM-u";
henrik.lundince5570e2016-05-24 06:14:57 -0700138 case NetEqDecoder::kDecoderPCMa:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000139 return "PCM-a";
henrik.lundince5570e2016-05-24 06:14:57 -0700140 case NetEqDecoder::kDecoderILBC:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000141 return "iLBC";
henrik.lundince5570e2016-05-24 06:14:57 -0700142 case NetEqDecoder::kDecoderISAC:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000143 return "iSAC";
henrik.lundince5570e2016-05-24 06:14:57 -0700144 case NetEqDecoder::kDecoderISACswb:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000145 return "iSAC-swb (32 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700146 case NetEqDecoder::kDecoderOpus:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000147 return "Opus";
henrik.lundince5570e2016-05-24 06:14:57 -0700148 case NetEqDecoder::kDecoderPCM16B:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000149 return "PCM16b-nb (8 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700150 case NetEqDecoder::kDecoderPCM16Bwb:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000151 return "PCM16b-wb (16 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700152 case NetEqDecoder::kDecoderPCM16Bswb32kHz:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000153 return "PCM16b-swb32 (32 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700154 case NetEqDecoder::kDecoderPCM16Bswb48kHz:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000155 return "PCM16b-swb48 (48 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700156 case NetEqDecoder::kDecoderG722:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000157 return "G.722";
henrik.lundince5570e2016-05-24 06:14:57 -0700158 case NetEqDecoder::kDecoderRED:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000159 return "redundant audio (RED)";
henrik.lundince5570e2016-05-24 06:14:57 -0700160 case NetEqDecoder::kDecoderAVT:
solenberg2779bab2016-11-17 04:45:19 -0800161 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.lundince5570e2016-05-24 06:14:57 -0700168 case NetEqDecoder::kDecoderCNGnb:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000169 return "comfort noise (8 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700170 case NetEqDecoder::kDecoderCNGwb:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000171 return "comfort noise (16 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700172 case NetEqDecoder::kDecoderCNGswb32kHz:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000173 return "comfort noise (32 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700174 case NetEqDecoder::kDecoderCNGswb48kHz:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000175 return "comfort noise (48 kHz)";
176 default:
henrik.lundine8a77e32016-06-22 06:34:03 -0700177 FATAL();
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000178 return "undefined";
179 }
180}
181
oprypin6e09d872017-08-31 03:21:39 -0700182void PrintCodecMappingEntry(NetEqDecoder codec, int flag) {
pkasting@chromium.orgd3245462015-02-23 21:28:22 +0000183 std::cout << CodecName(codec) << ": " << flag << std::endl;
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000184}
185
186void PrintCodecMapping() {
oprypin6e09d872017-08-31 03:21:39 -0700187 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.lundince5570e2016-05-24 06:14:57 -0700195 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb32kHz,
oprypin6e09d872017-08-31 03:21:39 -0700196 FLAG_pcm16b_swb32);
henrik.lundince5570e2016-05-24 06:14:57 -0700197 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb48kHz,
oprypin6e09d872017-08-31 03:21:39 -0700198 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.org4dba2e92015-01-26 19:59:32 +0000209}
210
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200211rtc::Optional<int> CodecSampleRate(uint8_t payload_type) {
oprypin6e09d872017-08-31 03:21:39 -0700212 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 Sundbom12ab00b2017-11-16 15:31:38 +0100215 return 8000;
oprypin6e09d872017-08-31 03:21:39 -0700216 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 Sundbom12ab00b2017-11-16 15:31:38 +0100219 return 16000;
oprypin6e09d872017-08-31 03:21:39 -0700220 if (payload_type == FLAG_isac_swb || payload_type == FLAG_pcm16b_swb32 ||
221 payload_type == FLAG_cn_swb32 || payload_type == FLAG_avt_32)
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100222 return 32000;
oprypin6e09d872017-08-31 03:21:39 -0700223 if (payload_type == FLAG_opus || payload_type == FLAG_pcm16b_swb48 ||
224 payload_type == FLAG_cn_swb48 || payload_type == FLAG_avt_48)
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100225 return 48000;
oprypin6e09d872017-08-31 03:21:39 -0700226 if (payload_type == FLAG_red)
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100227 return 0;
228 return rtc::nullopt;
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000229}
230
henrik.lundine8a77e32016-06-22 06:34:03 -0700231// Class to let through only the packets with a given SSRC. Should be used as an
232// outer layer on another NetEqInput object.
233class 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.lundind4ec9702016-09-06 01:22:45 -0700238 RTC_CHECK(source_->NextHeader()) << "Found no packet with SSRC = 0x"
239 << std::hex << ssrc_;
henrik.lundine8a77e32016-06-22 06:34:03 -0700240 }
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000241
henrik.lundine8a77e32016-06-22 06:34:03 -0700242 // 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.lundin246ef3e2017-04-24 09:14:32 -0700254 RTC_DCHECK(!packet_to_return || packet_to_return->header.ssrc == ssrc_);
henrik.lundine8a77e32016-06-22 06:34:03 -0700255 // 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.org4dba2e92015-01-26 19:59:32 +0000274 }
275 }
henrik.lundine8a77e32016-06-22 06:34:03 -0700276
277 std::unique_ptr<NetEqInput> source_;
278 uint32_t ssrc_;
279};
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000280
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200281// A callback class which prints whenver the inserted packet stream changes
282// the SSRC.
283class 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 Lundina2af0002017-06-20 16:54:39 +0200288 explicit SsrcSwitchDetector(NetEqPostInsertPacket* other_callback)
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200289 : other_callback_(other_callback) {}
290
Henrik Lundina2af0002017-06-20 16:54:39 +0200291 void AfterInsertPacket(const NetEqInput::PacketData& packet,
292 NetEq* neteq) override {
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200293 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 Sundbom12ab00b2017-11-16 15:31:38 +0100300 last_ssrc_ = packet.header.ssrc;
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200301 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 Lundina2af0002017-06-20 16:54:39 +0200311class 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 Lundina2af0002017-06-20 16:54:39 +0200320 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-webrtc0c3ca752017-08-23 15:59:38 +0200325 double secondary_discarded_rate = 0.0;
Henrik Lundina2af0002017-06-20 16:54:39 +0200326 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
Alex Narest7ff6ca52018-02-07 18:46:33 +0100334 struct ConcealmentEvent {
335 uint64_t duration_ms;
336 size_t concealment_event_number;
337 int64_t time_from_previous_event_end_ms;
338
339 friend std::ostream& operator<<(std::ostream& stream,
340 const ConcealmentEvent& concealment_event) {
341 stream << "ConcealmentEvent duration_ms:" << concealment_event.duration_ms
342 << " event_number:" << concealment_event.concealment_event_number
343 << " time_from_previous_event_end_ms:"
344 << concealment_event.time_from_previous_event_end_ms << "\n";
345 return stream;
346 }
347 };
348
Henrik Lundina2af0002017-06-20 16:54:39 +0200349 // Takes a pointer to another callback object, which will be invoked after
350 // this object finishes. This does not transfer ownership, and null is a
351 // valid value.
352 explicit StatsGetter(NetEqGetAudioCallback* other_callback)
353 : other_callback_(other_callback) {}
354
355 void BeforeGetAudio(NetEq* neteq) override {
356 if (other_callback_) {
357 other_callback_->BeforeGetAudio(neteq);
358 }
359 }
360
361 void AfterGetAudio(int64_t time_now_ms,
362 const AudioFrame& audio_frame,
363 bool muted,
364 NetEq* neteq) override {
365 if (++counter_ >= 100) {
366 counter_ = 0;
367 NetEqNetworkStatistics stats;
368 RTC_CHECK_EQ(neteq->NetworkStatistics(&stats), 0);
369 stats_.push_back(stats);
370 }
Alex Narest7ff6ca52018-02-07 18:46:33 +0100371 const auto lifetime_stat = neteq->GetLifetimeStatistics();
Alex Narest2734a062018-04-11 13:49:33 +0200372 if (current_concealment_event_ != lifetime_stat.concealment_events &&
373 voice_concealed_samples_until_last_event_ <
374 lifetime_stat.voice_concealed_samples) {
Alex Narest7ff6ca52018-02-07 18:46:33 +0100375 if (last_event_end_time_ms_ > 0) {
376 // Do not account for the first event to avoid start of the call
377 // skewing.
378 ConcealmentEvent concealment_event;
379 uint64_t last_event_voice_concealed_samples =
380 lifetime_stat.voice_concealed_samples -
381 voice_concealed_samples_until_last_event_;
382 RTC_CHECK_GT(last_event_voice_concealed_samples, 0);
383 concealment_event.duration_ms = last_event_voice_concealed_samples /
384 (audio_frame.sample_rate_hz_ / 1000);
385 concealment_event.concealment_event_number = current_concealment_event_;
386 concealment_event.time_from_previous_event_end_ms =
387 time_now_ms - last_event_end_time_ms_;
388 concealment_events_.emplace_back(concealment_event);
389 voice_concealed_samples_until_last_event_ =
390 lifetime_stat.voice_concealed_samples;
391 }
392 last_event_end_time_ms_ = time_now_ms;
393 voice_concealed_samples_until_last_event_ =
394 lifetime_stat.voice_concealed_samples;
395 current_concealment_event_ = lifetime_stat.concealment_events;
396 }
397
Henrik Lundina2af0002017-06-20 16:54:39 +0200398 if (other_callback_) {
henrik.lundinf09c9042017-08-29 09:14:08 -0700399 other_callback_->AfterGetAudio(time_now_ms, audio_frame, muted, neteq);
Henrik Lundina2af0002017-06-20 16:54:39 +0200400 }
401 }
402
403 double AverageSpeechExpandRate() const {
404 double sum_speech_expand =
405 std::accumulate(stats_.begin(), stats_.end(), double{0.0},
406 [](double a, NetEqNetworkStatistics b) {
407 return a + static_cast<double>(b.speech_expand_rate);
408 });
409 return sum_speech_expand / 16384.0 / stats_.size();
410 }
411
Alex Narest7ff6ca52018-02-07 18:46:33 +0100412 const std::vector<ConcealmentEvent>& concealment_events() {
413 // Do not account for the last concealment event to avoid potential end
414 // call skewing.
415 return concealment_events_;
416 }
417
Henrik Lundina2af0002017-06-20 16:54:39 +0200418 Stats AverageStats() const {
419 Stats sum_stats = std::accumulate(
420 stats_.begin(), stats_.end(), Stats(),
421 [](Stats a, NetEqNetworkStatistics b) {
422 a.current_buffer_size_ms += b.current_buffer_size_ms;
423 a.preferred_buffer_size_ms += b.preferred_buffer_size_ms;
424 a.jitter_peaks_found += b.jitter_peaks_found;
425 a.packet_loss_rate += b.packet_loss_rate / 16384.0;
Henrik Lundina2af0002017-06-20 16:54:39 +0200426 a.expand_rate += b.expand_rate / 16384.0;
427 a.speech_expand_rate += b.speech_expand_rate / 16384.0;
428 a.preemptive_rate += b.preemptive_rate / 16384.0;
429 a.accelerate_rate += b.accelerate_rate / 16384.0;
430 a.secondary_decoded_rate += b.secondary_decoded_rate / 16384.0;
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200431 a.secondary_discarded_rate += b.secondary_discarded_rate / 16384.0;
Henrik Lundina2af0002017-06-20 16:54:39 +0200432 a.clockdrift_ppm += b.clockdrift_ppm;
433 a.added_zero_samples += b.added_zero_samples;
434 a.mean_waiting_time_ms += b.mean_waiting_time_ms;
435 a.median_waiting_time_ms += b.median_waiting_time_ms;
henrik.lundin96571722017-08-30 00:41:30 -0700436 a.min_waiting_time_ms =
437 std::min(a.min_waiting_time_ms,
438 static_cast<double>(b.min_waiting_time_ms));
439 a.max_waiting_time_ms =
440 std::max(a.max_waiting_time_ms,
441 static_cast<double>(b.max_waiting_time_ms));
Henrik Lundina2af0002017-06-20 16:54:39 +0200442 return a;
443 });
444
445 sum_stats.current_buffer_size_ms /= stats_.size();
446 sum_stats.preferred_buffer_size_ms /= stats_.size();
447 sum_stats.jitter_peaks_found /= stats_.size();
448 sum_stats.packet_loss_rate /= stats_.size();
Henrik Lundina2af0002017-06-20 16:54:39 +0200449 sum_stats.expand_rate /= stats_.size();
450 sum_stats.speech_expand_rate /= stats_.size();
451 sum_stats.preemptive_rate /= stats_.size();
452 sum_stats.accelerate_rate /= stats_.size();
453 sum_stats.secondary_decoded_rate /= stats_.size();
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200454 sum_stats.secondary_discarded_rate /= stats_.size();
Henrik Lundina2af0002017-06-20 16:54:39 +0200455 sum_stats.clockdrift_ppm /= stats_.size();
456 sum_stats.added_zero_samples /= stats_.size();
457 sum_stats.mean_waiting_time_ms /= stats_.size();
458 sum_stats.median_waiting_time_ms /= stats_.size();
Henrik Lundina2af0002017-06-20 16:54:39 +0200459
460 return sum_stats;
461 }
462
463 private:
464 NetEqGetAudioCallback* other_callback_;
465 size_t counter_ = 0;
466 std::vector<NetEqNetworkStatistics> stats_;
Alex Narest7ff6ca52018-02-07 18:46:33 +0100467 size_t current_concealment_event_ = 1;
468 uint64_t voice_concealed_samples_until_last_event_ = 0;
469 std::vector<ConcealmentEvent> concealment_events_;
470 int64_t last_event_end_time_ms_ = 0;
Henrik Lundina2af0002017-06-20 16:54:39 +0200471};
472
henrik.lundin303d3e12016-05-26 05:56:03 -0700473int RunTest(int argc, char* argv[]) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000474 std::string program_name = argv[0];
475 std::string usage = "Tool for decoding an RTP dump file using NetEq.\n"
oprypin6e09d872017-08-31 03:21:39 -0700476 "Run " + program_name + " --help for usage.\n"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000477 "Example usage:\n" + program_name +
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000478 " input.rtp output.{pcm, wav}\n";
oprypin6e09d872017-08-31 03:21:39 -0700479 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) {
480 return 1;
481 }
482 if (FLAG_help) {
483 std::cout << usage;
484 rtc::FlagList::Print(nullptr, false);
485 return 0;
486 }
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000487
oprypin6e09d872017-08-31 03:21:39 -0700488 if (FLAG_codec_map) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000489 PrintCodecMapping();
490 }
491
492 if (argc != 3) {
oprypin6e09d872017-08-31 03:21:39 -0700493 if (FLAG_codec_map) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000494 // We have already printed the codec map. Just end the program.
495 return 0;
496 }
497 // Print usage information.
oprypin6e09d872017-08-31 03:21:39 -0700498 std::cout << usage;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000499 return 0;
500 }
oprypin6e09d872017-08-31 03:21:39 -0700501 RTC_CHECK(ValidatePayloadType(FLAG_pcmu));
502 RTC_CHECK(ValidatePayloadType(FLAG_pcma));
503 RTC_CHECK(ValidatePayloadType(FLAG_ilbc));
504 RTC_CHECK(ValidatePayloadType(FLAG_isac));
505 RTC_CHECK(ValidatePayloadType(FLAG_isac_swb));
506 RTC_CHECK(ValidatePayloadType(FLAG_opus));
507 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b));
508 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_wb));
509 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb32));
510 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb48));
511 RTC_CHECK(ValidatePayloadType(FLAG_g722));
512 RTC_CHECK(ValidatePayloadType(FLAG_avt));
513 RTC_CHECK(ValidatePayloadType(FLAG_avt_16));
514 RTC_CHECK(ValidatePayloadType(FLAG_avt_32));
515 RTC_CHECK(ValidatePayloadType(FLAG_avt_48));
516 RTC_CHECK(ValidatePayloadType(FLAG_red));
517 RTC_CHECK(ValidatePayloadType(FLAG_cn_nb));
518 RTC_CHECK(ValidatePayloadType(FLAG_cn_wb));
519 RTC_CHECK(ValidatePayloadType(FLAG_cn_swb32));
520 RTC_CHECK(ValidatePayloadType(FLAG_cn_swb48));
521 RTC_CHECK(ValidateSsrcValue(FLAG_ssrc));
522 RTC_CHECK(ValidateExtensionId(FLAG_audio_level));
523 RTC_CHECK(ValidateExtensionId(FLAG_abs_send_time));
524 RTC_CHECK(ValidateExtensionId(FLAG_transport_seq_no));
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000525
henrik.lundin8a6a6002016-08-25 00:46:36 -0700526 // Gather RTP header extensions in a map.
527 NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = {
oprypin6e09d872017-08-31 03:21:39 -0700528 {FLAG_audio_level, kRtpExtensionAudioLevel},
529 {FLAG_abs_send_time, kRtpExtensionAbsoluteSendTime},
530 {FLAG_transport_seq_no, kRtpExtensionTransportSequenceNumber}};
henrik.lundin8a6a6002016-08-25 00:46:36 -0700531
henrik.lundine8a77e32016-06-22 06:34:03 -0700532 const std::string input_file_name = argv[1];
533 std::unique_ptr<NetEqInput> input;
534 if (RtpFileSource::ValidRtpDump(input_file_name) ||
535 RtpFileSource::ValidPcap(input_file_name)) {
henrik.lundin8a6a6002016-08-25 00:46:36 -0700536 input.reset(new NetEqRtpDumpInput(input_file_name, rtp_ext_map));
ivoccaa5f4b2015-09-08 03:28:46 -0700537 } else {
henrik.lundin8a6a6002016-08-25 00:46:36 -0700538 input.reset(new NetEqEventLogInput(input_file_name, rtp_ext_map));
ivoccaa5f4b2015-09-08 03:28:46 -0700539 }
540
henrik.lundine8a77e32016-06-22 06:34:03 -0700541 std::cout << "Input file: " << input_file_name << std::endl;
542 RTC_CHECK(input) << "Cannot open input file";
543 RTC_CHECK(!input->ended()) << "Input file is empty";
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000544
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +0000545 // Check if an SSRC value was provided.
oprypin6e09d872017-08-31 03:21:39 -0700546 if (strlen(FLAG_ssrc) > 0) {
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +0000547 uint32_t ssrc;
oprypin6e09d872017-08-31 03:21:39 -0700548 RTC_CHECK(ParseSsrc(FLAG_ssrc, &ssrc)) << "Flag verification has failed.";
henrik.lundine8a77e32016-06-22 06:34:03 -0700549 input.reset(new FilterSsrcInput(std::move(input), ssrc));
ivoccaa5f4b2015-09-08 03:28:46 -0700550 }
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000551
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000552 // Check the sample rate.
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200553 rtc::Optional<int> sample_rate_hz;
554 std::set<std::pair<int, uint32_t>> discarded_pt_and_ssrc;
555 while (input->NextHeader()) {
556 rtc::Optional<RTPHeader> first_rtp_header = input->NextHeader();
557 RTC_DCHECK(first_rtp_header);
558 sample_rate_hz = CodecSampleRate(first_rtp_header->payloadType);
559 if (sample_rate_hz) {
560 std::cout << "Found valid packet with payload type "
561 << static_cast<int>(first_rtp_header->payloadType)
562 << " and SSRC 0x" << std::hex << first_rtp_header->ssrc
563 << std::dec << std::endl;
564 break;
565 }
566 // Discard this packet and move to the next. Keep track of discarded payload
567 // types and SSRCs.
568 discarded_pt_and_ssrc.emplace(first_rtp_header->payloadType,
569 first_rtp_header->ssrc);
570 input->PopPacket();
571 }
572 if (!discarded_pt_and_ssrc.empty()) {
573 std::cout << "Discarded initial packets with the following payload types "
574 "and SSRCs:"
575 << std::endl;
576 for (const auto& d : discarded_pt_and_ssrc) {
577 std::cout << "PT " << d.first << "; SSRC 0x" << std::hex
578 << static_cast<int>(d.second) << std::dec << std::endl;
579 }
580 }
581 if (!sample_rate_hz) {
582 std::cout << "Cannot find any packets with known payload types"
583 << std::endl;
584 RTC_NOTREACHED();
585 }
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000586
587 // Open the output file now that we know the sample rate. (Rate is only needed
588 // for wav files.)
henrik.lundine8a77e32016-06-22 06:34:03 -0700589 const std::string output_file_name = argv[2];
henrik.lundince5570e2016-05-24 06:14:57 -0700590 std::unique_ptr<AudioSink> output;
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000591 if (output_file_name.size() >= 4 &&
592 output_file_name.substr(output_file_name.size() - 4) == ".wav") {
593 // Open a wav file.
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200594 output.reset(new OutputWavFile(output_file_name, *sample_rate_hz));
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000595 } else {
596 // Open a pcm file.
henrik.lundince5570e2016-05-24 06:14:57 -0700597 output.reset(new OutputAudioFile(output_file_name));
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000598 }
599
henrik.lundine8a77e32016-06-22 06:34:03 -0700600 std::cout << "Output file: " << output_file_name << std::endl;
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000601
henrik.lundine8a77e32016-06-22 06:34:03 -0700602 NetEqTest::DecoderMap codecs = {
oprypin6e09d872017-08-31 03:21:39 -0700603 {FLAG_pcmu, std::make_pair(NetEqDecoder::kDecoderPCMu, "pcmu")},
604 {FLAG_pcma, std::make_pair(NetEqDecoder::kDecoderPCMa, "pcma")},
605 {FLAG_ilbc, std::make_pair(NetEqDecoder::kDecoderILBC, "ilbc")},
606 {FLAG_isac, std::make_pair(NetEqDecoder::kDecoderISAC, "isac")},
607 {FLAG_isac_swb,
henrik.lundine8a77e32016-06-22 06:34:03 -0700608 std::make_pair(NetEqDecoder::kDecoderISACswb, "isac-swb")},
oprypin6e09d872017-08-31 03:21:39 -0700609 {FLAG_opus, std::make_pair(NetEqDecoder::kDecoderOpus, "opus")},
610 {FLAG_pcm16b, std::make_pair(NetEqDecoder::kDecoderPCM16B, "pcm16-nb")},
611 {FLAG_pcm16b_wb,
henrik.lundine8a77e32016-06-22 06:34:03 -0700612 std::make_pair(NetEqDecoder::kDecoderPCM16Bwb, "pcm16-wb")},
oprypin6e09d872017-08-31 03:21:39 -0700613 {FLAG_pcm16b_swb32,
henrik.lundine8a77e32016-06-22 06:34:03 -0700614 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb32kHz, "pcm16-swb32")},
oprypin6e09d872017-08-31 03:21:39 -0700615 {FLAG_pcm16b_swb48,
henrik.lundine8a77e32016-06-22 06:34:03 -0700616 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb48kHz, "pcm16-swb48")},
oprypin6e09d872017-08-31 03:21:39 -0700617 {FLAG_g722, std::make_pair(NetEqDecoder::kDecoderG722, "g722")},
618 {FLAG_avt, std::make_pair(NetEqDecoder::kDecoderAVT, "avt")},
619 {FLAG_avt_16, std::make_pair(NetEqDecoder::kDecoderAVT16kHz, "avt-16")},
620 {FLAG_avt_32,
solenberg2779bab2016-11-17 04:45:19 -0800621 std::make_pair(NetEqDecoder::kDecoderAVT32kHz, "avt-32")},
oprypin6e09d872017-08-31 03:21:39 -0700622 {FLAG_avt_48,
solenberg2779bab2016-11-17 04:45:19 -0800623 std::make_pair(NetEqDecoder::kDecoderAVT48kHz, "avt-48")},
oprypin6e09d872017-08-31 03:21:39 -0700624 {FLAG_red, std::make_pair(NetEqDecoder::kDecoderRED, "red")},
625 {FLAG_cn_nb, std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb")},
626 {FLAG_cn_wb, std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb")},
627 {FLAG_cn_swb32,
henrik.lundine8a77e32016-06-22 06:34:03 -0700628 std::make_pair(NetEqDecoder::kDecoderCNGswb32kHz, "cng-swb32")},
oprypin6e09d872017-08-31 03:21:39 -0700629 {FLAG_cn_swb48,
henrik.lundine8a77e32016-06-22 06:34:03 -0700630 std::make_pair(NetEqDecoder::kDecoderCNGswb48kHz, "cng-swb48")}};
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000631
henrik.lundine8a77e32016-06-22 06:34:03 -0700632 // Check if a replacement audio file was provided.
633 std::unique_ptr<AudioDecoder> replacement_decoder;
634 NetEqTest::ExtDecoderMap ext_codecs;
oprypin6e09d872017-08-31 03:21:39 -0700635 if (strlen(FLAG_replacement_audio_file) > 0) {
henrik.lundine8a77e32016-06-22 06:34:03 -0700636 // Find largest unused payload type.
637 int replacement_pt = 127;
638 while (!(codecs.find(replacement_pt) == codecs.end() &&
639 ext_codecs.find(replacement_pt) == ext_codecs.end())) {
640 --replacement_pt;
641 RTC_CHECK_GE(replacement_pt, 0);
642 }
643
644 auto std_set_int32_to_uint8 = [](const std::set<int32_t>& a) {
645 std::set<uint8_t> b;
646 for (auto& x : a) {
647 b.insert(static_cast<uint8_t>(x));
648 }
649 return b;
650 };
651
652 std::set<uint8_t> cn_types = std_set_int32_to_uint8(
oprypin6e09d872017-08-31 03:21:39 -0700653 {FLAG_cn_nb, FLAG_cn_wb, FLAG_cn_swb32, FLAG_cn_swb48});
henrik.lundine8a77e32016-06-22 06:34:03 -0700654 std::set<uint8_t> forbidden_types =
oprypin6e09d872017-08-31 03:21:39 -0700655 std_set_int32_to_uint8({FLAG_g722, FLAG_red, FLAG_avt,
656 FLAG_avt_16, FLAG_avt_32, FLAG_avt_48});
henrik.lundine8a77e32016-06-22 06:34:03 -0700657 input.reset(new NetEqReplacementInput(std::move(input), replacement_pt,
658 cn_types, forbidden_types));
659
660 replacement_decoder.reset(new FakeDecodeFromFile(
661 std::unique_ptr<InputAudioFile>(
oprypin6e09d872017-08-31 03:21:39 -0700662 new InputAudioFile(FLAG_replacement_audio_file)),
henrik.lundine8a77e32016-06-22 06:34:03 -0700663 48000, false));
664 NetEqTest::ExternalDecoderInfo ext_dec_info = {
665 replacement_decoder.get(), NetEqDecoder::kDecoderArbitrary,
666 "replacement codec"};
667 ext_codecs[replacement_pt] = ext_dec_info;
668 }
669
henrik.lundin02739d92017-05-04 06:09:06 -0700670 NetEqTest::Callbacks callbacks;
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200671 std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer;
Ivo Creusend1d8dfb2017-12-06 10:48:10 +0100672 if (FLAG_matlabplot || FLAG_pythonplot) {
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200673 delay_analyzer.reset(new NetEqDelayAnalyzer);
674 }
675
676 SsrcSwitchDetector ssrc_switch_detector(delay_analyzer.get());
677 callbacks.post_insert_packet = &ssrc_switch_detector;
Henrik Lundina2af0002017-06-20 16:54:39 +0200678 StatsGetter stats_getter(delay_analyzer.get());
679 callbacks.get_audio_callback = &stats_getter;
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000680 NetEq::Config config;
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200681 config.sample_rate_hz = *sample_rate_hz;
henrik.lundine8a77e32016-06-22 06:34:03 -0700682 NetEqTest test(config, codecs, ext_codecs, std::move(input),
henrik.lundin02739d92017-05-04 06:09:06 -0700683 std::move(output), callbacks);
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000684
henrik.lundine8a77e32016-06-22 06:34:03 -0700685 int64_t test_duration_ms = test.Run();
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000686
oprypin6e09d872017-08-31 03:21:39 -0700687 if (FLAG_matlabplot) {
henrik.lundinf09c9042017-08-29 09:14:08 -0700688 auto matlab_script_name = output_file_name;
689 std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.',
690 '_');
691 std::cout << "Creating Matlab plot script " << matlab_script_name + ".m"
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200692 << std::endl;
henrik.lundinf09c9042017-08-29 09:14:08 -0700693 delay_analyzer->CreateMatlabScript(matlab_script_name + ".m");
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200694 }
Ivo Creusend1d8dfb2017-12-06 10:48:10 +0100695 if (FLAG_pythonplot) {
696 auto python_script_name = output_file_name;
697 std::replace(python_script_name.begin(), python_script_name.end(), '.',
698 '_');
699 std::cout << "Creating Python plot script " << python_script_name + ".py"
700 << std::endl;
701 delay_analyzer->CreatePythonScript(python_script_name + ".py");
702 }
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200703
henrik.lundine8a77e32016-06-22 06:34:03 -0700704 printf("Simulation statistics:\n");
705 printf(" output duration: %" PRId64 " ms\n", test_duration_ms);
Henrik Lundina2af0002017-06-20 16:54:39 +0200706 auto stats = stats_getter.AverageStats();
707 printf(" packet_loss_rate: %f %%\n", 100.0 * stats.packet_loss_rate);
Henrik Lundina2af0002017-06-20 16:54:39 +0200708 printf(" expand_rate: %f %%\n", 100.0 * stats.expand_rate);
709 printf(" speech_expand_rate: %f %%\n", 100.0 * stats.speech_expand_rate);
710 printf(" preemptive_rate: %f %%\n", 100.0 * stats.preemptive_rate);
711 printf(" accelerate_rate: %f %%\n", 100.0 * stats.accelerate_rate);
henrik.lundine8a77e32016-06-22 06:34:03 -0700712 printf(" secondary_decoded_rate: %f %%\n",
Henrik Lundina2af0002017-06-20 16:54:39 +0200713 100.0 * stats.secondary_decoded_rate);
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200714 printf(" secondary_discarded_rate: %f %%\n",
715 100.0 * stats.secondary_discarded_rate);
Henrik Lundina2af0002017-06-20 16:54:39 +0200716 printf(" clockdrift_ppm: %f ppm\n", stats.clockdrift_ppm);
717 printf(" mean_waiting_time_ms: %f ms\n", stats.mean_waiting_time_ms);
718 printf(" median_waiting_time_ms: %f ms\n", stats.median_waiting_time_ms);
719 printf(" min_waiting_time_ms: %f ms\n", stats.min_waiting_time_ms);
720 printf(" max_waiting_time_ms: %f ms\n", stats.max_waiting_time_ms);
Henrik Lundin156af4a2017-11-17 16:46:18 +0100721 printf(" current_buffer_size_ms: %f ms\n", stats.current_buffer_size_ms);
722 printf(" preferred_buffer_size_ms: %f ms\n", stats.preferred_buffer_size_ms);
Alex Narest7ff6ca52018-02-07 18:46:33 +0100723 if (FLAG_concealment_events) {
724 std::cout << " concealment_events_ms:"
725 << "\n";
726 for (auto concealment_event : stats_getter.concealment_events())
727 std::cout << concealment_event;
728 std::cout << " end of concealment_events_ms\n";
729 }
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000730 return 0;
731}
henrik.lundince5570e2016-05-24 06:14:57 -0700732
henrik.lundin303d3e12016-05-26 05:56:03 -0700733} // namespace
henrik.lundince5570e2016-05-24 06:14:57 -0700734} // namespace test
735} // namespace webrtc
henrik.lundin303d3e12016-05-26 05:56:03 -0700736
737int main(int argc, char* argv[]) {
Robin Raymond1c62ffa2017-12-03 16:45:56 -0500738 return webrtc::test::RunTest(argc, argv);
henrik.lundin303d3e12016-05-26 05:56:03 -0700739}