1
mirror of https://github.com/mpv-player/mpv synced 2024-07-31 16:29:58 +02:00

options: Move osd_level and osd_duration to options struct

This commit is contained in:
Uoti Urpala 2009-03-30 02:06:58 +03:00
parent 9156a396a5
commit 694c067e19
7 changed files with 36 additions and 27 deletions

View File

@ -242,8 +242,8 @@ const m_option_t mplayer_opts[]={
{"crash-debug", &crash_debug, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
{"nocrash-debug", &crash_debug, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL},
#endif
{"osdlevel", &osd_level, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL},
{"osd-duration", &osd_duration, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
OPT_INTRANGE("osdlevel", osd_level, 0, 0, 3),
OPT_INTRANGE("osd-duration", osd_duration, 0, 0, 3600000),
#ifdef CONFIG_MENU
{"menu", &use_menu, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
{"nomenu", &use_menu, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL},

View File

@ -172,7 +172,7 @@ static void log_sub(struct MPContext *mpctx)
static int mp_property_osdlevel(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
return m_property_choice(prop, action, arg, &osd_level);
return m_property_choice(prop, action, arg, &mpctx->opts.osd_level);
}
/// Loop (RW)
@ -385,6 +385,7 @@ static int mp_property_time_pos(m_option_t *prop, int action,
static int mp_property_chapter(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
int chapter = -1;
float next_pts = 0;
int chapter_num;
@ -440,13 +441,13 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg,
mpctx->rel_seek_secs = next_pts;
}
if (chapter_name)
set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
MSGTR_OSDChapter, chapter + 1, chapter_name);
}
else if (step_all > 0)
mpctx->rel_seek_secs = 1000000000.;
else
set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
MSGTR_OSDChapter, 0, MSGTR_Unknown);
if (chapter_name)
free(chapter_name);
@ -468,6 +469,7 @@ static int mp_property_chapters(m_option_t *prop, int action, void *arg,
static int mp_property_angle(m_option_t *prop, int action, void *arg,
MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
int angle = -1;
int angles;
char *angle_name = NULL;
@ -519,7 +521,7 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg,
return M_PROPERTY_NOT_IMPLEMENTED;
}
angle = demuxer_set_angle(mpctx->demuxer, angle);
set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration,
MSGTR_OSDAngle, angle, angles);
if (angle_name)
free(angle_name);
@ -2285,6 +2287,7 @@ static struct {
/// Handle commands that set a property.
static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
{
struct MPOpts *opts = &mpctx->opts;
int i, r;
m_option_t* prop;
const char *pname;
@ -2335,7 +2338,7 @@ static int set_property_command(MPContext *mpctx, mp_cmd_t *cmd)
if (val) {
set_osd_msg(set_prop_cmd[i].osd_id >=
0 ? set_prop_cmd[i].osd_id : OSD_MSG_PROPERTY + i,
1, osd_duration, set_prop_cmd[i].osd_msg, val);
1, opts->osd_duration, set_prop_cmd[i].osd_msg, val);
free(val);
}
}
@ -2377,6 +2380,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
struct MPOpts *opts = &mpctx->opts;
sh_audio_t * const sh_audio = mpctx->sh_audio;
sh_video_t * const sh_video = mpctx->sh_video;
int osd_duration = opts->osd_duration;
if (!set_property_command(mpctx, cmd))
switch (cmd->id) {
case MP_CMD_SEEK:{
@ -2621,18 +2625,18 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
int v = cmd->args[0].v.i;
int max = (term_osd
&& !sh_video) ? MAX_TERM_OSD_LEVEL : MAX_OSD_LEVEL;
if (osd_level > max)
osd_level = max;
if (opts->osd_level > max)
opts->osd_level = max;
if (v < 0)
osd_level = (osd_level + 1) % (max + 1);
opts->osd_level = (opts->osd_level + 1) % (max + 1);
else
osd_level = v > max ? max : v;
opts->osd_level = v > max ? max : v;
/* Show OSD state when disabled, but not when an explicit
argument is given to the OSD command, i.e. in slave mode. */
if (v == -1 && osd_level <= 1)
if (v == -1 && opts->osd_level <= 1)
set_osd_msg(OSD_MSG_OSD_STATUS, 0, osd_duration,
MSGTR_OSDosd,
osd_level ? MSGTR_OSDenabled :
opts->osd_level ? MSGTR_OSDenabled :
MSGTR_OSDdisabled);
else
rm_osd_msg(OSD_MSG_OSD_STATUS);
@ -3181,7 +3185,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
pointer_y = (int) (dy * (double) sh_video->disp_h);
mp_dvdnav_update_mouse_pos(mpctx->stream,
pointer_x, pointer_y, &button);
if (osd_level > 1 && button > 0)
if (opts->osd_level > 1 && button > 0)
set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
"Selected button number %d", button);
}
@ -3208,7 +3212,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
command = mp_dvdnav_bindings[i].cmd;
mp_dvdnav_handle_input(mpctx->stream,command,&button);
if (osd_level > 1 && button > 0)
if (opts->osd_level > 1 && button > 0)
set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
"Selected button number %d", button);
}

View File

@ -17,6 +17,8 @@ void set_default_mplayer_options(struct MPOpts *opts)
.vo_gamma_contrast = 1000,
.vo_gamma_saturation = 1000,
.vo_gamma_hue = 1000,
.osd_level = 1,
.osd_duration = 1000,
.loop_times = -1,
.user_correct_pts = -1,
.key_fifo_size = 7,

View File

@ -16,7 +16,6 @@
#define MAX_TERM_OSD_LEVEL 1
// These appear in options list
extern int osd_duration;
extern int term_osd;
struct MPContext;

View File

@ -201,10 +201,8 @@ int enqueue=0;
static int list_properties = 0;
int osd_level=1;
// if nonzero, hide current OSD contents when GetTimerMS() reaches this
unsigned int osd_visible;
int osd_duration = 1000;
int term_osd = 1;
static char* term_osd_esc = "\x1b[A\r\x1b[K";
@ -1403,6 +1401,7 @@ static void clear_osd_msgs(void) {
static mp_osd_msg_t* get_osd_msg(struct MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
mp_osd_msg_t *msg,*prev,*last = NULL;
static unsigned last_update = 0;
unsigned now = GetTimerMS();
@ -1428,14 +1427,16 @@ static mp_osd_msg_t* get_osd_msg(struct MPContext *mpctx)
// Look for the first message in the stack with high enough level.
for(msg = osd_msg_stack ; msg ; last = msg, msg = prev) {
prev = msg->prev;
if(msg->level > osd_level && hidden_dec_done) continue;
if (msg->level > opts->osd_level && hidden_dec_done)
continue;
// The message has a high enough level or it is the first hidden one
// in both cases we decrement the timer or kill it.
if(!msg->started || msg->time > diff) {
if(msg->started) msg->time -= diff;
else msg->started = 1;
// display it
if(msg->level <= osd_level) return msg;
if (msg->level <= opts->osd_level)
return msg;
hidden_dec_done = 1;
continue;
}
@ -1461,8 +1462,9 @@ static mp_osd_msg_t* get_osd_msg(struct MPContext *mpctx)
*/
void set_osd_bar(struct MPContext *mpctx, int type,const char* name,double min,double max,double val) {
if(osd_level < 1) return;
struct MPOpts *opts = &mpctx->opts;
if (opts->osd_level < 1)
return;
if(mpctx->sh_video) {
osd_visible = (GetTimerMS() + 1000) | 1;
@ -1472,8 +1474,8 @@ void set_osd_bar(struct MPContext *mpctx, int type,const char* name,double min,d
return;
}
set_osd_msg(OSD_MSG_BAR,1,osd_duration,"%s: %d %%",
name,ROUND(100*(val-min)/(max-min)));
set_osd_msg(OSD_MSG_BAR, 1, opts->osd_duration, "%s: %d %%",
name, ROUND(100*(val-min)/(max-min)));
}
@ -1488,6 +1490,7 @@ void set_osd_bar(struct MPContext *mpctx, int type,const char* name,double min,d
static void update_osd_msg(struct MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
mp_osd_msg_t *msg;
struct osd_state *osd = mpctx->osd;
char osd_text_timer[128];
@ -1504,7 +1507,7 @@ static void update_osd_msg(struct MPContext *mpctx)
if(mpctx->sh_video) {
// fallback on the timer
if(osd_level>=2) {
if (opts->osd_level >= 2) {
int len = demuxer_get_time_length(mpctx->demuxer);
int percentage = -1;
char percentage_text[10];
@ -1518,7 +1521,7 @@ static void update_osd_msg(struct MPContext *mpctx)
else
percentage_text[0] = 0;
if (osd_level == 3)
if (opts->osd_level == 3)
snprintf(osd_text_timer, 63,
"%c %02d:%02d:%02d / %02d:%02d:%02d%s",
mpctx->osd_function,pts/3600,(pts/60)%60,pts%60,

View File

@ -17,7 +17,6 @@ extern char * video_driver;
extern char * audio_driver;
extern float audio_delay;
extern int osd_level;
extern unsigned int osd_visible;
extern char * font_name;

View File

@ -25,6 +25,8 @@ typedef struct MPOpts {
int vo_gamma_saturation;
int vo_gamma_hue;
int osd_level;
int osd_duration;
int loop_times;
int correct_pts;
int user_correct_pts;