PDA

View Full Version : use of NEW, safe area, def file


vcmohan
1st November 2003, 04:12
I have seen in some plugin source opening of a file FILTER.def for accessing parameters passed as strings and checking them and putting default values if needed etc. However when I tried it I could not get that file opened for reading. I am using a 2.5+ version. Was this implemented? cat(Getvar $plugindir, "FILTER.def")

I read reference of SAFE area for a FILTER to store strings which will be alive till the FILTER is active. Where is this safe area? I intend to use this facility to debug the plugin. Is there a way to keep this safe area so that it can be seen after?

In a plugin I am writing I need to create a NewVideoFrame everytime. It is used as a work area. This sometimes is returned as the frame and sometimes some other input frame is returned. Thereby there can be a lot of new frames created. I hope that Avisynth takes care of these unreturned new frames. Or do I need to delete them? If there is some problem then I need to create a buffer with regular new expression of C and Delete it before returning? That is I will use it as a work area. Can I use the writeptr of the new frame as a readptr also?

Bidoche
1st November 2003, 11:00
You don't have to delete them, VideoFrames are handled by the smart pointer PVideoFrame who take cares of recycling no longer used ones.

And yes a write ptr is a read ptr too.

vcmohan
2nd November 2003, 03:19
Thanks. Apart from the other two issues to be clarified I have some doubts. One can get height and width by vi, height and vi.width. I assume these will be pixels. However I see in all the source these parameters are derived as GetHeight and GetRowsize commands and then calculate width by dividing with bytes per pixel. Is there some difference? I have these doubts as when I am using the width and height values I am ending with negative values sometimes.

Si
2nd November 2003, 08:35
vi.width/height are the width and height (in pixels) of the video frame.

GetRowSize returns the number of bytes in each row e.g if vi.width =480 the GetRowSize returns 960 if YUY2 colourspace, 1920 if RGB32, 480 for the Y plane and 240 for the U or V planes if using YV12 colourspace.

Similarly, GetRowHeight returns the height of the plane not the frame. It is always the same as the frame height except for the U and V planes in YV12 as they are half the height of the frame.

regards
Simon

vcmohan
3rd November 2003, 02:23
Thanks. What about the def file For checking the arguments?

Si
3rd November 2003, 08:44
The .def file concept was neuron2's.

The only info I know about is here (http://forum.doom9.org/showthread.php?s=&threadid=32532&highlight=telecide.def)

regards
Simon

neuron2
6th November 2003, 21:56
The .def file handling is not an Avisynth core function. It is implemented within the filter code. I use it in several of my filters and I believe marcfd also used it for at least one of his filters.

vcmohan
9th November 2003, 06:26
I am attempting to write transition software. The frame number n and vi.num_frames values are used. The simplest is to trim both clips to same size (left clip end part and right clip start part) process and then splice. Otherwise get n for left, if it is in range process. However it probably means Avisynth need to call the transition for every frame, which may take unnecessary time, but eliminates one trim and one splice. Please advise as to which is a better approach.

One other issue. There are many parts common for various types of transitions. Will it be better to make seperate plugin for individual transition type or create one large pack covering as many as possible, but making it rather difficult to debug and maintain.

Bidoche
9th November 2003, 12:10
My opinion is to avoid reinventing Trim and Splice, use them it will be simpler.

vcmohan
21st December 2003, 04:16
Thanks. I also thought so and proceeded. Now I have coded for the wipes, doors, rotations, rolls, patterns and scratch card transitions. All these work for RGB32, RGB24 and YuY2. (in one case when resize and rotation were opted together I get a color striped frame). I did not attempt YV12 as the coding required seems to be daunting. Also the interpolation required for resize and rotation are problematic in these color formats.

Will any one host these transitions? Whom should I contact?

Richard Berg
21st December 2003, 08:08
I can give you space on avisynth.org if need be.

vcmohan
22nd December 2003, 03:05
Thanks. I will comeback in a few days after I am satisfied fully wiyh my work.

vcmohan
30th December 2003, 14:53
Originally posted by Richard Berg
I can give you space on avisynth.org if need be.

Thanks. I am ready with several plugins. I would like to release the plugin dlls and scripting instructions together as one zip file for each of the plugins. I will release the source if also required. Should I Email you these files? Or what is the way?

I also need help in one issue. In one plugin I need to have a static array of about 200 integers which I can update and access. Where in the plugin code I can keep it? I find I can not keep it in the main public areas as the compiler says extern --- could not be resolved.
Other places are transients.

vcmohan
2nd January 2004, 04:07
I am trying to use the safe area to get some values which were generated in earlier frame processing. I have a two or 4 integers I tried store by calling the SaveString or Sprintf. I am not sure whether the pointer I get back is the one pointing to the start of this string stored or that will point to a new string. How do I acess the very first string and the subsequent strings (or the formatted values which I presume need to be recovered by a call to atoi(). All the trials are resulting in getting some wild values. Some times I get back values but probably because the system is keeping the same area of memory and my buffer in program has those values already.
I used the code
safe1=Sprintf("%d", array[1]);
safe2=Sprintf("d", array[2]);
slen=safe2-safe1;

start of safe=safe2-(n+1)*slen;
array[1]=atoi(safe);
array[2]=atoi(safe+slen);
I do not seem to suceed in pointing correctly.
Whats wrong?

Bidoche
2nd January 2004, 12:11
I don't really understand what you are trying to do, but :
- only SaveString saves string (by copying in memory zones specially allocated for that), sprintf is just a printf working working on char *
- I strongly suggest you take a look at std::string, it may need some time to get the hang of it, but it definitely helps getting rid of char * annoying features.

vcmohan
3rd January 2004, 02:55
sorry there were typos in my code.
It should read as
safe1=Sprintf("%d", array[1]);
safe2=Sprintf("%d", array[2]);
slen=safe2-safe1;// this should give length of string assuming storing consequetively

safe=safe2-(n+1)*slen;// start of safe area? n is frame number
array[1]=atoi(safe); // here I use a loop to get all previous strings
array[2]=atoi(safe+slen);
I do not seem to suceed in pointing correctly.
Whats wrong?
As per the writing plugins doc quote
virtual char* SaveString(const char* s, int length = -1);

This function copies its argument to a safe "permanent" location and returns a pointer to the ?new location.

Each ScriptEnvironment instance has a buffer set aside for storing strings, which is expanded as needed. The strings are not deleted until the ScriptEnvironment instance goes away (when the script file is closed, usually). This is usually all the permanence that is needed, since all related filter instances will already be gone by then.

The returned pointer is not const-qualified, and you're welcome to write to it, as long as you don't stray beyond the bounds of the string.

virtual char* Sprintf(const char* fmt, ...);

virtual char* VSprintf(const char* fmt, char* val);

These store strings away in the same way as SaveString, but they treat their arguments like printf and vprintf.

Currently there's a size limit of 4096 characters on strings created this way. (The implementation uses _vsnprintf, so you don't need to worry about buffer overrun.)
unquote
So Sprintf stores in the safe area which I should be able to retreive


In each frame I derive some two values which for all purposes are random. I need to get these values for subsequent frame processing. I tried to have static in the class but it refused to compile. In the Get frame area static doesnt seem to carry the values to next frame ( except when the same memory area is allotted at the next instance which can not be taken for granted.)
I thought that the strings formatted or unformatted are saved next to each other in the safe area. But when I examined them by printing out the contents through Throw Error call pointing to this area I get long long strings with the values I stored somewhere within. But also contain spaces (or unprintable char), some characters and else. The strings I store most recent appear in the early part of string. So I have doubts about the way the save string or Sprintf saves the strings in SafeArea. How can I get the start of safe area char * and all other strings I store while processing. So where exactly the char * returned is pointing? The start of string I stored or the start of string to be stored next? Are they stored next to each other? How do I retreive these strings?

Bidoche
3rd January 2004, 11:53
slen=safe2-safe1;// this should give length of string assuming storing consequetivelyIs an hackish way of doing things : you use internal knowledge of the SaveString facility, which is bad pratice...
Besides this snippet of code is broken : the result is false when SaveString saved in two different save blocks.

safe=safe2-(n+1)*slen;// start of safe area? n is frame numberSame as above, yuou are assuming that ALL saves are contiguous which is false.
And even more : that only you is saving strings.

array[1]=atoi(safe); // here I use a loop to get all previous strings
array[2]=atoi(safe+slen);
Why do you bother saving your ints (i guess) as strings if you want them as ints....

//Somewhere in constructor
(int *) array = new int[2 * frame_count];
//init to a special uninitialized value (-1 ?)

//in destructor
delete array;

//in GetFrame
array[2 * n] = ...
array[2 * n + 1] = ...
//...
//uses values from arrayWon't that do it ?

vcmohan
4th January 2004, 03:13
[QUOTE]Originally posted by Bidoche
[B]
Why do you bother saving your ints (i guess) as strings if you want them as ints....

The facility of savestring then what is the purpose? Which application can use it? Cannot some info be passed on to other apps? If I cannot access the Safe area strings for whatever reason, I am unable to see the utility of this. The writeup says that a 4096 character buffer is set apart and will be alive for the duration of the script. May be I can preface each string by a special code to retreive the strings I put in provided I know the start of Safe Area pointer. What is the purpose of the Savestring returning pointer to new area?
Even though getting pointer by hackerway is bad, still as I am using a single plugin during test and no other app is used, why is it I was unable to get the start of Safe area at any time? Are the strings stored in a linked list? If so returning a pointer to start of safe area will be useful.

Since I need to access all the integers (sometimes characters) created in previous frames processings, I need a permanant area from which I should get them back. Creating a file on disk will be a slow option.
I hope that may be in future versions such a facility could be incorporated.

Bidoche
4th January 2004, 13:08
The facility of savestring then what is the purpose? Which application can use it? I am tempted to say none...
In fact, the point is that you don't have to worry about char * deletion once they are SaveStringed which simplificates the parser logic. (But it's only because it's an hand-written parser which don't uses more advanced features)
Which application can use it?None should.
Cannot some info be passed on to other apps? What is the connection ?
If I cannot access the Safe area strings for whatever reason, I am unable to see the utility of this.And it has none, it's totally useless to filter writers.
Even when you do need a string, just use std::string and that's it.
May be I can preface each string by a special code to retreive the strings I put in provided I know the start of Safe Area pointer.Yes... :/ and you will scan the whole memory looking for your datas... very good idea...
What is the purpose of the Savestring returning pointer to new area?It replaces your 'has-to-be-deleted' char * by an 'has-not... char *, of course it has to return the new location.

Even though getting pointer by hackerway is bad, still as I am using a single plugin during test and no other app is used, why is it I was unable to get the start of Safe area at any time? Are the strings stored in a linked list? If so returning a pointer to start of safe area will be useful.
Stop thinking of it as a safe area, it is not.
Even more : forget it even exists...

Since I need to access all the integers (sometimes characters) created in previous frames processings, I need a permanant area from which I should get them back. And explain me how an array allocated by your filter is not permanent enough for you !?

vcmohan
5th January 2004, 03:00
Quote
--------------------------------------------------------------
And explain me how an array allocated by your filter is not permanent enough for you !?
_________________________________________________________________

Well as I mentioned in my earlier post, I tried using static array and found that it cannot be compiled. So I thought that since SaveString, Sprintf and VSprintf are available and the plugin coders are "welcome" to use this facility I tried it and ran into problems. Of course there will be various ways to solve a problem but it is necessary to investigate why a particular method cannot be used, while in the writeup the method is available.
Possibly in the original document these instructions need to be deleted.
As for use as a ordinary array, I am not sure whether it will be retained if some one uses the Animate or Range filters. In discussion it was mentioned that these filters construct for each frame. That was the reason to explore the SaveString feature.

vcmohan
6th January 2004, 03:04
Originally posted by Richard Berg
I can give you space on avisynth.org if need be.

I have posted a message on 30 th dec that I am ready with several plugins. I did not get a response. How should I transmit the Zip files, one each for each of a plugin. These contain the plugin dll and a text file.

Bidoche
6th January 2004, 13:54
Well as I mentioned in my earlier post, I tried using static array and found that it cannot be compiled.You must have made an error somewhere...

As for use as a ordinary array, I am not sure whether it will be retained if some one uses the Animate or Range filters. They won't be retained, but before worrying about your filters working with Animate, you should make them work at all.
Just make a regular array for now.
And think about Animate issues later.

vcmohan
7th January 2004, 03:12
Originally posted by Bidoche
They won't be retained, but before worrying about your filters working with Animate, you should make them work at all.
Just make a regular array for now.
And think about Animate issues later. [/B]

My filters work with regular array. But then I thought about the animate and range filters. What should I do in that case?

Bidoche
7th January 2004, 11:39
Give me details about the data you produce/need

vcmohan
9th January 2004, 03:41
Originally posted by Bidoche
Give me details about the data you produce/need

I start with some values randomly selected(best guess) and refine them by analyzing a window in the frame. These are carried over to next frame as starting values and the process goes. The subsequent process for each frame takes less time than the first one. The values are an array of integers.

Bidoche
9th January 2004, 12:34
And these values don't depend on parameters which could be changed by Animate ?

vcmohan
17th January 2004, 03:31
Originally posted by Bidoche
And these values don't depend on parameters which could be changed by Animate ?
I was away for a few days and so the delay

The window location could be changed by the animate. So I will end up in initial values from frame to frame without being able to refine them. I am therefore putting a caution of not to use with animate.