diff mbox series

[FFmpeg-devel] fftools/ffplay: use SDL_WaitEvent instead of SDL_PeepEvents while paused

Message ID d65b76a7-864a-4f6f-b9de-7f47ad99f104@gmail.com
State New
Headers show
Series [FFmpeg-devel] fftools/ffplay: use SDL_WaitEvent instead of SDL_PeepEvents while paused | expand

Checks

Context Check Description
andriy/configure_x86 warning Failed to apply patch
yinshiyou/configure_loongarch64 warning Failed to apply patch

Commit Message

Bolshoy Toster Nov. 7, 2023, 8:57 p.m. UTC
Currently, when ffplay is paused, it still constantly polls for events 
at the
REFRESH_RATE (100 times per second). This leads to a high (5-10% on the 
latest
commit, using SDL2 2.28.5-1) CPU usage, when it should be idle.

This commit changes this behavior to use SDL_WaitEvent while paused, 
allowing
ffplay to use less (0-5% under X11) CPU time while paused on supported 
platforms
(windows, X11 and wayland) with SDL versions >=2.0.16.

This has the side effect of only running the refresh loop when there's 
an event,
preventing the cursor from being hidden while paused.

Signed-off-by: bolshoytoster <toasterbig@gmail.com>
---
  fftools/ffplay.c | 31 ++++++++++++++++++++-----------
  1 file changed, 20 insertions(+), 11 deletions(-)

+            SDL_PumpEvents();
+        }
      }
  }
  -- 2.42.1

Comments

Michael Niedermayer Nov. 8, 2023, 11:33 p.m. UTC | #1
On Tue, Nov 07, 2023 at 08:57:57PM +0000, Bolshoy Toster wrote:
> Currently, when ffplay is paused, it still constantly polls for events at
> the
> REFRESH_RATE (100 times per second). This leads to a high (5-10% on the
> latest
> commit, using SDL2 2.28.5-1) CPU usage, when it should be idle.
> 
> This commit changes this behavior to use SDL_WaitEvent while paused,
> allowing
> ffplay to use less (0-5% under X11) CPU time while paused on supported
> platforms
> (windows, X11 and wayland) with SDL versions >=2.0.16.
> 
> This has the side effect of only running the refresh loop when there's an
> event,
> preventing the cursor from being hidden while paused.
> 
> Signed-off-by: bolshoytoster <toasterbig@gmail.com>
> ---
>  fftools/ffplay.c | 31 ++++++++++++++++++++-----------
>  1 file changed, 20 insertions(+), 11 deletions(-)
> 
> diff --git a/fftools/ffplay.c b/fftools/ffplay.c
> index d8c69e1..7814589 100644
> --- a/fftools/ffplay.c
> +++ b/fftools/ffplay.c
> @@ -3221,20 +3221,29 @@ static void toggle_audio_display(VideoState *is)
>      }
>  }
>  +static void refresh(VideoState *is, double *remaining_time) {
> +    if (!cursor_hidden && av_gettime_relative() - cursor_last_shown >
> CURSOR_HIDE_DELAY) {
> +        SDL_ShowCursor(0);

patch corupted by line breaks

Applying: fftools/ffplay: use SDL_WaitEvent instead of SDL_PeepEvents while paused
error: corrupt patch at line 50


[...]
diff mbox series

Patch

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index d8c69e1..7814589 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -3221,20 +3221,29 @@  static void toggle_audio_display(VideoState *is)
      }
  }
  +static void refresh(VideoState *is, double *remaining_time) {
+    if (!cursor_hidden && av_gettime_relative() - cursor_last_shown > 
CURSOR_HIDE_DELAY) {
+        SDL_ShowCursor(0);
+        cursor_hidden = 1;
+    }
+    if (*remaining_time > 0.0)
+        av_usleep((int64_t)(*remaining_time * 1000000.0));
+    *remaining_time = REFRESH_RATE;
+    if (is->show_mode != SHOW_MODE_NONE && (!is->paused || 
is->force_refresh))
+        video_refresh(is, remaining_time);
+}
+
  static void refresh_loop_wait_event(VideoState *is, SDL_Event *event) {
      double remaining_time = 0.0;
-    SDL_PumpEvents();
-    while (!SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, 
SDL_LASTEVENT)) {
-        if (!cursor_hidden && av_gettime_relative() - cursor_last_shown 
 > CURSOR_HIDE_DELAY) {
-            SDL_ShowCursor(0);
-            cursor_hidden = 1;
-        }
-        if (remaining_time > 0.0)
-            av_usleep((int64_t)(remaining_time * 1000000.0));
-        remaining_time = REFRESH_RATE;
-        if (is->show_mode != SHOW_MODE_NONE && (!is->paused || 
is->force_refresh))
-            video_refresh(is, &remaining_time);
+    if (is->paused) {
+        refresh(is, &remaining_time);
+        SDL_WaitEvent(event);
+    } else {
          SDL_PumpEvents();
+        while (!SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, 
SDL_LASTEVENT)) {
+            refresh(is, &remaining_time);