History

player: only coalesce callbacks from parsed config files

This relaxes what bbac628a1b01261766459c6556e36d2443a42534 introduced. Although it is rare, there may be scripts out there that depend on the old timing. We'd still like to process config files in a sane manner and not cause OOMs so keep the general coalescing mechanism in place but use it selectively. There is one special case with the --input-commands option. We want this coalesced as well so some special handling needs to be added for that.

Dudemanguy committed 1 year ago

Commit 533a6841 parent f1526747 files · +30 −5Browse files

Unified · Split

7 files
  1. input/cmd.h +1 −0
  2. options/m_config_frontend.c +3 −0
  3. options/m_config_frontend.h +1 −0
  4. options/m_property.h +2 −0
  5. player/command.c +21 −3
  6. player/command.h +1 −1
  7. player/playloop.c +1 −1
input/cmd.h+1−0
@@ -114,6 +114,7 @@ typedef struct mp_cmd { · 113 unmodified lines
114114 bool repeated : 1;
115115 bool mouse_move : 1;
116116 bool canceled : 1;
117+ bool coalesce : 1;
117118 int mouse_x, mouse_y;
118119 struct mp_cmd *queue_next;
119120 double scale; // for scaling numeric arguments
options/m_config_frontend.c+3−0
@@ -737,6 +737,9 @@ int m_config_set_option_cli(struct m_config *config, struct bstr name, · 736 unmodified lines
737737 param = bstr0("no");
738738 }
739739
740+ if (flags & M_SETOPT_FROM_CONFIG_FILE)
741+ co->coalesce = true;
742+
740743 // This is the only mandatory function
741744 mp_assert(co->opt->type->parse);
742745
options/m_config_frontend.h+1−0
@@ -49,6 +49,7 @@ struct m_config_option { · 48 unmodified lines
4949 bool is_set_from_config : 1; // Set by a config file
5050 bool is_set_locally : 1; // Has a backup entry
5151 bool warning_was_printed : 1;
52+ bool coalesce : 1; // Property changes should be coalesced
5253 int32_t opt_id; // For some m_config APIs
5354 const char *name; // Full name (ie option-subopt)
5455 const struct m_option *opt; // Option description
options/m_property.h+2−0
@@ -147,6 +147,8 @@ struct m_property { · 146 unmodified lines
147147 void *priv;
148148 // Special-case: mark options for which command.c uses the option-bridge
149149 bool is_option;
150+ // Special-case: option-bridge properties should be coalesced
151+ bool coalesce;
150152 };
151153
152154 struct m_property *m_property_list_find(const struct m_property *list,
player/command.c+21−3
@@ -434,6 +434,7 @@ static int mp_property_generic_option(void *ctx, struct m_property *prop, · 433 unmodified lines
434434 m_option_copy(opt->opt, arg, opt->data);
435435 return M_PROPERTY_OK;
436436 case M_PROPERTY_SET:
437+ opt->coalesce = prop->coalesce;
437438 if (m_config_set_option_raw(mpctx->mconfig, opt, arg, 0) < 0)
438439 return M_PROPERTY_ERROR;
439440 return M_PROPERTY_OK;
@@ -5219,8 +5220,17 @@ static void show_property_status(struct mp_cmd_ctx *cmd, const char *name, int r · 4779 unmodified lines
52195220 static void change_property_cmd(struct mp_cmd_ctx *cmd,
52205221 const char *name, int action, void *arg)
52215222 {
5223+ struct m_property *prop = NULL;
5224+ if (cmd->cmd->coalesce) {
5225+ struct command_ctx *ctx = cmd->mpctx->command_ctx;
5226+ prop = m_property_list_find(ctx->properties, name);
5227+ if (prop)
5228+ prop->coalesce = true;
5229+ }
52225230 int r = mp_property_do(name, action, arg, cmd->mpctx);
52235231 show_property_status(cmd, name, r);
5232+ if (prop)
5233+ prop->coalesce = false;
52245234 }
52255235
52265236 static void cmd_cycle_values(void *p)
@@ -7657,6 +7667,7 @@ void run_command_opts(struct MPContext *mpctx) · 2430 unmodified lines
76577667 for (int i = 0; opts->input_commands[i]; i++) {
76587668 struct mp_cmd *cmd = mp_input_parse_cmd(mpctx->input, bstr0(opts->input_commands[i]),
76597669 "the command line");
7670+ cmd->coalesce = true;
76607671 mp_input_queue_cmd(mpctx->input, cmd);
76617672 }
76627673 ctx->command_opts_processed = true;
@@ -7715,6 +7726,13 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, uint64_t f · 52 unmodified lines
77157726 if (self_update)
77167727 return;
77177728
7729+ // Run these immediately.
7730+ if (co && !co->coalesce) {
7731+ struct mp_option_callback callback = {.co = co, .flags = flags};
7732+ mp_option_run_callback(mpctx, &callback);
7733+ return;
7734+ }
7735+
77187736 // Coalesce redundant updates and only keep the newest one.
77197737 bool drop = false;
77207738 for (int i = 0; i < mpctx->num_option_callbacks; i++) {
@@ -7737,12 +7755,12 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, uint64_t f · 16 unmodified lines
77377755 }
77387756 }
77397757
7740−void mp_option_run_callback(struct MPContext *mpctx, int index)
7758+void mp_option_run_callback(struct MPContext *mpctx, struct mp_option_callback *callback)
77417759 {
77427760 struct MPOpts *opts = mpctx->opts;
7743− struct m_config_option *co = mpctx->option_callbacks[index].co;
7761+ struct m_config_option *co = callback->co;
77447762 void *opt_ptr = co ? co->data : NULL;
7745− uint64_t flags = mpctx->option_callbacks[index].flags;
7763+ uint64_t flags = callback->flags;
77467764
77477765 if (flags & UPDATE_TERM)
77487766 mp_update_logging(mpctx, false);
player/command.h+1−1
@@ -87,7 +87,7 @@ int mp_property_do(const char* name, int action, void* val, · 86 unmodified lines
8787
8888 void mp_option_change_callback(void *ctx, struct m_config_option *co, uint64_t flags,
8989 bool self_update);
90−void mp_option_run_callback(struct MPContext *mpctx, int index);
90+void mp_option_run_callback(struct MPContext *mpctx, struct mp_option_callback *callback);
9191
9292 void mp_notify(struct MPContext *mpctx, int event, void *arg);
9393 void mp_notify_property(struct MPContext *mpctx, const char *property);
player/playloop.c+1−1
@@ -125,7 +125,7 @@ static void mp_process_input(struct MPContext *mpctx) · 124 unmodified lines
125125 void handle_option_callbacks(struct MPContext *mpctx)
126126 {
127127 for (int i = 0; i < mpctx->num_option_callbacks; i++)
128− mp_option_run_callback(mpctx, i);
128+ mp_option_run_callback(mpctx, &mpctx->option_callbacks[i]);
129129 mpctx->num_option_callbacks = 0;
130130 }
131131

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t