* [FFmpeg-devel] [PATCH] fftools/ffplay: use SDL_WaitEvent instead of SDL_PeepEvents while paused
@ 2023-11-10 19:29 Bolshoy Toster
2023-11-10 20:01 ` Marton Balint
0 siblings, 1 reply; 4+ messages in thread
From: Bolshoy Toster @ 2023-11-10 19:29 UTC (permalink / raw)
To: ffmpeg-devel
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 behaviour 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);
+ 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);
+ SDL_PumpEvents();
+ }
}
}
-- 2.42.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] fftools/ffplay: use SDL_WaitEvent instead of SDL_PeepEvents while paused
2023-11-10 19:29 [FFmpeg-devel] [PATCH] fftools/ffplay: use SDL_WaitEvent instead of SDL_PeepEvents while paused Bolshoy Toster
@ 2023-11-10 20:01 ` Marton Balint
0 siblings, 0 replies; 4+ messages in thread
From: Marton Balint @ 2023-11-10 20:01 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Fri, 10 Nov 2023, 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 behaviour 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.
Was this always this way? Or upstream SDL changed something making the
Pump/GetEvent more resource intensive? Polling like 100 times per
second should not cause 10% cpu usage...
ALso, can this patch be made less intrusive? E.g. changing current code
around av_usleep(remainig time) to:
if (*remainig_time > 0.0) {
if (is->paused)
SDL_WaitEventTimeout(NULL, 100);
else
av_usleep()
}
Regards,
Marton
>
> 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);
> + 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);
> + SDL_PumpEvents();
> + }
> }
> }
> -- 2.42.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH] fftools/ffplay: use SDL_WaitEvent instead of SDL_PeepEvents while paused
@ 2023-11-07 20:57 Bolshoy Toster
2023-11-08 23:33 ` Michael Niedermayer
0 siblings, 1 reply; 4+ messages in thread
From: Bolshoy Toster @ 2023-11-07 20:57 UTC (permalink / raw)
To: ffmpeg-devel
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);
+ 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);
+ SDL_PumpEvents();
+ }
}
}
-- 2.42.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] fftools/ffplay: use SDL_WaitEvent instead of SDL_PeepEvents while paused
2023-11-07 20:57 Bolshoy Toster
@ 2023-11-08 23:33 ` Michael Niedermayer
0 siblings, 0 replies; 4+ messages in thread
From: Michael Niedermayer @ 2023-11-08 23:33 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1643 bytes --]
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
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
"I am not trying to be anyone's saviour, I'm trying to think about the
future and not be sad" - Elon Musk
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-10 20:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-10 19:29 [FFmpeg-devel] [PATCH] fftools/ffplay: use SDL_WaitEvent instead of SDL_PeepEvents while paused Bolshoy Toster
2023-11-10 20:01 ` Marton Balint
-- strict thread matches above, loose matches on Subject: below --
2023-11-07 20:57 Bolshoy Toster
2023-11-08 23:33 ` Michael Niedermayer
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git