Move producer/consumer frames out of video buffer

The video buffer held 3 frames:
 - the producer frame (for decoding)
 - the pending frame (to exchange between the producer and consumer)
 - the consumer frame (for rendering)

It worked well, but it prevented video buffers to be chained, because
the consumer frame of the first video buffer must be the same as the
producer frame of the second video buffer.

To solve this problem, make the decoder and the screen handle their own
frames, and keep only the pending frame in the video_buffer.

This paves the way to support asynchronous swscale.
This commit is contained in:
Romain Vimont
2021-02-21 17:39:59 +01:00
parent 11e1fcd10f
commit 48606b2942
6 changed files with 43 additions and 40 deletions

View File

@@ -29,9 +29,7 @@ typedef struct AVFrame AVFrame;
*/
struct video_buffer {
AVFrame *producer_frame;
AVFrame *pending_frame;
AVFrame *consumer_frame;
sc_mutex mutex;
bool wait_consumer; // never overwrite a pending frame if it is not consumed
@@ -67,13 +65,14 @@ video_buffer_set_consumer_callbacks(struct video_buffer *vb,
void *cbs_userdata);
// set the producer frame as ready for consuming
// the produced frame is exchanged with an unused allocated frame
void
video_buffer_producer_offer_frame(struct video_buffer *vb);
video_buffer_producer_offer_frame(struct video_buffer *vb, AVFrame **pframe);
// mark the consumer frame as consumed and return it
// the frame is valid until the next call to this function
const AVFrame *
video_buffer_consumer_take_frame(struct video_buffer *vb);
// mark the consumer frame as consumed and exchange it with an unused allocated
// frame
void
video_buffer_consumer_take_frame(struct video_buffer *vb, AVFrame **pframe);
// wake up and avoid any blocking call
void