mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
简化代码
This commit is contained in:
parent
5b4fe604cb
commit
5064137a22
@ -28,55 +28,47 @@ using namespace mediakit;
|
|||||||
|
|
||||||
#if defined(ENABLE_RTPPROXY)
|
#if defined(ENABLE_RTPPROXY)
|
||||||
static bool loadFile(const char *path){
|
static bool loadFile(const char *path){
|
||||||
std::shared_ptr<FILE> fp(fopen(path, "rb"), [](FILE *fp) {
|
FILE *fp = fopen(path, "rb");
|
||||||
if (fp) {
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
WarnL << "open file failed:" << path;
|
WarnL << "open file failed:" << path;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
semaphore sem;
|
|
||||||
uint16_t len = 0;
|
|
||||||
uint32_t timeStamp_last = 0;
|
uint32_t timeStamp_last = 0;
|
||||||
|
uint16_t len;
|
||||||
char rtp[2 * 1024];
|
char rtp[2 * 1024];
|
||||||
struct sockaddr addr = {0};
|
struct sockaddr addr = {0};
|
||||||
auto sock = Socket::createSocket();
|
auto sock = Socket::createSocket();
|
||||||
|
size_t total_size = 0;
|
||||||
sock->getPoller()->doDelayTask(0, [&]() mutable -> uint64_t {
|
while (true) {
|
||||||
if (2 != fread(&len, 1, 2, fp.get())) {
|
if (2 != fread(&len, 1, 2, fp)) {
|
||||||
WarnL;
|
WarnL;
|
||||||
sem.post();
|
break;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
len = ntohs(len);
|
len = ntohs(len);
|
||||||
if (len < 12 || len > sizeof(rtp)) {
|
if (len < 12 || len > sizeof(rtp)) {
|
||||||
WarnL << len;
|
WarnL << len;
|
||||||
sem.post();
|
break;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len != fread(rtp, 1, len, fp.get())) {
|
if (len != fread(rtp, 1, len, fp)) {
|
||||||
WarnL;
|
WarnL;
|
||||||
sem.post();
|
break;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
total_size += len;
|
||||||
uint32_t timeStamp;
|
uint32_t timeStamp;
|
||||||
|
|
||||||
RtpSelector::Instance().inputRtp(sock, rtp, len, &addr, &timeStamp);
|
RtpSelector::Instance().inputRtp(sock, rtp, len, &addr, &timeStamp);
|
||||||
if (timeStamp_last) {
|
auto diff = timeStamp - timeStamp_last;
|
||||||
auto diff = timeStamp - timeStamp_last;
|
if (diff > 0 && diff < 500) {
|
||||||
if (diff > 0 && diff < 500) {
|
usleep(diff * 1000);
|
||||||
timeStamp_last = timeStamp;
|
} else {
|
||||||
return diff;
|
usleep(1 * 1000);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
timeStamp_last = timeStamp;
|
timeStamp_last = timeStamp;
|
||||||
return 1;
|
}
|
||||||
});
|
WarnL << total_size / 1024 << "KB";
|
||||||
sem.wait();
|
fclose(fp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif//#if defined(ENABLE_RTPPROXY)
|
#endif//#if defined(ENABLE_RTPPROXY)
|
||||||
@ -97,11 +89,10 @@ int main(int argc,char *argv[]) {
|
|||||||
//此处选择是否导出调试文件
|
//此处选择是否导出调试文件
|
||||||
// mINI::Instance()[RtpProxy::kDumpDir] = "/Users/xzl/Desktop/";
|
// mINI::Instance()[RtpProxy::kDumpDir] = "/Users/xzl/Desktop/";
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2)
|
||||||
loadFile(argv[1]);
|
loadFile(argv[1]);
|
||||||
} else {
|
else
|
||||||
ErrorL << "parameter error.";
|
ErrorL << "parameter error.";
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
ErrorL << "please ENABLE_RTPPROXY and then test";
|
ErrorL << "please ENABLE_RTPPROXY and then test";
|
||||||
#endif//#if defined(ENABLE_RTPPROXY)
|
#endif//#if defined(ENABLE_RTPPROXY)
|
||||||
|
Loading…
Reference in New Issue
Block a user