Thread: Avisynth+
View Single Post
Old 9th January 2020, 22:30   #5053  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
stax, look in avs 2.6, or avs+ header.

The OLD v2.58 BAKED code that existed in v2.58 header was not very portable between avs versions, plugins compiled with such were basically
locked to the code in the header. The avs 2.60 header [after v2.60Alpha 4] implemented AVS_Linkage stuff when using the new AvisynthPluginInit3(), so that code is no longer BAKED into the plugin from the header,
but instead it can use code from within avisynth itself, and so is able to better adapt.
A plugin using eg Avs+ header but running under avs 2.60 standard, can still inquire stuff like bit depth, even though such functionality does not exist in avs 2.6 std(nor exists in 2.58).
[EDIT: There are kludges in the avs+ header to implement code not existing in the active version of avisynth]
For this more flexible whatsit to work proper, it is necessary to initialize AVS_Linkage with the pointer to vectors [EDIT: which is supplied by the server, usually avisynth] when
calling the instance of AvisynthPluginInit3() coded within a plugin, this replaces most of the previously BAKED-in code.

avs+ header
Code:
/*
 * Avisynth C++ plugin API code function pointers.
 *
 * In order to maintain binary compatibility with
 * future version do not change the order of the
 * existing function pointers. It will be baked
 * into all existing plugins.
 *
 * Add new function pointers to the end of the
 * structure. The linkage macros generate some
 * protection code to ensure newer plugin do not
 * call non-existing functions in an older host.
 */

struct AVS_Linkage {   // const AVS_Linkage *AVS_linkage is a pointer to struct of (mostly) function pointers to call

  int Size;

/**********************************************************************/

// struct VideoInfo
  bool    (VideoInfo::*HasVideo)() const;
  bool    (VideoInfo::*HasAudio)() const;
  bool    (VideoInfo::*IsRGB)() const;
  bool    (VideoInfo::*IsRGB24)() const;
  bool    (VideoInfo::*IsRGB32)() const;
  bool    (VideoInfo::*IsYUV)() const;

  // ... much more
Usual AvisynthPluginInit3() initializing [avisynth calls AvisynthPluginInit3() embedded into a plugin, to initialize that plugin]
Code:
/* New 2.6 requirement!!! */
// Declare and initialise server pointers static storage.
const AVS_Linkage *AVS_linkage = 0;    // UNSET as yet for current plugin, each plugin has its own instance

/* New 2.6 requirement!!! */
// DLL entry point called from LoadPlugin() to setup a user plugin.
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit3(IScriptEnvironment* env, const AVS_Linkage* const vectors) {
             // Above vectors, pointer provided by avisynth server (v2.6, avs+ or std) enabling non baked-in stuff

    /* New 2.6 requirment!!! */
    // Save the server pointers.
    AVS_linkage = vectors;    // make everything work like magic, plug vectors into AVS_linkage
    env->AddFunction("TitleBar", "c[Tit]s[ShowFrameNo]b[Col]i[ColChr]s[Esc]b", Create_TitleBar, 0);     // Some plugin, can now use avisynth server funcs via AVS_linkage
    return "'TitleBar' TitleBar plugin"; // A freeform name of the plugin.
}

hope that 'above sort of' explains it [it is likely that it could be explained better if anyone cares to - I'm happy to accept that 'it works'].

EDIT:
Some of the Kludgy stuff in avs+ header
Code:
  // AVS+ extensions
  // 20161005:
  //   Mapping of AVS+ extensions to classic 2.6 functions.
  //   In order to use these extended AVS+ functions for plugins that should work
  //   either with AVS+ or with Classic (8 bit) Avs 2.6 ans earlier AVS+ versions, there is an
  //   automatic fallback mechanism.
  //   From AVS+'s point of view these are not "baked" codes, the primary functions should exist.
  //   Examples:
  //   Is444() is mapped to IsYV24() for classic AVS2.6
  //   ComponentSize() returns constant 1 (1 bytes per pixel component)
  //   BitsPerComponent() returns constant 8 (Classic AVS2.6 is 8 bit only)

  // Returns the number of color channels or planes in a frame
  int NumComponents() const AVS_BakedCode(return AVS_LinkCallOptDefault(NumComponents, (((AVS_LinkCall(IsYUV)()) && !(AVS_LinkCall(IsY8)())) ? 3 : AVS_LinkCall(BytesFromPixels)(1)) ) )

  // Returns the size in bytes of a single component of a pixel
  int ComponentSize() const AVS_BakedCode(return AVS_LinkCallOptDefault(ComponentSize, 1))

  // Returns the bit depth of a single component of a pixel
  int BitsPerComponent() const AVS_BakedCode(return AVS_LinkCallOptDefault(BitsPerComponent, 8))    // simply return 8 if avs std (provided as default if non avs+ avisynth)


To better understand, maybe peruse link pointed to by Groucho [not just that post, entire thread]:- https://forum.doom9.org/showthread.php?t=101730

EDIT: Also take a peek at these two later posts in same thread by IanB some years later,
https://forum.doom9.org/showthread.p...92#post1567792
https://forum.doom9.org/showthread.p...72#post1580772
There may be more on same subject when avs+ was introduced.

EDIT: And avisynth v2.60Alpha4 thread, where AVS_linkage and AvisynthPluginInit3() introduced for real:- https://forum.doom9.org/showthread.php?t=166951
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 10th January 2020 at 00:53.
StainlessS is offline