1 // Avisynth v2.5. Copyright 2002 Ben Rudiak-Gould et al. 2 // Avisynth v2.6. Copyright 2006 Klaus Post. 3 // Avisynth v2.6. Copyright 2009 Ian Brabham. 4 // Avisynth+ project 5 // 20160613: new 16 bit planar pixel_type constants go live! 6 // 20160725: pixel_type constants 10-12-14 bit + planar RGB + BRG48/64 7 // 20161005: Fallback of VideoInfo functions to defaults if no function exists 8 // 20170117: global variables for VfW output OPT_xxxx 9 // 20170310: new MT mode: MT_SPECIAL_MT 10 // 20171103: (test with SIZETMOD define: Videoframe offsets to size_t, may affect x64) 11 // 20171207: C++ Standard Conformance (no change for plugin writers) 12 // 20180525: AVS_UNUSED define to supress parameter not used warnings 13 14 // http://www.avisynth.org 15 16 // This program is free software; you can redistribute it and/or modify 17 // it under the terms of the GNU General Public License as published by 18 // the Free Software Foundation; either version 2 of the License, or 19 // (at your option) any later version. 20 // 21 // This program is distributed in the hope that it will be useful, 22 // but WITHOUT ANY WARRANTY; without even the implied warranty of 23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 // GNU General Public License for more details. 25 // 26 // You should have received a copy of the GNU General Public License 27 // along with this program; if not, write to the Free Software 28 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 29 // http://www.gnu.org/copyleft/gpl.html . 30 // 31 // Linking Avisynth statically or dynamically with other modules is making 32 // a combined work based on Avisynth. Thus, the terms and conditions of 33 // the GNU General Public License cover the whole combination. 34 // 35 // As a special exception, the copyright holders of Avisynth give you 36 // permission to link Avisynth with independent modules that communicate 37 // with Avisynth solely through the interfaces defined in avisynth.h, 38 // regardless of the license terms of these independent modules, and to 39 // copy and distribute the resulting combined work under terms of your 40 // choice, provided that every copy of the combined work is accompanied 41 // by a complete copy of the source code of Avisynth (the version of 42 // Avisynth used to produce the combined work), being distributed under 43 // the terms of the GNU General Public License plus this exception. An 44 // independent module is a module which is not derived from or based on 45 // Avisynth, such as 3rd-party filters, import and export plugins, or 46 // graphical user interfaces. 47 48 49 50 51 #ifndef __AVISYNTH_6_H__ 52 #define __AVISYNTH_6_H__ 53 54 #include <avs/config.h> 55 #include <avs/capi.h> 56 #include <avs/types.h> 57 58 59 enum { AVISYNTH_INTERFACE_VERSION = 6 }; 60 61 62 /* Compiler-specific crap */ 63 64 // Tell MSVC to stop precompiling here 65 #if defined(_MSC_VER) && !defined(__clang__) 66 #pragma hdrstop 67 #endif 68 69 // Set up debugging macros for MS compilers; for others, step down to the 70 // standard <assert.h> interface 71 #ifdef _MSC_VER 72 #include <crtdbg.h> 73 #else 74 #undef _RPT0 75 #undef _RPT1 76 #undef _RPT2 77 #undef _RPT3 78 #undef _RPT4 79 #undef _RPT5 80 #define _RPT0(a,b) ((void)0) 81 #define _RPT1(a,b,c) ((void)0) 82 #define _RPT2(a,b,c,d) ((void)0) 83 #define _RPT3(a,b,c,d,e) ((void)0) 84 #define _RPT4(a,b,c,d,e,f) ((void)0) 85 #define _RPT5(a,b,c,d,e,f,g) ((void)0) 86 87 #include <cassert> 88 #undef _ASSERTE 89 #undef _ASSERT 90 #define _ASSERTE(x) assert(x) 91 #define _ASSERT(x) assert(x) 92 #endif 93 94 95 96 // I had problems with Premiere wanting 1-byte alignment for its structures, 97 // so I now set the Avisynth struct alignment explicitly here. 98 #pragma pack(push,8) 99 100 // The VideoInfo struct holds global information about a clip (i.e. 101 // information that does not depend on the frame number). The GetVideoInfo 102 // method in IClip returns this struct. 103 104 enum {SAMPLE_INT8 = 1<<0, 105 SAMPLE_INT16 = 1<<1, 106 SAMPLE_INT24 = 1<<2, // Int24 is a very stupid thing to code, but it's supported by some hardware. 107 SAMPLE_INT32 = 1<<3, 108 SAMPLE_FLOAT = 1<<4}; 109 110 enum { 111 AVS_PLANAR_Y=1<<0, 112 AVS_PLANAR_U=1<<1, 113 AVS_PLANAR_V=1<<2, 114 AVS_PLANAR_ALIGNED=1<<3, 115 AVS_PLANAR_Y_ALIGNED= AVS_PLANAR_Y| AVS_PLANAR_ALIGNED, // MEANX : Patched to avoid clash with adm names 116 AVS_PLANAR_U_ALIGNED= AVS_PLANAR_U| AVS_PLANAR_ALIGNED, 117 AVS_PLANAR_V_ALIGNED= AVS_PLANAR_V| AVS_PLANAR_ALIGNED, 118 PLANAR_A=1<<4, 119 PLANAR_R=1<<5, 120 PLANAR_G=1<<6, 121 PLANAR_B=1<<7, 122 PLANAR_A_ALIGNED=PLANAR_A| AVS_PLANAR_ALIGNED, 123 PLANAR_R_ALIGNED=PLANAR_R| AVS_PLANAR_ALIGNED, 124 PLANAR_G_ALIGNED=PLANAR_G| AVS_PLANAR_ALIGNED, 125 PLANAR_B_ALIGNED=PLANAR_B| AVS_PLANAR_ALIGNED, 126 }; 127 128 class AvisynthError /* exception */ { 129 public: 130 const char* const msg; AvisynthError(const char * _msg)131 AvisynthError(const char* _msg) : msg(_msg) {} 132 133 // Ensure AvisynthError cannot be publicly assigned! 134 private: 135 AvisynthError& operator=(const AvisynthError&); 136 }; // end class AvisynthError 137 138 139 /* Forward references */ 140 #if defined(MSVC) 141 #define SINGLE_INHERITANCE __single_inheritance 142 #else 143 #define SINGLE_INHERITANCE 144 #endif 145 struct SINGLE_INHERITANCE VideoInfo; 146 class SINGLE_INHERITANCE VideoFrameBuffer; 147 class SINGLE_INHERITANCE VideoFrame; 148 class IClip; 149 class SINGLE_INHERITANCE PClip; 150 class SINGLE_INHERITANCE PVideoFrame; 151 class IScriptEnvironment; 152 class SINGLE_INHERITANCE AVSValue; 153 154 155 /* 156 * Avisynth C++ plugin API code function pointers. 157 * 158 * In order to maintain binary compatibility with 159 * future version do not change the order of the 160 * existing function pointers. It will be baked 161 * into all existing plugins. 162 * 163 * Add new function pointers to the end of the 164 * structure. The linkage macros generate some 165 * protection code to ensure newer plugin do not 166 * call non-existing functions in an older host. 167 */ 168 169 struct AVS_Linkage { 170 171 int Size; 172 173 /**********************************************************************/ 174 175 // struct VideoInfo 176 bool (VideoInfo::*HasVideo)() const; 177 bool (VideoInfo::*HasAudio)() const; 178 bool (VideoInfo::*IsRGB)() const; 179 bool (VideoInfo::*IsRGB24)() const; 180 bool (VideoInfo::*IsRGB32)() const; 181 bool (VideoInfo::*IsYUV)() const; 182 bool (VideoInfo::*IsYUY2)() const; 183 bool (VideoInfo::*IsYV24)() const; 184 bool (VideoInfo::*IsYV16)() const; 185 bool (VideoInfo::*IsYV12)() const; 186 bool (VideoInfo::*IsYV411)() const; 187 bool (VideoInfo::*IsY8)() const; 188 bool (VideoInfo::*IsColorSpace)(int c_space) const; 189 bool (VideoInfo::*Is)(int property) const; 190 bool (VideoInfo::*IsPlanar)() const; 191 bool (VideoInfo::*IsFieldBased)() const; 192 bool (VideoInfo::*IsParityKnown)() const; 193 bool (VideoInfo::*IsBFF)() const; 194 bool (VideoInfo::*IsTFF)() const; 195 bool (VideoInfo::*IsVPlaneFirst)() const; 196 int (VideoInfo::*BytesFromPixels)(int pixels) const; 197 int (VideoInfo::*RowSize)(int plane) const; 198 int (VideoInfo::*BMPSize)() const; 199 __int64 (VideoInfo::*AudioSamplesFromFrames)(int frames) const; 200 int (VideoInfo::*FramesFromAudioSamples)(__int64 samples) const; 201 __int64 (VideoInfo::*AudioSamplesFromBytes)(__int64 bytes) const; 202 __int64 (VideoInfo::*BytesFromAudioSamples)(__int64 samples) const; 203 int (VideoInfo::*AudioChannels)() const; 204 int (VideoInfo::*SampleType)() const; 205 bool (VideoInfo::*IsSampleType)(int testtype) const; 206 int (VideoInfo::*SamplesPerSecond)() const; 207 int (VideoInfo::*BytesPerAudioSample)() const; 208 void (VideoInfo::*SetFieldBased)(bool isfieldbased); 209 void (VideoInfo::*Set)(int property); 210 void (VideoInfo::*Clear)(int property); 211 int (VideoInfo::*GetPlaneWidthSubsampling)(int plane) const; 212 int (VideoInfo::*GetPlaneHeightSubsampling)(int plane) const; 213 int (VideoInfo::*BitsPerPixel)() const; 214 int (VideoInfo::*BytesPerChannelSample)() const; 215 void (VideoInfo::*SetFPS)(unsigned numerator, unsigned denominator); 216 void (VideoInfo::*MulDivFPS)(unsigned multiplier, unsigned divisor); 217 bool (VideoInfo::*IsSameColorspace)(const VideoInfo& vi) const; 218 // end struct VideoInfo 219 220 /**********************************************************************/ 221 222 // class VideoFrameBuffer 223 const BYTE* (VideoFrameBuffer::*VFBGetReadPtr)() const; 224 BYTE* (VideoFrameBuffer::*VFBGetWritePtr)(); 225 #ifdef SIZETMOD 226 size_t (VideoFrameBuffer::*GetDataSize)() const; 227 #else 228 int (VideoFrameBuffer::*GetDataSize)() const; 229 #endif 230 int (VideoFrameBuffer::*GetSequenceNumber)() const; 231 int (VideoFrameBuffer::*GetRefcount)() const; 232 // end class VideoFrameBuffer 233 234 /**********************************************************************/ 235 236 // class VideoFrame 237 int (VideoFrame::*GetPitch)(int plane) const; 238 int (VideoFrame::*GetRowSize)(int plane) const; 239 int (VideoFrame::*GetHeight)(int plane) const; 240 VideoFrameBuffer* (VideoFrame::*GetFrameBuffer)() const; 241 #ifdef SIZETMOD 242 size_t (VideoFrame::*GetOffset)(int plane) const; 243 #else 244 int (VideoFrame::*GetOffset)(int plane) const; 245 #endif 246 const BYTE* (VideoFrame::*VFGetReadPtr)(int plane) const; 247 bool (VideoFrame::*IsWritable)() const; 248 BYTE* (VideoFrame::*VFGetWritePtr)(int plane) const; 249 void (VideoFrame::*VideoFrame_DESTRUCTOR)(); 250 // end class VideoFrame 251 252 /**********************************************************************/ 253 254 // class IClip 255 /* nothing */ 256 // end class IClip 257 258 /**********************************************************************/ 259 260 // class PClip 261 void (PClip::*PClip_CONSTRUCTOR0)(); 262 void (PClip::*PClip_CONSTRUCTOR1)(const PClip& x); 263 void (PClip::*PClip_CONSTRUCTOR2)(IClip* x); 264 void (PClip::*PClip_OPERATOR_ASSIGN0)(IClip* x); 265 void (PClip::*PClip_OPERATOR_ASSIGN1)(const PClip& x); 266 void (PClip::*PClip_DESTRUCTOR)(); 267 // end class PClip 268 269 /**********************************************************************/ 270 271 // class PVideoFrame 272 void (PVideoFrame::*PVideoFrame_CONSTRUCTOR0)(); 273 void (PVideoFrame::*PVideoFrame_CONSTRUCTOR1)(const PVideoFrame& x); 274 void (PVideoFrame::*PVideoFrame_CONSTRUCTOR2)(VideoFrame* x); 275 void (PVideoFrame::*PVideoFrame_OPERATOR_ASSIGN0)(VideoFrame* x); 276 void (PVideoFrame::*PVideoFrame_OPERATOR_ASSIGN1)(const PVideoFrame& x); 277 void (PVideoFrame::*PVideoFrame_DESTRUCTOR)(); 278 // end class PVideoFrame 279 280 /**********************************************************************/ 281 282 // class AVSValue 283 void (AVSValue::*AVSValue_CONSTRUCTOR0)(); 284 void (AVSValue::*AVSValue_CONSTRUCTOR1)(IClip* c); 285 void (AVSValue::*AVSValue_CONSTRUCTOR2)(const PClip& c); 286 void (AVSValue::*AVSValue_CONSTRUCTOR3)(bool b); 287 void (AVSValue::*AVSValue_CONSTRUCTOR4)(int i); 288 void (AVSValue::*AVSValue_CONSTRUCTOR5)(float f); 289 void (AVSValue::*AVSValue_CONSTRUCTOR6)(double f); 290 void (AVSValue::*AVSValue_CONSTRUCTOR7)(const char* s); 291 void (AVSValue::*AVSValue_CONSTRUCTOR8)(const AVSValue* a, int size); 292 void (AVSValue::*AVSValue_CONSTRUCTOR9)(const AVSValue& v); 293 void (AVSValue::*AVSValue_DESTRUCTOR)(); 294 AVSValue& (AVSValue::*AVSValue_OPERATOR_ASSIGN)(const AVSValue& v); 295 const AVSValue& (AVSValue::*AVSValue_OPERATOR_INDEX)(int index) const; 296 bool (AVSValue::*Defined)() const; 297 bool (AVSValue::*IsClip)() const; 298 bool (AVSValue::*IsBool)() const; 299 bool (AVSValue::*IsInt)() const; 300 bool (AVSValue::*IsFloat)() const; 301 bool (AVSValue::*IsString)() const; 302 bool (AVSValue::*IsArray)() const; 303 PClip (AVSValue::*AsClip)() const; 304 bool (AVSValue::*AsBool1)() const; 305 int (AVSValue::*AsInt1)() const; 306 const char* (AVSValue::*AsString1)() const; 307 double (AVSValue::*AsFloat1)() const; 308 bool (AVSValue::*AsBool2)(bool def) const; 309 int (AVSValue::*AsInt2)(int def) const; 310 double (AVSValue::*AsDblDef)(double def) const; 311 double (AVSValue::*AsFloat2)(float def) const; 312 const char* (AVSValue::*AsString2)(const char* def) const; 313 int (AVSValue::*ArraySize)() const; 314 // end class AVSValue 315 316 /**********************************************************************/ 317 // Reserve pointer space so that we can keep compatibility with Avs "classic" even if it adds functions on its own 318 void (VideoInfo::*reserved[32])(); 319 /**********************************************************************/ 320 // AviSynth+ additions 321 int (VideoInfo::*NumComponents)() const; 322 int (VideoInfo::*ComponentSize)() const; 323 int (VideoInfo::*BitsPerComponent)() const; 324 bool (VideoInfo::*Is444)() const; 325 bool (VideoInfo::*Is422)() const; 326 bool (VideoInfo::*Is420)() const; 327 bool (VideoInfo::*IsY)() const; 328 bool (VideoInfo::*IsRGB48)() const; 329 bool (VideoInfo::*IsRGB64)() const; 330 bool (VideoInfo::*IsYUVA)() const; 331 bool (VideoInfo::*IsPlanarRGB)() const; 332 bool (VideoInfo::*IsPlanarRGBA)() const; 333 /**********************************************************************/ 334 }; 335 336 #ifdef BUILDING_AVSCORE 337 /* Macro resolution for code inside Avisynth.dll */ 338 # define AVS_BakedCode(arg) ; 339 # define AVS_LinkCall(arg) 340 # define AVS_LinkCallV(arg) 341 # define AVS_LinkCallOpt(arg, argOpt) AVSLinkCall(arg) 342 # define AVS_LinkCallOptDefault(arg, argDefaultValue) AVSLinkCall(arg()) 343 # define CALL_MEMBER_FN(object,ptrToMember) 344 345 #else 346 /* Macro resolution for code inside user plugin */ 347 # ifdef AVS_LINKAGE_DLLIMPORT 348 extern __declspec(dllimport) const AVS_Linkage* const AVS_linkage; 349 # else 350 extern const AVS_Linkage* AVS_linkage; 351 # endif 352 353 # ifndef offsetof 354 # include <stddef.h> 355 # endif 356 357 # define AVS_BakedCode(arg) { arg ; } 358 # define AVS_LinkCall(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? 0 : (this->*(AVS_linkage->arg)) 359 # define AVS_LinkCall_Void(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? (void)0 : (this->*(AVS_linkage->arg)) 360 # define AVS_LinkCallV(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? *this : (this->*(AVS_linkage->arg)) 361 // Helper macros for fallback option when a function does not exists 362 #define CALL_MEMBER_FN(object,ptrToMember) ((object)->*(ptrToMember)) 363 #define AVS_LinkCallOpt(arg, argOpt) !AVS_linkage ? 0 : \ 364 ( offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? \ 365 (offsetof(AVS_Linkage, argOpt) >= AVS_linkage->Size ? 0 : CALL_MEMBER_FN(this, AVS_linkage->argOpt)() ) : \ 366 CALL_MEMBER_FN(this, AVS_linkage->arg)() ) 367 // AVS_LinkCallOptDefault puts automatically () only after arg 368 # define AVS_LinkCallOptDefault(arg, argDefaultValue) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? (argDefaultValue) : ((this->*(AVS_linkage->arg))()) 369 370 #endif 371 372 struct VideoInfo { 373 int width, height; // width=0 means no video 374 unsigned fps_numerator, fps_denominator; 375 int num_frames; 376 // This is more extensible than previous versions. More properties can be added seeminglesly. 377 378 // Colorspace properties. 379 /* 380 381 Planar match mask 1111.1000.0000.0111.0000.0111.0000.0111 382 Planar signature 10xx.1000.0000.00xx.0000.00xx.00xx.00xx ? 383 Planar signature 10xx.1000.0000.0xxx.0000.00xx.000x.x0xx ? *new 384 Planar filter mask 1111.1111.1111.1111.1111.1111.1110.0111 (typo from old header fixed) 385 386 pixel_type mapping 387 ================== 388 pixel_type bit-map PIYB.Z000.0???.0SSS.0000.0???.????.???? 389 planar YUV CCC HHH.000u.vWWW 390 planar RGB(A) CCC AR 391 nonplanar CCC 000.00wx xyAR 392 Legend 393 ====== 394 Planar YUV: 395 Code Bits Remark 396 W 0-2 Planar Width Subsampling bits 397 Use (X+1) & 3 for GetPlaneWidthSubsampling 398 000 => 1 YV12, YV16, YUV420, YUV422 399 001 => 2 YV411, YUV9 400 010 => reserved 401 011 => 0 YV24, YUV444, RGBP 402 1xx => reserved 403 v 3 VPlaneFirst YV12, YV16, YV24, YV411, YUV9 404 u 4 UPlaneFirst I420 405 H 7-9 Planar Height Subsampling bits 406 Use ((X>>8)+1) & 3 for GetPlaneHeightSubsampling 407 000 => 1 YV12, YUV420 408 001 => 2 YUV9 409 010 => reserved 410 011 => 0 YV16, YV24, YV411, YUV422, YUV444, RGBP 411 1xx => reserved 412 413 Planar RGB 414 Code Bits Remark 415 R 0 BGR, (with SSS bits for 8/16 bit/sample or float) 416 A 1 BGRA, (with SSS bits for 8/16 bit/sample or float) 417 418 419 Not Planar, Interleaved (I flag) 420 Code Bits Remark 421 R 0 BGR24, and BGRx in future (with SSS bits for 8/16 bit/sample or float) 422 A 1 BGR32, and BGRAx in future (with SSS bits for 8/16 bit/sample or float) 423 y 2 YUY2 424 x 3-4 reserved 425 w 5 Raw32 426 427 General 428 Code Bits Remark 429 S 16-18 Sample resolution bits 430 000 => 8 431 001 => 16 432 010 => 32 (float) 433 011,100 => reserved 434 101 => 10 bits 435 110 => 12 bits 436 111 => 14 bits 437 for packed RGB(A): only 8 and 16 bits are valid 438 439 Other YV12 specific (not used?) 440 C 20-22 Chroma Placement values 0-4 see CS_xxx_CHROMA_PLACEMENT 441 442 Color family and layout 443 Packed Planar Planar Planar 444 Code Bits Remark RGB/RGBA YUV YUY2 Y_Grey RGB/RGBA YUVA 445 R 0 1/0 - 0 - 1/0 - 446 A 1 0/1 - 0 - 0/1 - 447 y 2 - - 1 - 0 - 448 Z 27 YUVA 0 0 0 0 1 1 449 B 28 BGR 1 0 0 0 1* 0 450 Y 29 YUV 0 1 1 1 0 0 451 I 30 Interleaved 1 0 1 1 0 0 452 P 31 Planar 0 1 0 1 1 1 453 * Planar RGB plane order: G,B,R(,A) 454 455 */ 456 enum { 457 CS_YUVA = 1<<27, 458 CS_BGR = 1<<28, 459 CS_YUV = 1<<29, 460 CS_INTERLEAVED = 1<<30, 461 CS_PLANAR = 1<<31, 462 463 CS_Shift_Sub_Width = 0, 464 CS_Shift_Sub_Height = 8, 465 CS_Shift_Sample_Bits = 16, 466 467 CS_Sub_Width_Mask = 7 << CS_Shift_Sub_Width, 468 CS_Sub_Width_1 = 3 << CS_Shift_Sub_Width, // YV24 469 CS_Sub_Width_2 = 0 << CS_Shift_Sub_Width, // YV12, I420, YV16 470 CS_Sub_Width_4 = 1 << CS_Shift_Sub_Width, // YUV9, YV411 471 472 CS_VPlaneFirst = 1 << 3, // YV12, YV16, YV24, YV411, YUV9 473 CS_UPlaneFirst = 1 << 4, // I420 474 475 CS_Sub_Height_Mask = 7 << CS_Shift_Sub_Height, 476 CS_Sub_Height_1 = 3 << CS_Shift_Sub_Height, // YV16, YV24, YV411 477 CS_Sub_Height_2 = 0 << CS_Shift_Sub_Height, // YV12, I420 478 CS_Sub_Height_4 = 1 << CS_Shift_Sub_Height, // YUV9 479 480 CS_Sample_Bits_Mask = 7 << CS_Shift_Sample_Bits, 481 CS_Sample_Bits_8 = 0 << CS_Shift_Sample_Bits, 482 CS_Sample_Bits_10 = 5 << CS_Shift_Sample_Bits, 483 CS_Sample_Bits_12 = 6 << CS_Shift_Sample_Bits, 484 CS_Sample_Bits_14 = 7 << CS_Shift_Sample_Bits, 485 CS_Sample_Bits_16 = 1 << CS_Shift_Sample_Bits, 486 CS_Sample_Bits_32 = 2 << CS_Shift_Sample_Bits, 487 488 CS_PLANAR_MASK = CS_PLANAR | CS_INTERLEAVED | CS_YUV | CS_BGR | CS_YUVA | CS_Sample_Bits_Mask 489 | CS_Sub_Height_Mask | CS_Sub_Width_Mask, 490 CS_PLANAR_FILTER = ~( CS_VPlaneFirst | CS_UPlaneFirst ), 491 492 CS_RGB_TYPE = 1 << 0, 493 CS_RGBA_TYPE = 1 << 1, 494 495 // Specific colorformats 496 CS_UNKNOWN = 0, 497 498 CS_BGR24 = CS_RGB_TYPE | CS_BGR | CS_INTERLEAVED, 499 CS_BGR32 = CS_RGBA_TYPE | CS_BGR | CS_INTERLEAVED, 500 CS_YUY2 = 1<<2 | CS_YUV | CS_INTERLEAVED, 501 // CS_YV12 = 1<<3 Reserved 502 // CS_I420 = 1<<4 Reserved 503 CS_RAW32 = 1<<5 | CS_INTERLEAVED, 504 505 // YV12 must be 0xA000008 2.5 Baked API will see all new planar as YV12 506 // I420 must be 0xA000010 507 508 CS_GENERIC_YUV420 = CS_PLANAR | CS_YUV | CS_VPlaneFirst | CS_Sub_Height_2 | CS_Sub_Width_2, // 4:2:0 planar 509 CS_GENERIC_YUV422 = CS_PLANAR | CS_YUV | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_2, // 4:2:2 planar 510 CS_GENERIC_YUV444 = CS_PLANAR | CS_YUV | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_1, // 4:4:4 planar 511 CS_GENERIC_Y = CS_PLANAR | CS_INTERLEAVED | CS_YUV, // Y only (4:0:0) 512 CS_GENERIC_RGBP = CS_PLANAR | CS_BGR | CS_RGB_TYPE, // planar RGB. Though name is RGB but plane order G,B,R 513 CS_GENERIC_RGBAP = CS_PLANAR | CS_BGR | CS_RGBA_TYPE, // planar RGBA 514 CS_GENERIC_YUVA420 = CS_PLANAR | CS_YUVA | CS_VPlaneFirst | CS_Sub_Height_2 | CS_Sub_Width_2, // 4:2:0:A planar 515 CS_GENERIC_YUVA422 = CS_PLANAR | CS_YUVA | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_2, // 4:2:2:A planar 516 CS_GENERIC_YUVA444 = CS_PLANAR | CS_YUVA | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_1, // 4:4:4:A planar 517 518 CS_YV24 = CS_GENERIC_YUV444 | CS_Sample_Bits_8, // YVU 4:4:4 planar 519 CS_YV16 = CS_GENERIC_YUV422 | CS_Sample_Bits_8, // YVU 4:2:2 planar 520 CS_YV12 = CS_GENERIC_YUV420 | CS_Sample_Bits_8, // YVU 4:2:0 planar 521 CS_I420 = CS_PLANAR | CS_YUV | CS_Sample_Bits_8 | CS_UPlaneFirst | CS_Sub_Height_2 | CS_Sub_Width_2, // YUV 4:2:0 planar 522 CS_IYUV = CS_I420, 523 CS_YUV9 = CS_PLANAR | CS_YUV | CS_Sample_Bits_8 | CS_VPlaneFirst | CS_Sub_Height_4 | CS_Sub_Width_4, // YUV 4:1:0 planar 524 CS_YV411 = CS_PLANAR | CS_YUV | CS_Sample_Bits_8 | CS_VPlaneFirst | CS_Sub_Height_1 | CS_Sub_Width_4, // YUV 4:1:1 planar 525 526 CS_Y8 = CS_GENERIC_Y | CS_Sample_Bits_8, // Y 4:0:0 planar 527 528 //------------------------- 529 // AVS16: new planar constants go live! Experimental PF 160613 530 // 10-12-14 bit + planar RGB + BRG48/64 160725 531 532 CS_YUV444P10 = CS_GENERIC_YUV444 | CS_Sample_Bits_10, // YUV 4:4:4 10bit samples 533 CS_YUV422P10 = CS_GENERIC_YUV422 | CS_Sample_Bits_10, // YUV 4:2:2 10bit samples 534 CS_YUV420P10 = CS_GENERIC_YUV420 | CS_Sample_Bits_10, // YUV 4:2:0 10bit samples 535 CS_Y10 = CS_GENERIC_Y | CS_Sample_Bits_10, // Y 4:0:0 10bit samples 536 537 CS_YUV444P12 = CS_GENERIC_YUV444 | CS_Sample_Bits_12, // YUV 4:4:4 12bit samples 538 CS_YUV422P12 = CS_GENERIC_YUV422 | CS_Sample_Bits_12, // YUV 4:2:2 12bit samples 539 CS_YUV420P12 = CS_GENERIC_YUV420 | CS_Sample_Bits_12, // YUV 4:2:0 12bit samples 540 CS_Y12 = CS_GENERIC_Y | CS_Sample_Bits_12, // Y 4:0:0 12bit samples 541 542 CS_YUV444P14 = CS_GENERIC_YUV444 | CS_Sample_Bits_14, // YUV 4:4:4 14bit samples 543 CS_YUV422P14 = CS_GENERIC_YUV422 | CS_Sample_Bits_14, // YUV 4:2:2 14bit samples 544 CS_YUV420P14 = CS_GENERIC_YUV420 | CS_Sample_Bits_14, // YUV 4:2:0 14bit samples 545 CS_Y14 = CS_GENERIC_Y | CS_Sample_Bits_14, // Y 4:0:0 14bit samples 546 547 CS_YUV444P16 = CS_GENERIC_YUV444 | CS_Sample_Bits_16, // YUV 4:4:4 16bit samples 548 CS_YUV422P16 = CS_GENERIC_YUV422 | CS_Sample_Bits_16, // YUV 4:2:2 16bit samples 549 CS_YUV420P16 = CS_GENERIC_YUV420 | CS_Sample_Bits_16, // YUV 4:2:0 16bit samples 550 CS_Y16 = CS_GENERIC_Y | CS_Sample_Bits_16, // Y 4:0:0 16bit samples 551 552 // 32 bit samples (float) 553 CS_YUV444PS = CS_GENERIC_YUV444 | CS_Sample_Bits_32, // YUV 4:4:4 32bit samples 554 CS_YUV422PS = CS_GENERIC_YUV422 | CS_Sample_Bits_32, // YUV 4:2:2 32bit samples 555 CS_YUV420PS = CS_GENERIC_YUV420 | CS_Sample_Bits_32, // YUV 4:2:0 32bit samples 556 CS_Y32 = CS_GENERIC_Y | CS_Sample_Bits_32, // Y 4:0:0 32bit samples 557 558 // RGB packed 559 CS_BGR48 = CS_RGB_TYPE | CS_BGR | CS_INTERLEAVED | CS_Sample_Bits_16, // BGR 3x16 bit 560 CS_BGR64 = CS_RGBA_TYPE | CS_BGR | CS_INTERLEAVED | CS_Sample_Bits_16, // BGR 4x16 bit 561 // no packed 32 bit (float) support for these legacy types 562 563 // RGB planar 564 CS_RGBP = CS_GENERIC_RGBP | CS_Sample_Bits_8, // Planar RGB 8 bit samples 565 CS_RGBP10 = CS_GENERIC_RGBP | CS_Sample_Bits_10, // Planar RGB 10bit samples 566 CS_RGBP12 = CS_GENERIC_RGBP | CS_Sample_Bits_12, // Planar RGB 12bit samples 567 CS_RGBP14 = CS_GENERIC_RGBP | CS_Sample_Bits_14, // Planar RGB 14bit samples 568 CS_RGBP16 = CS_GENERIC_RGBP | CS_Sample_Bits_16, // Planar RGB 16bit samples 569 CS_RGBPS = CS_GENERIC_RGBP | CS_Sample_Bits_32, // Planar RGB 32bit samples 570 571 // RGBA planar 572 CS_RGBAP = CS_GENERIC_RGBAP | CS_Sample_Bits_8, // Planar RGBA 8 bit samples 573 CS_RGBAP10 = CS_GENERIC_RGBAP | CS_Sample_Bits_10, // Planar RGBA 10bit samples 574 CS_RGBAP12 = CS_GENERIC_RGBAP | CS_Sample_Bits_12, // Planar RGBA 12bit samples 575 CS_RGBAP14 = CS_GENERIC_RGBAP | CS_Sample_Bits_14, // Planar RGBA 14bit samples 576 CS_RGBAP16 = CS_GENERIC_RGBAP | CS_Sample_Bits_16, // Planar RGBA 16bit samples 577 CS_RGBAPS = CS_GENERIC_RGBAP | CS_Sample_Bits_32, // Planar RGBA 32bit samples 578 579 // Planar YUVA 580 CS_YUVA444 = CS_GENERIC_YUVA444 | CS_Sample_Bits_8, // YUVA 4:4:4 8bit samples 581 CS_YUVA422 = CS_GENERIC_YUVA422 | CS_Sample_Bits_8, // YUVA 4:2:2 8bit samples 582 CS_YUVA420 = CS_GENERIC_YUVA420 | CS_Sample_Bits_8, // YUVA 4:2:0 8bit samples 583 584 CS_YUVA444P10 = CS_GENERIC_YUVA444 | CS_Sample_Bits_10, // YUVA 4:4:4 10bit samples 585 CS_YUVA422P10 = CS_GENERIC_YUVA422 | CS_Sample_Bits_10, // YUVA 4:2:2 10bit samples 586 CS_YUVA420P10 = CS_GENERIC_YUVA420 | CS_Sample_Bits_10, // YUVA 4:2:0 10bit samples 587 588 CS_YUVA444P12 = CS_GENERIC_YUVA444 | CS_Sample_Bits_12, // YUVA 4:4:4 12bit samples 589 CS_YUVA422P12 = CS_GENERIC_YUVA422 | CS_Sample_Bits_12, // YUVA 4:2:2 12bit samples 590 CS_YUVA420P12 = CS_GENERIC_YUVA420 | CS_Sample_Bits_12, // YUVA 4:2:0 12bit samples 591 592 CS_YUVA444P14 = CS_GENERIC_YUVA444 | CS_Sample_Bits_14, // YUVA 4:4:4 14bit samples 593 CS_YUVA422P14 = CS_GENERIC_YUVA422 | CS_Sample_Bits_14, // YUVA 4:2:2 14bit samples 594 CS_YUVA420P14 = CS_GENERIC_YUVA420 | CS_Sample_Bits_14, // YUVA 4:2:0 14bit samples 595 596 CS_YUVA444P16 = CS_GENERIC_YUVA444 | CS_Sample_Bits_16, // YUVA 4:4:4 16bit samples 597 CS_YUVA422P16 = CS_GENERIC_YUVA422 | CS_Sample_Bits_16, // YUVA 4:2:2 16bit samples 598 CS_YUVA420P16 = CS_GENERIC_YUVA420 | CS_Sample_Bits_16, // YUVA 4:2:0 16bit samples 599 600 CS_YUVA444PS = CS_GENERIC_YUVA444 | CS_Sample_Bits_32, // YUVA 4:4:4 32bit samples 601 CS_YUVA422PS = CS_GENERIC_YUVA422 | CS_Sample_Bits_32, // YUVA 4:2:2 32bit samples 602 CS_YUVA420PS = CS_GENERIC_YUVA420 | CS_Sample_Bits_32, // YUVA 4:2:0 32bit samples 603 604 }; 605 606 int pixel_type; // changed to int as of 2.5 607 608 609 int audio_samples_per_second; // 0 means no audio 610 int sample_type; // as of 2.5 611 __int64 num_audio_samples; // changed as of 2.5 612 int nchannels; // as of 2.5 613 614 // Imagetype properties 615 616 int image_type; 617 618 enum { 619 IT_BFF = 1<<0, 620 IT_TFF = 1<<1, 621 IT_FIELDBASED = 1<<2 622 }; 623 624 // Chroma placement bits 20 -> 23 ::FIXME:: Really want a Class to support this 625 enum { 626 CS_UNKNOWN_CHROMA_PLACEMENT = 0 << 20, 627 CS_MPEG1_CHROMA_PLACEMENT = 1 << 20, 628 CS_MPEG2_CHROMA_PLACEMENT = 2 << 20, 629 CS_YUY2_CHROMA_PLACEMENT = 3 << 20, 630 CS_TOPLEFT_CHROMA_PLACEMENT = 4 << 20 631 }; 632 633 // useful functions of the above 634 bool HasVideo() const AVS_BakedCode(return AVS_LinkCall(HasVideo)()) 635 bool HasAudio() const AVS_BakedCode(return AVS_LinkCall(HasAudio)()) 636 bool IsRGB() const AVS_BakedCode(return AVS_LinkCall(IsRGB)()) 637 bool IsRGB24() const AVS_BakedCode(return AVS_LinkCall(IsRGB24)()) 638 bool IsRGB32() const AVS_BakedCode(return AVS_LinkCall(IsRGB32)()) 639 bool IsYUV() const AVS_BakedCode(return AVS_LinkCall(IsYUV)()) 640 bool IsYUY2() const AVS_BakedCode(return AVS_LinkCall(IsYUY2)()) 641 642 bool IsYV24() const AVS_BakedCode(return AVS_LinkCall(IsYV24)()) 643 bool IsYV16() const AVS_BakedCode(return AVS_LinkCall(IsYV16)()) 644 bool IsYV12() const AVS_BakedCode(return AVS_LinkCall(IsYV12)()) 645 bool IsYV411() const AVS_BakedCode(return AVS_LinkCall(IsYV411)()) 646 //bool IsYUV9() const; 647 bool IsY8() const AVS_BakedCode(return AVS_LinkCall(IsY8)()) 648 649 bool IsColorSpace(int c_space) const AVS_BakedCode(return AVS_LinkCall(IsColorSpace)(c_space)) 650 651 bool Is(int property) const AVS_BakedCode(return AVS_LinkCall(Is)(property)) 652 bool IsPlanar() const AVS_BakedCode(return AVS_LinkCall(IsPlanar)()) 653 bool IsFieldBased() const AVS_BakedCode(return AVS_LinkCall(IsFieldBased)()) 654 bool IsParityKnown() const AVS_BakedCode(return AVS_LinkCall(IsParityKnown)()) 655 bool IsBFF() const AVS_BakedCode(return AVS_LinkCall(IsBFF)()) 656 bool IsTFF() const AVS_BakedCode(return AVS_LinkCall(IsTFF)()) 657 658 bool IsVPlaneFirst() const AVS_BakedCode(return AVS_LinkCall(IsVPlaneFirst)()) // Don't use this 659 // Will not work on planar images, but will return only luma planes 660 int BytesFromPixels(int pixels) const AVS_BakedCode(return AVS_LinkCall(BytesFromPixels)(pixels)) 661 int RowSize(int plane = 0) const AVS_BakedCode(return AVS_LinkCall(RowSize)(plane)) 662 int BMPSize() const AVS_BakedCode(return AVS_LinkCall(BMPSize)()) 663 664 __int64 AudioSamplesFromFrames(int frames) const AVS_BakedCode(return AVS_LinkCall(AudioSamplesFromFrames)(frames)) 665 int FramesFromAudioSamples(__int64 samples) const AVS_BakedCode(return AVS_LinkCall(FramesFromAudioSamples)(samples)) 666 __int64 AudioSamplesFromBytes(__int64 bytes) const AVS_BakedCode(return AVS_LinkCall(AudioSamplesFromBytes)(bytes)) 667 __int64 BytesFromAudioSamples(__int64 samples) const AVS_BakedCode(return AVS_LinkCall(BytesFromAudioSamples)(samples)) 668 int AudioChannels() const AVS_BakedCode(return AVS_LinkCall(AudioChannels)()) 669 int SampleType() const AVS_BakedCode(return AVS_LinkCall(SampleType)()) 670 bool IsSampleType(int testtype) const AVS_BakedCode(return AVS_LinkCall(IsSampleType)(testtype)) 671 int SamplesPerSecond() const AVS_BakedCode(return AVS_LinkCall(SamplesPerSecond)()) 672 int BytesPerAudioSample() const AVS_BakedCode(return AVS_LinkCall(BytesPerAudioSample)()) 673 void SetFieldBased(bool isfieldbased) AVS_BakedCode(AVS_LinkCall_Void(SetFieldBased)(isfieldbased)) 674 void Set(int property) AVS_BakedCode(AVS_LinkCall_Void(Set)(property)) 675 void Clear(int property) AVS_BakedCode(AVS_LinkCall_Void(Clear)(property)) 676 // Subsampling in bitshifts! 677 int GetPlaneWidthSubsampling(int plane) const AVS_BakedCode(return AVS_LinkCall(GetPlaneWidthSubsampling)(plane)) 678 int GetPlaneHeightSubsampling(int plane) const AVS_BakedCode(return AVS_LinkCall(GetPlaneHeightSubsampling)(plane)) 679 int BitsPerPixel() const AVS_BakedCode(return AVS_LinkCall(BitsPerPixel)()) 680 681 int BytesPerChannelSample() const AVS_BakedCode(return AVS_LinkCall(BytesPerChannelSample)()) 682 683 // useful mutator 684 void SetFPS(unsigned numerator, unsigned denominator) AVS_BakedCode(AVS_LinkCall_Void(SetFPS)(numerator, denominator)) 685 686 // Range protected multiply-divide of FPS 687 void MulDivFPS(unsigned multiplier, unsigned divisor) AVS_BakedCode(AVS_LinkCall_Void(MulDivFPS)(multiplier, divisor)) 688 689 // Test for same colorspace 690 bool IsSameColorspace(const VideoInfo& vi) const AVS_BakedCode(return AVS_LinkCall(IsSameColorspace)(vi)) 691 692 // AVS+ extensions 693 // 20161005: 694 // Mapping of AVS+ extensions to classic 2.6 functions. 695 // In order to use these extended AVS+ functions for plugins that should work 696 // either with AVS+ or with Classic (8 bit) Avs 2.6 ans earlier AVS+ versions, there is an 697 // automatic fallback mechanism. 698 // From AVS+'s point of view these are not "baked" codes, the primary functions should exist. 699 // Examples: 700 // Is444() is mapped to IsYV24() for classic AVS2.6 701 // ComponentSize() returns constant 1 (1 bytes per pixel component) 702 // BitsPerComponent() returns constant 8 (Classic AVS2.6 is 8 bit only) 703 704 // Returns the number of color channels or planes in a frame 705 int NumComponents() const AVS_BakedCode(return AVS_LinkCallOptDefault(NumComponents, (((AVS_LinkCall(IsYUV)()) && !(AVS_LinkCall(IsY8)())) ? 3 : AVS_LinkCall(BytesFromPixels)(1)) ) ) 706 707 // Returns the size in bytes of a single component of a pixel 708 int ComponentSize() const AVS_BakedCode(return AVS_LinkCallOptDefault(ComponentSize, 1)) 709 710 // Returns the bit depth of a single component of a pixel 711 int BitsPerComponent() const AVS_BakedCode(return AVS_LinkCallOptDefault(BitsPerComponent, 8)) 712 713 // like IsYV24, but bit-depth independent also for YUVA 714 bool Is444() const AVS_BakedCode(return AVS_LinkCallOpt(Is444, IsYV24) ) 715 716 // like IsYV16, but bit-depth independent also for YUVA 717 bool Is422() const AVS_BakedCode(return AVS_LinkCallOpt(Is422, IsYV16) ) 718 719 // like IsYV12, but bit-depth independent also for YUVA 720 bool Is420() const AVS_BakedCode( return AVS_LinkCallOpt(Is420, IsYV12) ) 721 722 // like IsY8, but bit-depth independent 723 bool IsY() const AVS_BakedCode( return AVS_LinkCallOpt(IsY, IsY8) ) 724 725 // like IsRGB24 for 16 bit samples 726 bool IsRGB48() const AVS_BakedCode( return AVS_LinkCallOptDefault(IsRGB48, false) ) 727 728 // like IsRGB32 for 16 bit samples 729 bool IsRGB64() const AVS_BakedCode( return AVS_LinkCallOptDefault(IsRGB64, false) ) 730 731 // YUVA? 732 bool IsYUVA() const AVS_BakedCode( return AVS_LinkCallOptDefault(IsYUVA, false) ) 733 734 // Planar RGB? 735 bool IsPlanarRGB() const AVS_BakedCode( return AVS_LinkCallOptDefault(IsPlanarRGB, false) ) 736 737 // Planar RGBA? 738 bool IsPlanarRGBA() const AVS_BakedCode( return AVS_LinkCallOptDefault(IsPlanarRGBA, false) ) 739 740 }; // end struct VideoInfo 741 742 743 744 745 // VideoFrameBuffer holds information about a memory block which is used 746 // for video data. For efficiency, instances of this class are not deleted 747 // when the refcount reaches zero; instead they're stored in a linked list 748 // to be reused. The instances are deleted when the corresponding AVS 749 // file is closed. 750 751 class VideoFrameBuffer { 752 BYTE* data; 753 #ifdef SIZETMOD 754 size_t data_size; 755 #else 756 int data_size; 757 #endif 758 // sequence_number is incremented every time the buffer is changed, so 759 // that stale views can tell they're no longer valid. 760 volatile long sequence_number; 761 762 friend class VideoFrame; 763 friend class Cache; 764 friend class ScriptEnvironment; 765 volatile long refcount; 766 767 protected: 768 #ifdef SIZETMOD 769 VideoFrameBuffer(size_t size); 770 #else 771 VideoFrameBuffer(int size); 772 #endif 773 VideoFrameBuffer(); 774 ~VideoFrameBuffer(); 775 776 public: 777 const BYTE* GetReadPtr() const AVS_BakedCode( return AVS_LinkCall(VFBGetReadPtr)() ) 778 BYTE* GetWritePtr() AVS_BakedCode( return AVS_LinkCall(VFBGetWritePtr)() ) 779 #ifdef SIZETMOD 780 size_t GetDataSize() const AVS_BakedCode(return AVS_LinkCall(GetDataSize)()) 781 #else 782 int GetDataSize() const AVS_BakedCode( return AVS_LinkCall(GetDataSize)() ) 783 #endif 784 int GetSequenceNumber() const AVS_BakedCode( return AVS_LinkCall(GetSequenceNumber)() ) 785 int GetRefcount() const AVS_BakedCode( return AVS_LinkCall(GetRefcount)() ) 786 787 // Ensure VideoFrameBuffer cannot be publicly assigned 788 private: 789 VideoFrameBuffer& operator=(const VideoFrameBuffer&); 790 791 }; // end class VideoFrameBuffer 792 793 794 // VideoFrame holds a "window" into a VideoFrameBuffer. Operator new 795 // is overloaded to recycle class instances. 796 797 class VideoFrame { 798 volatile long refcount; 799 VideoFrameBuffer* vfb; 800 801 // Due to technical reasons these members are not const, but should be treated as such. 802 // That means do not modify them once the class has been constructed. 803 #ifdef SIZETMOD 804 size_t offset; 805 #else 806 int offset; 807 #endif 808 int pitch, row_size, height; 809 #ifdef SIZETMOD 810 size_t offsetU, offsetV; // U&V offsets are from top of picture. 811 #else 812 int offsetU, offsetV; // U&V offsets are from top of picture. 813 #endif 814 int pitchUV, row_sizeUV, heightUV; // for Planar RGB offsetU, offsetV is for the 2nd and 3rd Plane. 815 // for Planar RGB pitchUV and row_sizeUV = 0, because when no VideoInfo (MakeWriteable) 816 // the decision on existance of UV is checked by zero pitch 817 // AVS+ extension, does not break plugins if appended here 818 #ifdef SIZETMOD 819 size_t offsetA; 820 #else 821 int offsetA; 822 #endif 823 int pitchA, row_sizeA; // 4th alpha plane support, pitch and row_size is 0 is none 824 825 friend class PVideoFrame; 826 void AddRef(); 827 void Release(); 828 829 friend class ScriptEnvironment; 830 friend class Cache; 831 832 #ifdef SIZETMOD 833 VideoFrame(VideoFrameBuffer* _vfb, size_t _offset, int _pitch, int _row_size, int _height); 834 VideoFrame(VideoFrameBuffer* _vfb, size_t _offset, int _pitch, int _row_size, int _height, size_t _offsetU, size_t _offsetV, int _pitchUV, int _row_sizeUV, int _heightUV); 835 // for Alpha 836 VideoFrame(VideoFrameBuffer* _vfb, size_t _offset, int _pitch, int _row_size, int _height, size_t _offsetU, size_t _offsetV, int _pitchUV, int _row_sizeUV, int _heightUV, size_t _offsetA); 837 #else 838 VideoFrame(VideoFrameBuffer* _vfb, int _offset, int _pitch, int _row_size, int _height); 839 VideoFrame(VideoFrameBuffer* _vfb, int _offset, int _pitch, int _row_size, int _height, int _offsetU, int _offsetV, int _pitchUV, int _row_sizeUV, int _heightUV); 840 // for Alpha 841 VideoFrame(VideoFrameBuffer* _vfb, int _offset, int _pitch, int _row_size, int _height, int _offsetU, int _offsetV, int _pitchUV, int _row_sizeUV, int _heightUV, int _offsetA); 842 #endif 843 844 void* operator new(size_t size); 845 // TESTME: OFFSET U/V may be switched to what could be expected from AVI standard! 846 public: 847 int GetPitch(int plane=0) const AVS_BakedCode( return AVS_LinkCall(GetPitch)(plane) ) 848 int GetRowSize(int plane=0) const AVS_BakedCode( return AVS_LinkCall(GetRowSize)(plane) ) 849 int GetHeight(int plane=0) const AVS_BakedCode( return AVS_LinkCall(GetHeight)(plane) ) 850 851 // generally you shouldn't use these three 852 VideoFrameBuffer* GetFrameBuffer() const AVS_BakedCode( return AVS_LinkCall(GetFrameBuffer)() ) 853 #ifdef SIZETMOD 854 size_t GetOffset(int plane = 0) const AVS_BakedCode(return AVS_LinkCall(GetOffset)(plane)) 855 #else 856 int GetOffset(int plane=0) const AVS_BakedCode( return AVS_LinkCall(GetOffset)(plane) ) 857 #endif 858 859 // in plugins use env->SubFrame() -- because implementation code is only available inside avisynth.dll. Doh! 860 VideoFrame* Subframe(int rel_offset, int new_pitch, int new_row_size, int new_height) const; 861 VideoFrame* Subframe(int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int pitchUV) const; 862 // for Alpha 863 VideoFrame* Subframe(int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int pitchUV, int rel_offsetA) const; 864 865 const BYTE* GetReadPtr(int plane=0) const AVS_BakedCode( return AVS_LinkCall(VFGetReadPtr)(plane) ) 866 bool IsWritable() const AVS_BakedCode( return AVS_LinkCall(IsWritable)() ) 867 BYTE* GetWritePtr(int plane=0) const AVS_BakedCode( return AVS_LinkCall(VFGetWritePtr)(plane) ) 868 869 ~VideoFrame() AVS_BakedCode( AVS_LinkCall_Void(VideoFrame_DESTRUCTOR)() ) 870 #ifdef BUILDING_AVSCORE 871 public: 872 void DESTRUCTOR(); /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */ 873 #endif 874 875 // Ensure VideoFrame cannot be publicly assigned 876 private: 877 VideoFrame& operator=(const VideoFrame&); 878 879 }; // end class VideoFrame 880 881 enum CachePolicyHint { 882 // Values 0 to 5 are reserved for old 2.5 plugins 883 // do not use them in new plugins 884 885 // New 2.6 explicitly defined cache hints. 886 CACHE_NOTHING=10, // Do not cache video. 887 CACHE_WINDOW=11, // Hard protect upto X frames within a range of X from the current frame N. 888 CACHE_GENERIC=12, // LRU cache upto X frames. 889 CACHE_FORCE_GENERIC=13, // LRU cache upto X frames, override any previous CACHE_WINDOW. 890 891 CACHE_GET_POLICY=30, // Get the current policy. 892 CACHE_GET_WINDOW=31, // Get the current window h_span. 893 CACHE_GET_RANGE=32, // Get the current generic frame range. 894 895 CACHE_AUDIO=50, // Explicitly cache audio, X byte cache. 896 CACHE_AUDIO_NOTHING=51, // Explicitly do not cache audio. 897 CACHE_AUDIO_NONE=52, // Audio cache off (auto mode), X byte intial cache. 898 CACHE_AUDIO_AUTO=53, // Audio cache on (auto mode), X byte intial cache. 899 900 CACHE_GET_AUDIO_POLICY=70, // Get the current audio policy. 901 CACHE_GET_AUDIO_SIZE=71, // Get the current audio cache size. 902 903 CACHE_PREFETCH_FRAME=100, // Queue request to prefetch frame N. 904 CACHE_PREFETCH_GO=101, // Action video prefetches. 905 906 CACHE_PREFETCH_AUDIO_BEGIN=120, // Begin queue request transaction to prefetch audio (take critical section). 907 CACHE_PREFETCH_AUDIO_STARTLO=121, // Set low 32 bits of start. 908 CACHE_PREFETCH_AUDIO_STARTHI=122, // Set high 32 bits of start. 909 CACHE_PREFETCH_AUDIO_COUNT=123, // Set low 32 bits of length. 910 CACHE_PREFETCH_AUDIO_COMMIT=124, // Enqueue request transaction to prefetch audio (release critical section). 911 CACHE_PREFETCH_AUDIO_GO=125, // Action audio prefetches. 912 913 CACHE_GETCHILD_CACHE_MODE=200, // Cache ask Child for desired video cache mode. 914 CACHE_GETCHILD_CACHE_SIZE=201, // Cache ask Child for desired video cache size. 915 CACHE_GETCHILD_AUDIO_MODE=202, // Cache ask Child for desired audio cache mode. 916 CACHE_GETCHILD_AUDIO_SIZE=203, // Cache ask Child for desired audio cache size. 917 918 CACHE_GETCHILD_COST=220, // Cache ask Child for estimated processing cost. 919 CACHE_COST_ZERO=221, // Child response of zero cost (ptr arithmetic only). 920 CACHE_COST_UNIT=222, // Child response of unit cost (less than or equal 1 full frame blit). 921 CACHE_COST_LOW=223, // Child response of light cost. (Fast) 922 CACHE_COST_MED=224, // Child response of medium cost. (Real time) 923 CACHE_COST_HI=225, // Child response of heavy cost. (Slow) 924 925 CACHE_GETCHILD_THREAD_MODE=240, // Cache ask Child for thread safetyness. 926 CACHE_THREAD_UNSAFE=241, // Only 1 thread allowed for all instances. 2.5 filters default! 927 CACHE_THREAD_CLASS=242, // Only 1 thread allowed for each instance. 2.6 filters default! 928 CACHE_THREAD_SAFE=243, // Allow all threads in any instance. 929 CACHE_THREAD_OWN=244, // Safe but limit to 1 thread, internally threaded. 930 931 CACHE_GETCHILD_ACCESS_COST=260, // Cache ask Child for preferred access pattern. 932 CACHE_ACCESS_RAND=261, // Filter is access order agnostic. 933 CACHE_ACCESS_SEQ0=262, // Filter prefers sequential access (low cost) 934 CACHE_ACCESS_SEQ1=263, // Filter needs sequential access (high cost) 935 936 CACHE_AVSPLUS_CONSTANTS = 500, // Smaller values are reserved for classic Avisynth 937 938 CACHE_DONT_CACHE_ME, // Filters that don't need caching (eg. trim, cache etc.) should return 1 to this request 939 CACHE_SET_MIN_CAPACITY, 940 CACHE_SET_MAX_CAPACITY, 941 CACHE_GET_MIN_CAPACITY, 942 CACHE_GET_MAX_CAPACITY, 943 CACHE_GET_SIZE, 944 CACHE_GET_REQUESTED_CAP, 945 CACHE_GET_CAPACITY, 946 CACHE_GET_MTMODE, 947 948 CACHE_IS_CACHE_REQ, 949 CACHE_IS_CACHE_ANS, 950 CACHE_IS_MTGUARD_REQ, 951 CACHE_IS_MTGUARD_ANS, 952 953 CACHE_USER_CONSTANTS = 1000 // Smaller values are reserved for the core 954 955 }; 956 957 // Base class for all filters. 958 class IClip { 959 friend class PClip; 960 friend class AVSValue; 961 volatile long refcnt; 962 void AddRef(); 963 void Release(); 964 public: IClip()965 IClip() : refcnt(0) {} GetVersion()966 virtual int __stdcall GetVersion() { return AVISYNTH_INTERFACE_VERSION; } 967 virtual PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) = 0; 968 virtual bool __stdcall GetParity(int n) = 0; // return field parity if field_based, else parity of first field in frame 969 virtual void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env) = 0; // start and count are in samples 970 /* Need to check GetVersion first, pre v5 will return random crap from EAX reg. */ 971 virtual int __stdcall SetCacheHints(int cachehints,int frame_range) = 0 ; // We do not pass cache requests upwards, only to the next filter. 972 virtual const VideoInfo& __stdcall GetVideoInfo() = 0; ~IClip()973 virtual AVSC_CC ~IClip() {} 974 }; // end class IClip 975 976 977 // smart pointer to IClip 978 class PClip { 979 980 IClip* p; 981 982 IClip* GetPointerWithAddRef() const; 983 friend class AVSValue; 984 friend class VideoFrame; 985 986 void Init(IClip* x); 987 void Set(IClip* x); 988 989 public: 990 PClip() AVS_BakedCode( AVS_LinkCall_Void(PClip_CONSTRUCTOR0)() ) 991 PClip(const PClip& x) AVS_BakedCode( AVS_LinkCall_Void(PClip_CONSTRUCTOR1)(x) ) 992 PClip(IClip* x) AVS_BakedCode( AVS_LinkCall_Void(PClip_CONSTRUCTOR2)(x) ) 993 void operator=(IClip* x) AVS_BakedCode( AVS_LinkCall_Void(PClip_OPERATOR_ASSIGN0)(x) ) 994 void operator=(const PClip& x) AVS_BakedCode( AVS_LinkCall_Void(PClip_OPERATOR_ASSIGN1)(x) ) 995 996 IClip* operator->() const { return p; } 997 998 // useful in conditional expressions 999 operator void*() const { return p; } 1000 bool operator!() const { return !p; } 1001 1002 ~PClip() AVS_BakedCode( AVS_LinkCall_Void(PClip_DESTRUCTOR)() ) 1003 #ifdef BUILDING_AVSCORE 1004 public: 1005 void CONSTRUCTOR0(); /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */ 1006 void CONSTRUCTOR1(const PClip& x); 1007 void CONSTRUCTOR2(IClip* x); 1008 void OPERATOR_ASSIGN0(IClip* x); 1009 void OPERATOR_ASSIGN1(const PClip& x); 1010 void DESTRUCTOR(); 1011 #endif 1012 }; // end class PClip 1013 1014 1015 // smart pointer to VideoFrame 1016 class PVideoFrame { 1017 1018 VideoFrame* p; 1019 1020 void Init(VideoFrame* x); 1021 void Set(VideoFrame* x); 1022 1023 public: 1024 PVideoFrame() AVS_BakedCode( AVS_LinkCall_Void(PVideoFrame_CONSTRUCTOR0)() ) 1025 PVideoFrame(const PVideoFrame& x) AVS_BakedCode( AVS_LinkCall_Void(PVideoFrame_CONSTRUCTOR1)(x) ) 1026 PVideoFrame(VideoFrame* x) AVS_BakedCode( AVS_LinkCall_Void(PVideoFrame_CONSTRUCTOR2)(x) ) 1027 void operator=(VideoFrame* x) AVS_BakedCode( AVS_LinkCall_Void(PVideoFrame_OPERATOR_ASSIGN0)(x) ) 1028 void operator=(const PVideoFrame& x) AVS_BakedCode( AVS_LinkCall_Void(PVideoFrame_OPERATOR_ASSIGN1)(x) ) 1029 1030 VideoFrame* operator->() const { return p; } 1031 1032 // for conditional expressions 1033 operator void*() const { return p; } 1034 bool operator!() const { return !p; } 1035 1036 ~PVideoFrame() AVS_BakedCode( AVS_LinkCall_Void(PVideoFrame_DESTRUCTOR)() ) 1037 #ifdef BUILDING_AVSCORE 1038 public: 1039 void CONSTRUCTOR0(); /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */ 1040 void CONSTRUCTOR1(const PVideoFrame& x); 1041 void CONSTRUCTOR2(VideoFrame* x); 1042 void OPERATOR_ASSIGN0(VideoFrame* x); 1043 void OPERATOR_ASSIGN1(const PVideoFrame& x); 1044 void DESTRUCTOR(); 1045 #endif 1046 }; // end class PVideoFrame 1047 1048 1049 class AVSValue { 1050 public: 1051 1052 AVSValue() AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR0)() ) 1053 AVSValue(IClip* c) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR1)(c) ) 1054 AVSValue(const PClip& c) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR2)(c) ) 1055 AVSValue(bool b) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR3)(b) ) 1056 AVSValue(int i) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR4)(i) ) 1057 // AVSValue(__int64 l); 1058 AVSValue(float f) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR5)(f) ) 1059 AVSValue(double f) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR6)(f) ) 1060 AVSValue(const char* s) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR7)(s) ) 1061 AVSValue(const AVSValue* a, int size) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR8)(a, size) ) 1062 AVSValue(const AVSValue& a, int size) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR8)(&a, size) ) 1063 AVSValue(const AVSValue& v) AVS_BakedCode( AVS_LinkCall_Void(AVSValue_CONSTRUCTOR9)(v) ) 1064 1065 ~AVSValue() AVS_BakedCode( AVS_LinkCall_Void(AVSValue_DESTRUCTOR)() ) 1066 AVSValue& operator=(const AVSValue& v) AVS_BakedCode( return AVS_LinkCallV(AVSValue_OPERATOR_ASSIGN)(v) ) 1067 1068 // Note that we transparently allow 'int' to be treated as 'float'. 1069 // There are no int<->bool conversions, though. 1070 1071 bool Defined() const AVS_BakedCode( return AVS_LinkCall(Defined)() ) 1072 bool IsClip() const AVS_BakedCode( return AVS_LinkCall(IsClip)() ) 1073 bool IsBool() const AVS_BakedCode( return AVS_LinkCall(IsBool)() ) 1074 bool IsInt() const AVS_BakedCode( return AVS_LinkCall(IsInt)() ) 1075 // bool IsLong() const; 1076 bool IsFloat() const AVS_BakedCode( return AVS_LinkCall(IsFloat)() ) 1077 bool IsString() const AVS_BakedCode( return AVS_LinkCall(IsString)() ) 1078 bool IsArray() const AVS_BakedCode( return AVS_LinkCall(IsArray)() ) 1079 1080 PClip AsClip() const AVS_BakedCode( return AVS_LinkCall(AsClip)() ) 1081 bool AsBool() const AVS_BakedCode( return AVS_LinkCall(AsBool1)() ) 1082 int AsInt() const AVS_BakedCode( return AVS_LinkCall(AsInt1)() ) 1083 // int AsLong() const; 1084 const char* AsString() const AVS_BakedCode( return AVS_LinkCall(AsString1)() ) 1085 double AsFloat() const AVS_BakedCode( return AVS_LinkCall(AsFloat1)() ) 1086 float AsFloatf() const AVS_BakedCode( return float( AVS_LinkCall(AsFloat1)() ) ) 1087 1088 bool AsBool(bool def) const AVS_BakedCode( return AVS_LinkCall(AsBool2)(def) ) 1089 int AsInt(int def) const AVS_BakedCode( return AVS_LinkCall(AsInt2)(def) ) 1090 double AsDblDef(double def) const AVS_BakedCode( return AVS_LinkCall(AsDblDef)(def) ) // Value is still a float 1091 double AsFloat(float def) const AVS_BakedCode( return AVS_LinkCall(AsFloat2)(def) ) 1092 float AsFloatf(float def) const AVS_BakedCode( return float( AVS_LinkCall(AsFloat2)(def) ) ) 1093 const char* AsString(const char* def) const AVS_BakedCode( return AVS_LinkCall(AsString2)(def) ) 1094 1095 int ArraySize() const AVS_BakedCode( return AVS_LinkCall(ArraySize)() ) 1096 1097 const AVSValue& operator[](int index) const AVS_BakedCode( return AVS_LinkCallV(AVSValue_OPERATOR_INDEX)(index) ) 1098 1099 private: 1100 1101 short type; // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or RFU: 'l'ong ('d'ouble) 1102 short array_size; 1103 union { 1104 IClip* clip; 1105 bool boolean; 1106 int integer; 1107 float floating_pt; 1108 const char* string; 1109 const AVSValue* array; 1110 #ifdef X86_64 1111 // if ever, only x64 will support. It breaks struct size on 32 bit 1112 __int64 longlong; // 8 bytes 1113 double double_pt; // 8 bytes 1114 #endif 1115 }; 1116 1117 void Assign(const AVSValue* src, bool init); 1118 #ifdef BUILDING_AVSCORE 1119 public: 1120 void CONSTRUCTOR0(); /* Damn compiler won't allow taking the address of reserved constructs, make a dummy interlude */ 1121 void CONSTRUCTOR1(IClip* c); 1122 void CONSTRUCTOR2(const PClip& c); 1123 void CONSTRUCTOR3(bool b); 1124 void CONSTRUCTOR4(int i); 1125 void CONSTRUCTOR5(float f); 1126 void CONSTRUCTOR6(double f); 1127 void CONSTRUCTOR7(const char* s); 1128 void CONSTRUCTOR8(const AVSValue* a, int size); 1129 void CONSTRUCTOR9(const AVSValue& v); 1130 void DESTRUCTOR(); 1131 AVSValue& OPERATOR_ASSIGN(const AVSValue& v); 1132 const AVSValue& OPERATOR_INDEX(int index) const; 1133 1134 bool AsBool1() const; 1135 int AsInt1() const; 1136 const char* AsString1() const; 1137 double AsFloat1() const; 1138 1139 bool AsBool2(bool def) const; 1140 int AsInt2(int def) const; 1141 double AsFloat2(float def) const; 1142 const char* AsString2(const char* def) const; 1143 1144 #ifdef NEW_AVSVALUE 1145 void MarkArrayAsC(); 1146 void CONSTRUCTOR10(const AVSValue& v, bool c_arrays); 1147 AVSValue(const AVSValue& v, bool c_arrays); 1148 void Assign2(const AVSValue* src, bool init, bool c_arrays); 1149 #endif 1150 1151 #endif 1152 }; // end class AVSValue 1153 1154 #undef CALL_MEMBER_FN 1155 #undef AVS_LinkCallOptDefault 1156 #undef AVS_LinkCallOpt 1157 #undef AVS_LinkCallV 1158 #undef AVS_LinkCall 1159 #undef AVS_BakedCode 1160 1161 #define AVS_UNUSED(x) x 1162 1163 // instantiable null filter 1164 class GenericVideoFilter : public IClip { 1165 protected: 1166 PClip child; 1167 VideoInfo vi; 1168 public: GenericVideoFilter(PClip _child)1169 GenericVideoFilter(PClip _child) : child(_child) { vi = child->GetVideoInfo(); } GetFrame(int n,IScriptEnvironment * env)1170 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) { return child->GetFrame(n, env); } GetAudio(void * buf,__int64 start,__int64 count,IScriptEnvironment * env)1171 void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env) { child->GetAudio(buf, start, count, env); } GetVideoInfo()1172 const VideoInfo& __stdcall GetVideoInfo() { return vi; } GetParity(int n)1173 bool __stdcall GetParity(int n) { return child->GetParity(n); } SetCacheHints(int cachehints,int frame_range)1174 int __stdcall SetCacheHints(int cachehints, int frame_range) { AVS_UNUSED(cachehints); AVS_UNUSED(frame_range); return 0; }; // We do not pass cache requests upwards, only to the next filter. 1175 }; 1176 1177 1178 1179 1180 #include <avs/cpuid.h> 1181 1182 1183 1184 class IScriptEnvironment { 1185 public: ~IScriptEnvironment()1186 virtual AVSC_CC ~IScriptEnvironment() {} 1187 1188 virtual /*static*/ int __stdcall GetCPUFlags() = 0; 1189 1190 virtual char* __stdcall SaveString(const char* s, int length = -1) = 0; 1191 virtual char* __stdcall Sprintf(const char* fmt, ...) = 0; 1192 // note: val is really a va_list; I hope everyone typedefs va_list to a pointer 1193 virtual char* __stdcall VSprintf(const char* fmt, void* val) = 0; 1194 1195 __declspec(noreturn) virtual void __stdcall ThrowError(const char* fmt, ...) = 0; 1196 1197 class NotFound /*exception*/ {}; // thrown by Invoke and GetVar 1198 1199 typedef AVSValue (__cdecl *ApplyFunc)(AVSValue args, void* user_data, IScriptEnvironment* env); 1200 1201 virtual void __stdcall AddFunction(const char* name, const char* params, ApplyFunc apply, void* user_data) = 0; 1202 virtual bool __stdcall FunctionExists(const char* name) = 0; 1203 virtual AVSValue __stdcall Invoke(const char* name, const AVSValue args, const char* const* arg_names=0) = 0; 1204 1205 virtual AVSValue __stdcall GetVar(const char* name) = 0; 1206 virtual bool __stdcall SetVar(const char* name, const AVSValue& val) = 0; 1207 virtual bool __stdcall SetGlobalVar(const char* name, const AVSValue& val) = 0; 1208 1209 virtual void __stdcall PushContext(int level=0) = 0; 1210 virtual void __stdcall PopContext() = 0; 1211 1212 // align should be 4 or 8 1213 virtual PVideoFrame __stdcall NewVideoFrame(const VideoInfo& vi, int align=FRAME_ALIGN) = 0; 1214 1215 virtual bool __stdcall MakeWritable(PVideoFrame* pvf) = 0; 1216 1217 virtual void __stdcall BitBlt(BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height) = 0; 1218 1219 typedef void (__cdecl *ShutdownFunc)(void* user_data, IScriptEnvironment* env); 1220 virtual void __stdcall AtExit(ShutdownFunc function, void* user_data) = 0; 1221 1222 virtual void __stdcall CheckVersion(int version = AVISYNTH_INTERFACE_VERSION) = 0; 1223 1224 virtual PVideoFrame __stdcall Subframe(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, int new_height) = 0; 1225 1226 virtual int __stdcall SetMemoryMax(int mem) = 0; 1227 1228 virtual int __stdcall SetWorkingDir(const char * newdir) = 0; 1229 1230 virtual void* __stdcall ManageCache(int key, void* data) = 0; 1231 1232 enum PlanarChromaAlignmentMode { 1233 PlanarChromaAlignmentOff, 1234 PlanarChromaAlignmentOn, 1235 PlanarChromaAlignmentTest }; 1236 1237 virtual bool __stdcall PlanarChromaAlignment(PlanarChromaAlignmentMode key) = 0; 1238 1239 virtual PVideoFrame __stdcall SubframePlanar(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, 1240 int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV) = 0; 1241 1242 virtual void __stdcall DeleteScriptEnvironment() = 0; 1243 1244 virtual void __stdcall ApplyMessage(PVideoFrame* frame, const VideoInfo& vi, const char* message, int size, 1245 int textcolor, int halocolor, int bgcolor) = 0; 1246 1247 virtual const AVS_Linkage* const __stdcall GetAVSLinkage() = 0; 1248 1249 // noThrow version of GetVar 1250 virtual AVSValue __stdcall GetVarDef(const char* name, const AVSValue& def = AVSValue()) = 0; 1251 1252 }; // end class IScriptEnvironment 1253 1254 1255 enum MtMode 1256 { 1257 MT_INVALID = 0, 1258 MT_NICE_FILTER = 1, 1259 MT_MULTI_INSTANCE = 2, 1260 MT_SERIALIZED = 3, 1261 MT_SPECIAL_MT = 4, 1262 MT_MODE_COUNT = 5 1263 }; 1264 1265 class IJobCompletion 1266 { 1267 public: 1268 ~IJobCompletion()1269 virtual __stdcall ~IJobCompletion() {} 1270 virtual void __stdcall Wait() = 0; 1271 virtual AVSValue __stdcall Get(size_t i) = 0; 1272 virtual size_t __stdcall Size() const = 0; 1273 virtual size_t __stdcall Capacity() const = 0; 1274 virtual void __stdcall Reset() = 0; 1275 virtual void __stdcall Destroy() = 0; 1276 }; 1277 1278 class IScriptEnvironment2; 1279 class Prefetcher; 1280 typedef AVSValue (*ThreadWorkerFuncPtr)(IScriptEnvironment2* env, void* data); 1281 1282 enum AvsEnvProperty 1283 { 1284 AEP_PHYSICAL_CPUS = 1, 1285 AEP_LOGICAL_CPUS = 2, 1286 AEP_THREADPOOL_THREADS = 3, 1287 AEP_FILTERCHAIN_THREADS = 4, 1288 AEP_THREAD_ID = 5, 1289 AEP_VERSION = 6 1290 }; 1291 1292 enum AvsAllocType 1293 { 1294 AVS_NORMAL_ALLOC = 1, 1295 AVS_POOLED_ALLOC = 2 1296 }; 1297 1298 /* ----------------------------------------------------------------------------- 1299 Note to plugin authors: The interface in IScriptEnvironment2 is 1300 preliminary / under construction / only for testing / non-final etc.! 1301 As long as you see this note here, IScriptEnvironment2 might still change, 1302 in which case your plugin WILL break. This also means that you are welcome 1303 to test it and give your feedback about any ideas, improvements, or issues 1304 you might have. 1305 ----------------------------------------------------------------------------- */ 1306 class AVSFunction; 1307 class IScriptEnvironment2 : public IScriptEnvironment{ 1308 public: ~IScriptEnvironment2()1309 virtual ~IScriptEnvironment2() {} 1310 1311 // Generic system to ask for various properties 1312 virtual size_t __stdcall GetProperty(AvsEnvProperty prop) = 0; 1313 1314 // Returns TRUE and the requested variable. If the method fails, returns FALSE and does not touch 'val'. 1315 virtual bool __stdcall GetVar(const char* name, AVSValue *val) const = 0; 1316 1317 // Return the value of the requested variable. 1318 // If the variable was not found or had the wrong type, 1319 // return the supplied default value. 1320 virtual bool __stdcall GetVar(const char* name, bool def) const = 0; 1321 virtual int __stdcall GetVar(const char* name, int def) const = 0; 1322 virtual double __stdcall GetVar(const char* name, double def) const = 0; 1323 virtual const char* __stdcall GetVar(const char* name, const char* def) const = 0; 1324 1325 // Plugin functions 1326 virtual bool __stdcall LoadPlugin(const char* filePath, bool throwOnError, AVSValue *result) = 0; 1327 virtual void __stdcall AddAutoloadDir(const char* dirPath, bool toFront) = 0; 1328 virtual void __stdcall ClearAutoloadDirs() = 0; 1329 virtual void __stdcall AutoloadPlugins() = 0; 1330 virtual void __stdcall AddFunction(const char* name, const char* params, ApplyFunc apply, void* user_data, const char *exportVar) = 0; 1331 virtual bool __stdcall InternalFunctionExists(const char* name) = 0; 1332 1333 // Threading 1334 virtual void __stdcall SetFilterMTMode(const char* filter, MtMode mode, bool force) = 0; // If filter is "DEFAULT_MT_MODE", sets the default MT mode 1335 virtual IJobCompletion* __stdcall NewCompletion(size_t capacity) = 0; 1336 virtual void __stdcall ParallelJob(ThreadWorkerFuncPtr jobFunc, void* jobData, IJobCompletion* completion) = 0; 1337 1338 // This version of Invoke will return false instead of throwing NotFound(). 1339 virtual bool __stdcall Invoke(AVSValue *result, const char* name, const AVSValue& args, const char* const* arg_names=0) = 0; 1340 1341 // Support functions 1342 virtual void* __stdcall Allocate(size_t nBytes, size_t alignment, AvsAllocType type) = 0; 1343 virtual void __stdcall Free(void* ptr) = 0; 1344 1345 // These lines are needed so that we can overload the older functions from IScriptEnvironment. 1346 using IScriptEnvironment::Invoke; 1347 using IScriptEnvironment::AddFunction; 1348 using IScriptEnvironment::GetVar; 1349 1350 virtual PVideoFrame __stdcall SubframePlanarA(PVideoFrame src, int rel_offset, int new_pitch, int new_row_size, 1351 int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV, int rel_offsetA) = 0; 1352 1353 }; // end class IScriptEnvironment2 1354 1355 1356 // avisynth.dll exports this; it's a way to use it as a library, without 1357 // writing an AVS script or without going through AVIFile. 1358 AVSC_API(IScriptEnvironment*, CreateScriptEnvironment)(int version = AVISYNTH_INTERFACE_VERSION); 1359 1360 1361 // These are some global variables you can set in your script to change AviSynth's behavior. 1362 #define VARNAME_AllowFloatAudio "OPT_AllowFloatAudio" // Allow WAVE_FORMAT_IEEE_FLOAT audio output 1363 #define VARNAME_VDubPlanarHack "OPT_VDubPlanarHack" // Hack YV16 and YV24 chroma plane order for old VDub's 1364 #define VARNAME_AVIPadScanlines "OPT_AVIPadScanlines" // Have scanlines mod4 padded in all pixel formats 1365 #define VARNAME_UseWaveExtensible "OPT_UseWaveExtensible" // Use WAVEFORMATEXTENSIBLE when describing audio to Windows 1366 #define VARNAME_dwChannelMask "OPT_dwChannelMask" // Integer audio channel mask. See description of WAVEFORMATEXTENSIBLE for more info. 1367 #define VARNAME_Enable_V210 "OPT_Enable_V210" // AVS+ use V210 instead of P210 (VfW) 1368 #define VARNAME_Enable_Y3_10_10 "OPT_Enable_Y3_10_10" // AVS+ use Y3[10][10] instead of P210 (VfW) 1369 #define VARNAME_Enable_Y3_10_16 "OPT_Enable_Y3_10_16" // AVS+ use Y3[10][16] instead of P216 (VfW) 1370 #define VARNAME_Enable_b64a "OPT_Enable_b64a" // AVS+ use b64a instead of BRA[64] (VfW) 1371 #define VARNAME_Enable_PlanarToPackedRGB "OPT_Enable_PlanarToPackedRGB" // AVS+ convert Planar RGB to packed RGB (VfW) 1372 1373 // C exports 1374 #include <avs/capi.h> 1375 AVSC_API(IScriptEnvironment2*, CreateScriptEnvironment2)(int version = AVISYNTH_INTERFACE_VERSION); 1376 1377 #ifndef BUILDING_AVSCORE 1378 #undef AVS_UNUSED 1379 #endif 1380 1381 #pragma pack(pop) 1382 1383 #endif //__AVISYNTH_6_H__ 1384