diff --git a/app/src/decoder.c b/app/src/decoder.c index 23f9ce9d..4b1f0fce 100644 --- a/app/src/decoder.c +++ b/app/src/decoder.c @@ -18,6 +18,7 @@ push_frame(struct decoder *decoder) { video_buffer_offer_decoded_frame(decoder->video_buffer, &previous_frame_skipped); if (previous_frame_skipped) { + fps_counter_add_skipped_frame(decoder->fps_counter); // the previous EVENT_NEW_FRAME will consume this frame return; } @@ -28,8 +29,10 @@ push_frame(struct decoder *decoder) { } void -decoder_init(struct decoder *decoder, struct video_buffer *vb) { +decoder_init(struct decoder *decoder, struct video_buffer *vb, + struct fps_counter *fps_counter) { decoder->video_buffer = vb; + decoder->fps_counter = fps_counter; } bool diff --git a/app/src/decoder.h b/app/src/decoder.h index 27afcd8e..306cc77c 100644 --- a/app/src/decoder.h +++ b/app/src/decoder.h @@ -10,11 +10,14 @@ struct video_buffer; struct decoder { struct video_buffer *video_buffer; + struct fps_counter *fps_counter; + AVCodecContext *codec_ctx; }; void -decoder_init(struct decoder *decoder, struct video_buffer *vb); +decoder_init(struct decoder *decoder, struct video_buffer *vb, + struct fps_counter *fps_counter); bool decoder_open(struct decoder *decoder, const AVCodec *codec); diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 20ea05c5..7226d68f 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -480,9 +480,7 @@ input_manager_process_key(struct input_manager *im, return; case SDLK_i: if (!shift && !repeat && down) { - struct fps_counter *fps_counter = - im->video_buffer->fps_counter; - switch_fps_counter_state(fps_counter); + switch_fps_counter_state(im->fps_counter); } return; case SDLK_n: diff --git a/app/src/input_manager.h b/app/src/input_manager.h index 6acb354d..d10c96b5 100644 --- a/app/src/input_manager.h +++ b/app/src/input_manager.h @@ -16,6 +16,7 @@ struct input_manager { struct controller *controller; struct video_buffer *video_buffer; + struct fps_counter *fps_counter; struct screen *screen; // SDL reports repeated events as a boolean, but Android expects the actual diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index d24bba2c..a671c5e4 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -42,6 +42,7 @@ static struct file_handler file_handler; static struct input_manager input_manager = { .controller = &controller, .video_buffer = &video_buffer, + .fps_counter = &fps_counter, .screen = &screen, .repeat = 0, @@ -332,8 +333,7 @@ scrcpy(const struct scrcpy_options *options) { } fps_counter_initialized = true; - if (!video_buffer_init(&video_buffer, &fps_counter, - options->render_expired_frames)) { + if (!video_buffer_init(&video_buffer, options->render_expired_frames)) { goto end; } video_buffer_initialized = true; @@ -346,7 +346,7 @@ scrcpy(const struct scrcpy_options *options) { file_handler_initialized = true; } - decoder_init(&decoder, &video_buffer); + decoder_init(&decoder, &video_buffer, &fps_counter); dec = &decoder; } @@ -389,7 +389,7 @@ scrcpy(const struct scrcpy_options *options) { const char *window_title = options->window_title ? options->window_title : device_name; - screen_init(&screen, &video_buffer); + screen_init(&screen, &video_buffer, &fps_counter); if (!screen_init_rendering(&screen, window_title, frame_size, options->always_on_top, options->window_x, diff --git a/app/src/screen.c b/app/src/screen.c index 4b0321eb..7c2cea04 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -192,9 +192,11 @@ screen_update_content_rect(struct screen *screen) { } void -screen_init(struct screen *screen, struct video_buffer *vb) { +screen_init(struct screen *screen, struct video_buffer *vb, + struct fps_counter *fps_counter) { *screen = (struct screen) SCREEN_INITIALIZER; screen->vb = vb; + screen->fps_counter = fps_counter; } static inline SDL_Texture * @@ -450,6 +452,9 @@ update_texture(struct screen *screen, const AVFrame *frame) { static bool screen_update_frame(struct screen *screen) { const AVFrame *frame = video_buffer_take_rendering_frame(screen->vb); + + fps_counter_add_rendered_frame(screen->fps_counter); + 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 f2224ff1..8941416e 100644 --- a/app/src/screen.h +++ b/app/src/screen.h @@ -14,6 +14,8 @@ struct video_buffer; struct screen { struct video_buffer *vb; + struct fps_counter *fps_counter; + SDL_Window *window; SDL_Renderer *renderer; SDL_Texture *texture; @@ -38,6 +40,7 @@ struct screen { #define SCREEN_INITIALIZER { \ .vb = NULL, \ + .fps_counter = NULL, \ .window = NULL, \ .renderer = NULL, \ .texture = NULL, \ @@ -70,7 +73,8 @@ struct screen { // initialize default values void -screen_init(struct screen *screen, struct video_buffer *vb); +screen_init(struct screen *screen, struct video_buffer *vb, + struct fps_counter *fps_counter); // initialize screen, create window, renderer and texture (window is hidden) // window_x and window_y accept SC_WINDOW_POSITION_UNDEFINED diff --git a/app/src/video_buffer.c b/app/src/video_buffer.c index 4c8dd5da..903df070 100644 --- a/app/src/video_buffer.c +++ b/app/src/video_buffer.c @@ -7,10 +7,7 @@ #include "util/log.h" bool -video_buffer_init(struct video_buffer *vb, struct fps_counter *fps_counter, - bool render_expired_frames) { - vb->fps_counter = fps_counter; - +video_buffer_init(struct video_buffer *vb, bool render_expired_frames) { vb->decoding_frame = av_frame_alloc(); if (!vb->decoding_frame) { goto error_0; @@ -95,8 +92,6 @@ video_buffer_offer_decoded_frame(struct video_buffer *vb, while (!vb->pending_frame_consumed && !vb->interrupted) { sc_cond_wait(&vb->pending_frame_consumed_cond, &vb->mutex); } - } else if (!vb->pending_frame_consumed) { - fps_counter_add_skipped_frame(vb->fps_counter); } video_buffer_swap_decoding_frame(vb); @@ -113,8 +108,6 @@ video_buffer_take_rendering_frame(struct video_buffer *vb) { assert(!vb->pending_frame_consumed); vb->pending_frame_consumed = true; - fps_counter_add_rendered_frame(vb->fps_counter); - video_buffer_swap_rendering_frame(vb); if (vb->render_expired_frames) { diff --git a/app/src/video_buffer.h b/app/src/video_buffer.h index 3e52caa7..4c82fba4 100644 --- a/app/src/video_buffer.h +++ b/app/src/video_buffer.h @@ -39,13 +39,10 @@ struct video_buffer { sc_cond pending_frame_consumed_cond; bool pending_frame_consumed; - - struct fps_counter *fps_counter; }; bool -video_buffer_init(struct video_buffer *vb, struct fps_counter *fps_counter, - bool render_expired_frames); +video_buffer_init(struct video_buffer *vb, bool render_expired_frames); void video_buffer_destroy(struct video_buffer *vb);