Skip to content

Commit a1a6628

Browse files
committed
Another shuffle to try and shut down demuxers cleanly
1 parent d6b7541 commit a1a6628

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "beamcoder",
3-
"version": "0.6.7",
3+
"version": "0.6.8",
44
"description": "Node.js native bindings to FFmpeg.",
55
"main": "index.js",
66
"types": "index.d.ts",

src/format.cc

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3826,38 +3826,41 @@ void formatContextFinalizer(napi_env env, void* data, void* hint) {
38263826
AVFormatContext* fc = (AVFormatContext*) data;
38273827
Adaptor *adaptor = (Adaptor *)hint;
38283828
int ret;
3829-
if (fc->pb != nullptr) {
3830-
if (adaptor)
3831-
avio_context_free(&fc->pb);
3832-
else {
3833-
ret = avio_closep(&fc->pb);
3834-
if (ret < 0) {
3835-
printf("DEBUG: For url '%s', %s", (fc->url != nullptr) ? fc->url : "unknown",
3836-
avErrorMsg("error closing IO: ", ret));
3837-
}
3838-
}
3839-
}
3840-
// FIXME this is segfaulting ... why
3841-
/* if (fc->codec_whitelist != nullptr) {
3842-
av_freep(fc->codec_whitelist);
3843-
}
3844-
if (fc->format_whitelist != nullptr) {
3845-
av_freep(fc->format_whitelist);
3846-
}
3847-
if (fc->protocol_whitelist != nullptr) {
3848-
av_freep(fc->protocol_whitelist);
3849-
}
3850-
if (fc->protocol_blacklist != nullptr) {
3851-
av_freep(fc->protocol_blacklist);
3852-
} */
3829+
38533830
if (fc->iformat != nullptr) {
3854-
// The format context we get here is copy so the close_input call won't clear the JS format context
3831+
// The format context we get here is a copy so the close_input call won't clear the JS format context
38553832
// Hence copy the formatContext pointer to null the iformat after close to avoid a double delete
38563833
AVFormatContext* closeFc = fc;
38573834
avformat_close_input(&closeFc);
38583835
fc->iformat = nullptr;
3859-
} else if (fc->oformat != nullptr && !adaptor) // crashes otherwise...
3860-
avformat_free_context(fc);
3836+
} else if (fc->oformat != nullptr) {
3837+
if (fc->pb != nullptr) {
3838+
if (adaptor)
3839+
avio_context_free(&fc->pb);
3840+
else {
3841+
ret = avio_closep(&fc->pb);
3842+
if (ret < 0) {
3843+
printf("DEBUG: For url '%s', %s", (fc->url != nullptr) ? fc->url : "unknown",
3844+
avErrorMsg("error closing IO: ", ret));
3845+
}
3846+
}
3847+
}
3848+
// FIXME this is segfaulting ... why
3849+
/* if (fc->codec_whitelist != nullptr) {
3850+
av_freep(fc->codec_whitelist);
3851+
}
3852+
if (fc->format_whitelist != nullptr) {
3853+
av_freep(fc->format_whitelist);
3854+
}
3855+
if (fc->protocol_whitelist != nullptr) {
3856+
av_freep(fc->protocol_whitelist);
3857+
}
3858+
if (fc->protocol_blacklist != nullptr) {
3859+
av_freep(fc->protocol_blacklist);
3860+
} */
3861+
if (!adaptor) // crashes otherwise...
3862+
avformat_free_context(fc);
3863+
}
38613864
}
38623865

38633866
napi_value newStream(napi_env env, napi_callback_info info) {

0 commit comments

Comments
 (0)