Skip to content

Commit

Permalink
yuv: correctly handle reentrant inits, and fix close
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Dec 12, 2024
1 parent 1403e23 commit f3e4643
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/video/yuv.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,25 @@ DEFINE_RSP_UCODE(rsp_yuv,
#define CMD_YUV_INTERLEAVE4_32X16 0x2
#define CMD_YUV_INTERLEAVE2_32X16 0x3

static bool yuv_initialized = false;
static int8_t yuv_initialized = 0;

void yuv_init(void)
{
if (yuv_initialized)
return;

rspq_init();
ovl_yuv = rspq_overlay_register(&rsp_yuv);
yuv_initialized = true;
if (yuv_initialized == 0) {
rspq_init();
ovl_yuv = rspq_overlay_register(&rsp_yuv);
}
yuv_initialized++;
}

void yuv_close(void)
{
surface_free(&internal_buffer);
yuv_initialized = false;
assert(yuv_initialized > 0);
yuv_initialized--;
if (yuv_initialized == 0) {
surface_free(&internal_buffer);
rspq_overlay_unregister(ovl_yuv);
}
}

yuv_colorspace_t yuv_new_colorspace(float kr, float kb, int y0i, int yrangei, int crangei)
Expand Down

0 comments on commit f3e4643

Please sign in to comment.