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.

77 lines
2.1KB

  1. // rfc2326 12.33 RTP-Info (p55)
  2. // used to set RTP-specific parameters in the PLAY response
  3. // parameter: url rtp stream url
  4. // parameter: seq digit
  5. // parameter: rtptime digit
  6. // RTP-Info = "RTP-Info" ":" 1#stream-url 1*parameter
  7. // stream-url = "url" "=" url
  8. // parameter = ";" "seq" "=" 1*DIGIT
  9. // | ";" "rtptime" "=" 1*DIGIT
  10. //
  11. // e.g. RTP-Info: url=rtsp://foo.com/bar.avi/streamid=0;seq=45102,url=rtsp://foo.com/bar.avi/streamid=1;seq=30211
  12. #include "rtsp-header-rtp-info.h"
  13. #include <stdio.h>
  14. #include <assert.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <inttypes.h>
  18. #if defined(_WIN32) || defined(_WIN64) || defined(OS_WINDOWS)
  19. #define strncasecmp _strnicmp
  20. #endif
  21. #define RTP_INFO_SPECIAL ",;\r\n"
  22. int rtsp_header_rtp_info(const char* field, struct rtsp_header_rtp_info_t* rtpinfo)
  23. {
  24. const char* p1;
  25. const char* p = field;
  26. while(p && *p)
  27. {
  28. p1 = strpbrk(p, RTP_INFO_SPECIAL);
  29. if(0 == strncasecmp("url=", p, 4))
  30. {
  31. size_t n = (size_t)(p1 - p - 4); // ptrdiff_t -> size_t
  32. if(n >= sizeof(rtpinfo->url))
  33. return -1;
  34. memcpy(rtpinfo->url, p+4, n);
  35. rtpinfo->url[n] = '\0';
  36. }
  37. else if(1 == sscanf(p, "seq = %" PRIu64, &rtpinfo->seq))
  38. {
  39. }
  40. else if(1 == sscanf(p, "rtptime = %" PRIu64, &rtpinfo->rtptime))
  41. {
  42. }
  43. else
  44. {
  45. assert(0); // unknown parameter
  46. }
  47. if(NULL == p1 || '\r' == *p1 || '\n' == *p1 || '\0' == *p1 || ',' == *p1)
  48. break;
  49. p = p1 + 1;
  50. }
  51. return 0;
  52. }
  53. #if defined(DEBUG) || defined(_DEBUG)
  54. void rtsp_header_rtp_info_test(void)
  55. {
  56. struct rtsp_header_rtp_info_t rtp;
  57. memset(&rtp, 0, sizeof(rtp));
  58. assert(0 == rtsp_header_rtp_info("url=rtsp://foo.com/bar.avi/streamid=0;seq=45102", &rtp)); // rfc2326 p56
  59. assert(0 == strcmp(rtp.url, "rtsp://foo.com/bar.avi/streamid=0"));
  60. assert(rtp.seq == 45102);
  61. memset(&rtp, 0, sizeof(rtp));
  62. assert(0 == rtsp_header_rtp_info("url=rtsp://foo.com/bar.avi/streamid=0;seq=45102;rtptime=123456789, url=rtsp://foo.com/bar.avi/streamid=1;seq=30211", &rtp));
  63. assert(0 == strcmp(rtp.url, "rtsp://foo.com/bar.avi/streamid=0"));
  64. assert(rtp.seq == 45102 && rtp.rtptime == 123456789);
  65. }
  66. #endif