Re: How to get data chunk from a ReadableStream in c/c++

2022-01-07 Thread Floh
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 jiao...@gmail.com 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 emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/8fca4565-04a9-4449-b97c-f543b347233dn%40googlegroups.com.


Re: typescripten: Type-safe JavaScript interop with complex types

2022-01-07 Thread Sebastian Theophil
Hi Alon,

thank you very much and it's great to hear that you find this interesting.
I would be very interested in integrating this with emscripten of course.
How should we start this process? There are probably a few things that
still need to be implemented for a good MVP, so to speak.

Regards
Sebastian

Am Do., 6. Jan. 2022 um 21:59 Uhr schrieb Alon Zakai :

> Hi Sebastian,
>
> This is really nice! I watched your talk as well at CppCon (
> https://www.youtube.com/watch?v=CLuhogat6aY), very interesting.
>
> For a while it's seemed like we need something in this general area, so
> it's great to see it happen! I think this is a very good design, too (the
> performance issue with strings is the one concern I have, but as you say in
> the talk, that can be optimized - I'd use EM_JS for that probably).
>
> Did you have ideas about integrating this with upstream Emscripten? I
> think that might make sense to do, although maybe as part of a larger
> conversation on our bindings story (atm we have embind and the WebIDL
> binder, which already have some overlap).
>
> - Alon Zakai
>
> On Tue, Dec 28, 2021 at 2:21 AM Sebastian Theophil 
> wrote:
>
>> Hi,
>>
>> I wanted to plug my own project for some time here on the mailing list
>> because it also handles JavaScript - C++ interop and now wajic came up so I
>> thought I pitch in.
>>
>> My project https://github.com/think-cell/typescripten produces type-safe
>> C++ interfaces to JavaScript standard libraries or third-party libraries.
>> It reads TypeScript interface definition files and transforms them into C++
>> shims based on emscripten.
>>
>> The resulting C++ code is often a straight-forward port from
>> TypeScript/JavaScript, e.g.,
>>
>> JavaScript:
>>
>> var elem = document.createElement("p")
>> elem.innerText = "Hello CppCon 2021"
>> elem.style.fontSize = "20.0"
>> document.body.appendChild(elem)
>>
>> C++:
>>
>> auto elem = js::document()->createElement(js::string("p"));
>> elem->innerText(js::string("Hello CppCon 2021"));
>> elem->style()->fontSize(js::string("20vh"));
>> js::document()->body()->appendChild(elem);
>>
>> No macros and the C++ functions return typed JavaScript objects! Because
>> we use the TypeScript interface definitions, the C++ code is typechecked.
>> Passing a number to fontSize will create a compiler error.
>>
>> The project is not yet meaningfully complete but it bootstraps
>> successfully, i.e., the compiler understands the interface definition file
>> for the TypeScript compiler and parser API that it uses itself. TypeScript
>> generic constraints are not yet supported, for example, but should be.
>>
>> Maybe somebody else finds this useful. We have used it internally for a
>> small web app already that needed to call the tableau.com JavaScript
>> API.
>>
>> Regards
>> Sebastian
>>
>> --
>> 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 emscripten-discuss+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/emscripten-discuss/CAN%3D%3DuddahRRPV02%3DT9TaQd2%3D3YzxqHDBAqg8%3DsWJL-Taqh4-SQ%40mail.gmail.com
>> 
>> .
>>
> --
> 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 emscripten-discuss+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpSo_RuoctMU1TZObpugbtxS%3DgqrU-41typx2LuDKKMkWw%40mail.gmail.com
> 
> .
>

-- 
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 emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAN%3D%3Dudd2f0LqvFaCA%2BO7GUa5Yw6rfnnS8CxOzSHQqgcYdvxGUg%40mail.gmail.com.


How to get data chunk from a ReadableStream in c/c++

2022-01-07 Thread zebo jiao
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 emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/d761b193-487a-4e5c-95ad-5aac0e67425dn%40googlegroups.com.