|
1 | | -cimport libav as lib |
| 1 | +import cython |
| 2 | +from cython.cimports import libav as lib |
| 3 | +from cython.cimports.av.descriptor import wrap_avclass |
| 4 | +from cython.cimports.av.filter.link import alloc_filter_pads |
2 | 5 |
|
3 | | -from av.descriptor cimport wrap_avclass |
4 | | -from av.filter.link cimport alloc_filter_pads |
| 6 | +_cinit_sentinel = cython.declare(object, object()) |
5 | 7 |
|
6 | 8 |
|
7 | | -cdef object _cinit_sentinel = object() |
8 | | - |
9 | | - |
10 | | -cdef Filter wrap_filter(const lib.AVFilter *ptr): |
11 | | - cdef Filter filter_ = Filter(_cinit_sentinel) |
| 9 | +@cython.cfunc |
| 10 | +def wrap_filter(ptr: cython.pointer[cython.const[lib.AVFilter]]) -> Filter: |
| 11 | + filter_: Filter = Filter(_cinit_sentinel) |
12 | 12 | filter_.ptr = ptr |
13 | 13 | return filter_ |
14 | 14 |
|
15 | 15 |
|
16 | | -cdef class Filter: |
| 16 | +@cython.cclass |
| 17 | +class Filter: |
17 | 18 | def __cinit__(self, name): |
18 | 19 | if name is _cinit_sentinel: |
19 | 20 | return |
20 | 21 | if not isinstance(name, str): |
21 | 22 | raise TypeError("takes a filter name as a string") |
| 23 | + |
22 | 24 | self.ptr = lib.avfilter_get_by_name(name) |
23 | 25 | if not self.ptr: |
24 | 26 | raise ValueError(f"no filter {name}") |
@@ -60,19 +62,19 @@ def outputs(self): |
60 | 62 | return self._outputs |
61 | 63 |
|
62 | 64 |
|
63 | | -cdef get_filter_names(): |
64 | | - names = set() |
65 | | - cdef const lib.AVFilter *ptr |
66 | | - cdef void *opaque = NULL |
| 65 | +@cython.cfunc |
| 66 | +def get_filter_names() -> set: |
| 67 | + names: set = set() |
| 68 | + ptr: cython.pointer[cython.const[lib.AVFilter]] |
| 69 | + opaque: cython.p_void = cython.NULL |
67 | 70 | while True: |
68 | | - ptr = lib.av_filter_iterate(&opaque) |
| 71 | + ptr = lib.av_filter_iterate(cython.address(opaque)) |
69 | 72 | if ptr: |
70 | 73 | names.add(ptr.name) |
71 | 74 | else: |
72 | 75 | break |
73 | 76 | return names |
74 | 77 |
|
75 | | -filters_available = get_filter_names() |
76 | | - |
77 | 78 |
|
| 79 | +filters_available = get_filter_names() |
78 | 80 | filter_descriptor = wrap_avclass(lib.avfilter_get_class()) |
0 commit comments