241
330
vlc_input_title_Delete(p_sys->pp_title[i]);
242
331
TAB_CLEAN( p_sys->i_title, p_sys->pp_title );
244
/* bd_close( NULL ) can crash */
245
assert(p_sys->bluray);
246
bd_close(p_sys->bluray);
336
/*****************************************************************************
337
* subpicture_updater_t functions:
338
*****************************************************************************/
339
static int subpictureUpdaterValidate( subpicture_t *p_subpic,
340
bool b_fmt_src, const video_format_t *p_fmt_src,
341
bool b_fmt_dst, const video_format_t *p_fmt_dst,
344
VLC_UNUSED( b_fmt_src );
345
VLC_UNUSED( b_fmt_dst );
346
VLC_UNUSED( p_fmt_src );
347
VLC_UNUSED( p_fmt_dst );
350
subpicture_updater_sys_t *p_upd_sys = p_subpic->updater.p_sys;
351
bluray_overlay_t *p_overlay = p_upd_sys->p_overlay;
353
vlc_mutex_lock(&p_overlay->lock);
354
int res = p_overlay->status == Outdated;
355
vlc_mutex_unlock(&p_overlay->lock);
359
/* This should probably be moved to subpictures.c afterward */
360
static subpicture_region_t* subpicture_region_Clone(subpicture_region_t *p_region_src)
364
subpicture_region_t *p_region_dst = subpicture_region_New(&p_region_src->fmt);
365
if (unlikely(!p_region_dst))
368
p_region_dst->i_x = p_region_src->i_x;
369
p_region_dst->i_y = p_region_src->i_y;
370
p_region_dst->i_align = p_region_src->i_align;
371
p_region_dst->i_alpha = p_region_src->i_alpha;
373
p_region_dst->psz_text = p_region_src->psz_text ? strdup(p_region_src->psz_text) : NULL;
374
p_region_dst->psz_html = p_region_src->psz_html ? strdup(p_region_src->psz_html) : NULL;
375
if (p_region_src->p_style != NULL) {
376
p_region_dst->p_style = malloc(sizeof(*p_region_dst->p_style));
377
p_region_dst->p_style = text_style_Copy(p_region_dst->p_style,
378
p_region_src->p_style);
381
//Palette is already copied by subpicture_region_New, we just have to duplicate p_pixels
382
for (int i = 0; i < p_region_src->p_picture->i_planes; i++)
383
memcpy(p_region_dst->p_picture->p[i].p_pixels,
384
p_region_src->p_picture->p[i].p_pixels,
385
p_region_src->p_picture->p[i].i_lines * p_region_src->p_picture->p[i].i_pitch);
389
static void subpictureUpdaterUpdate(subpicture_t *p_subpic,
390
const video_format_t *p_fmt_src,
391
const video_format_t *p_fmt_dst,
394
VLC_UNUSED(p_fmt_src);
395
VLC_UNUSED(p_fmt_dst);
397
subpicture_updater_sys_t *p_upd_sys = p_subpic->updater.p_sys;
398
bluray_overlay_t *p_overlay = p_upd_sys->p_overlay;
401
* When this function is called, all p_subpic regions are gone.
402
* We need to duplicate our regions (stored internaly) to this subpic.
404
vlc_mutex_lock(&p_overlay->lock);
406
subpicture_region_t *p_src = p_overlay->p_regions;
410
subpicture_region_t **p_dst = &(p_subpic->p_region);
411
while (p_src != NULL) {
412
*p_dst = subpicture_region_Clone(p_src);
415
p_dst = &((*p_dst)->p_next);
416
p_src = p_src->p_next;
419
(*p_dst)->p_next = NULL;
420
p_overlay->status = Displayed;
421
vlc_mutex_unlock(&p_overlay->lock);
424
static void subpictureUpdaterDestroy(subpicture_t *p_subpic)
426
vlc_gc_decref(p_subpic->updater.p_sys->p_overlay);
429
/*****************************************************************************
431
*****************************************************************************/
432
static int onMouseEvent(vlc_object_t *p_vout, const char *psz_var, vlc_value_t old,
433
vlc_value_t val, void *p_data)
435
demux_t *p_demux = (demux_t*)p_data;
436
demux_sys_t *p_sys = p_demux->p_sys;
437
mtime_t now = mdate();
441
if (psz_var[6] == 'm') //Mouse moved
442
bd_mouse_select(p_sys->bluray, now, val.coords.x, val.coords.y);
443
else if (psz_var[6] == 'c') {
444
bd_mouse_select(p_sys->bluray, now, val.coords.x, val.coords.y);
445
bd_user_input(p_sys->bluray, now, BD_VK_MOUSE_ACTIVATE);
452
/*****************************************************************************
453
* libbluray overlay handling:
454
*****************************************************************************/
455
static void blurayCleanOverayStruct(gc_object_t *p_gc)
457
bluray_overlay_t *p_overlay = vlc_priv(p_gc, bluray_overlay_t);
460
* This will be called when destroying the picture.
461
* Don't delete it again from here!
463
vlc_mutex_destroy(&p_overlay->lock);
464
subpicture_region_Delete(p_overlay->p_regions);
468
static void blurayCloseAllOverlays(demux_t *p_demux)
470
demux_sys_t *p_sys = p_demux->p_sys;
472
p_demux->p_sys->current_overlay = -1;
473
if (p_sys->p_vout != NULL) {
474
for (int i = 0; i < 0; i++) {
475
if (p_sys->p_overlays[i] != NULL) {
476
vout_FlushSubpictureChannel(p_sys->p_vout,
477
p_sys->p_overlays[i]->p_pic->i_channel);
478
vlc_gc_decref(p_sys->p_overlays[i]);
479
p_sys->p_overlays[i] = NULL;
482
var_DelCallback(p_sys->p_vout, "mouse-moved", &onMouseEvent, p_demux);
483
var_DelCallback(p_sys->p_vout, "mouse-clicked", &onMouseEvent, p_demux);
484
vlc_object_release(p_sys->p_vout);
485
p_sys->p_vout = NULL;
490
* Mark the overlay as "ToDisplay" status.
491
* This will not send the overlay to the vout instantly, as the vout
492
* may not be acquired (not acquirable) yet.
493
* If is has already been acquired, the overlay has already been sent to it,
494
* therefore, we only flag the overlay as "Outdated"
496
static void blurayActivateOverlay(demux_t *p_demux, const BD_OVERLAY* const ov)
498
demux_sys_t *p_sys = p_demux->p_sys;
501
* If the overlay is already displayed, mark the picture as outdated.
502
* We must NOT use vout_PutSubpicture if a picture is already displayed.
504
vlc_mutex_lock(&p_sys->p_overlays[ov->plane]->lock);
505
if ((p_sys->p_overlays[ov->plane]->status == Displayed ||
506
p_sys->p_overlays[ov->plane]->status == Outdated)
508
p_sys->p_overlays[ov->plane]->status = Outdated;
509
vlc_mutex_unlock(&p_sys->p_overlays[ov->plane]->lock);
513
* Mark the overlay as available, but don't display it right now.
514
* the blurayDemuxMenu will send it to vout, as it may be unavailable when
515
* the overlay is computed
517
p_sys->current_overlay = ov->plane;
518
p_sys->p_overlays[ov->plane]->status = ToDisplay;
519
vlc_mutex_unlock(&p_sys->p_overlays[ov->plane]->lock);
522
static void blurayInitOverlay(demux_t *p_demux, const BD_OVERLAY* const ov)
524
demux_sys_t *p_sys = p_demux->p_sys;
526
assert(p_sys->p_overlays[ov->plane] == NULL);
528
p_sys->p_overlays[ov->plane] = calloc(1, sizeof(**p_sys->p_overlays));
529
if (unlikely(!p_sys->p_overlays[ov->plane]))
532
subpicture_updater_sys_t *p_upd_sys = malloc(sizeof(*p_upd_sys));
533
if (unlikely(!p_upd_sys)) {
534
free(p_sys->p_overlays[ov->plane]);
535
p_sys->p_overlays[ov->plane] = NULL;
538
vlc_gc_init(p_sys->p_overlays[ov->plane], blurayCleanOverayStruct);
539
/* Incrementing refcounter: vout + demux */
540
vlc_gc_incref(p_sys->p_overlays[ov->plane]);
542
p_upd_sys->p_overlay = p_sys->p_overlays[ov->plane];
543
subpicture_updater_t updater = {
544
.pf_validate = subpictureUpdaterValidate,
545
.pf_update = subpictureUpdaterUpdate,
546
.pf_destroy = subpictureUpdaterDestroy,
549
p_sys->p_overlays[ov->plane]->p_pic = subpicture_New(&updater);
550
p_sys->p_overlays[ov->plane]->p_pic->i_original_picture_width = ov->w;
551
p_sys->p_overlays[ov->plane]->p_pic->i_original_picture_height = ov->h;
552
p_sys->p_overlays[ov->plane]->p_pic->b_ephemer = true;
553
p_sys->p_overlays[ov->plane]->p_pic->b_absolute = true;
557
* Destroy every regions in the subpicture.
558
* This is done in two steps:
559
* - Wiping our private regions list
560
* - Flagging the overlay as outdated, so the changes are replicated from
561
* the subpicture_updater_t::pf_update
562
* This doesn't destroy the subpicture, as the overlay may be used again by libbluray.
564
static void blurayClearOverlay(demux_t *p_demux, const BD_OVERLAY* const ov)
566
demux_sys_t *p_sys = p_demux->p_sys;
568
vlc_mutex_lock(&p_sys->p_overlays[ov->plane]->lock);
570
subpicture_region_ChainDelete(p_sys->p_overlays[ov->plane]->p_regions);
571
p_sys->p_overlays[ov->plane]->p_regions = NULL;
572
p_sys->p_overlays[ov->plane]->status = Outdated;
573
vlc_mutex_unlock(&p_sys->p_overlays[ov->plane]->lock);
577
* This will draw to the overlay by adding a region to our region list
578
* This will have to be copied to the subpicture used to render the overlay.
580
static void blurayDrawOverlay(demux_t *p_demux, const BD_OVERLAY* const ov)
582
demux_sys_t *p_sys = p_demux->p_sys;
585
* Compute a subpicture_region_t.
586
* It will be copied and sent to the vout later.
591
vlc_mutex_lock(&p_sys->p_overlays[ov->plane]->lock);
593
/* Find a region to update */
594
subpicture_region_t *p_reg = p_sys->p_overlays[ov->plane]->p_regions;
595
subpicture_region_t *p_last = NULL;
596
while (p_reg != NULL) {
598
if (p_reg->i_x == ov->x && p_reg->i_y == ov->y &&
599
p_reg->fmt.i_width == ov->w && p_reg->fmt.i_height == ov->h)
601
p_reg = p_reg->p_next;
604
/* If there is no region to update, create a new one. */
607
video_format_Init(&fmt, 0);
608
video_format_Setup(&fmt, VLC_CODEC_YUVP, ov->w, ov->h, 1, 1);
610
p_reg = subpicture_region_New(&fmt);
613
/* Append it to our list. */
615
p_last->p_next = p_reg;
616
else /* If we don't have a last region, then our list empty */
617
p_sys->p_overlays[ov->plane]->p_regions = p_reg;
620
/* Now we can update the region, regardless it's an update or an insert */
621
const BD_PG_RLE_ELEM *img = ov->img;
622
for (int y = 0; y < ov->h; y++) {
623
for (int x = 0; x < ov->w;) {
624
memset(p_reg->p_picture->p[0].p_pixels +
625
y * p_reg->p_picture->p[0].i_pitch + x,
626
img->color, img->len);
632
p_reg->fmt.p_palette->i_entries = 256;
633
for (int i = 0; i < 256; ++i) {
634
p_reg->fmt.p_palette->palette[i][0] = ov->palette[i].Y;
635
p_reg->fmt.p_palette->palette[i][1] = ov->palette[i].Cb;
636
p_reg->fmt.p_palette->palette[i][2] = ov->palette[i].Cr;
637
p_reg->fmt.p_palette->palette[i][3] = ov->palette[i].T;
640
vlc_mutex_unlock(&p_sys->p_overlays[ov->plane]->lock);
642
* /!\ The region is now stored in our internal list, but not in the subpicture /!\
646
static void blurayOverlayProc(void *ptr, const BD_OVERLAY *const overlay)
648
demux_t *p_demux = (demux_t*)ptr;
651
msg_Info(p_demux, "Closing overlay.");
652
blurayCloseAllOverlays(p_demux);
655
switch (overlay->cmd) {
656
case BD_OVERLAY_INIT:
657
msg_Info(p_demux, "Initializing overlay");
658
blurayInitOverlay(p_demux, overlay);
660
case BD_OVERLAY_CLEAR:
661
blurayClearOverlay(p_demux, overlay);
663
case BD_OVERLAY_FLUSH:
664
blurayActivateOverlay(p_demux, overlay);
666
case BD_OVERLAY_DRAW:
667
blurayDrawOverlay(p_demux, overlay);
670
msg_Warn(p_demux, "Unknown BD overlay command: %u", overlay->cmd);
675
static void bluraySendOverlayToVout(demux_t *p_demux)
677
demux_sys_t *p_sys = p_demux->p_sys;
679
assert(p_sys->current_overlay >= 0 &&
680
p_sys->p_overlays[p_sys->current_overlay] != NULL &&
681
p_sys->p_overlays[p_sys->current_overlay]->p_pic != NULL);
683
p_sys->p_overlays[p_sys->current_overlay]->p_pic->i_start =
684
p_sys->p_overlays[p_sys->current_overlay]->p_pic->i_stop = mdate();
685
p_sys->p_overlays[p_sys->current_overlay]->p_pic->i_channel =
686
vout_RegisterSubpictureChannel(p_sys->p_vout);
688
* After this point, the picture should not be accessed from the demux thread,
689
* as it is held by the vout thread.
690
* This must be done only once per subpicture, ie. only once between each
691
* blurayInitOverlay & blurayCloseOverlay call.
693
vout_PutSubpicture(p_sys->p_vout, p_sys->p_overlays[p_sys->current_overlay]->p_pic);
695
* Mark the picture as Outdated, as it contains no region for now.
696
* This will make the subpicture_updater_t call pf_update
698
p_sys->p_overlays[p_sys->current_overlay]->status = Outdated;
251
701
static int blurayInitTitles(demux_t *p_demux )