You can read the C and Javascript source code in my sokol_fetch.h header for inspiration, this supports reading large data files piece by piece via HTTP Range requests (via XMLHttpRequest).
https://github.com/floooh/sokol/blob/master/sokol_fetch.h The interesting stuff is here: https://github.com/floooh/sokol/blob/4ff3ed7d604c3a876146cbf2d89597d81812de22/sokol_fetch.h#L1923-L2064 The fetched data is transferred to the C side by directly copying into the WASM heap here (using a pointer to a pre-allocated buffer from the C side): https://github.com/floooh/sokol/blob/4ff3ed7d604c3a876146cbf2d89597d81812de22/sokol_fetch.h#L1959 It should also be possible to dynamically allocate a memory chunk in the WASM heap on the Javascript side, but I haven't tried that yet. For such things I usually look in the Emscripten SDK's 'src' directory for examples. An example for sokol_fetch.h which loads data via Range requests is here (this uses https://github.com/phoboslab/pl_mpeg/blob/master/pl_mpeg.h to decode the MPEG stream): https://floooh.github.io/sokol-html5/plmpeg-sapp.html Cheers! -Floh. On Friday, 7 January 2022 at 13:07:44 UTC+1 [email protected] wrote: > Hi, > I want to compile ffmpeg to play some H.265 video on the web, i want to > use fetch api(https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) > in js layer to fetch the media data from my server and I can get a > ReadableStream, but how can i get the data chunk from this stream? what's > the best practice, or do i have a better solution? > > BTW I've tried the native fetch api ,since the media file may be too big > to load into memory, i must play it piece by piece. but the native fetch > api couldn't implement a "data chunk stream", i have to give it up. > > Best wishes. > Jiaozebo > -- 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/8fca4565-04a9-4449-b97c-f543b347233dn%40googlegroups.com.
