kemuri-_9
12th October 2009, 01:58
I've been trying to extend x264 to be able to open .avs files through avisynth.dll directly
rather than let windows do it through the VFW interface,
but I've been having an issue with it I've not been able to fix.
the code fragment surrounding the issue is
typedef struct {
PClip clip;
IScriptEnvironment *env;
HMODULE lib;
} avs_input_t;
int open_file_avs( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
{
avs_input_t *h = (avs_input_t*)malloc( sizeof(avs_input_t) );
int i_frames;
if( !h )
return -1;
try
{
h->lib = LoadLibrary( "avisynth" );
if( !h->lib )
{
fprintf( stderr, "avs [error]: failed to load avisynth" );
return -1;
}
IScriptEnvironment* (* CreateScriptEnvironment)( int version ) =
(IScriptEnvironment*(*)(int)) GetProcAddress( h->lib, "CreateScriptEnvironment" );
if( !CreateScriptEnvironment )
{
fprintf( stderr, "avs [error]: failed to load CreateScriptEnvironment()\n" );
return -1;
}
h->env = CreateScriptEnvironment( AVISYNTH_INTERFACE_VERSION );
if( !h->env )
{
fprintf( stderr, "avs [error]: failed to initiate CreateScriptEnvironment()\n" );
return -1;
}
AVSValue arg( psz_filename );
AVSValue res = h->env->Invoke( "Import", arg );
...
}
the issue is that
h->env = CreateScriptEnvironment( AVISYNTH_INTERFACE_VERSION );
is corrupting the EAX register, so a seg fault occurs shortly thereafter.
I'm exporting this and some other related functions as C, since x264 is currently completely only in C
I chose to use the C++ interface and export the function as C because the C interface does not seem be well maintained...
Is the EAX register corrupting a known issue for this kind of situation?
Or am I just going to have to bite the bullet and use the C interface?
rather than let windows do it through the VFW interface,
but I've been having an issue with it I've not been able to fix.
the code fragment surrounding the issue is
typedef struct {
PClip clip;
IScriptEnvironment *env;
HMODULE lib;
} avs_input_t;
int open_file_avs( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
{
avs_input_t *h = (avs_input_t*)malloc( sizeof(avs_input_t) );
int i_frames;
if( !h )
return -1;
try
{
h->lib = LoadLibrary( "avisynth" );
if( !h->lib )
{
fprintf( stderr, "avs [error]: failed to load avisynth" );
return -1;
}
IScriptEnvironment* (* CreateScriptEnvironment)( int version ) =
(IScriptEnvironment*(*)(int)) GetProcAddress( h->lib, "CreateScriptEnvironment" );
if( !CreateScriptEnvironment )
{
fprintf( stderr, "avs [error]: failed to load CreateScriptEnvironment()\n" );
return -1;
}
h->env = CreateScriptEnvironment( AVISYNTH_INTERFACE_VERSION );
if( !h->env )
{
fprintf( stderr, "avs [error]: failed to initiate CreateScriptEnvironment()\n" );
return -1;
}
AVSValue arg( psz_filename );
AVSValue res = h->env->Invoke( "Import", arg );
...
}
the issue is that
h->env = CreateScriptEnvironment( AVISYNTH_INTERFACE_VERSION );
is corrupting the EAX register, so a seg fault occurs shortly thereafter.
I'm exporting this and some other related functions as C, since x264 is currently completely only in C
I chose to use the C++ interface and export the function as C because the C interface does not seem be well maintained...
Is the EAX register corrupting a known issue for this kind of situation?
Or am I just going to have to bite the bullet and use the C interface?