2021-06-26 21:02:18 +08:00
|
|
|
#ifndef SC_VIDEO_BUFFER_H
|
|
|
|
#define SC_VIDEO_BUFFER_H
|
2017-12-12 22:12:07 +08:00
|
|
|
|
2021-01-09 02:24:51 +08:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdbool.h>
|
2017-12-12 22:12:07 +08:00
|
|
|
|
2021-07-04 21:24:51 +08:00
|
|
|
#include "clock.h"
|
2021-07-04 18:39:03 +08:00
|
|
|
#include "frame_buffer.h"
|
2021-07-04 21:24:51 +08:00
|
|
|
#include "util/queue.h"
|
|
|
|
#include "util/thread.h"
|
|
|
|
#include "util/tick.h"
|
2018-02-07 19:25:52 +08:00
|
|
|
|
2017-12-12 22:12:07 +08:00
|
|
|
// forward declarations
|
|
|
|
typedef struct AVFrame AVFrame;
|
|
|
|
|
2021-07-04 21:24:51 +08:00
|
|
|
struct sc_video_buffer_frame {
|
|
|
|
AVFrame *frame;
|
|
|
|
struct sc_video_buffer_frame *next;
|
2021-07-14 04:32:05 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
sc_tick push_date;
|
|
|
|
#endif
|
2021-07-04 21:24:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sc_video_buffer_frame_queue SC_QUEUE(struct sc_video_buffer_frame);
|
|
|
|
|
2021-06-26 21:02:18 +08:00
|
|
|
struct sc_video_buffer {
|
2021-07-04 18:39:03 +08:00
|
|
|
struct sc_frame_buffer fb;
|
2021-07-04 18:42:22 +08:00
|
|
|
|
2021-07-04 21:24:51 +08:00
|
|
|
sc_tick buffering_time;
|
|
|
|
|
|
|
|
// only if buffering_time > 0
|
|
|
|
struct {
|
|
|
|
sc_thread thread;
|
|
|
|
sc_mutex mutex;
|
|
|
|
sc_cond queue_cond;
|
|
|
|
sc_cond wait_cond;
|
|
|
|
|
|
|
|
struct sc_clock clock;
|
|
|
|
struct sc_video_buffer_frame_queue queue;
|
|
|
|
bool stopped;
|
|
|
|
} b; // buffering
|
|
|
|
|
2021-07-04 18:42:22 +08:00
|
|
|
const struct sc_video_buffer_callbacks *cbs;
|
|
|
|
void *cbs_userdata;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sc_video_buffer_callbacks {
|
|
|
|
void (*on_new_frame)(struct sc_video_buffer *vb, bool previous_skipped,
|
|
|
|
void *userdata);
|
2017-12-12 22:12:07 +08:00
|
|
|
};
|
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2021-07-04 21:24:51 +08:00
|
|
|
sc_video_buffer_init(struct sc_video_buffer *vb, sc_tick buffering_time,
|
2021-07-04 18:42:22 +08:00
|
|
|
const struct sc_video_buffer_callbacks *cbs,
|
|
|
|
void *cbs_userdata);
|
2019-03-03 03:09:56 +08:00
|
|
|
|
2021-07-04 21:24:51 +08:00
|
|
|
bool
|
|
|
|
sc_video_buffer_start(struct sc_video_buffer *vb);
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_video_buffer_stop(struct sc_video_buffer *vb);
|
|
|
|
|
|
|
|
void
|
|
|
|
sc_video_buffer_join(struct sc_video_buffer *vb);
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
void
|
2021-06-26 21:02:18 +08:00
|
|
|
sc_video_buffer_destroy(struct sc_video_buffer *vb);
|
2017-12-12 22:12:07 +08:00
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
bool
|
2021-07-04 18:42:22 +08:00
|
|
|
sc_video_buffer_push(struct sc_video_buffer *vb, const AVFrame *frame);
|
2018-02-09 02:23:24 +08:00
|
|
|
|
2021-04-11 21:01:05 +08:00
|
|
|
void
|
2021-06-26 21:02:18 +08:00
|
|
|
sc_video_buffer_consume(struct sc_video_buffer *vb, AVFrame *dst);
|
2017-12-12 22:12:07 +08:00
|
|
|
|
|
|
|
#endif
|