cURL / Mailing Lists / curl-library / Single Mail

curl-library

multi interface and RTSP interleved

From: Paweł Kopalko <pawel.kopalko_at_gmail.com>
Date: Mon, 12 Sep 2016 11:33:23 +0200

Hi,
first of all hello to everyone (since this is my first mail here ;) )
I'm using curl with RTSP/RTP streams, until now I've used easy_perform,
which worked ok for me, but since I had to move to several threads there
are complications, and thus I need to use multi interface since I
understand that it will help me to regain some control.
But the problem is I cannot get it to work for me, I made a simple app to
POC the solution but doesn't work. It would seem that I don't understand
it fully, thus I need to ask for some help.
The code I use looks like that (note it works for easy_perform so I ommit
function bodies)

curl_global_init(CURL_GLOBAL_DEFAULT);
   rtsp_handle = curl_easy_init();
   curl_easy_setopt(rtsp_handle, CURLOPT_URL, argv[1]);
   curl_easy_setopt(rtsp_handle, CURLOPT_RTSP_STREAM_URI, argv[1]);
   curl_easy_setopt(rtsp_handle, CURLOPT_FOLLOWLOCATION, 1);
   curl_easy_setopt(rtsp_handle, CURLOPT_HEADER, 1);
   // curl_easy_setopt(rtsp_handle, CURLOPT_VERBOSE, 1);
   curl_easy_setopt(rtsp_handle, CURLOPT_INTERLEAVEDATA, (void *)fd);

   rtsp_options(rtsp_handle, argv[1]);

   rtsp_describe(rtsp_handle, sdp);

   sprintf(uri, "%s/%s", argv[1], "track0");
   rtsp_setup(rtsp_handle, uri, "RTP/AVP/TCP;interleaved=0-1");

   //sprintf(uri, "%s/", argv[1]);
   rtsp_play(rtsp_handle, uri, "0.000-");

   multi_handle = curl_multi_init();

   /* add the individual transfers */
   curl_multi_add_handle(multi_handle, rtsp_handle);
   do
   {
      CURLMcode mc; /* curl_multi_wait() return code */
      int numfds;
      CURLMsg *msg;

      /* wait for activity, timeout or "nothing" */
      mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
      printf("%s:%d-%s after curl_multi_wait return is %d \n", __FILE__,
__LINE__, __FUNCTION__, mc);
      if(mc != CURLM_OK)
      {
         fprintf(stderr, "curl_multi_wait() failed, code %d.\n", mc);
         break;
      }
      if(!numfds)
      {
         repeats++; /* count number of repeated zero numfds */
         if(repeats > 1)
         {
            WAITMS(100); /* sleep 100 milliseconds */
         }
      }
      else repeats = 0;

      curl_multi_perform(multi_handle, &still_running);
      int msgs_left;
      /* See how the transfers went */
      while((msg = curl_multi_info_read(multi_handle, &msgs_left)))
      {
         if(msg->msg == CURLMSG_DONE)
         {
            printf("%s:%d-%s after curl_multi_info_read return is
CURLMSG_DONE \n", __FILE__, __LINE__, __FUNCTION__);
            curl_multi_remove_handle(multi_handle, rtsp_handle);
            curl_easy_setopt(rtsp_handle, CURLOPT_RTSP_REQUEST,
(long)CURL_RTSPREQ_RECEIVE);
            curl_multi_remove_handle(multi_handle, rtsp_handle);
         }
      }
   }
   while(still_running);

   //rtsp_receive_data(rtsp_handle, 1, rtp_write_callback);

   rtsp_teardown(rtsp_handle);

   curl_easy_cleanup(rtsp_handle);
   curl_multi_cleanup(multi_handle);
   curl_global_cleanup();

All the examples showed that multi_info_read should be after do {} while()
but that kind of doesn't appeal to me (maybe that what is wrong), but
nevertheless I would like to ask for help understanding what I'm doing
wrong.

Regards,
Pawel

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-09-12