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.
This commit is contained in:
Romain Vimont 2021-02-15 18:28:41 +01:00
parent 0538e9645b
commit ea2369f568
3 changed files with 12 additions and 7 deletions

View file

@ -30,7 +30,7 @@
#include "util/net.h"
static struct server server;
static struct screen screen = SCREEN_INITIALIZER;
static struct screen screen;
static struct fps_counter fps_counter;
static struct video_buffer video_buffer;
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
screen_show_window(&screen);
}
if (!screen_update_frame(&screen, &video_buffer)) {
if (!screen_update_frame(&screen)) {
return EVENT_RESULT_CONTINUE;
}
break;
@ -429,6 +429,8 @@ scrcpy(const struct scrcpy_options *options) {
const char *window_title =
options->window_title ? options->window_title : device_name;
screen_init(&screen, &video_buffer);
if (!screen_init_rendering(&screen, window_title, frame_size,
options->always_on_top, options->window_x,
options->window_y, options->window_width,

View file

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

View file

@ -13,6 +13,7 @@
struct video_buffer;
struct screen {
struct video_buffer *vb;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;
@ -37,6 +38,7 @@ struct screen {
};
#define SCREEN_INITIALIZER { \
.vb = NULL, \
.window = NULL, \
.renderer = NULL, \
.texture = NULL, \
@ -70,7 +72,7 @@ struct screen {
// initialize default values
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)
// 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
bool
screen_update_frame(struct screen *screen, struct video_buffer *vb);
screen_update_frame(struct screen *screen);
// render the texture to the renderer
//