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 276EB47FD6 for ; Tue, 7 Nov 2023 20:58:07 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 63FC168CB55; Tue, 7 Nov 2023 22:58:05 +0200 (EET) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD7F668CAE0 for ; Tue, 7 Nov 2023 22:57:58 +0200 (EET) Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4084de32db5so52692955e9.0 for ; Tue, 07 Nov 2023 12:57:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699390678; x=1699995478; darn=ffmpeg.org; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=08omm95qJR2koR6SYNVKseX4J1Gj7N3Fvt7gISHb5I0=; b=Q7q2DKHaXC0UzPl+RgZuNnN2HmK2g8kwgllSTO0p7BHxh10Leb26zaztY5TQfTLlUQ kg5JUwQp+kAvymXrb79UbFf7HzhkDVrouJAuT/XkLiHNkWWAPzrLhopBT/cMOg/mc56b x56jEzQhBJZPCiooeo3bNXNvLvkLJ/D9x/Wwkrth1382L/69ZntPcOTiYaFaDf5RLBhK svCDGGsGQjM35Si5EyGirDbUd2k/p7M8/X8KxiOltDomIF8JpMkmqG+d34VxIoNBGy5c WNr9f95rthMtOAeCwhxaf6b7U7mGrjEf2e53fcqohhSk4p1k0GQu3pjtO3/ivPgwTbSW ECrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699390678; x=1699995478; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=08omm95qJR2koR6SYNVKseX4J1Gj7N3Fvt7gISHb5I0=; b=SbWWQImx2u5V+4ldktXyCbkglFu2YbH6Z9+jx1NyvWlOdfUT8V+W2t+MYefPPUO64A w7NZSUenxtKMZ6rocj4iYfVCSZN/AogH4dH80wKHgk4z3U9Gs6NEFQNgVnKy35AYvgYF P7AmE4svhsKrXCFZN7ugOWoexrFRbt/dxT7Ii6jJx5w/EJesQp0I/5YjpsuwgvuZu8+S /capYYNs3I2chBx/ShG5DXYSVmCQeKFtvmcWQcd/VAAxS6oECohRruKYtG07Mjy7xzcx 7jfHCuD9Rf+PtlseDPap/gK64IAodByKPQpDzYCQkL53G6El24aBlDHNPAwG2ZOjn1ZW 3oHw== X-Gm-Message-State: AOJu0YwctPx9QPgFpS8rfjZp/8a+Vi2t7lQasev88CRIwS77VdS0jmAp ZV3rDio4CzJCzgRWjtbSy3ti4Vqpw/Xw5w== X-Google-Smtp-Source: AGHT+IHpPQVFKEeQ4Pwl7S+gqX9e6uU33D3lXMOEPhI63r35kQpmH99PGh+ecWXY1POnye0UkywzmA== X-Received: by 2002:a05:600c:4f87:b0:407:5b54:bb15 with SMTP id n7-20020a05600c4f8700b004075b54bb15mr96181wmq.36.1699390678021; Tue, 07 Nov 2023 12:57:58 -0800 (PST) Received: from [192.168.0.21] ([2.126.92.144]) by smtp.gmail.com with ESMTPSA id n26-20020a1c721a000000b0040849ce7116sm16524410wmc.43.2023.11.07.12.57.57 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Nov 2023 12:57:57 -0800 (PST) Message-ID: Date: Tue, 7 Nov 2023 20:57:57 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Bolshoy Toster To: ffmpeg-devel@ffmpeg.org Content-Language: en-US Subject: [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: 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 --- 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".