Commit b323c876 authored by Rafaël Carré's avatar Rafaël Carré

bluray: simplify overlay functions

parent b82f5755
...@@ -697,7 +697,9 @@ static void blurayCloseAllOverlays(demux_t *p_demux) ...@@ -697,7 +697,9 @@ static void blurayCloseAllOverlays(demux_t *p_demux)
demux_sys_t *p_sys = p_demux->p_sys; demux_sys_t *p_sys = p_demux->p_sys;
p_demux->p_sys->current_overlay = -1; p_demux->p_sys->current_overlay = -1;
if (p_sys->p_vout != NULL) { if (!p_sys->p_vout)
return;
for (int i = 0; i < 0; i++) { for (int i = 0; i < 0; i++) {
if (p_sys->p_overlays[i] != NULL) { if (p_sys->p_overlays[i] != NULL) {
vout_FlushSubpictureChannel(p_sys->p_vout, vout_FlushSubpictureChannel(p_sys->p_vout,
...@@ -706,11 +708,10 @@ static void blurayCloseAllOverlays(demux_t *p_demux) ...@@ -706,11 +708,10 @@ static void blurayCloseAllOverlays(demux_t *p_demux)
p_sys->p_overlays[i] = NULL; p_sys->p_overlays[i] = NULL;
} }
} }
var_DelCallback(p_sys->p_vout, "mouse-moved", &onMouseEvent, p_demux); var_DelCallback(p_sys->p_vout, "mouse-moved", onMouseEvent, p_demux);
var_DelCallback(p_sys->p_vout, "mouse-clicked", &onMouseEvent, p_demux); var_DelCallback(p_sys->p_vout, "mouse-clicked", onMouseEvent, p_demux);
vlc_object_release(p_sys->p_vout); vlc_object_release(p_sys->p_vout);
p_sys->p_vout = NULL; p_sys->p_vout = NULL;
}
} }
/* /*
...@@ -723,27 +724,27 @@ static void blurayCloseAllOverlays(demux_t *p_demux) ...@@ -723,27 +724,27 @@ static void blurayCloseAllOverlays(demux_t *p_demux)
static void blurayActivateOverlay(demux_t *p_demux, int plane) static void blurayActivateOverlay(demux_t *p_demux, int plane)
{ {
demux_sys_t *p_sys = p_demux->p_sys; demux_sys_t *p_sys = p_demux->p_sys;
bluray_overlay_t *ov = p_sys->p_overlays[plane];
/* /*
* If the overlay is already displayed, mark the picture as outdated. * If the overlay is already displayed, mark the picture as outdated.
* We must NOT use vout_PutSubpicture if a picture is already displayed. * We must NOT use vout_PutSubpicture if a picture is already displayed.
*/ */
vlc_mutex_lock(&p_sys->p_overlays[plane]->lock); vlc_mutex_lock(&ov->lock);
if ((p_sys->p_overlays[plane]->status == Displayed || if (ov->status >= Displayed && p_sys->p_vout) {
p_sys->p_overlays[plane]->status == Outdated) ov->status = Outdated;
&& p_sys->p_vout) { vlc_mutex_unlock(&ov->lock);
p_sys->p_overlays[plane]->status = Outdated;
vlc_mutex_unlock(&p_sys->p_overlays[plane]->lock);
return; return;
} }
/* /*
* Mark the overlay as available, but don't display it right now. * Mark the overlay as available, but don't display it right now.
* the blurayDemuxMenu will send it to vout, as it may be unavailable when * the blurayDemuxMenu will send it to vout, as it may be unavailable when
* the overlay is computed * the overlay is computed
*/ */
p_sys->current_overlay = plane; p_sys->current_overlay = plane;
p_sys->p_overlays[plane]->status = ToDisplay; ov->status = ToDisplay;
vlc_mutex_unlock(&p_sys->p_overlays[plane]->lock); vlc_mutex_unlock(&ov->lock);
} }
static void blurayInitOverlay(demux_t *p_demux, int plane, int width, int height) static void blurayInitOverlay(demux_t *p_demux, int plane, int width, int height)
...@@ -756,28 +757,30 @@ static void blurayInitOverlay(demux_t *p_demux, int plane, int width, int height ...@@ -756,28 +757,30 @@ static void blurayInitOverlay(demux_t *p_demux, int plane, int width, int height
if (unlikely(!p_sys->p_overlays[plane])) if (unlikely(!p_sys->p_overlays[plane]))
return; return;
bluray_overlay_t *ov = p_sys->p_overlays[plane];
subpicture_updater_sys_t *p_upd_sys = malloc(sizeof(*p_upd_sys)); subpicture_updater_sys_t *p_upd_sys = malloc(sizeof(*p_upd_sys));
if (unlikely(!p_upd_sys)) { if (unlikely(!p_upd_sys)) {
free(p_sys->p_overlays[plane]); free(ov);
p_sys->p_overlays[plane] = NULL; p_sys->p_overlays[plane] = NULL;
return; return;
} }
/* two references: vout + demux */ /* two references: vout + demux */
p_sys->p_overlays[plane]->released_once = ATOMIC_FLAG_INIT; ov->released_once = ATOMIC_FLAG_INIT;
p_upd_sys->p_overlay = p_sys->p_overlays[plane]; p_upd_sys->p_overlay = ov;
subpicture_updater_t updater = { subpicture_updater_t updater = {
.pf_validate = subpictureUpdaterValidate, .pf_validate = subpictureUpdaterValidate,
.pf_update = subpictureUpdaterUpdate, .pf_update = subpictureUpdaterUpdate,
.pf_destroy = subpictureUpdaterDestroy, .pf_destroy = subpictureUpdaterDestroy,
.p_sys = p_upd_sys, .p_sys = p_upd_sys,
}; };
vlc_mutex_init(&p_sys->p_overlays[plane]->lock); vlc_mutex_init(&ov->lock);
p_sys->p_overlays[plane]->p_pic = subpicture_New(&updater); ov->p_pic = subpicture_New(&updater);
p_sys->p_overlays[plane]->p_pic->i_original_picture_width = width; ov->p_pic->i_original_picture_width = width;
p_sys->p_overlays[plane]->p_pic->i_original_picture_height = height; ov->p_pic->i_original_picture_height = height;
p_sys->p_overlays[plane]->p_pic->b_ephemer = true; ov->p_pic->b_ephemer = true;
p_sys->p_overlays[plane]->p_pic->b_absolute = true; ov->p_pic->b_absolute = true;
} }
/** /**
...@@ -791,13 +794,15 @@ static void blurayInitOverlay(demux_t *p_demux, int plane, int width, int height ...@@ -791,13 +794,15 @@ static void blurayInitOverlay(demux_t *p_demux, int plane, int width, int height
static void blurayClearOverlay(demux_t *p_demux, int plane) static void blurayClearOverlay(demux_t *p_demux, int plane)
{ {
demux_sys_t *p_sys = p_demux->p_sys; demux_sys_t *p_sys = p_demux->p_sys;
bluray_overlay_t *ov = p_sys->p_overlays[plane];
vlc_mutex_lock(&ov->lock);
vlc_mutex_lock(&p_sys->p_overlays[plane]->lock); subpicture_region_ChainDelete(ov->p_regions);
ov->p_regions = NULL;
ov->status = Outdated;
subpicture_region_ChainDelete(p_sys->p_overlays[plane]->p_regions); vlc_mutex_unlock(&ov->lock);
p_sys->p_overlays[plane]->p_regions = NULL;
p_sys->p_overlays[plane]->status = Outdated;
vlc_mutex_unlock(&p_sys->p_overlays[plane]->lock);
} }
/* /*
...@@ -848,9 +853,8 @@ static void blurayDrawOverlay(demux_t *p_demux, const BD_OVERLAY* const ov) ...@@ -848,9 +853,8 @@ static void blurayDrawOverlay(demux_t *p_demux, const BD_OVERLAY* const ov)
const BD_PG_RLE_ELEM *img = ov->img; const BD_PG_RLE_ELEM *img = ov->img;
for (int y = 0; y < ov->h; y++) for (int y = 0; y < ov->h; y++)
for (int x = 0; x < ov->w;) { for (int x = 0; x < ov->w;) {
memset(p_reg->p_picture->p[0].p_pixels + plane_t *p = &p_reg->p_picture->p[0];
y * p_reg->p_picture->p[0].i_pitch + x, memset(&p->p_pixels[y * p->i_pitch + x], img->color, img->len);
img->color, img->len);
x += img->len; x += img->len;
img++; img++;
} }
...@@ -904,24 +908,18 @@ static void blurayOverlayProc(void *ptr, const BD_OVERLAY *const overlay) ...@@ -904,24 +908,18 @@ static void blurayOverlayProc(void *ptr, const BD_OVERLAY *const overlay)
/* /*
* ARGB overlay (BD-J) * ARGB overlay (BD-J)
*/ */
static void blurayInitArgbOverlay(demux_t *p_demux, int plane, int width, int height) static void blurayInitArgbOverlay(demux_t *p_demux, int plane, int width, int height)
{ {
demux_sys_t *p_sys = p_demux->p_sys; demux_sys_t *p_sys = p_demux->p_sys;
blurayInitOverlay(p_demux, plane, width, height); blurayInitOverlay(p_demux, plane, width, height);
/* If there is no region, create a new one. */ if (!p_sys->p_overlays[plane]->p_regions) {
subpicture_region_t *p_reg = p_sys->p_overlays[plane]->p_regions;
if (!p_reg) {
video_format_t fmt; video_format_t fmt;
video_format_Init(&fmt, 0); video_format_Init(&fmt, 0);
video_format_Setup(&fmt, VLC_CODEC_RGBA, width, height, 1, 1); video_format_Setup(&fmt, VLC_CODEC_RGBA, width, height, 1, 1);
p_reg = subpicture_region_New(&fmt); p_sys->p_overlays[plane]->p_regions = subpicture_region_New(&fmt);
p_reg->i_x = 0;
p_reg->i_y = 0;
p_sys->p_overlays[plane]->p_regions = p_reg;
} }
} }
...@@ -1366,9 +1364,11 @@ static int blurayDemux(demux_t *p_demux) ...@@ -1366,9 +1364,11 @@ static int blurayDemux(demux_t *p_demux)
} }
if (p_sys->current_overlay != -1) { if (p_sys->current_overlay != -1) {
vlc_mutex_lock(&p_sys->p_overlays[p_sys->current_overlay]->lock); bluray_overlay_t *ov = p_sys->p_overlays[p_sys->current_overlay];
if (p_sys->p_overlays[p_sys->current_overlay]->status == ToDisplay) { vlc_mutex_lock(&ov->lock);
vlc_mutex_unlock(&p_sys->p_overlays[p_sys->current_overlay]->lock); bool display = ov->status == ToDisplay;
vlc_mutex_unlock(&ov->lock);
if (display) {
if (p_sys->p_vout == NULL) if (p_sys->p_vout == NULL)
p_sys->p_vout = input_GetVout(p_sys->p_input); p_sys->p_vout = input_GetVout(p_sys->p_input);
if (p_sys->p_vout != NULL) { if (p_sys->p_vout != NULL) {
...@@ -1376,8 +1376,7 @@ static int blurayDemux(demux_t *p_demux) ...@@ -1376,8 +1376,7 @@ static int blurayDemux(demux_t *p_demux)
var_AddCallback(p_sys->p_vout, "mouse-clicked", onMouseEvent, p_demux); var_AddCallback(p_sys->p_vout, "mouse-clicked", onMouseEvent, p_demux);
bluraySendOverlayToVout(p_demux); bluraySendOverlayToVout(p_demux);
} }
} else }
vlc_mutex_unlock(&p_sys->p_overlays[p_sys->current_overlay]->lock);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment