ZLMediaKit/tests/test_rtcp_nack.cpp

55 lines
1.7 KiB
C++
Raw Permalink Normal View History

2021-06-28 16:02:13 +08:00
/*
2021-05-11 11:18:55 +08:00
* Copyright (c) 2016 The ZLToolKit project authors. All Rights Reserved.
*
* This file is part of ZLToolKit(https://github.com/xia-chu/ZLToolKit).
*
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#include <iostream>
#include "Util/logger.h"
2021-10-18 20:23:50 +08:00
#include "../webrtc/Nack.h"
2021-05-11 11:18:55 +08:00
using namespace std;
using namespace toolkit;
using namespace mediakit;
int main() {
Logger::Instance().add(std::make_shared<ConsoleChannel>());
2023-02-25 00:19:00 +08:00
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
2021-05-11 11:18:55 +08:00
2023-02-25 00:19:00 +08:00
srand((unsigned)time(NULL));
2021-05-11 11:18:55 +08:00
NackContext ctx;
2023-02-25 00:19:00 +08:00
ctx.setOnNack([](const FCI_NACK &nack){
InfoL << nack.dumpString();
});
auto drop_start = 0;
auto drop_len = 0;
uint16_t offset = 0xFFFF - 200 - 50;
for (int i = 1; i < 10000; ++i) {
if (i % 100 == 0) {
drop_start = i + rand() % 16;
drop_len = 4 + rand() % 16;
InfoL << "start drop:" << (uint16_t)(drop_start + offset) << " -> "
<< (uint16_t)(drop_start + offset + drop_len);
}
uint16_t seq = i + offset;
if ((i >= drop_start && i <= drop_start + drop_len) || seq == 65535 || seq == 0 || seq == 1) {
TraceL << "drop:" << (uint16_t)(i + offset);
2021-05-11 11:18:55 +08:00
} else {
2023-02-25 00:19:00 +08:00
static auto last_seq = seq;
if (seq - last_seq > 16) {
ctx.received(last_seq);
ctx.received(seq);
DebugL << "seq reduce:" << last_seq;
last_seq = seq;
} else {
ctx.received(seq);
}
2021-05-11 11:18:55 +08:00
}
}
sleep(1);
return 0;
}