Posted By

rowntreerob on 08/16/11


Tagged

curl rtsp media stream sdp


Versions (?)

curl - rtsp to GET SDP descriptor for media stream


 / Published in: C
 

use with single arg for the RTSP Url . OPTIONS, DESCRIBE , TEARDOWN commands issued during the conversation.

use on windows: ./rtspclient.exe rtsp://{streamURI}

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. //include <stddef.h>
  5. #include <curl/curl.h>
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. CURL *csession;
  10. CURLcode res;
  11. struct curl_slist *custom_msg = NULL;
  12. char URL[256];
  13. char temp_URL[256];
  14. char request[256];
  15. long rc;
  16. int port = 48000;
  17. FILE * protofile = NULL;
  18. protofile = fopen("Dump","wb");
  19. if (argc < 2)
  20. {
  21. fprintf (stderr, "ERROR: enter a valid URL\n");
  22. return -1;
  23. }
  24. csession = curl_easy_init();
  25. if (csession == NULL)
  26. return -1;
  27. printf("%s\n", argv[1]);
  28. sprintf (URL, "%s", argv[1]);
  29. curl_easy_setopt(csession, CURLOPT_URL, URL);
  30. curl_easy_setopt(csession, CURLOPT_RTSP_STREAM_URI, URL);
  31. curl_easy_setopt(csession, CURLOPT_FOLLOWLOCATION, 1);
  32. curl_easy_setopt(csession, CURLOPT_HEADER, 1);
  33. // curl_easy_setopt(csession, CURLOPT_INTERLEAVEFUNCTION, rtp_write);
  34. curl_easy_setopt(csession, CURLOPT_INTERLEAVEDATA, protofile);
  35. //curl_easy_setopt(csession, CURLOPT_RANGE, NULL);
  36. curl_easy_setopt(csession, CURLOPT_VERBOSE, 1);
  37. /** retrieve OPTIONS */
  38. curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS);
  39. res = curl_easy_perform(csession);
  40. res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
  41. if((res == CURLE_OK) && rc)
  42. {
  43. fprintf(stderr, "OPTIONS Response Code: %ld\n\n", rc);
  44. }
  45. else
  46. return -1;
  47. /** send DESCRIBE */
  48. custom_msg = curl_slist_append(custom_msg, "Accept: application/x-rtsp-mh, application/rtsl, application/sdp");
  49. curl_easy_setopt(csession, CURLOPT_RTSPHEADER, custom_msg);
  50. curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
  51. res = curl_easy_perform(csession);
  52. res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
  53. if((res == CURLE_OK) && rc)
  54. {
  55. fprintf(stderr, "DESCRIBE Response Code: %ld\n\n", rc);
  56. }
  57. else
  58. return -1;
  59. /** send SETUP */
  60. /** send PLAY */
  61.  
  62. //curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_RECEIVE);
  63. //res = curl_easy_perform(csession);
  64. /** send GET_PARAMETER */
  65. /** send TEARDOWN */
  66. curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN);
  67. res = curl_easy_perform(csession);
  68. res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
  69. if((res == CURLE_OK) && rc)
  70. {
  71. fprintf(stderr, "TEARDOWN Response Code: %ld\n\n", rc);
  72. }
  73. else
  74. return -1;
  75. curl_easy_cleanup(csession);
  76. fclose(protofile);
  77. return 0;
  78. }
  79.  
  80. CLI for build/ assemble
  81.  
  82. $ gcc -O2 -g -Wall -c -fmessage-length=0 -MMD -MP -o "src/rtsp_client.o"
  83.  
  84. $ gcc "src/rtsp_client.o" -o "src/rtsp_client.exe" -lcurl

Report this snippet  

You need to login to post a comment.