Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(*): fix external buffers #7

Closed
wants to merge 1 commit into from
Closed

Conversation

stepancar
Copy link

Electron does not allow to use https://nodejs.org/api/n-api.html#napi_create_external_buffer
You can follow nodejs documentation or look at electron/electron#35801 directly

Because of this limitation I had to run old version of electron.

This PR fixes that problem.

I tried to avoid fix this issue itself, because I was not sure how to build beamcoder, how that c++ code should look, etc.
But it is just 3 lines of code, I tested it and it seems like it works.

I'm not sure about memory leaks.

My plan is just to release it and try to run electron on production

@stepancar stepancar marked this pull request as ready for review February 1, 2024 20:36
// work through frame bufs checking whether allocation refcounts are shared
for ( int x = 1 ; x < AV_NUM_DATA_POINTERS ; x++ ) {
// printf("Buffer %i is %p\n", x, f->frame->data[x]);
if (f->frame->data[x] == nullptr) continue;
size_t bufSize = size;
if (f->frame->buf[x] == nullptr)
bufSize = f->frame->data[x] - f->frame->data[x-1];
status = napi_create_external_buffer(env, bufSize, data, frameBufferFinalizer, ref, &element);
status = napi_create_buffer_copy(env, bufSize, data, &resultData, &element);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed you've removed the finalizers. Is there something we should still do for those? It seems like those are called when the objects are garbage collected. Do we not need to clean up the same way anymore?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is what you mean in the description for

I'm not sure about memory leaks.

@@ -56,7 +56,7 @@ void readComplete(napi_env env, napi_status asyncStatus, void *data) {
}
REJECT_STATUS;

c->status = napi_create_external_buffer(env, c->readLen, c->readBuf, readFinalizer, (void*)(uint64_t)c->readLen, &result);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED be helpful to define? I saw that here when reading docs

Copy link

@michaeljherrmann michaeljherrmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hard for me to review, but I tried! I think it's fine if you're just testing, just make sure we don't accidentally upgrade before we're ready

@stepancar
Copy link
Author

I'm closing this PR, because we found a way how to run nwjs in production which does not require this change

@stepancar stepancar closed this Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants