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.

38 lines
809B

  1. #include "sockutil.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <assert.h>
  6. #include <stdint.h>
  7. void rtp_sender_test(const char* peer, int port, const char* rtpfile)
  8. {
  9. uint8_t packet[64 * 1024];
  10. socket_init();
  11. socket_t udp = socket_udp_bind_ipv4(NULL, 0);
  12. struct sockaddr_storage addr;
  13. socklen_t addrlen = sizeof(addr);
  14. memset(&addr, 0, sizeof(addr));
  15. socket_addr_from(&addr, &addrlen, peer, port);
  16. FILE* fp = fopen(rtpfile, "rb");
  17. uint8_t s2[2];
  18. while (2 == fread(s2, 1, 2, fp))
  19. {
  20. int size = (s2[0] << 8) | s2[1];
  21. assert(size < sizeof(packet));
  22. if (size != (int)fread(packet, 1, size, fp))
  23. break;
  24. int r = socket_sendto(udp, packet, size, 0, (struct sockaddr*)&addr, addrlen);
  25. assert(size == r);
  26. }
  27. fclose(fp);
  28. socket_close(udp);
  29. socket_cleanup();
  30. }