You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.1KB

  1. #include "sockutil.h"
  2. #include "rtp-dump.h"
  3. #include "sys/system.h"
  4. #include <stdio.h>
  5. #include <assert.h>
  6. #include <stdint.h>
  7. #include <inttypes.h>
  8. void rtp_dump_replay_test(const char* file, const char* peer, int port)
  9. {
  10. int r;
  11. uint8_t data[1500];
  12. uint32_t clock, clock0;
  13. uint64_t base = 0;
  14. struct rtpdump_t* dump;
  15. socket_init();
  16. socket_t udp = socket_udp_bind_ipv4(NULL, 0);
  17. socklen_t addrlen = 0;
  18. struct sockaddr_storage addr;
  19. assert(0 == socket_addr_from(&addr, &addrlen, peer, port));
  20. dump = rtpdump_open(file, 0);
  21. while (1)
  22. {
  23. r = rtpdump_read(dump, &clock, data, sizeof(data));
  24. if (r <= 0)
  25. break;
  26. assert(r >= 0);
  27. uint64_t now = system_clock();
  28. if (0 == base)
  29. {
  30. base = now;
  31. clock0 = clock;
  32. }
  33. else
  34. {
  35. if (now - base < clock - clock0)
  36. {
  37. uint64_t v = (uint64_t)(clock - clock0) - (now - base);
  38. if(v < 5000)
  39. system_sleep(v);
  40. }
  41. }
  42. printf("rtpdump replay [%u] bytes: %d\n", clock, r);
  43. assert(r == socket_sendto(udp, data, r, 0, (sockaddr*)&addr, addrlen));
  44. }
  45. rtpdump_close(dump);
  46. socket_close(udp);
  47. socket_cleanup();
  48. }