You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

728 lines
26KB

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