I have implemented HTTP streaming for an MPEG player in this sample: https://floooh.github.io/sokol-html5/plmpeg-sapp.html
However this doesn't use any of the emscripten APIs but instead uses embedded Javascript to do the streaming through XmlHttpRequest objects. The whole library is a bit more involved since it does a bit more then just streaming, but maybe you can rip out the relevant parts (or even just use it as is, it's a totally self-contained single-file library): https://github.com/floooh/sokol/blob/master/sokol_fetch.h Incremental streaming of large data files (such as the MPEG file) is done through HTTP range-requests to only load small parts of the file at once, but there's some action required by the application code to pause and continue the streaming so that there's always enough data preloaded for the video not to starve, but also not too much so that memory use doesn't explode. The actual sample source code is here, this also has some comments to explain how the whole thing works: https://github.com/floooh/sokol-samples/blob/master/sapp/plmpeg-sapp.c Hope this helps, -Floh. On Wednesday, 22 July 2020 16:51:30 UTC+2, Flix wrote: > > Hi, > > I'd like to port a (very basic) mp3 internet radio player to emscripten. > > The original C code uses libcurl, but the whole libcurl code is just > something like: > > // curl stream callback > size_t stream_callback(char *ptr, size_t size, size_t nmemb, void * > userdata) { > [...] > } > > int main(int argc, char* argv[]) { > CURL *c;CURLcode res; > const char * webaddr = NULL;/* URL of the radio-station in > <ip-addr>:<port> format */ > c = curl_easy_init(); > curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, stream_callback); > curl_easy_setopt (c, CURLOPT_NOPROGRESS, 1); > curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); > curl_easy_setopt(c, CURLOPT_URL, webaddr); > res = curl_easy_perform(c); > /* curl_easy_perform(...) never returns unless user forces > stream_callback to return 0, that results in res==CURLE_WRITE_ERROR */ > curl_easy_cleanup(c); > return 0; > } > > Basically I've seen that emscripten provides other ways to replace libcurl > (the emscripten_async_wget() function family), but, as far as I can > understand from the docs, there's no way to handle an "infinite" stream > (because in the example code "stream_callback(...)" never stops (unless > user wants it to stop). > > Is there a way to do the same in emscripten? > > Thank you in advance. > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/0f78118e-5833-45a1-b4d7-e74494ac38cfo%40googlegroups.com.
