Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
52869 views
1
// Avisynth C Interface Version 0.20
2
// Copyright 2003 Kevin Atkinson
3
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 2 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17
// MA 02110-1301 USA, or visit
18
// http://www.gnu.org/copyleft/gpl.html .
19
//
20
// As a special exception, I give you permission to link to the
21
// Avisynth C interface with independent modules that communicate with
22
// the Avisynth C interface solely through the interfaces defined in
23
// avisynth_c.h, regardless of the license terms of these independent
24
// modules, and to copy and distribute the resulting combined work
25
// under terms of your choice, provided that every copy of the
26
// combined work is accompanied by a complete copy of the source code
27
// of the Avisynth C interface and Avisynth itself (with the version
28
// used to produce the combined work), being distributed under the
29
// terms of the GNU General Public License plus this exception. An
30
// independent module is a module which is not derived from or based
31
// on Avisynth C Interface, such as 3rd-party filters, import and
32
// export plugins, or graphical user interfaces.
33
34
// NOTE: this is a partial update of the Avisynth C interface to recognize
35
// new color spaces added in Avisynth 2.60. By no means is this document
36
// completely Avisynth 2.60 compliant.
37
38
#ifndef __AVISYNTH_C__
39
#define __AVISYNTH_C__
40
41
#include "avs/config.h"
42
#include "avs/capi.h"
43
#include "avs/types.h"
44
45
46
/////////////////////////////////////////////////////////////////////
47
//
48
// Constants
49
//
50
51
#ifndef __AVISYNTH_6_H__
52
enum { AVISYNTH_INTERFACE_VERSION = 6 };
53
#endif
54
55
enum {AVS_SAMPLE_INT8 = 1<<0,
56
AVS_SAMPLE_INT16 = 1<<1,
57
AVS_SAMPLE_INT24 = 1<<2,
58
AVS_SAMPLE_INT32 = 1<<3,
59
AVS_SAMPLE_FLOAT = 1<<4};
60
61
enum {AVS_PLANAR_Y=1<<0,
62
AVS_PLANAR_U=1<<1,
63
AVS_PLANAR_V=1<<2,
64
AVS_PLANAR_ALIGNED=1<<3,
65
AVS_PLANAR_Y_ALIGNED=AVS_PLANAR_Y|AVS_PLANAR_ALIGNED,
66
AVS_PLANAR_U_ALIGNED=AVS_PLANAR_U|AVS_PLANAR_ALIGNED,
67
AVS_PLANAR_V_ALIGNED=AVS_PLANAR_V|AVS_PLANAR_ALIGNED,
68
AVS_PLANAR_A=1<<4,
69
AVS_PLANAR_R=1<<5,
70
AVS_PLANAR_G=1<<6,
71
AVS_PLANAR_B=1<<7,
72
AVS_PLANAR_A_ALIGNED=AVS_PLANAR_A|AVS_PLANAR_ALIGNED,
73
AVS_PLANAR_R_ALIGNED=AVS_PLANAR_R|AVS_PLANAR_ALIGNED,
74
AVS_PLANAR_G_ALIGNED=AVS_PLANAR_G|AVS_PLANAR_ALIGNED,
75
AVS_PLANAR_B_ALIGNED=AVS_PLANAR_B|AVS_PLANAR_ALIGNED};
76
77
// Colorspace properties.
78
enum {AVS_CS_BGR = 1<<28,
79
AVS_CS_YUV = 1<<29,
80
AVS_CS_INTERLEAVED = 1<<30,
81
AVS_CS_PLANAR = 1<<31,
82
83
AVS_CS_SHIFT_SUB_WIDTH = 0,
84
AVS_CS_SHIFT_SUB_HEIGHT = 8,
85
AVS_CS_SHIFT_SAMPLE_BITS = 16,
86
87
AVS_CS_SUB_WIDTH_MASK = 7 << AVS_CS_SHIFT_SUB_WIDTH,
88
AVS_CS_SUB_WIDTH_1 = 3 << AVS_CS_SHIFT_SUB_WIDTH, // YV24
89
AVS_CS_SUB_WIDTH_2 = 0 << AVS_CS_SHIFT_SUB_WIDTH, // YV12, I420, YV16
90
AVS_CS_SUB_WIDTH_4 = 1 << AVS_CS_SHIFT_SUB_WIDTH, // YUV9, YV411
91
92
AVS_CS_VPLANEFIRST = 1 << 3, // YV12, YV16, YV24, YV411, YUV9
93
AVS_CS_UPLANEFIRST = 1 << 4, // I420
94
95
AVS_CS_SUB_HEIGHT_MASK = 7 << AVS_CS_SHIFT_SUB_HEIGHT,
96
AVS_CS_SUB_HEIGHT_1 = 3 << AVS_CS_SHIFT_SUB_HEIGHT, // YV16, YV24, YV411
97
AVS_CS_SUB_HEIGHT_2 = 0 << AVS_CS_SHIFT_SUB_HEIGHT, // YV12, I420
98
AVS_CS_SUB_HEIGHT_4 = 1 << AVS_CS_SHIFT_SUB_HEIGHT, // YUV9
99
100
AVS_CS_SAMPLE_BITS_MASK = 7 << AVS_CS_SHIFT_SAMPLE_BITS,
101
AVS_CS_SAMPLE_BITS_8 = 0 << AVS_CS_SHIFT_SAMPLE_BITS,
102
AVS_CS_SAMPLE_BITS_16 = 1 << AVS_CS_SHIFT_SAMPLE_BITS,
103
AVS_CS_SAMPLE_BITS_32 = 2 << AVS_CS_SHIFT_SAMPLE_BITS,
104
105
AVS_CS_PLANAR_MASK = AVS_CS_PLANAR | AVS_CS_INTERLEAVED | AVS_CS_YUV | AVS_CS_BGR | AVS_CS_SAMPLE_BITS_MASK | AVS_CS_SUB_HEIGHT_MASK | AVS_CS_SUB_WIDTH_MASK,
106
AVS_CS_PLANAR_FILTER = ~( AVS_CS_VPLANEFIRST | AVS_CS_UPLANEFIRST )};
107
108
// Specific colorformats
109
enum {
110
AVS_CS_UNKNOWN = 0,
111
AVS_CS_BGR24 = 1<<0 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
112
AVS_CS_BGR32 = 1<<1 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
113
AVS_CS_YUY2 = 1<<2 | AVS_CS_YUV | AVS_CS_INTERLEAVED,
114
// AVS_CS_YV12 = 1<<3 Reserved
115
// AVS_CS_I420 = 1<<4 Reserved
116
AVS_CS_RAW32 = 1<<5 | AVS_CS_INTERLEAVED,
117
118
AVS_CS_YV24 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_1, // YVU 4:4:4 planar
119
AVS_CS_YV16 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_2, // YVU 4:2:2 planar
120
AVS_CS_YV12 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_2 | AVS_CS_SUB_WIDTH_2, // YVU 4:2:0 planar
121
AVS_CS_I420 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_UPLANEFIRST | AVS_CS_SUB_HEIGHT_2 | AVS_CS_SUB_WIDTH_2, // YUV 4:2:0 planar
122
AVS_CS_IYUV = AVS_CS_I420,
123
AVS_CS_YV411 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_1 | AVS_CS_SUB_WIDTH_4, // YVU 4:1:1 planar
124
AVS_CS_YUV9 = AVS_CS_PLANAR | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 | AVS_CS_VPLANEFIRST | AVS_CS_SUB_HEIGHT_4 | AVS_CS_SUB_WIDTH_4, // YVU 4:1:0 planar
125
AVS_CS_Y8 = AVS_CS_PLANAR | AVS_CS_INTERLEAVED | AVS_CS_YUV | AVS_CS_SAMPLE_BITS_8 // Y 4:0:0 planar
126
};
127
128
enum {
129
AVS_IT_BFF = 1<<0,
130
AVS_IT_TFF = 1<<1,
131
AVS_IT_FIELDBASED = 1<<2};
132
133
enum {
134
AVS_FILTER_TYPE=1,
135
AVS_FILTER_INPUT_COLORSPACE=2,
136
AVS_FILTER_OUTPUT_TYPE=9,
137
AVS_FILTER_NAME=4,
138
AVS_FILTER_AUTHOR=5,
139
AVS_FILTER_VERSION=6,
140
AVS_FILTER_ARGS=7,
141
AVS_FILTER_ARGS_INFO=8,
142
AVS_FILTER_ARGS_DESCRIPTION=10,
143
AVS_FILTER_DESCRIPTION=11};
144
145
enum { //SUBTYPES
146
AVS_FILTER_TYPE_AUDIO=1,
147
AVS_FILTER_TYPE_VIDEO=2,
148
AVS_FILTER_OUTPUT_TYPE_SAME=3,
149
AVS_FILTER_OUTPUT_TYPE_DIFFERENT=4};
150
151
enum {
152
// New 2.6 explicitly defined cache hints.
153
AVS_CACHE_NOTHING=10, // Do not cache video.
154
AVS_CACHE_WINDOW=11, // Hard protect upto X frames within a range of X from the current frame N.
155
AVS_CACHE_GENERIC=12, // LRU cache upto X frames.
156
AVS_CACHE_FORCE_GENERIC=13, // LRU cache upto X frames, override any previous CACHE_WINDOW.
157
158
AVS_CACHE_GET_POLICY=30, // Get the current policy.
159
AVS_CACHE_GET_WINDOW=31, // Get the current window h_span.
160
AVS_CACHE_GET_RANGE=32, // Get the current generic frame range.
161
162
AVS_CACHE_AUDIO=50, // Explicitly do cache audio, X byte cache.
163
AVS_CACHE_AUDIO_NOTHING=51, // Explicitly do not cache audio.
164
AVS_CACHE_AUDIO_NONE=52, // Audio cache off (auto mode), X byte intial cache.
165
AVS_CACHE_AUDIO_AUTO=53, // Audio cache on (auto mode), X byte intial cache.
166
167
AVS_CACHE_GET_AUDIO_POLICY=70, // Get the current audio policy.
168
AVS_CACHE_GET_AUDIO_SIZE=71, // Get the current audio cache size.
169
170
AVS_CACHE_PREFETCH_FRAME=100, // Queue request to prefetch frame N.
171
AVS_CACHE_PREFETCH_GO=101, // Action video prefetches.
172
173
AVS_CACHE_PREFETCH_AUDIO_BEGIN=120, // Begin queue request transaction to prefetch audio (take critical section).
174
AVS_CACHE_PREFETCH_AUDIO_STARTLO=121, // Set low 32 bits of start.
175
AVS_CACHE_PREFETCH_AUDIO_STARTHI=122, // Set high 32 bits of start.
176
AVS_CACHE_PREFETCH_AUDIO_COUNT=123, // Set low 32 bits of length.
177
AVS_CACHE_PREFETCH_AUDIO_COMMIT=124, // Enqueue request transaction to prefetch audio (release critical section).
178
AVS_CACHE_PREFETCH_AUDIO_GO=125, // Action audio prefetches.
179
180
AVS_CACHE_GETCHILD_CACHE_MODE=200, // Cache ask Child for desired video cache mode.
181
AVS_CACHE_GETCHILD_CACHE_SIZE=201, // Cache ask Child for desired video cache size.
182
AVS_CACHE_GETCHILD_AUDIO_MODE=202, // Cache ask Child for desired audio cache mode.
183
AVS_CACHE_GETCHILD_AUDIO_SIZE=203, // Cache ask Child for desired audio cache size.
184
185
AVS_CACHE_GETCHILD_COST=220, // Cache ask Child for estimated processing cost.
186
AVS_CACHE_COST_ZERO=221, // Child response of zero cost (ptr arithmetic only).
187
AVS_CACHE_COST_UNIT=222, // Child response of unit cost (less than or equal 1 full frame blit).
188
AVS_CACHE_COST_LOW=223, // Child response of light cost. (Fast)
189
AVS_CACHE_COST_MED=224, // Child response of medium cost. (Real time)
190
AVS_CACHE_COST_HI=225, // Child response of heavy cost. (Slow)
191
192
AVS_CACHE_GETCHILD_THREAD_MODE=240, // Cache ask Child for thread safetyness.
193
AVS_CACHE_THREAD_UNSAFE=241, // Only 1 thread allowed for all instances. 2.5 filters default!
194
AVS_CACHE_THREAD_CLASS=242, // Only 1 thread allowed for each instance. 2.6 filters default!
195
AVS_CACHE_THREAD_SAFE=243, // Allow all threads in any instance.
196
AVS_CACHE_THREAD_OWN=244, // Safe but limit to 1 thread, internally threaded.
197
198
AVS_CACHE_GETCHILD_ACCESS_COST=260, // Cache ask Child for preferred access pattern.
199
AVS_CACHE_ACCESS_RAND=261, // Filter is access order agnostic.
200
AVS_CACHE_ACCESS_SEQ0=262, // Filter prefers sequential access (low cost)
201
AVS_CACHE_ACCESS_SEQ1=263, // Filter needs sequential access (high cost)
202
};
203
204
#ifdef BUILDING_AVSCORE
205
struct AVS_ScriptEnvironment {
206
IScriptEnvironment * env;
207
const char * error;
208
AVS_ScriptEnvironment(IScriptEnvironment * e = 0)
209
: env(e), error(0) {}
210
};
211
#endif
212
213
typedef struct AVS_Clip AVS_Clip;
214
typedef struct AVS_ScriptEnvironment AVS_ScriptEnvironment;
215
216
/////////////////////////////////////////////////////////////////////
217
//
218
// AVS_VideoInfo
219
//
220
221
// AVS_VideoInfo is layed out identicly to VideoInfo
222
typedef struct AVS_VideoInfo {
223
int width, height; // width=0 means no video
224
unsigned fps_numerator, fps_denominator;
225
int num_frames;
226
227
int pixel_type;
228
229
int audio_samples_per_second; // 0 means no audio
230
int sample_type;
231
INT64 num_audio_samples;
232
int nchannels;
233
234
// Imagetype properties
235
236
int image_type;
237
} AVS_VideoInfo;
238
239
// useful functions of the above
240
AVSC_INLINE int avs_has_video(const AVS_VideoInfo * p)
241
{ return (p->width!=0); }
242
243
AVSC_INLINE int avs_has_audio(const AVS_VideoInfo * p)
244
{ return (p->audio_samples_per_second!=0); }
245
246
AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo * p)
247
{ return !!(p->pixel_type&AVS_CS_BGR); }
248
249
AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo * p)
250
{ return (p->pixel_type&AVS_CS_BGR24)==AVS_CS_BGR24; } // Clear out additional properties
251
252
AVSC_INLINE int avs_is_rgb32(const AVS_VideoInfo * p)
253
{ return (p->pixel_type & AVS_CS_BGR32) == AVS_CS_BGR32 ; }
254
255
AVSC_INLINE int avs_is_yuv(const AVS_VideoInfo * p)
256
{ return !!(p->pixel_type&AVS_CS_YUV ); }
257
258
AVSC_INLINE int avs_is_yuy2(const AVS_VideoInfo * p)
259
{ return (p->pixel_type & AVS_CS_YUY2) == AVS_CS_YUY2; }
260
261
AVSC_API(int, avs_is_yv24)(const AVS_VideoInfo * p);
262
263
AVSC_API(int, avs_is_yv16)(const AVS_VideoInfo * p);
264
265
AVSC_API(int, avs_is_yv12)(const AVS_VideoInfo * p) ;
266
267
AVSC_API(int, avs_is_yv411)(const AVS_VideoInfo * p);
268
269
AVSC_API(int, avs_is_y8)(const AVS_VideoInfo * p);
270
271
AVSC_INLINE int avs_is_property(const AVS_VideoInfo * p, int property)
272
{ return ((p->image_type & property)==property ); }
273
274
AVSC_INLINE int avs_is_planar(const AVS_VideoInfo * p)
275
{ return !!(p->pixel_type & AVS_CS_PLANAR); }
276
277
AVSC_API(int, avs_is_color_space)(const AVS_VideoInfo * p, int c_space);
278
279
AVSC_INLINE int avs_is_field_based(const AVS_VideoInfo * p)
280
{ return !!(p->image_type & AVS_IT_FIELDBASED); }
281
282
AVSC_INLINE int avs_is_parity_known(const AVS_VideoInfo * p)
283
{ return ((p->image_type & AVS_IT_FIELDBASED)&&(p->image_type & (AVS_IT_BFF | AVS_IT_TFF))); }
284
285
AVSC_INLINE int avs_is_bff(const AVS_VideoInfo * p)
286
{ return !!(p->image_type & AVS_IT_BFF); }
287
288
AVSC_INLINE int avs_is_tff(const AVS_VideoInfo * p)
289
{ return !!(p->image_type & AVS_IT_TFF); }
290
291
AVSC_API(int, avs_get_plane_width_subsampling)(const AVS_VideoInfo * p, int plane);
292
293
AVSC_API(int, avs_get_plane_height_subsampling)(const AVS_VideoInfo * p, int plane);
294
295
296
AVSC_API(int, avs_bits_per_pixel)(const AVS_VideoInfo * p);
297
298
AVSC_API(int, avs_bytes_from_pixels)(const AVS_VideoInfo * p, int pixels);
299
300
AVSC_API(int, avs_row_size)(const AVS_VideoInfo * p, int plane);
301
302
AVSC_API(int, avs_bmp_size)(const AVS_VideoInfo * vi);
303
304
AVSC_INLINE int avs_samples_per_second(const AVS_VideoInfo * p)
305
{ return p->audio_samples_per_second; }
306
307
308
AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo * p)
309
{
310
switch (p->sample_type) {
311
case AVS_SAMPLE_INT8: return sizeof(signed char);
312
case AVS_SAMPLE_INT16: return sizeof(signed short);
313
case AVS_SAMPLE_INT24: return 3;
314
case AVS_SAMPLE_INT32: return sizeof(signed int);
315
case AVS_SAMPLE_FLOAT: return sizeof(float);
316
default: return 0;
317
}
318
}
319
AVSC_INLINE int avs_bytes_per_audio_sample(const AVS_VideoInfo * p)
320
{ return p->nchannels*avs_bytes_per_channel_sample(p);}
321
322
AVSC_INLINE INT64 avs_audio_samples_from_frames(const AVS_VideoInfo * p, INT64 frames)
323
{ return ((INT64)(frames) * p->audio_samples_per_second * p->fps_denominator / p->fps_numerator); }
324
325
AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
326
{ return (int)(samples * (INT64)p->fps_numerator / (INT64)p->fps_denominator / (INT64)p->audio_samples_per_second); }
327
328
AVSC_INLINE INT64 avs_audio_samples_from_bytes(const AVS_VideoInfo * p, INT64 bytes)
329
{ return bytes / avs_bytes_per_audio_sample(p); }
330
331
AVSC_INLINE INT64 avs_bytes_from_audio_samples(const AVS_VideoInfo * p, INT64 samples)
332
{ return samples * avs_bytes_per_audio_sample(p); }
333
334
AVSC_INLINE int avs_audio_channels(const AVS_VideoInfo * p)
335
{ return p->nchannels; }
336
337
AVSC_INLINE int avs_sample_type(const AVS_VideoInfo * p)
338
{ return p->sample_type;}
339
340
// useful mutator
341
AVSC_INLINE void avs_set_property(AVS_VideoInfo * p, int property)
342
{ p->image_type|=property; }
343
344
AVSC_INLINE void avs_clear_property(AVS_VideoInfo * p, int property)
345
{ p->image_type&=~property; }
346
347
AVSC_INLINE void avs_set_field_based(AVS_VideoInfo * p, int isfieldbased)
348
{ if (isfieldbased) p->image_type|=AVS_IT_FIELDBASED; else p->image_type&=~AVS_IT_FIELDBASED; }
349
350
AVSC_INLINE void avs_set_fps(AVS_VideoInfo * p, unsigned numerator, unsigned denominator)
351
{
352
unsigned x=numerator, y=denominator;
353
while (y) { // find gcd
354
unsigned t = x%y; x = y; y = t;
355
}
356
p->fps_numerator = numerator/x;
357
p->fps_denominator = denominator/x;
358
}
359
360
#ifdef AVS_IMPLICIT_FUNCTION_DECLARATION_ERROR
361
AVSC_INLINE int avs_is_same_colorspace(AVS_VideoInfo * x, AVS_VideoInfo * y)
362
{
363
return (x->pixel_type == y->pixel_type)
364
|| (avs_is_yv12(x) && avs_is_yv12(y));
365
}
366
#endif
367
368
/////////////////////////////////////////////////////////////////////
369
//
370
// AVS_VideoFrame
371
//
372
373
// VideoFrameBuffer holds information about a memory block which is used
374
// for video data. For efficiency, instances of this class are not deleted
375
// when the refcount reaches zero; instead they're stored in a linked list
376
// to be reused. The instances are deleted when the corresponding AVS
377
// file is closed.
378
379
// AVS_VideoFrameBuffer is layed out identicly to VideoFrameBuffer
380
// DO NOT USE THIS STRUCTURE DIRECTLY
381
typedef struct AVS_VideoFrameBuffer {
382
BYTE * data;
383
int data_size;
384
// sequence_number is incremented every time the buffer is changed, so
385
// that stale views can tell they're no longer valid.
386
volatile long sequence_number;
387
388
volatile long refcount;
389
} AVS_VideoFrameBuffer;
390
391
// VideoFrame holds a "window" into a VideoFrameBuffer.
392
393
// AVS_VideoFrame is layed out identicly to IVideoFrame
394
// DO NOT USE THIS STRUCTURE DIRECTLY
395
typedef struct AVS_VideoFrame {
396
volatile long refcount;
397
AVS_VideoFrameBuffer * vfb;
398
int offset, pitch, row_size, height, offsetU, offsetV, pitchUV; // U&V offsets are from top of picture.
399
int row_sizeUV, heightUV;
400
} AVS_VideoFrame;
401
402
// Access functions for AVS_VideoFrame
403
AVSC_API(int, avs_get_pitch_p)(const AVS_VideoFrame * p, int plane);
404
405
#ifdef AVS_IMPLICIT_FUNCTION_DECLARATION_ERROR
406
AVSC_INLINE int avs_get_pitch(const AVS_VideoFrame * p) {
407
return avs_get_pitch_p(p, 0);}
408
#endif
409
410
AVSC_API(int, avs_get_row_size_p)(const AVS_VideoFrame * p, int plane);
411
412
AVSC_INLINE int avs_get_row_size(const AVS_VideoFrame * p) {
413
return p->row_size; }
414
415
AVSC_API(int, avs_get_height_p)(const AVS_VideoFrame * p, int plane);
416
417
AVSC_INLINE int avs_get_height(const AVS_VideoFrame * p) {
418
return p->height;}
419
420
AVSC_API(const BYTE *, avs_get_read_ptr_p)(const AVS_VideoFrame * p, int plane);
421
422
#ifdef AVS_IMPLICIT_FUNCTION_DECLARATION_ERROR
423
AVSC_INLINE const BYTE* avs_get_read_ptr(const AVS_VideoFrame * p) {
424
return avs_get_read_ptr_p(p, 0);}
425
#endif
426
427
AVSC_API(int, avs_is_writable)(const AVS_VideoFrame * p);
428
429
AVSC_API(BYTE *, avs_get_write_ptr_p)(const AVS_VideoFrame * p, int plane);
430
431
#ifdef AVS_IMPLICIT_FUNCTION_DECLARATION_ERROR
432
AVSC_INLINE BYTE* avs_get_write_ptr(const AVS_VideoFrame * p) {
433
return avs_get_write_ptr_p(p, 0);}
434
#endif
435
436
AVSC_API(void, avs_release_video_frame)(AVS_VideoFrame *);
437
// makes a shallow copy of a video frame
438
AVSC_API(AVS_VideoFrame *, avs_copy_video_frame)(AVS_VideoFrame *);
439
440
#ifndef AVSC_NO_DECLSPEC
441
AVSC_INLINE void avs_release_frame(AVS_VideoFrame * f)
442
{avs_release_video_frame(f);}
443
AVSC_INLINE AVS_VideoFrame * avs_copy_frame(AVS_VideoFrame * f)
444
{return avs_copy_video_frame(f);}
445
#endif
446
447
/////////////////////////////////////////////////////////////////////
448
//
449
// AVS_Value
450
//
451
452
// Treat AVS_Value as a fat pointer. That is use avs_copy_value
453
// and avs_release_value appropiaty as you would if AVS_Value was
454
// a pointer.
455
456
// To maintain source code compatibility with future versions of the
457
// avisynth_c API don't use the AVS_Value directly. Use the helper
458
// functions below.
459
460
// AVS_Value is layed out identicly to AVSValue
461
typedef struct AVS_Value AVS_Value;
462
struct AVS_Value {
463
short type; // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong
464
// for some function e'rror
465
short array_size;
466
union {
467
void * clip; // do not use directly, use avs_take_clip
468
char boolean;
469
int integer;
470
float floating_pt;
471
const char * string;
472
const AVS_Value * array;
473
} d;
474
};
475
476
// AVS_Value should be initilized with avs_void.
477
// Should also set to avs_void after the value is released
478
// with avs_copy_value. Consider it the equalvent of setting
479
// a pointer to NULL
480
static const AVS_Value avs_void = {'v'};
481
482
AVSC_API(void, avs_copy_value)(AVS_Value * dest, AVS_Value src);
483
AVSC_API(void, avs_release_value)(AVS_Value);
484
485
AVSC_INLINE int avs_defined(AVS_Value v) { return v.type != 'v'; }
486
AVSC_INLINE int avs_is_clip(AVS_Value v) { return v.type == 'c'; }
487
AVSC_INLINE int avs_is_bool(AVS_Value v) { return v.type == 'b'; }
488
AVSC_INLINE int avs_is_int(AVS_Value v) { return v.type == 'i'; }
489
AVSC_INLINE int avs_is_float(AVS_Value v) { return v.type == 'f' || v.type == 'i'; }
490
AVSC_INLINE int avs_is_string(AVS_Value v) { return v.type == 's'; }
491
AVSC_INLINE int avs_is_array(AVS_Value v) { return v.type == 'a'; }
492
AVSC_INLINE int avs_is_error(AVS_Value v) { return v.type == 'e'; }
493
494
AVSC_API(AVS_Clip *, avs_take_clip)(AVS_Value, AVS_ScriptEnvironment *);
495
AVSC_API(void, avs_set_to_clip)(AVS_Value *, AVS_Clip *);
496
497
AVSC_INLINE int avs_as_bool(AVS_Value v)
498
{ return v.d.boolean; }
499
AVSC_INLINE int avs_as_int(AVS_Value v)
500
{ return v.d.integer; }
501
AVSC_INLINE const char * avs_as_string(AVS_Value v)
502
{ return avs_is_error(v) || avs_is_string(v) ? v.d.string : 0; }
503
AVSC_INLINE double avs_as_float(AVS_Value v)
504
{ return avs_is_int(v) ? v.d.integer : v.d.floating_pt; }
505
AVSC_INLINE const char * avs_as_error(AVS_Value v)
506
{ return avs_is_error(v) ? v.d.string : 0; }
507
AVSC_INLINE const AVS_Value * avs_as_array(AVS_Value v)
508
{ return v.d.array; }
509
AVSC_INLINE int avs_array_size(AVS_Value v)
510
{ return avs_is_array(v) ? v.array_size : 1; }
511
AVSC_INLINE AVS_Value avs_array_elt(AVS_Value v, int index)
512
{ return avs_is_array(v) ? v.d.array[index] : v; }
513
514
// only use these functions on an AVS_Value that does not already have
515
// an active value. Remember, treat AVS_Value as a fat pointer.
516
AVSC_INLINE AVS_Value avs_new_value_bool(int v0)
517
{ AVS_Value v; v.type = 'b'; v.d.boolean = v0 == 0 ? 0 : 1; return v; }
518
AVSC_INLINE AVS_Value avs_new_value_int(int v0)
519
{ AVS_Value v; v.type = 'i'; v.d.integer = v0; return v; }
520
AVSC_INLINE AVS_Value avs_new_value_string(const char * v0)
521
{ AVS_Value v; v.type = 's'; v.d.string = v0; return v; }
522
AVSC_INLINE AVS_Value avs_new_value_float(float v0)
523
{ AVS_Value v; v.type = 'f'; v.d.floating_pt = v0; return v;}
524
AVSC_INLINE AVS_Value avs_new_value_error(const char * v0)
525
{ AVS_Value v; v.type = 'e'; v.d.string = v0; return v; }
526
#ifndef AVSC_NO_DECLSPEC
527
AVSC_INLINE AVS_Value avs_new_value_clip(AVS_Clip * v0)
528
{ AVS_Value v; avs_set_to_clip(&v, v0); return v; }
529
#endif
530
AVSC_INLINE AVS_Value avs_new_value_array(AVS_Value * v0, int size)
531
{ AVS_Value v; v.type = 'a'; v.d.array = v0; v.array_size = size; return v; }
532
533
/////////////////////////////////////////////////////////////////////
534
//
535
// AVS_Clip
536
//
537
538
AVSC_API(void, avs_release_clip)(AVS_Clip *);
539
AVSC_API(AVS_Clip *, avs_copy_clip)(AVS_Clip *);
540
541
AVSC_API(const char *, avs_clip_get_error)(AVS_Clip *); // return 0 if no error
542
543
AVSC_API(const AVS_VideoInfo *, avs_get_video_info)(AVS_Clip *);
544
545
AVSC_API(int, avs_get_version)(AVS_Clip *);
546
547
AVSC_API(AVS_VideoFrame *, avs_get_frame)(AVS_Clip *, int n);
548
// The returned video frame must be released with avs_release_video_frame
549
550
AVSC_API(int, avs_get_parity)(AVS_Clip *, int n);
551
// return field parity if field_based, else parity of first field in frame
552
553
AVSC_API(int, avs_get_audio)(AVS_Clip *, void * buf,
554
INT64 start, INT64 count);
555
// start and count are in samples
556
557
AVSC_API(int, avs_set_cache_hints)(AVS_Clip *,
558
int cachehints, int frame_range);
559
560
// This is the callback type used by avs_add_function
561
typedef AVS_Value (AVSC_CC * AVS_ApplyFunc)
562
(AVS_ScriptEnvironment *, AVS_Value args, void * user_data);
563
564
typedef struct AVS_FilterInfo AVS_FilterInfo;
565
struct AVS_FilterInfo
566
{
567
// these members should not be modified outside of the AVS_ApplyFunc callback
568
AVS_Clip * child;
569
AVS_VideoInfo vi;
570
AVS_ScriptEnvironment * env;
571
AVS_VideoFrame * (AVSC_CC * get_frame)(AVS_FilterInfo *, int n);
572
int (AVSC_CC * get_parity)(AVS_FilterInfo *, int n);
573
int (AVSC_CC * get_audio)(AVS_FilterInfo *, void * buf,
574
INT64 start, INT64 count);
575
int (AVSC_CC * set_cache_hints)(AVS_FilterInfo *, int cachehints,
576
int frame_range);
577
void (AVSC_CC * free_filter)(AVS_FilterInfo *);
578
579
// Should be set when ever there is an error to report.
580
// It is cleared before any of the above methods are called
581
const char * error;
582
// this is to store whatever and may be modified at will
583
void * user_data;
584
};
585
586
// Create a new filter
587
// fi is set to point to the AVS_FilterInfo so that you can
588
// modify it once it is initilized.
589
// store_child should generally be set to true. If it is not
590
// set than ALL methods (the function pointers) must be defined
591
// If it is set than you do not need to worry about freeing the child
592
// clip.
593
AVSC_API(AVS_Clip *, avs_new_c_filter)(AVS_ScriptEnvironment * e,
594
AVS_FilterInfo * * fi,
595
AVS_Value child, int store_child);
596
597
/////////////////////////////////////////////////////////////////////
598
//
599
// AVS_ScriptEnvironment
600
//
601
602
// For GetCPUFlags. These are backwards-compatible with those in VirtualDub.
603
enum {
604
/* slowest CPU to support extension */
605
AVS_CPU_FORCE = 0x01, // N/A
606
AVS_CPU_FPU = 0x02, // 386/486DX
607
AVS_CPU_MMX = 0x04, // P55C, K6, PII
608
AVS_CPU_INTEGER_SSE = 0x08, // PIII, Athlon
609
AVS_CPU_SSE = 0x10, // PIII, Athlon XP/MP
610
AVS_CPU_SSE2 = 0x20, // PIV, Hammer
611
AVS_CPU_3DNOW = 0x40, // K6-2
612
AVS_CPU_3DNOW_EXT = 0x80, // Athlon
613
AVS_CPU_X86_64 = 0xA0, // Hammer (note: equiv. to 3DNow + SSE2,
614
// which only Hammer will have anyway)
615
AVS_CPUF_SSE3 = 0x100, // PIV+, K8 Venice
616
AVS_CPUF_SSSE3 = 0x200, // Core 2
617
AVS_CPUF_SSE4 = 0x400, // Penryn, Wolfdale, Yorkfield
618
AVS_CPUF_SSE4_1 = 0x400,
619
//AVS_CPUF_AVX = 0x800, // Sandy Bridge, Bulldozer
620
AVS_CPUF_SSE4_2 = 0x1000, // Nehalem
621
//AVS_CPUF_AVX2 = 0x2000, // Haswell
622
//AVS_CPUF_AVX512 = 0x4000, // Knights Landing
623
};
624
625
626
AVSC_API(const char *, avs_get_error)(AVS_ScriptEnvironment *); // return 0 if no error
627
628
AVSC_API(int, avs_get_cpu_flags)(AVS_ScriptEnvironment *);
629
AVSC_API(int, avs_check_version)(AVS_ScriptEnvironment *, int version);
630
631
AVSC_API(char *, avs_save_string)(AVS_ScriptEnvironment *, const char* s, int length);
632
AVSC_API(char *, avs_sprintf)(AVS_ScriptEnvironment *, const char * fmt, ...);
633
634
AVSC_API(char *, avs_vsprintf)(AVS_ScriptEnvironment *, const char * fmt, void* val);
635
// note: val is really a va_list; I hope everyone typedefs va_list to a pointer
636
637
AVSC_API(int, avs_add_function)(AVS_ScriptEnvironment *,
638
const char * name, const char * params,
639
AVS_ApplyFunc apply, void * user_data);
640
641
AVSC_API(int, avs_function_exists)(AVS_ScriptEnvironment *, const char * name);
642
643
AVSC_API(AVS_Value, avs_invoke)(AVS_ScriptEnvironment *, const char * name,
644
AVS_Value args, const char** arg_names);
645
// The returned value must be be released with avs_release_value
646
647
AVSC_API(AVS_Value, avs_get_var)(AVS_ScriptEnvironment *, const char* name);
648
// The returned value must be be released with avs_release_value
649
650
AVSC_API(int, avs_set_var)(AVS_ScriptEnvironment *, const char* name, AVS_Value val);
651
652
AVSC_API(int, avs_set_global_var)(AVS_ScriptEnvironment *, const char* name, const AVS_Value val);
653
654
//void avs_push_context(AVS_ScriptEnvironment *, int level=0);
655
//void avs_pop_context(AVS_ScriptEnvironment *);
656
657
AVSC_API(AVS_VideoFrame *, avs_new_video_frame_a)(AVS_ScriptEnvironment *,
658
const AVS_VideoInfo * vi, int align);
659
// align should be at least 16
660
661
#ifndef AVSC_NO_DECLSPEC
662
AVSC_INLINE
663
AVS_VideoFrame * avs_new_video_frame(AVS_ScriptEnvironment * env,
664
const AVS_VideoInfo * vi)
665
{return avs_new_video_frame_a(env,vi,FRAME_ALIGN);}
666
667
AVSC_INLINE
668
AVS_VideoFrame * avs_new_frame(AVS_ScriptEnvironment * env,
669
const AVS_VideoInfo * vi)
670
{return avs_new_video_frame_a(env,vi,FRAME_ALIGN);}
671
#endif
672
673
674
AVSC_API(int, avs_make_writable)(AVS_ScriptEnvironment *, AVS_VideoFrame * * pvf);
675
676
AVSC_API(void, avs_bit_blt)(AVS_ScriptEnvironment *, BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height);
677
678
typedef void (AVSC_CC *AVS_ShutdownFunc)(void* user_data, AVS_ScriptEnvironment * env);
679
AVSC_API(void, avs_at_exit)(AVS_ScriptEnvironment *, AVS_ShutdownFunc function, void * user_data);
680
681
AVSC_API(AVS_VideoFrame *, avs_subframe)(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height);
682
// The returned video frame must be be released
683
684
AVSC_API(int, avs_set_memory_max)(AVS_ScriptEnvironment *, int mem);
685
686
AVSC_API(int, avs_set_working_dir)(AVS_ScriptEnvironment *, const char * newdir);
687
688
// avisynth.dll exports this; it's a way to use it as a library, without
689
// writing an AVS script or without going through AVIFile.
690
AVSC_API(AVS_ScriptEnvironment *, avs_create_script_environment)(int version);
691
692
// this symbol is the entry point for the plugin and must
693
// be defined
694
AVSC_EXPORT
695
const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment* env);
696
697
698
AVSC_API(void, avs_delete_script_environment)(AVS_ScriptEnvironment *);
699
700
701
AVSC_API(AVS_VideoFrame *, avs_subframe_planar)(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height, int rel_offsetU, int rel_offsetV, int new_pitchUV);
702
// The returned video frame must be be released
703
704
#ifdef AVSC_NO_DECLSPEC
705
// use LoadLibrary and related functions to dynamically load Avisynth instead of declspec(dllimport)
706
/*
707
The following functions needs to have been declared, probably from windows.h
708
709
void* malloc(size_t)
710
void free(void*);
711
712
HMODULE LoadLibrary(const char*);
713
void* GetProcAddress(HMODULE, const char*);
714
FreeLibrary(HMODULE);
715
*/
716
717
718
typedef struct AVS_Library AVS_Library;
719
720
#define AVSC_DECLARE_FUNC(name) name##_func name
721
722
struct AVS_Library {
723
HMODULE handle;
724
725
AVSC_DECLARE_FUNC(avs_add_function);
726
AVSC_DECLARE_FUNC(avs_at_exit);
727
AVSC_DECLARE_FUNC(avs_bit_blt);
728
AVSC_DECLARE_FUNC(avs_check_version);
729
AVSC_DECLARE_FUNC(avs_clip_get_error);
730
AVSC_DECLARE_FUNC(avs_copy_clip);
731
AVSC_DECLARE_FUNC(avs_copy_value);
732
AVSC_DECLARE_FUNC(avs_copy_video_frame);
733
AVSC_DECLARE_FUNC(avs_create_script_environment);
734
AVSC_DECLARE_FUNC(avs_delete_script_environment);
735
AVSC_DECLARE_FUNC(avs_function_exists);
736
AVSC_DECLARE_FUNC(avs_get_audio);
737
AVSC_DECLARE_FUNC(avs_get_cpu_flags);
738
AVSC_DECLARE_FUNC(avs_get_frame);
739
AVSC_DECLARE_FUNC(avs_get_parity);
740
AVSC_DECLARE_FUNC(avs_get_var);
741
AVSC_DECLARE_FUNC(avs_get_version);
742
AVSC_DECLARE_FUNC(avs_get_video_info);
743
AVSC_DECLARE_FUNC(avs_invoke);
744
AVSC_DECLARE_FUNC(avs_make_writable);
745
AVSC_DECLARE_FUNC(avs_new_c_filter);
746
AVSC_DECLARE_FUNC(avs_new_video_frame_a);
747
AVSC_DECLARE_FUNC(avs_release_clip);
748
AVSC_DECLARE_FUNC(avs_release_value);
749
AVSC_DECLARE_FUNC(avs_release_video_frame);
750
AVSC_DECLARE_FUNC(avs_save_string);
751
AVSC_DECLARE_FUNC(avs_set_cache_hints);
752
AVSC_DECLARE_FUNC(avs_set_global_var);
753
AVSC_DECLARE_FUNC(avs_set_memory_max);
754
AVSC_DECLARE_FUNC(avs_set_to_clip);
755
AVSC_DECLARE_FUNC(avs_set_var);
756
AVSC_DECLARE_FUNC(avs_set_working_dir);
757
AVSC_DECLARE_FUNC(avs_sprintf);
758
AVSC_DECLARE_FUNC(avs_subframe);
759
AVSC_DECLARE_FUNC(avs_subframe_planar);
760
AVSC_DECLARE_FUNC(avs_take_clip);
761
AVSC_DECLARE_FUNC(avs_vsprintf);
762
763
AVSC_DECLARE_FUNC(avs_get_error);
764
AVSC_DECLARE_FUNC(avs_is_yv24);
765
AVSC_DECLARE_FUNC(avs_is_yv16);
766
AVSC_DECLARE_FUNC(avs_is_yv12);
767
AVSC_DECLARE_FUNC(avs_is_yv411);
768
AVSC_DECLARE_FUNC(avs_is_y8);
769
AVSC_DECLARE_FUNC(avs_is_color_space);
770
771
AVSC_DECLARE_FUNC(avs_get_plane_width_subsampling);
772
AVSC_DECLARE_FUNC(avs_get_plane_height_subsampling);
773
AVSC_DECLARE_FUNC(avs_bits_per_pixel);
774
AVSC_DECLARE_FUNC(avs_bytes_from_pixels);
775
AVSC_DECLARE_FUNC(avs_row_size);
776
AVSC_DECLARE_FUNC(avs_bmp_size);
777
AVSC_DECLARE_FUNC(avs_get_pitch_p);
778
AVSC_DECLARE_FUNC(avs_get_row_size_p);
779
AVSC_DECLARE_FUNC(avs_get_height_p);
780
AVSC_DECLARE_FUNC(avs_get_read_ptr_p);
781
AVSC_DECLARE_FUNC(avs_is_writable);
782
AVSC_DECLARE_FUNC(avs_get_write_ptr_p);
783
};
784
785
#undef AVSC_DECLARE_FUNC
786
787
788
AVSC_INLINE AVS_Library * avs_load_library() {
789
AVS_Library *library = (AVS_Library *)malloc(sizeof(AVS_Library));
790
if (library == NULL)
791
return NULL;
792
library->handle = LoadLibrary("avisynth");
793
if (library->handle == NULL)
794
goto fail;
795
796
#define __AVSC_STRINGIFY(x) #x
797
#define AVSC_STRINGIFY(x) __AVSC_STRINGIFY(x)
798
#define AVSC_LOAD_FUNC(name) {\
799
library->name = (name##_func) GetProcAddress(library->handle, AVSC_STRINGIFY(name));\
800
if (library->name == NULL)\
801
goto fail;\
802
}
803
804
AVSC_LOAD_FUNC(avs_add_function);
805
AVSC_LOAD_FUNC(avs_at_exit);
806
AVSC_LOAD_FUNC(avs_bit_blt);
807
AVSC_LOAD_FUNC(avs_check_version);
808
AVSC_LOAD_FUNC(avs_clip_get_error);
809
AVSC_LOAD_FUNC(avs_copy_clip);
810
AVSC_LOAD_FUNC(avs_copy_value);
811
AVSC_LOAD_FUNC(avs_copy_video_frame);
812
AVSC_LOAD_FUNC(avs_create_script_environment);
813
AVSC_LOAD_FUNC(avs_delete_script_environment);
814
AVSC_LOAD_FUNC(avs_function_exists);
815
AVSC_LOAD_FUNC(avs_get_audio);
816
AVSC_LOAD_FUNC(avs_get_cpu_flags);
817
AVSC_LOAD_FUNC(avs_get_frame);
818
AVSC_LOAD_FUNC(avs_get_parity);
819
AVSC_LOAD_FUNC(avs_get_var);
820
AVSC_LOAD_FUNC(avs_get_version);
821
AVSC_LOAD_FUNC(avs_get_video_info);
822
AVSC_LOAD_FUNC(avs_invoke);
823
AVSC_LOAD_FUNC(avs_make_writable);
824
AVSC_LOAD_FUNC(avs_new_c_filter);
825
AVSC_LOAD_FUNC(avs_new_video_frame_a);
826
AVSC_LOAD_FUNC(avs_release_clip);
827
AVSC_LOAD_FUNC(avs_release_value);
828
AVSC_LOAD_FUNC(avs_release_video_frame);
829
AVSC_LOAD_FUNC(avs_save_string);
830
AVSC_LOAD_FUNC(avs_set_cache_hints);
831
AVSC_LOAD_FUNC(avs_set_global_var);
832
AVSC_LOAD_FUNC(avs_set_memory_max);
833
AVSC_LOAD_FUNC(avs_set_to_clip);
834
AVSC_LOAD_FUNC(avs_set_var);
835
AVSC_LOAD_FUNC(avs_set_working_dir);
836
AVSC_LOAD_FUNC(avs_sprintf);
837
AVSC_LOAD_FUNC(avs_subframe);
838
AVSC_LOAD_FUNC(avs_subframe_planar);
839
AVSC_LOAD_FUNC(avs_take_clip);
840
AVSC_LOAD_FUNC(avs_vsprintf);
841
842
AVSC_LOAD_FUNC(avs_get_error);
843
AVSC_LOAD_FUNC(avs_is_yv24);
844
AVSC_LOAD_FUNC(avs_is_yv16);
845
AVSC_LOAD_FUNC(avs_is_yv12);
846
AVSC_LOAD_FUNC(avs_is_yv411);
847
AVSC_LOAD_FUNC(avs_is_y8);
848
AVSC_LOAD_FUNC(avs_is_color_space);
849
850
AVSC_LOAD_FUNC(avs_get_plane_width_subsampling);
851
AVSC_LOAD_FUNC(avs_get_plane_height_subsampling);
852
AVSC_LOAD_FUNC(avs_bits_per_pixel);
853
AVSC_LOAD_FUNC(avs_bytes_from_pixels);
854
AVSC_LOAD_FUNC(avs_row_size);
855
AVSC_LOAD_FUNC(avs_bmp_size);
856
AVSC_LOAD_FUNC(avs_get_pitch_p);
857
AVSC_LOAD_FUNC(avs_get_row_size_p);
858
AVSC_LOAD_FUNC(avs_get_height_p);
859
AVSC_LOAD_FUNC(avs_get_read_ptr_p);
860
AVSC_LOAD_FUNC(avs_is_writable);
861
AVSC_LOAD_FUNC(avs_get_write_ptr_p);
862
863
#undef __AVSC_STRINGIFY
864
#undef AVSC_STRINGIFY
865
#undef AVSC_LOAD_FUNC
866
867
return library;
868
869
fail:
870
free(library);
871
return NULL;
872
}
873
874
AVSC_INLINE void avs_free_library(AVS_Library *library) {
875
if (library == NULL)
876
return;
877
FreeLibrary(library->handle);
878
free(library);
879
}
880
#endif
881
882
#endif
883
884