From: Thilo Borgmann via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: Thilo Borgmann <thilo.borgmann@mail.de> Subject: Re: [FFmpeg-devel] [PATCH 1/2] avfilter: Add fsync filter Date: Sat, 16 Dec 2023 09:13:09 +0100 Message-ID: <abc6a55b-258c-4da0-b23a-27224b619de7@mail.de> (raw) In-Reply-To: <AS8P250MB0744B1CD932FFDC0803D256C8F93A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> Am 15.12.23 um 15:17 schrieb Andreas Rheinhardt: > Thilo Borgmann via ffmpeg-devel: >> --- >> Changelog | 1 + >> MAINTAINERS | 1 + >> doc/filters.texi | 33 +++++ >> libavfilter/Makefile | 1 + >> libavfilter/allfilters.c | 1 + >> libavfilter/version.h | 2 +- >> libavfilter/vf_fsync.c | 304 +++++++++++++++++++++++++++++++++++++++ >> 7 files changed, 342 insertions(+), 1 deletion(-) >> create mode 100644 libavfilter/vf_fsync.c >> >> [...] >> +// fills the buffer from cur to end, add \0 at EOF >> +static int buf_fill(FsyncContext *ctx) >> +{ >> + int ret; >> + int num = ctx->end - ctx->cur; >> + >> + ret = avio_read(ctx->avio_ctx, ctx->cur, num); >> + if (ret < 0) >> + return ret; >> + if (ret < num) { >> + *(ctx->cur + ret) = '\0'; >> + } >> + >> + return ret; >> +} >> + >> +// copies cur to end to the beginning and fills the rest >> +static int buf_reload(FsyncContext *ctx) >> +{ >> + int i, ret; >> + int num = ctx->end - ctx->cur; >> + >> + for (i = 0; i < num; i++) { >> + ctx->buf[i] = *ctx->cur++; >> + } >> + >> + ctx->cur = ctx->buf + i; >> + ret = buf_fill(ctx); >> + if (ret < 0) >> + return ret; >> + ctx->cur = ctx->buf; > > I wonder whether you should not just use avio_read_to_bprint() for all > of this. I tested a bit. It appears good for filling the buffer with one function call, getting the stuff out for scanf appears not as well as when and how to refill the buffer. Comparing a bit to f_metadata where this is used, the necessary function get bigger and more complex than this easily. Maybe its just I didn't use it often enough, but this char* handling appears easier and less complex to me. So if you don't insist I'd leave it that way. >> + >> + return ret; >> +} >> + >> +// skip from cur over eol >> +static void buf_skip_eol(FsyncContext *ctx) >> +{ >> + char *i; >> + for (i = ctx->cur; i < ctx->end; i++) { >> + if (*i != '\n')// && *i != '\r') >> + break; >> + } >> + ctx->cur = i; >> +} >> + >> +// get number of bytes from cur until eol >> +static int buf_get_line_count(FsyncContext *ctx) >> +{ >> + int ret = 0; >> + char *i; >> + for (i = ctx->cur; i < ctx->end; i++, ret++) { >> + if (*i == '\0' || *i == '\n') >> + return ret; > > If you unconditionally added a single \0 to the end of the buffer, you > could use strchr() here. I'd need two strchr() calls, for \0 and \n, plus the interpretation of the resulting pointers. Where \0 would always be found at the end of the buffer which needs another if to see if its what I need or do need to load more data. >> [...] >> + >> +static av_cold void fsync_uninit(AVFilterContext *ctx) >> +{ >> + FsyncContext *s = ctx->priv; >> + >> + avio_close(s->avio_ctx); > > avio_closep() > >> + av_freep(&s->buf); >> + av_frame_unref(s->last_frame); > > I expect that this needs to be changed to av_frame_free(). Anyway, you > should run your tests via valgrind/asan. Asan is fine both ways, so I assume it wouldn't catch it? Changed to av_frame_free anyways. There appears no Valgrind nor msan to be available for OSX. 'leaks' also even complains it cannot really do its job: "Can't examine target process's malloc zone asan_0x10c134950, so memory analysis will be incomplete or incorrect. Reason: for security, cannot load non-system library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib Process 49784 is not debuggable. Due to security restrictions, leaks can only show or save contents of readonly memory of restricted processes." Am I out of options on OSX? Seems like the first real drawback when on a mac... Fixed all the other things for v3. -Thilo _______________________________________________ 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".
next prev parent reply other threads:[~2023-12-16 8:13 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-15 7:24 [FFmpeg-devel] [PATCH 0/2] " Thilo Borgmann via ffmpeg-devel 2023-12-15 7:24 ` [FFmpeg-devel] [PATCH 1/2] " Thilo Borgmann via ffmpeg-devel 2023-12-15 14:17 ` Andreas Rheinhardt 2023-12-16 8:13 ` Thilo Borgmann via ffmpeg-devel [this message] 2023-12-15 7:24 ` [FFmpeg-devel] [PATCH 2/2] fate: Add fsync filter tests Thilo Borgmann via ffmpeg-devel
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=abc6a55b-258c-4da0-b23a-27224b619de7@mail.de \ --to=ffmpeg-devel@ffmpeg.org \ --cc=thilo.borgmann@mail.de \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
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