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.
This commit is contained in:
Romain Vimont 2021-04-11 15:01:05 +02:00
parent 6f5ad21f57
commit e91acdb0c4
3 changed files with 18 additions and 25 deletions

View file

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

View file

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

View file

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