]> git.sesse.net Git - x264/commitdiff
Detect Avisynth initialization failures
authorSteven Walters <kemuri9@gmail.com>
Thu, 14 Oct 2010 01:53:50 +0000 (21:53 -0400)
committerFiona Glaser <fiona@x264.com>
Tue, 7 Dec 2010 02:57:00 +0000 (18:57 -0800)
Detect if there is a critical Avisynth initialization failure and print the associated error.
This, however, requires a feature present in the latest version of Avisynth alpha (2.6).
Previous versions are unaffected.

extras/avisynth_c.h
input/avs.c

index 64deaadfc1c092045f7228691bdc82002318185f..5044efb0aa6816eac59c80c9a85b422d588cb2a4 100644 (file)
@@ -552,7 +552,7 @@ AVSC_INLINE int avs_array_size(AVS_Value v)
 AVSC_INLINE AVS_Value avs_array_elt(AVS_Value v, int index) 
         { return avs_is_array(v) ? v.d.array[index] : v; }
 
-// only use these functions on am AVS_Value that does not already have
+// only use these functions on an AVS_Value that does not already have
 // an active value.  Remember, treat AVS_Value as a fat pointer.
 AVSC_INLINE AVS_Value avs_new_value_bool(int v0) 
         { AVS_Value v; v.type = 'b'; v.d.boolean = v0 == 0 ? 0 : 1; return v; }   
@@ -660,6 +660,7 @@ enum {
   AVS_CPUF_SSE4_2     = 0x800,   //  Nehalem
 };
 
+AVSC_API(const char *, avs_get_error)(AVS_ScriptEnvironment *); // return 0 if no error
 
 AVSC_API(long, avs_get_cpu_flags)(AVS_ScriptEnvironment *);
 AVSC_API(int, avs_check_version)(AVS_ScriptEnvironment *, int version);
@@ -771,6 +772,7 @@ struct AVS_Library {
   AVSC_DECLARE_FUNC(avs_function_exists);
   AVSC_DECLARE_FUNC(avs_get_audio);
   AVSC_DECLARE_FUNC(avs_get_cpu_flags);
+  AVSC_DECLARE_FUNC(avs_get_error);
   AVSC_DECLARE_FUNC(avs_get_frame);
   AVSC_DECLARE_FUNC(avs_get_parity);
   AVSC_DECLARE_FUNC(avs_get_var);
@@ -829,6 +831,7 @@ AVSC_INLINE AVS_Library * avs_load_library() {
   AVSC_LOAD_FUNC(avs_function_exists);
   AVSC_LOAD_FUNC(avs_get_audio);
   AVSC_LOAD_FUNC(avs_get_cpu_flags);
+  AVSC_LOAD_FUNC(avs_get_error);
   AVSC_LOAD_FUNC(avs_get_frame);
   AVSC_LOAD_FUNC(avs_get_parity);
   AVSC_LOAD_FUNC(avs_get_var);
index 7cfdfd8dbdce0685001b32e6ea69fc6736cf3593..5bd8dcd4f43034070da54486abeb428784beb18a 100644 (file)
@@ -61,6 +61,7 @@ typedef struct
         AVSC_DECLARE_FUNC( avs_clip_get_error );
         AVSC_DECLARE_FUNC( avs_create_script_environment );
         AVSC_DECLARE_FUNC( avs_delete_script_environment );
+        AVSC_DECLARE_FUNC( avs_get_error );
         AVSC_DECLARE_FUNC( avs_get_frame );
         AVSC_DECLARE_FUNC( avs_get_video_info );
         AVSC_DECLARE_FUNC( avs_function_exists );
@@ -81,6 +82,7 @@ static int x264_avs_load_library( avs_hnd_t *h )
     LOAD_AVS_FUNC( avs_clip_get_error, 0 );
     LOAD_AVS_FUNC( avs_create_script_environment, 0 );
     LOAD_AVS_FUNC( avs_delete_script_environment, 1 );
+    LOAD_AVS_FUNC( avs_get_error, 1 );
     LOAD_AVS_FUNC( avs_get_frame, 0 );
     LOAD_AVS_FUNC( avs_get_video_info, 0 );
     LOAD_AVS_FUNC( avs_function_exists, 0 );
@@ -132,7 +134,11 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
         return -1;
     FAIL_IF_ERROR( x264_avs_load_library( h ), "failed to load avisynth\n" )
     h->env = h->func.avs_create_script_environment( AVS_INTERFACE_25 );
-    FAIL_IF_ERROR( !h->env, "failed to initiate avisynth\n" )
+    if( h->func.avs_get_error )
+    {
+        const char *error = h->func.avs_get_error( h->env );
+        FAIL_IF_ERROR( error, "%s\n", error );
+    }
     AVS_Value arg = avs_new_value_string( psz_filename );
     AVS_Value res;
     char *filename_ext = get_filename_extension( psz_filename );