2010-07-05 17:04:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Benjamin Zores <ben@geexbox.org>
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Blu-ray parser/reader using libbluray
|
|
|
|
* Use 'git clone git://git.videolan.org/libbluray' to get it.
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* - Add descrambled keys database support (KEYDB.cfg)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-11-18 23:22:43 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2010-07-05 17:04:46 +00:00
|
|
|
|
2013-07-12 20:04:44 +00:00
|
|
|
#include <libbluray/bluray.h>
|
2014-03-12 05:41:34 +00:00
|
|
|
#include <libbluray/meta_data.h>
|
2014-03-28 15:00:02 +00:00
|
|
|
#include <libbluray/overlay.h>
|
|
|
|
#include <libbluray/keys.h>
|
|
|
|
#include <libbluray/bluray-version.h>
|
2013-07-12 20:04:44 +00:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
2010-07-05 17:04:46 +00:00
|
|
|
#include "config.h"
|
2012-02-19 13:15:41 +00:00
|
|
|
#include "talloc.h"
|
2013-12-18 16:12:21 +00:00
|
|
|
#include "common/common.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2014-06-10 20:09:27 +00:00
|
|
|
#include "options/options.h"
|
2010-07-05 17:04:46 +00:00
|
|
|
#include "stream.h"
|
2014-03-26 18:15:37 +00:00
|
|
|
#include "osdep/timer.h"
|
2014-03-30 02:42:49 +00:00
|
|
|
#include "discnav.h"
|
2014-03-28 15:00:02 +00:00
|
|
|
#include "sub/osd.h"
|
|
|
|
#include "sub/img_convert.h"
|
|
|
|
#include "video/mp_image.h"
|
|
|
|
#include "video/mp_image_pool.h"
|
2010-07-05 17:04:46 +00:00
|
|
|
|
|
|
|
#define BLURAY_SECTOR_SIZE 6144
|
|
|
|
|
|
|
|
#define BLURAY_DEFAULT_ANGLE 0
|
|
|
|
#define BLURAY_DEFAULT_CHAPTER 0
|
2014-03-28 15:00:02 +00:00
|
|
|
#define BLURAY_DEFAULT_TITLE -2
|
|
|
|
#define BLURAY_MENU_TITLE -1
|
2010-07-05 17:04:46 +00:00
|
|
|
|
2013-05-05 17:02:10 +00:00
|
|
|
// 90khz ticks
|
|
|
|
#define BD_TIMEBASE (90000)
|
|
|
|
#define BD_TIME_TO_MP(x) ((x) / (double)(BD_TIMEBASE))
|
|
|
|
#define BD_TIME_FROM_MP(x) ((uint64_t)(x * BD_TIMEBASE))
|
|
|
|
|
2014-03-30 06:42:16 +00:00
|
|
|
// copied from aacs.h in libaacs
|
|
|
|
#define AACS_ERROR_CORRUPTED_DISC -1 /* opening or reading of AACS files failed */
|
|
|
|
#define AACS_ERROR_NO_CONFIG -2 /* missing config file */
|
|
|
|
#define AACS_ERROR_NO_PK -3 /* no matching processing key */
|
|
|
|
#define AACS_ERROR_NO_CERT -4 /* no valid certificate */
|
|
|
|
#define AACS_ERROR_CERT_REVOKED -5 /* certificate has been revoked */
|
|
|
|
#define AACS_ERROR_MMC_OPEN -6 /* MMC open failed (no MMC drive ?) */
|
|
|
|
#define AACS_ERROR_MMC_FAILURE -7 /* MMC failed */
|
|
|
|
#define AACS_ERROR_NO_DK -8 /* no matching device key */
|
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
struct bluray_overlay {
|
|
|
|
struct sub_bitmap *image;
|
|
|
|
bool clean, hidden;
|
|
|
|
int x, y, w, h;
|
|
|
|
};
|
|
|
|
|
2010-07-05 20:52:47 +00:00
|
|
|
struct bluray_priv_s {
|
|
|
|
BLURAY *bd;
|
2014-03-26 18:17:31 +00:00
|
|
|
BLURAY_TITLE_INFO *title_info;
|
2013-09-10 13:39:48 +00:00
|
|
|
int num_titles;
|
2010-07-05 20:52:47 +00:00
|
|
|
int current_angle;
|
|
|
|
int current_title;
|
2014-03-26 18:19:14 +00:00
|
|
|
int current_playlist;
|
2013-08-02 15:02:34 +00:00
|
|
|
|
|
|
|
int cfg_title;
|
|
|
|
char *cfg_device;
|
2014-03-28 15:00:02 +00:00
|
|
|
|
|
|
|
// overlay stuffs
|
|
|
|
struct bluray_overlay overlays[2], ol_flushed[2];
|
|
|
|
struct mp_image_pool *pool;
|
|
|
|
|
|
|
|
// navigation stuffs
|
|
|
|
uint64_t next_event;
|
|
|
|
uint32_t still_length;
|
|
|
|
int mousex, mousey;
|
|
|
|
bool in_menu, use_nav, nav_enabled, popup_enabled;
|
2010-07-05 20:52:47 +00:00
|
|
|
};
|
|
|
|
|
2014-06-11 22:32:37 +00:00
|
|
|
static const struct bluray_priv_s bluray_stream_priv_dflts = {
|
2014-03-28 15:00:02 +00:00
|
|
|
.cfg_title = BLURAY_DEFAULT_TITLE,
|
|
|
|
};
|
|
|
|
|
2014-06-11 22:32:37 +00:00
|
|
|
static const struct bluray_priv_s bdnav_stream_priv_dflts = {
|
2014-03-28 15:00:02 +00:00
|
|
|
.cfg_title = BLURAY_DEFAULT_TITLE,
|
|
|
|
.use_nav = true,
|
2010-07-05 17:04:46 +00:00
|
|
|
};
|
|
|
|
|
2013-08-02 15:02:34 +00:00
|
|
|
#define OPT_BASE_STRUCT struct bluray_priv_s
|
2010-07-05 17:04:46 +00:00
|
|
|
static const m_option_t bluray_stream_opts_fields[] = {
|
2014-03-18 13:34:23 +00:00
|
|
|
OPT_CHOICE_OR_INT("title", cfg_title, 0, 0, 99999,
|
|
|
|
({"longest", BLURAY_DEFAULT_TITLE})),
|
2013-08-02 15:02:34 +00:00
|
|
|
OPT_STRING("device", cfg_device, 0),
|
|
|
|
{0}
|
2010-07-05 17:04:46 +00:00
|
|
|
};
|
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
static const m_option_t bdnav_stream_opts_fields[] = {
|
|
|
|
OPT_CHOICE_OR_INT("title", cfg_title, 0, 0, 99999,
|
|
|
|
({"menu", BLURAY_MENU_TITLE},
|
|
|
|
{"first", BLURAY_DEFAULT_TITLE})),
|
|
|
|
OPT_STRING("device", cfg_device, 0),
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void destruct(struct bluray_priv_s *priv)
|
2010-07-05 17:04:46 +00:00
|
|
|
{
|
2014-03-28 15:00:02 +00:00
|
|
|
if (priv->title_info)
|
|
|
|
bd_free_title_info(priv->title_info);
|
|
|
|
bd_close(priv->bd);
|
|
|
|
talloc_free(priv->pool);
|
|
|
|
}
|
2010-07-05 20:52:47 +00:00
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
inline static int play_title(struct bluray_priv_s *priv, int title)
|
|
|
|
{
|
|
|
|
if (priv->use_nav) {
|
|
|
|
if (title == priv->num_titles - 1)
|
|
|
|
title = BLURAY_TITLE_FIRST_PLAY;
|
|
|
|
return bd_play_title(priv->bd, title);
|
|
|
|
} else
|
|
|
|
return bd_select_title(priv->bd, title);
|
2010-07-05 17:04:46 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
static void overlay_release(struct bluray_overlay *overlay)
|
2010-07-05 17:04:46 +00:00
|
|
|
{
|
2014-03-28 15:00:02 +00:00
|
|
|
if (overlay->image)
|
|
|
|
talloc_free(overlay->image);
|
|
|
|
*overlay = (struct bluray_overlay) { .clean = true };
|
|
|
|
}
|
|
|
|
|
|
|
|
static void overlay_alloc(struct bluray_priv_s *priv,
|
|
|
|
struct bluray_overlay *overlay,
|
|
|
|
int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
assert(overlay->image == NULL);
|
|
|
|
struct sub_bitmap *image = talloc_zero(NULL, struct sub_bitmap);
|
|
|
|
overlay->w = image->w = image->dw = w;
|
|
|
|
overlay->h = image->h = image->dh = h;
|
|
|
|
overlay->x = image->x = x;
|
|
|
|
overlay->y = image->y = y;
|
|
|
|
struct mp_image *mpi = mp_image_pool_get(priv->pool, IMGFMT_RGBA, w, h);
|
|
|
|
mpi = talloc_steal(image, mpi);
|
|
|
|
assert(image->w > 0 && image->h > 0 && mpi != NULL);
|
|
|
|
image->stride = mpi->stride[0];
|
|
|
|
image->bitmap = mpi->planes[0];
|
|
|
|
overlay->image = image;
|
|
|
|
overlay->clean = true;
|
|
|
|
overlay->hidden = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void overlay_close_all(struct bluray_priv_s *priv)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
overlay_release(&priv->overlays[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void overlay_close(struct bluray_priv_s *priv,
|
|
|
|
const BD_OVERLAY *const bo)
|
|
|
|
{
|
|
|
|
overlay_release(&priv->overlays[bo->plane]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t conv_rgba(const BD_PG_PALETTE_ENTRY *p)
|
|
|
|
{
|
|
|
|
uint32_t rgba;
|
|
|
|
uint8_t *out = (uint8_t*)&rgba;
|
|
|
|
const int y = p->Y, cb = (int)p->Cb - 128, cr = (int)p->Cr - 128;
|
|
|
|
// CAUTION: inaccurate but fast, broken in big endian
|
|
|
|
#define CONV(a) (MPCLAMP((a), 0, 255)*p->T >> 8)
|
|
|
|
out[0] = CONV(y + cb + (cb >> 1) + (cb >> 2) + (cb >> 6));
|
|
|
|
out[1] = CONV(y - ((cb >> 2) + (cb >> 4) + (cb >> 5))
|
|
|
|
- ((cr >> 3) + (cr >> 4) + (cr >> 5)));
|
|
|
|
out[2] = CONV(y + cr + (cr >> 2) + (cr >> 3) + (cr >> 5));
|
|
|
|
out[3] = p->T;
|
|
|
|
#undef CONV
|
|
|
|
return rgba;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void overlay_process(void *data, const BD_OVERLAY *const bo)
|
|
|
|
{
|
|
|
|
stream_t *s = data;
|
|
|
|
struct bluray_priv_s *priv = s->priv;
|
|
|
|
if (!bo) {
|
|
|
|
overlay_close_all(priv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct bluray_overlay *overlay = &priv->overlays[bo->plane];
|
|
|
|
switch (bo->cmd) {
|
|
|
|
case BD_OVERLAY_INIT:
|
|
|
|
overlay_alloc(priv, overlay, bo->x, bo->y, bo->w, bo->h);
|
|
|
|
break;
|
|
|
|
case BD_OVERLAY_CLOSE:
|
|
|
|
overlay_close(priv, bo);
|
|
|
|
break;
|
|
|
|
case BD_OVERLAY_CLEAR:
|
|
|
|
if (!overlay->clean) {
|
|
|
|
memset(overlay->image->bitmap, 0,
|
|
|
|
overlay->image->stride*overlay->h);
|
|
|
|
overlay->clean = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BD_OVERLAY_DRAW: {
|
|
|
|
if (!bo->img)
|
|
|
|
break;
|
|
|
|
overlay->hidden = false;
|
|
|
|
overlay->clean = false;
|
|
|
|
struct sub_bitmap *img = overlay->image;
|
|
|
|
uint32_t *const origin = img->bitmap;
|
|
|
|
const BD_PG_RLE_ELEM *in = bo->img;
|
|
|
|
for (int y = 0; y < bo->h; y++) {
|
|
|
|
uint32_t *out = origin + (img->stride/4) * (y + bo->y) + bo->x;
|
|
|
|
for (int x = 0; x < bo->w; ) {
|
|
|
|
uint32_t c = 0;
|
|
|
|
if (bo->palette[in->color].T) {
|
|
|
|
c = conv_rgba(&bo->palette[in->color]);
|
|
|
|
for (int i = 0; i < in->len; i++)
|
|
|
|
*out++ = c;
|
|
|
|
} else {
|
|
|
|
memset(out, 0, in->len*4);
|
|
|
|
out += in->len;
|
|
|
|
}
|
|
|
|
x += in->len;
|
|
|
|
++in;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-03-30 02:16:32 +00:00
|
|
|
}
|
|
|
|
case BD_OVERLAY_WIPE: {
|
2014-03-28 15:00:02 +00:00
|
|
|
uint32_t *const origin = overlay->image->bitmap;
|
|
|
|
for (int y = 0; y < bo->h; y++)
|
|
|
|
memset(origin + overlay->w * (y + bo->y) + bo->x, 0, 4 * bo->w);
|
|
|
|
break;
|
2014-03-30 02:16:32 +00:00
|
|
|
}
|
|
|
|
case BD_OVERLAY_HIDE:
|
2014-03-28 15:00:02 +00:00
|
|
|
priv->overlays[bo->plane].hidden = true;
|
|
|
|
break;
|
|
|
|
case BD_OVERLAY_FLUSH: {
|
|
|
|
struct bluray_overlay *in = overlay;
|
|
|
|
struct bluray_overlay *out = &priv->ol_flushed[bo->plane];
|
|
|
|
if (out->image && (out->image->stride != in->image->stride ||
|
|
|
|
out->image->h != in->image->h))
|
|
|
|
overlay_release(out);
|
|
|
|
if (!out->image)
|
|
|
|
overlay_alloc(priv, out, in->x, in->y, in->w, in->h);
|
|
|
|
const int len = in->image->stride*in->image->h;
|
|
|
|
memcpy(out->image->bitmap, in->image->bitmap, len);
|
|
|
|
out->clean = in->clean;
|
|
|
|
out->hidden = in->hidden;
|
|
|
|
priv->next_event |= 1 << MP_NAV_EVENT_OVERLAY;
|
|
|
|
break;
|
|
|
|
} default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool set_event_type(struct bluray_priv_s *priv, int type,
|
|
|
|
struct mp_nav_event *event)
|
|
|
|
{
|
|
|
|
if (!(priv->next_event & (1 << type)))
|
|
|
|
return false;
|
|
|
|
priv->next_event &= ~(1 << type);
|
|
|
|
event->event = type;
|
|
|
|
return true;
|
|
|
|
}
|
2010-07-05 17:04:46 +00:00
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
static void fill_next_event(stream_t *s, struct mp_nav_event **ret)
|
|
|
|
{
|
|
|
|
struct bluray_priv_s *priv = s->priv;
|
|
|
|
struct mp_nav_event e = {0};
|
|
|
|
// this should be checked before any other events
|
|
|
|
if (!set_event_type(priv, MP_NAV_EVENT_RESET_ALL, &e))
|
|
|
|
for (int n = 0; n < 30 && !set_event_type(priv, n, &e); n++) ;
|
|
|
|
switch (e.event) {
|
|
|
|
case MP_NAV_EVENT_NONE:
|
|
|
|
return;
|
|
|
|
case MP_NAV_EVENT_OVERLAY: {
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
struct bluray_overlay *o = &priv->ol_flushed[i];
|
|
|
|
e.u.overlay.images[i] = NULL;
|
|
|
|
if (!o->clean && !o->hidden) {
|
|
|
|
e.u.overlay.images[i] = o->image;
|
|
|
|
o->image = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-03-30 02:16:32 +00:00
|
|
|
}
|
|
|
|
case MP_NAV_EVENT_MENU_MODE:
|
2014-03-28 15:00:02 +00:00
|
|
|
e.u.menu_mode.enable = priv->in_menu;
|
|
|
|
break;
|
|
|
|
case MP_NAV_EVENT_STILL_FRAME:
|
|
|
|
e.u.still_frame.seconds = priv->still_length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*ret = talloc(NULL, struct mp_nav_event);
|
|
|
|
**ret = e;
|
|
|
|
}
|
2010-07-05 17:04:46 +00:00
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
static void bluray_stream_close(stream_t *s)
|
|
|
|
{
|
|
|
|
destruct(s->priv);
|
2010-07-05 17:04:46 +00:00
|
|
|
}
|
|
|
|
|
2014-03-26 18:15:37 +00:00
|
|
|
static void handle_event(stream_t *s, const BD_EVENT *ev)
|
|
|
|
{
|
2014-03-28 15:00:02 +00:00
|
|
|
static const int reset_flags = (1 << MP_NAV_EVENT_RESET_ALL)
|
|
|
|
| (1 << MP_NAV_EVENT_RESET);
|
2014-03-26 18:17:31 +00:00
|
|
|
struct bluray_priv_s *b = s->priv;
|
2014-03-26 18:15:37 +00:00
|
|
|
switch (ev->event) {
|
2014-03-28 15:00:02 +00:00
|
|
|
case BD_EVENT_MENU:
|
|
|
|
b->in_menu = ev->param;
|
|
|
|
b->next_event |= 1 << MP_NAV_EVENT_MENU_MODE;
|
|
|
|
break;
|
|
|
|
case BD_EVENT_STILL:
|
|
|
|
b->still_length = ev->param ? -1 : 0;
|
|
|
|
if (b->nav_enabled)
|
|
|
|
b->next_event |= 1 << MP_NAV_EVENT_STILL_FRAME;
|
|
|
|
break;
|
|
|
|
case BD_EVENT_STILL_TIME:
|
|
|
|
b->still_length = ev->param ? -1 : ev->param*1000;
|
|
|
|
if (b->nav_enabled)
|
|
|
|
b->next_event |= 1 << MP_NAV_EVENT_STILL_FRAME;
|
|
|
|
else
|
|
|
|
bd_read_skip_still(b->bd);
|
|
|
|
break;
|
|
|
|
case BD_EVENT_END_OF_TITLE:
|
|
|
|
overlay_close_all(b);
|
|
|
|
break;
|
2014-03-26 18:19:14 +00:00
|
|
|
case BD_EVENT_PLAYLIST:
|
2014-03-28 15:00:02 +00:00
|
|
|
b->next_event = reset_flags;
|
2014-03-26 18:19:14 +00:00
|
|
|
b->current_playlist = ev->param;
|
2014-03-28 15:00:02 +00:00
|
|
|
if (!b->use_nav)
|
|
|
|
b->current_title = bd_get_current_title(b->bd);
|
2014-03-26 18:19:14 +00:00
|
|
|
if (b->title_info)
|
|
|
|
bd_free_title_info(b->title_info);
|
|
|
|
b->title_info = bd_get_playlist_info(b->bd, b->current_playlist,
|
|
|
|
b->current_angle);
|
|
|
|
break;
|
2014-03-26 18:17:31 +00:00
|
|
|
case BD_EVENT_TITLE:
|
2014-03-28 15:00:02 +00:00
|
|
|
b->next_event = reset_flags;
|
|
|
|
if (ev->param == BLURAY_TITLE_FIRST_PLAY) {
|
|
|
|
if (b->use_nav)
|
|
|
|
b->current_title = b->num_titles - 1;
|
|
|
|
else
|
|
|
|
b->current_title = bd_get_current_title(b->bd);
|
|
|
|
} else
|
2014-03-26 18:17:31 +00:00
|
|
|
b->current_title = ev->param;
|
|
|
|
if (b->title_info) {
|
|
|
|
bd_free_title_info(b->title_info);
|
|
|
|
b->title_info = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BD_EVENT_ANGLE:
|
|
|
|
b->current_angle = ev->param;
|
|
|
|
if (b->title_info) {
|
|
|
|
bd_free_title_info(b->title_info);
|
2014-03-26 18:19:14 +00:00
|
|
|
b->title_info = bd_get_playlist_info(b->bd, b->current_playlist,
|
|
|
|
b->current_angle);
|
2014-03-26 18:17:31 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-03-28 15:00:02 +00:00
|
|
|
case BD_EVENT_POPUP:
|
|
|
|
b->popup_enabled = ev->param;
|
|
|
|
break;
|
|
|
|
#if BLURAY_VERSION >= BLURAY_VERSION_CODE(0, 5, 0)
|
|
|
|
case BD_EVENT_DISCONTINUITY:
|
|
|
|
b->next_event = reset_flags;
|
|
|
|
break;
|
|
|
|
#endif
|
2014-03-26 18:15:37 +00:00
|
|
|
default:
|
|
|
|
MP_TRACE(s, "Unhandled event: %d %d\n", ev->event, ev->param);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-05 17:04:46 +00:00
|
|
|
static int bluray_stream_fill_buffer(stream_t *s, char *buf, int len)
|
|
|
|
{
|
2010-07-05 20:52:47 +00:00
|
|
|
struct bluray_priv_s *b = s->priv;
|
2014-03-28 15:00:02 +00:00
|
|
|
assert(!b->use_nav);
|
2014-03-26 18:15:37 +00:00
|
|
|
BD_EVENT event;
|
|
|
|
while (bd_get_event(b->bd, &event))
|
|
|
|
handle_event(s, &event);
|
2010-07-05 20:52:47 +00:00
|
|
|
return bd_read(b->bd, buf, len);
|
|
|
|
}
|
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
static int bdnav_stream_fill_buffer(stream_t *s, char *buf, int len)
|
|
|
|
{
|
|
|
|
struct bluray_priv_s *b = s->priv;
|
|
|
|
assert(b->use_nav);
|
|
|
|
BD_EVENT event;
|
|
|
|
int read = -1;
|
|
|
|
for (;;) {
|
|
|
|
read = bd_read_ext(b->bd, buf, len, &event);
|
|
|
|
if (read < 0)
|
|
|
|
return read;
|
|
|
|
if (read == 0) {
|
|
|
|
if (event.event == BD_EVENT_NONE)
|
|
|
|
return 0; // end of stream
|
|
|
|
handle_event(s, &event);
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bd_vk_key_e translate_nav_menu_action(const char *cmd)
|
|
|
|
{
|
|
|
|
if (strcmp(cmd, "mouse") == 0)
|
|
|
|
return BD_VK_MOUSE_ACTIVATE;
|
|
|
|
if (strcmp(cmd, "up") == 0)
|
|
|
|
return BD_VK_UP;
|
|
|
|
if (strcmp(cmd, "down") == 0)
|
|
|
|
return BD_VK_DOWN;
|
|
|
|
if (strcmp(cmd, "left") == 0)
|
|
|
|
return BD_VK_LEFT;
|
|
|
|
if (strcmp(cmd, "right") == 0)
|
|
|
|
return BD_VK_RIGHT;
|
|
|
|
if (strcmp(cmd, "select") == 0)
|
|
|
|
return BD_VK_ENTER;
|
|
|
|
return BD_VK_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_nav_command(stream_t *s, struct mp_nav_cmd *ev)
|
|
|
|
{
|
|
|
|
struct bluray_priv_s *priv = s->priv;
|
|
|
|
switch (ev->event) {
|
|
|
|
case MP_NAV_CMD_ENABLE:
|
|
|
|
priv->nav_enabled = true;
|
|
|
|
break;
|
|
|
|
case MP_NAV_CMD_MENU: {
|
|
|
|
const int64_t pts = mp_time_us();
|
|
|
|
const char *action = ev->u.menu.action;
|
|
|
|
bd_vk_key_e key = translate_nav_menu_action(action);
|
|
|
|
if (key != BD_VK_NONE) {
|
|
|
|
if (key == BD_VK_MOUSE_ACTIVATE)
|
|
|
|
bd_mouse_select(priv->bd, pts, priv->mousex, priv->mousey);
|
|
|
|
bd_user_input(priv->bd, pts, key);
|
|
|
|
} else if (strcmp(action, "menu") == 0) {
|
|
|
|
if (priv->popup_enabled)
|
|
|
|
bd_user_input(priv->bd, pts, BD_VK_POPUP);
|
|
|
|
else
|
|
|
|
bd_menu_call(priv->bd, pts);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} case MP_NAV_CMD_MOUSE_POS:
|
|
|
|
priv->mousex = ev->u.mouse_pos.x;
|
|
|
|
priv->mousey = ev->u.mouse_pos.y;
|
|
|
|
bd_mouse_select(priv->bd, mp_time_us(), priv->mousex, priv->mousey);
|
|
|
|
break;
|
|
|
|
case MP_NAV_CMD_SKIP_STILL:
|
|
|
|
bd_read_skip_still(priv->bd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-05 20:52:47 +00:00
|
|
|
static int bluray_stream_control(stream_t *s, int cmd, void *arg)
|
|
|
|
{
|
|
|
|
struct bluray_priv_s *b = s->priv;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case STREAM_CTRL_GET_NUM_CHAPTERS: {
|
2014-03-26 18:17:31 +00:00
|
|
|
const BLURAY_TITLE_INFO *ti = b->title_info;
|
2010-07-05 20:52:47 +00:00
|
|
|
if (!ti)
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
*((unsigned int *) arg) = ti->chapter_count;
|
2014-03-30 00:44:18 +00:00
|
|
|
return STREAM_OK;
|
2010-07-05 20:52:47 +00:00
|
|
|
}
|
2013-05-09 16:49:16 +00:00
|
|
|
case STREAM_CTRL_GET_CHAPTER_TIME: {
|
2014-03-26 18:17:31 +00:00
|
|
|
const BLURAY_TITLE_INFO *ti = b->title_info;
|
2013-05-09 16:49:16 +00:00
|
|
|
if (!ti)
|
|
|
|
return STREAM_UNSUPPORTED;
|
2014-03-30 02:16:32 +00:00
|
|
|
int chapter = *(double *)arg;
|
|
|
|
double time = MP_NOPTS_VALUE;
|
|
|
|
if (chapter >= 0 || chapter < ti->chapter_count)
|
2013-05-09 16:49:16 +00:00
|
|
|
time = BD_TIME_TO_MP(ti->chapters[chapter].start);
|
2014-03-30 02:16:32 +00:00
|
|
|
if (time == MP_NOPTS_VALUE)
|
|
|
|
return STREAM_ERROR;
|
|
|
|
*(double *)arg = time;
|
|
|
|
return STREAM_OK;
|
2013-05-09 16:49:16 +00:00
|
|
|
}
|
2014-03-18 04:03:00 +00:00
|
|
|
case STREAM_CTRL_SET_CURRENT_TITLE: {
|
|
|
|
const uint32_t title = *((unsigned int*)arg);
|
2014-03-30 02:16:32 +00:00
|
|
|
if (title >= b->num_titles || !play_title(b, title))
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
b->current_title = title;
|
|
|
|
return STREAM_OK;
|
2014-03-18 04:03:00 +00:00
|
|
|
}
|
2012-10-21 14:56:50 +00:00
|
|
|
case STREAM_CTRL_GET_CURRENT_TITLE: {
|
|
|
|
*((unsigned int *) arg) = b->current_title;
|
2014-03-30 00:44:18 +00:00
|
|
|
return STREAM_OK;
|
2012-10-21 14:56:50 +00:00
|
|
|
}
|
2013-09-10 13:39:48 +00:00
|
|
|
case STREAM_CTRL_GET_NUM_TITLES: {
|
|
|
|
*((unsigned int *)arg) = b->num_titles;
|
2014-03-30 00:44:18 +00:00
|
|
|
return STREAM_OK;
|
2013-09-10 13:39:48 +00:00
|
|
|
}
|
2013-05-05 17:02:10 +00:00
|
|
|
case STREAM_CTRL_GET_TIME_LENGTH: {
|
2014-03-26 18:17:31 +00:00
|
|
|
const BLURAY_TITLE_INFO *ti = b->title_info;
|
2013-05-05 17:02:10 +00:00
|
|
|
if (!ti)
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
*((double *) arg) = BD_TIME_TO_MP(ti->duration);
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_CURRENT_TIME: {
|
|
|
|
*((double *) arg) = BD_TIME_TO_MP(bd_tell_time(b->bd));
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_SEEK_TO_TIME: {
|
|
|
|
double pts = *((double *) arg);
|
|
|
|
bd_seek_time(b->bd, BD_TIME_FROM_MP(pts));
|
2014-03-28 15:00:02 +00:00
|
|
|
stream_drop_buffers(s);
|
2013-05-05 17:02:10 +00:00
|
|
|
// API makes it hard to determine seeking success
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
2010-07-05 20:52:47 +00:00
|
|
|
case STREAM_CTRL_GET_NUM_ANGLES: {
|
2014-03-26 18:17:31 +00:00
|
|
|
const BLURAY_TITLE_INFO *ti = b->title_info;
|
2010-07-05 20:52:47 +00:00
|
|
|
if (!ti)
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
*((int *) arg) = ti->angle_count;
|
2014-03-30 00:44:18 +00:00
|
|
|
return STREAM_OK;
|
2010-07-05 20:52:47 +00:00
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_ANGLE: {
|
|
|
|
*((int *) arg) = b->current_angle;
|
2014-03-30 00:44:18 +00:00
|
|
|
return STREAM_OK;
|
2010-07-05 20:52:47 +00:00
|
|
|
}
|
|
|
|
case STREAM_CTRL_SET_ANGLE: {
|
2014-03-26 18:17:31 +00:00
|
|
|
const BLURAY_TITLE_INFO *ti = b->title_info;
|
2010-07-05 20:52:47 +00:00
|
|
|
if (!ti)
|
|
|
|
return STREAM_UNSUPPORTED;
|
2014-03-30 02:16:32 +00:00
|
|
|
int angle = *((int *) arg);
|
|
|
|
if (angle < 0 || angle > ti->angle_count)
|
2010-07-05 20:52:47 +00:00
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
b->current_angle = angle;
|
|
|
|
bd_seamless_angle_change(b->bd, angle);
|
2014-03-30 00:44:18 +00:00
|
|
|
return STREAM_OK;
|
2010-07-05 20:52:47 +00:00
|
|
|
}
|
2012-02-19 13:15:41 +00:00
|
|
|
case STREAM_CTRL_GET_LANG: {
|
2014-03-26 18:17:31 +00:00
|
|
|
const BLURAY_TITLE_INFO *ti = b->title_info;
|
|
|
|
if (ti && ti->clip_count) {
|
2014-03-30 02:16:32 +00:00
|
|
|
struct stream_lang_req *req = arg;
|
2012-02-19 13:15:41 +00:00
|
|
|
BLURAY_STREAM_INFO *si = NULL;
|
|
|
|
int count = 0;
|
|
|
|
switch (req->type) {
|
core: fix DVD subtitle selection
Add all subtitle tracks as reported by libdvdread at playback start.
Display language for subtitle and audio tracks. This commit restores
these features to the state when demux_mpg was default for DVD playback,
and makes them work with demux_lavf and the recent changes to subtitle
selection in the frontend.
demux_mpg, which was the default demuxer for DVD playback, reordered
the subtitle streams according to the "logical" subtitle track number,
which conforms to the track layout reported by libdvdread, and is what
stream_dvd expects for the STREAM_CTRL_GET_LANG call. demux_lavf, on
the other hand, adds the streams in the order it encounters them in
the MPEG stream. It seems this order is essentially random, and can't
be mapped easily to what stream_dvd expects.
Solve this by making demux_lavf hand out the MPEG stream IDs (using the
demuxer_id field). The MPEG IDs are mapped by mplayer.c by special
casing DVD playback (map_id_from/to_demuxer() functions). This mapping
is essentially the same what demux_mpg did. Making demux_lavf reorder
the streams is out of the question, because its stream handling is
already messy enough.
(Note that demux_lavf doesn't export stream IDs for other formats,
because most time libavformat demuxers do not set AVStream.id, and we
don't know which demuxers do. But we know that MPEG is safe.)
Another major complication is that subtitle tracks are added lazily, as
soon as the demuxer encounters the first subtitle packet for a given
subtitle stream. Add the streams in advance. If a yet non-existent
stream is selected, demux_lavf must be made to auto-select that subtitle
stream as soon as it is added. Otherwise, the first subtitle packet
would be lost. This is done by DEMUXER_CTRL_PRESELECT_SUBTITLE.
demux_mpg didn't need this: the frontend code could just set ds->id to
the desired stream number. But demux_lavf's stream IDs don't map
directly to the stream number as used by libdvdread, which is why this
hack is needed.
2012-08-30 14:43:31 +00:00
|
|
|
case STREAM_AUDIO:
|
2012-02-19 13:15:41 +00:00
|
|
|
count = ti->clips[0].audio_stream_count;
|
|
|
|
si = ti->clips[0].audio_streams;
|
|
|
|
break;
|
core: fix DVD subtitle selection
Add all subtitle tracks as reported by libdvdread at playback start.
Display language for subtitle and audio tracks. This commit restores
these features to the state when demux_mpg was default for DVD playback,
and makes them work with demux_lavf and the recent changes to subtitle
selection in the frontend.
demux_mpg, which was the default demuxer for DVD playback, reordered
the subtitle streams according to the "logical" subtitle track number,
which conforms to the track layout reported by libdvdread, and is what
stream_dvd expects for the STREAM_CTRL_GET_LANG call. demux_lavf, on
the other hand, adds the streams in the order it encounters them in
the MPEG stream. It seems this order is essentially random, and can't
be mapped easily to what stream_dvd expects.
Solve this by making demux_lavf hand out the MPEG stream IDs (using the
demuxer_id field). The MPEG IDs are mapped by mplayer.c by special
casing DVD playback (map_id_from/to_demuxer() functions). This mapping
is essentially the same what demux_mpg did. Making demux_lavf reorder
the streams is out of the question, because its stream handling is
already messy enough.
(Note that demux_lavf doesn't export stream IDs for other formats,
because most time libavformat demuxers do not set AVStream.id, and we
don't know which demuxers do. But we know that MPEG is safe.)
Another major complication is that subtitle tracks are added lazily, as
soon as the demuxer encounters the first subtitle packet for a given
subtitle stream. Add the streams in advance. If a yet non-existent
stream is selected, demux_lavf must be made to auto-select that subtitle
stream as soon as it is added. Otherwise, the first subtitle packet
would be lost. This is done by DEMUXER_CTRL_PRESELECT_SUBTITLE.
demux_mpg didn't need this: the frontend code could just set ds->id to
the desired stream number. But demux_lavf's stream IDs don't map
directly to the stream number as used by libdvdread, which is why this
hack is needed.
2012-08-30 14:43:31 +00:00
|
|
|
case STREAM_SUB:
|
2012-02-19 13:15:41 +00:00
|
|
|
count = ti->clips[0].pg_stream_count;
|
|
|
|
si = ti->clips[0].pg_streams;
|
|
|
|
break;
|
|
|
|
}
|
2013-05-05 17:02:27 +00:00
|
|
|
for (int n = 0; n < count; n++) {
|
|
|
|
BLURAY_STREAM_INFO *i = &si[n];
|
|
|
|
if (i->pid == req->id) {
|
|
|
|
snprintf(req->name, sizeof(req->name), "%.4s", i->lang);
|
2012-02-19 13:15:41 +00:00
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2014-03-30 02:16:32 +00:00
|
|
|
case STREAM_CTRL_GET_START_TIME: {
|
2013-05-05 17:02:10 +00:00
|
|
|
*((double *)arg) = 0;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_MANAGES_TIMELINE:
|
|
|
|
return STREAM_OK;
|
2014-03-30 02:16:32 +00:00
|
|
|
case STREAM_CTRL_GET_DISC_NAME: {
|
2014-03-12 05:41:34 +00:00
|
|
|
const struct meta_dl *meta = bd_get_meta(b->bd);
|
|
|
|
if (!meta || !meta->di_name || !meta->di_name[0])
|
|
|
|
break;
|
|
|
|
*(char**)arg = talloc_strdup(NULL, meta->di_name);
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
2014-03-28 15:00:02 +00:00
|
|
|
case STREAM_CTRL_NAV_CMD:
|
|
|
|
if (!b->use_nav)
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
handle_nav_command(s, arg);
|
|
|
|
return STREAM_OK;
|
|
|
|
case STREAM_CTRL_GET_NAV_EVENT: {
|
|
|
|
struct mp_nav_event **ev = arg;
|
|
|
|
if (ev)
|
|
|
|
fill_next_event(s, ev);
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
2010-07-05 20:52:47 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return STREAM_UNSUPPORTED;
|
2010-07-05 17:04:46 +00:00
|
|
|
}
|
|
|
|
|
2014-03-30 06:55:32 +00:00
|
|
|
static const char *aacs_strerr(int err)
|
|
|
|
{
|
|
|
|
switch (err) {
|
|
|
|
case AACS_ERROR_CORRUPTED_DISC: return "opening or reading of AACS files failed";
|
|
|
|
case AACS_ERROR_NO_CONFIG: return "missing config file";
|
|
|
|
case AACS_ERROR_NO_PK: return "no matching processing key";
|
|
|
|
case AACS_ERROR_NO_CERT: return "no valid certificate";
|
|
|
|
case AACS_ERROR_CERT_REVOKED: return "certificate has been revoked";
|
|
|
|
case AACS_ERROR_MMC_OPEN: return "MMC open failed (maybe no MMC drive?)";
|
|
|
|
case AACS_ERROR_MMC_FAILURE: return "MMC failed";
|
|
|
|
case AACS_ERROR_NO_DK: return "no matching device key";
|
|
|
|
default: return "unknown error";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-30 06:42:16 +00:00
|
|
|
static bool check_disc_info(stream_t *s)
|
|
|
|
{
|
|
|
|
struct bluray_priv_s *b = s->priv;
|
|
|
|
const BLURAY_DISC_INFO *info = bd_get_disc_info(b->bd);
|
|
|
|
|
|
|
|
// check Blu-ray
|
|
|
|
if (!info->bluray_detected) {
|
|
|
|
MP_ERR(s, "Given stream is not a Blu-ray.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check AACS
|
|
|
|
if (info->aacs_detected) {
|
|
|
|
if (!info->libaacs_detected) {
|
|
|
|
MP_ERR(s, "AACS encryption detected but cannot find libaacs.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!info->aacs_handled) {
|
2014-03-30 06:55:32 +00:00
|
|
|
MP_ERR(s, "AACS error: %s\n", aacs_strerr(info->aacs_error_code));
|
2014-03-30 06:42:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check BD+
|
|
|
|
if (info->bdplus_detected) {
|
|
|
|
if (!info->libbdplus_detected) {
|
|
|
|
MP_ERR(s, "BD+ encryption detected but cannot find libbdplus.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!info->bdplus_handled) {
|
|
|
|
MP_ERR(s, "Cannot decrypt BD+ encryption.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-30 01:04:39 +00:00
|
|
|
static void select_initial_title(stream_t *s, int title_guess) {
|
|
|
|
struct bluray_priv_s *b = s->priv;
|
|
|
|
|
|
|
|
int title = -1;
|
|
|
|
if (b->use_nav) {
|
|
|
|
if (b->cfg_title == BLURAY_MENU_TITLE)
|
|
|
|
title = 0; // BLURAY_TITLE_TOP_MENU
|
|
|
|
else if (b->cfg_title == BLURAY_DEFAULT_TITLE)
|
|
|
|
title = b->num_titles - 1;
|
|
|
|
else
|
|
|
|
title = b->cfg_title;
|
|
|
|
} else {
|
|
|
|
if (b->cfg_title != BLURAY_DEFAULT_TITLE )
|
|
|
|
title = b->cfg_title;
|
|
|
|
else
|
|
|
|
title = title_guess;
|
|
|
|
}
|
|
|
|
if (title < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (play_title(b, title))
|
|
|
|
b->current_title = title;
|
|
|
|
else {
|
|
|
|
MP_WARN(s, "Couldn't start title '%d'.\n", title);
|
|
|
|
if (!b->use_nav) // cannot query title info in nav
|
|
|
|
b->current_title = bd_get_current_title(b->bd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void select_initial_angle(stream_t *s) {
|
|
|
|
struct bluray_priv_s *b = s->priv;
|
|
|
|
if (!b->use_nav) // no way to figure out current title info
|
|
|
|
return;
|
|
|
|
BLURAY_TITLE_INFO *info = bd_get_title_info(b->bd, b->current_title, 0);
|
|
|
|
if (!info)
|
|
|
|
return;
|
|
|
|
/* Select angle */
|
2014-06-10 20:09:27 +00:00
|
|
|
unsigned int angle = s->opts->bluray_angle;
|
|
|
|
if (!angle)
|
|
|
|
angle = BLURAY_DEFAULT_ANGLE;
|
2014-03-30 01:04:39 +00:00
|
|
|
angle = FFMIN(angle, info->angle_count);
|
|
|
|
if (angle)
|
|
|
|
bd_select_angle(b->bd, angle);
|
|
|
|
b->current_angle = bd_get_current_angle(b->bd);
|
|
|
|
bd_free_title_info(info);
|
|
|
|
}
|
|
|
|
|
2014-05-24 12:06:13 +00:00
|
|
|
static int bluray_stream_open(stream_t *s)
|
2010-07-05 17:04:46 +00:00
|
|
|
{
|
2013-08-02 15:02:34 +00:00
|
|
|
struct bluray_priv_s *b = s->priv;
|
2010-07-05 20:52:47 +00:00
|
|
|
|
2014-03-30 02:16:32 +00:00
|
|
|
const char *device = NULL;
|
2010-07-05 17:04:46 +00:00
|
|
|
/* find the requested device */
|
2014-06-10 20:09:27 +00:00
|
|
|
if (b->cfg_device && b->cfg_device[0])
|
2013-08-02 15:02:34 +00:00
|
|
|
device = b->cfg_device;
|
2014-06-10 20:09:27 +00:00
|
|
|
else if (s->opts->bluray_device && s->opts->bluray_device[0])
|
|
|
|
device = s->opts->bluray_device;
|
2010-07-05 17:04:46 +00:00
|
|
|
|
|
|
|
if (!device) {
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_ERR(s, "No Blu-ray device/location was specified ...\n");
|
2010-07-05 17:04:46 +00:00
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open device */
|
2014-03-30 02:16:32 +00:00
|
|
|
BLURAY *bd = bd_open(device, NULL);
|
2010-07-05 17:04:46 +00:00
|
|
|
if (!bd) {
|
2014-03-30 02:16:32 +00:00
|
|
|
MP_ERR(s, "Couldn't open Blu-ray device: %s\n", device);
|
2010-07-05 17:04:46 +00:00
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
2014-03-30 06:42:16 +00:00
|
|
|
b->bd = bd;
|
2010-07-05 17:04:46 +00:00
|
|
|
|
2014-03-30 06:42:16 +00:00
|
|
|
if (!check_disc_info(s)) {
|
2014-03-28 15:00:02 +00:00
|
|
|
destruct(b);
|
2010-07-05 17:04:46 +00:00
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2014-03-30 02:16:32 +00:00
|
|
|
int title_guess = BLURAY_DEFAULT_TITLE;
|
2014-03-28 15:00:02 +00:00
|
|
|
if (b->use_nav) {
|
2014-03-30 06:42:16 +00:00
|
|
|
const BLURAY_DISC_INFO *disc_info = bd_get_disc_info(b->bd);
|
2014-03-28 15:00:02 +00:00
|
|
|
b->num_titles = disc_info->num_hdmv_titles + disc_info->num_bdj_titles;
|
|
|
|
++b->num_titles; // for BLURAY_TITLE_TOP_MENU
|
|
|
|
++b->num_titles; // for BLURAY_TITLE_FIRST_PLAY
|
|
|
|
} else {
|
|
|
|
/* check for available titles on disc */
|
2014-03-30 02:16:32 +00:00
|
|
|
b->num_titles = bd_get_titles(bd, TITLES_RELEVANT, 0);
|
2014-03-28 15:00:02 +00:00
|
|
|
if (!b->num_titles) {
|
|
|
|
MP_ERR(s, "Can't find any Blu-ray-compatible title here.\n");
|
|
|
|
destruct(b);
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
2010-07-05 17:04:46 +00:00
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
/* parse titles information */
|
2014-03-30 02:16:32 +00:00
|
|
|
uint64_t max_duration = 0;
|
|
|
|
for (int i = 0; i < b->num_titles; i++) {
|
|
|
|
BLURAY_TITLE_INFO *ti = bd_get_title_info(bd, i, 0);
|
2014-03-28 15:00:02 +00:00
|
|
|
if (!ti)
|
|
|
|
continue;
|
2010-07-05 17:04:46 +00:00
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
/* try to guess which title may contain the main movie */
|
|
|
|
if (ti->duration > max_duration) {
|
|
|
|
max_duration = ti->duration;
|
|
|
|
title_guess = i;
|
|
|
|
}
|
2010-07-05 17:04:46 +00:00
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
bd_free_title_info(ti);
|
|
|
|
}
|
2010-07-05 17:04:46 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
// these should be set before any callback
|
|
|
|
b->pool = mp_image_pool_new(6);
|
|
|
|
b->current_angle = -1;
|
|
|
|
b->current_title = -1;
|
|
|
|
|
2014-03-26 18:15:37 +00:00
|
|
|
// initialize libbluray event queue
|
|
|
|
bd_get_event(bd, NULL);
|
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
if (b->use_nav) {
|
|
|
|
if (!bd_play(bd)) {
|
|
|
|
destruct(b);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
bd_register_overlay_proc(bd, s, overlay_process);
|
|
|
|
}
|
|
|
|
|
2014-03-30 01:04:39 +00:00
|
|
|
select_initial_title(s, title_guess);
|
|
|
|
select_initial_angle(s);
|
2010-07-05 17:04:46 +00:00
|
|
|
|
2014-03-28 15:00:02 +00:00
|
|
|
if (b->use_nav)
|
|
|
|
s->fill_buffer = bdnav_stream_fill_buffer;
|
|
|
|
else
|
|
|
|
s->fill_buffer = bluray_stream_fill_buffer;
|
2010-07-05 17:04:46 +00:00
|
|
|
s->close = bluray_stream_close;
|
2010-07-05 20:52:47 +00:00
|
|
|
s->control = bluray_stream_control;
|
2014-01-14 21:02:52 +00:00
|
|
|
s->type = STREAMTYPE_BLURAY;
|
2014-03-30 02:16:32 +00:00
|
|
|
s->end_pos = bd_get_title_size(bd);
|
2010-07-05 17:04:46 +00:00
|
|
|
s->sector_size = BLURAY_SECTOR_SIZE;
|
2010-07-05 20:52:47 +00:00
|
|
|
s->priv = b;
|
2010-07-05 17:04:46 +00:00
|
|
|
|
2013-12-21 19:36:45 +00:00
|
|
|
MP_VERBOSE(s, "Blu-ray successfully opened.\n");
|
2010-07-05 17:04:46 +00:00
|
|
|
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const stream_info_t stream_info_bluray = {
|
stream: fix url_options field, make protocols field not fixed length
The way the url_options field was handled was not entirely sane: it's
actually a flexible array member, so it points to garbage for streams
which do not initialize this member (it just points to the data right
after the struct, which is garbage in theory and practice). This was
not actually a problem, since the field is only used if priv_size is
set (due to how this stuff is used). But it doesn't allow setting
priv_size only, which might be useful in some cases.
Also, make the protocols array not a fixed size array. Most stream
implementations have only 1 protocol prefix, but stream_lavf.c has
over 10 (whitelists ffmpeg protocols). The high size of the fixed
size protocol array wastes space, and it is _still_ annoying to
add new prefixes to stream_lavf (have to bump the maximum length),
so make it arbitrary length.
The two changes (plus some more cosmetic changes) arte conflated into
one, because it was annoying going over all the stream implementations.
2013-08-25 20:49:27 +00:00
|
|
|
.name = "bd",
|
|
|
|
.open = bluray_stream_open,
|
2014-06-11 22:32:37 +00:00
|
|
|
.protocols = (const char*const[]){ "bd", "br", "bluray", NULL },
|
2013-08-02 15:02:34 +00:00
|
|
|
.priv_defaults = &bluray_stream_priv_dflts,
|
|
|
|
.priv_size = sizeof(struct bluray_priv_s),
|
|
|
|
.options = bluray_stream_opts_fields,
|
2014-06-11 22:32:37 +00:00
|
|
|
.url_options = (const char*const[]){
|
stream: fix url_options field, make protocols field not fixed length
The way the url_options field was handled was not entirely sane: it's
actually a flexible array member, so it points to garbage for streams
which do not initialize this member (it just points to the data right
after the struct, which is garbage in theory and practice). This was
not actually a problem, since the field is only used if priv_size is
set (due to how this stuff is used). But it doesn't allow setting
priv_size only, which might be useful in some cases.
Also, make the protocols array not a fixed size array. Most stream
implementations have only 1 protocol prefix, but stream_lavf.c has
over 10 (whitelists ffmpeg protocols). The high size of the fixed
size protocol array wastes space, and it is _still_ annoying to
add new prefixes to stream_lavf (have to bump the maximum length),
so make it arbitrary length.
The two changes (plus some more cosmetic changes) arte conflated into
one, because it was annoying going over all the stream implementations.
2013-08-25 20:49:27 +00:00
|
|
|
"hostname=title",
|
|
|
|
"filename=device",
|
|
|
|
NULL
|
2013-08-02 15:02:34 +00:00
|
|
|
},
|
2010-07-05 17:04:46 +00:00
|
|
|
};
|
2014-03-28 15:00:02 +00:00
|
|
|
|
|
|
|
const stream_info_t stream_info_bdnav = {
|
|
|
|
.name = "bdnav",
|
|
|
|
.open = bluray_stream_open,
|
2014-06-11 22:32:37 +00:00
|
|
|
.protocols = (const char*const[]){ "bdnav", "brnav", "bluraynav", NULL },
|
2014-03-28 15:00:02 +00:00
|
|
|
.priv_defaults = &bdnav_stream_priv_dflts,
|
|
|
|
.priv_size = sizeof(struct bluray_priv_s),
|
|
|
|
.options = bdnav_stream_opts_fields,
|
2014-06-11 22:32:37 +00:00
|
|
|
.url_options = (const char*const[]){
|
2014-03-28 15:00:02 +00:00
|
|
|
"hostname=title",
|
|
|
|
"filename=device",
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
};
|