* Re: [FFmpeg-devel] [PATCH] avformat/file: seek back to initial position for fd protocol
2023-12-18 16:42 [FFmpeg-devel] [PATCH] avformat/file: seek back to initial position for fd protocol Zhao Zhili
@ 2023-12-18 11:27 ` Anton Khirnov
0 siblings, 0 replies; 2+ messages in thread
From: Anton Khirnov @ 2023-12-18 11:27 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Zhao Zhili
Quoting Zhao Zhili (2023-12-18 17:42:39)
> From: Zhao Zhili <zhilizhao@tencent.com>
>
> So user's fd can be passed to libavformat multiple times in sequence
> without changing the position.
>
> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
> ---
> libavformat/file.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
Looks ok.
--
Anton Khirnov
_______________________________________________
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
* [FFmpeg-devel] [PATCH] avformat/file: seek back to initial position for fd protocol
@ 2023-12-18 16:42 Zhao Zhili
2023-12-18 11:27 ` Anton Khirnov
0 siblings, 1 reply; 2+ messages in thread
From: Zhao Zhili @ 2023-12-18 16:42 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
From: Zhao Zhili <zhilizhao@tencent.com>
So user's fd can be passed to libavformat multiple times in sequence
without changing the position.
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
---
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".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-18 11:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-18 16:42 [FFmpeg-devel] [PATCH] avformat/file: seek back to initial position for fd protocol Zhao Zhili
2023-12-18 11:27 ` Anton Khirnov
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git