From: Petri Hintukainen Date: Fri, 9 Aug 2013 11:04:58 +0000 (+0300) Subject: bluray: ARGB overlay support (BD-J) X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=97c403a20e0e1a7c0e83824728cfbae1718c139b;hp=6deffd85b0a443dd7c6e914acb4dbd376cdd29e3;p=vlc bluray: ARGB overlay support (BD-J) Signed-off-by: Rafaël Carré --- diff --git a/modules/access/bluray.c b/modules/access/bluray.c index c98301d7c9..d3b8ffa0a6 100644 --- a/modules/access/bluray.c +++ b/modules/access/bluray.c @@ -160,6 +160,7 @@ static int blurayInitTitles(demux_t *p_demux ); static int bluraySetTitle(demux_t *p_demux, int i_title); static void blurayOverlayProc(void *ptr, const BD_OVERLAY * const overlay); +static void blurayArgbOverlayProc(void *ptr, const BD_ARGB_OVERLAY * const overlay); static int onMouseEvent(vlc_object_t *p_vout, const char *psz_var, vlc_value_t old, vlc_value_t val, void *p_data); @@ -351,6 +352,11 @@ static int blurayOpen( vlc_object_t *object ) goto error; } + /* Register ARGB overlay handler for BD-J */ + if (disc_info->num_bdj_titles) { + bd_register_argb_overlay_proc(p_sys->bluray, p_demux, blurayArgbOverlayProc, NULL); + } + /* libbluray will start playback from "First-Title" title */ if (bd_play(p_sys->bluray) == 0) { error_msg = "Failed to start bluray playback. Please try without menu support."; @@ -904,6 +910,93 @@ static void blurayOverlayProc(void *ptr, const BD_OVERLAY *const overlay) } } +/* + * ARGB overlay (BD-J) + */ + +static void blurayInitArgbOverlay(demux_t *p_demux, int plane, int width, int height) +{ + demux_sys_t *p_sys = p_demux->p_sys; + + blurayInitOverlay(p_demux, plane, width, height); + + /* If there is no region, create a new one. */ + subpicture_region_t *p_reg = p_sys->p_overlays[plane]->p_regions; + if (!p_reg) { + video_format_t fmt; + video_format_Init(&fmt, 0); + video_format_Setup(&fmt, VLC_CODEC_RGBA, width, height, 1, 1); + + p_reg = subpicture_region_New(&fmt); + p_reg->i_x = 0; + p_reg->i_y = 0; + p_sys->p_overlays[plane]->p_regions = p_reg; + } +} + +static void blurayDrawArgbOverlay(demux_t *p_demux, const BD_ARGB_OVERLAY* const ov) +{ + demux_sys_t *p_sys = p_demux->p_sys; + + vlc_mutex_lock(&p_sys->p_overlays[ov->plane]->lock); + + /* Find a region to update */ + subpicture_region_t *p_reg = p_sys->p_overlays[ov->plane]->p_regions; + if (!p_reg) { + vlc_mutex_unlock(&p_sys->p_overlays[ov->plane]->lock); + return; + } + + /* Now we can update the region */ + const uint32_t *src0 = ov->argb; + uint8_t *dst0 = p_reg->p_picture->p[0].p_pixels + + p_reg->p_picture->p[0].i_pitch * ov->y + + ov->x * 4; + + for (int y = 0; y < ov->h; y++) { + // XXX: add support for this format ? Should be possible with OPENGL/VDPAU/... + // - or add libbluray option to select the format ? + for (int x = 0; x < ov->w; x++) { + dst0[x*4 ] = src0[x]>>16; /* R */ + dst0[x*4+1] = src0[x]>>8; /* G */ + dst0[x*4+2] = src0[x]; /* B */ + dst0[x*4+3] = src0[x]>>24; /* A */ + } + + src0 += ov->stride; + dst0 += p_reg->p_picture->p[0].i_pitch; + } + + vlc_mutex_unlock(&p_sys->p_overlays[ov->plane]->lock); + /* + * /!\ The region is now stored in our internal list, but not in the subpicture /!\ + */ +} + +static void blurayArgbOverlayProc(void *ptr, const BD_ARGB_OVERLAY *const overlay) +{ + demux_t *p_demux = (demux_t*)ptr; + + switch (overlay->cmd) { + case BD_ARGB_OVERLAY_INIT: + blurayInitArgbOverlay(p_demux, overlay->plane, overlay->w, overlay->h); + break; + case BD_ARGB_OVERLAY_CLOSE: + blurayClearOverlay(p_demux, overlay->plane); + // TODO: blurayCloseOverlay(p_demux, overlay->plane); + break; + case BD_ARGB_OVERLAY_FLUSH: + blurayActivateOverlay(p_demux, overlay->plane); + break; + case BD_ARGB_OVERLAY_DRAW: + blurayDrawArgbOverlay(p_demux, overlay); + break; + default: + msg_Warn(p_demux, "Unknown BD ARGB overlay command: %u", overlay->cmd); + break; + } +} + static void bluraySendOverlayToVout(demux_t *p_demux) { demux_sys_t *p_sys = p_demux->p_sys;