aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/avisynth.c
diff options
context:
space:
mode:
authorNil Admirari <nil-admirari@mailo.com>2022-06-20 13:30:00 +0300
committerMartin Storsjö <martin@martin.st>2022-06-21 13:27:46 +0300
commitc381f5412fe810bd8118123aed9bd4f76b75b59d (patch)
tree959b4b45a0e7aee5ee37cafec26474707053c252 /libavformat/avisynth.c
parent13350e81fd43cbd1aa3bbb7ed567e7dc7dd2b7f5 (diff)
downloadffmpeg-c381f5412fe810bd8118123aed9bd4f76b75b59d.tar.gz
libavformat: Remove MAX_PATH limit and use UTF-8 version of getenv()
1. getenv() is replaced with getenv_utf8() across libavformat. 2. New versions of AviSynth+ are now called with UTF-8 filenames. 3. Old versions of AviSynth are still using ANSI strings, but MAX_PATH limit on filename is removed. Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/avisynth.c')
-rw-r--r--libavformat/avisynth.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 8ba2bdead2..a97d12b6b6 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -34,6 +34,7 @@
/* Platform-specific directives. */
#ifdef _WIN32
#include "compat/w32dlfcn.h"
+ #include "libavutil/wchar_filename.h"
#undef EXTERN_C
#define AVISYNTH_LIB "avisynth"
#else
@@ -56,6 +57,7 @@ typedef struct AviSynthLibrary {
#define AVSC_DECLARE_FUNC(name) name ## _func name
AVSC_DECLARE_FUNC(avs_bit_blt);
AVSC_DECLARE_FUNC(avs_clip_get_error);
+ AVSC_DECLARE_FUNC(avs_check_version);
AVSC_DECLARE_FUNC(avs_create_script_environment);
AVSC_DECLARE_FUNC(avs_delete_script_environment);
AVSC_DECLARE_FUNC(avs_get_audio);
@@ -137,6 +139,7 @@ static av_cold int avisynth_load_library(void)
LOAD_AVS_FUNC(avs_bit_blt, 0);
LOAD_AVS_FUNC(avs_clip_get_error, 0);
+ LOAD_AVS_FUNC(avs_check_version, 0);
LOAD_AVS_FUNC(avs_create_script_environment, 0);
LOAD_AVS_FUNC(avs_delete_script_environment, 0);
LOAD_AVS_FUNC(avs_get_audio, 0);
@@ -807,26 +810,38 @@ static int avisynth_create_stream(AVFormatContext *s)
static int avisynth_open_file(AVFormatContext *s)
{
AviSynthContext *avs = s->priv_data;
- AVS_Value arg, val;
+ AVS_Value val;
int ret;
-#ifdef _WIN32
- char filename_ansi[MAX_PATH * 4];
- wchar_t filename_wc[MAX_PATH * 4];
-#endif
if (ret = avisynth_context_create(s))
return ret;
+ if (!avs_library.avs_check_version(avs->env, 7)) {
+ AVS_Value args[] = {
+ avs_new_value_string(s->url),
+ avs_new_value_bool(1) // filename is in UTF-8
+ };
+ val = avs_library.avs_invoke(avs->env, "Import",
+ avs_new_value_array(args, 2), 0);
+ } else {
+ AVS_Value arg;
#ifdef _WIN32
- /* Convert UTF-8 to ANSI code page */
- MultiByteToWideChar(CP_UTF8, 0, s->url, -1, filename_wc, MAX_PATH * 4);
- WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
- MAX_PATH * 4, NULL, NULL);
- arg = avs_new_value_string(filename_ansi);
+ char *filename_ansi;
+ /* Convert UTF-8 to ANSI code page */
+ if (utf8toansi(s->url, &filename_ansi)) {
+ ret = AVERROR_UNKNOWN;
+ goto fail;
+ }
+ arg = avs_new_value_string(filename_ansi);
#else
- arg = avs_new_value_string(s->url);
+ arg = avs_new_value_string(s->url);
#endif
- val = avs_library.avs_invoke(avs->env, "Import", arg, 0);
+ val = avs_library.avs_invoke(avs->env, "Import", arg, 0);
+#ifdef _WIN32
+ av_free(filename_ansi);
+#endif
+ }
+
if (avs_is_error(val)) {
av_log(s, AV_LOG_ERROR, "%s\n", avs_as_error(val));
ret = AVERROR_UNKNOWN;