2014-07-15 01:49:02 +02:00
|
|
|
/*
|
2015-04-13 09:36:54 +02:00
|
|
|
* This file is part of mpv.
|
2014-07-15 01:49:02 +02:00
|
|
|
*
|
2015-04-13 09:36:54 +02:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2014-07-15 01:49:02 +02:00
|
|
|
* 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.
|
|
|
|
*
|
2015-04-13 09:36:54 +02:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2014-07-15 01:49:02 +02:00
|
|
|
* 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
|
2015-04-13 09:36:54 +02:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2014-07-15 01:49:02 +02:00
|
|
|
*/
|
2015-04-13 09:36:54 +02:00
|
|
|
|
2014-07-15 01:49:02 +02:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
2014-09-25 23:54:58 +02:00
|
|
|
#include <strings.h>
|
2014-07-15 01:49:02 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <dvdnav/dvdnav.h>
|
|
|
|
|
2014-09-25 23:54:58 +02:00
|
|
|
#include "osdep/io.h"
|
|
|
|
|
2014-07-15 01:49:02 +02:00
|
|
|
#include "options/options.h"
|
|
|
|
#include "common/msg.h"
|
|
|
|
#include "input/input.h"
|
2016-09-08 21:46:48 +02:00
|
|
|
#include "options/m_config.h"
|
2014-09-25 23:54:58 +02:00
|
|
|
#include "options/path.h"
|
2014-07-15 01:49:02 +02:00
|
|
|
#include "osdep/timer.h"
|
|
|
|
#include "stream.h"
|
|
|
|
#include "demux/demux.h"
|
|
|
|
#include "video/out/vo.h"
|
|
|
|
#include "stream_dvd_common.h"
|
|
|
|
|
|
|
|
#define TITLE_MENU -1
|
|
|
|
#define TITLE_LONGEST -2
|
|
|
|
|
|
|
|
struct priv {
|
|
|
|
dvdnav_t *dvdnav; // handle to libdvdnav stuff
|
|
|
|
char *filename; // path
|
|
|
|
unsigned int duration; // in milliseconds
|
|
|
|
int mousex, mousey;
|
|
|
|
int title;
|
|
|
|
uint32_t spu_clut[16];
|
|
|
|
bool spu_clut_valid;
|
|
|
|
bool had_initial_vts;
|
|
|
|
|
|
|
|
int dvd_speed;
|
|
|
|
|
|
|
|
int track;
|
|
|
|
char *device;
|
|
|
|
|
2016-09-08 21:46:48 +02:00
|
|
|
struct dvd_opts *opts;
|
2014-07-15 01:49:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DNE(e) [e] = # e
|
|
|
|
static const char *const mp_dvdnav_events[] = {
|
|
|
|
DNE(DVDNAV_BLOCK_OK),
|
|
|
|
DNE(DVDNAV_NOP),
|
|
|
|
DNE(DVDNAV_STILL_FRAME),
|
|
|
|
DNE(DVDNAV_SPU_STREAM_CHANGE),
|
|
|
|
DNE(DVDNAV_AUDIO_STREAM_CHANGE),
|
|
|
|
DNE(DVDNAV_VTS_CHANGE),
|
|
|
|
DNE(DVDNAV_CELL_CHANGE),
|
|
|
|
DNE(DVDNAV_NAV_PACKET),
|
|
|
|
DNE(DVDNAV_STOP),
|
|
|
|
DNE(DVDNAV_HIGHLIGHT),
|
|
|
|
DNE(DVDNAV_SPU_CLUT_CHANGE),
|
|
|
|
DNE(DVDNAV_HOP_CHANNEL),
|
|
|
|
DNE(DVDNAV_WAIT),
|
|
|
|
};
|
|
|
|
|
|
|
|
#define LOOKUP_NAME(array, i) \
|
|
|
|
(((i) >= 0 && (i) < MP_ARRAY_SIZE(array)) ? array[(i)] : "?")
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief mp_dvdnav_lang_from_aid() returns the language corresponding to audio id 'aid'
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \param sid: physical subtitle id
|
|
|
|
* \return 0 on error, otherwise language id
|
|
|
|
*/
|
|
|
|
static int mp_dvdnav_lang_from_aid(stream_t *stream, int aid)
|
|
|
|
{
|
|
|
|
uint8_t lg;
|
|
|
|
uint16_t lang;
|
|
|
|
struct priv *priv = stream->priv;
|
|
|
|
|
|
|
|
if (aid < 0)
|
|
|
|
return 0;
|
|
|
|
lg = dvdnav_get_audio_logical_stream(priv->dvdnav, aid & 0x7);
|
|
|
|
if (lg == 0xff)
|
|
|
|
return 0;
|
|
|
|
lang = dvdnav_audio_stream_to_lang(priv->dvdnav, lg);
|
|
|
|
if (lang == 0xffff)
|
|
|
|
return 0;
|
|
|
|
return lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief mp_dvdnav_lang_from_sid() returns the language corresponding to subtitle id 'sid'
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \param sid: physical subtitle id
|
|
|
|
* \return 0 on error, otherwise language id
|
|
|
|
*/
|
|
|
|
static int mp_dvdnav_lang_from_sid(stream_t *stream, int sid)
|
|
|
|
{
|
|
|
|
uint8_t k;
|
|
|
|
uint16_t lang;
|
|
|
|
struct priv *priv = stream->priv;
|
|
|
|
if (sid < 0)
|
|
|
|
return 0;
|
|
|
|
for (k = 0; k < 32; k++)
|
|
|
|
if (dvdnav_get_spu_logical_stream(priv->dvdnav, k) == sid)
|
|
|
|
break;
|
|
|
|
if (k == 32)
|
|
|
|
return 0;
|
|
|
|
lang = dvdnav_spu_stream_to_lang(priv->dvdnav, k);
|
|
|
|
if (lang == 0xffff)
|
|
|
|
return 0;
|
|
|
|
return lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief mp_dvdnav_number_of_subs() returns the count of available subtitles
|
|
|
|
* \param stream: - stream pointer
|
|
|
|
* \return 0 on error, something meaningful otherwise
|
|
|
|
*/
|
|
|
|
static int mp_dvdnav_number_of_subs(stream_t *stream)
|
|
|
|
{
|
|
|
|
struct priv *priv = stream->priv;
|
|
|
|
uint8_t lg, k, n = 0;
|
|
|
|
|
|
|
|
for (k = 0; k < 32; k++) {
|
|
|
|
lg = dvdnav_get_spu_logical_stream(priv->dvdnav, k);
|
|
|
|
if (lg == 0xff)
|
|
|
|
continue;
|
|
|
|
if (lg >= n)
|
|
|
|
n = lg + 1;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fill_buffer(stream_t *s, char *buf, int max_len)
|
|
|
|
{
|
|
|
|
struct priv *priv = s->priv;
|
|
|
|
dvdnav_t *dvdnav = priv->dvdnav;
|
|
|
|
|
|
|
|
if (max_len < 2048)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int len = -1;
|
|
|
|
int event = DVDNAV_NOP;
|
|
|
|
if (dvdnav_get_next_block(dvdnav, buf, &event, &len) != DVDNAV_STATUS_OK)
|
|
|
|
{
|
|
|
|
MP_ERR(s, "Error getting next block from DVD %d (%s)\n",
|
|
|
|
event, dvdnav_err_to_string(dvdnav));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (event != DVDNAV_BLOCK_OK) {
|
|
|
|
const char *name = LOOKUP_NAME(mp_dvdnav_events, event);
|
|
|
|
MP_VERBOSE(s, "DVDNAV: event %s (%d).\n", name, event);
|
|
|
|
}
|
|
|
|
switch (event) {
|
|
|
|
case DVDNAV_BLOCK_OK:
|
|
|
|
return len;
|
2015-08-03 23:40:41 +02:00
|
|
|
case DVDNAV_STOP:
|
2014-07-15 01:49:02 +02:00
|
|
|
return 0;
|
|
|
|
case DVDNAV_NAV_PACKET: {
|
|
|
|
pci_t *pnavpci = dvdnav_get_current_nav_pci(dvdnav);
|
|
|
|
uint32_t start_pts = pnavpci->pci_gi.vobu_s_ptm;
|
|
|
|
MP_TRACE(s, "start pts = %"PRIu32"\n", start_pts);
|
|
|
|
break;
|
|
|
|
}
|
2015-08-03 23:40:41 +02:00
|
|
|
case DVDNAV_STILL_FRAME:
|
|
|
|
dvdnav_still_skip(dvdnav);
|
2014-07-15 01:49:02 +02:00
|
|
|
return 0;
|
2015-08-03 23:40:41 +02:00
|
|
|
case DVDNAV_WAIT:
|
|
|
|
dvdnav_wait_skip(dvdnav);
|
2014-07-15 01:49:02 +02:00
|
|
|
return 0;
|
2015-08-03 23:40:41 +02:00
|
|
|
case DVDNAV_HIGHLIGHT:
|
2014-07-15 01:49:02 +02:00
|
|
|
break;
|
|
|
|
case DVDNAV_VTS_CHANGE: {
|
|
|
|
int tit = 0, part = 0;
|
|
|
|
dvdnav_vts_change_event_t *vts_event =
|
|
|
|
(dvdnav_vts_change_event_t *)s->buffer;
|
|
|
|
MP_INFO(s, "DVDNAV, switched to title: %d\n",
|
|
|
|
vts_event->new_vtsN);
|
|
|
|
if (!priv->had_initial_vts) {
|
|
|
|
// dvdnav sends an initial VTS change before any data; don't
|
|
|
|
// cause a blocking wait for the player, because the player in
|
|
|
|
// turn can't initialize the demuxer without data.
|
|
|
|
priv->had_initial_vts = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dvdnav_current_title_info(dvdnav, &tit, &part) == DVDNAV_STATUS_OK)
|
|
|
|
{
|
|
|
|
MP_VERBOSE(s, "DVDNAV, NEW TITLE %d\n", tit);
|
2015-08-03 23:40:41 +02:00
|
|
|
if (priv->title > 0 && tit != priv->title)
|
2014-07-15 01:49:02 +02:00
|
|
|
MP_WARN(s, "Requested title not found\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DVDNAV_CELL_CHANGE: {
|
|
|
|
dvdnav_cell_change_event_t *ev = (dvdnav_cell_change_event_t *)buf;
|
|
|
|
|
|
|
|
if (ev->pgc_length)
|
|
|
|
priv->duration = ev->pgc_length / 90;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DVDNAV_SPU_CLUT_CHANGE: {
|
|
|
|
memcpy(priv->spu_clut, buf, 16 * sizeof(uint32_t));
|
|
|
|
priv->spu_clut_valid = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int control(stream_t *stream, int cmd, void *arg)
|
|
|
|
{
|
|
|
|
struct priv *priv = stream->priv;
|
|
|
|
dvdnav_t *dvdnav = priv->dvdnav;
|
|
|
|
int tit, part;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case STREAM_CTRL_GET_NUM_CHAPTERS: {
|
|
|
|
if (dvdnav_current_title_info(dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
if (dvdnav_get_number_of_parts(dvdnav, tit, &part) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
if (!part)
|
|
|
|
break;
|
2014-12-13 18:40:44 +01:00
|
|
|
*(unsigned int *)arg = part;
|
2014-07-15 01:49:02 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_CHAPTER_TIME: {
|
|
|
|
double *ch = arg;
|
|
|
|
int chapter = *ch;
|
|
|
|
if (dvdnav_current_title_info(dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
uint64_t *parts = NULL, duration = 0;
|
|
|
|
int n = dvdnav_describe_title_chapters(dvdnav, tit, &parts, &duration);
|
|
|
|
if (!parts)
|
|
|
|
break;
|
2014-12-16 19:28:08 +01:00
|
|
|
if (chapter < 0 || chapter + 1 > n)
|
2014-07-15 01:49:02 +02:00
|
|
|
break;
|
2014-12-13 18:37:31 +01:00
|
|
|
*ch = chapter > 0 ? parts[chapter - 1] / 90000.0 : 0;
|
2014-07-15 01:49:02 +02:00
|
|
|
free(parts);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_TIME_LENGTH: {
|
|
|
|
if (priv->duration) {
|
|
|
|
*(double *)arg = (double)priv->duration / 1000.0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_ASPECT_RATIO: {
|
|
|
|
uint8_t ar = dvdnav_get_video_aspect(dvdnav);
|
|
|
|
*(double *)arg = !ar ? 4.0 / 3.0 : 16.0 / 9.0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_CURRENT_TIME: {
|
|
|
|
double tm;
|
|
|
|
tm = dvdnav_get_current_time(dvdnav) / 90000.0f;
|
|
|
|
if (tm != -1) {
|
|
|
|
*(double *)arg = tm;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_NUM_TITLES: {
|
|
|
|
int32_t num_titles = 0;
|
|
|
|
if (dvdnav_get_number_of_titles(dvdnav, &num_titles) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
*((unsigned int*)arg)= num_titles;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
2014-12-13 20:25:31 +01:00
|
|
|
case STREAM_CTRL_GET_TITLE_LENGTH: {
|
|
|
|
int t = *(double *)arg;
|
|
|
|
int32_t num_titles = 0;
|
|
|
|
if (dvdnav_get_number_of_titles(dvdnav, &num_titles) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
if (t < 0 || t >= num_titles)
|
|
|
|
break;
|
|
|
|
uint64_t duration = 0;
|
|
|
|
uint64_t *parts = NULL;
|
|
|
|
dvdnav_describe_title_chapters(dvdnav, t + 1, &parts, &duration);
|
|
|
|
if (!parts)
|
|
|
|
break;
|
|
|
|
free(parts);
|
|
|
|
*(double *)arg = duration / 90000.0;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
2014-07-15 01:49:02 +02:00
|
|
|
case STREAM_CTRL_GET_CURRENT_TITLE: {
|
|
|
|
if (dvdnav_current_title_info(dvdnav, &tit, &part) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
*((unsigned int *) arg) = tit - 1;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_SET_CURRENT_TITLE: {
|
|
|
|
int title = *((unsigned int *) arg);
|
|
|
|
if (dvdnav_title_play(priv->dvdnav, title + 1) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
stream_drop_buffers(stream);
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_SEEK_TO_TIME: {
|
dvd: try to improve seeking
libdvdnav is garbage. Seeking by time is incredibly inexact, which is in
part due to the fact that it does not use the DVD seek tables. Instead,
it assumes CBR for certain ranges within the DVD, which makes especially
small seeks unreliable.
I have no good fix for this, other than hacking libdvdnav (I'd rather
prefer to remove mpv DVD support completely than doing this). So here's
a shitty hack that tries to workaround these problems. A basic
observation is that seeking in VLC seems to work quite well; however it
seems to be based on seeking by blocks (unless there is a subtle "trick"
I didn't see in the source code). mpv usually seeks by timestamps, so
this is not an option for us. However, we can pretend we are doing this
in the DVD layer.
The previous commit added a way to pass through relative seeks. This
commit uses the relative seek. STREAM_CTRL_SEEK_TO_TIME is backwards
compatible (there's still dvdread and bluray), so most code is about
extracing the relative seek information and turning it into a block
seek.
(Another way would have been using SEEK_FACTOR stuff, but that would
probably make for a less reliable way to handle this situation.)
Additionally, if a hr-seek is done, add an offset by 10 seconds. As long
as the error done by libdvdnav is not worse, this should help with hr-
seeks - although it makes them much slower.
2015-01-19 21:25:30 +01:00
|
|
|
double *args = arg;
|
|
|
|
double d = args[0]; // absolute target timestamp
|
2016-02-28 19:14:23 +01:00
|
|
|
int flags = args[1]; // from SEEK_* flags (demux.h)
|
dvd: try to improve seeking
libdvdnav is garbage. Seeking by time is incredibly inexact, which is in
part due to the fact that it does not use the DVD seek tables. Instead,
it assumes CBR for certain ranges within the DVD, which makes especially
small seeks unreliable.
I have no good fix for this, other than hacking libdvdnav (I'd rather
prefer to remove mpv DVD support completely than doing this). So here's
a shitty hack that tries to workaround these problems. A basic
observation is that seeking in VLC seems to work quite well; however it
seems to be based on seeking by blocks (unless there is a subtle "trick"
I didn't see in the source code). mpv usually seeks by timestamps, so
this is not an option for us. However, we can pretend we are doing this
in the DVD layer.
The previous commit added a way to pass through relative seeks. This
commit uses the relative seek. STREAM_CTRL_SEEK_TO_TIME is backwards
compatible (there's still dvdread and bluray), so most code is about
extracing the relative seek information and turning it into a block
seek.
(Another way would have been using SEEK_FACTOR stuff, but that would
probably make for a less reliable way to handle this situation.)
Additionally, if a hr-seek is done, add an offset by 10 seconds. As long
as the error done by libdvdnav is not worse, this should help with hr-
seeks - although it makes them much slower.
2015-01-19 21:25:30 +01:00
|
|
|
if (flags & SEEK_HR)
|
|
|
|
d -= 10; // fudge offset; it's a hack, because fuck libdvd*
|
2014-07-15 01:49:02 +02:00
|
|
|
int64_t tm = (int64_t)(d * 90000);
|
|
|
|
if (tm < 0)
|
|
|
|
tm = 0;
|
|
|
|
if (priv->duration && tm >= (priv->duration * 90))
|
|
|
|
tm = priv->duration * 90 - 1;
|
dvd: try to improve seeking
libdvdnav is garbage. Seeking by time is incredibly inexact, which is in
part due to the fact that it does not use the DVD seek tables. Instead,
it assumes CBR for certain ranges within the DVD, which makes especially
small seeks unreliable.
I have no good fix for this, other than hacking libdvdnav (I'd rather
prefer to remove mpv DVD support completely than doing this). So here's
a shitty hack that tries to workaround these problems. A basic
observation is that seeking in VLC seems to work quite well; however it
seems to be based on seeking by blocks (unless there is a subtle "trick"
I didn't see in the source code). mpv usually seeks by timestamps, so
this is not an option for us. However, we can pretend we are doing this
in the DVD layer.
The previous commit added a way to pass through relative seeks. This
commit uses the relative seek. STREAM_CTRL_SEEK_TO_TIME is backwards
compatible (there's still dvdread and bluray), so most code is about
extracing the relative seek information and turning it into a block
seek.
(Another way would have been using SEEK_FACTOR stuff, but that would
probably make for a less reliable way to handle this situation.)
Additionally, if a hr-seek is done, add an offset by 10 seconds. As long
as the error done by libdvdnav is not worse, this should help with hr-
seeks - although it makes them much slower.
2015-01-19 21:25:30 +01:00
|
|
|
uint32_t pos, len;
|
|
|
|
if (dvdnav_get_position(dvdnav, &pos, &len) != DVDNAV_STATUS_OK)
|
2014-07-15 01:49:02 +02:00
|
|
|
break;
|
2016-02-28 19:14:23 +01:00
|
|
|
MP_VERBOSE(stream, "seek to PTS %f (%"PRId64")\n", d, tm);
|
|
|
|
if (dvdnav_time_search(dvdnav, tm) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
2014-07-15 01:49:02 +02:00
|
|
|
stream_drop_buffers(stream);
|
|
|
|
d = dvdnav_get_current_time(dvdnav) / 90000.0f;
|
|
|
|
MP_VERBOSE(stream, "landed at: %f\n", d);
|
dvd: try to improve seeking
libdvdnav is garbage. Seeking by time is incredibly inexact, which is in
part due to the fact that it does not use the DVD seek tables. Instead,
it assumes CBR for certain ranges within the DVD, which makes especially
small seeks unreliable.
I have no good fix for this, other than hacking libdvdnav (I'd rather
prefer to remove mpv DVD support completely than doing this). So here's
a shitty hack that tries to workaround these problems. A basic
observation is that seeking in VLC seems to work quite well; however it
seems to be based on seeking by blocks (unless there is a subtle "trick"
I didn't see in the source code). mpv usually seeks by timestamps, so
this is not an option for us. However, we can pretend we are doing this
in the DVD layer.
The previous commit added a way to pass through relative seeks. This
commit uses the relative seek. STREAM_CTRL_SEEK_TO_TIME is backwards
compatible (there's still dvdread and bluray), so most code is about
extracing the relative seek information and turning it into a block
seek.
(Another way would have been using SEEK_FACTOR stuff, but that would
probably make for a less reliable way to handle this situation.)
Additionally, if a hr-seek is done, add an offset by 10 seconds. As long
as the error done by libdvdnav is not worse, this should help with hr-
seeks - although it makes them much slower.
2015-01-19 21:25:30 +01:00
|
|
|
if (dvdnav_get_position(dvdnav, &pos, &len) == DVDNAV_STATUS_OK)
|
|
|
|
MP_VERBOSE(stream, "block: %lu\n", (unsigned long)pos);
|
2014-07-15 01:49:02 +02:00
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_NUM_ANGLES: {
|
|
|
|
uint32_t curr, angles;
|
|
|
|
if (dvdnav_get_angle_info(dvdnav, &curr, &angles) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
*(int *)arg = angles;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_ANGLE: {
|
|
|
|
uint32_t curr, angles;
|
|
|
|
if (dvdnav_get_angle_info(dvdnav, &curr, &angles) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
*(int *)arg = curr;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_SET_ANGLE: {
|
|
|
|
uint32_t curr, angles;
|
|
|
|
int new_angle = *(int *)arg;
|
|
|
|
if (dvdnav_get_angle_info(dvdnav, &curr, &angles) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
if (new_angle > angles || new_angle < 1)
|
|
|
|
break;
|
|
|
|
if (dvdnav_angle_change(dvdnav, new_angle) != DVDNAV_STATUS_OK)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_LANG: {
|
|
|
|
struct stream_lang_req *req = arg;
|
|
|
|
int lang = 0;
|
|
|
|
switch (req->type) {
|
|
|
|
case STREAM_AUDIO:
|
|
|
|
lang = mp_dvdnav_lang_from_aid(stream, req->id);
|
|
|
|
break;
|
|
|
|
case STREAM_SUB:
|
|
|
|
lang = mp_dvdnav_lang_from_sid(stream, req->id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!lang)
|
|
|
|
break;
|
|
|
|
snprintf(req->name, sizeof(req->name), "%c%c", lang >> 8, lang);
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_DVD_INFO: {
|
|
|
|
struct stream_dvd_info_req *req = arg;
|
|
|
|
memset(req, 0, sizeof(*req));
|
|
|
|
req->num_subs = mp_dvdnav_number_of_subs(stream);
|
|
|
|
assert(sizeof(uint32_t) == sizeof(unsigned int));
|
|
|
|
memcpy(req->palette, priv->spu_clut, sizeof(req->palette));
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_DISC_NAME: {
|
|
|
|
const char *volume = NULL;
|
|
|
|
if (dvdnav_get_title_string(dvdnav, &volume) != DVDNAV_STATUS_OK)
|
|
|
|
break;
|
|
|
|
if (!volume || !volume[0])
|
|
|
|
break;
|
|
|
|
*(char**)arg = talloc_strdup(NULL, volume);
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stream_dvdnav_close(stream_t *s)
|
|
|
|
{
|
|
|
|
struct priv *priv = s->priv;
|
|
|
|
dvdnav_close(priv->dvdnav);
|
|
|
|
priv->dvdnav = NULL;
|
|
|
|
if (priv->dvd_speed)
|
|
|
|
dvd_set_speed(s, priv->filename, -1);
|
|
|
|
if (priv->filename)
|
|
|
|
free(priv->filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct priv *new_dvdnav_stream(stream_t *stream, char *filename)
|
|
|
|
{
|
|
|
|
struct priv *priv = stream->priv;
|
|
|
|
const char *title_str;
|
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(priv->filename = strdup(filename)))
|
|
|
|
return NULL;
|
|
|
|
|
2016-09-08 21:46:48 +02:00
|
|
|
priv->dvd_speed = priv->opts->speed;
|
2014-07-15 01:49:02 +02:00
|
|
|
dvd_set_speed(stream, priv->filename, priv->dvd_speed);
|
|
|
|
|
|
|
|
if (dvdnav_open(&(priv->dvdnav), priv->filename) != DVDNAV_STATUS_OK) {
|
|
|
|
free(priv->filename);
|
|
|
|
priv->filename = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!priv->dvdnav)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dvdnav_set_readahead_flag(priv->dvdnav, 1);
|
|
|
|
if (dvdnav_set_PGC_positioning_flag(priv->dvdnav, 1) != DVDNAV_STATUS_OK)
|
|
|
|
MP_ERR(stream, "stream_dvdnav, failed to set PGC positioning\n");
|
|
|
|
/* report the title?! */
|
|
|
|
dvdnav_get_title_string(priv->dvdnav, &title_str);
|
|
|
|
|
|
|
|
return priv;
|
|
|
|
}
|
|
|
|
|
2016-09-08 21:46:48 +02:00
|
|
|
static int open_s_internal(stream_t *stream)
|
2014-07-15 01:49:02 +02:00
|
|
|
{
|
|
|
|
struct priv *priv, *p;
|
|
|
|
priv = p = stream->priv;
|
|
|
|
char *filename;
|
|
|
|
|
2016-09-08 21:46:48 +02:00
|
|
|
p->opts = mp_get_config_group(stream, stream->global, &dvd_conf);
|
|
|
|
|
2014-07-15 01:49:02 +02:00
|
|
|
if (p->device && p->device[0])
|
|
|
|
filename = p->device;
|
2016-09-08 21:46:48 +02:00
|
|
|
else if (p->opts->device && p->opts->device[0])
|
|
|
|
filename = p->opts->device;
|
2014-07-15 01:49:02 +02:00
|
|
|
else
|
|
|
|
filename = DEFAULT_DVD_DEVICE;
|
|
|
|
if (!new_dvdnav_stream(stream, filename)) {
|
|
|
|
MP_ERR(stream, "Couldn't open DVD device: %s\n",
|
|
|
|
filename);
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p->track == TITLE_LONGEST) { // longest
|
|
|
|
dvdnav_t *dvdnav = priv->dvdnav;
|
|
|
|
uint64_t best_length = 0;
|
|
|
|
int best_title = -1;
|
|
|
|
int32_t num_titles;
|
|
|
|
if (dvdnav_get_number_of_titles(dvdnav, &num_titles) == DVDNAV_STATUS_OK) {
|
2017-03-29 03:16:11 +02:00
|
|
|
MP_VERBOSE(stream, "List of available titles:\n");
|
2014-07-15 01:49:02 +02:00
|
|
|
for (int n = 1; n <= num_titles; n++) {
|
|
|
|
uint64_t *parts = NULL, duration = 0;
|
|
|
|
dvdnav_describe_title_chapters(dvdnav, n, &parts, &duration);
|
|
|
|
if (parts) {
|
|
|
|
if (duration > best_length) {
|
|
|
|
best_length = duration;
|
|
|
|
best_title = n;
|
|
|
|
}
|
2017-03-29 03:16:11 +02:00
|
|
|
if (duration > 90000) { // arbitrarily ignore <1s titles
|
|
|
|
char *time = mp_format_time(duration / 90000, false);
|
|
|
|
MP_VERBOSE(stream, "title: %3d duration: %s\n",
|
|
|
|
n - 1, time);
|
|
|
|
talloc_free(time);
|
|
|
|
}
|
2014-07-15 01:49:02 +02:00
|
|
|
free(parts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p->track = best_title - 1;
|
|
|
|
MP_INFO(stream, "Selecting title %d.\n", p->track);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p->track >= 0) {
|
|
|
|
priv->title = p->track;
|
|
|
|
if (dvdnav_title_play(priv->dvdnav, p->track + 1) != DVDNAV_STATUS_OK) {
|
|
|
|
MP_FATAL(stream, "dvdnav_stream, couldn't select title %d, error '%s'\n",
|
|
|
|
p->track, dvdnav_err_to_string(priv->dvdnav));
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
} else {
|
2015-06-26 23:37:23 +02:00
|
|
|
MP_FATAL(stream, "DVD menu support has been removed.\n");
|
|
|
|
return STREAM_ERROR;
|
2014-07-15 01:49:02 +02:00
|
|
|
}
|
2016-09-08 21:46:48 +02:00
|
|
|
if (p->opts->angle > 1)
|
|
|
|
dvdnav_angle_change(priv->dvdnav, p->opts->angle);
|
2014-07-15 01:49:02 +02:00
|
|
|
|
|
|
|
stream->sector_size = 2048;
|
|
|
|
stream->fill_buffer = fill_buffer;
|
|
|
|
stream->control = control;
|
|
|
|
stream->close = stream_dvdnav_close;
|
|
|
|
stream->demuxer = "+disc";
|
|
|
|
stream->lavf_type = "mpeg";
|
|
|
|
stream->allow_caching = false;
|
|
|
|
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
|
2016-09-08 21:46:48 +02:00
|
|
|
static int open_s(stream_t *stream)
|
|
|
|
{
|
|
|
|
struct priv *priv = talloc_zero(stream, struct priv);
|
|
|
|
stream->priv = priv;
|
|
|
|
|
|
|
|
bstr title, bdevice;
|
|
|
|
bstr_split_tok(bstr0(stream->path), "/", &title, &bdevice);
|
|
|
|
|
|
|
|
priv->track = TITLE_LONGEST;
|
|
|
|
|
|
|
|
if (bstr_equals0(title, "longest") || bstr_equals0(title, "first")) {
|
|
|
|
priv->track = TITLE_LONGEST;
|
|
|
|
} else if (bstr_equals0(title, "menu")) {
|
|
|
|
priv->track = TITLE_MENU;
|
|
|
|
} else if (title.len) {
|
|
|
|
bstr rest;
|
2017-03-29 03:14:39 +02:00
|
|
|
priv->track = bstrtoll(title, &rest, 10);
|
2016-09-08 21:46:48 +02:00
|
|
|
if (rest.len) {
|
|
|
|
MP_ERR(stream, "number expected: '%.*s'\n", BSTR_P(rest));
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->device = bstrto0(priv, bdevice);
|
|
|
|
|
|
|
|
return open_s_internal(stream);
|
|
|
|
}
|
|
|
|
|
2014-07-15 01:49:02 +02:00
|
|
|
const stream_info_t stream_info_dvdnav = {
|
|
|
|
.name = "dvdnav",
|
|
|
|
.open = open_s,
|
|
|
|
.protocols = (const char*const[]){ "dvd", "dvdnav", NULL },
|
|
|
|
};
|
2014-09-25 23:54:58 +02:00
|
|
|
|
|
|
|
static bool check_ifo(const char *path)
|
|
|
|
{
|
|
|
|
if (strcasecmp(mp_basename(path), "video_ts.ifo"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return dvd_probe(path, ".ifo", "DVDVIDEO-VMG");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ifo_dvdnav_stream_open(stream_t *stream)
|
|
|
|
{
|
2016-09-08 21:46:48 +02:00
|
|
|
struct priv *priv = talloc_zero(stream, struct priv);
|
2014-09-25 23:54:58 +02:00
|
|
|
stream->priv = priv;
|
2016-09-08 21:46:48 +02:00
|
|
|
|
2016-12-04 23:15:31 +01:00
|
|
|
if (!stream->access_references)
|
|
|
|
goto unsupported;
|
|
|
|
|
2016-09-08 21:46:48 +02:00
|
|
|
priv->track = TITLE_LONGEST;
|
2014-09-25 23:54:58 +02:00
|
|
|
|
|
|
|
char *path = mp_file_get_path(priv, bstr0(stream->url));
|
|
|
|
if (!path)
|
|
|
|
goto unsupported;
|
|
|
|
|
|
|
|
// We allow the path to point to a directory containing VIDEO_TS/, a
|
|
|
|
// directory containing VIDEO_TS.IFO, or that file itself.
|
|
|
|
if (!check_ifo(path)) {
|
|
|
|
// On UNIX, just assume the filename is always uppercase.
|
2015-05-09 15:26:47 +02:00
|
|
|
char *npath = mp_path_join(priv, path, "VIDEO_TS.IFO");
|
2014-09-25 23:54:58 +02:00
|
|
|
if (!check_ifo(npath)) {
|
2015-05-09 15:26:47 +02:00
|
|
|
npath = mp_path_join(priv, path, "VIDEO_TS/VIDEO_TS.IFO");
|
2014-09-25 23:54:58 +02:00
|
|
|
if (!check_ifo(npath))
|
|
|
|
goto unsupported;
|
|
|
|
}
|
|
|
|
path = npath;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->device = bstrto0(priv, mp_dirname(path));
|
|
|
|
|
|
|
|
MP_INFO(stream, ".IFO detected. Redirecting to dvd://\n");
|
2016-09-08 21:46:48 +02:00
|
|
|
return open_s_internal(stream);
|
2014-09-25 23:54:58 +02:00
|
|
|
|
|
|
|
unsupported:
|
|
|
|
talloc_free(priv);
|
|
|
|
stream->priv = NULL;
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
const stream_info_t stream_info_ifo_dvdnav = {
|
2017-02-02 18:24:27 +01:00
|
|
|
.name = "ifo_dvdnav",
|
2014-09-25 23:54:58 +02:00
|
|
|
.open = ifo_dvdnav_stream_open,
|
|
|
|
.protocols = (const char*const[]){ "file", "", NULL },
|
|
|
|
};
|