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 F318640D3A for ; Fri, 17 Mar 2023 06:32:23 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1985B68C184; Fri, 17 Mar 2023 08:32:20 +0200 (EET) Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3819468C0EB for ; Fri, 17 Mar 2023 08:32:14 +0200 (EET) Received: by mail-qt1-f172.google.com with SMTP id c19so4598695qtn.13 for ; Thu, 16 Mar 2023 23:32:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davyandbeth-com.20210112.gappssmtp.com; s=20210112; t=1679034732; h=content-transfer-encoding:to:content-language:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=azbcBynD9SoFg3wm34+6MbC1KHMkSEUB+tN158ZHRb0=; b=zpMUElg4h5zCrJX3GyFNzXaqCe3OHrj1IqHaJ3FqY+HrNJauvoNSRUmvJ9r/M/Zewn un90f5iW9ITDprb2qrLJ9ju7jN9pHGPCdlylfnH+4A2OWVnTEJVQYak7u5CW3I4YScEX VuhtsvbiM29lBDkTQx8RSAGO6uIs9fqjZF2iEBAeX4b0c3V4fn2nghmf2FX5vtVL0zit dvOAVktbqCFGsgEACp2TYUUMmPWZxeazg18kuGuNm23zgwhM19cWB/3+wVhgl3uCDM9Z 6fHSTS+E9GtJ7B8DEEajVcVjX87u9r+4O4+xbVtTiazzO5r29xlsgnSB96CE2vfGvc7Y RkOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679034732; h=content-transfer-encoding:to:content-language:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=azbcBynD9SoFg3wm34+6MbC1KHMkSEUB+tN158ZHRb0=; b=j3qyFTd9f9NoSAX7NhbP2LBdJ/OL0d/trG+lrqeGXqADafGFEhcsjaGPzK84gRqPal +QlYfviAoKmv/wSfxwlHYPKvm1G3AokOUwEp/28dVsY88alXPMHLgFsgpx8OuBxbDJNx tEX1Oe5orfWValBlyV+C6nGjotK8q+AxkvBGHUWJaQIUVwhCgiiZ08pdQ81dggvBC83r b2JTbGcsZCI1Y/R7MOg9JlQMY0eatdCrql9s0DYt5jPEmUSRE2toA2Hh8XcbU2mvQdfm nvgJRphUUOZLErArWYMmq1B+2khSrFdVXwrx+pvLx7ujQoISbjpbhj2aH2uJZqAEM891 iNzg== X-Gm-Message-State: AO0yUKVPzlD2RBn7a3R2tLiyaD4N2bXiEuUbLbuuWJGYp5ih8HlTvFxH EAEDiZg9yxVxdp4Q8Gl8Gs+HKcwGslAbDIsQOa70gQ== X-Google-Smtp-Source: AK7set/mmY212OotTuTeZ5IDcG8C81RotJOcVZZVfgC3er8PrHl9uWd6EIJZcBMq1dyvYO1loMdAjQ== X-Received: by 2002:a05:622a:3c7:b0:3bf:c221:5871 with SMTP id k7-20020a05622a03c700b003bfc2215871mr11032748qtx.54.1679034732135; Thu, 16 Mar 2023 23:32:12 -0700 (PDT) Received: from [192.168.1.92] ([68.249.219.17]) by smtp.googlemail.com with ESMTPSA id t184-20020ae9dfc1000000b007424239e4casm1062702qkf.117.2023.03.16.23.32.11 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Mar 2023 23:32:11 -0700 (PDT) Message-ID: <1731e457-2939-9406-ef33-88722444fc43@davyandbeth.com> Date: Fri, 17 Mar 2023 01:32:11 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 From: Davy Durham Content-Language: en-US To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avformat/file: fd, pipe and file input/output now honor rw_timeout 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: File descriptors, pipes or even filenames (that may be fifos or reference other non-regular files) may have upstream or downstream processess that stall out just like any network channel. Hence ffmpeg should respect -rw_timeout for these types too. This is necessary when, for example, input from a pipe has stalled and we want ffmpeg to timeout in order to have a pipeline tear down. --- doc/protocols.texi | 4 ++-- libavformat/file.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index 21ae6181a0..d75521ced2 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -45,8 +45,8 @@ All protocols accept the following options: @table @option @item rw_timeout -Maximum time to wait for (network) read/write operations to complete, -in microseconds. +Maximum time to wait for (network, file, fd, and pipe) read/write operations +to complete, in microseconds. @end table A description of the currently available protocols follows. diff --git a/libavformat/file.c b/libavformat/file.c index cbdf48de0a..fc1d15a672 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -40,6 +40,7 @@ #include #include "os_support.h" #include "url.h" +#include "network.h" /* Some systems may not have S_ISFIFO */ #ifndef S_ISFIFO @@ -140,6 +141,11 @@ static int file_read(URLContext *h, unsigned char *buf, int size) FileContext *c = h->priv_data; int ret; size = FFMIN(size, c->blocksize); + if (h->rw_timeout > 0) { /* wait for something, anything to read */ + ret = ff_network_wait_fd_timeout(c->fd, 0, h->rw_timeout, NULL); + if (ret) + return ret; + } ret = read(c->fd, buf, size); if (ret == 0 && c->follow) return AVERROR(EAGAIN); @@ -152,6 +158,11 @@ static int file_write(URLContext *h, const unsigned char *buf, int size) { FileContext *c = h->priv_data; int ret; + if (h->rw_timeout > 0) { /* wait for something, anything to read */ + ret = ff_network_wait_fd_timeout(c->fd, 1, h->rw_timeout, NULL); + if (ret) + return ret; + } size = FFMIN(size, c->blocksize); ret = write(c->fd, buf, size); return (ret == -1) ? AVERROR(errno) : ret; @@ -304,6 +315,9 @@ static int file_open(URLContext *h, const char *filename, int flags) if (fd == -1) return AVERROR(errno); c->fd = fd; + if (h->rw_timeout > 0) { /* if we'll be doing reads w/ timeout, mark non-blocking */ + fcntl(c->fd, F_SETFL, fcntl(c->fd, F_GETFL, 0) | O_NONBLOCK); + } h->is_streamed = !fstat(fd, &st) && S_ISFIFO(st.st_mode); @@ -448,6 +462,9 @@ static int pipe_open(URLContext *h, const char *filename, int flags) c->fd = fd_dup(h, c->fd); if (c->fd == -1) return AVERROR(errno); + if (h->rw_timeout > 0) { /* if we'll be doing reads w/ timeout, mark non-blocking */ + fcntl(c->fd, F_SETFL, fcntl(c->fd, F_GETFL, 0) | O_NONBLOCK); + } h->is_streamed = 1; return 0; } @@ -493,6 +510,9 @@ static int fd_open(URLContext *h, const char *filename, int flags) c->fd = fd_dup(h, c->fd); if (c->fd == -1) return AVERROR(errno); + if (h->rw_timeout > 0) { /* if we'll be doing reads w/ timeout, mark non-blocking */ + fcntl(c->fd, F_SETFL, fcntl(c->fd, F_GETFL, 0) | O_NONBLOCK); + } return 0; } -- 2.25.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".