mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-02-01 12:04:35 +01:00
Currently, a frame is available to the consumer as soon as it is pushed by the producer (which can detect if the previous frame is skipped). Notify the new frames (and frame skipped) via callbacks instead. This paves the way to add (optional) buffering, which will introduce a delay between the time when the frame is produced and the time it is available to be consumed.
47 lines
1.0 KiB
C
47 lines
1.0 KiB
C
#include "video_buffer.h"
|
|
|
|
#include <assert.h>
|
|
#include <libavutil/avutil.h>
|
|
#include <libavformat/avformat.h>
|
|
|
|
#include "util/log.h"
|
|
|
|
bool
|
|
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;
|
|
}
|
|
|
|
void
|
|
sc_video_buffer_destroy(struct sc_video_buffer *vb) {
|
|
sc_frame_buffer_destroy(&vb->fb);
|
|
}
|
|
|
|
bool
|
|
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;
|
|
}
|
|
|
|
void
|
|
sc_video_buffer_consume(struct sc_video_buffer *vb, AVFrame *dst) {
|
|
sc_frame_buffer_consume(&vb->fb, dst);
|
|
}
|