/ 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}
Expand |
Embed | Plain Text
#include <stdio.h> #include <stdlib.h> #include <string.h> //include <stddef.h> #include <curl/curl.h> int main(int argc, char *argv[]) { CURL *csession; CURLcode res; struct curl_slist *custom_msg = NULL; char URL[256]; char temp_URL[256]; char request[256]; long rc; int port = 48000; FILE * protofile = NULL; protofile = fopen("Dump","wb"); if (argc < 2) { fprintf (stderr, "ERROR: enter a valid URL\n"); return -1; } csession = curl_easy_init(); if (csession == NULL) return -1; sprintf (URL, "%s", argv[1]); curl_easy_setopt(csession, CURLOPT_URL, URL); curl_easy_setopt(csession, CURLOPT_RTSP_STREAM_URI, URL); curl_easy_setopt(csession, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(csession, CURLOPT_HEADER, 1); // curl_easy_setopt(csession, CURLOPT_INTERLEAVEFUNCTION, rtp_write); curl_easy_setopt(csession, CURLOPT_INTERLEAVEDATA, protofile); //curl_easy_setopt(csession, CURLOPT_RANGE, NULL); curl_easy_setopt(csession, CURLOPT_VERBOSE, 1); /** retrieve OPTIONS */ curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS); res = curl_easy_perform(csession); res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc); if((res == CURLE_OK) && rc) { fprintf(stderr, "OPTIONS Response Code: %ld\n\n", rc); } else return -1; /** send DESCRIBE */ custom_msg = curl_slist_append(custom_msg, "Accept: application/x-rtsp-mh, application/rtsl, application/sdp"); curl_easy_setopt(csession, CURLOPT_RTSPHEADER, custom_msg); curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE); res = curl_easy_perform(csession); res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc); if((res == CURLE_OK) && rc) { fprintf(stderr, "DESCRIBE Response Code: %ld\n\n", rc); } else return -1; /** send SETUP */ /** send PLAY */ //curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_RECEIVE); //res = curl_easy_perform(csession); /** send GET_PARAMETER */ /** send TEARDOWN */ curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN); res = curl_easy_perform(csession); res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc); if((res == CURLE_OK) && rc) { fprintf(stderr, "TEARDOWN Response Code: %ld\n\n", rc); } else return -1; curl_easy_cleanup(csession); fclose(protofile); return 0; } CLI for build/ assemble $ gcc -O2 -g -Wall -c -fmessage-length=0 -MMD -MP -o "src/rtsp_client.o" $ gcc "src/rtsp_client.o" -o "src/rtsp_client.exe" -lcurl
You need to login to post a comment.
