Using cURL and rtsp



使用 cURL,我收到此错误

$ ./rtspclient.o rtsp://192.168.1.5:554/streamingVideos_10/Movie8minMedium.mov 2000 0 10
rtsp://192.168.1.5:554/streamingVideos_10/Movie8minMedium.mov
* Protocol rtsp not supported or disabled in libcurl
* Unsupported protocol

根据手册,这是由于错别字而发生的! 但是,这不适用于我的情况。

更多信息:

我已经成功安装了 cURL,如下所示

mkdir curlinst
./configure --prefix=/path/to/curldirectory/curlinst/ --enable-rtsp
make
make install

使用代码 rtspclientfinal.c :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream){
  printf("Size is: %dn",size);
  printf("Nmemb is: %dn",nmemb);
  return size*nmemb;
}
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 URLn");
      return -1;
  }
  csession = curl_easy_init();
  if (csession == NULL)
      return -1;
  printf("%sn", argv[1]);  
  sprintf (URL, "%s", argv[1]);
  port = atoi(argv[2]);
  int timeoutend = atoi(argv[3]);
  timeoutend *= 30; //timeoutend holds the correct number of seconds the stream is expected to last
  curl_easy_setopt(csession, CURLOPT_URL, URL);
  curl_easy_setopt(csession, CURLOPT_RTSP_STREAM_URI, URL);
  curl_easy_setopt(csession, CURLOPT_HEADER, 1);
  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: %ldnn", 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: %ldnn", rc);
  }
  else
      return -1;
  /** send SETUP */
  sprintf(temp_URL, "%s/trackID=3", URL);
  printf("%sn",temp_URL);
  curl_easy_setopt(csession, CURLOPT_RTSP_STREAM_URI, temp_URL);
  sprintf (request, "RTP/AVP/UDP;unicast;client_port=%d-%d", port,port+1);
  curl_easy_setopt(csession, CURLOPT_RTSP_TRANSPORT, request);
  curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
  res = curl_easy_perform(csession);
  res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
  if((res == CURLE_OK) && rc)
  {
      fprintf(stderr, "SETUP Response Code: %ldnn", rc);
  }
  else
      return -1;
  sprintf(temp_URL, "%s/trackID=4", URL);
  printf("%sn",temp_URL);
  curl_easy_setopt(csession, CURLOPT_RTSP_STREAM_URI, temp_URL);
  sprintf (request, "RTP/AVP/UDP;unicast;client_port=%d-%d", port,port+1);
  curl_easy_setopt(csession, CURLOPT_RTSP_TRANSPORT, request);
  curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
  res = curl_easy_perform(csession);
  res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
  if((res == CURLE_OK) && rc)
  {
      fprintf(stderr, "SETUP Response Code: %ldnn", rc);
  }
  else
      return -1;

  /** send PLAY */
  curl_easy_setopt(csession, CURLOPT_RTSP_STREAM_URI, URL);
  curl_easy_setopt(csession, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
  fprintf(stderr, "playing...nn");
  res = curl_easy_perform(csession);
  if(res != CURLE_OK)
  {
      fprintf(stderr, "PLAY failed: %d (%s)nn", res, curl_easy_strerror(res));
      return -1;
  } else {
      res = curl_easy_getinfo(csession, CURLINFO_RESPONSE_CODE, &rc);
      fprintf(stderr, "PLAY Response Code: %ldnn", rc);
  }

  sleep(timeoutend);
  /** 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: %ldnn", rc);
  }
  else
      return -1;
  curl_easy_cleanup(csession);
  return 0;
}

然后我用以下命令编译 rtspclientfinal.c

gcc -I /path/to/curl/curlinst/include -L /path/to/curl/curlinst/lib/ -lcurl rtspclientfinal.c -o rtspclient.o

没有任何错误。

我猜你使用的是系统的共享库libcurl,而不是你构建的那个。

您可以使用命令 ldd ./rtspclient.o 检查程序使用的 libcurl 。

为了加载你构建的库,你可以运行:

LD_LIBRARY_PATH=/path/to/curl/curlinst/lib/  ./rtspclient.o rtsp://192.168.1.5:554/streamingVideos_10/Movie8minMedium.mov 2000 0 10

相关内容

  • 没有找到相关文章

最新更新