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. |
13th January 2012, 10:26 | #1 | Link |
Registered User
Join Date: Dec 2011
Location: West Somerset, UK
Posts: 130
|
Filter/plugin lifecycle
I may be being picky, but is there a distinct end-point to the life-cycle of a plugin? I ask as I allocate memory at the start of processing (during the first frame request) and keep this (references from userData in params) throughout the life of the plugin.
When should I free it? I thought that maybe I could calculate the last frame to be requested, but I can see problems with that. For example I build the data that goes in this allocated memory by looking at every single frame the previous filter in the chain will provide. So if someone else did this to me I would be freeing the memory and recalculating the data more frequently than needed. I was always taught that 'if you open it, shut it, if you take it out put it back, if you allocate it then free it'. What do folk here do? |
13th January 2012, 11:17 | #2 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
I believe you are using the C API.
In that case, you should set the free_filter member of your AVS_FilterInfo to be a function that does the required freeing of memory. Things are simpler when using the C++ API as you would simply do the freeing in the filter's destructor. You cannot know what is the last frame to be rendered since frame requests can come in any order. |
13th January 2012, 12:11 | #3 | Link | |
Registered User
Join Date: Dec 2011
Location: West Somerset, UK
Posts: 130
|
Quote:
You are right, I am using the C API. I did not know that there was a FreeFilter function. Where might I find more info, please. I will look around for it myself, but may miss it, so any pointers would be very helpful. |
|
13th January 2012, 12:49 | #4 | Link |
Registered User
Join Date: Dec 2011
Location: West Somerset, UK
Posts: 130
|
Ahh, I think I have got it
Code:
void AVSC_CC freeFilter(AVS_FilterInfo *) { MyParams* params = (MyParams*) p->user_data; // free the memory here } AVS_Value AVSC_CC extractMotion(AVS_ScriptEnvironment * env, AVS_Value args, void * use_inplace) { AVS_Value v; AVS_FilterInfo * fi; (........................) fi->user_data = (void*) params; fi->get_frame = extractMotionGetFrame; // my function to return frames fi->free_filter = freeFilter; // my function to free resources v = avs_new_value_clip(new_clip); (.......................) return v; } Code:
params->uberMask = new int[dataSize]; Code:
params->uberMask = malloc(dataSize * sizeof(int)); (............................) mfree(params->uberMask); params->uberMask = 0; |
13th January 2012, 13:10 | #5 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Code:
delete [] params->ubermask; (Perhaps you don't know C++ well or don't have a Microsoft compiler.) The C++ API is much simpler to use (and doesn't really require advanced knowledge of C++). Last edited by Gavino; 13th January 2012 at 13:13. |
|
13th January 2012, 13:36 | #6 | Link | |
Registered User
Join Date: Dec 2011
Location: West Somerset, UK
Posts: 130
|
Quote:
I am using Codeblocks and its default compiler because I liked the price. I am using C rather than C++ because I thought I read that in order to compile C++ I needed some stuff associated with MSVC++ and that that would drag down a load of .NET, all of which seems like overkill for a hundred lines of source code. I am as adept at C++ as I am at C, but both of those were last used in anger (i.e. commercially) some two decades or more ago (yep, old duffer now). I code for a hobby now, but prefer Java (since Smalltalk is passé). The similarities between languages make swapping easier (algorithms are nearly identical) and harder (when dealing with low level stuff like actual memory). I have nearly finalised my code now - I have added a 'blur' stage to the the uber-mask which helps remove small areas of persistent but uninteresting change. I will comment the code heavily and make it available to anyone interested. Probably on SourceForge. |
|
15th January 2012, 20:49 | #7 | Link |
Registered User
Join Date: Aug 2007
Posts: 374
|
Native API of Avisynth is C++, C one is ugly hack in my opinion. Use of MSVC won't drag any .NET until you actually use it, if IDE of it isn't needed - look at the PlatformSDK, it also contains compiler and required libraries.
|
15th January 2012, 21:51 | #8 | Link | |
Registered User
Join Date: Dec 2011
Location: West Somerset, UK
Posts: 130
|
Quote:
I have a filter doing roughly what I want now. (I am on stage three of 'make it work, make it right, make it fast'). I am not sure that I want to install a load more gorp and learn to drive another set of compile tools unless there is a big benefit. Maybe if I think of another filter I need then that will enthuse me. But if anyone is rewriting AVISynth in Java, please give me a call........... |
|
16th January 2012, 09:21 | #10 | Link | |
Registered User
Join Date: Dec 2011
Location: West Somerset, UK
Posts: 130
|
Quote:
|
|
16th January 2012, 10:08 | #11 | Link | |
Registered User
Join Date: Mar 2009
Location: Germany
Posts: 5,769
|
Quote:
C++ is portable enough .
__________________
Born in the USB (not USA) |
|
16th January 2012, 17:13 | #12 | Link | |
Guest
Posts: n/a
|
Quote:
Last edited by amtm; 16th January 2012 at 17:15. |
|
17th January 2012, 11:01 | #14 | Link | ||
Registered User
Join Date: Dec 2011
Location: West Somerset, UK
Posts: 130
|
Quote:
Quote:
Of course, the killer argument against a rewrite is that AVISynth works, it works well, and it works now. Nuff said, and sorry I opened that can of worms..... Phill |
||
Thread Tools | Search this Thread |
Display Modes | |
|
|