]> git.sesse.net Git - x264/blob - extras/avisynth_c.h
Add getopt_long to the included getopt.c
[x264] / extras / avisynth_c.h
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., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
17 // http://www.gnu.org/copyleft/gpl.html .
18 //
19 // As a special exception, I give you permission to link to the
20 // Avisynth C interface with independent modules that communicate with
21 // the Avisynth C interface solely through the interfaces defined in
22 // avisynth_c.h, regardless of the license terms of these independent
23 // modules, and to copy and distribute the resulting combined work
24 // under terms of your choice, provided that every copy of the
25 // combined work is accompanied by a complete copy of the source code
26 // of the Avisynth C interface and Avisynth itself (with the version
27 // used to produce the combined work), being distributed under the
28 // terms of the GNU General Public License plus this exception.  An
29 // independent module is a module which is not derived from or based
30 // on Avisynth C Interface, such as 3rd-party filters, import and
31 // export plugins, or graphical user interfaces.
32
33 #ifndef __AVISYNTH_C__
34 #define __AVISYNTH_C__
35
36 #ifdef __cplusplus
37 #  define EXTERN_C extern "C"
38 #else
39 #  define EXTERN_C
40 #endif
41
42 #define AVSC_USE_STDCALL 1
43
44 #ifndef AVSC_USE_STDCALL
45 #  define AVSC_CC __cdecl
46 #else
47 #  define AVSC_CC __stdcall
48 #endif
49
50 #define AVSC_EXPORT EXTERN_C __declspec(dllexport)
51 #define AVSC_INLINE static __inline
52 #ifdef AVISYNTH_C_EXPORTS
53 #  define AVSC_API(ret) EXTERN_C __declspec(dllexport) ret AVSC_CC
54 #else
55 #  define AVSC_API(ret) EXTERN_C __declspec(dllimport) ret AVSC_CC
56 #endif
57
58 typedef unsigned char BYTE;
59 #ifdef __GNUC__
60 typedef long long int INT64;
61 #else
62 typedef __int64 INT64;
63 #endif
64
65
66 /////////////////////////////////////////////////////////////////////
67 //
68 // Constants
69 //
70
71 #ifndef __AVISYNTH_H__
72 enum { AVISYNTH_INTERFACE_VERSION = 2 };
73 #endif
74
75 enum {AVS_SAMPLE_INT8  = 1<<0,
76       AVS_SAMPLE_INT16 = 1<<1, 
77       AVS_SAMPLE_INT24 = 1<<2,
78       AVS_SAMPLE_INT32 = 1<<3,
79       AVS_SAMPLE_FLOAT = 1<<4};
80
81 enum {AVS_PLANAR_Y=1<<0,
82       AVS_PLANAR_U=1<<1,
83       AVS_PLANAR_V=1<<2,
84       AVS_PLANAR_ALIGNED=1<<3,
85       AVS_PLANAR_Y_ALIGNED=AVS_PLANAR_Y|AVS_PLANAR_ALIGNED,
86       AVS_PLANAR_U_ALIGNED=AVS_PLANAR_U|AVS_PLANAR_ALIGNED,
87       AVS_PLANAR_V_ALIGNED=AVS_PLANAR_V|AVS_PLANAR_ALIGNED};
88
89   // Colorspace properties.
90 enum {AVS_CS_BGR = 1<<28,  
91       AVS_CS_YUV = 1<<29,
92       AVS_CS_INTERLEAVED = 1<<30,
93       AVS_CS_PLANAR = 1<<31};
94
95   // Specific colorformats
96 enum {
97   AVS_CS_UNKNOWN = 0,
98   AVS_CS_BGR24 = 1<<0 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
99   AVS_CS_BGR32 = 1<<1 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
100   AVS_CS_YUY2 = 1<<2 | AVS_CS_YUV | AVS_CS_INTERLEAVED,
101   AVS_CS_YV12 = 1<<3 | AVS_CS_YUV | AVS_CS_PLANAR,  // y-v-u, planar
102   AVS_CS_I420 = 1<<4 | AVS_CS_YUV | AVS_CS_PLANAR,  // y-u-v, planar
103   AVS_CS_IYUV = 1<<4 | AVS_CS_YUV | AVS_CS_PLANAR  // same as above
104 };
105
106 enum {
107   AVS_IT_BFF = 1<<0,
108   AVS_IT_TFF = 1<<1,
109   AVS_IT_FIELDBASED = 1<<2};
110
111 enum {
112   AVS_FILTER_TYPE=1,
113   AVS_FILTER_INPUT_COLORSPACE=2,
114   AVS_FILTER_OUTPUT_TYPE=9,
115   AVS_FILTER_NAME=4,
116   AVS_FILTER_AUTHOR=5,
117   AVS_FILTER_VERSION=6,
118   AVS_FILTER_ARGS=7,
119   AVS_FILTER_ARGS_INFO=8,
120   AVS_FILTER_ARGS_DESCRIPTION=10,
121   AVS_FILTER_DESCRIPTION=11};
122
123 enum {  //SUBTYPES
124   AVS_FILTER_TYPE_AUDIO=1,
125   AVS_FILTER_TYPE_VIDEO=2,
126   AVS_FILTER_OUTPUT_TYPE_SAME=3,
127   AVS_FILTER_OUTPUT_TYPE_DIFFERENT=4};
128
129 enum {
130   AVS_CACHE_NOTHING=0,
131   AVS_CACHE_RANGE=1 };
132
133 #define AVS_FRAME_ALIGN 16 
134
135 typedef struct AVS_Clip AVS_Clip;
136 typedef struct AVS_ScriptEnvironment AVS_ScriptEnvironment;
137
138 /////////////////////////////////////////////////////////////////////
139 //
140 // AVS_VideoInfo
141 //
142
143 // AVS_VideoInfo is layed out identicly to VideoInfo
144 typedef struct AVS_VideoInfo {
145   int width, height;    // width=0 means no video
146   unsigned fps_numerator, fps_denominator;
147   int num_frames;
148
149   int pixel_type;
150   
151   int audio_samples_per_second;   // 0 means no audio
152   int sample_type;
153   INT64 num_audio_samples;
154   int nchannels;
155
156   // Imagetype properties
157
158   int image_type;
159 } AVS_VideoInfo;
160
161 // useful functions of the above
162 AVSC_INLINE int avs_has_video(const AVS_VideoInfo * p) 
163         { return (p->width!=0); }
164
165 AVSC_INLINE int avs_has_audio(const AVS_VideoInfo * p) 
166         { return (p->audio_samples_per_second!=0); }
167
168 AVSC_INLINE int avs_is_rgb(const AVS_VideoInfo * p) 
169         { return !!(p->pixel_type&AVS_CS_BGR); }
170
171 AVSC_INLINE int avs_is_rgb24(const AVS_VideoInfo * p) 
172         { return (p->pixel_type&AVS_CS_BGR24)==AVS_CS_BGR24; } // Clear out additional properties
173
174 AVSC_INLINE int avs_is_rgb32(const AVS_VideoInfo * p) 
175         { return (p->pixel_type & AVS_CS_BGR32) == AVS_CS_BGR32 ; }
176
177 AVSC_INLINE int avs_is_yuv(const AVS_VideoInfo * p) 
178         { return !!(p->pixel_type&AVS_CS_YUV ); }
179
180 AVSC_INLINE int avs_is_yuy2(const AVS_VideoInfo * p) 
181         { return (p->pixel_type & AVS_CS_YUY2) == AVS_CS_YUY2; }  
182
183 AVSC_INLINE int avs_is_yv12(const AVS_VideoInfo * p) 
184         { return ((p->pixel_type & AVS_CS_YV12) == AVS_CS_YV12)||((p->pixel_type & AVS_CS_I420) == AVS_CS_I420); }
185
186 AVSC_INLINE int avs_is_color_space(const AVS_VideoInfo * p, int c_space) 
187         { return ((p->pixel_type & c_space) == c_space); }
188
189 AVSC_INLINE int avs_is_property(const AVS_VideoInfo * p, int property) 
190         { return ((p->pixel_type & property)==property ); }
191
192 AVSC_INLINE int avs_is_planar(const AVS_VideoInfo * p) 
193         { return !!(p->pixel_type & AVS_CS_PLANAR); }
194         
195 AVSC_INLINE int avs_is_field_based(const AVS_VideoInfo * p) 
196         { return !!(p->image_type & AVS_IT_FIELDBASED); }
197
198 AVSC_INLINE int avs_is_parity_known(const AVS_VideoInfo * p) 
199         { return ((p->image_type & AVS_IT_FIELDBASED)&&(p->image_type & (AVS_IT_BFF | AVS_IT_TFF))); }
200
201 AVSC_INLINE int avs_is_bff(const AVS_VideoInfo * p) 
202         { return !!(p->image_type & AVS_IT_BFF); }
203
204 AVSC_INLINE int avs_is_tff(const AVS_VideoInfo * p) 
205         { return !!(p->image_type & AVS_IT_TFF); }
206
207 AVSC_INLINE int avs_bits_per_pixel(const AVS_VideoInfo * p) 
208
209   switch (p->pixel_type) {
210       case AVS_CS_BGR24: return 24;
211       case AVS_CS_BGR32: return 32;
212       case AVS_CS_YUY2:  return 16;
213       case AVS_CS_YV12:
214       case AVS_CS_I420:  return 12;
215       default:           return 0;
216     }
217 }
218 AVSC_INLINE int avs_bytes_from_pixels(const AVS_VideoInfo * p, int pixels) 
219         { return pixels * (avs_bits_per_pixel(p)>>3); }   // Will work on planar images, but will return only luma planes
220
221 AVSC_INLINE int avs_row_size(const AVS_VideoInfo * p) 
222         { return avs_bytes_from_pixels(p,p->width); }  // Also only returns first plane on planar images
223
224 AVSC_INLINE int avs_bmp_size(const AVS_VideoInfo * vi)                
225         { if (avs_is_planar(vi)) {int p = vi->height * ((avs_row_size(vi)+3) & ~3); p+=p>>1; return p;  } return vi->height * ((avs_row_size(vi)+3) & ~3); }
226
227 AVSC_INLINE int avs_samples_per_second(const AVS_VideoInfo * p) 
228         { return p->audio_samples_per_second; }
229
230
231 AVSC_INLINE int avs_bytes_per_channel_sample(const AVS_VideoInfo * p) 
232 {
233     switch (p->sample_type) {
234       case AVS_SAMPLE_INT8:  return sizeof(signed char);
235       case AVS_SAMPLE_INT16: return sizeof(signed short);
236       case AVS_SAMPLE_INT24: return 3;
237       case AVS_SAMPLE_INT32: return sizeof(signed int);
238       case AVS_SAMPLE_FLOAT: return sizeof(float);
239       default: return 0;
240     }
241 }
242 AVSC_INLINE int avs_bytes_per_audio_sample(const AVS_VideoInfo * p)   
243         { return p->nchannels*avs_bytes_per_channel_sample(p);}
244
245 AVSC_INLINE INT64 avs_audio_samples_from_frames(const AVS_VideoInfo * p, INT64 frames) 
246         { return ((INT64)(frames) * p->audio_samples_per_second * p->fps_denominator / p->fps_numerator); }
247
248 AVSC_INLINE int avs_frames_from_audio_samples(const AVS_VideoInfo * p, INT64 samples) 
249         { return (int)(samples * (INT64)p->fps_numerator / (INT64)p->fps_denominator / (INT64)p->audio_samples_per_second); }
250
251 AVSC_INLINE INT64 avs_audio_samples_from_bytes(const AVS_VideoInfo * p, INT64 bytes) 
252         { return bytes / avs_bytes_per_audio_sample(p); }
253
254 AVSC_INLINE INT64 avs_bytes_from_audio_samples(const AVS_VideoInfo * p, INT64 samples) 
255         { return samples * avs_bytes_per_audio_sample(p); }
256
257 AVSC_INLINE int avs_audio_channels(const AVS_VideoInfo * p) 
258         { return p->nchannels; }
259
260 AVSC_INLINE int avs_sample_type(const AVS_VideoInfo * p)
261         { return p->sample_type;}
262
263 // useful mutator
264 AVSC_INLINE void avs_set_property(AVS_VideoInfo * p, int property)  
265         { p->image_type|=property; }
266
267 AVSC_INLINE void avs_clear_property(AVS_VideoInfo * p, int property)  
268         { p->image_type&=~property; }
269
270 AVSC_INLINE void avs_set_field_based(AVS_VideoInfo * p, int isfieldbased)  
271         { if (isfieldbased) p->image_type|=AVS_IT_FIELDBASED; else p->image_type&=~AVS_IT_FIELDBASED; }
272
273 AVSC_INLINE void avs_set_fps(AVS_VideoInfo * p, unsigned numerator, unsigned denominator) 
274 {
275     unsigned x=numerator, y=denominator;
276     while (y) {   // find gcd
277       unsigned t = x%y; x = y; y = t;
278     }
279     p->fps_numerator = numerator/x;
280     p->fps_denominator = denominator/x;
281 }
282
283 AVSC_INLINE int avs_is_same_colorspace(AVS_VideoInfo * x, AVS_VideoInfo * y)
284 {
285         return (x->pixel_type == y->pixel_type)
286                 || (avs_is_yv12(x) && avs_is_yv12(y));
287 }
288
289 /////////////////////////////////////////////////////////////////////
290 //
291 // AVS_VideoFrame
292 //
293
294 // VideoFrameBuffer holds information about a memory block which is used
295 // for video data.  For efficiency, instances of this class are not deleted
296 // when the refcount reaches zero; instead they're stored in a linked list
297 // to be reused.  The instances are deleted when the corresponding AVS
298 // file is closed.
299
300 // AVS_VideoFrameBuffer is layed out identicly to VideoFrameBuffer
301 // DO NOT USE THIS STRUCTURE DIRECTLY
302 typedef struct AVS_VideoFrameBuffer {
303   BYTE * data;
304   int data_size;
305   // sequence_number is incremented every time the buffer is changed, so
306   // that stale views can tell they're no longer valid.
307   long sequence_number;
308
309   long refcount;
310 } AVS_VideoFrameBuffer;
311
312 // VideoFrame holds a "window" into a VideoFrameBuffer.
313
314 // AVS_VideoFrame is layed out identicly to IVideoFrame
315 // DO NOT USE THIS STRUCTURE DIRECTLY
316 typedef struct AVS_VideoFrame {
317   int refcount;
318   AVS_VideoFrameBuffer * vfb;
319   int offset, pitch, row_size, height, offsetU, offsetV, pitchUV;  // U&V offsets are from top of picture.
320 } AVS_VideoFrame;
321
322 // Access functions for AVS_VideoFrame
323 AVSC_INLINE int avs_get_pitch(const AVS_VideoFrame * p) {
324         return p->pitch;}
325
326 AVSC_INLINE int avs_get_pitch_p(const AVS_VideoFrame * p, int plane) { 
327   switch (plane) {
328   case AVS_PLANAR_U: case AVS_PLANAR_V: return p->pitchUV;}
329   return p->pitch;}
330
331 AVSC_INLINE int avs_get_row_size(const AVS_VideoFrame * p) {
332         return p->row_size; }
333
334 AVSC_INLINE int avs_get_row_size_p(const AVS_VideoFrame * p, int plane) { 
335         int r;
336     switch (plane) {
337     case AVS_PLANAR_U: case AVS_PLANAR_V: 
338                 if (p->pitchUV) return p->row_size>>1; 
339                 else            return 0;
340     case AVS_PLANAR_U_ALIGNED: case AVS_PLANAR_V_ALIGNED: 
341                 if (p->pitchUV) { 
342                         int r = ((p->row_size+AVS_FRAME_ALIGN-1)&(~(AVS_FRAME_ALIGN-1)) )>>1; // Aligned rowsize
343                         if (r < p->pitchUV) 
344                                 return r; 
345                         return p->row_size>>1; 
346                 } else return 0;
347     case AVS_PLANAR_Y_ALIGNED:
348                 r = (p->row_size+AVS_FRAME_ALIGN-1)&(~(AVS_FRAME_ALIGN-1)); // Aligned rowsize
349                 if (r <= p->pitch) 
350                         return r; 
351                 return p->row_size;
352     }
353     return p->row_size;
354 }
355
356 AVSC_INLINE int avs_get_height(const AVS_VideoFrame * p) {
357         return p->height;}
358
359 AVSC_INLINE int avs_get_height_p(const AVS_VideoFrame * p, int plane) {
360         switch (plane) {
361                 case AVS_PLANAR_U: case AVS_PLANAR_V: 
362                         if (p->pitchUV) return p->height>>1;
363                         return 0;
364         }
365         return p->height;}
366
367 AVSC_INLINE const BYTE* avs_get_read_ptr(const AVS_VideoFrame * p) {
368         return p->vfb->data + p->offset;}
369
370 AVSC_INLINE const BYTE* avs_get_read_ptr_p(const AVS_VideoFrame * p, int plane) 
371 {
372         switch (plane) {
373                 case AVS_PLANAR_U: return p->vfb->data + p->offsetU;
374                 case AVS_PLANAR_V: return p->vfb->data + p->offsetV;
375                 default:           return p->vfb->data + p->offset;}
376 }
377
378 AVSC_INLINE int avs_is_writable(const AVS_VideoFrame * p) {
379         return (p->refcount == 1 && p->vfb->refcount == 1);}
380
381 AVSC_INLINE BYTE* avs_get_write_ptr(const AVS_VideoFrame * p) 
382 {
383         if (avs_is_writable(p)) {
384                 ++p->vfb->sequence_number;
385                 return p->vfb->data + p->offset;
386         } else
387                 return 0;
388 }
389
390 AVSC_INLINE BYTE* avs_get_write_ptr_p(const AVS_VideoFrame * p, int plane) 
391 {
392         if (plane==AVS_PLANAR_Y && avs_is_writable(p)) {
393                 ++p->vfb->sequence_number;
394                 return p->vfb->data + p->offset;
395         } else if (plane==AVS_PLANAR_Y) {
396                 return 0;
397         } else {
398                 switch (plane) {
399                         case AVS_PLANAR_U: return p->vfb->data + p->offsetU;
400                         case AVS_PLANAR_V: return p->vfb->data + p->offsetV;
401                         default:       return p->vfb->data + p->offset;
402                 }
403         }
404 }
405
406
407 AVSC_API(void) avs_release_video_frame(AVS_VideoFrame *);
408 // makes a shallow copy of a video frame
409 AVSC_API(AVS_VideoFrame *) avs_copy_video_frame(AVS_VideoFrame *);
410
411 AVSC_INLINE void avs_release_frame(AVS_VideoFrame * f)
412   {avs_release_video_frame(f);}
413 AVSC_INLINE AVS_VideoFrame * avs_copy_frame(AVS_VideoFrame * f)
414   {return avs_copy_video_frame(f);}
415
416
417
418 /////////////////////////////////////////////////////////////////////
419 //
420 // AVS_Value
421 //
422
423 // Treat AVS_Value as a fat pointer.  That is use avs_copy_value
424 // and avs_release_value appropiaty as you would if AVS_Value was
425 // a pointer.
426
427 // To maintain source code compatibility with future versions of the
428 // avisynth_c API don't use the AVS_Value directly.  Use the helper
429 // functions below.
430
431 // AVS_Value is layed out identicly to AVSValue
432 typedef struct AVS_Value AVS_Value;
433 struct AVS_Value {
434   short type;  // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong
435                // for some function e'rror
436   short array_size;
437   union {
438     void * clip; // do not use directly, use avs_take_clip
439     char boolean;
440     int integer;
441     float floating_pt;
442     const char * string;
443     const AVS_Value * array;
444   } d;
445 };
446
447 // AVS_Value should be initilized with avs_void.
448 // Should also set to avs_void after the value is released
449 // with avs_copy_value.  Consider it the equalvent of setting
450 // a pointer to NULL
451 static const AVS_Value avs_void = {'v'};
452
453 AVSC_API(void) avs_copy_value(AVS_Value * dest, AVS_Value src);
454 AVSC_API(void) avs_release_value(AVS_Value);
455
456 AVSC_INLINE int avs_defined(AVS_Value v) { return v.type != 'v'; }
457 AVSC_INLINE int avs_is_clip(AVS_Value v) { return v.type == 'c'; }
458 AVSC_INLINE int avs_is_bool(AVS_Value v) { return v.type == 'b'; }
459 AVSC_INLINE int avs_is_int(AVS_Value v) { return v.type == 'i'; }
460 AVSC_INLINE int avs_is_float(AVS_Value v) { return v.type == 'f' || v.type == 'i'; }
461 AVSC_INLINE int avs_is_string(AVS_Value v) { return v.type == 's'; }
462 AVSC_INLINE int avs_is_array(AVS_Value v) { return v.type == 'a'; }
463 AVSC_INLINE int avs_is_error(AVS_Value v) { return v.type == 'e'; }
464
465 AVSC_API(AVS_Clip *) avs_take_clip(AVS_Value, AVS_ScriptEnvironment *);
466 AVSC_API(void) avs_set_to_clip(AVS_Value *, AVS_Clip *);
467
468 AVSC_INLINE int avs_as_bool(AVS_Value v) 
469         { return v.d.boolean; }   
470 AVSC_INLINE int avs_as_int(AVS_Value v) 
471         { return v.d.integer; }   
472 AVSC_INLINE const char * avs_as_string(AVS_Value v) 
473         { return avs_is_error(v) || avs_is_string(v) ? v.d.string : 0; }
474 AVSC_INLINE double avs_as_float(AVS_Value v) 
475         { return avs_is_int(v) ? v.d.integer : v.d.floating_pt; }
476 AVSC_INLINE const char * avs_as_error(AVS_Value v) 
477         { return avs_is_error(v) ? v.d.string : 0; }
478 AVSC_INLINE const AVS_Value * avs_as_array(AVS_Value v)
479         { return v.d.array; }
480 AVSC_INLINE int avs_array_size(AVS_Value v) 
481         { return avs_is_array(v) ? v.array_size : 1; }
482 AVSC_INLINE AVS_Value avs_array_elt(AVS_Value v, int index) 
483         { return avs_is_array(v) ? v.d.array[index] : v; }
484
485 // only use these functions on am AVS_Value that does not already have
486 // an active value.  Remember, treat AVS_Value as a fat pointer.
487 AVSC_INLINE AVS_Value avs_new_value_bool(int v0) 
488         { AVS_Value v; v.type = 'b'; v.d.boolean = v0 == 0 ? 0 : 1; return v; }   
489 AVSC_INLINE AVS_Value avs_new_value_int(int v0) 
490         { AVS_Value v; v.type = 'i'; v.d.integer = v0; return v; }   
491 AVSC_INLINE AVS_Value avs_new_value_string(const char * v0) 
492         { AVS_Value v; v.type = 's'; v.d.string = v0; return v; }
493 AVSC_INLINE AVS_Value avs_new_value_float(float v0) 
494         { AVS_Value v; v.type = 'f'; v.d.floating_pt = v0; return v;}
495 AVSC_INLINE AVS_Value avs_new_value_error(const char * v0) 
496         { AVS_Value v; v.type = 'e'; v.d.string = v0; return v; }
497 AVSC_INLINE AVS_Value avs_new_value_clip(AVS_Clip * v0)
498         { AVS_Value v; avs_set_to_clip(&v, v0); return v; }
499 AVSC_INLINE AVS_Value avs_new_value_array(AVS_Value * v0, int size)
500         { AVS_Value v; v.type = 'a'; v.d.array = v0; v.array_size = size; return v; }
501
502 /////////////////////////////////////////////////////////////////////
503 //
504 // AVS_Clip
505 //
506
507 AVSC_API(void) avs_release_clip(AVS_Clip *);
508 AVSC_API(AVS_Clip *) avs_copy_clip(AVS_Clip *);
509
510 AVSC_API(const char *) avs_clip_get_error(AVS_Clip *); // return 0 if no error
511
512 AVSC_API(const AVS_VideoInfo *) avs_get_video_info(AVS_Clip *);
513
514 AVSC_API(int) avs_get_version(AVS_Clip *);
515  
516 AVSC_API(AVS_VideoFrame *) avs_get_frame(AVS_Clip *, int n);
517 // The returned video frame must be released with avs_release_video_frame
518
519 AVSC_API(int) avs_get_parity(AVS_Clip *, int n); 
520 // return field parity if field_based, else parity of first field in frame
521
522 AVSC_API(int) avs_get_audio(AVS_Clip *, void * buf, 
523                                   INT64 start, INT64 count); 
524 // start and count are in samples
525
526 AVSC_API(int) avs_set_cache_hints(AVS_Clip *, 
527                                         int cachehints, int frame_range);
528
529 // This is the callback type used by avs_add_function
530 typedef AVS_Value (AVSC_CC * AVS_ApplyFunc)
531                         (AVS_ScriptEnvironment *, AVS_Value args, void * user_data);
532
533 typedef struct AVS_FilterInfo AVS_FilterInfo;
534 struct AVS_FilterInfo
535 {
536   // these members should not be modified outside of the AVS_ApplyFunc callback
537   AVS_Clip * child;
538   AVS_VideoInfo vi;
539   AVS_ScriptEnvironment * env;
540   AVS_VideoFrame * (AVSC_CC * get_frame)(AVS_FilterInfo *, int n);
541   int (AVSC_CC * get_parity)(AVS_FilterInfo *, int n);
542   int (AVSC_CC * get_audio)(AVS_FilterInfo *, void * buf, 
543                                   INT64 start, INT64 count);
544   int (AVSC_CC * set_cache_hints)(AVS_FilterInfo *, int cachehints, 
545                                         int frame_range);
546   void (AVSC_CC * free_filter)(AVS_FilterInfo *);
547   
548   // Should be set when ever there is an error to report.
549   // It is cleared before any of the above methods are called
550   const char * error;
551   // this is to store whatever and may be modified at will
552   void * user_data;
553 };
554
555 // Create a new filter
556 // fi is set to point to the AVS_FilterInfo so that you can
557 //   modify it once it is initilized.
558 // store_child should generally be set to true.  If it is not
559 //    set than ALL methods (the function pointers) must be defined
560 // If it is set than you do not need to worry about freeing the child
561 //    clip.
562 AVSC_API(AVS_Clip *) avs_new_c_filter(AVS_ScriptEnvironment * e,
563                                             AVS_FilterInfo * * fi,
564                                             AVS_Value child, int store_child);
565
566 /////////////////////////////////////////////////////////////////////
567 //
568 // AVS_ScriptEnvironment
569 //
570
571 // For GetCPUFlags.  These are backwards-compatible with those in VirtualDub.
572 enum {                    
573                                 /* slowest CPU to support extension */
574   AVS_CPU_FORCE        = 0x01,   // N/A
575   AVS_CPU_FPU          = 0x02,   // 386/486DX
576   AVS_CPU_MMX          = 0x04,   // P55C, K6, PII
577   AVS_CPU_INTEGER_SSE  = 0x08,   // PIII, Athlon
578   AVS_CPU_SSE          = 0x10,   // PIII, Athlon XP/MP
579   AVS_CPU_SSE2         = 0x20,   // PIV, Hammer
580   AVS_CPU_3DNOW        = 0x40,   // K6-2
581   AVS_CPU_3DNOW_EXT    = 0x80,   // Athlon
582   AVS_CPU_X86_64       = 0xA0,   // Hammer (note: equiv. to 3DNow + SSE2, 
583                                  // which only Hammer will have anyway)
584 };
585
586
587 AVSC_API(long) avs_get_cpu_flags(AVS_ScriptEnvironment *);
588 AVSC_API(int) avs_check_version(AVS_ScriptEnvironment *, int version);
589
590 AVSC_API(char *) avs_save_string(AVS_ScriptEnvironment *, const char* s, int length);
591 AVSC_API(char *) avs_sprintf(AVS_ScriptEnvironment *, const char * fmt, ...);
592
593 AVSC_API(char *) avs_vsprintf(AVS_ScriptEnvironment *, const char * fmt, void* val);
594  // note: val is really a va_list; I hope everyone typedefs va_list to a pointer
595
596 AVSC_API(int) avs_add_function(AVS_ScriptEnvironment *, 
597                                      const char * name, const char * params, 
598                                      AVS_ApplyFunc apply, void * user_data);
599
600 AVSC_API(int) avs_function_exists(AVS_ScriptEnvironment *, const char * name);
601
602 AVSC_API(AVS_Value) avs_invoke(AVS_ScriptEnvironment *, const char * name, 
603                                AVS_Value args, const char** arg_names);
604 // The returned value must be be released with avs_release_value
605
606 AVSC_API(AVS_Value) avs_get_var(AVS_ScriptEnvironment *, const char* name);
607 // The returned value must be be released with avs_release_value
608
609 AVSC_API(int) avs_set_var(AVS_ScriptEnvironment *, const char* name, AVS_Value val);
610
611 AVSC_API(int) avs_set_global_var(AVS_ScriptEnvironment *, const char* name, const AVS_Value val);
612
613 //void avs_push_context(AVS_ScriptEnvironment *, int level=0);
614 //void avs_pop_context(AVS_ScriptEnvironment *);
615
616 AVSC_API(AVS_VideoFrame *) avs_new_video_frame_a(AVS_ScriptEnvironment *, 
617                                           const AVS_VideoInfo * vi, int align);
618 // align should be at least 16
619
620 AVSC_INLINE 
621 AVS_VideoFrame * avs_new_video_frame(AVS_ScriptEnvironment * env, 
622                                      const AVS_VideoInfo * vi)
623   {return avs_new_video_frame_a(env,vi,AVS_FRAME_ALIGN);}
624
625 AVSC_INLINE 
626 AVS_VideoFrame * avs_new_frame(AVS_ScriptEnvironment * env, 
627                                const AVS_VideoInfo * vi)
628   {return avs_new_video_frame_a(env,vi,AVS_FRAME_ALIGN);}
629
630
631 AVSC_API(int) avs_make_writable(AVS_ScriptEnvironment *, AVS_VideoFrame * * pvf);
632
633 AVSC_API(void) avs_bit_blt(AVS_ScriptEnvironment *, BYTE* dstp, int dst_pitch, const BYTE* srcp, int src_pitch, int row_size, int height);
634
635 typedef void (AVSC_CC *AVS_ShutdownFunc)(void* user_data, AVS_ScriptEnvironment * env);
636 AVSC_API(void) avs_at_exit(AVS_ScriptEnvironment *, AVS_ShutdownFunc function, void * user_data);
637
638 AVSC_API(AVS_VideoFrame *) avs_subframe(AVS_ScriptEnvironment *, AVS_VideoFrame * src, int rel_offset, int new_pitch, int new_row_size, int new_height);
639 // The returned video frame must be be released
640
641 AVSC_API(int) avs_set_memory_max(AVS_ScriptEnvironment *, int mem);
642
643 AVSC_API(int) avs_set_working_dir(AVS_ScriptEnvironment *, const char * newdir);
644
645 // avisynth.dll exports this; it's a way to use it as a library, without
646 // writing an AVS script or without going through AVIFile.
647 AVSC_API(AVS_ScriptEnvironment *) avs_create_script_environment(int version);
648
649 // this symbol is the entry point for the plugin and must
650 // be defined
651 AVSC_EXPORT
652 const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment* env);
653
654
655 AVSC_API(void) avs_delete_script_environment(AVS_ScriptEnvironment *);
656
657
658 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);
659 // The returned video frame must be be released
660
661 #endif