From 734cd06a48a3b1d29148e24bc644c02c92bd3d6a Mon Sep 17 00:00:00 2001 From: monktan Date: Mon, 19 Oct 2020 16:57:40 +0800 Subject: [PATCH] update rtp sort --- 3rdpart/media-server | 2 +- src/Rtp/RtpProcess.cpp | 4 +-- tests/test_rtp.cpp | 12 +++++---- tests/test_rtp_tcp.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 tests/test_rtp_tcp.cpp diff --git a/3rdpart/media-server b/3rdpart/media-server index b878e869..d54285e9 160000 --- a/3rdpart/media-server +++ b/3rdpart/media-server @@ -1 +1 @@ -Subproject commit b878e869f995855d09013585de686e6a7330bd43 +Subproject commit d54285e96260e6d56d68929ec9ace402b83ff6b0 diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index 6ee5fa30..17216b44 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -137,8 +137,8 @@ const char *RtpProcess::onSearchPacketTail(const char *packet,int bytes){ return nullptr; } catch (std::exception &ex) { InfoL << "解析ps或ts异常: bytes=" << bytes - << " ,exception=" << ex.what() - << " ,hex=" << hexdump((uint8_t *) packet, bytes); + << " ,exception=" << ex.what(); + //<< " ,hex=" << hexdump((uint8_t *) packet, bytes); return nullptr; } } diff --git a/tests/test_rtp.cpp b/tests/test_rtp.cpp index 24d9ac83..fa9b545e 100644 --- a/tests/test_rtp.cpp +++ b/tests/test_rtp.cpp @@ -10,8 +10,6 @@ #include #include -#include "Util/MD5.h" -#include "Util/File.h" #include "Util/logger.h" #include "Util/SSLBox.h" #include "Util/util.h" @@ -38,22 +36,26 @@ static bool loadFile(const char *path){ uint16_t len; char rtp[2 * 1024]; struct sockaddr addr = {0}; + int rtp_count = 0; + int bytes = 0; while (true) { if (2 != fread(&len, 1, 2, fp)) { - WarnL; + WarnL << bytes << " " << rtp_count; break; } len = ntohs(len); if (len < 12 || len > sizeof(rtp)) { - WarnL << len; + WarnL << bytes << " " << rtp_count << " " << len; break; } if (len != fread(rtp, 1, len, fp)) { - WarnL; + WarnL << bytes << " " << rtp_count; break; } + bytes += 2 + len; + ++rtp_count; uint32_t timeStamp; RtpSelector::Instance().inputRtp(nullptr, rtp, len, &addr, &timeStamp); if(timeStamp_last){ diff --git a/tests/test_rtp_tcp.cpp b/tests/test_rtp_tcp.cpp new file mode 100644 index 00000000..c81ff32f --- /dev/null +++ b/tests/test_rtp_tcp.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. + * + * This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit). + * + * 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 +#include "Network/TcpClient.h" +using namespace std; +using namespace toolkit; + +int main(int argc,char *argv[]) { + //设置日志 + Logger::Instance().add(std::make_shared("ConsoleChannel")); + if(argc < 4){ + ErrorL << "用法: ./test_rtp_tcp rtp_file server_url server_port"; + return -1; + } + FILE *fp = fopen(argv[1], "rb"); + if (!fp) { + ErrorL << "打开文件失败:" << argv[1]; + return -1; + } + + static semaphore sem; + Socket::Ptr socket = std::make_shared(); + socket->connect(argv[2], atoi(argv[3]), [&](const SockException &err) { + if (err) { + ErrorL << "连接服务器" << argv[2] << ":" << atoi(argv[3]) << "失败:" << err.what(); + sem.post(); + return; + } + char buf[4 * 1024]; + while (true) { + auto size = fread(buf, 1, sizeof(buf), fp); + if (size < sizeof(buf)) { + break; + } + socket->send(buf, size); + //休眠 + usleep(10 * 1000); + } + sem.post(); + }); + + signal(SIGINT, [](int) { sem.post(); });// 设置退出信号 + sem.wait(); + fclose(fp); +} + +