Debian Codegraph @

av/filter/filter.py

raw
1 import cython
2 from cython.cimports import libav as lib
3 from cython.cimports.av.filter.link import alloc_filter_pads
4
5 _cinit_sentinel = cython.declare(object, object())
6
7
8 @cython.cfunc
9 def wrap_filter(ptr: cython.pointer[cython.const[lib.AVFilter]]) -> Filter:
10 filter_: Filter = Filter(_cinit_sentinel)
11 filter_.ptr = ptr
12 return filter_
13
14
15 @cython.final
16 @cython.cclass
17 class Filter:
18 def __cinit__(self, name):
19 if name is _cinit_sentinel:
20 return
21 if not isinstance(name, str):
22 raise TypeError("takes a filter name as a string")
23
24 self.ptr = lib.avfilter_get_by_name(name)
25 if not self.ptr:
26 raise ValueError(f"no filter {name}")
27
28 @property
29 def name(self):
30 return self.ptr.name
31
32 @property
33 def description(self):
34 return self.ptr.description
35
36 @property
37 def flags(self):
38 return self.ptr.flags
39
40 @property
41 def inputs(self):
42 if self._inputs is None:
43 self._inputs = alloc_filter_pads(self, self.ptr.inputs, True)
44 return self._inputs
45
46 @property
47 def outputs(self):
48 if self._outputs is None:
49 self._outputs = alloc_filter_pads(self, self.ptr.outputs, False)
50 return self._outputs
51
52
53 @cython.cfunc
54 def get_filter_names() -> set:
55 names: set = set()
56 ptr: cython.pointer[cython.const[lib.AVFilter]]
57 opaque: cython.p_void = cython.NULL
58 while True:
59 ptr = lib.av_filter_iterate(cython.address(opaque))
60 if ptr:
61 names.add(ptr.name)
62 else:
63 break
64 return names
65
66
67 filters_available = get_filter_names()