[FFmpeg-devel] Support for Unicode filenames on Windows: try #2

Karl Blomster kalle
Wed Oct 21 09:34:23 CEST 2009


M?ns Rullg?rd wrote:
> Karl Blomster <kalle at agigen.se> writes:
> 
>> Karl Blomster wrote:
>>> Anyway, winutf8_try2.diff is my patch (probably full of bad and
>>> wrong things).
>>> ramiro_winutf8_4.diff is Ramiro's old patch, attached for reference
>>> (it no longer applies, but the needed changes are pretty minor).
>> Patch was broken (missing winmain.c/winmain.h), but Ramiro suggested
>> on IRC that I only submit the lavf part for now and save the
>> ffmpeg/ffplay commandline support for later. Simpler patch attached.
> 
> Won't this break the command line tools?

It will for all filenames that aren't effectively 7-bit ASCII, at least until a 
patch to add Unicode support for the command line tools is accepted. (My first 
attempt at a reworking of Ramiro's old patch does add input support that works 
just fine, but when ffmpeg attempts to print the input filename it just prints 
garbage because the vanilla printf doesn't expect UTF8. Maybe a patch that adds 
Unicode support should fix that too.)

This is just an attempt to get the smallest possible change accepted. I changed 
the configure help message to try to document it better, but I'm sure it could 
be done better, and it could be documented in the general documentation too.

>> Index: libavformat/os_support.c
>> ===================================================================
>> --- libavformat/os_support.c	(revision 20336)
>> +++ libavformat/os_support.c	(working copy)
>> @@ -30,6 +30,36 @@
>>  #include <sys/time.h>
>>  #include "os_support.h"
>>
>> +#ifdef CONFIG_WIN_UNICODE
> 
> #if

fixed

>> +#define WIN32_LEAN_AND_MEAN
>> +#include <windows.h>
>> +#include <wchar.h>
>> +
>> +static wchar_t *dup_char_to_wchar(const char *s)
>> +{
>> +    wchar_t *w;
>> +    int l;
>> +    if (!(l = MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,s,-1,0,0)))
>> +        return NULL;
>> +    if (!(w = av_malloc(l*sizeof(wchar_t))))
>> +        return NULL;
>> +    if (MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,s,-1,w,l) <= 0)
>> +        av_freep(&w);
>> +    return w;
>> +}
>> +
>> +int ff_winutf8_open(const char *fname, int oflags, int pmode)
>> +{
>> +    wchar_t *wfname = dup_char_to_wchar(fname);
>> +    if (wfname) {
>> +        int ret = _wopen(wfname, oflags, pmode);
>> +        av_free(wfname);
>> +        return ret;
>> +    }
>> +    return _open(fname, oflags, pmode); /* very likely to fail, but at least it's worth trying */
> 
> I don't like that way of thinking.

Changed to return -1 as per Ramiro's suggestion. If there's a specific error 
code that suits the situation better, feel free to tell me which one it is.

>> +}
>> +#endif /* CONFIG_WIN_UNICODE */
>> +
>>  #if CONFIG_NETWORK
>>  #if !HAVE_POLL_H
>>  #if HAVE_WINSOCK2_H
>> Index: libavformat/os_support.h
>> ===================================================================
>> --- libavformat/os_support.h	(revision 20336)
>> +++ libavformat/os_support.h	(working copy)
>> @@ -32,7 +32,11 @@
>>  #if defined(__MINGW32__) && !defined(__MINGW32CE__)
>>  #  include <fcntl.h>
>>  #  define lseek(f,p,w) _lseeki64((f), (p), (w))
>> -#endif
>> +#  ifdef CONFIG_WIN_UNICODE
> 
> #if

fixed

>> +#    define open(fn,of,pm) ff_winutf8_open((fn), (of), (pm))
> 
> Unnecessary () around args.

fixed, was following the pattern used by the _lseeki64 define a few lines above

>> +int ff_winutf8_open(const char *fname, int oflags, int pmode);
>> +#  endif /* CONFIG_WIN_UNICODE */
>> +#endif /* defined(__MINGW32__) && !defined(__MINGW32CE__) */
> 
> Adding that comment is cosmetic and doesn't belong in this patch.

fixed by ramiro

Best regards,
Karl Blomster

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: winutf8_try2.2.diff
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20091021/64918c17/attachment.txt>



More information about the ffmpeg-devel mailing list