Add intermediate frame in video buffer

There were only two frames simultaneously:
 - one used by the decoder;
 - one used by the renderer.

When the decoder finished decoding a frame, it swapped it with the
rendering frame.

Adding a third frame provides several benefits:
 - the decoder do not have to wait for the renderer to release the
   mutex;
 - it simplifies the video_buffer API;
 - it makes the rendering frame valid until the next call to
   video_buffer_take_rendering_frame(), which will be useful for
   swscaling on window resize.
This commit is contained in:
Romain Vimont
2021-02-01 09:38:11 +01:00
parent c53bd4d8b6
commit c0c4ba7009
3 changed files with 70 additions and 32 deletions

View File

@@ -453,15 +453,12 @@ update_texture(struct screen *screen, const AVFrame *frame) {
bool
screen_update_frame(struct screen *screen, struct video_buffer *vb) {
sc_mutex_lock(&vb->mutex);
const AVFrame *frame = video_buffer_consume_rendered_frame(vb);
const AVFrame *frame = video_buffer_take_rendering_frame(vb);
struct size new_frame_size = {frame->width, frame->height};
if (!prepare_for_frame(screen, new_frame_size)) {
sc_mutex_unlock(&vb->mutex);
return false;
}
update_texture(screen, frame);
sc_mutex_unlock(&vb->mutex);
screen_render(screen, false);
return true;