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 892EF487E4 for ; Mon, 18 Dec 2023 08:43:01 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 60FB268D1BB; Mon, 18 Dec 2023 10:42:57 +0200 (EET) Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6C77B68D1A7 for ; Mon, 18 Dec 2023 10:42:50 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1702888960; bh=8uSY1591Lm5O6kUnnd0vwd8C2QT8tsYswP9R9pFqI5Y=; h=From:To:Cc:Subject:Date; b=dS+zhN97YKudQ/CQSJUdsvZGQzFgmdVEE7PgiWqCUfRdlZSZHAWn7Zjbvf2f4tO3j NQ+q3ji919PMCwVCBOokE9gVRkkWpMXVPbNLUuaNvHrpF2oO9h0sBJBgskj4mYDEsi EQBoohRrHKeNPiSCyXN3CpIdWCK1OcpEgOAWiQKQ= Received: from localhost.localdomain ([113.108.77.64]) by newxmesmtplogicsvrszc5-1.qq.com (NewEsmtp) with SMTP id AA70C4F9; Mon, 18 Dec 2023 16:42:39 +0800 X-QQ-mid: xmsmtpt1702888959t6fl9fw3y Message-ID: X-QQ-XMAILINFO: OKKHiI6c9SH3vxT3aH57sf3lQrYCNuAvI4mZ57Voc95KL3CI3eQJGgYa1GQhHN cNt774s1BcjKbuH3NG4fzNjKXy/Fx2+7yQV61/wD3SwZz6huICDRhJIhv/HF67QEFSPpGdKXeHsl oM0uoYBQDLOy/KJ5aeHF/Iu9ciGRRaYsXn0q4E9KOdZ5b3DajHrJsijAS8ZPxJY6q40Z33JSaoOy O2fUOEhRjGPYUDoGm+5+mgcpGTYwET/3VwlwN5nbPyw7OoE/fVQyyR/d7GT5rUzUMAYKucyWCpB0 OQNP28jGNLWzSNFDQzmKX5P+uwop2SKSBMKOSW4V+B7gvDU2d22uVRBIRnGiEuyMg85hVY4p8NaJ hfXBX+uXhxnI+jDHXKkAws/xqEsvcJ+1HHctitf2bA8tLnkiI0LpsNgoD5tAKtFNBNXL+d2XEfe8 7t58A6UUNrv4Pyf89T9YiZ+tgnSG5UX3SeVx2tSs0i96tvUC8wura7XCq0gBvsDSFfvHVXSk86RU iS7rsp3qnBk7jbarwjfBjF7IzlMfQVVa7+0EXhWAcHIRjI8/bIwaieWBpz5BUEY02SrZP4EohEjf N9Y9noVURlI4J4NqwXC2sYrGHiA/rXuD7xk8hdTDa341RBE9jC1praGlmVw5ikEjGEXpmtTgXonR y3b2prM9c1l74Te4QfEhhw51FviKMN6L9dDJCg1MAo0o4sROY0AMLiiCaBCDeaAxog9BrJ3dSSWe gMaDDI5jwjLGwvgrHzsapMDIB7rj7LoHTkZhUIAJGCdUuALguvr+CEXuw5xF/lbhE7wkU06a18BZ xX5Y8Gg2YRg05RHpkkXWa1bLpx8PyI2qBBrYFGsuouU/E/iNmTwk9/6K2elCIkEPBsrf2OVZShRW CL3LYbbyjM/dYr8qeyRb5wGnbPGURNpoMaq4Dqq/k7BokrT3dv0IX91mZRFYIlEilJbXTyBUTggl s7nUeJbsiVZmQXO3lrVaXyFJZJ7IaJR73uwl1vOuI= X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Dec 2023 00:42:39 +0800 X-OQ-MSGID: <20231218164239.358474-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/file: seek back to initial position for 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Zhao Zhili So user's fd can be passed to libavformat multiple times in sequence without changing the position. Signed-off-by: Zhao Zhili --- libavformat/file.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libavformat/file.c b/libavformat/file.c index cbdf48de0a..64df7ff6fb 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -98,6 +98,7 @@ typedef struct FileContext { #if HAVE_DIRENT_H DIR *dir; #endif + int64_t initial_pos; } FileContext; static const AVOption file_options[] = { @@ -218,7 +219,12 @@ static int fd_dup(URLContext *h, int oldfd) static int file_close(URLContext *h) { FileContext *c = h->priv_data; - int ret = close(c->fd); + int ret; + + if (c->initial_pos >= 0 && !h->is_streamed) + lseek(c->fd, c->initial_pos, SEEK_SET); + + ret = close(c->fd); return (ret == -1) ? AVERROR(errno) : 0; } @@ -286,6 +292,7 @@ static int file_open(URLContext *h, const char *filename, int flags) av_strstart(filename, "file:", &filename); + c->initial_pos = -1; if (flags & AVIO_FLAG_WRITE && flags & AVIO_FLAG_READ) { access = O_CREAT | O_RDWR; if (c->trunc) @@ -494,6 +501,11 @@ static int fd_open(URLContext *h, const char *filename, int flags) if (c->fd == -1) return AVERROR(errno); + if (h->is_streamed) + c->initial_pos = -1; + else + c->initial_pos = lseek(c->fd, 0, SEEK_CUR); + 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".