[node-webkit] Fast copy node buffer to DOM ArrayBuffer

6 views
Skip to first unread message

Denys Khanzhyiev

unread,
May 10, 2014, 6:15:56 PM5/10/14
to node-webkit
I have an idea to implement video player module in NW based on ffmpeg, canvas and Web Audio API.

Originally I was in need to play IPTV streams (mutlicast UDP). First I tryed to use MediaSource API, with conversion from multicast UDP MPEG 2 TS to MPEG 4 DASH  standard sections. This approach works but it is too much components (ffmpeg + MP4box) and unnecessary transcoding, temporary files etc,

Now I have working much simpler prototype - direct decoding by ffmpeg to raw frames and pcm, raw frames are rendered then with canvas, and pcm stream played using web audio api. This works good for SD video and I'll release simple module for this soon. But for HD video poor performance of Node Buffers to DOM ArrayBuffer makes technology unusable. What is strange video plays smooth, but audio glitches, when I switch off video frames copying, audio plays good.

 For me copying node Buffer to DOM array buffer takes (for 1920x800x32bit frame) about 30 ms. The fastest method I found is 

var domBuffer = new window.Uint8Array(nodeBuffer);

while copying same buffer between dom buffers takes about 1 ms.

So the question is Is there any other faster method to transfer data from Node Buffer to DOM ArrayBuffer ? 

The method is very promising as solves any media playing problems w/o need of replacing ffmpegsumo. It is possible to play any formats supproted by ffmpeg, and to play various streams (udp, rtp, mutlicast) directly in NW.

Denys Khanzhyiev

unread,
May 10, 2014, 8:45:03 PM5/10/14
to node-webkit

Roger Wang

unread,
May 11, 2014, 1:10:10 AM5/11/14
to node-...@googlegroups.com
I'm thinking to support converting Buffer to ArrayBuffer with zero-copy. This is quite doable in Chromiium C++ code. I'll look to add this in future version. Please submit an issue to track it.

Roger

Denys Khanzhyiev

unread,
May 11, 2014, 6:20:09 PM5/11/14
to node-webkit
I have found that NW 0.9.X (as based on Node 0.11.X) has Buffer.toArrayBuffer method which is quite performant.
So writing

var domBuffer = new window.Uint8Array(nodeBuffer.toArrayBuffer());

instead of 

var domBuffer = new window.Uint8Array(nodeBuffer);

is about 1ms vs 30ms. But my demo nw app crashes after a dozen seconds of playback(probably on GC invocation). It looks like GC cleans something wrong, though Buffer.toArrayBuffer makes a copy (not zero copy) - I looked into sources.

I also achived smoother playback with just 500ms buffering. Will update repo.



--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages