Discussion:
[nodejs] N-API Continuous callbacks for c++ media stream
Victor du Mesnil du Buisson
2018-06-12 11:47:40 UTC
Permalink
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 <https://nodejs.org/api/n-api.html>. 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
<https://nodejs.org/api/n-api.html#n_api_napi_create_async_work>, by
creating a lambda function in the execute parameter function, which would
allow me to call napi_make_callback
<https://nodejs.org/api/n-api.html#n_api_napi_make_callback> for every
frame callback, but then I get the following error :

Fatal error in HandleScope::HandleScopeEntering 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!
--
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+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/c38a453a-8ed2-46a2-b4a1-660d8587b649%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mikkel Wilson
2018-06-14 15:06:05 UTC
Permalink
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
<https://github.com/paixaop/node-sodium/blob/master/src/include/node_sodium.h>.
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
https://www.oblivious.io/ <https://www.oblivious.io/?r=googlenodejs>


On Tuesday, June 12, 2018 at 9:34:36 PM UTC-7, Victor du Mesnil du Buisson
Post by Victor du Mesnil du Buisson
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 <https://nodejs.org/api/n-api.html>. 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
<https://nodejs.org/api/n-api.html#n_api_napi_create_async_work>, by
creating a lambda function in the execute parameter function, which would
allow me to call napi_make_callback
<https://nodejs.org/api/n-api.html#n_api_napi_make_callback> for every
Fatal error in HandleScope::HandleScopeEntering 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!
--
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+***@googlegroups.com.
To post to this group, send email to ***@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.
Victor dMdB
2018-06-14 18:07:29 UTC
Permalink
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.

You can find my solution here:
https://stackoverflow.com/questions/50815038/n-api-continuous-callbacks-for-c-media-stream/50828983#50828983

It works great now.
ᐧ
Post by Mikkel Wilson
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
<https://github.com/paixaop/node-sodium/blob/master/src/include/node_sodium.h>.
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
https://www.oblivious.io/ <https://www.oblivious.io/?r=googlenodejs>
On Tuesday, June 12, 2018 at 9:34:36 PM UTC-7, Victor du Mesnil du Buisson
Post by Victor du Mesnil du Buisson
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 <https://nodejs.org/api/n-api.html>. 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
<https://nodejs.org/api/n-api.html#n_api_napi_create_async_work>, by
creating a lambda function in the execute parameter function, which would
allow me to call napi_make_callback
<https://nodejs.org/api/n-api.html#n_api_napi_make_callback> for every
Fatal error in HandleScope::HandleScopeEntering 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!
--
Job board: http://jobs.nodejs.org/
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/1348808f-3923-4ec6-8b3a-4acc9603da03%40googlegroups.com
<https://groups.google.com/d/msgid/nodejs/1348808f-3923-4ec6-8b3a-4acc9603da03%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
Find my profile on LinkedIn:

https://www.linkedin.com/in/victordmdb/
<http://uk.linkedin.com/in/victordmdb>
--
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+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAJvjMc_pu%2Bfb9_f_MeWkEPEsw%3DiqQSSG32BwvM_nQVJjLAOnUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...