Skip to content

Commit

Permalink
Free decoder packet and improve decoder destructor
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Jan 20, 2024
1 parent 22b0812 commit 36deb29
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions c_src/xav/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,14 @@ int decoder_decode(struct Decoder *decoder, AVPacket *pkt, AVFrame *frame) {
}

return 0;
}

void decoder_free(struct Decoder *decoder) {
if (decoder->swr_ctx != NULL) {
swr_free(&decoder->swr_ctx);
}

if (decoder->c != NULL) {
avcodec_free_context(&decoder->c);
}
}
6 changes: 3 additions & 3 deletions c_src/xav/xav_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,20 @@ ERL_NIF_TERM decode(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
}

av_frame_free(&frame);
av_packet_free(&pkt);
return xav_nif_ok(env, frame_term);
}

void free_reader(ErlNifEnv *env, void *obj) {
XAV_LOG_DEBUG("Freeing Reader object");
struct Reader *reader = (struct Reader *)obj;
reader_free(reader);
}

void free_decoder(ErlNifEnv *env, void *obj) {
XAV_LOG_DEBUG("Freeing Decoder object");
struct Decoder *decoder = (struct Decoder *)obj;
if (decoder->c) {
avcodec_free_context(&decoder->c);
}
decoder_free(decoder);
}

static ErlNifFunc xav_funcs[] = {{"new_reader", 3, new_reader},
Expand Down

0 comments on commit 36deb29

Please sign in to comment.