curl-users
Re: HTTP1.1 chunked encoding - stream audio data
Date: 3 May 2017 16:30:29 -0000
Thank you for your response. I am trying to do something similar to what you explained. But I see that curl_easy_perform does not return at all even if I return CURL_READFUNC_PAUSE. I want curl_easy_perform to return every time so that I can check if there was something in response from the server to the transfer that was done. And based on if there was a reponse and type of response I either want to resume sending data or otherwise.From: Ray Satiro via curl-users <curl-users_at_cool.haxx.se>Sent: Fri, 28 Apr 2017 10:40:13 To: curl-users_at_cool.haxx.seCc: Ray Satiro <raysatiro_at_yahoo.com>Subject: Re: HTTP1.1 chunked encoding - stream audio dataOn 4/27/2017 3:15 PM, channa reddy patil wrote:
> I have a question regarding if we can use curl to stream live audio
> captured from the MIC device.
> The problem I am facing is, the server is responding back immediately
> after the first chunk since it receives a end of chunk frame. Below
> are the steps I want to do
> 1. read MIC device some bytes to a buffer
> 2. Pass the buffer to curl to send it as chunked data
> 3. repeat step-1 again.
> Basically I do not want curl to send the end of with the transfer of
> the first buffer
If the server will wait then yes. You can pause the stream by returning
CURL_READFUNC_PAUSE [1] from your read function instead of 0. You can
use the progress callback [2][3][4] to check whether more uldata is
available and to unpause [5]. Note the progress function is called quite
frequently, at least once per second, so do as little processing there
as possible.
I actually can't find I've done this so I don't have a working sample
for you. I'm going to take a shot at how I think it would look but I'd
wait a bit in case someone more experienced in this area says it's wrong:
For each handle have a variable last_pause that tracks the handle's
pause state. Set it to 0 before calling perform on the handle, and then
during perform set it to the pause state you set with curl_easy_pause or
return from read function with CURL_READFUNC_PAUSE (last_pause |=
CURLPAUSE_SEND) or from write function with CURL_WRITEFUNC_PAUSE
(last_pause |= CURLPAUSE_RECV).
uldata_available represents some way you determine if upload data is
available.
Beginning of read function:
if(!userp->uldata_available) {
userp->last_pause |= CURLPAUSE_SEND;
return CURL_READFUNC_PAUSE;
}
Beginning of progress function:
if((userp->last_pause & CURLPAUSE_SEND) && userp->uldata_available) {
userp->last_pause &= ~CURLPAUSE_SEND;
res = curl_easy_pause(userp->handle, userp->last_pause);
if(res != CURLE_OK)
return (int)res;
}
[1]: https://curl.haxx.se/libcurl/c/CURLOPT_READFUNCTION.html
[2]: https://curl.haxx.se/libcurl/c/CURLOPT_XFERINFOFUNCTION.html
[3]: https://curl.haxx.se/libcurl/c/CURLOPT_NOPROGRESS.html
[4]: https://curl.haxx.se/libcurl/c/CURLOPT_XFERINFODATA.html
[5]: https://curl.haxx.se/libcurl/c/curl_easy_pause.html
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-05-03