blob: 8c1fa38c471cd25c9caf79167d8c1c6d6be0557e [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"
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 Bonadei71207422017-09-15 13:58:09 +020039#include "typedefs.h" // NOLINT(build/include)
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000040
henrik.lundince5570e2016-05-24 06:14:57 -070041namespace webrtc {
42namespace test {
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +000043namespace {
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +000044
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +000045// 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.
48bool ParseSsrc(const std::string& str, uint32_t* ssrc) {
49 if (str.empty())
henrik.lundin@webrtc.org91039532014-10-07 07:18:36 +000050 return true;
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +000051 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.orgd94659d2013-01-29 12:09:21 +000068// Flag validators.
oprypin6e09d872017-08-31 03:21:39 -070069bool ValidatePayloadType(int value) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000070 if (value >= 0 && value <= 127) // Value is ok.
71 return true;
oprypin6e09d872017-08-31 03:21:39 -070072 printf("Payload type must be between 0 and 127, not %d\n",
73 static_cast<int>(value));
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000074 return false;
75}
76
oprypin6e09d872017-08-31 03:21:39 -070077bool ValidateSsrcValue(const std::string& str) {
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +000078 uint32_t dummy_ssrc;
oprypin6e09d872017-08-31 03:21:39 -070079 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.org8b65d512014-10-07 05:30:04 +000083}
84
oprypin6e09d872017-08-31 03:21:39 -070085static bool ValidateExtensionId(int value) {
henrik.lundin8a6a6002016-08-25 00:46:36 -070086 if (value > 0 && value <= 255) // Value is ok.
87 return true;
oprypin6e09d872017-08-31 03:21:39 -070088 printf("Extension ID must be between 1 and 255, not %d\n",
89 static_cast<int>(value));
henrik.lundin8a6a6002016-08-25 00:46:36 -070090 return false;
91}
92
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000093// Define command line flags.
oprypin6e09d872017-08-31 03:21:39 -070094DEFINE_int(pcmu, 0, "RTP payload type for PCM-u");
95DEFINE_int(pcma, 8, "RTP payload type for PCM-a");
96DEFINE_int(ilbc, 102, "RTP payload type for iLBC");
97DEFINE_int(isac, 103, "RTP payload type for iSAC");
98DEFINE_int(isac_swb, 104, "RTP payload type for iSAC-swb (32 kHz)");
99DEFINE_int(opus, 111, "RTP payload type for Opus");
100DEFINE_int(pcm16b, 93, "RTP payload type for PCM16b-nb (8 kHz)");
101DEFINE_int(pcm16b_wb, 94, "RTP payload type for PCM16b-wb (16 kHz)");
102DEFINE_int(pcm16b_swb32, 95, "RTP payload type for PCM16b-swb32 (32 kHz)");
103DEFINE_int(pcm16b_swb48, 96, "RTP payload type for PCM16b-swb48 (48 kHz)");
104DEFINE_int(g722, 9, "RTP payload type for G.722");
105DEFINE_int(avt, 106, "RTP payload type for AVT/DTMF (8 kHz)");
106DEFINE_int(avt_16, 114, "RTP payload type for AVT/DTMF (16 kHz)");
107DEFINE_int(avt_32, 115, "RTP payload type for AVT/DTMF (32 kHz)");
108DEFINE_int(avt_48, 116, "RTP payload type for AVT/DTMF (48 kHz)");
109DEFINE_int(red, 117, "RTP payload type for redundant audio (RED)");
110DEFINE_int(cn_nb, 13, "RTP payload type for comfort noise (8 kHz)");
111DEFINE_int(cn_wb, 98, "RTP payload type for comfort noise (16 kHz)");
112DEFINE_int(cn_swb32, 99, "RTP payload type for comfort noise (32 kHz)");
113DEFINE_int(cn_swb48, 100, "RTP payload type for comfort noise (48 kHz)");
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000114DEFINE_bool(codec_map, false, "Prints the mapping between RTP payload type and "
115 "codec");
henrik.lundin@webrtc.org75642fc2014-02-05 08:49:13 +0000116DEFINE_string(replacement_audio_file, "",
117 "A PCM file that will be used to populate ""dummy"" RTP packets");
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +0000118DEFINE_string(ssrc,
119 "",
120 "Only use packets with this SSRC (decimal or hex, the latter "
121 "starting with 0x)");
oprypin6e09d872017-08-31 03:21:39 -0700122DEFINE_int(audio_level, 1, "Extension ID for audio level (RFC 6464)");
123DEFINE_int(abs_send_time, 3, "Extension ID for absolute sender time");
124DEFINE_int(transport_seq_no, 5, "Extension ID for transport sequence number");
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200125DEFINE_bool(matlabplot,
126 false,
127 "Generates a matlab script for plotting the delay profile");
Ivo Creusend1d8dfb2017-12-06 10:48:10 +0100128DEFINE_bool(pythonplot,
129 false,
130 "Generates a python script for plotting the delay profile");
oprypin6e09d872017-08-31 03:21:39 -0700131DEFINE_bool(help, false, "Prints this message");
Alex Narest7ff6ca52018-02-07 18:46:33 +0100132DEFINE_bool(concealment_events, false, "Prints concealment events");
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000133
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000134// Maps a codec type to a printable name string.
henrik.lundince5570e2016-05-24 06:14:57 -0700135std::string CodecName(NetEqDecoder codec) {
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000136 switch (codec) {
henrik.lundince5570e2016-05-24 06:14:57 -0700137 case NetEqDecoder::kDecoderPCMu:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000138 return "PCM-u";
henrik.lundince5570e2016-05-24 06:14:57 -0700139 case NetEqDecoder::kDecoderPCMa:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000140 return "PCM-a";
henrik.lundince5570e2016-05-24 06:14:57 -0700141 case NetEqDecoder::kDecoderILBC:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000142 return "iLBC";
henrik.lundince5570e2016-05-24 06:14:57 -0700143 case NetEqDecoder::kDecoderISAC:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000144 return "iSAC";
henrik.lundince5570e2016-05-24 06:14:57 -0700145 case NetEqDecoder::kDecoderISACswb:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000146 return "iSAC-swb (32 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700147 case NetEqDecoder::kDecoderOpus:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000148 return "Opus";
henrik.lundince5570e2016-05-24 06:14:57 -0700149 case NetEqDecoder::kDecoderPCM16B:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000150 return "PCM16b-nb (8 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700151 case NetEqDecoder::kDecoderPCM16Bwb:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000152 return "PCM16b-wb (16 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700153 case NetEqDecoder::kDecoderPCM16Bswb32kHz:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000154 return "PCM16b-swb32 (32 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700155 case NetEqDecoder::kDecoderPCM16Bswb48kHz:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000156 return "PCM16b-swb48 (48 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700157 case NetEqDecoder::kDecoderG722:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000158 return "G.722";
henrik.lundince5570e2016-05-24 06:14:57 -0700159 case NetEqDecoder::kDecoderRED:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000160 return "redundant audio (RED)";
henrik.lundince5570e2016-05-24 06:14:57 -0700161 case NetEqDecoder::kDecoderAVT:
solenberg2779bab2016-11-17 04:45:19 -0800162 return "AVT/DTMF (8 kHz)";
163 case NetEqDecoder::kDecoderAVT16kHz:
164 return "AVT/DTMF (16 kHz)";
165 case NetEqDecoder::kDecoderAVT32kHz:
166 return "AVT/DTMF (32 kHz)";
167 case NetEqDecoder::kDecoderAVT48kHz:
168 return "AVT/DTMF (48 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700169 case NetEqDecoder::kDecoderCNGnb:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000170 return "comfort noise (8 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700171 case NetEqDecoder::kDecoderCNGwb:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000172 return "comfort noise (16 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700173 case NetEqDecoder::kDecoderCNGswb32kHz:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000174 return "comfort noise (32 kHz)";
henrik.lundince5570e2016-05-24 06:14:57 -0700175 case NetEqDecoder::kDecoderCNGswb48kHz:
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000176 return "comfort noise (48 kHz)";
177 default:
henrik.lundine8a77e32016-06-22 06:34:03 -0700178 FATAL();
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000179 return "undefined";
180 }
181}
182
oprypin6e09d872017-08-31 03:21:39 -0700183void PrintCodecMappingEntry(NetEqDecoder codec, int flag) {
pkasting@chromium.orgd3245462015-02-23 21:28:22 +0000184 std::cout << CodecName(codec) << ": " << flag << std::endl;
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000185}
186
187void PrintCodecMapping() {
oprypin6e09d872017-08-31 03:21:39 -0700188 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMu, FLAG_pcmu);
189 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCMa, FLAG_pcma);
190 PrintCodecMappingEntry(NetEqDecoder::kDecoderILBC, FLAG_ilbc);
191 PrintCodecMappingEntry(NetEqDecoder::kDecoderISAC, FLAG_isac);
192 PrintCodecMappingEntry(NetEqDecoder::kDecoderISACswb, FLAG_isac_swb);
193 PrintCodecMappingEntry(NetEqDecoder::kDecoderOpus, FLAG_opus);
194 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16B, FLAG_pcm16b);
195 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bwb, FLAG_pcm16b_wb);
henrik.lundince5570e2016-05-24 06:14:57 -0700196 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb32kHz,
oprypin6e09d872017-08-31 03:21:39 -0700197 FLAG_pcm16b_swb32);
henrik.lundince5570e2016-05-24 06:14:57 -0700198 PrintCodecMappingEntry(NetEqDecoder::kDecoderPCM16Bswb48kHz,
oprypin6e09d872017-08-31 03:21:39 -0700199 FLAG_pcm16b_swb48);
200 PrintCodecMappingEntry(NetEqDecoder::kDecoderG722, FLAG_g722);
201 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT, FLAG_avt);
202 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT16kHz, FLAG_avt_16);
203 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT32kHz, FLAG_avt_32);
204 PrintCodecMappingEntry(NetEqDecoder::kDecoderAVT48kHz, FLAG_avt_48);
205 PrintCodecMappingEntry(NetEqDecoder::kDecoderRED, FLAG_red);
206 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGnb, FLAG_cn_nb);
207 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGwb, FLAG_cn_wb);
208 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb32kHz, FLAG_cn_swb32);
209 PrintCodecMappingEntry(NetEqDecoder::kDecoderCNGswb48kHz, FLAG_cn_swb48);
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000210}
211
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200212rtc::Optional<int> CodecSampleRate(uint8_t payload_type) {
oprypin6e09d872017-08-31 03:21:39 -0700213 if (payload_type == FLAG_pcmu || payload_type == FLAG_pcma ||
214 payload_type == FLAG_ilbc || payload_type == FLAG_pcm16b ||
215 payload_type == FLAG_cn_nb || payload_type == FLAG_avt)
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100216 return 8000;
oprypin6e09d872017-08-31 03:21:39 -0700217 if (payload_type == FLAG_isac || payload_type == FLAG_pcm16b_wb ||
218 payload_type == FLAG_g722 || payload_type == FLAG_cn_wb ||
219 payload_type == FLAG_avt_16)
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100220 return 16000;
oprypin6e09d872017-08-31 03:21:39 -0700221 if (payload_type == FLAG_isac_swb || payload_type == FLAG_pcm16b_swb32 ||
222 payload_type == FLAG_cn_swb32 || payload_type == FLAG_avt_32)
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100223 return 32000;
oprypin6e09d872017-08-31 03:21:39 -0700224 if (payload_type == FLAG_opus || payload_type == FLAG_pcm16b_swb48 ||
225 payload_type == FLAG_cn_swb48 || payload_type == FLAG_avt_48)
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100226 return 48000;
oprypin6e09d872017-08-31 03:21:39 -0700227 if (payload_type == FLAG_red)
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100228 return 0;
229 return rtc::nullopt;
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000230}
231
henrik.lundine8a77e32016-06-22 06:34:03 -0700232// Class to let through only the packets with a given SSRC. Should be used as an
233// outer layer on another NetEqInput object.
234class FilterSsrcInput : public NetEqInput {
235 public:
236 FilterSsrcInput(std::unique_ptr<NetEqInput> source, uint32_t ssrc)
237 : source_(std::move(source)), ssrc_(ssrc) {
238 FindNextWithCorrectSsrc();
henrik.lundind4ec9702016-09-06 01:22:45 -0700239 RTC_CHECK(source_->NextHeader()) << "Found no packet with SSRC = 0x"
240 << std::hex << ssrc_;
henrik.lundine8a77e32016-06-22 06:34:03 -0700241 }
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000242
henrik.lundine8a77e32016-06-22 06:34:03 -0700243 // All methods but PopPacket() simply relay to the |source_| object.
244 rtc::Optional<int64_t> NextPacketTime() const override {
245 return source_->NextPacketTime();
246 }
247 rtc::Optional<int64_t> NextOutputEventTime() const override {
248 return source_->NextOutputEventTime();
249 }
250
251 // Returns the next packet, and throws away upcoming packets that do not match
252 // the desired SSRC.
253 std::unique_ptr<PacketData> PopPacket() override {
254 std::unique_ptr<PacketData> packet_to_return = source_->PopPacket();
henrik.lundin246ef3e2017-04-24 09:14:32 -0700255 RTC_DCHECK(!packet_to_return || packet_to_return->header.ssrc == ssrc_);
henrik.lundine8a77e32016-06-22 06:34:03 -0700256 // Pre-fetch the next packet with correct SSRC. Hence, |source_| will always
257 // be have a valid packet (or empty if no more packets are available) when
258 // this method returns.
259 FindNextWithCorrectSsrc();
260 return packet_to_return;
261 }
262
263 void AdvanceOutputEvent() override { source_->AdvanceOutputEvent(); }
264
265 bool ended() const override { return source_->ended(); }
266
267 rtc::Optional<RTPHeader> NextHeader() const override {
268 return source_->NextHeader();
269 }
270
271 private:
272 void FindNextWithCorrectSsrc() {
273 while (source_->NextHeader() && source_->NextHeader()->ssrc != ssrc_) {
274 source_->PopPacket();
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000275 }
276 }
henrik.lundine8a77e32016-06-22 06:34:03 -0700277
278 std::unique_ptr<NetEqInput> source_;
279 uint32_t ssrc_;
280};
pkasting@chromium.org4dba2e92015-01-26 19:59:32 +0000281
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200282// A callback class which prints whenver the inserted packet stream changes
283// the SSRC.
284class SsrcSwitchDetector : public NetEqPostInsertPacket {
285 public:
286 // Takes a pointer to another callback object, which will be invoked after
287 // this object finishes. This does not transfer ownership, and null is a
288 // valid value.
Henrik Lundina2af0002017-06-20 16:54:39 +0200289 explicit SsrcSwitchDetector(NetEqPostInsertPacket* other_callback)
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200290 : other_callback_(other_callback) {}
291
Henrik Lundina2af0002017-06-20 16:54:39 +0200292 void AfterInsertPacket(const NetEqInput::PacketData& packet,
293 NetEq* neteq) override {
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200294 if (last_ssrc_ && packet.header.ssrc != *last_ssrc_) {
295 std::cout << "Changing streams from 0x" << std::hex << *last_ssrc_
296 << " to 0x" << std::hex << packet.header.ssrc
297 << std::dec << " (payload type "
298 << static_cast<int>(packet.header.payloadType) << ")"
299 << std::endl;
300 }
Oskar Sundbom12ab00b2017-11-16 15:31:38 +0100301 last_ssrc_ = packet.header.ssrc;
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200302 if (other_callback_) {
303 other_callback_->AfterInsertPacket(packet, neteq);
304 }
305 }
306
307 private:
308 NetEqPostInsertPacket* other_callback_;
309 rtc::Optional<uint32_t> last_ssrc_;
310};
311
Henrik Lundina2af0002017-06-20 16:54:39 +0200312class StatsGetter : public NetEqGetAudioCallback {
313 public:
314 // This struct is a replica of webrtc::NetEqNetworkStatistics, but with all
315 // values stored in double precision.
316 struct Stats {
317 double current_buffer_size_ms = 0.0;
318 double preferred_buffer_size_ms = 0.0;
319 double jitter_peaks_found = 0.0;
320 double packet_loss_rate = 0.0;
Henrik Lundina2af0002017-06-20 16:54:39 +0200321 double expand_rate = 0.0;
322 double speech_expand_rate = 0.0;
323 double preemptive_rate = 0.0;
324 double accelerate_rate = 0.0;
325 double secondary_decoded_rate = 0.0;
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200326 double secondary_discarded_rate = 0.0;
Henrik Lundina2af0002017-06-20 16:54:39 +0200327 double clockdrift_ppm = 0.0;
328 double added_zero_samples = 0.0;
329 double mean_waiting_time_ms = 0.0;
330 double median_waiting_time_ms = 0.0;
331 double min_waiting_time_ms = 0.0;
332 double max_waiting_time_ms = 0.0;
333 };
334
Alex Narest7ff6ca52018-02-07 18:46:33 +0100335 struct ConcealmentEvent {
336 uint64_t duration_ms;
337 size_t concealment_event_number;
338 int64_t time_from_previous_event_end_ms;
339
340 friend std::ostream& operator<<(std::ostream& stream,
341 const ConcealmentEvent& concealment_event) {
342 stream << "ConcealmentEvent duration_ms:" << concealment_event.duration_ms
343 << " event_number:" << concealment_event.concealment_event_number
344 << " time_from_previous_event_end_ms:"
345 << concealment_event.time_from_previous_event_end_ms << "\n";
346 return stream;
347 }
348 };
349
Henrik Lundina2af0002017-06-20 16:54:39 +0200350 // Takes a pointer to another callback object, which will be invoked after
351 // this object finishes. This does not transfer ownership, and null is a
352 // valid value.
353 explicit StatsGetter(NetEqGetAudioCallback* other_callback)
354 : other_callback_(other_callback) {}
355
356 void BeforeGetAudio(NetEq* neteq) override {
357 if (other_callback_) {
358 other_callback_->BeforeGetAudio(neteq);
359 }
360 }
361
362 void AfterGetAudio(int64_t time_now_ms,
363 const AudioFrame& audio_frame,
364 bool muted,
365 NetEq* neteq) override {
366 if (++counter_ >= 100) {
367 counter_ = 0;
368 NetEqNetworkStatistics stats;
369 RTC_CHECK_EQ(neteq->NetworkStatistics(&stats), 0);
370 stats_.push_back(stats);
371 }
Alex Narest7ff6ca52018-02-07 18:46:33 +0100372 const auto lifetime_stat = neteq->GetLifetimeStatistics();
373 if (current_concealment_event_ != lifetime_stat.concealment_events) {
374 if (last_event_end_time_ms_ > 0) {
375 // Do not account for the first event to avoid start of the call
376 // skewing.
377 ConcealmentEvent concealment_event;
378 uint64_t last_event_voice_concealed_samples =
379 lifetime_stat.voice_concealed_samples -
380 voice_concealed_samples_until_last_event_;
381 RTC_CHECK_GT(last_event_voice_concealed_samples, 0);
382 concealment_event.duration_ms = last_event_voice_concealed_samples /
383 (audio_frame.sample_rate_hz_ / 1000);
384 concealment_event.concealment_event_number = current_concealment_event_;
385 concealment_event.time_from_previous_event_end_ms =
386 time_now_ms - last_event_end_time_ms_;
387 concealment_events_.emplace_back(concealment_event);
388 voice_concealed_samples_until_last_event_ =
389 lifetime_stat.voice_concealed_samples;
390 }
391 last_event_end_time_ms_ = time_now_ms;
392 voice_concealed_samples_until_last_event_ =
393 lifetime_stat.voice_concealed_samples;
394 current_concealment_event_ = lifetime_stat.concealment_events;
395 }
396
Henrik Lundina2af0002017-06-20 16:54:39 +0200397 if (other_callback_) {
henrik.lundinf09c9042017-08-29 09:14:08 -0700398 other_callback_->AfterGetAudio(time_now_ms, audio_frame, muted, neteq);
Henrik Lundina2af0002017-06-20 16:54:39 +0200399 }
400 }
401
402 double AverageSpeechExpandRate() const {
403 double sum_speech_expand =
404 std::accumulate(stats_.begin(), stats_.end(), double{0.0},
405 [](double a, NetEqNetworkStatistics b) {
406 return a + static_cast<double>(b.speech_expand_rate);
407 });
408 return sum_speech_expand / 16384.0 / stats_.size();
409 }
410
Alex Narest7ff6ca52018-02-07 18:46:33 +0100411 const std::vector<ConcealmentEvent>& concealment_events() {
412 // Do not account for the last concealment event to avoid potential end
413 // call skewing.
414 return concealment_events_;
415 }
416
Henrik Lundina2af0002017-06-20 16:54:39 +0200417 Stats AverageStats() const {
418 Stats sum_stats = std::accumulate(
419 stats_.begin(), stats_.end(), Stats(),
420 [](Stats a, NetEqNetworkStatistics b) {
421 a.current_buffer_size_ms += b.current_buffer_size_ms;
422 a.preferred_buffer_size_ms += b.preferred_buffer_size_ms;
423 a.jitter_peaks_found += b.jitter_peaks_found;
424 a.packet_loss_rate += b.packet_loss_rate / 16384.0;
Henrik Lundina2af0002017-06-20 16:54:39 +0200425 a.expand_rate += b.expand_rate / 16384.0;
426 a.speech_expand_rate += b.speech_expand_rate / 16384.0;
427 a.preemptive_rate += b.preemptive_rate / 16384.0;
428 a.accelerate_rate += b.accelerate_rate / 16384.0;
429 a.secondary_decoded_rate += b.secondary_decoded_rate / 16384.0;
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200430 a.secondary_discarded_rate += b.secondary_discarded_rate / 16384.0;
Henrik Lundina2af0002017-06-20 16:54:39 +0200431 a.clockdrift_ppm += b.clockdrift_ppm;
432 a.added_zero_samples += b.added_zero_samples;
433 a.mean_waiting_time_ms += b.mean_waiting_time_ms;
434 a.median_waiting_time_ms += b.median_waiting_time_ms;
henrik.lundin96571722017-08-30 00:41:30 -0700435 a.min_waiting_time_ms =
436 std::min(a.min_waiting_time_ms,
437 static_cast<double>(b.min_waiting_time_ms));
438 a.max_waiting_time_ms =
439 std::max(a.max_waiting_time_ms,
440 static_cast<double>(b.max_waiting_time_ms));
Henrik Lundina2af0002017-06-20 16:54:39 +0200441 return a;
442 });
443
444 sum_stats.current_buffer_size_ms /= stats_.size();
445 sum_stats.preferred_buffer_size_ms /= stats_.size();
446 sum_stats.jitter_peaks_found /= stats_.size();
447 sum_stats.packet_loss_rate /= stats_.size();
Henrik Lundina2af0002017-06-20 16:54:39 +0200448 sum_stats.expand_rate /= stats_.size();
449 sum_stats.speech_expand_rate /= stats_.size();
450 sum_stats.preemptive_rate /= stats_.size();
451 sum_stats.accelerate_rate /= stats_.size();
452 sum_stats.secondary_decoded_rate /= stats_.size();
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200453 sum_stats.secondary_discarded_rate /= stats_.size();
Henrik Lundina2af0002017-06-20 16:54:39 +0200454 sum_stats.clockdrift_ppm /= stats_.size();
455 sum_stats.added_zero_samples /= stats_.size();
456 sum_stats.mean_waiting_time_ms /= stats_.size();
457 sum_stats.median_waiting_time_ms /= stats_.size();
Henrik Lundina2af0002017-06-20 16:54:39 +0200458
459 return sum_stats;
460 }
461
462 private:
463 NetEqGetAudioCallback* other_callback_;
464 size_t counter_ = 0;
465 std::vector<NetEqNetworkStatistics> stats_;
Alex Narest7ff6ca52018-02-07 18:46:33 +0100466 size_t current_concealment_event_ = 1;
467 uint64_t voice_concealed_samples_until_last_event_ = 0;
468 std::vector<ConcealmentEvent> concealment_events_;
469 int64_t last_event_end_time_ms_ = 0;
Henrik Lundina2af0002017-06-20 16:54:39 +0200470};
471
henrik.lundin303d3e12016-05-26 05:56:03 -0700472int RunTest(int argc, char* argv[]) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000473 std::string program_name = argv[0];
474 std::string usage = "Tool for decoding an RTP dump file using NetEq.\n"
oprypin6e09d872017-08-31 03:21:39 -0700475 "Run " + program_name + " --help for usage.\n"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000476 "Example usage:\n" + program_name +
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000477 " input.rtp output.{pcm, wav}\n";
oprypin6e09d872017-08-31 03:21:39 -0700478 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true)) {
479 return 1;
480 }
481 if (FLAG_help) {
482 std::cout << usage;
483 rtc::FlagList::Print(nullptr, false);
484 return 0;
485 }
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000486
oprypin6e09d872017-08-31 03:21:39 -0700487 if (FLAG_codec_map) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000488 PrintCodecMapping();
489 }
490
491 if (argc != 3) {
oprypin6e09d872017-08-31 03:21:39 -0700492 if (FLAG_codec_map) {
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000493 // We have already printed the codec map. Just end the program.
494 return 0;
495 }
496 // Print usage information.
oprypin6e09d872017-08-31 03:21:39 -0700497 std::cout << usage;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000498 return 0;
499 }
oprypin6e09d872017-08-31 03:21:39 -0700500 RTC_CHECK(ValidatePayloadType(FLAG_pcmu));
501 RTC_CHECK(ValidatePayloadType(FLAG_pcma));
502 RTC_CHECK(ValidatePayloadType(FLAG_ilbc));
503 RTC_CHECK(ValidatePayloadType(FLAG_isac));
504 RTC_CHECK(ValidatePayloadType(FLAG_isac_swb));
505 RTC_CHECK(ValidatePayloadType(FLAG_opus));
506 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b));
507 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_wb));
508 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb32));
509 RTC_CHECK(ValidatePayloadType(FLAG_pcm16b_swb48));
510 RTC_CHECK(ValidatePayloadType(FLAG_g722));
511 RTC_CHECK(ValidatePayloadType(FLAG_avt));
512 RTC_CHECK(ValidatePayloadType(FLAG_avt_16));
513 RTC_CHECK(ValidatePayloadType(FLAG_avt_32));
514 RTC_CHECK(ValidatePayloadType(FLAG_avt_48));
515 RTC_CHECK(ValidatePayloadType(FLAG_red));
516 RTC_CHECK(ValidatePayloadType(FLAG_cn_nb));
517 RTC_CHECK(ValidatePayloadType(FLAG_cn_wb));
518 RTC_CHECK(ValidatePayloadType(FLAG_cn_swb32));
519 RTC_CHECK(ValidatePayloadType(FLAG_cn_swb48));
520 RTC_CHECK(ValidateSsrcValue(FLAG_ssrc));
521 RTC_CHECK(ValidateExtensionId(FLAG_audio_level));
522 RTC_CHECK(ValidateExtensionId(FLAG_abs_send_time));
523 RTC_CHECK(ValidateExtensionId(FLAG_transport_seq_no));
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000524
henrik.lundin8a6a6002016-08-25 00:46:36 -0700525 // Gather RTP header extensions in a map.
526 NetEqPacketSourceInput::RtpHeaderExtensionMap rtp_ext_map = {
oprypin6e09d872017-08-31 03:21:39 -0700527 {FLAG_audio_level, kRtpExtensionAudioLevel},
528 {FLAG_abs_send_time, kRtpExtensionAbsoluteSendTime},
529 {FLAG_transport_seq_no, kRtpExtensionTransportSequenceNumber}};
henrik.lundin8a6a6002016-08-25 00:46:36 -0700530
henrik.lundine8a77e32016-06-22 06:34:03 -0700531 const std::string input_file_name = argv[1];
532 std::unique_ptr<NetEqInput> input;
533 if (RtpFileSource::ValidRtpDump(input_file_name) ||
534 RtpFileSource::ValidPcap(input_file_name)) {
henrik.lundin8a6a6002016-08-25 00:46:36 -0700535 input.reset(new NetEqRtpDumpInput(input_file_name, rtp_ext_map));
ivoccaa5f4b2015-09-08 03:28:46 -0700536 } else {
henrik.lundin8a6a6002016-08-25 00:46:36 -0700537 input.reset(new NetEqEventLogInput(input_file_name, rtp_ext_map));
ivoccaa5f4b2015-09-08 03:28:46 -0700538 }
539
henrik.lundine8a77e32016-06-22 06:34:03 -0700540 std::cout << "Input file: " << input_file_name << std::endl;
541 RTC_CHECK(input) << "Cannot open input file";
542 RTC_CHECK(!input->ended()) << "Input file is empty";
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000543
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +0000544 // Check if an SSRC value was provided.
oprypin6e09d872017-08-31 03:21:39 -0700545 if (strlen(FLAG_ssrc) > 0) {
henrik.lundin@webrtc.org8b65d512014-10-07 05:30:04 +0000546 uint32_t ssrc;
oprypin6e09d872017-08-31 03:21:39 -0700547 RTC_CHECK(ParseSsrc(FLAG_ssrc, &ssrc)) << "Flag verification has failed.";
henrik.lundine8a77e32016-06-22 06:34:03 -0700548 input.reset(new FilterSsrcInput(std::move(input), ssrc));
ivoccaa5f4b2015-09-08 03:28:46 -0700549 }
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000550
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000551 // Check the sample rate.
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200552 rtc::Optional<int> sample_rate_hz;
553 std::set<std::pair<int, uint32_t>> discarded_pt_and_ssrc;
554 while (input->NextHeader()) {
555 rtc::Optional<RTPHeader> first_rtp_header = input->NextHeader();
556 RTC_DCHECK(first_rtp_header);
557 sample_rate_hz = CodecSampleRate(first_rtp_header->payloadType);
558 if (sample_rate_hz) {
559 std::cout << "Found valid packet with payload type "
560 << static_cast<int>(first_rtp_header->payloadType)
561 << " and SSRC 0x" << std::hex << first_rtp_header->ssrc
562 << std::dec << std::endl;
563 break;
564 }
565 // Discard this packet and move to the next. Keep track of discarded payload
566 // types and SSRCs.
567 discarded_pt_and_ssrc.emplace(first_rtp_header->payloadType,
568 first_rtp_header->ssrc);
569 input->PopPacket();
570 }
571 if (!discarded_pt_and_ssrc.empty()) {
572 std::cout << "Discarded initial packets with the following payload types "
573 "and SSRCs:"
574 << std::endl;
575 for (const auto& d : discarded_pt_and_ssrc) {
576 std::cout << "PT " << d.first << "; SSRC 0x" << std::hex
577 << static_cast<int>(d.second) << std::dec << std::endl;
578 }
579 }
580 if (!sample_rate_hz) {
581 std::cout << "Cannot find any packets with known payload types"
582 << std::endl;
583 RTC_NOTREACHED();
584 }
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000585
586 // Open the output file now that we know the sample rate. (Rate is only needed
587 // for wav files.)
henrik.lundine8a77e32016-06-22 06:34:03 -0700588 const std::string output_file_name = argv[2];
henrik.lundince5570e2016-05-24 06:14:57 -0700589 std::unique_ptr<AudioSink> output;
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000590 if (output_file_name.size() >= 4 &&
591 output_file_name.substr(output_file_name.size() - 4) == ".wav") {
592 // Open a wav file.
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200593 output.reset(new OutputWavFile(output_file_name, *sample_rate_hz));
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000594 } else {
595 // Open a pcm file.
henrik.lundince5570e2016-05-24 06:14:57 -0700596 output.reset(new OutputAudioFile(output_file_name));
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000597 }
598
henrik.lundine8a77e32016-06-22 06:34:03 -0700599 std::cout << "Output file: " << output_file_name << std::endl;
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000600
henrik.lundine8a77e32016-06-22 06:34:03 -0700601 NetEqTest::DecoderMap codecs = {
oprypin6e09d872017-08-31 03:21:39 -0700602 {FLAG_pcmu, std::make_pair(NetEqDecoder::kDecoderPCMu, "pcmu")},
603 {FLAG_pcma, std::make_pair(NetEqDecoder::kDecoderPCMa, "pcma")},
604 {FLAG_ilbc, std::make_pair(NetEqDecoder::kDecoderILBC, "ilbc")},
605 {FLAG_isac, std::make_pair(NetEqDecoder::kDecoderISAC, "isac")},
606 {FLAG_isac_swb,
henrik.lundine8a77e32016-06-22 06:34:03 -0700607 std::make_pair(NetEqDecoder::kDecoderISACswb, "isac-swb")},
oprypin6e09d872017-08-31 03:21:39 -0700608 {FLAG_opus, std::make_pair(NetEqDecoder::kDecoderOpus, "opus")},
609 {FLAG_pcm16b, std::make_pair(NetEqDecoder::kDecoderPCM16B, "pcm16-nb")},
610 {FLAG_pcm16b_wb,
henrik.lundine8a77e32016-06-22 06:34:03 -0700611 std::make_pair(NetEqDecoder::kDecoderPCM16Bwb, "pcm16-wb")},
oprypin6e09d872017-08-31 03:21:39 -0700612 {FLAG_pcm16b_swb32,
henrik.lundine8a77e32016-06-22 06:34:03 -0700613 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb32kHz, "pcm16-swb32")},
oprypin6e09d872017-08-31 03:21:39 -0700614 {FLAG_pcm16b_swb48,
henrik.lundine8a77e32016-06-22 06:34:03 -0700615 std::make_pair(NetEqDecoder::kDecoderPCM16Bswb48kHz, "pcm16-swb48")},
oprypin6e09d872017-08-31 03:21:39 -0700616 {FLAG_g722, std::make_pair(NetEqDecoder::kDecoderG722, "g722")},
617 {FLAG_avt, std::make_pair(NetEqDecoder::kDecoderAVT, "avt")},
618 {FLAG_avt_16, std::make_pair(NetEqDecoder::kDecoderAVT16kHz, "avt-16")},
619 {FLAG_avt_32,
solenberg2779bab2016-11-17 04:45:19 -0800620 std::make_pair(NetEqDecoder::kDecoderAVT32kHz, "avt-32")},
oprypin6e09d872017-08-31 03:21:39 -0700621 {FLAG_avt_48,
solenberg2779bab2016-11-17 04:45:19 -0800622 std::make_pair(NetEqDecoder::kDecoderAVT48kHz, "avt-48")},
oprypin6e09d872017-08-31 03:21:39 -0700623 {FLAG_red, std::make_pair(NetEqDecoder::kDecoderRED, "red")},
624 {FLAG_cn_nb, std::make_pair(NetEqDecoder::kDecoderCNGnb, "cng-nb")},
625 {FLAG_cn_wb, std::make_pair(NetEqDecoder::kDecoderCNGwb, "cng-wb")},
626 {FLAG_cn_swb32,
henrik.lundine8a77e32016-06-22 06:34:03 -0700627 std::make_pair(NetEqDecoder::kDecoderCNGswb32kHz, "cng-swb32")},
oprypin6e09d872017-08-31 03:21:39 -0700628 {FLAG_cn_swb48,
henrik.lundine8a77e32016-06-22 06:34:03 -0700629 std::make_pair(NetEqDecoder::kDecoderCNGswb48kHz, "cng-swb48")}};
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000630
henrik.lundine8a77e32016-06-22 06:34:03 -0700631 // Check if a replacement audio file was provided.
632 std::unique_ptr<AudioDecoder> replacement_decoder;
633 NetEqTest::ExtDecoderMap ext_codecs;
oprypin6e09d872017-08-31 03:21:39 -0700634 if (strlen(FLAG_replacement_audio_file) > 0) {
henrik.lundine8a77e32016-06-22 06:34:03 -0700635 // Find largest unused payload type.
636 int replacement_pt = 127;
637 while (!(codecs.find(replacement_pt) == codecs.end() &&
638 ext_codecs.find(replacement_pt) == ext_codecs.end())) {
639 --replacement_pt;
640 RTC_CHECK_GE(replacement_pt, 0);
641 }
642
643 auto std_set_int32_to_uint8 = [](const std::set<int32_t>& a) {
644 std::set<uint8_t> b;
645 for (auto& x : a) {
646 b.insert(static_cast<uint8_t>(x));
647 }
648 return b;
649 };
650
651 std::set<uint8_t> cn_types = std_set_int32_to_uint8(
oprypin6e09d872017-08-31 03:21:39 -0700652 {FLAG_cn_nb, FLAG_cn_wb, FLAG_cn_swb32, FLAG_cn_swb48});
henrik.lundine8a77e32016-06-22 06:34:03 -0700653 std::set<uint8_t> forbidden_types =
oprypin6e09d872017-08-31 03:21:39 -0700654 std_set_int32_to_uint8({FLAG_g722, FLAG_red, FLAG_avt,
655 FLAG_avt_16, FLAG_avt_32, FLAG_avt_48});
henrik.lundine8a77e32016-06-22 06:34:03 -0700656 input.reset(new NetEqReplacementInput(std::move(input), replacement_pt,
657 cn_types, forbidden_types));
658
659 replacement_decoder.reset(new FakeDecodeFromFile(
660 std::unique_ptr<InputAudioFile>(
oprypin6e09d872017-08-31 03:21:39 -0700661 new InputAudioFile(FLAG_replacement_audio_file)),
henrik.lundine8a77e32016-06-22 06:34:03 -0700662 48000, false));
663 NetEqTest::ExternalDecoderInfo ext_dec_info = {
664 replacement_decoder.get(), NetEqDecoder::kDecoderArbitrary,
665 "replacement codec"};
666 ext_codecs[replacement_pt] = ext_dec_info;
667 }
668
henrik.lundin02739d92017-05-04 06:09:06 -0700669 NetEqTest::Callbacks callbacks;
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200670 std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer;
Ivo Creusend1d8dfb2017-12-06 10:48:10 +0100671 if (FLAG_matlabplot || FLAG_pythonplot) {
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200672 delay_analyzer.reset(new NetEqDelayAnalyzer);
673 }
674
675 SsrcSwitchDetector ssrc_switch_detector(delay_analyzer.get());
676 callbacks.post_insert_packet = &ssrc_switch_detector;
Henrik Lundina2af0002017-06-20 16:54:39 +0200677 StatsGetter stats_getter(delay_analyzer.get());
678 callbacks.get_audio_callback = &stats_getter;
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000679 NetEq::Config config;
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200680 config.sample_rate_hz = *sample_rate_hz;
henrik.lundine8a77e32016-06-22 06:34:03 -0700681 NetEqTest test(config, codecs, ext_codecs, std::move(input),
henrik.lundin02739d92017-05-04 06:09:06 -0700682 std::move(output), callbacks);
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000683
henrik.lundine8a77e32016-06-22 06:34:03 -0700684 int64_t test_duration_ms = test.Run();
henrik.lundin@webrtc.org03499a02014-11-24 14:50:53 +0000685
oprypin6e09d872017-08-31 03:21:39 -0700686 if (FLAG_matlabplot) {
henrik.lundinf09c9042017-08-29 09:14:08 -0700687 auto matlab_script_name = output_file_name;
688 std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.',
689 '_');
690 std::cout << "Creating Matlab plot script " << matlab_script_name + ".m"
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200691 << std::endl;
henrik.lundinf09c9042017-08-29 09:14:08 -0700692 delay_analyzer->CreateMatlabScript(matlab_script_name + ".m");
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200693 }
Ivo Creusend1d8dfb2017-12-06 10:48:10 +0100694 if (FLAG_pythonplot) {
695 auto python_script_name = output_file_name;
696 std::replace(python_script_name.begin(), python_script_name.end(), '.',
697 '_');
698 std::cout << "Creating Python plot script " << python_script_name + ".py"
699 << std::endl;
700 delay_analyzer->CreatePythonScript(python_script_name + ".py");
701 }
Henrik Lundin0bc0ccd2017-06-20 14:48:50 +0200702
henrik.lundine8a77e32016-06-22 06:34:03 -0700703 printf("Simulation statistics:\n");
704 printf(" output duration: %" PRId64 " ms\n", test_duration_ms);
Henrik Lundina2af0002017-06-20 16:54:39 +0200705 auto stats = stats_getter.AverageStats();
706 printf(" packet_loss_rate: %f %%\n", 100.0 * stats.packet_loss_rate);
Henrik Lundina2af0002017-06-20 16:54:39 +0200707 printf(" expand_rate: %f %%\n", 100.0 * stats.expand_rate);
708 printf(" speech_expand_rate: %f %%\n", 100.0 * stats.speech_expand_rate);
709 printf(" preemptive_rate: %f %%\n", 100.0 * stats.preemptive_rate);
710 printf(" accelerate_rate: %f %%\n", 100.0 * stats.accelerate_rate);
henrik.lundine8a77e32016-06-22 06:34:03 -0700711 printf(" secondary_decoded_rate: %f %%\n",
Henrik Lundina2af0002017-06-20 16:54:39 +0200712 100.0 * stats.secondary_decoded_rate);
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200713 printf(" secondary_discarded_rate: %f %%\n",
714 100.0 * stats.secondary_discarded_rate);
Henrik Lundina2af0002017-06-20 16:54:39 +0200715 printf(" clockdrift_ppm: %f ppm\n", stats.clockdrift_ppm);
716 printf(" mean_waiting_time_ms: %f ms\n", stats.mean_waiting_time_ms);
717 printf(" median_waiting_time_ms: %f ms\n", stats.median_waiting_time_ms);
718 printf(" min_waiting_time_ms: %f ms\n", stats.min_waiting_time_ms);
719 printf(" max_waiting_time_ms: %f ms\n", stats.max_waiting_time_ms);
Henrik Lundin156af4a2017-11-17 16:46:18 +0100720 printf(" current_buffer_size_ms: %f ms\n", stats.current_buffer_size_ms);
721 printf(" preferred_buffer_size_ms: %f ms\n", stats.preferred_buffer_size_ms);
Alex Narest7ff6ca52018-02-07 18:46:33 +0100722 if (FLAG_concealment_events) {
723 std::cout << " concealment_events_ms:"
724 << "\n";
725 for (auto concealment_event : stats_getter.concealment_events())
726 std::cout << concealment_event;
727 std::cout << " end of concealment_events_ms\n";
728 }
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000729 return 0;
730}
henrik.lundince5570e2016-05-24 06:14:57 -0700731
henrik.lundin303d3e12016-05-26 05:56:03 -0700732} // namespace
henrik.lundince5570e2016-05-24 06:14:57 -0700733} // namespace test
734} // namespace webrtc
henrik.lundin303d3e12016-05-26 05:56:03 -0700735
736int main(int argc, char* argv[]) {
Robin Raymond1c62ffa2017-12-03 16:45:56 -0500737 return webrtc::test::RunTest(argc, argv);
henrik.lundin303d3e12016-05-26 05:56:03 -0700738}