curl / Mailing Lists / curl-users / Single Mail

curl-users

Re: HTTP1.1 chunked encoding - stream audio data

From: channa reddy patil <reddychanna_at_rediffmail.com>
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 &lt;curl-users_at_cool.haxx.se&gt;Sent: Fri, 28 Apr 2017 10:40:13 To: curl-users_at_cool.haxx.seCc: Ray Satiro &lt;raysatiro_at_yahoo.com&gt;Subject: Re: HTTP1.1 chunked encoding - stream audio dataOn 4/27/2017 3:15 PM, channa reddy patil wrote:

&gt; I have a question regarding if we can use curl to stream live audio

&gt; captured from the MIC device.

&gt; The problem I am facing is, the server is responding back immediately

&gt; after the first chunk since it receives a end of chunk frame. Below

&gt; are the steps I want to do

&gt; 1. read MIC device some bytes to a buffer

&gt; 2. Pass the buffer to curl to send it as chunked data

&gt; 3. repeat step-1 again.

&gt; Basically I do not want curl to send the end of with the transfer of

&gt; 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-&gt;uldata_available) {

 &nbsp;userp-&gt;last_pause |= CURLPAUSE_SEND;

 &nbsp;return CURL_READFUNC_PAUSE;

}

Beginning of progress function:

if((userp-&gt;last_pause &amp; CURLPAUSE_SEND) &amp;&amp; userp-&gt;uldata_available) {

 &nbsp;userp-&gt;last_pause &amp;= ~CURLPAUSE_SEND;

 &nbsp;res = curl_easy_pause(userp-&gt;handle, userp-&gt;last_pause);

 &nbsp;if(res != CURLE_OK)

 &nbsp; &nbsp;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: &nbsp; 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