@@ -41,6 +41,10 @@ extern "C"
41
41
#include " lwlibav_source.h"
42
42
#include " ../common/lwlibav_video_internal.h"
43
43
44
+ #ifdef _WIN32
45
+ #include < windows.h>
46
+ #endif
47
+
44
48
#ifdef _MSC_VER
45
49
#pragma warning( disable:4996 )
46
50
#endif
@@ -172,9 +176,7 @@ LWLibavVideoSource::LWLibavVideoSource
172
176
/* */
173
177
prepare_video_decoding ( vdhp, vohp, direct_rendering, pixel_format, env );
174
178
175
- has_at_least_v8 = true ;
176
- try { env->CheckVersion (8 ); }
177
- catch (const AvisynthError&) { has_at_least_v8 = false ; }
179
+ has_at_least_v8 = env->FunctionExists (" propShow" );
178
180
179
181
av_frame = lwlibav_video_get_frame_buffer (vdhp);
180
182
int num = av_frame->sample_aspect_ratio .num ;
@@ -373,9 +375,66 @@ static void set_av_log_level( int level )
373
375
av_log_set_level ( AV_LOG_TRACE );
374
376
}
375
377
378
+ #ifdef WIN32
379
+ static AVS_FORCEINLINE int ansi_to_wchar (const char * filename_ansi, wchar_t ** filename_w)
380
+ {
381
+ int num_chars;
382
+ num_chars = MultiByteToWideChar (CP_ACP, 0 , filename_ansi, -1 , NULL , 0 );
383
+ if (num_chars <= 0 ) {
384
+ *filename_w = NULL ;
385
+ return 0 ;
386
+ }
387
+ *filename_w = (wchar_t *)av_calloc (num_chars, sizeof (wchar_t ));
388
+ if (!*filename_w) {
389
+ errno = ENOMEM;
390
+ return -1 ;
391
+ }
392
+ MultiByteToWideChar (CP_ACP, 0 , filename_ansi, -1 , *filename_w, num_chars);
393
+ return 0 ;
394
+ }
395
+
396
+ static AVS_FORCEINLINE int wchar_to_utf8 (const wchar_t * filename_w, char ** filename)
397
+ {
398
+ int num_chars = WideCharToMultiByte (CP_UTF8, WC_ERR_INVALID_CHARS, filename_w, -1 , NULL , 0 , NULL , NULL );
399
+ if (num_chars <= 0 ) {
400
+ *filename = NULL ;
401
+ return 0 ;
402
+ }
403
+ *filename = (char *)av_malloc_array (num_chars, sizeof * filename);
404
+ if (!*filename) {
405
+ errno = ENOMEM;
406
+ return -1 ;
407
+ }
408
+ WideCharToMultiByte (CP_UTF8, WC_ERR_INVALID_CHARS, filename_w, -1 , *filename, num_chars, NULL , NULL );
409
+ return 0 ;
410
+ }
411
+
412
+ static AVS_FORCEINLINE int ansi_to_utf8 (const char * filename_ansi, char ** filename)
413
+ {
414
+ wchar_t * filename_w = NULL ;
415
+ int ret = -1 ;
416
+ if (ansi_to_wchar (filename_ansi, &filename_w))
417
+ return -1 ;
418
+
419
+ if (!filename_w) {
420
+ *filename = NULL ;
421
+ return 0 ;
422
+ }
423
+
424
+ ret = wchar_to_utf8 (filename_w, filename);
425
+ av_free (filename_w);
426
+ return ret;
427
+ }
428
+ #endif
429
+
376
430
AVSValue __cdecl CreateLWLibavVideoSource ( AVSValue args, void *user_data, IScriptEnvironment *env )
377
431
{
378
- const char *source = args[0 ].AsString ();
432
+ #ifdef WIN32
433
+ const char *source_
434
+ #else
435
+ const char *source
436
+ #endif
437
+ = args[0 ].AsString ();
379
438
int stream_index = args[1 ].AsInt ( -1 );
380
439
int threads = args[2 ].AsInt ( 0 );
381
440
int no_create_index = args[3 ].AsBool ( true ) ? 0 : 1 ;
@@ -399,6 +458,18 @@ AVSValue __cdecl CreateLWLibavVideoSource( AVSValue args, void *user_data, IScri
399
458
int ff_loglevel = args[15 ].AsInt ( 0 );
400
459
const char * cdir = args[16 ].AsString ( nullptr );
401
460
const bool progress = args[17 ].AsBool (true );
461
+
462
+ #ifdef WIN32
463
+ char * tmp = nullptr ;
464
+ if (ansi_to_utf8 (source_, &tmp))
465
+ env->ThrowError (" LWLibavVideoSource: Cannot allocate filename" );
466
+ if (!tmp)
467
+ env->ThrowError (" LWLibavVideoSource: Cannot retrieve num_chars" );
468
+
469
+ const char * source = tmp;
470
+ av_free (tmp);
471
+ #endif
472
+
402
473
/* Set LW-Libav options. */
403
474
lwlibav_option_t opt;
404
475
opt.file_path = source;
@@ -427,7 +498,12 @@ AVSValue __cdecl CreateLWLibavVideoSource( AVSValue args, void *user_data, IScri
427
498
428
499
AVSValue __cdecl CreateLWLibavAudioSource ( AVSValue args, void *user_data, IScriptEnvironment *env )
429
500
{
430
- const char *source = args[0 ].AsString ();
501
+ #ifdef WIN32
502
+ const char * source_
503
+ #else
504
+ const char * source
505
+ #endif
506
+ = args[0 ].AsString ();
431
507
int stream_index = args[1 ].AsInt ( -1 );
432
508
int no_create_index = args[2 ].AsBool ( true ) ? 0 : 1 ;
433
509
const char *index_file_path = args[3 ].AsString ( nullptr );
@@ -439,6 +515,18 @@ AVSValue __cdecl CreateLWLibavAudioSource( AVSValue args, void *user_data, IScri
439
515
const char * cdir = args[9 ].AsString ( nullptr );
440
516
double drc = args[10 ].AsFloatf ( 1 .0f );
441
517
const bool progress = args[11 ].AsBool (true );
518
+
519
+ #ifdef WIN32
520
+ char * tmp = nullptr ;
521
+ if (ansi_to_utf8 (source_, &tmp))
522
+ env->ThrowError (" LWLibavAudioSource: Cannot allocate filename" );
523
+ if (!tmp)
524
+ env->ThrowError (" LWLibavAudioSource: Cannot retrieve num_chars" );
525
+
526
+ const char * source = tmp;
527
+ av_free (tmp);
528
+ #endif
529
+
442
530
/* Set LW-Libav options. */
443
531
lwlibav_option_t opt;
444
532
opt.file_path = source;
0 commit comments