Skip to content

Async subs or something - #18916

Open
kasper93 wants to merge 51 commits into
mpv-player:masterfrom
kasper93:async_subs
Open

kasper93 wants to merge 51 commits into
mpv-player:masterfrom
kasper93:async_subs

Conversation

@kasper93

Copy link
Copy Markdown
Member

No description provided.

It rendered the first frame after a segment switch without them, the
player passes them only on its next update. dec_sub keeps the last ones
for that.
They can't fit the rectangles, and every attempt went over all of them.
The resulting size and positions stay the same.
The atlas for a very large image list could not be allocated, and no
subtitles were shown at all.
The bitmaps of libass are padded to whole tiles, and a row without
coverage leaves the destination as it is.
A caller that still referenced the previous result made the next pack
copy the whole atlas before overwriting it.
Every external overlay was rendered again on each draw.
It returns nothing for a track that is not visible. The OSD checks that
before every call so far, which takes the decoder lock a second time.
It checks the visibility of its track itself, so the decoder lock is
taken once per draw instead of twice.
Four places pass packets to the decoder, and all of them are going to
drop kept results after it. No functional change.
dec_sub is going to keep rendered subtitles and has to know which of
them a new packet makes stale. That is not always the pts of the packet,
sd_lavc takes the time of a subtitle from the decoder.
The decoders give a number that tells whether the bitmaps differ from
those of the previous call. That stops working once a result is handed
out more than once, so sub_get_bitmaps() gives every new result a new id
and the OSD counts a change when the id differs from the last one.
The subtitle time gets a variable of its own. No functional change.
sub_get_bitmaps() rendered on every draw, also when a frame is shown
for several vsyncs. A result now stays until a packet, a seek or an
option changes what is shown at its time.
get_bitmaps_end() gives the next start or end of an event, or the time
itself while an animated event is shown. Nothing calls it yet.
A kept result only served calls with the time it was rendered for, so
the subtitles were still rendered once per video frame. It now serves
every time up to the one get_bitmaps_end() gives.
The style is all it takes. The call no longer creates the track and
the renderer of the OSD.
They read it from the object. No functional change.
As the other setters do. No functional change.
Every change of what the OSD or the external overlays show calls
osd_object_changed(), which is where the changes are going to be
counted. osd_changed() calls it after the options update, which is part
of the change. No functional change.
The OSD and the external overlays went through libass and the packer on
every draw. Every change now gives the object a new state id, and the
result is kept until the state id, the size or the format differs.
It told osd_object_get_bitmaps() whether the OSD text has to be built
again. The function is only called for a new state, size or format now,
so the flag only saved that for a change of the format alone.
ass_state.vo_res was the size of the last update_playres() call. The one
place that read it had just made that call with the size of the object,
so the field is not needed.
osd_set_external() built the track on every call. The next render or
bounds query builds it now, so a script that updates an overlay faster
than it is drawn no longer builds tracks that nobody sees.
osd_object_prepare() does the allocations and osd_object_render() the
rest. No functional change.
osd_object_prepare() takes the copy. The render then no longer reads the
fields that osd_set_text() and osd_set_progbar() write, which lets it
run without the lock later.
osd_object_prepare() copies the data of the overlays that
osd_set_external() changed and tells the packer about the change, which
osd_set_external() did itself. The render then no longer shares these
fields with it.
It waits until no thread renders an object. Nothing counts as a render
yet.
A thread that waits for the decoder lock takes the result of the thread
that held it. This happens once the OSD no longer serializes the calls.
dec_sub has a lock of its own. What the lock protected here is the track
of the object, so osd_set_sub() waits for its renders before it replaces
the track.
The renders of the OSD and of the overlays read the options.
osd_changed() waits for them before it updates the options, which only
matters once they run without the lock.
Such a call does nothing, and it returns before the wait that the next
commit adds. No functional change.
Adding, removing and reordering overlays and the bounds query wait for
the renders of the object. A new content of an overlay does not, the
render has its copy.
A thread that finds no result waits for the render of another thread and
looks again before it renders. This only matters once a render runs
without the lock.
The render reads the copies of osd_object_prepare(), and what else it
reads waits for it. The result is stored with the state it was made
from, so a change that comes during the render is drawn by the next one.
The query counts as a render of the object now and releases the lock
while it builds and measures the track.
osd_prefetch() is going to make the same choice. No functional change.
osd_prefetch() is going to go over the same objects. No functional
change.
Tells whether sub_get_bitmaps() would have to render.
A VO can ask ahead for what a coming osd_render() call returns. A thread
pool then renders the subtitles in the meantime, and osd_render() waits
for them if they are not done. The return value tells whether everything
is at hand already. --osd-thread=no turns the jobs off.
They are rendered on another thread while the current frame is on
screen, instead of in front of the first draw of their frame. They are
asked for once the current frame has its own, which keeps the renders
in order.
For redraw requests that come from another thread than the player's.
Nothing calls the callback yet.
The core asks the OSD whether it wants a redraw only when something
wakes it up.
A job that renders an object again and again is going to let them go
first.
With it a change of the OSD or of an external overlay is rendered by a
job on another thread, and osd_render() returns the previous result
until the job is done, so a VO never waits for the OSD. The job asks
for the redraw, and lets threads that wait for the object go before it
renders again.
A change of the OSD or of a script overlay is rendered on another
thread and shown by the first draw after that.
update_target_overlays() has the signature of pl_frame.acquire_overlays,
so the flags and the source image are kept in mppl_video, which the
target points to. No functional change.
With pl_frame.acquire_overlays the wait for subtitles that are still
rendered comes after the passes of the frame, which are flushed to the
GPU first.
A frame is marked when its subtitles are outdated, and
update_image_overlays() renders them and sets the overlays of the
frame from its overlay state.
As for the target overlays. Only a frame that is drawn gets its
subtitles then, and a frame that waits in the mix has them rendered on
the other thread until it is shown.
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.

1 participant