2019-03-02 22:16:55 +08:00
|
|
|
#include "video_buffer.h"
|
|
|
|
|
2019-11-28 04:11:40 +08:00
|
|
|
#include <assert.h>
|
2019-03-02 22:16:55 +08:00
|
|
|
#include <libavutil/avutil.h>
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
|
2019-11-24 18:53:00 +08:00
|
|
|
#include "util/log.h"
|
2019-03-02 22:16:55 +08:00
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2021-07-04 18:42:22 +08:00
|
|
|
sc_video_buffer_init(struct sc_video_buffer *vb,
|
|
|
|
const struct sc_video_buffer_callbacks *cbs,
|
|
|
|
void *cbs_userdata) {
|
|
|
|
bool ok = sc_frame_buffer_init(&vb->fb);
|
|
|
|
if (!ok) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(cbs);
|
|
|
|
assert(cbs->on_new_frame);
|
|
|
|
|
|
|
|
vb->cbs = cbs;
|
|
|
|
vb->cbs_userdata = cbs_userdata;
|
|
|
|
return true;
|
2019-03-02 22:16:55 +08:00
|
|
|
}
|
|
|
|
|
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) {
|
2021-07-04 18:39:03 +08:00
|
|
|
sc_frame_buffer_destroy(&vb->fb);
|
2019-03-02 22:16:55 +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) {
|
|
|
|
bool previous_skipped;
|
|
|
|
bool ok = sc_frame_buffer_push(&vb->fb, frame, &previous_skipped);
|
|
|
|
if (!ok) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
vb->cbs->on_new_frame(vb, previous_skipped, vb->cbs_userdata);
|
|
|
|
return true;
|
2019-03-02 22:16:55 +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) {
|
2021-07-04 18:39:03 +08:00
|
|
|
sc_frame_buffer_consume(&vb->fb, dst);
|
2019-03-02 22:16:55 +08:00
|
|
|
}
|