N-API Continuous callbacks for c++ media stream

118 views
Skip to first unread message

Victor du Mesnil du Buisson

unread,
Jun 13, 2018, 12:34:36 AM6/13/18
to nodejs

I'm trying to create a node interface for a c++ media player. Upon decoding of a frame, there is an event which allows me to access the frame data, which I'm trying to funnel into node. But I can't seem to figure out how to get that kind of functionality to work with the functions available in the node api. My approach, for the time being, is to figure out a push mechanism to get the data from c++ to javascript where all i need is to initialize a callback in javascript, since it seems more elegant. If that fails I could create a polling loop in js to check if there is new frame data, but it seems less efficient.

I've tried with napi_create_async_work, by creating a lambda function in the execute parameter function, which would allow me to call napi_make_callback for every frame callback, but then I get the following error :

Fatal error in HandleScope::HandleScope
Entering the V8 API without proper locking in place

I'm likely approaching this incorrectly, its the first time I use n-api.

Any help is welcome, thank you!

Mikkel Wilson

unread,
Jun 14, 2018, 11:51:41 AM6/14/18
to nodejs
I had this same problem last year. I really wanted to use N-API because it's considered the new hotness and will make things portable going forward and not tied directly to V8. However, the documentation and examples available on the web are all about Native Addons for Node, which is tied to V8. I can see from your error message that you've made at least one call that's using the V8 API. This shouldn't happen if all the functions are pure N-API.

Eventually I fell back and stuck with NAN instead of using N-API. It was drastically simpler and I can revisit the code when N-API becomes more stable and well documented. One project I found to have a lot of good examples and macros was libsodium. This helped me learn how to convert data types back and forth between node and C. There should be some stream examples in here as well that may be of particular use for you.

I realize I'm answering your question about N-API by telling you to not use N-API, but maybe this is an alternative solution.

Best,
Mikkel

Victor dMdB

unread,
Jun 14, 2018, 2:12:45 PM6/14/18
to nod...@googlegroups.com
Thanks for the answer Mikkel!

I figured it out eventually, by using the C++ N-API wrapper and some extra functionality from a git repo which used libuv.


It works great now.

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/1348808f-3923-4ec6-8b3a-4acc9603da03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Find my profile on LinkedIn:


Reply all
Reply to author
Forward
0 new messages