summaryrefslogtreecommitdiffstats
path: root/mpvcore
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-12 01:44:28 +0100
committerwm4 <wm4@nowhere>2013-12-12 01:46:45 +0100
commit053044741713eddc4aea024fb0c175aa01fc092d (patch)
treebdf12e75b406696c19519649a4ba32d0e170e8f0 /mpvcore
parent76ce5434b2716abf063b6d581fe2930825cdecab (diff)
downloadmpv-053044741713eddc4aea024fb0c175aa01fc092d.tar.bz2
mpv-053044741713eddc4aea024fb0c175aa01fc092d.tar.xz
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?
Diffstat (limited to 'mpvcore')
-rw-r--r--mpvcore/input/input.c2
-rw-r--r--mpvcore/input/input.h2
-rw-r--r--mpvcore/options.c2
-rw-r--r--mpvcore/player/command.c10
-rw-r--r--mpvcore/player/configfiles.c2
-rw-r--r--mpvcore/player/dvdnav.c207
-rw-r--r--mpvcore/player/loadfile.c24
-rw-r--r--mpvcore/player/mp_core.h10
-rw-r--r--mpvcore/player/playloop.c5
-rw-r--r--mpvcore/player/sub.c2
10 files changed, 243 insertions, 23 deletions
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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <limits.h>
+#include <assert.h>
+
+#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)