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