From patchwork Sun Dec 11 15:17:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 39677 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp2945246pzb; Sun, 11 Dec 2022 07:18:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf6GLPZ/nlogEF0xJCOomK35ozGmi4ie49FVvNK5Jt+0tkynjbaxcGWWGNovGjAHbLuEcW7b X-Received: by 2002:a17:907:c78f:b0:7c1:4e8f:df2f with SMTP id tz15-20020a170907c78f00b007c14e8fdf2fmr7757438ejc.17.1670771902897; Sun, 11 Dec 2022 07:18:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670771902; cv=none; d=google.com; s=arc-20160816; b=CvUTKd+Dpp40HjTQb2XFuhftrqvUWyzD46P9PyhPuCgWv4RDWmg3+FZ/sKsClFuQmQ CT/Ese92TKYDSxxe/AEd6GFm3W+V/Lti/5+khrMa4owZg7MovzLD5TdJsZGbPo3DrEuW IvSoYIDWCSO6JAzS+8IuCSWig4GtD8qiDnFLp4t8GHzmbcfg9a6RIlFXnT5+3z/PspX7 meFFAnhpfH4TvFaxTiogk/fsU3+lI7vCIZVtrERWhShWmnSjMCv6HcFotO/JsuAH3v6o 96YMzYXNh2UQrwXNoW6LrPWs3ud1Doet8XK1pTk/tZGbD/z0LgjCczx4/d90KM15GavO J5KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:date:to:from:message-id :dkim-signature:delivered-to; bh=9nU4/aMfCADmc3zXVCVU1Zij6r8qwE4d6Mc743xV8VQ=; b=Qg88raFcwb39EFSNrjY9AvPyMy3fydZZJUrF46cECWu9uLRFKr9qOAB3RqHnXyQ/u/ VWuj5ElyRVEuCQPKkbYqEHcr3Fu7XPS1aSDluIdf2S5y6+u/1+Pf+2byQLZdK0HnxGTv MCBD6uHDmQh2eXN4/hL1/hrvV7YEJjPkxSfM1OILWB98mt3+2vKF5jgMik/w8vnyK7Oy DGfKtbfqhMc861g+7Wx5FcmLtWiEsyHs9vt21xZCoIV6fQMeY5zNoQXX3/CcfRxs+OxQ oUr5FVPF5GabjxXBjzKhtBpjAjXG3fJNFo+FvfRyH3tiEG0u/VBm4fC4m+B9BbgQj8w8 NAlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=jsVx97zq; 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=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id js8-20020a17090797c800b007bfdadb58e7si4519839ejc.546.2022.12.11.07.18.22; Sun, 11 Dec 2022 07:18:22 -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=@foxmail.com header.s=s201512 header.b=jsVx97zq; 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=NONE dis=NONE) header.from=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4033868BDFB; Sun, 11 Dec 2022 17:18:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out203-205-221-202.mail.qq.com (out203-205-221-202.mail.qq.com [203.205.221.202]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3336168BDDB for ; Sun, 11 Dec 2022 17:18:00 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1670771875; bh=SKzCkOMzTaxmBH2DhEvquyiF/x84cVtZxC0t2SbBnjg=; h=From:To:Cc:Subject:Date; b=jsVx97zqR9ogkgfjfhV2+l/wsgjsQ/IxIP9PHyE2QKN6Nh1C9LU9IrM59R1nDJkoU SD22LRpnLpO/nggYv60H+qH5mWkr0pLd5g5rSoCLUjIAb+CWSSwlQuYs8/ultSU9UZ /8OOD+Iw4FBpOUDBTUSzdxJCxSkaG+C9p5iELHBE= Received: from localhost.localdomain ([113.116.30.206]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 4762AC8A; Sun, 11 Dec 2022 23:17:54 +0800 X-QQ-mid: xmsmtpt1670771874tdq8w47ck Message-ID: X-QQ-XMAILINFO: NMmJpeSXIGQN8B3mNDVak5x4GCuunWMMaltPWGPMxEQJkE1yZi+QHgG6gQk88l WvHN9K+h3lW5kzsyNY9WZW3qW36OB7VAWLNjsDehf94X98HLz8hYc5OeWCClc969xQzestiXTI7n /0UAsDJREPZPLJKqUcIG28kiCwd2UgHTf6EBHRW5D07oW7mHfAyCppLDnuhwOaAl3qj/pSUfPY1e 7SwNPmZhMgM2+yjUggaGf2fw8F/34LWKxj9oeyhdYdR53DJCs22yUmF6xN2Dkh1RalXlGUDhmeGJ tWuGKctOzw8cyk+/yiSN+laVTgPcFxXqj0bu7EhQDg05Zxi+4/nkUQ88V6klCnkvJLguohsqWOYD rgcrqcyZVSsmr7qNVaeIVVbb2xTKNboL92OmJm35Ou9QQHNwMOVxsZdJk23vuq6kHi5ZtPA806UE f3qnxQyxBk0vfbnORpoPc+bctk4ma5ppJ6xtBxOX6niKtsQpa15aGOyXh7PW/mL+etcp+Kk/5EE5 7agzmsyqnduk2/WkCGSE9iUsOXgTMQbJgaIbanNJPWIYIfvtvej2kQZxBD9+q/asC0zyBqATTSRF IEyOv4O5J+/Q4c1PzHdm2Za0hFK5fOlslVV5qH4SlZkRPddK7Z2ggBpTce695rCVk5jxNs3nw8m/ U8zbQBAH1zY2ij0YuIfDGemD1ii2wjwBHAR9oFNuseeDWXnmsNiD4Wv2takVNXyy6Hc08XwF66HY rniHmoDA8CDwGmCyEVhx6wHKvLVG0Nj/JsY25dHbx03ESXIJI8b6F8Iwb/4uIdEb27D7IKoTbYzm NRb+lBTz4KZ/a+zkuApowLvRmTNTmltQxzYuQS7QlpbyZ89W5X9KMno5RM7aC7FD4a8qrHB2IxrN /32YKYwFoXkA2yp2BpFQO8ehVeADqQe0L9QnPLBAE1OPaUY802fRThVqq2e3InbfHjtAyEUkq2G1 goS4qlqpcPWA3397xlDQ== From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Sun, 11 Dec 2022 23:17:27 +0800 X-OQ-MSGID: <20221211151729.120662-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/3] avformat/file: add fd protocol 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 Cc: Zhao Zhili Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Tal0qQQvbw4a From: Zhao Zhili Unlike the pipe protocol, fd protocol has seek support if it corresponding to a regular file. --- v2: dup the file descriptor for safety doc/protocols.texi | 24 ++++++++++++++++++ libavformat/Makefile | 1 + libavformat/file.c | 55 +++++++++++++++++++++++++++++++++++++++++ libavformat/protocols.c | 1 + libavformat/version.h | 4 +-- 5 files changed, 83 insertions(+), 2 deletions(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index 5e9198e67c..d9f2d2dec3 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -275,6 +275,30 @@ For example, to convert a GIF file given inline with @command{ffmpeg}: ffmpeg -i "data:image/gif;base64,R0lGODdhCAAIAMIEAAAAAAAA//8AAP//AP///////////////ywAAAAACAAIAAADF0gEDLojDgdGiJdJqUX02iB4E8Q9jUMkADs=" smiley.png @end example +@section fd + +File descriptor access protocol. + +The accepted syntax is: +@example +fd:[@var{number}] +@end example + +@var{number} is the number corresponding to a file descriptor. Unlike the pipe +protocol, fd protocol has seek support if it corresponding to a regular file. +If @var{number} is not specified, by default the stdout file descriptor will +be used for writing, stdin for reading. + +This protocol accepts the following options: + +@table @option +@item blocksize +Set I/O operation maximum block size, in bytes. Default value is +@code{INT_MAX}, which results in not limiting the requested block size. +Setting this value reasonably low improves user termination request reaction +time, which is valuable if data transmission is slow. +@end table + @section file File access protocol. diff --git a/libavformat/Makefile b/libavformat/Makefile index d7f198bf39..1452216e29 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -647,6 +647,7 @@ OBJS-$(CONFIG_DATA_PROTOCOL) += data_uri.o OBJS-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += rtmpcrypt.o rtmpdigest.o rtmpdh.o OBJS-$(CONFIG_FFRTMPHTTP_PROTOCOL) += rtmphttp.o OBJS-$(CONFIG_FILE_PROTOCOL) += file.o +OBJS-$(CONFIG_FD_PROTOCOL) += file.o OBJS-$(CONFIG_FTP_PROTOCOL) += ftp.o urldecode.o OBJS-$(CONFIG_GOPHER_PROTOCOL) += gopher.o OBJS-$(CONFIG_GOPHERS_PROTOCOL) += gopher.o diff --git a/libavformat/file.c b/libavformat/file.c index 6103c37b34..b8725c1f48 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -109,6 +109,13 @@ static const AVClass pipe_class = { .version = LIBAVUTIL_VERSION_INT, }; +static const AVClass fd_class = { + .class_name = "fd", + .item_name = av_default_item_name, + .option = pipe_options, + .version = LIBAVUTIL_VERSION_INT, +}; + static int file_read(URLContext *h, unsigned char *buf, int size) { FileContext *c = h->priv_data; @@ -412,3 +419,51 @@ const URLProtocol ff_pipe_protocol = { }; #endif /* CONFIG_PIPE_PROTOCOL */ + +#if CONFIG_FD_PROTOCOL + +static int fd_open(URLContext *h, const char *filename, int flags) +{ + FileContext *c = h->priv_data; + int fd; + char *final; + struct stat st; + + av_strstart(filename, "fd:", &filename); + + fd = strtol(filename, &final, 10); + if ((filename == final) || *final ) { + if (flags & AVIO_FLAG_WRITE) { + fd = 1; + } else { + fd = 0; + } + } +#if HAVE_SETMODE + setmode(fd, O_BINARY); +#endif + if (fstat(fd, &st) < 0) + return AVERROR(errno); + h->is_streamed = !(S_ISREG(st.st_mode) || S_ISBLK(st.st_mode)); + c->fd = dup(fd); + if (c->fd < 0) + return AVERROR(errno); + + return 0; +} + +const URLProtocol ff_fd_protocol = { + .name = "fd", + .url_open = fd_open, + .url_read = file_read, + .url_write = file_write, + .url_seek = file_seek, + .url_close = file_close, + .url_get_file_handle = file_get_handle, + .url_check = file_check, + .priv_data_size = sizeof(FileContext), + .priv_data_class = &fd_class, + .default_whitelist = "crypto,data" +}; + +#endif /* CONFIG_FD_PROTOCOL */ diff --git a/libavformat/protocols.c b/libavformat/protocols.c index 8b7d1b940f..82cb1033e4 100644 --- a/libavformat/protocols.c +++ b/libavformat/protocols.c @@ -29,6 +29,7 @@ extern const URLProtocol ff_concat_protocol; extern const URLProtocol ff_concatf_protocol; extern const URLProtocol ff_crypto_protocol; extern const URLProtocol ff_data_protocol; +extern const URLProtocol ff_fd_protocol; extern const URLProtocol ff_ffrtmpcrypt_protocol; extern const URLProtocol ff_ffrtmphttp_protocol; extern const URLProtocol ff_file_protocol; diff --git a/libavformat/version.h b/libavformat/version.h index a7e5a9ac66..f5a7f579b3 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -31,8 +31,8 @@ #include "version_major.h" -#define LIBAVFORMAT_VERSION_MINOR 34 -#define LIBAVFORMAT_VERSION_MICRO 102 +#define LIBAVFORMAT_VERSION_MINOR 35 +#define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \