2019-03-02 22:16:55 +08:00
|
|
|
#ifndef VIDEO_BUFFER_H
|
|
|
|
#define VIDEO_BUFFER_H
|
2017-12-12 22:12:07 +08:00
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdbool.h>
|
2017-12-16 00:34:16 +08:00
|
|
|
#include <SDL2/SDL_mutex.h>
|
2017-12-12 22:12:07 +08:00
|
|
|
|
2019-09-30 04:36:56 +08:00
|
|
|
#include "config.h"
|
2018-08-15 23:01:54 +08:00
|
|
|
#include "fps_counter.h"
|
2018-02-07 19:25:52 +08:00
|
|
|
|
2017-12-12 22:12:07 +08:00
|
|
|
// forward declarations
|
|
|
|
typedef struct AVFrame AVFrame;
|
|
|
|
|
2019-03-02 22:16:55 +08:00
|
|
|
struct video_buffer {
|
2017-12-12 22:12:07 +08:00
|
|
|
AVFrame *decoding_frame;
|
|
|
|
AVFrame *rendering_frame;
|
|
|
|
SDL_mutex *mutex;
|
2019-06-06 01:02:50 +08:00
|
|
|
bool render_expired_frames;
|
2019-03-03 06:52:22 +08:00
|
|
|
bool interrupted;
|
2017-12-12 22:12:07 +08:00
|
|
|
SDL_cond *rendering_frame_consumed_cond;
|
2019-03-03 06:52:22 +08:00
|
|
|
bool rendering_frame_consumed;
|
2019-06-07 22:55:19 +08:00
|
|
|
struct fps_counter *fps_counter;
|
2017-12-12 22:12:07 +08:00
|
|
|
};
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2019-06-07 22:55:19 +08:00
|
|
|
video_buffer_init(struct video_buffer *vb, struct fps_counter *fps_counter,
|
|
|
|
bool render_expired_frames);
|
2019-03-03 03:09:56 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
video_buffer_destroy(struct video_buffer *vb);
|
2017-12-12 22:12:07 +08:00
|
|
|
|
2019-03-02 22:16:55 +08:00
|
|
|
// set the decoded frame as ready for rendering
|
2018-02-09 02:23:24 +08:00
|
|
|
// this function locks frames->mutex during its execution
|
2019-03-03 07:26:48 +08: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-09 02:23:24 +08: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-03 03:09:56 +08:00
|
|
|
const AVFrame *
|
|
|
|
video_buffer_consume_rendered_frame(struct video_buffer *vb);
|
2017-12-12 22:12:07 +08:00
|
|
|
|
2018-02-09 15:42:39 +08:00
|
|
|
// wake up and avoid any blocking call
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
|
|
|
video_buffer_interrupt(struct video_buffer *vb);
|
2018-02-09 15:42:39 +08:00
|
|
|
|
2017-12-12 22:12:07 +08:00
|
|
|
#endif
|