Move video_buffer to screen

The video buffer is now an internal detail of the screen component.

Since the screen is plugged to the decoder via the frame sink trait, the
decoder does not access to the video buffer anymore.
nosecureflag_quickfix
Romain Vimont 3 years ago
parent 6f5ad21f57
commit e91acdb0c4

@ -25,14 +25,12 @@
#include "server.h" #include "server.h"
#include "stream.h" #include "stream.h"
#include "tiny_xpm.h" #include "tiny_xpm.h"
#include "video_buffer.h"
#include "util/log.h" #include "util/log.h"
#include "util/net.h" #include "util/net.h"
static struct server server; static struct server server;
static struct screen screen; static struct screen screen;
static struct fps_counter fps_counter; static struct fps_counter fps_counter;
static struct video_buffer video_buffer;
static struct stream stream; static struct stream stream;
static struct decoder decoder; static struct decoder decoder;
static struct recorder recorder; static struct recorder recorder;
@ -247,7 +245,6 @@ scrcpy(const struct scrcpy_options *options) {
bool server_started = false; bool server_started = false;
bool fps_counter_initialized = false; bool fps_counter_initialized = false;
bool video_buffer_initialized = false;
bool file_handler_initialized = false; bool file_handler_initialized = false;
bool recorder_initialized = false; bool recorder_initialized = false;
bool stream_started = false; bool stream_started = false;
@ -305,11 +302,6 @@ scrcpy(const struct scrcpy_options *options) {
} }
fps_counter_initialized = true; fps_counter_initialized = true;
if (!video_buffer_init(&video_buffer)) {
goto end;
}
video_buffer_initialized = true;
if (options->control) { if (options->control) {
if (!file_handler_init(&file_handler, server.serial, if (!file_handler_init(&file_handler, server.serial,
options->push_target)) { options->push_target)) {
@ -376,8 +368,7 @@ scrcpy(const struct scrcpy_options *options) {
.fullscreen = options->fullscreen, .fullscreen = options->fullscreen,
}; };
if (!screen_init(&screen, &video_buffer, &fps_counter, if (!screen_init(&screen, &fps_counter, &screen_params)) {
&screen_params)) {
goto end; goto end;
} }
screen_initialized = true; screen_initialized = true;
@ -453,10 +444,6 @@ end:
file_handler_destroy(&file_handler); file_handler_destroy(&file_handler);
} }
if (video_buffer_initialized) {
video_buffer_destroy(&video_buffer);
}
if (fps_counter_initialized) { if (fps_counter_initialized) {
fps_counter_join(&fps_counter); fps_counter_join(&fps_counter);
fps_counter_destroy(&fps_counter); fps_counter_destroy(&fps_counter);

@ -284,14 +284,12 @@ screen_frame_sink_close(struct sc_frame_sink *sink) {
static bool static bool
screen_frame_sink_push(struct sc_frame_sink *sink, const AVFrame *frame) { screen_frame_sink_push(struct sc_frame_sink *sink, const AVFrame *frame) {
struct screen *screen = DOWNCAST(sink); struct screen *screen = DOWNCAST(sink);
return video_buffer_push(screen->vb, frame); return video_buffer_push(&screen->vb, frame);
} }
bool bool
screen_init(struct screen *screen, struct video_buffer *vb, screen_init(struct screen *screen, struct fps_counter *fps_counter,
struct fps_counter *fps_counter,
const struct screen_params *params) { const struct screen_params *params) {
screen->vb = vb;
screen->fps_counter = fps_counter; screen->fps_counter = fps_counter;
screen->resize_pending = false; screen->resize_pending = false;
@ -299,11 +297,17 @@ screen_init(struct screen *screen, struct video_buffer *vb,
screen->fullscreen = false; screen->fullscreen = false;
screen->maximized = false; screen->maximized = false;
bool ok = video_buffer_init(&screen->vb);
if (!ok) {
LOGE("Could not initialize video buffer");
return false;
}
static const struct video_buffer_callbacks cbs = { static const struct video_buffer_callbacks cbs = {
.on_frame_available = on_frame_available, .on_frame_available = on_frame_available,
.on_frame_skipped = on_frame_skipped, .on_frame_skipped = on_frame_skipped,
}; };
video_buffer_set_consumer_callbacks(vb, &cbs, screen); video_buffer_set_consumer_callbacks(&screen->vb, &cbs, screen);
screen->frame_size = params->frame_size; screen->frame_size = params->frame_size;
screen->rotation = params->rotation; screen->rotation = params->rotation;
@ -349,6 +353,7 @@ screen_init(struct screen *screen, struct video_buffer *vb,
if (!screen->renderer) { if (!screen->renderer) {
LOGC("Could not create renderer: %s", SDL_GetError()); LOGC("Could not create renderer: %s", SDL_GetError());
SDL_DestroyWindow(screen->window); SDL_DestroyWindow(screen->window);
video_buffer_destroy(&screen->vb);
return false; return false;
} }
@ -400,6 +405,7 @@ screen_init(struct screen *screen, struct video_buffer *vb,
LOGC("Could not create texture: %s", SDL_GetError()); LOGC("Could not create texture: %s", SDL_GetError());
SDL_DestroyRenderer(screen->renderer); SDL_DestroyRenderer(screen->renderer);
SDL_DestroyWindow(screen->window); SDL_DestroyWindow(screen->window);
video_buffer_destroy(&screen->vb);
return false; return false;
} }
@ -409,6 +415,7 @@ screen_init(struct screen *screen, struct video_buffer *vb,
SDL_DestroyTexture(screen->texture); SDL_DestroyTexture(screen->texture);
SDL_DestroyRenderer(screen->renderer); SDL_DestroyRenderer(screen->renderer);
SDL_DestroyWindow(screen->window); SDL_DestroyWindow(screen->window);
video_buffer_destroy(&screen->vb);
return false; return false;
} }
@ -449,6 +456,7 @@ screen_destroy(struct screen *screen) {
SDL_DestroyTexture(screen->texture); SDL_DestroyTexture(screen->texture);
SDL_DestroyRenderer(screen->renderer); SDL_DestroyRenderer(screen->renderer);
SDL_DestroyWindow(screen->window); SDL_DestroyWindow(screen->window);
video_buffer_destroy(&screen->vb);
} }
static void static void
@ -554,7 +562,7 @@ update_texture(struct screen *screen, const AVFrame *frame) {
static bool static bool
screen_update_frame(struct screen *screen) { screen_update_frame(struct screen *screen) {
av_frame_unref(screen->frame); av_frame_unref(screen->frame);
video_buffer_consume(screen->vb, screen->frame); video_buffer_consume(&screen->vb, screen->frame);
AVFrame *frame = screen->frame; AVFrame *frame = screen->frame;
fps_counter_add_rendered_frame(screen->fps_counter); fps_counter_add_rendered_frame(screen->fps_counter);

@ -10,13 +10,12 @@
#include "coords.h" #include "coords.h"
#include "opengl.h" #include "opengl.h"
#include "trait/frame_sink.h" #include "trait/frame_sink.h"
#include "video_buffer.h"
struct video_buffer;
struct screen { struct screen {
struct sc_frame_sink frame_sink; // frame sink trait struct sc_frame_sink frame_sink; // frame sink trait
struct video_buffer *vb; struct video_buffer vb;
struct fps_counter *fps_counter; struct fps_counter *fps_counter;
SDL_Window *window; SDL_Window *window;
@ -63,8 +62,7 @@ struct screen_params {
// initialize screen, create window, renderer and texture (window is hidden) // initialize screen, create window, renderer and texture (window is hidden)
bool bool
screen_init(struct screen *screen, struct video_buffer *vb, screen_init(struct screen *screen, struct fps_counter *fps_counter,
struct fps_counter *fps_counter,
const struct screen_params *params); const struct screen_params *params);
// destroy window, renderer and texture (if any) // destroy window, renderer and texture (if any)

Loading…
Cancel
Save