Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 17th December 2006, 02:39   #21  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
I would encourage all users to read the plugin docs.
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick
I usually do not provide a technical support in private messages.
Fizick is offline   Reply With Quote
Old 17th December 2006, 07:04   #22  |  Link
3ngel
Registered User
 
Join Date: Mar 2005
Posts: 457
And i dont' understand what does it cost you to add 3 rows of code as a
// Approx code
if(!Loadlibrary("fftw3.dll"))
{
path=Getcwd()
or
path=GetDllDirectory()
Loadlibrary(path + "fftw3.dll"))
}

// Second example
Path=SetDllDirectory(Getcwd())
or
Path=SetDllDirectory(GetDllDirectory())

Last edited by 3ngel; 17th December 2006 at 07:19.
3ngel is offline   Reply With Quote
Old 17th December 2006, 11:26   #23  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
Why stop here?
Lets search all user hard disk for the DLL, them CDROM, floppy.
Not found? Lets repeat full disks search for all Zip archives, and automatically unpack the Dll.
Not found? Lets connent to Internet, automatically download and install DLL.
Not found? Lets make automatical call to authors phone.
Not help? RTFM at last.
__________________
My Avisynth plugins are now at http://avisynth.org.ru and mirror at http://avisynth.nl/users/fizick
I usually do not provide a technical support in private messages.
Fizick is offline   Reply With Quote
Old 17th December 2006, 11:30   #24  |  Link
3ngel
Registered User
 
Join Date: Mar 2005
Posts: 457
Don't say nonsense.
I think it's a minimum for a plugin to search in its own folder!

PS: If my code doesn't work and Getcwd() returns Avisynth dir, then IanB code sure will do.

Last edited by 3ngel; 17th December 2006 at 11:51.
3ngel is offline   Reply With Quote
Old 17th December 2006, 14:26   #25  |  Link
3ngel
Registered User
 
Join Date: Mar 2005
Posts: 457
Quote:
@3ngel, Please don't get bent out of shape, it does not help.
Oh, really? Pheraps i've not undestood well, but I thought, seeing the code that you've got the dirpath of the plugin .dll starting from its memory address, and then use that dirpath to load the fftw3.dll (same path).

Quote:
You have asked for something that actually requires a fair amount of thought and trickery to correctly and portably implement.
I don't think at all. I want only that a .dll load another .dll (that is located in /thesamediroftheplugin/whatihavetowritenowidontknow instead of /system32) and use it. I don't think it's so complicated.

The most simple way would be the first i said, that it was avisynth that load the library (through a custom external command LoadExternalDll("path")). At this point having already loaded the library (fftw3.dll) the next plugin requiring it, when it does the loadlibrary it doesn't search in the PATH 'cause it's already available in memory, loaded by avisynth.
At the end of the script there would be a freeing command
UnloadExternalLibraries("Path")
or better
UnloadExternalLibraries() with an internal implemented stack that automatically unload all the library references in the stack.
Better again
....
There is no need for a function. Avisynth automatically call at the end of the script UnloadExternalLibraries() to unload the (eventually) loaded library
It seem to you so complicated (even from an avisynth point of view)?

Last edited by 3ngel; 17th December 2006 at 14:30.
3ngel is offline   Reply With Quote
Old 17th December 2006, 15:06   #26  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
3ngel of this 3 solution to your problem with of them seems to be the best?
1) require every user of a filter that needs to load a dll to use a LoadExternalDll command before calling the filter and at the same time requires the developer of avisynth to add the necessary code to the next version and at the same time figure out a way to let the filters get the required handles to the loaded dll. This will also require that the filters to be rewritten and compiled to support this (and it will only work with the new version on avisynth).
2) the filter developer just copy paste the code that Ian provide and include it in the next version of their filter (or the user that really needs this downloads microsoft visual c++ express and make the change themselves)
3) the user copies the external dll to a directory in the PATH (like windows\system32) or modify the PATH so that the plugin directory is included
__________________
Get my avisynth filters @ http://www.avisynth.org/tsp/
tsp is offline   Reply With Quote
Old 17th December 2006, 16:16   #27  |  Link
3ngel
Registered User
 
Join Date: Mar 2005
Posts: 457
Personally for me, 2 could be the best (filter developer willingly). Number 1 could also be good because
Quote:
same time figure out a way to let the filters get the required handles to the loaded dll
there is no need to pass a handler to the filter. The filters doesn't need any modification because when avisynth load the library the entire library stays in memory. When the plugin call LoadLibrary("") windows get the library from memory (that is a private copy of the library loaded previously by avisynth).
3ngel is offline   Reply With Quote
Old 17th December 2006, 16:32   #28  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
Quote:
Originally Posted by 3ngel View Post
Personally for me, 2 could be the best (filter developer willingly). Number 1 could also be good because

there is no need to pass a handler to the filter. The filters doesn't need any modification because when avisynth load the library the entire library stays in memory. When the plugin call LoadLibrary("") windows get the library from memory (that is a private copy of the library loaded previously by avisynth).
hmm seems you are right about that. I will create the filter for you tomorrow when I get home from work.
__________________
Get my avisynth filters @ http://www.avisynth.org/tsp/
tsp is offline   Reply With Quote
Old 18th December 2006, 10:41   #29  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
sorry 3ngel it was very easy to create the filter (about 20 minutes) . You can download it here.

The only reason not to add it to avisynth was that not many will need it so it may just clutter up the number of built in functions

here is the sourcecode for the filter:
Code:
// LoadDll
// Copyright(C)2006 Tonny Petersen (tsp@person.dk) 
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
// http://www.gnu.org/copyleft/gpl.html .

#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include "avisynth.h"

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    return TRUE;
}

void __cdecl UnloadDll(void* hinst,IScriptEnvironment* env)
{
	if(hinst)
		FreeLibrary(static_cast<HMODULE>(hinst)); 
}

AVSValue __cdecl LoadDll(AVSValue args, void* user_data, IScriptEnvironment* env){
	HMODULE hinst=0;
	hinst=LoadLibrary(args[0].AsString());
	env->AtExit(UnloadDll,hinst);
	return hinst!=NULL;
}

extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) {
	env->AddFunction("loaddll", "s", LoadDll, 0);
	return "loaddll 1.0";
}
__________________
Get my avisynth filters @ http://www.avisynth.org/tsp/
tsp is offline   Reply With Quote
Old 18th December 2006, 11:53   #30  |  Link
3ngel
Registered User
 
Join Date: Mar 2005
Posts: 457
Fantastic tsp, it works great!

Thank you so much!

It wasn't so complicated, nč IanB? (joking eh thanks for you precious code)

One question tsp,
what happen if i call 2 times the loadll?
I see you do a FreeLibrary() only for one instance.
On the second instance what happens?
Are two separate instances of Loaddll created (so each one frees its own library) or there is one .dll that remains in memory? (i don't know the functioning of avisynth environment)

EDIT: I put the link on the first post.

Last edited by 3ngel; 18th December 2006 at 11:57.
3ngel is offline   Reply With Quote
Old 18th December 2006, 12:20   #31  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
if you have this script:
Code:
loaddll(c:\fftw3.dll")
loaddll(c:\fftw3.dll")
blackness().converttoyv12()
fft3dfilter()
the first instance of loaddll loads fft3w.dll into memory and increases the reference count of fftw3 library to 1 (or rather loadlibrary does that)
the next instance of loaddll increases the reference count to 2(as the dll is already loaded)
and finally fft3dfilter increases the reference count to 3
when the script is closed first fft3dfilter is destroyed. This decreases the reference count to 2 (this happends when it calls freelibrary)
next avisynth calls UnloadDll from the second instance of loadDll that calls freelibrary that decreases the reference count to 1
and finally avisynth runs the first instance UnloadDll and the reference count decreases to 0 and fftw.dll is unloaded from memory.
__________________
Get my avisynth filters @ http://www.avisynth.org/tsp/
tsp is offline   Reply With Quote
Old 18th December 2006, 12:24   #32  |  Link
3ngel
Registered User
 
Join Date: Mar 2005
Posts: 457
I see.

Last edited by 3ngel; 6th January 2007 at 15:53.
3ngel is offline   Reply With Quote
Old 27th July 2014, 14:03   #33  |  Link
Reino
Registered User
 
Reino's Avatar
 
Join Date: Nov 2005
Posts: 693
Because tsp's last activity was on 1st May 2009 and because avisynth.org has moved to avisynth.nl, his filters are now to be found here and LoadDll you can download here.
--------------------------------

BassAudioSource_test.avs:
Code:
LoadDll("D:\tak_deco_lib.dll")
BassAudioSource("sample(2ch).tak")


Playing AviSynth-scripts (with LoadDll) in MPC-HC has never been a problem, but recently I noticed that, unlike with MPC-HC, the above error-message pops up while opening avs-files with ffmpeg.exe, ffplay.exe and avs2pipemod.exe as well.
This error always pops up, whatever the map LoadDll is pointing to (even the most simple one, D:\), with the exception of AviSynth's plugin-map.
It's not a usage blocking issue though, because ffmpeg.exe, ffplay.exe and avs2pipemod.exe appear to continue/work normally after that, but it is annoying.
Does someone with coding experience know how to easily fix this in LoadDll?
__________________
My hobby website
Reino is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 15:17.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.