Reference video buffer from screen

This paves the way to handle EVENT_NEW_FRAME from screen.c, by allowing
to call screen_update_frame() without an explicit video_buffer instance.
filter.12
Romain Vimont 3 years ago
parent 0538e9645b
commit ea2369f568

@ -30,7 +30,7 @@
#include "util/net.h" #include "util/net.h"
static struct server server; static struct server server;
static struct screen screen = SCREEN_INITIALIZER; static struct screen screen;
static struct fps_counter fps_counter; static struct fps_counter fps_counter;
static struct video_buffer video_buffer; static struct video_buffer video_buffer;
static struct stream stream; static struct stream stream;
@ -179,7 +179,7 @@ handle_event(SDL_Event *event, const struct scrcpy_options *options) {
// this is the very first frame, show the window // this is the very first frame, show the window
screen_show_window(&screen); screen_show_window(&screen);
} }
if (!screen_update_frame(&screen, &video_buffer)) { if (!screen_update_frame(&screen)) {
return EVENT_RESULT_CONTINUE; return EVENT_RESULT_CONTINUE;
} }
break; break;
@ -429,6 +429,8 @@ scrcpy(const struct scrcpy_options *options) {
const char *window_title = const char *window_title =
options->window_title ? options->window_title : device_name; options->window_title ? options->window_title : device_name;
screen_init(&screen, &video_buffer);
if (!screen_init_rendering(&screen, window_title, frame_size, if (!screen_init_rendering(&screen, window_title, frame_size,
options->always_on_top, options->window_x, options->always_on_top, options->window_x,
options->window_y, options->window_width, options->window_y, options->window_width,

@ -191,8 +191,9 @@ screen_update_content_rect(struct screen *screen) {
} }
void void
screen_init(struct screen *screen) { screen_init(struct screen *screen, struct video_buffer *vb) {
*screen = (struct screen) SCREEN_INITIALIZER; *screen = (struct screen) SCREEN_INITIALIZER;
screen->vb = vb;
} }
static inline SDL_Texture * static inline SDL_Texture *
@ -446,8 +447,8 @@ update_texture(struct screen *screen, const AVFrame *frame) {
} }
bool bool
screen_update_frame(struct screen *screen, struct video_buffer *vb) { screen_update_frame(struct screen *screen) {
const AVFrame *frame = video_buffer_take_rendering_frame(vb); const AVFrame *frame = video_buffer_take_rendering_frame(screen->vb);
struct size new_frame_size = {frame->width, frame->height}; struct size new_frame_size = {frame->width, frame->height};
if (!prepare_for_frame(screen, new_frame_size)) { if (!prepare_for_frame(screen, new_frame_size)) {
return false; return false;

@ -13,6 +13,7 @@
struct video_buffer; struct video_buffer;
struct screen { struct screen {
struct video_buffer *vb;
SDL_Window *window; SDL_Window *window;
SDL_Renderer *renderer; SDL_Renderer *renderer;
SDL_Texture *texture; SDL_Texture *texture;
@ -37,6 +38,7 @@ struct screen {
}; };
#define SCREEN_INITIALIZER { \ #define SCREEN_INITIALIZER { \
.vb = NULL, \
.window = NULL, \ .window = NULL, \
.renderer = NULL, \ .renderer = NULL, \
.texture = NULL, \ .texture = NULL, \
@ -70,7 +72,7 @@ struct screen {
// initialize default values // initialize default values
void void
screen_init(struct screen *screen); screen_init(struct screen *screen, struct video_buffer *vb);
// initialize screen, create window, renderer and texture (window is hidden) // initialize screen, create window, renderer and texture (window is hidden)
// window_x and window_y accept SC_WINDOW_POSITION_UNDEFINED // window_x and window_y accept SC_WINDOW_POSITION_UNDEFINED
@ -91,7 +93,7 @@ screen_destroy(struct screen *screen);
// resize if necessary and write the rendered frame into the texture // resize if necessary and write the rendered frame into the texture
bool bool
screen_update_frame(struct screen *screen, struct video_buffer *vb); screen_update_frame(struct screen *screen);
// render the texture to the renderer // render the texture to the renderer
// //

Loading…
Cancel
Save