rustsynth-sys 0.5.6

Low level bindings to VapourSynth
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#
# Copyright (c) 2012-2025 Fredrik Mellbin
#
# This file is part of VapourSynth.
#
# VapourSynth is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# VapourSynth is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with VapourSynth; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
#cython: language_level=3

from libc.stdint cimport uint8_t, uint32_t, int64_t, uint64_t, uintptr_t
from libc.stddef cimport ptrdiff_t

cdef extern from "include/VapourSynth4.h" nogil:
    enum:
        VS_CURRENT_RELEASE
        VAPOURSYNTH_API_MAJOR
        VAPOURSYNTH_API_MINOR
        VAPOURSYNTH_API_VERSION

    ctypedef struct VSFrame:
        pass
    ctypedef struct VSNode:
        pass
    ctypedef struct VSCore:
        pass
    ctypedef struct VSPlugin:
        pass
    ctypedef struct VSPluginFunction:
        pass
    ctypedef struct VSFunction:
        pass
    ctypedef struct VSMap:
        pass
    ctypedef struct VSLogHandle:
        pass
    ctypedef struct VSFrameContext:
        pass

    enum:
        mtVideo
        mtAudio

    enum:
        cfUndefined
        cfGray
        cfRGB
        cfYUV

    enum:
        stInteger
        stFloat

    enum:
        pfNone

        pfGray8
        pfGray9
        pfGray10
        pfGray12
        pfGray14
        pfGray16
        pfGray32

        pfGrayH
        pfGrayS

        pfYUV410P8
        pfYUV411P8
        pfYUV440P8

        pfYUV420P8
        pfYUV422P8
        pfYUV444P8

        pfYUV420P9
        pfYUV422P9
        pfYUV444P9

        pfYUV420P10
        pfYUV422P10
        pfYUV444P10

        pfYUV420P12
        pfYUV422P12
        pfYUV444P12

        pfYUV420P14
        pfYUV422P14
        pfYUV444P14

        pfYUV420P16
        pfYUV422P16
        pfYUV444P16

        pfYUV420PH
        pfYUV420PS
        
        pfYUV422PH
        pfYUV422PS

        pfYUV444PH
        pfYUV444PS

        pfRGB24
        pfRGB27
        pfRGB30
        pfRGB36
        pfRGB42
        pfRGB48

        pfRGBH
        pfRGBS

    enum:
        fmParallel
        fmParallelRequests
        fmUnordered
        fmFrameState

    ctypedef struct VSVideoFormat:
        int colorFamily
        int sampleType
        int bytesPerSample
        int bitsPerSample
        int subSamplingW
        int subSamplingH
        int numPlanes

    enum:
        acFrontLeft
        acFrontRight
        acFrontCenter
        acLowFrequency
        acBackLeft
        acBackRight
        acFrontLeftOFCenter
        acFrontRightOFCenter
        acBackCenter
        acSideLeft
        acSideRight
        acTopCenter
        acTopFrontLeft
        acTopFrontCenter
        acTopFrontRight
        acTopBackLeft
        acTopBackCenter
        acTopBackRight
        acStereoLeft
        acStereoRight
        acWideLeft
        acWideRight
        acSurroundDirectLeft
        acSurroundDirectRight
        acLowFrequency2

    ctypedef struct VSAudioFormat:
        int sampleType
        int bitsPerSample
        int bytesPerSample
        int numChannels
        uint64_t channelLayout

    enum VSPropertyType:
        ptUnset
        ptInt
        ptFloat
        ptData
        ptFunction
        ptVideoNode
        ptAudioNode
        ptVideoFrame
        ptAudioFrame

    enum VSMapPropertyError:
        peSuccess
        peUnset
        peType
        peIndex
        peError

    enum VSMapAppendMode:
        maReplace
        maAppend

    struct VSCoreInfo:
        char *versionString
        int core
        int api
        int numThreads
        int64_t maxFramebufferSize
        int64_t usedFramebufferSize

    struct VSVideoInfo:
        VSVideoFormat format
        int64_t fpsNum
        int64_t fpsDen
        int width
        int height
        int numFrames

    struct VSAudioInfo:
        VSAudioFormat format
        int sampleRate
        int64_t numSamples
        int numFrames

    enum VSActivationReason:
        arInitial
        arAllFramesReady
        arError

    enum:
        mtDebug
        mtInformation
        mtWarning
        mtCritical
        mtFatal

    enum:
        ccfEnableGraphInspection
        ccfDisableAutoLoading
        ccfDisableLibraryUnloading

    enum VSPluginConfigFlags:
        pcModifiable

    enum VSDataTypeHint:
        dtUnknown
        dtBinary
        dtUtf8

    struct VSFilterDependency:
        VSNode *source;
        int requestPattern


    ctypedef const VSAPI *(__stdcall *VSGetVapourSynthAPI)(int version)

    ctypedef void (__stdcall *VSPublicFunction)(const VSMap *input, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi)
    ctypedef void (__stdcall *VSInitPlugin)(VSPlugin *plugin, const VSPLUGINAPI *vspapi)

    ctypedef void (__stdcall *VSFreeFunctionData)(void *userData)
    ctypedef const VSFrame *(__stdcall *VSFilterGetFrame)(int n, int activationReason, void *instanceData, void **frameData, VSFrameContext *frameCtx, VSCore *core, const VSAPI *vsapi)
    ctypedef void (__stdcall *VSFilterFree)(void *instanceData, VSCore *core, const VSAPI *vsapi)

    ctypedef void (__stdcall *VSFrameDoneCallback)(void *userData, const VSFrame *f, int n, VSNode *node, const char *errorMsg)
    ctypedef void (__stdcall *VSLogHandler)(int msgType, const char *msg, void *userData)
    ctypedef void (__stdcall *VSLogHandlerFree)(void *userData)

    ctypedef struct VSPLUGINAPI:
        int getAPIVersion() nogil
        bint configPlugin(const char *identifier, const char *pluginNamespace, const char *name, int pluginVersion, int apiVersion, int flags, VSPlugin *plugin) nogil
        bint registerFunction(const char *name, const char *args, const char *returnType, VSPublicFunction argsFunc, void *functionData, VSPlugin *plugin) nogil

    ctypedef struct VSAPI:
        # Audio and video filter
        void createVideoFilter(VSMap *out, const char *name, const VSVideoInfo *vi, VSFilterGetFrame getFrame, VSFilterFree free, int filterMode, int flags, void *instanceData, VSCore *core) nogil
        VSNode *createVideoFilter2(const char *name, const VSVideoInfo *vi, VSFilterGetFrame getFrame, VSFilterFree free, int filterMode, int flags, void *instanceData, VSCore *core) nogil
        void createAudioFilter(VSMap *out, const char *name, const VSAudioInfo *ai, VSFilterGetFrame getFrame, VSFilterFree free, int filterMode, int flags, void *instanceData, VSCore *core) nogil
        VSNode *createAudioFilter2(const char *name, const VSAudioInfo *ai, VSFilterGetFrame getFrame, VSFilterFree free, int filterMode, int flags, void *instanceData, VSCore *core) nogil
        int setLinearFilter(VSNode *node) nogil

        void freeNode(VSNode *node) nogil
        VSNode *addNodeRef(VSNode *node) nogil
        int getNodeType(VSNode *node) nogil
        void setCacheMode(VSNode *node, int mode) nogil
        const VSVideoInfo *getVideoInfo(VSNode *node) nogil
        const VSAudioInfo *getAudioInfo(VSNode *node) nogil

        # Frame related
        VSFrame *newVideoFrame(const VSVideoFormat *format, int width, int height, const VSFrame *propSrc, VSCore *core) nogil
        VSFrame *newVideoFrame2(const VSVideoFormat *format, int width, int height, const VSFrame **planeSrc, const int *planes, const VSFrame *propSrc, VSCore *core) nogil
        VSFrame *newAudioFrame(const VSAudioFormat *format, int sampleRate, const VSFrame *propSrc, VSCore *core) nogil
        VSFrame *newAudioFrame2(const VSAudioFormat *format, int numSamples, const VSFrame **channelSrc, const int *channels, const VSFrame *propSrc, VSCore *core) nogil
        void freeFrame(const VSFrame *f) nogil
        const VSFrame *addFrameRef(const VSFrame *f) nogil
        VSFrame *copyFrame(const VSFrame *f, VSCore *core) nogil
        const VSMap *getFramePropertiesRO(const VSFrame *f) nogil
        VSMap *getFramePropertiesRW(VSFrame *f) nogil

        ptrdiff_t getStride(const VSFrame *f, int plane) nogil
        const uint8_t *getReadPtr(const VSFrame *f, int plane) nogil
        uint8_t *getWritePtr(VSFrame *f, int plane) nogil

        const VSVideoFormat *getVideoFrameFormat(const VSFrame *f) nogil
        const VSAudioFormat *getAudioFrameFormat(const VSFrame *f) nogil
        int getFrameType(const VSFrame *f) nogil
        int getFrameWidth(const VSFrame *f, int plane) nogil
        int getFrameHeight(const VSFrame *f, int plane) nogil
        int getFrameLength(const VSFrame *f) nogil

        # General format functions
        bint getVideoFormatName(const VSVideoFormat *format, char *buffer) nogil
        bint getAudioFormatName(const VSAudioFormat *format, char *buffer) nogil
        bint queryVideoFormat(VSVideoFormat *format, int colorFamily, int sampleType, int bitsPerSample, int subSamplingW, int subSamplingH, VSCore *core) nogil
        bint queryAudioFormat(VSAudioFormat *format, int sampleType, int bitsPerSample, uint64_t channelLayout, VSCore *core) nogil
        uint32_t queryVideoFormatID(int colorFamily, int sampleType, int bitsPerSample, int subSamplingW, int subSamplingH, VSCore *core) nogil
        int getVideoFormatByID(VSVideoFormat *format, uint32_t id, VSCore *core) nogil

        # Frame requests
        const VSFrame *getFrame(int n, VSNode *node, char *errorMsg, int bufSize) nogil
        void getFrameAsync(int n, VSNode *node, VSFrameDoneCallback callback, void *userData) nogil
        const VSFrame *getFrameFilter(int n, VSNode *node, VSFrameContext *frameCtx) nogil
        void requestFrameFilter(int n, VSNode *node, VSFrameContext *frameCtx) nogil
        void releaseFrameEarly(VSNode *node, int n, VSFrameContext *frameCtx) nogil
        void cacheFrame(const VSFrame *frame, int n, VSFrameContext *frameCtx) nogil
        void setFilterError(const char *errorMessage, VSFrameContext *frameCtx) nogil

        # External functions
        VSFunction *createFunction(VSPublicFunction func, void *userData, VSFreeFunctionData free, VSCore *core) nogil
        void freeFunction(VSFunction *f) nogil
        VSFunction *addFunctionRef(VSFunction *f) nogil
        void callFunction(VSFunction *func, const VSMap *inm, VSMap *outm) nogil

        # Map and property access
        VSMap *createMap() nogil
        void freeMap(VSMap *map) nogil
        void clearMap(VSMap *map) nogil
        void copyMap(const VSMap *src, VSMap *dst) nogil

        void mapSetError(VSMap *map, const char *errorMessage) nogil
        char *mapGetError(const VSMap *map) nogil

        int mapNumKeys(const VSMap *map) nogil
        const char *mapGetKey(const VSMap *map, int index) nogil
        bint mapDeleteKey(VSMap *map, const char *key) nogil
        int mapNumElements(const VSMap *map, const char *key) nogil
        int mapGetType(const VSMap *map, const char *key) nogil
        int mapSetEmpty(VSMap *map, const char *key, int type) nogil

        int64_t mapGetInt(const VSMap *map, const char *key, int index, int *error) nogil
        int mapGetIntSaturated(const VSMap *map, const char *key, int index, int *error) nogil
        const int64_t *mapGetIntArray(const VSMap *map, const char *key, int *error) nogil
        bint mapSetInt(VSMap *map, const char *key, int64_t i, int append) nogil
        bint mapSetIntArray(VSMap *map, const char *key, const int64_t *i, int size) nogil

        double mapGetFloat(const VSMap *map, const char *key, int index, int *error) nogil
        float mapGetFloatSaturated(const VSMap *map, const char *key, int index, int *error) nogil
        const double *mapGetFloatArray(const VSMap *map, const char *key, int *error) nogil
        bint mapSetFloat(VSMap *map, const char *key, double d, int append) nogil
        bint mapSetFloatArray(VSMap *map, const char *key, const double *d, int size) nogil

        const char *mapGetData(const VSMap *map, const char *key, int index, int *error) nogil
        int mapGetDataSize(const VSMap *map, const char *key, int index, int *error) nogil
        int mapGetDataTypeHint(const VSMap *map, const char *key, int index, int *error) nogil
        bint mapSetData(VSMap *map, const char *key, const char *data, int size, int type, int append) nogil

        VSNode *mapGetNode(const VSMap *map, const char *key, int index, int *error) nogil
        bint mapSetNode(VSMap *map, const char *key, VSNode *node, int append) nogil
        bint mapConsumeNode(VSMap *map, const char *key, VSNode *node, int append) nogil

        const VSFrame *mapGetFrame(const VSMap *map, const char *key, int index, int *error) nogil
        bint mapSetFrame(VSMap *map, const char *key, const VSFrame *f, int append) nogil
        bint mapConsumeFrame(VSMap *map, const char *key, const VSFrame *f, int append) nogil

        VSFunction *mapGetFunction(const VSMap *map, const char *key, int index, int *error) nogil
        bint mapSetFunction(VSMap *map, const char *key, VSFunction *func, int append) nogil
        bint mapConsumeFunction(VSMap *map, const char *key, VSFunction *func, int append) nogil

        # Plugin and function related
        bint registerFunction(const char *name, const char *args, const char *returnType, VSPublicFunction argsFunc, void *functionData, VSPlugin *plugin) nogil
        VSPlugin *getPluginByID(const char *identifier, VSCore *core) nogil
        VSPlugin *getPluginByNamespace(const char *ns, VSCore *core) nogil
        VSPlugin *getNextPlugin(VSPlugin *plugin, VSCore *core) nogil
        const char *getPluginName(VSPlugin *plugin) nogil
        const char *getPluginID(VSPlugin *plugin) nogil
        const char *getPluginNamespace(VSPlugin *plugin) nogil
        VSPluginFunction *getNextPluginFunction(VSPluginFunction *func, VSPlugin *plugin) nogil
        VSPluginFunction *getPluginFunctionByName(const char *name, VSPlugin *plugin) nogil
        const char *getPluginFunctionName(VSPluginFunction *func) nogil
        const char *getPluginFunctionArguments(VSPluginFunction *func) nogil
        const char *getPluginFunctionReturnType(VSPluginFunction *func) nogil
        const char *getPluginPath(const VSPlugin *plugin) nogil
        int *getPluginVersion(const VSPlugin *plugin) nogil;
        VSMap *invoke(VSPlugin *plugin, const char *name, const VSMap *args) nogil

        # Core and information
        VSCore *createCore(int flags) nogil
        void freeCore(VSCore *core) nogil
        int64_t setMaxCacheSize(int64_t bytes, VSCore *core) nogil
        int setThreadCount(int threads, VSCore *core) nogil
        void getCoreInfo(VSCore *core, VSCoreInfo *info) nogil
        int getAPIVersion() nogil

        # Message handler
        void logMessage(int msgType, const char *msg, VSCore *core) nogil
        VSLogHandle *addLogHandler(VSLogHandler handler, VSLogHandlerFree free, void *userData, VSCore *core) nogil
        bint removeLogHandler(VSLogHandle *handle, VSCore *core) nogil

        # Additional cache management to free memory */
        void clearNodeCache(VSNode *node) nogil
        void clearCoreCaches(VSCore *core) nogil

        # Basic node information
        const char *getNodeName(VSNode *node) nogil
        int getNodeFilterMode(VSNode *node) nogil
        int getNumNodeDependencies(VSNode *node) nogil
        const VSFilterDependency *getNodeDependency(VSNode *node, int index) nogil

        # Node timing functions
        int getCoreNodeTiming(VSCore *core) nogil
        void setCoreNodeTiming(VSCore *core, int enable) nogil
        int64_t getNodeProcessingTime(VSNode *node, int reset) nogil
        int64_t getFreedNodeProcessingTime(VSCore *core, int reset) nogil

        # Unstable API, has no set place.
        const char *getNodeCreationFunctionName(VSNode *node, int level) nogil
        const VSMap *getNodeCreationFunctionArguments(VSNode *node, int level) nogil

    const VSAPI *getVapourSynthAPI(int version) nogil