From: "Martin Storsjö" <martin@martin.st>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH 1/3] fftools: Stop using av_fopen_utf8
Date: Mon, 23 May 2022 13:53:14 +0300 (EEST)
Message-ID: <c1b753a-cd7b-8598-c13e-f03974ab7f47@martin.st> (raw)
In-Reply-To: <DM8P223MB0365E324B09046D214ED8383BAD29@DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM>
On Sat, 21 May 2022, Soft Works wrote:
>> -----Original Message-----
>> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Martin
>> Storsjö
>> Sent: Friday, May 20, 2022 11:13 PM
>> To: ffmpeg-devel@ffmpeg.org
>> Subject: [FFmpeg-devel] [PATCH 1/3] fftools: Stop using av_fopen_utf8
>>
>> Provide a header based inline reimplementation of it.
>>
>> Using av_fopen_utf8 doesn't work outside of the libraries when built
>> with MSVC as shared libraries (in the default configuration, where
>> each DLL gets a separate statically linked CRT).
>> ---
>> fftools/ffmpeg_opt.c | 3 +-
>> fftools/fopen_utf8.h | 71 ++++++++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 73 insertions(+), 1 deletion(-)
>> create mode 100644 fftools/fopen_utf8.h
>>
>> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
>> index 47e8b9b7bd..a5cd989d35 100644
>> --- a/fftools/ffmpeg_opt.c
>> +++ b/fftools/ffmpeg_opt.c
>> @@ -28,6 +28,7 @@
>> #endif
>>
>> #include "ffmpeg.h"
>> +#include "fopen_utf8.h"
>> #include "cmdutils.h"
>> #include "opt_common.h"
>>
>> @@ -1882,7 +1883,7 @@ static OutputStream *new_video_stream(OptionsContext
>> *o, AVFormatContext *oc, in
>> video_enc->stats_in = logbuffer;
>> }
>> if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
>> - f = av_fopen_utf8(logfilename, "wb");
>> + f = fopen_utf8(logfilename, "wb");
>> if (!f) {
>> av_log(NULL, AV_LOG_FATAL,
>> "Cannot write log file '%s' for pass-1
>> encoding: %s\n",
>> diff --git a/fftools/fopen_utf8.h b/fftools/fopen_utf8.h
>> new file mode 100644
>> index 0000000000..db57fcaec4
>> --- /dev/null
>> +++ b/fftools/fopen_utf8.h
>> @@ -0,0 +1,71 @@
>> +/*
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 of the License, or (at your option) any later version.
>> + *
>> + * FFmpeg is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser General Public
>> + * License along with FFmpeg; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-
>> 1301 USA
>> + */
>> +
>> +#ifndef FFTOOLS_FOPEN_UTF8_H
>> +#define FFTOOLS_FOPEN_UTF8_H
>> +
>> +#include <stdio.h>
>> +
>> +/* The fopen_utf8 function here is essentially equivalent to
>> av_fopen_utf8,
>> + * except that it doesn't set O_CLOEXEC, and that it isn't exported
>> + * from a different library. (On Windows, each DLL might use a different
>> + * CRT, and FILE* handles can't be shared across them.) */
>> +
>> +#ifdef _WIN32
>> +#include "libavutil/wchar_filename.h"
>> +
>> +static inline FILE *fopen_utf8(const char *path_utf8, const char *mode)
>> +{
>> + wchar_t *path_w, *mode_w;
>> + FILE *f;
>> +
>> + /* convert UTF-8 to wide chars */
>> + if (utf8towchar(path_utf8, &path_w)) /* This sets errno on error. */
>> + return NULL;
>> + if (!path_w)
>> + goto fallback;
>> +
>> + if (utf8towchar(mode, &mode_w))
>> + return NULL;
>> + if (!mode_w) {
>> + /* If failing to interpret the mode string as utf8, it is an
>> invalid
>> + * parameter. */
>> + av_freep(&path_w);
>> + errno = EINVAL;
>> + return NULL;
>> + }
>> +
>> + f = _wfopen(path_w, mode_w);
>> + av_freep(&path_w);
>> + av_freep(&mode_w);
>> +
>> + return f;
>> +fallback:
>> + /* path may be in CP_ACP */
>> + return fopen(path_utf8, mode);
>> +}
>> +
>> +#else
>> +
>> +static inline FILE *fopen_utf8(const char *path, const char *mode)
>> +{
>> + return fopen(path, mode);
>> +}
>> +#endif
>> +
>> +#endif /* FFTOOLS_FOPEN_UTF8_H */
>> --
>
> LGTM. (all three)
>
> Tested with VS project build (full static linkage, though).
I discussed this with Anton on irc, and he was ok with the patchset too,
so I pushed it now.
// Martin
_______________________________________________
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:[~2022-05-23 10:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-20 21:12 Martin Storsjö
2022-05-20 21:12 ` [FFmpeg-devel] [PATCH 2/3] libavutil: Deprecate av_fopen_utf8, provide an avpriv version Martin Storsjö
2022-05-20 21:12 ` [FFmpeg-devel] [PATCH 3/3] Switch uses of av_fopen_utf8 to avpriv_fopen_utf8 Martin Storsjö
2022-05-21 5:07 ` [FFmpeg-devel] [PATCH 1/3] fftools: Stop using av_fopen_utf8 Soft Works
2022-05-23 10:53 ` Martin Storsjö [this message]
2022-05-23 10:55 ` Soft Works
2022-05-23 10:58 ` Martin Storsjö
2022-05-23 11:06 ` Soft Works
2022-05-23 11:11 ` Martin Storsjö
2022-05-23 11:44 ` Soft Works
2022-05-24 9:29 ` Martin Storsjö
2022-05-24 19:45 ` Soft Works
2022-05-24 20:21 ` Martin Storsjö
2022-05-24 20:50 ` Soft Works
2022-05-24 20:55 ` Martin Storsjö
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=c1b753a-cd7b-8598-c13e-f03974ab7f47@martin.st \
--to=martin@martin.st \
--cc=ffmpeg-devel@ffmpeg.org \
/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