Hello all,
I am using jni+curl+nghttp2+openssl to do request from AVS on Android. But I am stuck with 2 problems as follows:
1. Long time voice interaction
Like here https://forums.developer.amazon.com/questions/33828/long-time-voice-interaction.html , it cost long time to response. I record audio on java layer, and save the audio data to a file. Then I post the file to avs on jni like this:
code = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "uploadfile", CURLFORM_FILE, filename_str, CURLFORM_CONTENTTYPE, content_type_str, CURLFORM_END); code = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "filename", CURLFORM_COPYCONTENTS, "avsrec.pcm", CURLFORM_END);
A few seconds later, I get the audio response from avs, it's normal. But it cost too long time.
I try to do as swasey@amazon said to use CURLOPT_READFUNCTION, but I cannot get the correct response. I write the multipart body to a buffer which contains audio data in java layer, and then send it in jni layer with the curse of using CURLOPT_READFUNCTION like this:
struct postdata curl_fetch_read; curl_fetch_read.data = (const char*)p_content; curl_fetch_read.body_pos = 0; curl_fetch_read.body_size = content_length; ... curl_easy_setopt(eh, CURLOPT_READFUNCTION, &on_read); curl_easy_setopt(eh, CURLOPT_READDATA, &curl_fetch_read);
As I said, it failed. The function CURLOPT_READFUNCTION on_read is to copy buffer data to send. I found that it's max size seems to be 16384, but my buffer size is more than that. So maybe it cause the request sended incorrectly.
Can anyone give me an example or advice about how to use CURLOPT_READFUNCTION to do the post reqeust?
2. Cannot get the directives
Also use curl the get directives like alarm, timer. Request header and body are both normal. But when doing request with below option
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
I can get a response but not with body data, just header.
When I set the option like this
curl_easy_setopt(curl, CURLOPT_NOBODY, 0L);
I cannot get any normal data. It just reach timeout.
So, can anyone give me an example or advice about how to use curl to get directives from avs.
Thank you.