Skip to content

osc.lua: always observe duration#17784

Open
guidocella wants to merge 1 commit intompv-player:masterfrom
guidocella:osc-duration
Open

osc.lua: always observe duration#17784
guidocella wants to merge 1 commit intompv-player:masterfrom
guidocella:osc-duration

Conversation

@guidocella
Copy link
Copy Markdown
Contributor

@guidocella guidocella commented Apr 20, 2026

Currently the duration observer is toggled in multiple places to not call request_init unecessarily. It is much simpler to always observe it and call request_init conditionally in the callback. This also allows reusing the cached value throughout the OSC.

Note that dividing by 0 is not an error in Lua so there is no need to check for both 0 and nil.

@avih
Copy link
Copy Markdown
Member

avih commented Apr 20, 2026

You're removing the comment which says why it's conditional.

If you think that the comment no longer relevant today, or that you have other reasons which are stronger than what this comment says - which it appears that you do, then the commit message should explain why that comment is no longer relevant or otherwise can be ignored.

@guidocella
Copy link
Copy Markdown
Contributor Author

It's just already explained in the livemarkers section of the manual.

@avih
Copy link
Copy Markdown
Member

avih commented Apr 20, 2026

It's just already explained in the livemarkers section of the manual.

I didn't look for that, and I fail to see how that could be relevant.

The comment you're removing says that observing duration is conditional for performance reasons, and that it's only relevant for a single use case, which is rare.

If you think this comment is no longer relevant, or you have reasons stronger than that to make it unconditional anyway, then it should be explained someplace, but currently it's not explained anywhere as far as I can tell.

@guidocella
Copy link
Copy Markdown
Contributor Author

It's obviously relevant due to the condition being if user_opts.livemarkers. The comment explains that request_init, not observing duration, is expensive, and so does the commit message.

Currently the duration observer is toggled in multiple places to not
call request_init unecessarily. It is much simpler to always observe it
and call request_init conditionally in the callback. This also allows
reusing the cached value throughout the OSC.

Note that dividing by 0 is not an error in Lua so there is no need to
check for both 0 and nil.
Comment thread player/lua/osc.lua
end
end

return mp.format_time(state.duration or 0, state.tc_ms and "%H:%M:%S.%T" or "%H:%M:%S")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you duplicate formatting logic from mpv core?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a time format counts as logic? It just avoids retrieving duration on every tick when it's already cached. I can revert it if you want I guess.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does you code support MP_NOPTS_VALUE which should show unknown?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mp.get_property_osd('duration') returns an empty string when it's unavailable not unknown. Also this should never run if duration is unavailable because ne.visible = state.duration ~= nil, I added or 0 just in case things get updated in an unexpected order.

Comment thread player/lua/osc.lua
end)
observe_cached("duration", function ()
if user_opts.livemarkers and state.chapter_list[1] then
request_init()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have to be whole request_init? We should update only things that depend on duration. Duration will change on every tick for live content, so it's important to keep the update clean.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably extract the code that generates the ASS' seekbar out of prepare_elements into a new function, and add a new type of request to update the seekbar. But that may not be worth it because according to 96b246d livestreams with chapters are very rare, and even on 2016 hardware request_init only increased the render time from 1.3 to 1.4ms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants