mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-21 03:55:05 +00:00
Expose screen as frame sink
Make screen implement the frame sink trait. This will allow the decoder to push frames without depending on the concrete sink type.
This commit is contained in:
parent
bb6ac2b084
commit
6d8f0a247f
2 changed files with 36 additions and 0 deletions
|
@ -13,6 +13,8 @@
|
|||
|
||||
#define DISPLAY_MARGINS 96
|
||||
|
||||
#define DOWNCAST(SINK) container_of(SINK, struct screen, frame_sink)
|
||||
|
||||
static inline struct size
|
||||
get_rotated_size(struct size size, int rotation) {
|
||||
struct size rotated_size;
|
||||
|
@ -262,6 +264,29 @@ event_watcher(void *data, SDL_Event *event) {
|
|||
}
|
||||
#endif
|
||||
|
||||
static bool
|
||||
screen_frame_sink_open(struct sc_frame_sink *sink) {
|
||||
struct screen *screen = DOWNCAST(sink);
|
||||
(void) screen;
|
||||
|
||||
// nothing to do, the screen is already open on the main thread
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
screen_frame_sink_close(struct sc_frame_sink *sink) {
|
||||
struct screen *screen = DOWNCAST(sink);
|
||||
(void) screen;
|
||||
|
||||
// nothing to do, the screen lifecycle is not managed by the frame producer
|
||||
}
|
||||
|
||||
static bool
|
||||
screen_frame_sink_push(struct sc_frame_sink *sink, const AVFrame *frame) {
|
||||
struct screen *screen = DOWNCAST(sink);
|
||||
return video_buffer_push(screen->vb, frame);
|
||||
}
|
||||
|
||||
bool
|
||||
screen_init(struct screen *screen, struct video_buffer *vb,
|
||||
struct fps_counter *fps_counter,
|
||||
|
@ -402,6 +427,14 @@ screen_init(struct screen *screen, struct video_buffer *vb,
|
|||
SDL_AddEventWatch(event_watcher, screen);
|
||||
#endif
|
||||
|
||||
static const struct sc_frame_sink_ops ops = {
|
||||
.open = screen_frame_sink_open,
|
||||
.close = screen_frame_sink_close,
|
||||
.push = screen_frame_sink_push,
|
||||
};
|
||||
|
||||
screen->frame_sink.ops = &ops;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,10 +9,13 @@
|
|||
|
||||
#include "coords.h"
|
||||
#include "opengl.h"
|
||||
#include "trait/frame_sink.h"
|
||||
|
||||
struct video_buffer;
|
||||
|
||||
struct screen {
|
||||
struct sc_frame_sink frame_sink; // frame sink trait
|
||||
|
||||
struct video_buffer *vb;
|
||||
struct fps_counter *fps_counter;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue