2019-03-02 15:16:55 +01:00
|
|
|
#ifndef VIDEO_BUFFER_H
|
|
|
|
#define VIDEO_BUFFER_H
|
2017-12-12 15:12:07 +01:00
|
|
|
|
2019-03-02 23:52:22 +01:00
|
|
|
#include <stdbool.h>
|
2017-12-15 17:34:16 +01:00
|
|
|
#include <SDL2/SDL_mutex.h>
|
2017-12-12 15:12:07 +01:00
|
|
|
|
2021-01-08 19:18:02 +01:00
|
|
|
#include "common.h"
|
2018-08-15 17:01:54 +02:00
|
|
|
#include "fps_counter.h"
|
2018-02-07 12:25:52 +01:00
|
|
|
|
2017-12-12 15:12:07 +01:00
|
|
|
// forward declarations
|
|
|
|
typedef struct AVFrame AVFrame;
|
|
|
|
|
2019-03-02 15:16:55 +01:00
|
|
|
struct video_buffer {
|
2017-12-12 15:12:07 +01:00
|
|
|
AVFrame *decoding_frame;
|
|
|
|
AVFrame *rendering_frame;
|
|
|
|
SDL_mutex *mutex;
|
2019-06-05 19:02:50 +02:00
|
|
|
bool render_expired_frames;
|
2019-03-02 23:52:22 +01:00
|
|
|
bool interrupted;
|
2017-12-12 15:12:07 +01:00
|
|
|
SDL_cond *rendering_frame_consumed_cond;
|
2019-03-02 23:52:22 +01:00
|
|
|
bool rendering_frame_consumed;
|
2019-06-07 16:55:19 +02:00
|
|
|
struct fps_counter *fps_counter;
|
2017-12-12 15:12:07 +01:00
|
|
|
};
|
|
|
|
|
2019-03-02 23:52:22 +01:00
|
|
|
bool
|
2019-06-07 16:55:19 +02:00
|
|
|
video_buffer_init(struct video_buffer *vb, struct fps_counter *fps_counter,
|
|
|
|
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
|
2018-02-08 19:23:24 +01:00
|
|
|
// this function locks frames->mutex during its execution
|
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
|
|
|
|
// MUST be called with frames->mutex locked!!!
|
|
|
|
// the caller is expected to render the returned frame to some texture before
|
|
|
|
// unlocking frames->mutex
|
2019-03-02 20:09:56 +01:00
|
|
|
const AVFrame *
|
|
|
|
video_buffer_consume_rendered_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
|