mirror of
https://github.com/Genymobile/scrcpy
synced 2024-11-18 21:26:07 +00:00
f410f2bdc4
A video buffer had 2 responsibilities: - handle the frame delaying mechanism (queuing packets and pushing them after the expected delay); - keep only the most recent frame (using a sc_frame_buffer). In order to be able to reuse only the frame delaying mechanism, extract it to a separate component, sc_delay_buffer.
70 lines
1.4 KiB
C
70 lines
1.4 KiB
C
#ifndef SC_DELAY_BUFFER_H
|
|
#define SC_DELAY_BUFFER_H
|
|
|
|
#include "common.h"
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "clock.h"
|
|
#include "util/thread.h"
|
|
#include "util/tick.h"
|
|
#include "util/vecdeque.h"
|
|
|
|
// forward declarations
|
|
typedef struct AVFrame AVFrame;
|
|
|
|
struct sc_delayed_frame {
|
|
AVFrame *frame;
|
|
#ifndef NDEBUG
|
|
sc_tick push_date;
|
|
#endif
|
|
};
|
|
|
|
struct sc_delayed_frame_queue SC_VECDEQUE(struct sc_delayed_frame);
|
|
|
|
struct sc_delay_buffer {
|
|
sc_tick delay;
|
|
|
|
// only if delay > 0
|
|
struct {
|
|
sc_thread thread;
|
|
sc_mutex mutex;
|
|
sc_cond queue_cond;
|
|
sc_cond wait_cond;
|
|
|
|
struct sc_clock clock;
|
|
struct sc_delayed_frame_queue queue;
|
|
bool stopped;
|
|
} b; // buffering
|
|
|
|
const struct sc_delay_buffer_callbacks *cbs;
|
|
void *cbs_userdata;
|
|
};
|
|
|
|
struct sc_delay_buffer_callbacks {
|
|
bool (*on_new_frame)(struct sc_delay_buffer *db, const AVFrame *frame,
|
|
void *userdata);
|
|
};
|
|
|
|
bool
|
|
sc_delay_buffer_init(struct sc_delay_buffer *db, sc_tick delay,
|
|
const struct sc_delay_buffer_callbacks *cbs,
|
|
void *cbs_userdata);
|
|
|
|
bool
|
|
sc_delay_buffer_start(struct sc_delay_buffer *db);
|
|
|
|
void
|
|
sc_delay_buffer_stop(struct sc_delay_buffer *db);
|
|
|
|
void
|
|
sc_delay_buffer_join(struct sc_delay_buffer *db);
|
|
|
|
void
|
|
sc_delay_buffer_destroy(struct sc_delay_buffer *db);
|
|
|
|
bool
|
|
sc_delay_buffer_push(struct sc_delay_buffer *db, const AVFrame *frame);
|
|
|
|
#endif
|