diff --git a/tests/test_rtp.cpp b/tests/test_rtp.cpp index 2cb2f593..2312d835 100644 --- a/tests/test_rtp.cpp +++ b/tests/test_rtp.cpp @@ -28,55 +28,47 @@ using namespace mediakit; #if defined(ENABLE_RTPPROXY) static bool loadFile(const char *path){ - std::shared_ptr 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)