1
mirror of https://github.com/mpv-player/mpv synced 2024-12-28 06:03:45 +01: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:
Uoti Urpala 2010-04-24 20:09:31 +03:00
parent 9c63c084ff
commit a2133d7684
12 changed files with 69 additions and 60 deletions

View File

@ -52,12 +52,12 @@
{"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},
{"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
{"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", "MPlayer was compiled without libdvdread support.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif /* CONFIG_DVDREAD */
OPT_INTPAIR("chapter", chapterrange, 0),
OPT_INTRANGE("edition", edition_id, 0, -1, 8190),
{"alang", &audio_lang, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"slang", &dvdsub_lang, CONF_TYPE_STRING, 0, 0, 0, NULL},

View File

@ -21,6 +21,7 @@ void set_default_mplayer_options(struct MPOpts *opts)
.osd_duration = 1000,
.loop_times = -1,
.ordered_chapters = 1,
.chapterrange = {-1, -1},
.edition_id = -1,
.user_correct_pts = -1,
.key_fifo_size = 7,

View File

@ -221,6 +221,52 @@ const m_option_type_t m_option_type_int64 = {
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
#undef VAL

View File

@ -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_int;
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_double;
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_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_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_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)}

View File

@ -644,9 +644,9 @@ if(stream->type==STREAMTYPE_DVDNAV){
}
}
if(dvd_chapter>1) {
if(opts.chapterrange[0]>1) {
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;
}
@ -1193,9 +1193,9 @@ while(!at_eof){
--play_n_frames;
if(play_n_frames<0) break;
}
if(dvd_last_chapter>0) {
if(opts.chapterrange[1]>0) {
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;
}

View File

@ -3571,8 +3571,8 @@ if(stream_dump_type==5){
mp_tmsg(MSGT_CPLAYER,MSGL_FATAL,"Cannot open dump file.\n");
exit_player(mpctx, EXIT_ERROR);
}
if (dvd_chapter > 1) {
int chapter = dvd_chapter - 1;
if (opts->chapterrange[0] > 1) {
int chapter = opts->chapterrange[0] - 1;
stream_control(mpctx->stream, STREAM_CTRL_SEEK_TO_CHAPTER, &chapter);
}
while(!mpctx->stream->eof && !async_quit_request){
@ -3583,10 +3583,11 @@ if(stream_dump_type==5){
exit_player(mpctx, EXIT_ERROR);
}
}
if(dvd_last_chapter > 0) {
if (opts->chapterrange[1] > 0) {
int chapter = -1;
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;
}
}
@ -3715,9 +3716,9 @@ if(!mpctx->demuxer)
mpctx->num_sources = 1;
}
if(dvd_chapter>1) {
if(opts->chapterrange[0]>1) {
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);
}
@ -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)
&& stream_dump_type==2) fwrite(&in_size,1,4,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);
if(cur_chapter!=-1 && cur_chapter+1>dvd_last_chapter)
if(cur_chapter!=-1 && cur_chapter+1 > opts->chapterrange[1])
break;
}
}
@ -4090,9 +4091,9 @@ if (mpctx->stream->type == STREAMTYPE_DVDNAV) {
while(!mpctx->stop_play){
float aq_sleep_time=0;
if(dvd_last_chapter>0) {
if (opts->chapterrange[1] > 0) {
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;
}

View File

@ -29,6 +29,7 @@ typedef struct MPOpts {
int osd_duration;
int loop_times;
int ordered_chapters;
int chapterrange[2];
int edition_id;
int correct_pts;
int user_correct_pts;

View File

@ -39,8 +39,6 @@
/// We keep these 2 for the gui atm, but they will be removed.
int vcd_track=0;
char* cdrom_device=NULL;
int dvd_chapter=1;
int dvd_last_chapter=0;
char* dvd_device=NULL;
int dvd_title=0;

View File

@ -342,8 +342,6 @@ void stream_set_interrupt_callback(int (*cb)(struct input_ctx*, int),
int stream_check_interrupt(int time);
extern int dvd_title;
extern int dvd_chapter;
extern int dvd_last_chapter;
extern int dvd_angle;
extern char * audio_stream;

View File

@ -83,42 +83,6 @@ static const struct m_struct_st stream_opts = {
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)
{
pgc_t * cur_pgc;
@ -411,8 +375,6 @@ static void dvd_close(dvd_priv_t *d) {
ifoClose(d->vmg_file);
DVDCloseFile(d->title);
DVDClose(d->dvd);
dvd_chapter = 1;
dvd_last_chapter = 0;
dvd_set_speed(dvd_device_current, -1); /* -1 => restore default */
}

View File

@ -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_sid_from_lang(stream_t *stream, unsigned char* lang);
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 */

View File

@ -23,6 +23,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "options.h"
#include "mp_msg.h"
#include "osdep/timer.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;
if (priv->state & NAV_FLAG_WAIT_READ_AUTO)
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;
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;
return 0;
}