Hi, I'm newbie here. No Unicode API in FFmpeg make me very sad (this is important only for Windows applications). I partially investigate the current i/o and found that creating Unicode versions for major functions cause to create the tons of another stuff. But I found another 'stupid' way - I define new fileU protocol which assume the input path is in utf-8, automatically converts it to the utf16 string and use Unicode function to open the file.
Tell me if there is a better way to provide Unicode support or give me your suggestions how I should modify the patch. Thanks. ----------------------------------------------- Kirill Gavrilov, Software designer.
From 821e4adb8c7241ecc9a7e0c15593ca8a3741865e Mon Sep 17 00:00:00 2001 From: Kirill Gavrilov <[email protected]> Date: Wed, 13 Apr 2011 00:05:44 +0400 Subject: [PATCH] Added fileU protocol for Windows unicode support New protocol allows to open files with unicode symbols. For compatibility the file path L'fileU:C:\my\movie.mkv' should be converted to Utf8 and than could be used with FFmpeg API. Signed-off-by: Kirill Gavrilov <[email protected]> --- libavformat/allformats.c | 7 ++++- libavformat/file.c | 56 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/libavformat/allformats.c b/libavformat/allformats.c index f0e98ed..8730445 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -36,7 +36,7 @@ #define REGISTER_PROTOCOL(X,x) { \ extern URLProtocol ff_##x##_protocol; \ if(CONFIG_##X##_PROTOCOL) ffurl_register_protocol(&ff_##x##_protocol, sizeof(ff_##x##_protocol)); } - + void av_register_all(void) { static int initialized; @@ -236,7 +236,10 @@ void av_register_all(void) /* protocols */ REGISTER_PROTOCOL (APPLEHTTP, applehttp); REGISTER_PROTOCOL (CONCAT, concat); - REGISTER_PROTOCOL (FILE, file); + REGISTER_PROTOCOL (FILE, file); +#if(defined(_WIN32) || defined(__WIN32__)) + REGISTER_PROTOCOL (FILE, fileU); +#endif REGISTER_PROTOCOL (GOPHER, gopher); REGISTER_PROTOCOL (HTTP, http); REGISTER_PROTOCOL (MMSH, mmsh); diff --git a/libavformat/file.c b/libavformat/file.c index 64f8782..d7429b3 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -104,9 +104,63 @@ URLProtocol ff_file_protocol = { .url_close = file_close, .url_get_file_handle = file_get_handle, }; + +#if(defined(_WIN32) || defined(__WIN32__)) + +#include <windows.h> + +/* Unicode version for Windows */ +static int file_openU(URLContext *h, const char *filenameUtf8, int flags) +{ + int access; + int fd; + int uChars; + wchar_t *filenameUtf16; + + av_strstart(filenameUtf8, "fileU:", &filenameUtf8); + uChars = MultiByteToWideChar(CP_UTF8, 0, + filenameUtf8, -1, + NULL, 0); + if (uChars <= 0) { + return AVERROR(errno); + } + filenameUtf16 = (wchar_t* )av_malloc(sizeof(wchar_t) * uChars); + memset(filenameUtf16, 0, sizeof(wchar_t) * uChars); + MultiByteToWideChar(CP_UTF8, 0, + filenameUtf8, -1, + filenameUtf16, uChars); + + if (flags & AVIO_RDWR) { + access = O_CREAT | O_TRUNC | O_RDWR; + } else if (flags & AVIO_WRONLY) { + access = O_CREAT | O_TRUNC | O_WRONLY; + } else { + access = O_RDONLY; + } +#ifdef O_BINARY + access |= O_BINARY; +#endif + fd = _wopen(filenameUtf16, access, 0666); + av_freep(&filenameUtf16); + if (fd == -1) + return AVERROR(errno); + h->priv_data = (void *) (intptr_t) fd; + return 0; +} + +URLProtocol ff_fileU_protocol = { + .name = "fileU", + .url_open = file_openU, + .url_read = file_read, + .url_write = file_write, + .url_seek = file_seek, + .url_close = file_close, + .url_get_file_handle = file_get_handle, +}; +#endif /* WIN32 */ #endif /* CONFIG_FILE_PROTOCOL */ - + #if CONFIG_PIPE_PROTOCOL static int pipe_open(URLContext *h, const char *filename, int flags) -- 1.7.0.4
_______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
