mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-04-21 01:33:36 +00:00
Use a callback to notify a new frame
Make the decoder independant of the SDL even mechanism, by registering a callback on the video_buffer.
This commit is contained in:
parent
72df2c23f9
commit
b1c7c71160
4 changed files with 46 additions and 10 deletions
|
|
@ -7,7 +7,9 @@
|
|||
#include "util/log.h"
|
||||
|
||||
bool
|
||||
video_buffer_init(struct video_buffer *vb, bool wait_consumer) {
|
||||
video_buffer_init(struct video_buffer *vb, bool wait_consumer,
|
||||
const struct video_buffer_callbacks *cbs,
|
||||
void *cbs_userdata) {
|
||||
vb->producer_frame = av_frame_alloc();
|
||||
if (!vb->producer_frame) {
|
||||
goto error_0;
|
||||
|
|
@ -43,6 +45,11 @@ video_buffer_init(struct video_buffer *vb, bool wait_consumer) {
|
|||
// there is initially no frame, so consider it has already been consumed
|
||||
vb->pending_frame_consumed = true;
|
||||
|
||||
assert(cbs);
|
||||
assert(cbs->on_frame_available);
|
||||
vb->cbs = cbs;
|
||||
vb->cbs_userdata = cbs_userdata;
|
||||
|
||||
return true;
|
||||
|
||||
error_3:
|
||||
|
|
@ -95,10 +102,17 @@ video_buffer_producer_offer_frame(struct video_buffer *vb,
|
|||
|
||||
video_buffer_swap_producer_frame(vb);
|
||||
|
||||
*previous_frame_skipped = !vb->pending_frame_consumed;
|
||||
bool skipped = !vb->pending_frame_consumed;
|
||||
*previous_frame_skipped = skipped;
|
||||
vb->pending_frame_consumed = false;
|
||||
|
||||
sc_mutex_unlock(&vb->mutex);
|
||||
|
||||
if (!skipped) {
|
||||
// If skipped, then the previous call will consume this frame, the
|
||||
// callback must not be called
|
||||
vb->cbs->on_frame_available(vb, vb->cbs_userdata);
|
||||
}
|
||||
}
|
||||
|
||||
const AVFrame *
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue