Skip to content

Commit

Permalink
vcomp/cmpto_j2k: if enc fails, free data
Browse files Browse the repository at this point in the history
We need to release the resources if encode fails - otherwise eg. the
pool will get exhausted because it has a limited capacity.

+ print enc image failure whether was in push or pop
  • Loading branch information
MartinPulec committed Aug 26, 2024
1 parent 9304717 commit 9577372
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/video_compress/cmpto_j2k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,9 @@ static std::shared_ptr<video_frame> j2k_compress_pop(struct module *state)
struct cmpto_j2k_enc_img *img;
int status;
CHECK_OK(cmpto_j2k_enc_ctx_get_encoded_img(
s->context,
1,
&img /* Set to NULL if encoder stopped */,
&status), "Encode image", HANDLE_ERROR_COMPRESS_POP);
s->context, 1, &img /* Set to NULL if encoder stopped */,
&status),
"Encode image pop", HANDLE_ERROR_COMPRESS_POP);
{
unique_lock<mutex> lk(s->lock);
s->in_frames--;
Expand Down Expand Up @@ -516,8 +515,14 @@ static void j2k_compress_push(struct module *state, std::shared_ptr<video_frame>
unique_lock<mutex> lk(s->lock);
s->frame_popped.wait(lk, [s]{return s->in_frames < s->max_in_frames;});
lk.unlock();
bool failed = false;
CHECK_OK(cmpto_j2k_enc_img_encode(img, s->enc_settings),
"Encode image", return);
"Encode image push", failed = true);
if (failed) {
udata->frame.~shared_ptr<video_frame>();
cmpto_j2k_enc_img_destroy(img);
return;
}
lk.lock();
s->in_frames++;
lk.unlock();
Expand Down

0 comments on commit 9577372

Please sign in to comment.