From patchwork Fri Nov 10 19:29:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bolshoy Toster X-Patchwork-Id: 44610 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4f99:b0:181:818d:5e7f with SMTP id gh25csp483606pzb; Fri, 10 Nov 2023 11:29:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUxlbSIGSvx5cYhXb48Us4W2hu6xSUy7Xsj5EJD2v13yZZdkuxcp/rUbc4ZymM3lRgvHzC X-Received: by 2002:a17:907:9620:b0:9d3:e48f:30d3 with SMTP id gb32-20020a170907962000b009d3e48f30d3mr8473213ejc.31.1699644564847; Fri, 10 Nov 2023 11:29:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699644564; cv=none; d=google.com; s=arc-20160816; b=DA97NPcc4fWjqFoHGiQFVMsNzA8vhNveNBqs4hxs5kUv+DsG55yWkz0msjZoN6IiGc a5rKGtJ4bXcVsh8V/onZTupXBj++H+Puo8LuMZGh46Ua2xAxpDdKofoBjnO0rIaeGv55 yjLGxd80bf/AL/uuw/Ky1U3lQwbqbJz3jLPfM6sXAvKpDIJnGAnJM0ZPAumdB6hmEjtx 68FEuOy3A98cdLDsUJkTQCuRhb2Dt/fQQY4xdCyMB9SRe9s0f4U+y/e3dbwgQv2uNHUP R29ZMpDGiz7ADzrZ5JqtzH0YY+DLON5qPoX8/if+fe/vbUxQGoI7nVmCagznGfIqvQtS CNEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:content-language:to:from:user-agent:mime-version :date:message-id:dkim-signature:delivered-to; bh=TDCHAEWhSGYoEceHIk4xlPGATm9CPa1gDsAmZYbK+fQ=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=PsFLjRx9PjxA+5HLuf8XJgXIP+GC3FY3D/R3Wp8T1Qkbt6onmfRaLv1EUzRCVkq/hF rIeOPmpf3GJNdvCY4iqSL94sc5OBymDrF/Qpj9e5OKuK7nf/RS7RDmHki+qR+JHFINQP 5F6xDDywUh/0dguhd4auI/oAQmvhNkYuSc4AxKtmEaZ6PypTZcAs4WZrCPlrg3a/VQpA tDdQ1+U+kp6+4YsgFjb/UdjqSIxwxBwl71LyjsNh5IxtufLnQ/2SqkIPNla9YrItWW6e Fies5Q+oqqVawCDBjfTZ+yhrsY9p86eN2ws+EMY19TczV/BYHoqS26d710z+2fAGrBkV OmiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=IQteOiS2; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qf4-20020a1709077f0400b009b653f79463si4829537ejc.170.2023.11.10.11.29.24; Fri, 10 Nov 2023 11:29:24 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=IQteOiS2; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A079C68CC28; Fri, 10 Nov 2023 21:29:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3A54068CA0A for ; Fri, 10 Nov 2023 21:29:14 +0200 (EET) Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-40790b0a224so17528925e9.0 for ; Fri, 10 Nov 2023 11:29:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699644553; x=1700249353; 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=eGMrDEq1WfL5jwLwXzBx/Yacg+0FwWZcJxU3U7qqz60=; b=IQteOiS2/rTgomi7v8weFkfUHuMRAZOqMVuFH7UbBH1SVY9An/++JikzwWsVNOMm3k IRItE2aMHz2cOk6FQln+IcJJjrSuMQLVp6coUlwaUlQM6G/Nz2Lsd79hjV6cexvhalIK ByRal41zJvyUXNOEsucvIuOTWD20MiHO5o89ty7Ohx3SWZWDTWLhIaGfpslc1zXiYQ0N m8KeBGqyBUO694G9m+RoBI0Akc1nLanJvzLHVb8JEWhBzba+55cmEyWTawHp7giD8lw/ LcNDRlYFVURw0+TOq+ZC5KNRF1RMPkiR3GYoYt38maLpLQLKrslnQ/U+NUbYbQcN92Y6 mwFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699644553; x=1700249353; 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=eGMrDEq1WfL5jwLwXzBx/Yacg+0FwWZcJxU3U7qqz60=; b=qoKIMkgZFUxfwpUhgpNzlNvFJ6qV4350eIPsuxcNZmIzR8JCmZpNiPeqWt3MNY5ude pAN0F6pduW6XjkdyUMH0/fZQyanu9eeNdd4byKCaRJ3BKEGRgkpsMLF1FAXpTpdSLX4J odCQBQIUg3Oib+ddSttypWiB8La3w7sLFLQo0bI8EI67ndoPlotxT9Ld9xx6aHbMNMpX x0QIAELQb2aR5poUXdRE2nOvaJfWNHkNtidGLeRwmL2h5i7qooRDnTVTxaBg9r/N/nXC 7h+oIdNGYlKCbOfJ9rCa3CJrAymXGHRFYFg6cQqEurxHd7YXWk91m7G1jhW6NS/tRftJ e6zQ== X-Gm-Message-State: AOJu0Yxz12/XG0ygJgPSoghQQ1OZ7Vt+sw1kCx+QcOkRtMGqiDEPunyU ftaqHmMv1dfjlmFyJLKYH3GZ9R9tFZtqAw== X-Received: by 2002:a05:600c:4f11:b0:408:3eaa:aea6 with SMTP id l17-20020a05600c4f1100b004083eaaaea6mr260004wmq.7.1699644553125; Fri, 10 Nov 2023 11:29:13 -0800 (PST) Received: from [192.168.0.21] ([2.126.92.144]) by smtp.gmail.com with ESMTPSA id e10-20020a05600c4e4a00b004063ea92492sm231319wmq.22.2023.11.10.11.29.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Nov 2023 11:29:11 -0800 (PST) Message-ID: Date: Fri, 10 Nov 2023 19:29:09 +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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: zUjYOzwjrFIE 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 --- fftools/ffplay.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) + SDL_PumpEvents(); + } } } -- 2.42.1 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);