2020-05-18 15:31:49 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
2019-12-05 19:53:55 +08:00
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2019-12-05 19:53:55 +08:00
|
|
|
|
*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* 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.
|
2019-12-05 19:53:55 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include "Util/MD5.h"
|
|
|
|
|
#include "Util/File.h"
|
|
|
|
|
#include "Util/logger.h"
|
|
|
|
|
#include "Util/SSLBox.h"
|
|
|
|
|
#include "Util/util.h"
|
|
|
|
|
#include "Network/TcpServer.h"
|
|
|
|
|
#include "Common/config.h"
|
|
|
|
|
#include "Rtsp/RtspSession.h"
|
|
|
|
|
#include "Rtmp/RtmpSession.h"
|
|
|
|
|
#include "Http/HttpSession.h"
|
2019-12-06 11:54:10 +08:00
|
|
|
|
#include "Rtp/RtpSelector.h"
|
2019-12-05 19:53:55 +08:00
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace toolkit;
|
|
|
|
|
using namespace mediakit;
|
|
|
|
|
|
2019-12-06 11:54:10 +08:00
|
|
|
|
#if defined(ENABLE_RTPPROXY)
|
|
|
|
|
static bool loadFile(const char *path){
|
2021-03-07 10:05:52 +08:00
|
|
|
|
FILE *fp = fopen(path, "rb");
|
2019-12-06 11:54:10 +08:00
|
|
|
|
if (!fp) {
|
|
|
|
|
WarnL << "open file failed:" << path;
|
|
|
|
|
return false;
|
2019-12-05 19:53:55 +08:00
|
|
|
|
}
|
2019-12-06 11:54:10 +08:00
|
|
|
|
|
|
|
|
|
uint32_t timeStamp_last = 0;
|
2021-03-07 10:05:52 +08:00
|
|
|
|
uint16_t len;
|
2021-08-12 10:43:12 +08:00
|
|
|
|
char rtp[0xFFFF];
|
2019-12-11 20:01:51 +08:00
|
|
|
|
struct sockaddr addr = {0};
|
2021-02-04 18:20:59 +08:00
|
|
|
|
auto sock = Socket::createSocket();
|
2021-03-07 10:05:52 +08:00
|
|
|
|
size_t total_size = 0;
|
|
|
|
|
while (true) {
|
|
|
|
|
if (2 != fread(&len, 1, 2, fp)) {
|
2019-12-06 11:54:10 +08:00
|
|
|
|
WarnL;
|
2021-03-07 10:05:52 +08:00
|
|
|
|
break;
|
2019-12-06 11:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
len = ntohs(len);
|
|
|
|
|
if (len < 12 || len > sizeof(rtp)) {
|
|
|
|
|
WarnL << len;
|
2021-03-07 10:05:52 +08:00
|
|
|
|
break;
|
2019-12-06 11:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-07 10:05:52 +08:00
|
|
|
|
if (len != fread(rtp, 1, len, fp)) {
|
2019-12-06 11:54:10 +08:00
|
|
|
|
WarnL;
|
2021-03-07 10:05:52 +08:00
|
|
|
|
break;
|
2019-12-06 11:54:10 +08:00
|
|
|
|
}
|
2021-03-07 10:05:52 +08:00
|
|
|
|
total_size += len;
|
2019-12-06 11:54:10 +08:00
|
|
|
|
uint32_t timeStamp;
|
2021-03-07 10:05:52 +08:00
|
|
|
|
|
2021-02-04 18:20:59 +08:00
|
|
|
|
RtpSelector::Instance().inputRtp(sock, rtp, len, &addr, &timeStamp);
|
2021-03-07 10:05:52 +08:00
|
|
|
|
auto diff = timeStamp - timeStamp_last;
|
|
|
|
|
if (diff > 0 && diff < 500) {
|
|
|
|
|
usleep(diff * 1000);
|
|
|
|
|
} else {
|
|
|
|
|
usleep(1 * 1000);
|
2019-12-06 11:54:10 +08:00
|
|
|
|
}
|
|
|
|
|
timeStamp_last = timeStamp;
|
2021-03-07 10:05:52 +08:00
|
|
|
|
}
|
|
|
|
|
WarnL << total_size / 1024 << "KB";
|
|
|
|
|
fclose(fp);
|
2019-12-06 11:54:10 +08:00
|
|
|
|
return true;
|
2019-12-05 19:53:55 +08:00
|
|
|
|
}
|
2019-12-06 11:54:10 +08:00
|
|
|
|
#endif//#if defined(ENABLE_RTPPROXY)
|
2019-12-05 19:53:55 +08:00
|
|
|
|
|
2019-12-06 11:54:10 +08:00
|
|
|
|
int main(int argc,char *argv[]) {
|
|
|
|
|
//设置日志
|
|
|
|
|
Logger::Instance().add(std::make_shared<ConsoleChannel>("ConsoleChannel"));
|
|
|
|
|
#if defined(ENABLE_RTPPROXY)
|
|
|
|
|
//启动异步日志线程
|
|
|
|
|
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
|
|
|
|
|
loadIniConfig((exeDir() + "config.ini").data());
|
|
|
|
|
TcpServer::Ptr rtspSrv(new TcpServer());
|
|
|
|
|
TcpServer::Ptr rtmpSrv(new TcpServer());
|
|
|
|
|
TcpServer::Ptr httpSrv(new TcpServer());
|
|
|
|
|
rtspSrv->start<RtspSession>(554);//默认554
|
|
|
|
|
rtmpSrv->start<RtmpSession>(1935);//默认1935
|
|
|
|
|
httpSrv->start<HttpSession>(80);//默认80
|
2019-12-13 15:43:24 +08:00
|
|
|
|
//此处选择是否导出调试文件
|
|
|
|
|
// mINI::Instance()[RtpProxy::kDumpDir] = "/Users/xzl/Desktop/";
|
|
|
|
|
|
2021-03-07 10:05:52 +08:00
|
|
|
|
if (argc == 2)
|
|
|
|
|
loadFile(argv[1]);
|
|
|
|
|
else
|
|
|
|
|
ErrorL << "parameter error.";
|
2019-12-06 11:54:10 +08:00
|
|
|
|
#else
|
|
|
|
|
ErrorL << "please ENABLE_RTPPROXY and then test";
|
|
|
|
|
#endif//#if defined(ENABLE_RTPPROXY)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-12-05 19:53:55 +08:00
|
|
|
|
|
|
|
|
|
|