2010-07-05 19:04:46 +02: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 libbdnav support for menus navigation
|
|
|
|
* - Add AACS/BD+ protection detection
|
|
|
|
* - Add descrambled keys database support (KEYDB.cfg)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-11-19 00:22:43 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2010-07-05 19:04:46 +02:00
|
|
|
|
2013-07-12 22:04:44 +02:00
|
|
|
#include <libbluray/bluray.h>
|
2014-03-12 06:41:34 +01:00
|
|
|
#include <libbluray/meta_data.h>
|
2013-07-12 22:04:44 +02:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
2010-07-05 19:04:46 +02:00
|
|
|
#include "config.h"
|
2012-02-19 14:15:41 +01:00
|
|
|
#include "talloc.h"
|
2013-12-18 17:12:21 +01:00
|
|
|
#include "common/common.h"
|
2013-12-17 02:39:45 +01:00
|
|
|
#include "common/msg.h"
|
2013-12-17 02:02:25 +01:00
|
|
|
#include "options/m_option.h"
|
2010-07-05 19:04:46 +02:00
|
|
|
#include "stream.h"
|
2014-03-26 19:15:37 +01:00
|
|
|
#include "osdep/timer.h"
|
2010-07-05 19:04:46 +02:00
|
|
|
|
|
|
|
#define BLURAY_SECTOR_SIZE 6144
|
|
|
|
|
|
|
|
#define BLURAY_DEFAULT_ANGLE 0
|
|
|
|
#define BLURAY_DEFAULT_CHAPTER 0
|
2014-03-18 14:34:23 +01:00
|
|
|
#define BLURAY_DEFAULT_TITLE -1
|
2010-07-05 19:04:46 +02:00
|
|
|
|
2013-05-05 19:02:10 +02: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))
|
|
|
|
|
2010-07-05 19:04:46 +02:00
|
|
|
char *bluray_device = NULL;
|
|
|
|
int bluray_angle = 0;
|
|
|
|
|
2010-07-05 22:52:47 +02:00
|
|
|
struct bluray_priv_s {
|
|
|
|
BLURAY *bd;
|
2014-03-26 19:17:31 +01:00
|
|
|
BLURAY_TITLE_INFO *title_info;
|
2013-09-10 15:39:48 +02:00
|
|
|
int num_titles;
|
2010-07-05 22:52:47 +02:00
|
|
|
int current_angle;
|
|
|
|
int current_title;
|
2014-03-26 19:19:14 +01:00
|
|
|
int current_playlist;
|
2013-08-02 17:02:34 +02:00
|
|
|
|
|
|
|
int cfg_title;
|
|
|
|
char *cfg_device;
|
2010-07-05 22:52:47 +02:00
|
|
|
};
|
|
|
|
|
2013-08-12 15:38:22 +02:00
|
|
|
static struct bluray_priv_s bluray_stream_priv_dflts = {
|
|
|
|
.cfg_title = BLURAY_DEFAULT_TITLE
|
2010-07-05 19:04:46 +02:00
|
|
|
};
|
|
|
|
|
2013-08-02 17:02:34 +02:00
|
|
|
#define OPT_BASE_STRUCT struct bluray_priv_s
|
2010-07-05 19:04:46 +02:00
|
|
|
static const m_option_t bluray_stream_opts_fields[] = {
|
2014-03-18 14:34:23 +01:00
|
|
|
OPT_CHOICE_OR_INT("title", cfg_title, 0, 0, 99999,
|
|
|
|
({"longest", BLURAY_DEFAULT_TITLE})),
|
2013-08-02 17:02:34 +02:00
|
|
|
OPT_STRING("device", cfg_device, 0),
|
|
|
|
{0}
|
2010-07-05 19:04:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void bluray_stream_close(stream_t *s)
|
|
|
|
{
|
2010-07-05 22:52:47 +02:00
|
|
|
struct bluray_priv_s *b = s->priv;
|
|
|
|
|
2014-03-26 19:17:31 +01:00
|
|
|
if (b->title_info)
|
|
|
|
bd_free_title_info(b->title_info);
|
2010-07-05 22:52:47 +02:00
|
|
|
bd_close(b->bd);
|
2010-07-05 19:04:46 +02:00
|
|
|
}
|
|
|
|
|
2012-11-18 20:46:12 +01:00
|
|
|
static int bluray_stream_seek(stream_t *s, int64_t pos)
|
2010-07-05 19:04:46 +02:00
|
|
|
{
|
2010-07-05 22:52:47 +02:00
|
|
|
struct bluray_priv_s *b = s->priv;
|
2012-11-18 20:46:12 +01:00
|
|
|
int64_t p;
|
2010-07-05 19:04:46 +02:00
|
|
|
|
2010-07-05 22:52:47 +02:00
|
|
|
p = bd_seek(b->bd, pos);
|
2010-07-05 19:04:46 +02:00
|
|
|
if (p == -1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-26 19:15:37 +01:00
|
|
|
static void handle_event(stream_t *s, const BD_EVENT *ev)
|
|
|
|
{
|
2014-03-26 19:17:31 +01:00
|
|
|
struct bluray_priv_s *b = s->priv;
|
2014-03-26 19:15:37 +01:00
|
|
|
switch (ev->event) {
|
2014-03-26 19:19:14 +01:00
|
|
|
case BD_EVENT_PLAYLIST:
|
|
|
|
b->current_playlist = ev->param;
|
|
|
|
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 19:17:31 +01:00
|
|
|
case BD_EVENT_TITLE:
|
|
|
|
if (ev->param == BLURAY_TITLE_FIRST_PLAY)
|
|
|
|
b->current_title = bd_get_current_title(b->bd);
|
|
|
|
else
|
|
|
|
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 19:19:14 +01:00
|
|
|
b->title_info = bd_get_playlist_info(b->bd, b->current_playlist,
|
|
|
|
b->current_angle);
|
2014-03-26 19:17:31 +01:00
|
|
|
}
|
|
|
|
break;
|
2014-03-26 19:15:37 +01:00
|
|
|
default:
|
|
|
|
MP_TRACE(s, "Unhandled event: %d %d\n", ev->event, ev->param);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-05 19:04:46 +02:00
|
|
|
static int bluray_stream_fill_buffer(stream_t *s, char *buf, int len)
|
|
|
|
{
|
2010-07-05 22:52:47 +02:00
|
|
|
struct bluray_priv_s *b = s->priv;
|
|
|
|
|
2014-03-26 19:15:37 +01:00
|
|
|
BD_EVENT event;
|
|
|
|
while (bd_get_event(b->bd, &event))
|
|
|
|
handle_event(s, &event);
|
2010-07-05 22:52:47 +02:00
|
|
|
return bd_read(b->bd, buf, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 19:17:31 +01:00
|
|
|
const BLURAY_TITLE_INFO *ti = b->title_info;
|
2010-07-05 22:52:47 +02:00
|
|
|
|
|
|
|
if (!ti)
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
|
|
|
|
*((unsigned int *) arg) = ti->chapter_count;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-05-09 18:49:16 +02:00
|
|
|
case STREAM_CTRL_GET_CHAPTER_TIME: {
|
2014-03-26 19:17:31 +01:00
|
|
|
const BLURAY_TITLE_INFO *ti = b->title_info;
|
2013-05-09 18:49:16 +02:00
|
|
|
int chapter = *(double *)arg;
|
|
|
|
double time = MP_NOPTS_VALUE;
|
|
|
|
|
|
|
|
if (!ti)
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
|
|
|
|
if (chapter >= 0 || chapter < ti->chapter_count) {
|
|
|
|
time = BD_TIME_TO_MP(ti->chapters[chapter].start);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time != MP_NOPTS_VALUE) {
|
|
|
|
*(double *)arg = time;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2014-03-18 05:03:00 +01:00
|
|
|
case STREAM_CTRL_SET_CURRENT_TITLE: {
|
|
|
|
const uint32_t title = *((unsigned int*)arg);
|
|
|
|
if (title < b->num_titles && bd_select_title(b->bd, title)) {
|
|
|
|
b->current_title = title;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2012-10-21 16:56:50 +02:00
|
|
|
case STREAM_CTRL_GET_CURRENT_TITLE: {
|
|
|
|
*((unsigned int *) arg) = b->current_title;
|
|
|
|
return 1;
|
|
|
|
}
|
2013-09-10 15:39:48 +02:00
|
|
|
case STREAM_CTRL_GET_NUM_TITLES: {
|
|
|
|
*((unsigned int *)arg) = b->num_titles;
|
|
|
|
return 1;
|
|
|
|
}
|
2012-10-21 16:56:50 +02:00
|
|
|
|
2013-05-05 19:02:10 +02:00
|
|
|
case STREAM_CTRL_GET_TIME_LENGTH: {
|
2014-03-26 19:17:31 +01:00
|
|
|
const BLURAY_TITLE_INFO *ti = b->title_info;
|
2013-05-05 19:02:10 +02: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));
|
|
|
|
// Reset mpv internal stream position.
|
|
|
|
stream_seek(s, bd_tell(b->bd));
|
|
|
|
// API makes it hard to determine seeking success
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-05 22:52:47 +02:00
|
|
|
case STREAM_CTRL_GET_NUM_ANGLES: {
|
2014-03-26 19:17:31 +01:00
|
|
|
const BLURAY_TITLE_INFO *ti = b->title_info;
|
2010-07-05 22:52:47 +02:00
|
|
|
|
|
|
|
if (!ti)
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
|
|
|
|
*((int *) arg) = ti->angle_count;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
case STREAM_CTRL_GET_ANGLE: {
|
|
|
|
*((int *) arg) = b->current_angle;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
case STREAM_CTRL_SET_ANGLE: {
|
2014-03-26 19:17:31 +01:00
|
|
|
const BLURAY_TITLE_INFO *ti = b->title_info;
|
2010-07-05 22:52:47 +02:00
|
|
|
int angle = *((int *) arg);
|
|
|
|
|
|
|
|
if (!ti)
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
|
|
|
|
if (angle < 0 || angle > ti->angle_count) {
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
b->current_angle = angle;
|
|
|
|
bd_seamless_angle_change(b->bd, angle);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-02-19 14:15:41 +01:00
|
|
|
case STREAM_CTRL_GET_LANG: {
|
|
|
|
struct stream_lang_req *req = arg;
|
2014-03-26 19:17:31 +01:00
|
|
|
const BLURAY_TITLE_INFO *ti = b->title_info;
|
|
|
|
if (ti && ti->clip_count) {
|
2012-02-19 14:15:41 +01: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 16:43:31 +02:00
|
|
|
case STREAM_AUDIO:
|
2012-02-19 14:15:41 +01: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 16:43:31 +02:00
|
|
|
case STREAM_SUB:
|
2012-02-19 14:15:41 +01:00
|
|
|
count = ti->clips[0].pg_stream_count;
|
|
|
|
si = ti->clips[0].pg_streams;
|
|
|
|
break;
|
|
|
|
}
|
2013-05-05 19:02:27 +02: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 14:15:41 +01:00
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2013-05-05 19:02:10 +02:00
|
|
|
case STREAM_CTRL_GET_START_TIME:
|
|
|
|
{
|
|
|
|
*((double *)arg) = 0;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_MANAGES_TIMELINE:
|
|
|
|
return STREAM_OK;
|
2014-03-12 06:41:34 +01:00
|
|
|
case STREAM_CTRL_GET_DISC_NAME:
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2010-07-05 22:52:47 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return STREAM_UNSUPPORTED;
|
2010-07-05 19:04:46 +02:00
|
|
|
}
|
|
|
|
|
2013-08-02 17:02:34 +02:00
|
|
|
static int bluray_stream_open(stream_t *s, int mode)
|
2010-07-05 19:04:46 +02:00
|
|
|
{
|
2013-08-02 17:02:34 +02:00
|
|
|
struct bluray_priv_s *b = s->priv;
|
2010-07-05 22:52:47 +02:00
|
|
|
|
2010-07-05 19:04:46 +02:00
|
|
|
BLURAY_TITLE_INFO *info = NULL;
|
|
|
|
BLURAY *bd;
|
|
|
|
|
2013-09-10 15:39:48 +02:00
|
|
|
int title, title_guess;
|
2010-07-05 19:04:46 +02:00
|
|
|
uint64_t title_size;
|
|
|
|
|
2013-04-26 21:50:19 +02:00
|
|
|
unsigned int angle = 0;
|
2010-07-05 19:04:46 +02:00
|
|
|
uint64_t max_duration = 0;
|
|
|
|
|
|
|
|
char *device = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* find the requested device */
|
2013-08-02 17:02:34 +02:00
|
|
|
if (b->cfg_device)
|
|
|
|
device = b->cfg_device;
|
2010-07-05 19:04:46 +02:00
|
|
|
else if (bluray_device)
|
|
|
|
device = bluray_device;
|
|
|
|
|
|
|
|
if (!device) {
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_ERR(s, "No Blu-ray device/location was specified ...\n");
|
2010-07-05 19:04:46 +02:00
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open device */
|
|
|
|
bd = bd_open(device, NULL);
|
|
|
|
if (!bd) {
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_ERR(s, "Couldn't open Blu-ray device: %s\n",
|
2010-07-05 19:04:46 +02:00
|
|
|
device);
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for available titles on disc */
|
2013-09-10 15:39:48 +02:00
|
|
|
b->num_titles = bd_get_titles(bd, TITLES_RELEVANT, angle);
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_SMODE(s, "ID_BLURAY_TITLES=%d\n", b->num_titles);
|
2013-09-10 15:39:48 +02:00
|
|
|
if (!b->num_titles) {
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_ERR(s, "Can't find any Blu-ray-compatible title here.\n");
|
2010-07-05 19:04:46 +02:00
|
|
|
bd_close(bd);
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse titles information */
|
|
|
|
title_guess = BLURAY_DEFAULT_TITLE;
|
2013-09-10 15:39:48 +02:00
|
|
|
for (i = 0; i < b->num_titles; i++) {
|
2010-07-05 19:04:46 +02:00
|
|
|
BLURAY_TITLE_INFO *ti;
|
|
|
|
int sec, msec;
|
|
|
|
|
2011-07-10 10:21:35 +02:00
|
|
|
ti = bd_get_title_info(bd, i, angle);
|
2010-07-05 19:04:46 +02:00
|
|
|
if (!ti)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sec = ti->duration / 90000;
|
|
|
|
msec = (ti->duration - sec) % 1000;
|
|
|
|
|
2014-03-18 14:34:23 +01:00
|
|
|
MP_SMODE(s, "ID_BLURAY_TITLE_%d_CHAPTERS=%d\n", i, ti->chapter_count);
|
|
|
|
MP_SMODE(s, "ID_BLURAY_TITLE_%d_ANGLE=%d\n", i, ti->angle_count);
|
|
|
|
MP_SMODE(s, "ID_BLURAY_TITLE_%d_LENGTH=%d.%03d\n", i, sec, msec);
|
2010-07-05 19:04:46 +02:00
|
|
|
|
|
|
|
/* try to guess which title may contain the main movie */
|
|
|
|
if (ti->duration > max_duration) {
|
|
|
|
max_duration = ti->duration;
|
|
|
|
title_guess = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
bd_free_title_info(ti);
|
|
|
|
}
|
|
|
|
|
2014-03-26 19:15:37 +01:00
|
|
|
// initialize libbluray event queue
|
|
|
|
bd_get_event(bd, NULL);
|
|
|
|
|
2010-07-05 19:04:46 +02:00
|
|
|
/* Select current title */
|
2014-03-18 14:34:23 +01:00
|
|
|
if (b->cfg_title != BLURAY_DEFAULT_TITLE)
|
|
|
|
title = b->cfg_title;
|
|
|
|
else
|
|
|
|
title = title_guess;
|
2013-09-10 15:39:48 +02:00
|
|
|
title = FFMIN(title, b->num_titles - 1);
|
2010-07-05 19:04:46 +02:00
|
|
|
|
|
|
|
bd_select_title(bd, title);
|
|
|
|
|
|
|
|
title_size = bd_get_title_size(bd);
|
2014-03-18 14:34:23 +01:00
|
|
|
MP_SMODE(s, "ID_BLURAY_CURRENT_TITLE=%d\n", title);
|
2010-07-05 19:04:46 +02:00
|
|
|
|
|
|
|
/* Get current title information */
|
2011-07-10 10:21:35 +02:00
|
|
|
info = bd_get_title_info(bd, title, angle);
|
2010-07-05 19:04:46 +02:00
|
|
|
if (!info)
|
|
|
|
goto err_no_info;
|
|
|
|
|
|
|
|
/* Select angle */
|
|
|
|
angle = bluray_angle ? bluray_angle : BLURAY_DEFAULT_ANGLE;
|
|
|
|
angle = FFMIN(angle, info->angle_count);
|
|
|
|
|
|
|
|
if (angle)
|
|
|
|
bd_select_angle(bd, angle);
|
|
|
|
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_SMODE(s, "ID_BLURAY_CURRENT_ANGLE=%d\n", angle + 1);
|
2010-07-05 19:04:46 +02:00
|
|
|
|
|
|
|
bd_free_title_info(info);
|
|
|
|
|
|
|
|
err_no_info:
|
|
|
|
s->fill_buffer = bluray_stream_fill_buffer;
|
|
|
|
s->seek = bluray_stream_seek;
|
|
|
|
s->close = bluray_stream_close;
|
2010-07-05 22:52:47 +02:00
|
|
|
s->control = bluray_stream_control;
|
|
|
|
|
|
|
|
b->bd = bd;
|
|
|
|
b->current_angle = angle;
|
|
|
|
b->current_title = title;
|
2010-07-05 19:04:46 +02:00
|
|
|
|
2014-01-14 22:02:52 +01:00
|
|
|
s->type = STREAMTYPE_BLURAY;
|
2010-07-05 19:04:46 +02:00
|
|
|
s->end_pos = title_size;
|
|
|
|
s->sector_size = BLURAY_SECTOR_SIZE;
|
2013-07-07 20:49:15 +02:00
|
|
|
s->flags = MP_STREAM_SEEK;
|
2010-07-05 22:52:47 +02:00
|
|
|
s->priv = b;
|
2010-07-05 19:04:46 +02:00
|
|
|
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_VERBOSE(s, "Blu-ray successfully opened.\n");
|
2010-07-05 19:04:46 +02: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 22:49:27 +02:00
|
|
|
.name = "bd",
|
|
|
|
.open = bluray_stream_open,
|
|
|
|
.protocols = (const char*[]){ "bd", "br", "bluray", NULL },
|
2013-08-02 17:02:34 +02:00
|
|
|
.priv_defaults = &bluray_stream_priv_dflts,
|
|
|
|
.priv_size = sizeof(struct bluray_priv_s),
|
|
|
|
.options = bluray_stream_opts_fields,
|
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 22:49:27 +02:00
|
|
|
.url_options = (const char*[]){
|
|
|
|
"hostname=title",
|
|
|
|
"filename=device",
|
|
|
|
NULL
|
2013-08-02 17:02:34 +02:00
|
|
|
},
|
2010-07-05 19:04:46 +02:00
|
|
|
};
|