curl-library
Serious problem with CURLOPT_WRITEDATA
Date: Mon, 24 Jun 2013 01:12:27 -0400
I am developing a libcurl-based multi-threaded headless Linux service programmed in C that performs work with video streams. The video streams are RTSP therefore I am using the following source code as the basis of my initial implementation tests...
http://curl.haxx.se/libcurl/c/rtsp.html
Due to the design of the software the callback function described by CURLOPT_WRITEFUNCTION must be accompanied by an object pointer containing the private thread data. The frustrating part is that it works the first time but not anymore after that.
The following code will work fine...
my_curl_easy_setopt(TestApp.CurlInfo.curl, CURLOPT_WRITEFUNCTION, &TestWriteFunction);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RTSP_STREAM_URI, TestApp.CurlInfo.URI);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RANGE, NULL);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_WRITEDATA, &TestApp);
my_curl_easy_perform(TestApp->CurlInfo.curl);
But if I repeat the perform command in order to collect the stream data, "TestApp" will not be sent and in its place will be a NULL...
my_curl_easy_setopt(TestApp.CurlInfo.curl, CURLOPT_WRITEFUNCTION, &TestWriteFunction);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RTSP_STREAM_URI, TestApp.CurlInfo.URI);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RANGE, NULL);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_WRITEDATA, &TestApp);
my_curl_easy_perform(TestApp->CurlInfo.curl); // userdata = &TestApp
my_curl_easy_perform(TestApp->CurlInfo.curl); // userdata = NULL
I have tried many configurations with no avail..
my_curl_easy_setopt(TestApp.CurlInfo.curl, CURLOPT_WRITEFUNCTION, &TestWriteFunction);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RTSP_STREAM_URI, TestApp.CurlInfo.URI);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RANGE, NULL);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_WRITEDATA, &TestApp);
my_curl_easy_perform(TestApp->CurlInfo.curl); // userdata = &TestApp
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_WRITEDATA, &TestApp);
my_curl_easy_perform(TestApp->CurlInfo.curl); // userdata = NULL
And...
my_curl_easy_setopt(TestApp.CurlInfo.curl, CURLOPT_WRITEFUNCTION, &TestWriteFunction);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RTSP_STREAM_URI, TestApp.CurlInfo.URI);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RANGE, NULL);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_WRITEDATA, &TestApp);
my_curl_easy_perform(TestApp->CurlInfo.curl); // userdata = &TestApp
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RTSP_STREAM_URI, TestApp.CurlInfo.URI);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RANGE, NULL);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_WRITEDATA, &TestApp);
my_curl_easy_perform(TestApp->CurlInfo.curl); // userdata = NULL
And...
my_curl_easy_setopt(TestApp.CurlInfo.curl, CURLOPT_WRITEFUNCTION, &TestWriteFunction);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RTSP_STREAM_URI, TestApp.CurlInfo.URI);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RANGE, NULL);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_WRITEDATA, &TestApp);
my_curl_easy_perform(TestApp->CurlInfo.curl); // userdata = &TestApp
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_WRITEDATA, NULL);
my_curl_easy_setopt (TestApp.CurlInfo.curl, CURLOPT_WRITEDATA, &TestApp);
my_curl_easy_perform(TestApp->CurlInfo.curl); // userdata = NULL
None of these will send "TestApp" to the callback function on the second call. Does anyone have any ideas what might be wrong here?
Thank you in advance for your help.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-06-24