AVSValue __cdecl CSRIAviSynth::Create(AVSValue args, void* user_data, IScriptEnvironment* env) { const char *rname = args.ArraySize() >= 2 ? args[2].AsString() : NULL, *rver = args.ArraySize() >= 3 ? args[3].AsString() : NULL; return new CSRIAviSynth(args[0].AsClip(), env, args[1].AsString(), rname, rver); }
MVClipArray::MVClipArray(const AVSValue &vectors, int nSCD1, int nSCD2, IScriptEnvironment *env) { DebugPrintf("Constructing mvClipArray... : %i", vectors.ArraySize()); size_ = vectors.ArraySize(); pmvClips = new MVClip*[size_]; for ( int i = 0; i < size_; i++ ) pmvClips[i] = new MVClip(vectors[i].AsClip(), nSCD1, nSCD2, env); }
Echo( PClip _child, const AVSValue _clips, IScriptEnvironment* env ) : GenericVideoFilter(_child), ClipCount(_clips.ArraySize()) { clips = new PClip[ClipCount]; for (int i=0; i < ClipCount; i++) clips[i] = _clips[i].AsClip(); }
AVSValueStruct CAsifScriptEnvironment::Invoke(const char* command) { AVSValueStruct ir; ir.arraysize = 0; ir.errors = false; ir.returnvalue.ival = 0; ir.type = 0; std::vector<const char *> tempargnames(args.size()); for (size_t i = 0; i < tempargnames.size(); i++) tempargnames[i] = (argnames[i].c_str() == "" ? nullptr : argnames[i].c_str()); try { AVSValue ret = envse->Invoke(command, AVSValue(args.data(), args.size()), tempargnames.data()); if (ret.IsClip()) { ir.returnvalue.cval = new CAsifClip(ret.AsClip(), envse); ir.type = 1; } else if (ret.IsBool()) { ir.returnvalue.bval = ret.AsBool(); ir.type = 2; } else if (ret.IsInt()) { ir.returnvalue.ival = ret.AsInt(); ir.type = 3; } else if (ret.IsFloat()) { ir.returnvalue.fval = (float)ret.AsFloat(); ir.type = 4; } else if (ret.IsString()) { ir.returnvalue.sval = ret.AsString(); ir.type = 5; } else if (ret.IsArray()) { // ir.returnvalue.aval=ret. ir.arraysize = ret.ArraySize(); ir.type = 6; } } catch (AvisynthError &e) { ir.type = 100; ir.returnvalue.sval = e.msg; ir.errors = 1; } ResetArgs(); return ir; }
AVSValue LoadPlugin(AVSValue args, void* user_data, IScriptEnvironment* env) { bool quiet = (user_data != 0); args = args[0]; const char* result=0; for (int i=0; i<args.ArraySize(); ++i) { HMODULE plugin; const char* plugin_name = args[i].AsString(); if (MyLoadLibrary(plugin_name, &plugin, quiet, env)) { typedef const char* (__stdcall *AvisynthPluginInitFunc)(IScriptEnvironment* env); AvisynthPluginInitFunc AvisynthPluginInit = (AvisynthPluginInitFunc)dlsym(plugin, "AvisynthPluginInit2"); if (!AvisynthPluginInit) { AvisynthPluginInit = (AvisynthPluginInitFunc)dlsym(plugin, "_AvisynthPluginInit2@4"); /* if (!AvisynthPluginInit) { // Attempt C-plugin AvisynthPluginInit = (AvisynthPluginInitFunc)dlsym(plugin, "avisynth_c_plugin_init"); if (AvisynthPluginInit) { dlclose(plugin); return env->Invoke("LoadCPlugin", args); } } */ if (!AvisynthPluginInit) { // Older version dlclose(plugin); if (quiet) { // remove the last handle from the list HMODULE* loaded_plugins = (HMODULE*)env->GetVar("$Plugins$").AsString(); int j=0; while (loaded_plugins[j+1]) j++; loaded_plugins[j] = 0; } else { env->ThrowError("Plugin %s is not an AviSynth 2.5 plugin.",plugin_name); } } else { result = AvisynthPluginInit(env); } } else { result = AvisynthPluginInit(env); } } } if (loadplugin_prefix) free((void*)loadplugin_prefix); // Tritical May 2005 loadplugin_prefix = 0; return result ? AVSValue(result) : AVSValue(); }
Write::Write (PClip _child, const char* _filename, AVSValue args, int _linecheck, bool _append, bool _flush, IScriptEnvironment* env): GenericVideoFilter(_child), linecheck(_linecheck), flush(_flush), append(_append), arglist(0) { _fullpath(filename, _filename, _MAX_PATH); fout = fopen(filename, append ? AplusT : WplusT); //append or purge file if (!fout) env->ThrowError("Write: File '%s' cannot be opened.", filename); if (flush) fclose(fout); //will be reopened in FileOut arrsize = args.ArraySize(); arglist = new exp_res[arrsize]; for (int i=0; i<arrsize; i++) { arglist[i].expression = args[i].AsString(EMPTY); arglist[i].string = EMPTY; } if (linecheck == -1) { //write at start AVSValue prev_last = env->GetVarDef("last"); // Store previous last AVSValue prev_current_frame = env->GetVarDef("current_frame"); // Store previous current_frame env->SetVar("last", (AVSValue)child); // Set implicit last env->SetVar("current_frame", -1); Write::DoEval(env); Write::FileOut(env, AplusT); env->SetVar("last", prev_last); // Restore implicit last env->SetVar("current_frame", prev_current_frame); // Restore current_frame } if (linecheck == -2) { //write at end, evaluate right now AVSValue prev_last = env->GetVarDef("last"); // Store previous last AVSValue prev_current_frame = env->GetVarDef("current_frame"); // Store previous current_frame env->SetVar("last", (AVSValue)child); // Set implicit last env->SetVar("current_frame", -2); Write::DoEval(env); env->SetVar("last", prev_last); // Restore implicit last env->SetVar("current_frame", prev_current_frame); // Restore current_frame } }
MVMultiExtract::MVMultiExtract(PClip _child, AVSValue _indicies, IScriptEnvironment* env) : GenericVideoFilter(_child), NumIndices(_indicies.ArraySize()) { if ( NumIndices<1 || NumIndices>=vi.height) env->ThrowError("MVMultiExtract : Number of indicies must be between 0 and number of elements in array minus 1"); // extract the indicies for(int IndexNum=0; IndexNum<NumIndices; ++IndexNum) { Index[IndexNum]=_indicies[IndexNum].AsInt(); } // check indicies for(int IndexNum=0; IndexNum<NumIndices; ++IndexNum) { if (Index[IndexNum]<0 || Index[IndexNum]>=vi.height) env->ThrowError("MVMultiExtract: Index must be between 0 and number of elements in array minus 1"); if (IndexNum>0) { if (Index[IndexNum]<=Index[IndexNum-1]) env->ThrowError("MVMultiExtract: Indicies must be in ascending order"); } } // adjust pointer to the appropriate index MVAnalysisData *pAnalyseFilterArray = reinterpret_cast<MVAnalysisData*>(vi.nchannels); if (vi.nchannels >= 0 && vi.nchannels < 9) // seems some normal clip instead of vectors env->ThrowError("MVMultiExtract: invalid vectors stream"); // create array to hold indicies pAnalysisData=new MVAnalysisData[NumIndices]; // update video information for number of rows and pointer to analysis data vi.height=NumIndices; vi.nchannels = reinterpret_cast<int>(pAnalysisData); // copy analysis data rows for(int IndexNum=0; IndexNum<NumIndices; ++IndexNum) { memcpy(reinterpret_cast<void*>(&pAnalysisData[IndexNum]), reinterpret_cast<void const*>(&pAnalyseFilterArray[Index[IndexNum]]), sizeof(MVAnalysisData)); } }
Write::Write (PClip _child, const char _filename[], AVSValue args, int _linecheck, bool _append, bool _flush, IScriptEnvironment* env): GenericVideoFilter(_child), linecheck(_linecheck), flush(_flush), append(_append) { memset(filename, 0, PATH_MAX*sizeof(char)); char* retValue = realpath(_filename, filename); // may check for NULL return value if((NULL == retValue) && (0 == strlen(filename))) { env->ThrowError("Write::Write() failed determining realpath, error = %s\n", strerror(errno)); } arrsize = std::min(args.ArraySize(), maxWriteArgs); int i; for (i=0; i<maxWriteArgs; i++) strcpy(arglist[i].string, ""); for (i=0; i<arrsize; i++) { strncpy(arglist[i].expression, args[i].AsString(""), 254); } if (append) { strcpy(mode, "a+t"); } else { strcpy(mode, "w+t"); } fout = fopen(filename, mode); //append or purge file if (!fout) env->ThrowError("Write: File '%s' cannot be opened.", filename); if (flush) fclose(fout); //will be reopened in FileOut strcpy(mode, "a+t"); // in GetFrame always appending if (linecheck == -1) { //write at start env->SetVar("current_frame",-1); Write::DoEval(env); Write::FileOut(env); } if (linecheck == -2) { //write at end, evaluate right now env->SetVar("current_frame",-2); Write::DoEval(env); } }
ThunkedInterleave::ThunkedInterleave(const ThunkedInterleave_parameter_storage_t& o, AVSValue clips, IScriptEnvironment* env) : ThunkedInterleave_parameter_storage_t(o) { assert(clips.ArraySize() > 0); memset(&_vi, 0, sizeof(_vi)); memset(&_clips, 0, sizeof(_clips)); if (_thunk_size <= 0) { env->ThrowError("SelectThunkEvery: thunk_size must be greater than 0."); } _clip_count = clips.ArraySize(); if (_clip_count > MAX_CLIPS) { env->ThrowError("ThunkedInterleave: Too many clips."); } int framecount_full = 0; bool found_last_part = false; _vi = clips[0].AsClip()->GetVideoInfo(); _vi.num_frames = 0; _vi.audio_samples_per_second = 0; for (int i = 0; i < _clip_count; i++) { _clips[i] = clips[i].AsClip(); const VideoInfo& clip_vi = _clips[i]->GetVideoInfo(); if (!clip_vi.IsSameColorspace(_vi) || clip_vi.width != _vi.width || clip_vi.height != _vi.height || (clip_vi.image_type & 7) != (_vi.image_type & 7) // Seems someone uses this field to store flags? ) { cleanup_clips(); env->ThrowError("ThunkedInterleave: Clip #%d doesn't have correct parameters.", i); } if (framecount_full <= 0) { framecount_full = clip_vi.num_frames; if (framecount_full % _thunk_size != 0) { framecount_full = _thunk_size * (framecount_full / _thunk_size + 1); found_last_part = true; } } else if (clip_vi.num_frames > framecount_full) { cleanup_clips(); env->ThrowError("ThunkedInterleave: Clip #%d has incorrect frame count (%d). It should be the same as or less than frame count of Clip #0 (%d).", i, clip_vi.num_frames, framecount_full); } else if (clip_vi.num_frames < framecount_full) { int diff = framecount_full - clip_vi.num_frames; assert(diff > 0); if (diff > _thunk_size) { cleanup_clips(); env->ThrowError("ThunkedInterleave: Clip #%d has incorrect frame count (%d). It shouldn't be more than one thunk less than frame count of Clip #0 (%d).", i, clip_vi.num_frames, framecount_full); } else if (diff < _thunk_size) { if (found_last_part) { cleanup_clips(); env->ThrowError("ThunkedInterleave: Clip #%d has incorrect frame count (%d). It should be one thunk less than frame count of Clip #0 since it is after the clip with last thunk (%d).", i, clip_vi.num_frames, framecount_full); } found_last_part = true; } else { // diff == _thunk_size found_last_part = true; } } else { // clip_vi.num_frames == framecount_full if (found_last_part) { cleanup_clips(); env->ThrowError("ThunkedInterleave: Clip #%d has incorrect frame count (%d). It should be one thunk less than frame count of Clip #0 since it is after the clip with last thunk (%d).", i, clip_vi.num_frames, framecount_full); } } _vi.num_frames += clip_vi.num_frames; } _vi.MulDivFPS(_clip_count, 1); }