mirror of
https://github.com/mpv-player/mpv
synced 2025-04-23 12:59:51 +02:00
options: move -chapter values to option struct
-chapter can optionally take a range with a start and an end. Add a new option type which supports such values and use that instead of a custom per-option function. This commit also fixes a build configuration bug: before the availability of the -chapter option depended on DVD functionality being enabled in the binary, even though the option works with other sources too.
This commit is contained in:
parent
9c63c084ff
commit
a2133d7684
@ -52,12 +52,12 @@
|
|||||||
{"dvd-speed", &dvd_speed, CONF_TYPE_INT, 0, 0, 0, NULL},
|
{"dvd-speed", &dvd_speed, CONF_TYPE_INT, 0, 0, 0, NULL},
|
||||||
{"dvd", "-dvd N has been removed, use dvd://N instead.\n" , CONF_TYPE_PRINT, 0, 0, 0, NULL},
|
{"dvd", "-dvd N has been removed, use dvd://N instead.\n" , CONF_TYPE_PRINT, 0, 0, 0, NULL},
|
||||||
{"dvdangle", &dvd_angle, CONF_TYPE_INT, CONF_RANGE, 1, 99, NULL},
|
{"dvdangle", &dvd_angle, CONF_TYPE_INT, CONF_RANGE, 1, 99, NULL},
|
||||||
{"chapter", dvd_parse_chapter_range, CONF_TYPE_FUNC_PARAM, 0, 0, 0, NULL},
|
|
||||||
#else
|
#else
|
||||||
{"dvd-device", "MPlayer was compiled without libdvdread support.\n", CONF_TYPE_PRINT, 0, 0, 0, NULL},
|
{"dvd-device", "MPlayer was compiled without libdvdread support.\n", CONF_TYPE_PRINT, 0, 0, 0, NULL},
|
||||||
{"dvd-speed", "MPlayer was compiled without libdvdread support.\n", CONF_TYPE_PRINT, 0, 0, 0, NULL},
|
{"dvd-speed", "MPlayer was compiled without libdvdread support.\n", CONF_TYPE_PRINT, 0, 0, 0, NULL},
|
||||||
{"dvd", "MPlayer was compiled without libdvdread support.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
|
{"dvd", "MPlayer was compiled without libdvdread support.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
|
||||||
#endif /* CONFIG_DVDREAD */
|
#endif /* CONFIG_DVDREAD */
|
||||||
|
OPT_INTPAIR("chapter", chapterrange, 0),
|
||||||
OPT_INTRANGE("edition", edition_id, 0, -1, 8190),
|
OPT_INTRANGE("edition", edition_id, 0, -1, 8190),
|
||||||
{"alang", &audio_lang, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
{"alang", &audio_lang, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
||||||
{"slang", &dvdsub_lang, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
{"slang", &dvdsub_lang, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
||||||
|
@ -21,6 +21,7 @@ void set_default_mplayer_options(struct MPOpts *opts)
|
|||||||
.osd_duration = 1000,
|
.osd_duration = 1000,
|
||||||
.loop_times = -1,
|
.loop_times = -1,
|
||||||
.ordered_chapters = 1,
|
.ordered_chapters = 1,
|
||||||
|
.chapterrange = {-1, -1},
|
||||||
.edition_id = -1,
|
.edition_id = -1,
|
||||||
.user_correct_pts = -1,
|
.user_correct_pts = -1,
|
||||||
.key_fifo_size = 7,
|
.key_fifo_size = 7,
|
||||||
|
46
m_option.c
46
m_option.c
@ -221,6 +221,52 @@ const m_option_type_t m_option_type_int64 = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int parse_intpair(const struct m_option *opt, const char *name,
|
||||||
|
const char *param, void *dst, int src)
|
||||||
|
{
|
||||||
|
if (param == NULL)
|
||||||
|
return M_OPT_MISSING_PARAM;
|
||||||
|
|
||||||
|
char *s = (char *)param;
|
||||||
|
int start = -1;
|
||||||
|
int end = -1;
|
||||||
|
if (*s) {
|
||||||
|
start = strtol(s, &s, 10);
|
||||||
|
if (s == param)
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
if (*s) {
|
||||||
|
if (*s != '-')
|
||||||
|
goto bad;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
if (*s)
|
||||||
|
end = strtol(s, &s, 10);
|
||||||
|
if (*s)
|
||||||
|
goto bad;
|
||||||
|
|
||||||
|
if (dst) {
|
||||||
|
int *p = dst;
|
||||||
|
p[0] = start;
|
||||||
|
p[1] = end;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
bad:
|
||||||
|
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid integer range "
|
||||||
|
"specification for option %s: %s\n", name, param);
|
||||||
|
return M_OPT_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct m_option_type m_option_type_intpair = {
|
||||||
|
.name = "Int[-Int]",
|
||||||
|
.size = sizeof(int[2]),
|
||||||
|
.parse = parse_intpair,
|
||||||
|
.save = copy_opt,
|
||||||
|
.set = copy_opt,
|
||||||
|
};
|
||||||
|
|
||||||
// Float
|
// Float
|
||||||
|
|
||||||
#undef VAL
|
#undef VAL
|
||||||
|
@ -45,6 +45,7 @@ struct m_struct_st;
|
|||||||
extern const m_option_type_t m_option_type_flag;
|
extern const m_option_type_t m_option_type_flag;
|
||||||
extern const m_option_type_t m_option_type_int;
|
extern const m_option_type_t m_option_type_int;
|
||||||
extern const m_option_type_t m_option_type_int64;
|
extern const m_option_type_t m_option_type_int64;
|
||||||
|
extern const m_option_type_t m_option_type_intpair;
|
||||||
extern const m_option_type_t m_option_type_float;
|
extern const m_option_type_t m_option_type_float;
|
||||||
extern const m_option_type_t m_option_type_double;
|
extern const m_option_type_t m_option_type_double;
|
||||||
extern const m_option_type_t m_option_type_string;
|
extern const m_option_type_t m_option_type_string;
|
||||||
@ -525,6 +526,7 @@ m_option_free(const m_option_t* opt,void* dst) {
|
|||||||
#define OPT_STRINGLIST(optname, varname, flags) {optname, NULL, &m_option_type_string_list, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
|
#define OPT_STRINGLIST(optname, varname, flags) {optname, NULL, &m_option_type_string_list, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
|
||||||
#define OPT_INT(optname, varname, flags) {optname, NULL, &m_option_type_int, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
|
#define OPT_INT(optname, varname, flags) {optname, NULL, &m_option_type_int, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
|
||||||
#define OPT_INTRANGE(optname, varname, flags, min, max) {optname, NULL, &m_option_type_int, (flags)|CONF_RANGE, min, max, NULL, 1, offsetof(struct MPOpts, varname)}
|
#define OPT_INTRANGE(optname, varname, flags, min, max) {optname, NULL, &m_option_type_int, (flags)|CONF_RANGE, min, max, NULL, 1, offsetof(struct MPOpts, varname)}
|
||||||
|
#define OPT_INTPAIR(optname, varname, flags) {optname, NULL, &m_option_type_intpair, (flags), 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
|
||||||
#define OPT_FLOATRANGE(optname, varname, flags, min, max) {optname, NULL, &m_option_type_float, (flags)|CONF_RANGE, min, max, NULL, 1, offsetof(struct MPOpts, varname)}
|
#define OPT_FLOATRANGE(optname, varname, flags, min, max) {optname, NULL, &m_option_type_float, (flags)|CONF_RANGE, min, max, NULL, 1, offsetof(struct MPOpts, varname)}
|
||||||
#define OPT_STRING(optname, varname, flags) {optname, NULL, &m_option_type_string, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
|
#define OPT_STRING(optname, varname, flags) {optname, NULL, &m_option_type_string, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)}
|
||||||
#define OPT_SETTINGSLIST(optname, varname, flags, objlist) {optname, NULL, &m_option_type_obj_settings_list, flags, 0, 0, objlist, 1, offsetof(struct MPOpts, varname)}
|
#define OPT_SETTINGSLIST(optname, varname, flags, objlist) {optname, NULL, &m_option_type_obj_settings_list, flags, 0, 0, objlist, 1, offsetof(struct MPOpts, varname)}
|
||||||
|
@ -644,9 +644,9 @@ if(stream->type==STREAMTYPE_DVDNAV){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dvd_chapter>1) {
|
if(opts.chapterrange[0]>1) {
|
||||||
double pts;
|
double pts;
|
||||||
if (demuxer_seek_chapter(demuxer, dvd_chapter-1, &pts, NULL) >= 0 && pts > -1.0)
|
if (demuxer_seek_chapter(demuxer, opts.chapterrange[0]-1, &pts, NULL) >= 0 && pts > -1.0)
|
||||||
seek_to_sec = pts;
|
seek_to_sec = pts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1193,9 +1193,9 @@ while(!at_eof){
|
|||||||
--play_n_frames;
|
--play_n_frames;
|
||||||
if(play_n_frames<0) break;
|
if(play_n_frames<0) break;
|
||||||
}
|
}
|
||||||
if(dvd_last_chapter>0) {
|
if(opts.chapterrange[1]>0) {
|
||||||
int cur_chapter = demuxer_get_current_chapter(demuxer);
|
int cur_chapter = demuxer_get_current_chapter(demuxer);
|
||||||
if(cur_chapter!=-1 && cur_chapter+1>dvd_last_chapter)
|
if(cur_chapter!=-1 && cur_chapter+1>opts.chapterrange[1])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
mplayer.c
21
mplayer.c
@ -3571,8 +3571,8 @@ if(stream_dump_type==5){
|
|||||||
mp_tmsg(MSGT_CPLAYER,MSGL_FATAL,"Cannot open dump file.\n");
|
mp_tmsg(MSGT_CPLAYER,MSGL_FATAL,"Cannot open dump file.\n");
|
||||||
exit_player(mpctx, EXIT_ERROR);
|
exit_player(mpctx, EXIT_ERROR);
|
||||||
}
|
}
|
||||||
if (dvd_chapter > 1) {
|
if (opts->chapterrange[0] > 1) {
|
||||||
int chapter = dvd_chapter - 1;
|
int chapter = opts->chapterrange[0] - 1;
|
||||||
stream_control(mpctx->stream, STREAM_CTRL_SEEK_TO_CHAPTER, &chapter);
|
stream_control(mpctx->stream, STREAM_CTRL_SEEK_TO_CHAPTER, &chapter);
|
||||||
}
|
}
|
||||||
while(!mpctx->stream->eof && !async_quit_request){
|
while(!mpctx->stream->eof && !async_quit_request){
|
||||||
@ -3583,10 +3583,11 @@ if(stream_dump_type==5){
|
|||||||
exit_player(mpctx, EXIT_ERROR);
|
exit_player(mpctx, EXIT_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(dvd_last_chapter > 0) {
|
if (opts->chapterrange[1] > 0) {
|
||||||
int chapter = -1;
|
int chapter = -1;
|
||||||
if (stream_control(mpctx->stream, STREAM_CTRL_GET_CURRENT_CHAPTER,
|
if (stream_control(mpctx->stream, STREAM_CTRL_GET_CURRENT_CHAPTER,
|
||||||
&chapter) == STREAM_OK && chapter + 1 > dvd_last_chapter)
|
&chapter) == STREAM_OK
|
||||||
|
&& chapter + 1 > opts->chapterrange[1])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3715,9 +3716,9 @@ if(!mpctx->demuxer)
|
|||||||
mpctx->num_sources = 1;
|
mpctx->num_sources = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dvd_chapter>1) {
|
if(opts->chapterrange[0]>1) {
|
||||||
double pts;
|
double pts;
|
||||||
if (seek_chapter(mpctx, dvd_chapter-1, &pts, NULL) >= 0 && pts > -1.0)
|
if (seek_chapter(mpctx, opts->chapterrange[0]-1, &pts, NULL) >= 0 && pts > -1.0)
|
||||||
seek(mpctx, pts, SEEK_ABSOLUTE);
|
seek(mpctx, pts, SEEK_ABSOLUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3799,9 +3800,9 @@ if((stream_dump_type)&&(stream_dump_type<4)){
|
|||||||
if( (mpctx->demuxer->file_format==DEMUXER_TYPE_AVI || mpctx->demuxer->file_format==DEMUXER_TYPE_ASF || mpctx->demuxer->file_format==DEMUXER_TYPE_MOV)
|
if( (mpctx->demuxer->file_format==DEMUXER_TYPE_AVI || mpctx->demuxer->file_format==DEMUXER_TYPE_ASF || mpctx->demuxer->file_format==DEMUXER_TYPE_MOV)
|
||||||
&& stream_dump_type==2) fwrite(&in_size,1,4,f);
|
&& stream_dump_type==2) fwrite(&in_size,1,4,f);
|
||||||
if(in_size>0) fwrite(start,in_size,1,f);
|
if(in_size>0) fwrite(start,in_size,1,f);
|
||||||
if(dvd_last_chapter>0) {
|
if (opts->chapterrange[1] > 0) {
|
||||||
int cur_chapter = demuxer_get_current_chapter(mpctx->demuxer);
|
int cur_chapter = demuxer_get_current_chapter(mpctx->demuxer);
|
||||||
if(cur_chapter!=-1 && cur_chapter+1>dvd_last_chapter)
|
if(cur_chapter!=-1 && cur_chapter+1 > opts->chapterrange[1])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4090,9 +4091,9 @@ if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
|
|||||||
while(!mpctx->stop_play){
|
while(!mpctx->stop_play){
|
||||||
float aq_sleep_time=0;
|
float aq_sleep_time=0;
|
||||||
|
|
||||||
if(dvd_last_chapter>0) {
|
if (opts->chapterrange[1] > 0) {
|
||||||
int cur_chapter = get_current_chapter(mpctx);
|
int cur_chapter = get_current_chapter(mpctx);
|
||||||
if(cur_chapter!=-1 && cur_chapter+1>dvd_last_chapter)
|
if(cur_chapter!=-1 && cur_chapter+1 > opts->chapterrange[1])
|
||||||
goto goto_next_file;
|
goto goto_next_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ typedef struct MPOpts {
|
|||||||
int osd_duration;
|
int osd_duration;
|
||||||
int loop_times;
|
int loop_times;
|
||||||
int ordered_chapters;
|
int ordered_chapters;
|
||||||
|
int chapterrange[2];
|
||||||
int edition_id;
|
int edition_id;
|
||||||
int correct_pts;
|
int correct_pts;
|
||||||
int user_correct_pts;
|
int user_correct_pts;
|
||||||
|
@ -39,8 +39,6 @@
|
|||||||
/// We keep these 2 for the gui atm, but they will be removed.
|
/// We keep these 2 for the gui atm, but they will be removed.
|
||||||
int vcd_track=0;
|
int vcd_track=0;
|
||||||
char* cdrom_device=NULL;
|
char* cdrom_device=NULL;
|
||||||
int dvd_chapter=1;
|
|
||||||
int dvd_last_chapter=0;
|
|
||||||
char* dvd_device=NULL;
|
char* dvd_device=NULL;
|
||||||
int dvd_title=0;
|
int dvd_title=0;
|
||||||
|
|
||||||
|
@ -342,8 +342,6 @@ void stream_set_interrupt_callback(int (*cb)(struct input_ctx*, int),
|
|||||||
int stream_check_interrupt(int time);
|
int stream_check_interrupt(int time);
|
||||||
|
|
||||||
extern int dvd_title;
|
extern int dvd_title;
|
||||||
extern int dvd_chapter;
|
|
||||||
extern int dvd_last_chapter;
|
|
||||||
extern int dvd_angle;
|
extern int dvd_angle;
|
||||||
|
|
||||||
extern char * audio_stream;
|
extern char * audio_stream;
|
||||||
|
@ -83,42 +83,6 @@ static const struct m_struct_st stream_opts = {
|
|||||||
stream_opts_fields
|
stream_opts_fields
|
||||||
};
|
};
|
||||||
|
|
||||||
int dvd_parse_chapter_range(const m_option_t *conf, const char *range) {
|
|
||||||
const char *s;
|
|
||||||
char *t;
|
|
||||||
if (!range)
|
|
||||||
return M_OPT_MISSING_PARAM;
|
|
||||||
s = range;
|
|
||||||
dvd_chapter = 1;
|
|
||||||
dvd_last_chapter = 0;
|
|
||||||
if(*range && isdigit(*range)) {
|
|
||||||
dvd_chapter = strtol(range, &s, 10);
|
|
||||||
if(range == s) {
|
|
||||||
mp_tmsg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range);
|
|
||||||
return M_OPT_INVALID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(*s == 0)
|
|
||||||
return 0;
|
|
||||||
else if(*s != '-') {
|
|
||||||
mp_tmsg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range);
|
|
||||||
return M_OPT_INVALID;
|
|
||||||
}
|
|
||||||
++s;
|
|
||||||
if(*s == 0)
|
|
||||||
return 0;
|
|
||||||
if(! isdigit(*s)) {
|
|
||||||
mp_tmsg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range);
|
|
||||||
return M_OPT_INVALID;
|
|
||||||
}
|
|
||||||
dvd_last_chapter = strtol(s, &t, 10);
|
|
||||||
if (s == t || *t) {
|
|
||||||
mp_tmsg(MSGT_OPEN, MSGL_ERR, "Invalid chapter range specification %s\n", range);
|
|
||||||
return M_OPT_INVALID;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dvd_chapter_from_cell(dvd_priv_t* dvd,int title,int cell)
|
int dvd_chapter_from_cell(dvd_priv_t* dvd,int title,int cell)
|
||||||
{
|
{
|
||||||
pgc_t * cur_pgc;
|
pgc_t * cur_pgc;
|
||||||
@ -411,8 +375,6 @@ static void dvd_close(dvd_priv_t *d) {
|
|||||||
ifoClose(d->vmg_file);
|
ifoClose(d->vmg_file);
|
||||||
DVDCloseFile(d->title);
|
DVDCloseFile(d->title);
|
||||||
DVDClose(d->dvd);
|
DVDClose(d->dvd);
|
||||||
dvd_chapter = 1;
|
|
||||||
dvd_last_chapter = 0;
|
|
||||||
dvd_set_speed(dvd_device_current, -1); /* -1 => restore default */
|
dvd_set_speed(dvd_device_current, -1); /* -1 => restore default */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,6 +62,5 @@ int dvd_lang_from_sid(stream_t *stream, int id);
|
|||||||
int dvd_aid_from_lang(stream_t *stream, unsigned char* lang);
|
int dvd_aid_from_lang(stream_t *stream, unsigned char* lang);
|
||||||
int dvd_sid_from_lang(stream_t *stream, unsigned char* lang);
|
int dvd_sid_from_lang(stream_t *stream, unsigned char* lang);
|
||||||
int dvd_chapter_from_cell(dvd_priv_t *dvd,int title,int cell);
|
int dvd_chapter_from_cell(dvd_priv_t *dvd,int title,int cell);
|
||||||
int dvd_parse_chapter_range(const m_option_t *conf, const char *range);
|
|
||||||
|
|
||||||
#endif /* MPLAYER_STREAM_DVD_H */
|
#endif /* MPLAYER_STREAM_DVD_H */
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include "options.h"
|
||||||
#include "mp_msg.h"
|
#include "mp_msg.h"
|
||||||
#include "osdep/timer.h"
|
#include "osdep/timer.h"
|
||||||
#include "input/input.h"
|
#include "input/input.h"
|
||||||
@ -379,9 +380,9 @@ static int fill_buffer(stream_t *s, char *but, int len)
|
|||||||
priv->state &= ~NAV_FLAG_WAIT;
|
priv->state &= ~NAV_FLAG_WAIT;
|
||||||
if (priv->state & NAV_FLAG_WAIT_READ_AUTO)
|
if (priv->state & NAV_FLAG_WAIT_READ_AUTO)
|
||||||
priv->state |= NAV_FLAG_WAIT_READ;
|
priv->state |= NAV_FLAG_WAIT_READ;
|
||||||
if(priv->title > 0 && dvd_last_chapter > 0) {
|
if(priv->title > 0 && s->opts->chapterrange[1] > 0) {
|
||||||
int tit=0, part=0;
|
int tit=0, part=0;
|
||||||
if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) == DVDNAV_STATUS_OK && part > dvd_last_chapter) {
|
if(dvdnav_current_title_info(priv->dvdnav, &tit, &part) == DVDNAV_STATUS_OK && part > s->opts->chapterrange[1]) {
|
||||||
priv->state |= NAV_FLAG_EOF;
|
priv->state |= NAV_FLAG_EOF;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user