2019-03-02 15:16:55 +01:00
|
|
|
#ifndef VIDEO_BUFFER_H
|
|
|
|
#define VIDEO_BUFFER_H
|
2017-12-12 15:12:07 +01:00
|
|
|
|
2021-01-08 19:24:51 +01:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-03-02 23:52:22 +01:00
|
|
|
#include <stdbool.h>
|
2017-12-12 15:12:07 +01:00
|
|
|
|
2018-08-15 17:01:54 +02:00
|
|
|
#include "fps_counter.h"
|
2021-01-31 18:24:35 +01:00
|
|
|
#include "util/thread.h"
|
2018-02-07 12:25:52 +01:00
|
|
|
|
2017-12-12 15:12:07 +01:00
|
|
|
// forward declarations
|
|
|
|
typedef struct AVFrame AVFrame;
|
|
|
|
|
2021-02-01 09:38:11 +01:00
|
|
|
/**
|
|
|
|
* There are 3 frames in memory:
|
|
|
|
* - one frame is held by the decoder (decoding_frame)
|
|
|
|
* - one frame is held by the renderer (rendering_frame)
|
|
|
|
* - one frame is shared between the decoder and the renderer (pending_frame)
|
|
|
|
*
|
|
|
|
* The decoder decodes a packet into the decoding_frame (it may takes time).
|
|
|
|
*
|
|
|
|
* Once the frame is decoded, it calls video_buffer_offer_decoded_frame(),
|
|
|
|
* which swaps the decoding and pending frames.
|
|
|
|
*
|
|
|
|
* When the renderer is notified that a new frame is available, it calls
|
|
|
|
* video_buffer_take_rendering_frame() to retrieve it, which swaps the pending
|
|
|
|
* and rendering frames. The frame is valid until the next call, without
|
|
|
|
* blocking the decoder.
|
|
|
|
*/
|
|
|
|
|
2019-03-02 15:16:55 +01:00
|
|
|
struct video_buffer {
|
2017-12-12 15:12:07 +01:00
|
|
|
AVFrame *decoding_frame;
|
2021-02-01 09:38:11 +01:00
|
|
|
AVFrame *pending_frame;
|
2017-12-12 15:12:07 +01:00
|
|
|
AVFrame *rendering_frame;
|
2021-02-01 09:38:11 +01:00
|
|
|
|
2021-01-31 18:24:35 +01:00
|
|
|
sc_mutex mutex;
|
2019-06-05 19:02:50 +02:00
|
|
|
bool render_expired_frames;
|
2019-03-02 23:52:22 +01:00
|
|
|
bool interrupted;
|
2021-02-01 09:38:11 +01:00
|
|
|
|
|
|
|
sc_cond pending_frame_consumed_cond;
|
|
|
|
bool pending_frame_consumed;
|
2017-12-12 15:12:07 +01:00
|
|
|
};
|
|
|
|
|
2019-03-02 23:52:22 +01:00
|
|
|
bool
|
2021-02-19 20:56:09 +01:00
|
|
|
video_buffer_init(struct video_buffer *vb, bool render_expired_frames);
|
2019-03-02 20:09:56 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
video_buffer_destroy(struct video_buffer *vb);
|
2017-12-12 15:12:07 +01:00
|
|
|
|
2019-03-02 15:16:55 +01:00
|
|
|
// set the decoded frame as ready for rendering
|
2019-03-03 00:26:48 +01:00
|
|
|
// the output flag is set to report whether the previous frame has been skipped
|
|
|
|
void
|
|
|
|
video_buffer_offer_decoded_frame(struct video_buffer *vb,
|
|
|
|
bool *previous_frame_skipped);
|
2018-02-08 19:23:24 +01:00
|
|
|
|
|
|
|
// mark the rendering frame as consumed and return it
|
2021-02-01 09:38:11 +01:00
|
|
|
// the frame is valid until the next call to this function
|
2019-03-02 20:09:56 +01:00
|
|
|
const AVFrame *
|
2021-02-01 09:38:11 +01:00
|
|
|
video_buffer_take_rendering_frame(struct video_buffer *vb);
|
2017-12-12 15:12:07 +01:00
|
|
|
|
2018-02-09 08:42:39 +01:00
|
|
|
// wake up and avoid any blocking call
|
2019-03-02 20:09:56 +01:00
|
|
|
void
|
|
|
|
video_buffer_interrupt(struct video_buffer *vb);
|
2018-02-09 08:42:39 +01:00
|
|
|
|
2017-12-12 15:12:07 +01:00
|
|
|
#endif
|