mp4: Remove GPAC Windows Unicode compatibility shim
GPAC has native UTF-8 support nowadays. Also move the compatibility code to input/avs.c since that's the only remaining code that uses it now.
This commit is contained in:
+27
-1
@@ -253,6 +253,32 @@ static float get_avs_version( avs_hnd_t *h )
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
static int utf16_to_ansi( const wchar_t *utf16, char *ansi )
|
||||
{
|
||||
BOOL invalid;
|
||||
return WideCharToMultiByte( CP_ACP, WC_NO_BEST_FIT_CHARS, utf16, -1, ansi, MAX_PATH, NULL, &invalid ) && !invalid;
|
||||
}
|
||||
|
||||
static int utf8_to_ansi( const char *filename, char *ansi_filename )
|
||||
{
|
||||
wchar_t filename_utf16[MAX_PATH];
|
||||
if( utf8_to_utf16( filename, filename_utf16 ) )
|
||||
{
|
||||
/* Check if the filename already is valid ANSI. */
|
||||
if( utf16_to_ansi( filename_utf16, ansi_filename ) )
|
||||
return 1;
|
||||
|
||||
/* Check for a legacy 8.3 short filename. */
|
||||
int short_length = GetShortPathNameW( filename_utf16, filename_utf16, MAX_PATH );
|
||||
if( short_length > 0 && short_length < MAX_PATH )
|
||||
if( utf16_to_ansi( filename_utf16, ansi_filename ) )
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt )
|
||||
{
|
||||
FILE *fh = x264_fopen( psz_filename, "r" );
|
||||
@@ -280,7 +306,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
|
||||
#ifdef _WIN32
|
||||
/* Avisynth doesn't support Unicode filenames. */
|
||||
char ansi_filename[MAX_PATH];
|
||||
FAIL_IF_ERROR( !x264_ansi_filename( psz_filename, ansi_filename, MAX_PATH, 0 ), "invalid ansi filename\n" );
|
||||
FAIL_IF_ERROR( !utf8_to_ansi( psz_filename, ansi_filename ), "invalid ansi filename\n" );
|
||||
AVS_Value arg = avs_new_value_string( ansi_filename );
|
||||
#else
|
||||
AVS_Value arg = avs_new_value_string( psz_filename );
|
||||
|
||||
@@ -27,10 +27,6 @@
|
||||
#include "output.h"
|
||||
#include <gpac/isomedia.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GF_ISOFile *p_file;
|
||||
@@ -181,15 +177,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt
|
||||
if( !p_mp4 )
|
||||
return -1;
|
||||
|
||||
#ifdef _WIN32
|
||||
/* GPAC doesn't support Unicode filenames. */
|
||||
char ansi_filename[MAX_PATH];
|
||||
FAIL_IF_ERR( !x264_ansi_filename( psz_filename, ansi_filename, MAX_PATH, 1 ), "mp4", "invalid ansi filename\n" );
|
||||
p_mp4->p_file = gf_isom_open( ansi_filename, GF_ISOM_OPEN_WRITE, NULL );
|
||||
#else
|
||||
p_mp4->p_file = gf_isom_open( psz_filename, GF_ISOM_OPEN_WRITE, NULL );
|
||||
#endif
|
||||
|
||||
p_mp4->b_dts_compress = opt->use_dts_compress;
|
||||
|
||||
if( !(p_mp4->p_sample = gf_isom_sample_new()) )
|
||||
|
||||
@@ -84,40 +84,6 @@ void x264_cli_set_console_title( const char *title )
|
||||
SetConsoleTitleW( title_utf16 );
|
||||
}
|
||||
|
||||
static int utf16_to_ansi( const wchar_t *utf16, char *ansi, int size )
|
||||
{
|
||||
int invalid;
|
||||
return WideCharToMultiByte( CP_ACP, WC_NO_BEST_FIT_CHARS, utf16, -1, ansi, size, NULL, &invalid ) && !invalid;
|
||||
}
|
||||
|
||||
/* Some external libraries doesn't support Unicode in filenames,
|
||||
* as a workaround we can try to get an ANSI filename instead. */
|
||||
int x264_ansi_filename( const char *filename, char *ansi_filename, int size, int create_file )
|
||||
{
|
||||
wchar_t filename_utf16[MAX_PATH];
|
||||
if( utf8_to_utf16( filename, filename_utf16 ) )
|
||||
{
|
||||
if( create_file )
|
||||
{
|
||||
/* Create the file using the Unicode filename if it doesn't already exist. */
|
||||
FILE *fh = _wfopen( filename_utf16, L"ab" );
|
||||
if( fh )
|
||||
fclose( fh );
|
||||
}
|
||||
|
||||
/* Check if the filename already is valid ANSI. */
|
||||
if( utf16_to_ansi( filename_utf16, ansi_filename, size ) )
|
||||
return 1;
|
||||
|
||||
/* Check for a legacy 8.3 short filename. */
|
||||
int short_length = GetShortPathNameW( filename_utf16, filename_utf16, MAX_PATH );
|
||||
if( short_length > 0 && short_length < MAX_PATH )
|
||||
if( utf16_to_ansi( filename_utf16, ansi_filename, size ) )
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Retrieve command line arguments as UTF-8. */
|
||||
static int get_argv_utf8( int *argc_ptr, char ***argv_ptr )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user