-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
options: add watch-later-options #8960
options: add watch-later-options #8960
Conversation
That's the current behavior with this implementation which is certainly fair. But perhaps it would be better if |
128680e
to
2ca3469
Compare
I think that calculating almost 1000 properties + 1000 options on every startup could slow it done for basically no advantage. |
Finally got around to testing this one, it seems And I'm sorry, I know we've had this discussion in IRC before but why is all the |
That's because
When you add I think there are 3 options:
|
Oops, I didn't notice that. It is indeed coded into
To me, that makes sense and would be the preferred behavior. I would think values should always be compared to startup value regardless of when something is added/removed to the list. I understand that's incredibly subjective though. |
But the start option is different from the playback position on quit. If you do |
That's a good point.
You could do always do both. Have |
Actually that made no sense since |
Ouch, that gets trickier. I just assumed internally it used the option-property bridge when reading the file. I didn't think it literally only accepted options. If you don't feel like refactoring how the watch_later reading mechanism works (it would probably also need to accept generic properties), I think it's OK to just leave the As an aside if it doesn't actually accept properties that aren't options, the name is kind of misleading but eh. |
It uses the same code that parses There actually are some property-only keys like I don't think that there's any writable property without a corresponding option that is worth saving with So do you want to try a version that fetches every property and option on startup and see how long it takes to run? Note that it would slow down quitting as well since for every watch-later property, it would have to loop through up to 3000 With the current 108 |
Nah that seems silly to me. To be honest, I don't really like the |
5ab2683
to
a1e9ee3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the work on this. This is the best version of this feature yet so I guess it's a good thing the previous attempts all failed.
I'm glad that someone has started work in this. I implemented a prototype in https://github.com/wnoun/mpv/tree/watch-later-properties. I did not submit a patch due to some doubts. I would like to suggest that:
|
It does work on runtime changes though. |
but for the current implementation, if user changes it, the program may crash due to bad access to the |
Huh? How would that happen? |
because the mismatch of |
If you are referring to the loop in |
I means the statement |
Right, but it actually just returns |
what you means is accessing an array out of it ranges always returns NULL without any other side effect!? |
Yes. |
I think there is nothing to discuss |
A quick search returns articles like https://www.geeksforgeeks.org/accessing-array-bounds-ccpp/ which state that accessing C arrays out of bounds can indeed cause a segmentation fault. This was meant to support runtime changes at the cost of writing more properties than necessary but I did not consider this. Since as wnoun says I don't think you can make options immutable, I guess we should go back to the version that saved the names of |
a1e9ee3
to
cc7e8f8
Compare
I added a check to not access elements past the end of |
I think it is reasonable to change
it breaks the current behavior. mpv uses option values in config file as the option default, which means whenever I change the config file, the option value is not affected by the watch later file as long as it is not modified. |
Sorry for all the fuss. I suppose the name-value implementation was necessary after all. |
cc7e8f8
to
4f68f2f
Compare
player/configfiles.c
Outdated
struct resume_default **list = talloc_zero_array(mpctx, struct resume_default *, size); | ||
|
||
for (int i = 0; watch_later_properties[i]; i++) { | ||
list[i] = talloc_zero(list, struct resume_default); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use array of resume_default
instead of array of resume_default *
so you can save memory allocations here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you adapt mpctx->resume_defaults = list
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just change resume_defaults
to resume_default *
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean change mpctx->resume_defaults
to array of resume_default
player/command.c
Outdated
@@ -6713,6 +6713,9 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags, | |||
|
|||
if (opt_ptr == &opts->vo->taskbar_progress) | |||
update_vo_playback_state(mpctx); | |||
|
|||
if (opt_ptr == &opts->watch_later_properties) | |||
mp_get_resume_defaults(mpctx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if runtime change support is unnecessary, please remove all relative codes. It doesn't seem to work as expected because the current option value may not be the default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is? If we didn't want runtime support we could have used the simpler version. It's documented in the manpage that the value at the time options are added is used. The alternative is storing a copy of every option and property on startup and finding it for each proeprty in mp_write_watch_later_conf
, which is slower, though we can try that too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as I said, we cannot prevent user from changing it only through the man page. The name-value list works regardless of whether the user modifies it or not, while the "simpler version" does not. "no runtime change support" means that we allow user to change it but ignore the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. This supports runtime changes in the way documented in the manpage. And this name-value list doesn't work if when the user modifies watch-later-properties
at runtime mp_get_resume_defaults
isn't called again since mp_write_watch_later_conf
still does the comparison based on the array indexes.
4f68f2f
to
1499763
Compare
player/configfiles.c
Outdated
for (int i = 0; backup_properties[i]; i++) { | ||
const char *pname = backup_properties[i]; | ||
for (int i = 0; opts->watch_later_properties[i]; i++) { | ||
const char *pname = opts->watch_later_properties[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the key is that we shouldn't touch opts->watch_later_properties
here. since the mpctx->resume_defaults
has both the name and the default value, we can just iterate through mpctx->resume_defaults
(add a sentinel element to make it null-terminated). so we are not affected by the the opts->watch_later_properties
changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why would we want that if this is supposed to support runtime changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I explained the meaning of runtime change support. If you want the true runtime change support, you should backup all properties first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind if it supports runtime changes or not, since I only need this in mpv.conf
as I suspect most users do, and didn't mean to support runtime changes at first. Copying the existing resume defaults and calculating any new one when watch-later-properties
is modified at runtime is what Dudemanguy suggested on IRC, and he said storing every option and property at startup is silly, so it's up to him or the other maintainers to decide which version of this to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storing every single option/property on startup could have a measurable impact on startup times which is definitely unacceptable for this feature imo. I am perfectly fine with the caveat explained in the manpage and it's easy for a user to workaround it.
I tried to refactor this with void mp_get_resume_defaults(struct MPContext *mpctx)
{
char **watch_later_properties = mpctx->opts->watch_later_properties;
// If you do --watch-later-properties=,
// the first element of the list option is "" rather than NULL.
if (strcmp(watch_later_properties[0], "") == 0 && !watch_later_properties[1]) {
talloc_free(mpctx->resume_defaults);
return;
}
struct resume_default *list;
int i = 0;
while (watch_later_properties[i]) {
struct resume_default def = {
.pname = talloc_strdup(list, watch_later_properties[i]),
.val = NULL
};
// If watch-later-properties is modified at runtime,
// copy existing default values from the old resume_defaults.
for (int j = 0; mpctx->resume_defaults
&& mpctx->resume_defaults[j].pname; j++) {
if (strcmp(def.pname, mpctx->resume_defaults[j].pname) == 0) {
def.val = talloc_strdup(list, mpctx->resume_defaults[j].val);
break;
}
}
if (!def.val) {
char *val = NULL;
int r = mp_property_do(def.pname, M_PROPERTY_GET_STRING, &val,
mpctx);
if (r == M_PROPERTY_OK) {
def.val = talloc_steal(list, val);
} else if (r == M_PROPERTY_UNKNOWN) {
MP_ERR(mpctx->mconfig, "Option %s not found.\n", def.pname);
}
}
MP_TARRAY_APPEND(mpctx, list, i, def);
}
MP_TARRAY_APPEND(mpctx, list, i,
(struct resume_default){ .pname = NULL, .val = NULL });
talloc_free(mpctx->resume_defaults);
mpctx->resume_defaults = list;
} |
1499763
to
ec0aae0
Compare
Actually I just had to initialize I also restored the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's good now (second time I know but still).
Alright. Are we sure we don't want to name this |
It does work by reading mini config files so technically |
ec0aae0
to
cfa7c86
Compare
Renamed. I also moved the documentation to below |
I wrote another implementation that backups every option at startup, so that even if While calculating every property at startup may be slow, it's fine to do it just for options, since It is also 30 lines shorter, and allows removing the With the default What do you think? |
That approach looks better actually. The startup time increasing does feel a bit wrong, but the actual magnitude is incredibly small so it should be okay. Everything else looks better though. One question. Why is this part needed exactly? I wasn't too sure from the patch.
|
I wrote it in the commit message: Toggling a video or audio filter twice would treat the option as changed It doesn't seem to break anything. I think it's reasonable to consider NULL and a list with one empty item as equal. Actually I was pretty worried about not being to use this version just because it was saving vf and af unnecessarily (which would overwrite new defaults you set in I don't know how hard it would be modify the behavior of vf and af instead so they reset to NULL when removing all filters. |
Oh crap my bad for not reading that.
Are these the only options that work like this internally? Probably given their relative complexity. |
It seems so, regular list options don't have this issue, only vf and af. If you revert the change to |
cfa7c86
to
7fd203d
Compare
So just to document some brief IRC discussion, some testing seems to reveal that |
This allows configuring which options are saved by quit-watch-later. Fixes mpv-player#4126, mpv-player#4641 and mpv-player#5567. Toggling a video or audio filter twice would treat the option as changed because the backup value is NULL, and the current value of vf/af is a list with one empty item, so obj_settings_list_equal had to be changed.
7fd203d
to
9ca0725
Compare
Fixed the indentation in |
This allows configuring which properties are saved by quit-watch-later.
Fixes #4126, fixes #4641, fixes #5567.