Skip to content

Display and control your Android device

Reference video buffer from screen

Romain Vimontea2369f568cc
diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c
index 505b5eaf..f669ef40 100644
--- a/app/src/scrcpy.c
+++ b/app/src/scrcpy.c
@@ -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,
diff --git a/app/src/screen.c b/app/src/screen.c
index 959af9c7..4d01ba7e 100644
--- a/app/src/screen.c
+++ b/app/src/screen.c
@@ -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;
diff --git a/app/src/screen.h b/app/src/screen.h
index 35d5df50..6db52dec 100644
--- a/app/src/screen.h
+++ b/app/src/screen.h
@@ -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
//