mplayer: attempt to make playback resume work with DVD/BD

The problem with DVD/BD and playback resume is that most often, the
filename is just "dvd://", while the actual path to the DVD disk image
is given with --dvd-device. But playback resume works on the filename
only.

Add a pretty bad hack that includes the path to the disk image if the
filename starts with dvd://, and the same for BD respectively. (It's a
bad hack, but I want to go to bed, so here we go. I might revert or
improve it later, depending on user feedback.)

We have to cleanup the global variable mess around the dvd_device.
Ideally, this should go into MPOpts, but it isn't yet. Make the code
paths in mplayer.c take MPOpts anyway.
This commit is contained in:
wm4 2013-09-22 03:04:57 +02:00
parent b0f7a26f1a
commit cc7f8ee620
8 changed files with 27 additions and 19 deletions

View File

@ -2411,7 +2411,8 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
talloc_free(pl); talloc_free(pl);
if (!append && mpctx->playlist->first) { if (!append && mpctx->playlist->first) {
struct playlist_entry *e = mp_resume_playlist(mpctx->playlist); struct playlist_entry *e =
mp_resume_playlist(mpctx->playlist, opts);
mp_set_playlist_entry(mpctx, e ? e : mpctx->playlist->first); mp_set_playlist_entry(mpctx, e ? e : mpctx->playlist->first);
} }
} else { } else {

View File

@ -336,7 +336,8 @@ struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction,
int mp_get_cache_percent(struct MPContext *mpctx); int mp_get_cache_percent(struct MPContext *mpctx);
void mp_write_watch_later_conf(struct MPContext *mpctx); void mp_write_watch_later_conf(struct MPContext *mpctx);
void mp_set_playlist_entry(struct MPContext *mpctx, struct playlist_entry *e); void mp_set_playlist_entry(struct MPContext *mpctx, struct playlist_entry *e);
struct playlist_entry *mp_resume_playlist(struct playlist *pl); struct playlist_entry *mp_resume_playlist(struct playlist *playlist,
struct MPOpts *opts);
void mp_force_video_refresh(struct MPContext *mpctx); void mp_force_video_refresh(struct MPContext *mpctx);
void mp_print_version(int always); void mp_print_version(int always);

View File

@ -777,17 +777,28 @@ static void load_per_file_config(m_config_t *conf, const char * const file,
#define MP_WATCH_LATER_CONF "watch_later" #define MP_WATCH_LATER_CONF "watch_later"
static char *get_playback_resume_config_filename(const char *fname) static char *get_playback_resume_config_filename(const char *fname,
struct MPOpts *opts)
{ {
char *res = NULL; char *res = NULL;
void *tmp = talloc_new(NULL); void *tmp = talloc_new(NULL);
const char *realpath = fname; const char *realpath = fname;
if (!mp_is_url(bstr0(fname))) { bstr bfname = bstr0(fname);
if (!mp_is_url(bfname)) {
char *cwd = mp_getcwd(tmp); char *cwd = mp_getcwd(tmp);
if (!cwd) if (!cwd)
goto exit; goto exit;
realpath = mp_path_join(tmp, bstr0(cwd), bstr0(fname)); realpath = mp_path_join(tmp, bstr0(cwd), bstr0(fname));
} }
#ifdef CONFIG_DVDREAD
if (bstr_startswith0(bfname, "dvd://"))
realpath = talloc_asprintf(tmp, "%s - %s", realpath, dvd_device);
#endif
#ifdef CONFIG_LIBBLURAY
if (bstr_startswith0(bfname, "br://") || bstr_startswith0(bfname, "bd://") ||
bstr_startswith0(bfname, "bluray://"))
realpath = talloc_asprintf(tmp, "%s - %s", realpath, bluray_device);
#endif
uint8_t md5[16]; uint8_t md5[16];
av_md5_sum(md5, realpath, strlen(realpath)); av_md5_sum(md5, realpath, strlen(realpath));
char *conf = talloc_strdup(tmp, ""); char *conf = talloc_strdup(tmp, "");
@ -853,7 +864,8 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
mk_config_dir(MP_WATCH_LATER_CONF); mk_config_dir(MP_WATCH_LATER_CONF);
char *conffile = get_playback_resume_config_filename(mpctx->filename); char *conffile = get_playback_resume_config_filename(mpctx->filename,
mpctx->opts);
talloc_steal(tmp, conffile); talloc_steal(tmp, conffile);
if (!conffile) if (!conffile)
goto exit; goto exit;
@ -880,7 +892,7 @@ exit:
static void load_playback_resume(m_config_t *conf, const char *file) static void load_playback_resume(m_config_t *conf, const char *file)
{ {
char *fname = get_playback_resume_config_filename(file); char *fname = get_playback_resume_config_filename(file, conf->optstruct);
if (fname && mp_path_exists(fname)) { if (fname && mp_path_exists(fname)) {
// Never apply the saved start position to following files // Never apply the saved start position to following files
m_config_backup_opt(conf, "start"); m_config_backup_opt(conf, "start");
@ -897,10 +909,11 @@ static void load_playback_resume(m_config_t *conf, const char *file)
// resume file for them, this is simpler, and also has the nice property // resume file for them, this is simpler, and also has the nice property
// that appending to a playlist doesn't interfere with resuming (especially // that appending to a playlist doesn't interfere with resuming (especially
// if the playlist comes from the command line). // if the playlist comes from the command line).
struct playlist_entry *mp_resume_playlist(struct playlist *playlist) struct playlist_entry *mp_resume_playlist(struct playlist *playlist,
struct MPOpts *opts)
{ {
for (struct playlist_entry *e = playlist->first; e; e = e->next) { for (struct playlist_entry *e = playlist->first; e; e = e->next) {
char *conf = get_playback_resume_config_filename(e->filename); char *conf = get_playback_resume_config_filename(e->filename, opts);
bool exists = conf && mp_path_exists(conf); bool exists = conf && mp_path_exists(conf);
talloc_free(conf); talloc_free(conf);
if (exists) if (exists)
@ -4892,7 +4905,7 @@ static int mpv_main(int argc, char *argv[])
if (opts->shuffle) if (opts->shuffle)
playlist_shuffle(mpctx->playlist); playlist_shuffle(mpctx->playlist);
mpctx->playlist->current = mp_resume_playlist(mpctx->playlist); mpctx->playlist->current = mp_resume_playlist(mpctx->playlist, opts);
if (!mpctx->playlist->current) if (!mpctx->playlist->current)
mpctx->playlist->current = mpctx->playlist->first; mpctx->playlist->current = mpctx->playlist->first;

View File

@ -53,8 +53,6 @@ extern char *lirc_configfile;
extern int mp_msg_color; extern int mp_msg_color;
extern int mp_msg_module; extern int mp_msg_module;
extern int dvd_speed; /* stream/stream_dvd.c */
/* defined in demux: */ /* defined in demux: */
extern const m_option_t demux_rawaudio_opts[]; extern const m_option_t demux_rawaudio_opts[];
extern const m_option_t demux_rawvideo_opts[]; extern const m_option_t demux_rawvideo_opts[];
@ -178,8 +176,6 @@ static const m_option_t scaler_filter_conf[]={
{NULL, NULL, 0, 0, 0, 0, NULL} {NULL, NULL, 0, 0, 0, 0, NULL}
}; };
extern char *dvd_device, *cdrom_device;
extern double mf_fps; extern double mf_fps;
extern char * mf_type; extern char * mf_type;
extern const struct m_obj_list vf_obj_list; extern const struct m_obj_list vf_obj_list;

View File

@ -257,8 +257,11 @@ int stream_check_interrupt(int time);
bool stream_manages_timeline(stream_t *s); bool stream_manages_timeline(stream_t *s);
/* stream/stream_dvd.c */
extern int dvd_title; extern int dvd_title;
extern int dvd_angle; extern int dvd_angle;
extern int dvd_speed;
extern char *dvd_device, *cdrom_device;
extern int bluray_angle; extern int bluray_angle;
extern char *bluray_device; extern char *bluray_device;

View File

@ -50,8 +50,6 @@
#include "mpvcore/mp_msg.h" #include "mpvcore/mp_msg.h"
extern char *cdrom_device;
typedef struct { typedef struct {
cdrom_drive_t *cd; cdrom_drive_t *cd;
cdrom_paranoia_t *cdp; cdrom_paranoia_t *cdp;

View File

@ -23,11 +23,9 @@
#include <inttypes.h> #include <inttypes.h>
#include <dvdread/ifo_types.h> #include <dvdread/ifo_types.h>
extern char *dvd_device;
extern const char * const dvd_audio_stream_channels[6]; extern const char * const dvd_audio_stream_channels[6];
extern const char * const dvd_audio_stream_types[8]; extern const char * const dvd_audio_stream_types[8];
extern int dvd_speed;
void dvd_set_speed(char *device, unsigned speed); void dvd_set_speed(char *device, unsigned speed);
int mp_dvdtimetomsec(dvd_time_t *dt); int mp_dvdtimetomsec(dvd_time_t *dt);

View File

@ -56,8 +56,6 @@
#define vcd_close(priv) (close(((mp_vcd_priv_t*)priv)->fd)) #define vcd_close(priv) (close(((mp_vcd_priv_t*)priv)->fd))
#endif #endif
extern char *cdrom_device;
static int fill_buffer(stream_t *s, char* buffer, int max_len){ static int fill_buffer(stream_t *s, char* buffer, int max_len){
if(s->pos > s->end_pos) /// don't past end of current track if(s->pos > s->end_pos) /// don't past end of current track
return 0; return 0;