From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id B53DA47500 for ; Fri, 10 Nov 2023 20:01:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E468C68CC4E; Fri, 10 Nov 2023 22:01:26 +0200 (EET) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F137068CA14 for ; Fri, 10 Nov 2023 22:01:20 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 5DE2AE982C for ; Fri, 10 Nov 2023 21:01:20 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LkHIs37VbUPl for ; Fri, 10 Nov 2023 21:01:17 +0100 (CET) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id E17EEE97CA for ; Fri, 10 Nov 2023 21:01:16 +0100 (CET) Date: Fri, 10 Nov 2023 21:01:16 +0100 (CET) From: Marton Balint To: FFmpeg development discussions and patches In-Reply-To: Message-ID: References: MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH] fftools/ffplay: use SDL_WaitEvent instead of SDL_PeepEvents while paused X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 > --- > 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".