From 053044741713eddc4aea024fb0c175aa01fc092d Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 12 Dec 2013 01:44:28 +0100 Subject: Add prelimimary (basic, possibly broken) dvdnav support This readds a more or less completely new dvdnav implementation, though it's based on the code from before commit 41fbcee. Note that this is rather basic, and might be broken or not quite usable in many cases. Most importantly, navigation highlights are not correctly implemented. This would require changes in the FFmpeg dvdsub decoder (to apply a different internal CLUT), so supporting it is not really possible right now. And in fact, I don't think I ever want to support it, because it's a very small gain for a lot of work. Instead, mpv will display fake highlights, which are an approximate bounding box around the real highlights. Some things like mouse input or switching audio/subtitles stream using the dvdnav VM are not supported. Might be quite fragile on transitions: if dvdnav initiates a transition, and doesn't give us enough mpeg data to initialize video playback, the player will just quit. This is added only because some users seem to want it. I don't intend to make mpv a good DVD player, so the very basic minimum will have to do. How about you just convert your DVD to proper video files? --- demux/demux.c | 4 +- etc/input.conf | 13 + mpvcore/input/input.c | 2 + mpvcore/input/input.h | 2 + mpvcore/options.c | 2 +- mpvcore/player/command.c | 10 +- mpvcore/player/configfiles.c | 2 +- mpvcore/player/dvdnav.c | 207 +++++++++++++ mpvcore/player/loadfile.c | 24 +- mpvcore/player/mp_core.h | 10 +- mpvcore/player/playloop.c | 5 +- mpvcore/player/sub.c | 2 - old-configure | 21 ++ old-makefile | 3 + stream/cache.c | 1 + stream/stream.c | 4 + stream/stream.h | 3 + stream/stream_dvdnav.c | 718 +++++++++++++++++++++++++++++++++++++++++++ stream/stream_dvdnav.h | 81 +++++ sub/dec_sub.h | 1 + sub/osd.c | 2 + sub/osd.h | 8 + sub/sd_lavc.c | 19 +- wscript | 4 + wscript_build.py | 2 + 25 files changed, 1122 insertions(+), 28 deletions(-) create mode 100644 mpvcore/player/dvdnav.c create mode 100644 stream/stream_dvdnav.c create mode 100644 stream/stream_dvdnav.h diff --git a/demux/demux.c b/demux/demux.c index bfa999ab15..f1a468272d 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -523,7 +523,6 @@ static struct demuxer *open_given_type(struct MPOpts *opts, .metadata = talloc_zero(demuxer, struct mp_tags), }; demuxer->params = params; // temporary during open() - stream_seek(stream, stream->start_pos); mp_msg(MSGT_DEMUXER, MSGL_V, "Trying demuxer: %s (force-level: %s)\n", desc->name, d_level(check)); @@ -542,6 +541,8 @@ static struct demuxer *open_given_type(struct MPOpts *opts, demuxer->ts_resets_possible = false; // Doesn't work, because stream_pts is a "guess". demuxer->accurate_seek = false; + // Can be seekable even if the stream isn't. + demuxer->seekable = true; } add_stream_chapters(demuxer); demuxer_sort_chapters(demuxer); @@ -556,6 +557,7 @@ static struct demuxer *open_given_type(struct MPOpts *opts, } free_demuxer(demuxer); + stream_seek(stream, stream->start_pos); return NULL; } diff --git a/etc/input.conf b/etc/input.conf index 6bbb6996b7..5c000bcd60 100644 --- a/etc/input.conf +++ b/etc/input.conf @@ -189,6 +189,19 @@ #JOY_BTN2 add volume 1 #JOY_BTN3 add volume -1 +# For dvdnav:// + +# dvdnav controls during playback +#ENTER {dvdnav} dvdnav menu # DVDNav MENU +# BS {dvdnav} dvdnav prev # DVDNav PREVIOUS menu (in the order chapter->title->root) +# dvdnav controls when showing menu (additionally to the controls above) +#UP {dvdnav-menu} dvdnav up # DVDNav UP +#DOWN {dvdnav-menu} dvdnav down # DVDNav DOWN +#LEFT {dvdnav-menu} dvdnav left # DVDNav LEFT +#RIGHT {dvdnav-menu} dvdnav right # DVDNav RIGHT +#ENTER {dvdnav-menu} dvdnav select # DVDNav SELECT (ok) +#MOUSE_MOVE {dvdnav-menu} ignore # block mouse events + # # Not assigned by default # (not an exhaustive list of unbound commands) diff --git a/mpvcore/input/input.c b/mpvcore/input/input.c index dbda34ed40..f6553e7ba4 100644 --- a/mpvcore/input/input.c +++ b/mpvcore/input/input.c @@ -241,6 +241,8 @@ static const struct mp_cmd_def mp_cmds[] = { }}, { MP_CMD_DISABLE_INPUT_SECTION, "disable_section", { ARG_STRING } }, + { MP_CMD_DVDNAV, "dvdnav", { ARG_STRING } }, + { MP_CMD_AF, "af", { ARG_STRING, ARG_STRING } }, { MP_CMD_VF, "vf", { ARG_STRING, ARG_STRING } }, diff --git a/mpvcore/input/input.h b/mpvcore/input/input.h index 2465fe6010..13b86d227e 100644 --- a/mpvcore/input/input.h +++ b/mpvcore/input/input.h @@ -75,6 +75,8 @@ enum mp_command_type { MP_CMD_ENABLE_INPUT_SECTION, MP_CMD_DISABLE_INPUT_SECTION, + MP_CMD_DVDNAV, + /// DVB commands MP_CMD_DVB_SET_CHANNEL, diff --git a/mpvcore/options.c b/mpvcore/options.c index 97a5a5e6dc..de7183014f 100644 --- a/mpvcore/options.c +++ b/mpvcore/options.c @@ -365,7 +365,7 @@ const m_option_t mp_opts[] = { 0, 40, ({"no", -1})), {"cdrom-device", &cdrom_device, CONF_TYPE_STRING, 0, 0, 0, NULL}, -#if HAVE_DVDREAD +#if HAVE_DVDREAD || HAVE_DVDNAV {"dvd-device", &dvd_device, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"dvd-speed", &dvd_speed, CONF_TYPE_INT, 0, 0, 0, NULL}, {"dvdangle", &dvd_angle, CONF_TYPE_INT, CONF_RANGE, 1, 99, NULL}, diff --git a/mpvcore/player/command.c b/mpvcore/player/command.c index 7f92c50bd9..05285e0111 100644 --- a/mpvcore/player/command.c +++ b/mpvcore/player/command.c @@ -2957,8 +2957,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) if (dvb_step_channel(mpctx->stream, dir)) { - mpctx->stop_play = PT_NEXT_ENTRY; - mpctx->dvbin_reopen = 1; + mpctx->stop_play = PT_RELOAD_DEMUXER; } } #endif /* HAVE_DVBIN */ @@ -2989,8 +2988,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) if (dvb_set_channel(mpctx->stream, cmd->args[1].v.i, cmd->args[0].v.i)) { - mpctx->stop_play = PT_NEXT_ENTRY; - mpctx->dvbin_reopen = 1; + mpctx->stop_play = PT_RELOAD_DEMUXER; } } break; @@ -3087,6 +3085,10 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) mp_input_disable_section(mpctx->input, cmd->args[0].v.s); break; + case MP_CMD_DVDNAV: + mp_nav_user_input(mpctx, cmd->args[0].v.s); + break; + case MP_CMD_VO_CMDLINE: if (mpctx->video_out) { char *s = cmd->args[0].v.s; diff --git a/mpvcore/player/configfiles.c b/mpvcore/player/configfiles.c index 31e3d0e75d..21450b482d 100644 --- a/mpvcore/player/configfiles.c +++ b/mpvcore/player/configfiles.c @@ -201,7 +201,7 @@ char *mp_get_playback_resume_config_filename(const char *fname, goto exit; realpath = mp_path_join(tmp, bstr0(cwd), bstr0(fname)); } -#if HAVE_DVDREAD +#if HAVE_DVDREAD || HAVE_DVDNAV if (bstr_startswith0(bfname, "dvd://")) realpath = talloc_asprintf(tmp, "%s - %s", realpath, dvd_device); #endif diff --git a/mpvcore/player/dvdnav.c b/mpvcore/player/dvdnav.c new file mode 100644 index 0000000000..879bacd1c1 --- /dev/null +++ b/mpvcore/player/dvdnav.c @@ -0,0 +1,207 @@ +/* + * This file is part of mpv. + * + * mpv 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. + * + * mpv 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 mpv. If not, see . + */ + +#include +#include + +#include "mp_core.h" + +#include "mpvcore/mp_msg.h" +#include "mpvcore/mp_common.h" +#include "mpvcore/input/input.h" + +#include "stream/stream_dvdnav.h" + +#include "sub/dec_sub.h" +#include "sub/osd.h" + +#include "video/mp_image.h" +#include "video/decode/dec_video.h" + +struct mp_nav_state { + struct mp_log *log; + + bool nav_still_frame; + bool nav_eof; + bool nav_menu; + int hi_visible; + int highlight[4]; // x0 y0 x1 y1 + int subsize[2]; + struct sub_bitmap *hi_elem; +}; + +// Allocate state and enable navigation features. Must happen before +// initializing cache, because the cache would read data. Since stream_dvdnav is +// in a mode which skips all transitions on reading data (before enabling +// data), this would skip stuff. +void mp_nav_init(struct MPContext *mpctx) +{ + assert(!mpctx->nav_state); + + // dvdnav is interactive + if (mpctx->encode_lavc_ctx) + return; + + struct mp_nav_cmd inp = {MP_NAV_CMD_ENABLE}; + if (stream_control(mpctx->stream, STREAM_CTRL_NAV_CMD, &inp) < 1) + return; + + mpctx->nav_state = talloc_zero(NULL, struct mp_nav_state); + mpctx->nav_state->log = mp_log_new(mpctx->nav_state, mpctx->log, "dvdnav"); + + MP_VERBOSE(mpctx->nav_state, "enabling\n"); + + mp_input_enable_section(mpctx->input, "dvdnav", 0); + mp_input_set_section_mouse_area(mpctx->input, "dvdnav-menu", + INT_MIN, INT_MIN, INT_MAX, INT_MAX); +} + +void mp_nav_reset(struct MPContext *mpctx) +{ + struct mp_nav_state *nav = mpctx->nav_state; + if (!nav) + return; + struct mp_nav_cmd inp = {MP_NAV_CMD_RESUME}; + stream_control(mpctx->stream, STREAM_CTRL_NAV_CMD, &inp); + nav->hi_visible = 0; + nav->nav_menu = false; + mp_input_disable_section(mpctx->input, "dvdnav-menu"); + // Prevent demuxer init code to seek to the "start" + if (mpctx->stream) + mpctx->stream->start_pos = stream_tell(mpctx->stream); +} + +void mp_nav_destroy(struct MPContext *mpctx) +{ + if (!mpctx->nav_state) + return; + mp_input_disable_section(mpctx->input, "dvdnav"); + mp_input_disable_section(mpctx->input, "dvdnav-menu"); + talloc_free(mpctx->nav_state); + mpctx->nav_state = NULL; +} + +void mp_nav_user_input(struct MPContext *mpctx, char *command) +{ + struct mp_nav_state *nav = mpctx->nav_state; + if (!nav) + return; + struct mp_nav_cmd inp = {MP_NAV_CMD_MENU}; + inp.u.menu.action = command; + stream_control(mpctx->stream, STREAM_CTRL_NAV_CMD, &inp); +} + +void mp_handle_nav(struct MPContext *mpctx) +{ + struct mp_nav_state *nav = mpctx->nav_state; + if (!nav) + return; + while (1) { + struct mp_nav_event *ev = NULL; + stream_control(mpctx->stream, STREAM_CTRL_GET_NAV_EVENT, &ev); + if (!ev) + break; + switch (ev->event) { + case MP_NAV_EVENT_DRAIN: { + struct mp_nav_cmd inp = {MP_NAV_CMD_DRAIN_OK}; + stream_control(mpctx->stream, STREAM_CTRL_NAV_CMD, &inp); + MP_VERBOSE(nav, "drain\n"); + break; + } + case MP_NAV_EVENT_RESET_ALL: { + mpctx->stop_play = PT_RELOAD_DEMUXER; + MP_VERBOSE(nav, "reload\n"); + break; + } + case MP_NAV_EVENT_EOF: + nav->nav_eof = true; + break; + case MP_NAV_EVENT_MENU_MODE: + nav->nav_menu = ev->u.menu_mode.enable; + if (nav->nav_menu) { + mp_input_enable_section(mpctx->input, "dvdnav-menu", 0); + } else { + mp_input_disable_section(mpctx->input, "dvdnav-menu"); + } + break; + case MP_NAV_EVENT_HIGHLIGHT: + MP_VERBOSE(nav, "highlight: %d %d %d - %d %d\n", + ev->u.highlight.display, + ev->u.highlight.sx, ev->u.highlight.sy, + ev->u.highlight.ex, ev->u.highlight.ey); + nav->highlight[0] = MPCLAMP(ev->u.highlight.sx, 0, 720); + nav->highlight[1] = MPCLAMP(ev->u.highlight.sy, 0, 480); + nav->highlight[2] = MPCLAMP(ev->u.highlight.ex, 0, 720); + nav->highlight[3] = MPCLAMP(ev->u.highlight.ey, 0, 480); + nav->hi_visible = ev->u.highlight.display; + mpctx->osd->highlight_priv = mpctx; + osd_changed(mpctx->osd, OSDTYPE_NAV_HIGHLIGHT); + break; + default: ; // ignore + } + talloc_free(ev); + } + // E.g. keep displaying still frames + if (mpctx->stop_play == AT_END_OF_FILE && !nav->nav_eof) + mpctx->stop_play = KEEP_PLAYING; +} + +// Render "fake" highlights, because using actual dvd sub highlight elements +// is too hard, and would require extra libavcodec to begin with. +// Note: a proper solution would introduce something like +// SD_CTRL_APPLY_DVDNAV, which would crop the vobsub frame, +// and apply the current CLUT. +void mp_nav_get_highlight(struct osd_state *osd, struct mp_osd_res res, + struct sub_bitmaps *out_imgs) +{ + struct MPContext *mpctx = osd->highlight_priv; + struct mp_nav_state *nav = mpctx ? mpctx->nav_state : NULL; + if (!nav) + return; + struct sub_bitmap *sub = nav->hi_elem; + if (!sub) + sub = talloc_zero(nav, struct sub_bitmap); + + nav->hi_elem = sub; + int sizes[2] = {0}; + if (mpctx->d_sub) + sub_control(mpctx->d_sub, SD_CTRL_GET_RESOLUTION, sizes); + if (sizes[0] < 1 || sizes[1] < 1) { + struct mp_image_params vid = {0}; + if (mpctx->d_video) + vid = mpctx->d_video->decoder_output; + sizes[0] = vid.w; + sizes[1] = vid.h; + } + if (sizes[0] < 1 || sizes[1] < 1) + return; + if (sizes[0] != nav->subsize[0] || sizes[1] != nav->subsize[1]) { + talloc_free(sub->bitmap); + sub->bitmap = talloc_array(sub, uint32_t, sizes[0] * sizes[1]); + memset(sub->bitmap, 0x80, talloc_get_size(sub->bitmap)); + } + + sub->x = nav->highlight[0]; + sub->y = nav->highlight[1]; + sub->w = MPMAX(nav->highlight[2] - sub->x, 0); + sub->h = MPMAX(nav->highlight[3] - sub->y, 0); + sub->stride = sub->w; + out_imgs->format = SUBBITMAP_RGBA; + out_imgs->parts = sub; + out_imgs->num_parts = sub->w > 0 && sub->h > 0 && nav->hi_visible; + osd_rescale_bitmaps(out_imgs, sizes[0], sizes[1], res, -1); +} diff --git a/mpvcore/player/loadfile.c b/mpvcore/player/loadfile.c index 00b6a4b97c..72d17086f9 100644 --- a/mpvcore/player/loadfile.c +++ b/mpvcore/player/loadfile.c @@ -477,7 +477,6 @@ void add_demuxer_tracks(struct MPContext *mpctx, struct demuxer *demuxer) static void add_dvd_tracks(struct MPContext *mpctx) { -#if HAVE_DVDREAD struct demuxer *demuxer = mpctx->demuxer; struct stream *stream = demuxer->stream; struct stream_dvd_info_req info; @@ -500,7 +499,6 @@ static void add_dvd_tracks(struct MPContext *mpctx) } } demuxer_enable_autoselect(demuxer); -#endif } // Result numerically higher => better match. 0 == no match. @@ -1078,6 +1076,9 @@ static void play_current_file(struct MPContext *mpctx) goto terminate_playback; } + // Must be called before enabling cache. + mp_nav_init(mpctx); + // CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts) int res = stream_enable_cache_percent(&mpctx->stream, opts->stream_cache_size, @@ -1090,9 +1091,9 @@ static void play_current_file(struct MPContext *mpctx) stream_set_capture_file(mpctx->stream, opts->stream_capture); -#if HAVE_DVBIN goto_reopen_demuxer: ; -#endif + + mp_nav_reset(mpctx); //============ Open DEMUXERS --- DETECT file type ======================= @@ -1201,10 +1202,8 @@ goto_reopen_demuxer: ; else dir = DVB_CHANNEL_LOWER; - if (dvb_step_channel(mpctx->stream, dir)) { - mpctx->stop_play = PT_NEXT_ENTRY; - mpctx->dvbin_reopen = 1; - } + if (dvb_step_channel(mpctx->stream, dir)) + mpctx->stop_play = PT_RELOAD_DEMUXER; } #endif goto terminate_playback; @@ -1268,19 +1267,18 @@ goto_reopen_demuxer: ; MP_VERBOSE(mpctx, "EOF code: %d \n", mpctx->stop_play); -#if HAVE_DVBIN - if (mpctx->dvbin_reopen) { - mpctx->stop_play = 0; + if (mpctx->stop_play == PT_RELOAD_DEMUXER) { + mpctx->stop_play = KEEP_PLAYING; uninit_player(mpctx, INITIALIZED_ALL - (INITIALIZED_PLAYBACK | INITIALIZED_STREAM | INITIALIZED_GETCH2 | (opts->fixed_vo ? INITIALIZED_VO : 0))); - mpctx->dvbin_reopen = 0; goto goto_reopen_demuxer; } -#endif terminate_playback: // don't jump here after ao/vo/getch initialization! + mp_nav_destroy(mpctx); + if (mpctx->stop_play == KEEP_PLAYING) mpctx->stop_play = AT_END_OF_FILE; diff --git a/mpvcore/player/mp_core.h b/mpvcore/player/mp_core.h index 607000cd5c..9827387e2c 100644 --- a/mpvcore/player/mp_core.h +++ b/mpvcore/player/mp_core.h @@ -47,6 +47,7 @@ enum stop_play_reason { PT_CURRENT_ENTRY, // prepare to play mpctx->playlist->current PT_STOP, // stop playback, clear playlist PT_RESTART, // restart previous file + PT_RELOAD_DEMUXER, // restart playback, but keep stream open PT_QUIT, // stop playback, quit player }; @@ -310,7 +311,6 @@ typedef struct MPContext { struct ass_library *ass_library; int last_dvb_step; - int dvbin_reopen; bool paused; // step this many frames, then pause @@ -329,6 +329,7 @@ typedef struct MPContext { struct command_ctx *command_ctx; struct encode_lavc_context *encode_lavc_ctx; struct lua_ctx *lua_ctx; + struct mp_nav_state *nav_state; } MPContext; // audio.c @@ -354,6 +355,13 @@ void mp_write_watch_later_conf(struct MPContext *mpctx); struct playlist_entry *mp_resume_playlist(struct playlist *playlist, struct MPOpts *opts); +// dvdnav.c +void mp_nav_init(struct MPContext *mpctx); +void mp_nav_reset(struct MPContext *mpctx); +void mp_nav_destroy(struct MPContext *mpctx); +void mp_nav_user_input(struct MPContext *mpctx, char *command); +void mp_handle_nav(struct MPContext *mpctx); + // loadfile.c void uninit_player(struct MPContext *mpctx, unsigned int mask); struct track *mp_add_subtitles(struct MPContext *mpctx, char *filename); diff --git a/mpvcore/player/playloop.c b/mpvcore/player/playloop.c index 359e38058e..b2eae3807c 100644 --- a/mpvcore/player/playloop.c +++ b/mpvcore/player/playloop.c @@ -1234,9 +1234,10 @@ void run_playloop(struct MPContext *mpctx) }, true); } else mpctx->stop_play = AT_END_OF_FILE; - sleeptime = 0; } + mp_handle_nav(mpctx); + if (!mpctx->stop_play && !mpctx->restart_playback) { // If no more video is available, one frame means one playloop iteration. @@ -1269,6 +1270,8 @@ void run_playloop(struct MPContext *mpctx) if (!mpctx->stop_play) { double audio_sleep = 9; + if (mpctx->restart_playback) + sleeptime = 0; if (mpctx->d_audio && !mpctx->paused) { if (mpctx->ao->untimed) { if (!video_left) diff --git a/mpvcore/player/sub.c b/mpvcore/player/sub.c index 2c6ec1dfc5..d3ce466121 100644 --- a/mpvcore/player/sub.c +++ b/mpvcore/player/sub.c @@ -133,7 +133,6 @@ void update_subtitles(struct MPContext *mpctx) static void set_dvdsub_fake_extradata(struct dec_sub *dec_sub, struct stream *st, int width, int height) { -#if HAVE_DVDREAD if (!st) return; @@ -169,7 +168,6 @@ static void set_dvdsub_fake_extradata(struct dec_sub *dec_sub, struct stream *st sub_set_extradata(dec_sub, s, strlen(s)); talloc_free(s); -#endif } void reinit_subs(struct MPContext *mpctx) diff --git a/old-configure b/old-configure index 45e7add61b..63eaf1fd03 100755 --- a/old-configure +++ b/old-configure @@ -319,6 +319,7 @@ Optional features: --disable-vcd disable VCD support [autodetect] --disable-bluray disable Blu-ray support [autodetect] --disable-dvdread disable libdvdread [autodetect] + --disable-dvdnav disable libdvdnav [autodetect] --disable-enca disable ENCA charset oracle library [autodetect] --disable-pthreads disable Posix threads support [autodetect] --disable-libass disable subtitle rendering with libass [autodetect] @@ -451,6 +452,7 @@ _libbs2b=auto _vcd=auto _bluray=auto _dvdread=auto +_dvdnav=auto _lcms2=auto _xinerama=auto _vm=auto @@ -639,6 +641,8 @@ for ac_option do --disable-bluray) _bluray=no ;; --enable-dvdread) _dvdread=yes ;; --disable-dvdread) _dvdread=no ;; + --enable-dvdnav) _dvdnav=yes ;; + --disable-dvdnav) _dvdnav=no ;; --enable-lcms2) _lcms2=yes ;; --disable-lcms2) _lcms2=no ;; --enable-xinerama) _xinerama=yes ;; @@ -2467,6 +2471,21 @@ fi echores "$_dvdread" +echocheck "dvdnav" +if test "$_dvdnav" = auto ; then + _dvdnav=no + pkg_config_add 'dvdnav >= 4.2.0' && _dvdnav=yes +fi +if test "$_dvdnav" = yes ; then + def_dvdnav='#define HAVE_DVDNAV 1' + inputmodules="dvdnav $inputmodules" +else + def_dvdnav='#define HAVE_DVDNAV 0' + noinputmodules="dvdnav $noinputmodules" +fi +echores "$_dvdnav" + + echocheck "libcdio" if test "$_libcdio" = auto ; then _libcdio=no @@ -3249,6 +3268,7 @@ DSOUND = $_dsound WASAPI = $_wasapi DVBIN = $_dvbin DVDREAD = $_dvdread +DVDNAV = $_dvdnav GL = $_gl GL_COCOA = $_gl_cocoa GL_WIN32 = $_gl_win32 @@ -3396,6 +3416,7 @@ $def_arch_x86_64 $def_bluray $def_cdda $def_dvdread +$def_dvdnav $def_vcd diff --git a/old-makefile b/old-makefile index f6108bac67..31fa13dd43 100644 --- a/old-makefile +++ b/old-makefile @@ -33,6 +33,8 @@ SOURCES-$(DVBIN) += stream/dvb_tune.c \ stream/stream_dvb.c SOURCES-$(DVDREAD) += stream/stream_dvd.c \ stream/stream_dvd_common.c +SOURCES-$(DVDNAV) += stream/stream_dvdnav.c \ + stream/stream_dvd_common.c SOURCES-$(HAVE_SYS_MMAN_H) += audio/filter/af_export.c SOURCES-$(LADSPA) += audio/filter/af_ladspa.c @@ -215,6 +217,7 @@ SOURCES = audio/audio.c \ mpvcore/player/audio.c \ mpvcore/player/configfiles.c \ mpvcore/player/command.c \ + mpvcore/player/dvdnav.c \ mpvcore/player/loadfile.c \ mpvcore/player/main.c \ mpvcore/player/misc.c \ diff --git a/stream/cache.c b/stream/cache.c index 2f66ccedc3..930e2c4ba7 100644 --- a/stream/cache.c +++ b/stream/cache.c @@ -377,6 +377,7 @@ static bool control_needs_flush(int stream_ctrl) case STREAM_CTRL_SEEK_TO_TIME: case STREAM_CTRL_SEEK_TO_CHAPTER: case STREAM_CTRL_SET_ANGLE: + case STREAM_CTRL_SET_CURRENT_TITLE: return true; } return false; diff --git a/stream/stream.c b/stream/stream.c index 74715970af..b7c373b6d4 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -74,6 +74,7 @@ extern const stream_info_t stream_info_avdevice; extern const stream_info_t stream_info_file; extern const stream_info_t stream_info_ifo; extern const stream_info_t stream_info_dvd; +extern const stream_info_t stream_info_dvdnav; extern const stream_info_t stream_info_bluray; extern const stream_info_t stream_info_rar_filter; extern const stream_info_t stream_info_rar_entry; @@ -107,6 +108,9 @@ static const stream_info_t *const stream_list[] = { &stream_info_ifo, &stream_info_dvd, #endif +#if HAVE_DVDNAV + &stream_info_dvdnav, +#endif #if HAVE_LIBBLURAY &stream_info_bluray, #endif diff --git a/stream/stream.h b/stream/stream.h index 6d43f02a7c..6182d6414d 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -89,6 +89,7 @@ enum stream_ctrl { STREAM_CTRL_GET_NUM_TITLES, STREAM_CTRL_GET_LANG, STREAM_CTRL_GET_CURRENT_TITLE, + STREAM_CTRL_SET_CURRENT_TITLE, STREAM_CTRL_GET_CACHE_SIZE, STREAM_CTRL_GET_CACHE_FILL, STREAM_CTRL_GET_CACHE_IDLE, @@ -101,6 +102,8 @@ enum stream_ctrl { STREAM_CTRL_SET_CONTENTS, STREAM_CTRL_GET_METADATA, STREAM_CTRL_GET_BASE_FILENAME, + STREAM_CTRL_GET_NAV_EVENT, // struct mp_nav_event** + STREAM_CTRL_NAV_CMD, // struct mp_nav_cmd* }; struct stream_lang_req { diff --git a/stream/stream_dvdnav.c b/stream/stream_dvdnav.c new file mode 100644 index 0000000000..b6a5aae554 --- /dev/null +++ b/stream/stream_dvdnav.c @@ -0,0 +1,718 @@ +/* + * 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. + */ +#include + +#include "config.h" + +#include +#include +#include +#include +#include +#include + +#include + +#include "mpvcore/options.h" +#include "mpvcore/mp_msg.h" +#include "mpvcore/input/input.h" +#include "mpvcore/m_option.h" +#include "osdep/timer.h" +#include "stream.h" +#include "demux/demux.h" +#include "stream_dvdnav.h" +#include "video/out/vo.h" +#include "stream_dvd_common.h" + +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; + dvdnav_highlight_event_t hlev; + int still_length; // still frame duration + unsigned long next_event; // bitmask of events to return to player + bool suspended_read; + bool nav_enabled; + bool had_initial_vts; + + int track; + char *device; +}; + +#define OPT_BASE_STRUCT struct priv +static const m_option_t stream_opts_fields[] = { + OPT_INTRANGE("title", track, 0, 1, 99), + OPT_STRING("device", device, 0), + {0} +}; + +#define DNE(e) [e] = # e +static char *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), +}; + +static char *mp_nav_cmd_types[] = { + DNE(MP_NAV_CMD_NONE), + DNE(MP_NAV_CMD_ENABLE), + DNE(MP_NAV_CMD_DRAIN_OK), + DNE(MP_NAV_CMD_RESUME), + DNE(MP_NAV_CMD_MENU), + DNE(MP_NAV_CMD_MOUSE_POS), +}; + +static char *mp_nav_event_types[] = { + DNE(MP_NAV_EVENT_NONE), + DNE(MP_NAV_EVENT_RESET), + DNE(MP_NAV_EVENT_RESET_CLUT), + DNE(MP_NAV_EVENT_RESET_ALL), + DNE(MP_NAV_EVENT_DRAIN), + DNE(MP_NAV_EVENT_STILL_FRAME), + DNE(MP_NAV_EVENT_HIGHLIGHT), + DNE(MP_NAV_EVENT_MENU_MODE), + DNE(MP_NAV_EVENT_EOF), +}; + +#define LOOKUP_NAME(array, i) \ + (((i) >= 0 && (i) < MP_ARRAY_SIZE(array)) ? array[(i)] : "?") + +static void dvdnav_get_highlight(struct priv *priv, int display_mode) +{ + pci_t *pnavpci = NULL; + dvdnav_highlight_event_t *hlev = &(priv->hlev); + int btnum; + + if (!priv || !priv->dvdnav) + return; + + pnavpci = dvdnav_get_current_nav_pci(priv->dvdnav); + if (!pnavpci) + return; + + dvdnav_get_current_highlight(priv->dvdnav, &(hlev->buttonN)); + hlev->display = display_mode; /* show */ + + if (hlev->buttonN > 0 && pnavpci->hli.hl_gi.btn_ns > 0 && hlev->display) { + for (btnum = 0; btnum < pnavpci->hli.hl_gi.btn_ns; btnum++) { + btni_t *btni = &(pnavpci->hli.btnit[btnum]); + + if (hlev->buttonN == btnum + 1) { + hlev->sx = FFMIN(btni->x_start, btni->x_end); + hlev->ex = FFMAX(btni->x_start, btni->x_end); + hlev->sy = FFMIN(btni->y_start, btni->y_end); + hlev->ey = FFMAX(btni->y_start, btni->y_end); + + hlev->palette = (btni->btn_coln == 0) ? + 0 : pnavpci->hli.btn_colit.btn_coli[btni->btn_coln - 1][0]; + break; + } + } + } else { /* hide button or no button */ + hlev->sx = hlev->ex = 0; + hlev->sy = hlev->ey = 0; + hlev->palette = hlev->buttonN = 0; + } +} + +static inline int dvdnav_get_duration(int length) +{ + return (length == 255) ? 0 : length * 1000; +} + +static void handle_menu_input(stream_t *stream, const char *cmd) +{ + struct priv *priv = stream->priv; + dvdnav_t *nav = priv->dvdnav; + dvdnav_status_t status = DVDNAV_STATUS_ERR; + pci_t *pci = dvdnav_get_current_nav_pci(nav); + + mp_msg(MSGT_CPLAYER, MSGL_V, "DVDNAV: input '%s'\n", cmd); + + if (!pci) + return; + + if (strcmp(cmd, "up") == 0) { + status = dvdnav_upper_button_select(nav, pci); + } else if (strcmp(cmd, "down") == 0) { + status = dvdnav_lower_button_select(nav, pci); + } else if (strcmp(cmd, "left") == 0) { + status = dvdnav_left_button_select(nav, pci); + } else if (strcmp(cmd, "right") == 0) { + status = dvdnav_right_button_select(nav, pci); + } else if (strcmp(cmd, "menu") == 0) { + status = dvdnav_menu_call(nav, DVD_MENU_Root); + } else if (strcmp(cmd, "prev") == 0) { + int title = 0, part = 0; + dvdnav_current_title_info(nav, &title, &part); + if (title) + status = dvdnav_menu_call(nav, DVD_MENU_Part); + if (status != DVDNAV_STATUS_OK) + status = dvdnav_menu_call(nav, DVD_MENU_Title); + if (status != DVDNAV_STATUS_OK) + status = dvdnav_menu_call(nav, DVD_MENU_Root); + } else if (strcmp(cmd, "select") == 0) { + status = dvdnav_button_activate(nav, pci); + } else if (strcmp(cmd, "mouse") == 0) { + status = dvdnav_mouse_activate(nav, pci, priv->mousex, priv->mousey); + } else { + mp_msg(MSGT_CPLAYER, MSGL_V, "Unknown DVDNAV command: '%s'\n", cmd); + } +} + +static void handle_mouse_pos(stream_t *stream, int x, int y) +{ + struct priv *priv = stream->priv; + dvdnav_t *nav = priv->dvdnav; + pci_t *pci = dvdnav_get_current_nav_pci(nav); + + if (!pci) + return; + + dvdnav_mouse_select(nav, pci, x, y); + priv->mousex = x; + priv->mousey = y; +} + +/** + * \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 void handle_cmd(stream_t *s, struct mp_nav_cmd *ev) +{ + struct priv *priv = s->priv; + mp_msg(MSGT_CPLAYER, MSGL_V, "DVDNAV: input '%s'\n", + LOOKUP_NAME(mp_nav_cmd_types, ev->event)); + switch (ev->event) { + case MP_NAV_CMD_ENABLE: + priv->nav_enabled = true; + break; + case MP_NAV_CMD_DRAIN_OK: + dvdnav_wait_skip(priv->dvdnav); + break; + case MP_NAV_CMD_RESUME: + priv->suspended_read = false; + break; + case MP_NAV_CMD_MENU: + handle_menu_input(s, ev->u.menu.action); + break; + case MP_NAV_CMD_MOUSE_POS: + handle_mouse_pos(s, ev->u.mouse_pos.x, ev->u.mouse_pos.y); + break; + } + +} + +static void fill_next_event(stream_t *s, struct mp_nav_event **ret) +{ + struct priv *priv = s->priv; + struct mp_nav_event e = {0}; + for (int n = 0; n < 30; n++) { + if (priv->next_event & (1 << n)) { + priv->next_event &= ~(1 << n); + e.event = n; + switch (e.event) { + case MP_NAV_EVENT_HIGHLIGHT: { + dvdnav_highlight_event_t hlev = priv->hlev; + e.u.highlight.display = hlev.display; + e.u.highlight.sx = hlev.sx; + e.u.highlight.sy = hlev.sy; + e.u.highlight.ex = hlev.ex; + e.u.highlight.ey = hlev.ey; + e.u.highlight.palette = hlev.palette; + break; + } + case MP_NAV_EVENT_MENU_MODE: + e.u.menu_mode.enable = !dvdnav_is_domain_vts(priv->dvdnav); + break; + } + break; + } + } + if (e.event) { + *ret = talloc(NULL, struct mp_nav_event); + **ret = e; + + mp_msg(MSGT_CPLAYER, MSGL_V, "DVDNAV: player event '%s'\n", + LOOKUP_NAME(mp_nav_event_types, e.event)); + } +} + +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) { + if (priv->suspended_read) + return -1; + + int len = -1; + int event = DVDNAV_NOP; + if (dvdnav_get_next_block(dvdnav, buf, &event, &len) != DVDNAV_STATUS_OK) + { + mp_msg(MSGT_CPLAYER, MSGL_ERR, + "Error getting next block from DVD %d (%s)\n", + event, dvdnav_err_to_string(dvdnav)); + return 0; + } + if (1||event != DVDNAV_BLOCK_OK) { + const char *name = LOOKUP_NAME(mp_dvdnav_events, event); + mp_msg(MSGT_CPLAYER, MSGL_V, "DVDNAV: event %s (%d).\n", name, event); + dvdnav_get_highlight(priv, 1); + } + switch (event) { + case DVDNAV_BLOCK_OK: + return len; + case DVDNAV_STOP: { + priv->next_event |= 1 << MP_NAV_EVENT_EOF; + return 0; + } + case DVDNAV_NAV_PACKET: + break; + case DVDNAV_STILL_FRAME: { + dvdnav_still_event_t *still_event = (dvdnav_still_event_t *) buf; + priv->still_length = still_event->length; + mp_msg(MSGT_CPLAYER, MSGL_V, "len=%d\n", priv->still_length); + /* set still frame duration */ + priv->duration = dvdnav_get_duration(priv->still_length); + if (priv->still_length <= 1) { + pci_t *pnavpci = dvdnav_get_current_nav_pci(dvdnav); + priv->duration = mp_dvdtimetomsec(&pnavpci->pci_gi.e_eltm); + } + if (priv->nav_enabled) { + priv->next_event |= 1 << MP_NAV_EVENT_STILL_FRAME; + } else { + dvdnav_still_skip(dvdnav); + } + return 0; + } + case DVDNAV_WAIT: { + if (priv->nav_enabled) { + priv->next_event |= 1 << MP_NAV_EVENT_DRAIN; + } else { + dvdnav_wait_skip(dvdnav); + } + return 0; + } + case DVDNAV_HIGHLIGHT: { + dvdnav_get_highlight(priv, 1); + priv->next_event |= 1 << MP_NAV_EVENT_HIGHLIGHT; + 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_msg(MSGT_CPLAYER, MSGL_INFO, "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; + } + priv->next_event |= 1 << MP_NAV_EVENT_RESET; + priv->next_event |= 1 << MP_NAV_EVENT_RESET_ALL; + if (dvdnav_current_title_info(dvdnav, &tit, &part) == DVDNAV_STATUS_OK) + { + mp_msg(MSGT_CPLAYER, MSGL_V, "DVDNAV, NEW TITLE %d\n", tit); + dvdnav_get_highlight(priv, 0); + if (priv->title > 0 && tit != priv->title) { + priv->next_event |= 1 << MP_NAV_EVENT_EOF;; + mp_msg(MSGT_CPLAYER, MSGL_WARN, "Requested title not found\n"); + return 0; + } + } + if (priv->nav_enabled) + priv->suspended_read = true; + break; + } + case DVDNAV_CELL_CHANGE: { + dvdnav_cell_change_event_t *ev = (dvdnav_cell_change_event_t *)buf; + uint32_t nextstill; + + priv->next_event |= 1 << MP_NAV_EVENT_RESET; + priv->next_event |= 1 << MP_NAV_EVENT_MENU_MODE; + if (ev->pgc_length) + priv->duration = ev->pgc_length / 90; + + nextstill = dvdnav_get_next_still_flag(dvdnav); + if (nextstill) { + priv->duration = dvdnav_get_duration(nextstill); + priv->still_length = nextstill; + if (priv->still_length <= 1) { + pci_t *pnavpci = dvdnav_get_current_nav_pci(dvdnav); + priv->duration = mp_dvdtimetomsec(&pnavpci->pci_gi.e_eltm); + } + } + + dvdnav_get_highlight(priv, 1); + break; + } + case DVDNAV_SPU_CLUT_CHANGE: { + memcpy(priv->spu_clut, buf, 16 * sizeof(uint32_t)); + priv->spu_clut_valid = true; + priv->next_event |= 1 << MP_NAV_EVENT_RESET_CLUT; + 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_SEEK_TO_CHAPTER: { + int chap = *(unsigned int *)arg + 1; + + if (chap < 1) + break; + if (dvdnav_current_title_info(dvdnav, &tit, &part) != DVDNAV_STATUS_OK) + break; + if (dvdnav_part_play(dvdnav, tit, chap) != DVDNAV_STATUS_OK) + break; + return 1; + } + 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; + *(unsigned int *)arg = part; + 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; + if (chapter < 0 || chapter >= n) + break; + *ch = parts[chapter] / 90000.0; + free(parts); + return 1; + } + case STREAM_CTRL_GET_CURRENT_CHAPTER: { + if (dvdnav_current_title_info(dvdnav, &tit, &part) != DVDNAV_STATUS_OK) + break; + *(unsigned int *)arg = part - 1; + 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_CURRENT_TITLE: { + if (dvdnav_current_title_info(dvdnav, &tit, &part) != DVDNAV_STATUS_OK) + break; + *((unsigned int *) arg) = tit; + return STREAM_OK; + } + case STREAM_CTRL_SET_CURRENT_TITLE: { + int title = *((unsigned int *) arg); + if (dvdnav_title_play(priv->dvdnav, title) != DVDNAV_STATUS_OK) + break; + return STREAM_OK; + } + case STREAM_CTRL_SEEK_TO_TIME: { + uint64_t tm = (uint64_t) (*((double *)arg) * 90000); + if (dvdnav_time_search(dvdnav, tm) == DVDNAV_STATUS_OK) + return 1; + break; + } + 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_MANAGES_TIMELINE: + 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_NAV_EVENT: { + struct mp_nav_event **ev = arg; + if (ev) + fill_next_event(stream, ev); + return STREAM_OK; + } + case STREAM_CTRL_NAV_CMD: { + handle_cmd(stream, (struct mp_nav_cmd *)arg); + 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; + dvd_set_speed(priv->filename, -1); +} + +static struct priv *new_dvdnav_stream(struct priv *priv, char *filename) +{ + const char *title_str; + + if (!filename) + return NULL; + + if (!(priv->filename = strdup(filename))) + return NULL; + + dvd_set_speed(priv->filename, 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; + + /* turn off dvdnav caching */ + dvdnav_set_readahead_flag(priv->dvdnav, 0); + if (dvdnav_set_PGC_positioning_flag(priv->dvdnav, 1) != DVDNAV_STATUS_OK) + mp_msg(MSGT_OPEN, MSGL_ERR, + "stream_dvdnav, failed to set PGC positioning\n"); + /* report the title?! */ + if (dvdnav_get_title_string(priv->dvdnav, &title_str) == DVDNAV_STATUS_OK) + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_DVD_VOLUME_ID=%s\n", title_str); + + return priv; +} + +static int open_s(stream_t *stream, int mode) +{ + struct priv *priv, *p; + priv = p = stream->priv; + char *filename; + + if (p->device) + filename = p->device; + else if (dvd_device) + filename = dvd_device; + else + filename = DEFAULT_DVD_DEVICE; + if (!new_dvdnav_stream(priv, filename)) { + mp_tmsg(MSGT_OPEN, MSGL_ERR, "Couldn't open DVD device: %s\n", + filename); + return STREAM_UNSUPPORTED; + } + + if (p->track > 0) { + priv->title = p->track; + if (dvdnav_title_play(priv->dvdnav, p->track) != DVDNAV_STATUS_OK) { + mp_msg(MSGT_OPEN, MSGL_FATAL, + "dvdnav_stream, couldn't select title %d, error '%s'\n", + p->track, dvdnav_err_to_string(priv->dvdnav)); + return STREAM_UNSUPPORTED; + } + mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_DVD_CURRENT_TITLE=%d\n", p->track); + } else if (p->track == 0) { + if (dvdnav_menu_call(priv->dvdnav, DVD_MENU_Root) != DVDNAV_STATUS_OK) + dvdnav_menu_call(priv->dvdnav, DVD_MENU_Title); + } + if (dvd_angle > 1) + dvdnav_angle_change(priv->dvdnav, dvd_angle); + + stream->sector_size = 2048; + stream->flags = STREAM_READ; + stream->fill_buffer = fill_buffer; + stream->control = control; + stream->close = stream_dvdnav_close; + stream->type = STREAMTYPE_DVD; + stream->demuxer = "lavf"; + stream->lavf_type = "mpeg"; + + if (!stream->pos && p->track > 0) + mp_msg(MSGT_OPEN, MSGL_ERR, "INIT ERROR: couldn't get init pos %s\r\n", + dvdnav_err_to_string(priv->dvdnav)); + + mp_msg(MSGT_OPEN, MSGL_INFO, "Remember to disable mpv's cache when " + "playing dvdnav:// streams (adding -no-cache to your command line)\n"); + + return STREAM_OK; +} + +const stream_info_t stream_info_dvdnav = { + .name = "dvdnav", + .open = open_s, + .protocols = (const char*[]){ "dvdnav", NULL }, + .priv_size = sizeof(struct priv), + .options = stream_opts_fields, + .url_options = (const char*[]){ + "hostname=title", + "filename=device", + NULL + }, +}; diff --git a/stream/stream_dvdnav.h b/stream/stream_dvdnav.h new file mode 100644 index 0000000000..cc8163e015 --- /dev/null +++ b/stream/stream_dvdnav.h @@ -0,0 +1,81 @@ +/* + * 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. + */ + +#ifndef MPLAYER_STREAM_DVDNAV_H +#define MPLAYER_STREAM_DVDNAV_H + +#include +#include +#include "stream.h" + +// Sent from stream to player. +// Note: order matters somewhat (stream_dvdnav sends them in numeric order) +enum mp_nav_event_type { + MP_NAV_EVENT_NONE, + MP_NAV_EVENT_RESET, // reinitialize some things + MP_NAV_EVENT_RESET_CLUT, // reinitialize sub palette + MP_NAV_EVENT_RESET_ALL, // reinitialize all things + MP_NAV_EVENT_DRAIN, // reply with MP_NAV_CMD_DRAIN_OK + MP_NAV_EVENT_STILL_FRAME, // keep displaying current frame + MP_NAV_EVENT_HIGHLIGHT, // highlight changed + MP_NAV_EVENT_MENU_MODE, // menu mode on/off + MP_NAV_EVENT_EOF, // it's over +}; + +struct mp_nav_event { + enum mp_nav_event_type event; + union { + /* + struct { + int seconds; + } still_frame; + */ + struct { + int display; + int sx, sy, ex, ey; + uint32_t palette; + } highlight; + struct { + bool enable; + } menu_mode; + } u; +}; + +// Sent from player to stream. +enum mp_nav_cmd_type { + MP_NAV_CMD_NONE, + MP_NAV_CMD_ENABLE, // enable interactive navigation + MP_NAV_CMD_DRAIN_OK, // acknowledge EVENT_DRAIN + MP_NAV_CMD_RESUME, + MP_NAV_CMD_MENU, + MP_NAV_CMD_MOUSE_POS, +}; + +struct mp_nav_cmd { + enum mp_nav_cmd_type event; + union { + struct { + const char *action; + } menu; + struct { + int x, y; + } mouse_pos; + } u; +}; + +#endif /* MPLAYER_STREAM_DVDNAV_H */ diff --git a/sub/dec_sub.h b/sub/dec_sub.h index 4fa62d7b97..36b947fffa 100644 --- a/sub/dec_sub.h +++ b/sub/dec_sub.h @@ -19,6 +19,7 @@ struct sd; enum sd_ctrl { SD_CTRL_SUB_STEP, SD_CTRL_SET_VIDEO_PARAMS, + SD_CTRL_GET_RESOLUTION, }; struct dec_sub *sub_create(struct MPOpts *opts); diff --git a/sub/osd.c b/sub/osd.c index 66b79f7bb8..ab3764cb00 100644 --- a/sub/osd.c +++ b/sub/osd.c @@ -167,6 +167,8 @@ static void render_object(struct osd_state *osd, struct osd_object *obj, *out_imgs = osd->external2; osd->external2.bitmap_id = osd->external2.bitmap_pos_id = 0; } + } else if (obj->type == OSDTYPE_NAV_HIGHLIGHT) { + mp_nav_get_highlight(osd, obj->vo_res, out_imgs); } else { osd_object_get_bitmaps(osd, obj, out_imgs); } diff --git a/sub/osd.h b/sub/osd.h index fc2b76df00..75536f6692 100644 --- a/sub/osd.h +++ b/sub/osd.h @@ -86,6 +86,8 @@ enum mp_osdtype { OSDTYPE_SUB, OSDTYPE_SUBTEXT, + OSDTYPE_NAV_HIGHLIGHT, // dvdnav fake highlights + OSDTYPE_PROGBAR, OSDTYPE_OSD, @@ -148,6 +150,8 @@ struct osd_state { struct sub_bitmaps external2; // OSDTYPE_SUB struct dec_sub *dec_sub; + // OSDTYPE_NAV_HIGHLIGHT + void *highlight_priv; struct MPOpts *opts; @@ -244,4 +248,8 @@ void osd_get_function_sym(char *buffer, size_t buffer_size, int osd_function); void osd_init_backend(struct osd_state *osd); void osd_destroy_backend(struct osd_state *osd); +// defined in player +void mp_nav_get_highlight(struct osd_state *osd, struct mp_osd_res res, + struct sub_bitmaps *out_imgs); + #endif /* MPLAYER_SUB_H */ diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index 724a4fe77c..da8a07e48e 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -83,6 +83,14 @@ static void guess_resolution(enum AVCodecID type, int *w, int *h) } } +static void get_resolution(struct sd *sd, int wh[2]) +{ + struct sd_lavc_priv *priv = sd->priv; + wh[0] = priv->avctx->width; + wh[1] = priv->avctx->height; + guess_resolution(priv->avctx->codec_id, &wh[0], &wh[1]); +} + static int init(struct sd *sd) { struct sd_lavc_priv *priv = talloc_zero(NULL, struct sd_lavc_priv); @@ -216,9 +224,7 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts, if (!priv->outbitmaps) priv->outbitmaps = talloc_size(priv, size); memcpy(priv->outbitmaps, priv->inbitmaps, size); - int inw = priv->avctx->width; - int inh = priv->avctx->height; - guess_resolution(priv->avctx->codec_id, &inw, &inh); + res->parts = priv->outbitmaps; res->num_parts = priv->count; if (priv->bitmaps_changed) @@ -234,7 +240,9 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts, (priv->video_params.d_w / (double)priv->video_params.d_h) / (priv->video_params.w / (double)priv->video_params.h); } - osd_rescale_bitmaps(res, inw, inh, d, video_par); + int insize[2]; + get_resolution(sd, insize); + osd_rescale_bitmaps(res, insize[0], insize[1], d, video_par); } static void reset(struct sd *sd) @@ -264,6 +272,9 @@ static int control(struct sd *sd, enum sd_ctrl cmd, void *arg) case SD_CTRL_SET_VIDEO_PARAMS: priv->video_params = *(struct mp_image_params *)arg; return CONTROL_OK; + case SD_CTRL_GET_RESOLUTION: + get_resolution(sd, arg); + return CONTROL_OK; default: return CONTROL_UNKNOWN; } diff --git a/wscript b/wscript index 0da79b484c..deac5e8373 100644 --- a/wscript +++ b/wscript @@ -251,6 +251,10 @@ If you really mean to compile without libass support use --disable-libass." 'name': '--dvdread', 'desc': 'dvdread support', 'func': check_pkg_config('dvdread', '>= 4.1.0'), + }, { + 'name': '--dvdnav', + 'desc': 'dvdnav support', + 'func': check_pkg_config('dvdnav', '>= 4.2.0'), }, { 'name': '--cdda', 'desc': 'cdda support (libcdio)', diff --git a/wscript_build.py b/wscript_build.py index a15c5c161a..a5f92b1f9f 100644 --- a/wscript_build.py +++ b/wscript_build.py @@ -169,6 +169,7 @@ def build(ctx): ( "mpvcore/player/audio.c" ), ( "mpvcore/player/command.c" ), ( "mpvcore/player/configfiles.c" ), + ( "mpvcore/player/dvdnav.c" ), ( "mpvcore/player/loadfile.c" ), ( "mpvcore/player/main.c" ), ( "mpvcore/player/misc.c" ), @@ -239,6 +240,7 @@ def build(ctx): ( "stream/stream_dvb.c", "dvbin" ), ( "stream/stream_dvd.c", "dvdread" ), ( "stream/stream_dvd_common.c", "dvdread" ), + ( "stream/stream_dvdnav.c", "dvdnav" ), ( "stream/stream_edl.c" ), ( "stream/stream_file.c" ), ( "stream/stream_lavf.c" ), -- cgit v1.2.3