Skip to content

Commit 400bf88

Browse files
committed
Make filter/filter pure
1 parent d3fbbd2 commit 400bf88

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

av/filter/filter.pxd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ from av.descriptor cimport Descriptor
44

55

66
cdef class Filter:
7-
87
cdef const lib.AVFilter *ptr
9-
108
cdef object _inputs
119
cdef object _outputs
1210
cdef Descriptor _descriptor
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
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
25

3-
from av.descriptor cimport wrap_avclass
4-
from av.filter.link cimport alloc_filter_pads
6+
_cinit_sentinel = cython.declare(object, object())
57

68

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)
1212
filter_.ptr = ptr
1313
return filter_
1414

1515

16-
cdef class Filter:
16+
@cython.cclass
17+
class Filter:
1718
def __cinit__(self, name):
1819
if name is _cinit_sentinel:
1920
return
2021
if not isinstance(name, str):
2122
raise TypeError("takes a filter name as a string")
23+
2224
self.ptr = lib.avfilter_get_by_name(name)
2325
if not self.ptr:
2426
raise ValueError(f"no filter {name}")
@@ -60,19 +62,19 @@ def outputs(self):
6062
return self._outputs
6163

6264

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
6770
while True:
68-
ptr = lib.av_filter_iterate(&opaque)
71+
ptr = lib.av_filter_iterate(cython.address(opaque))
6972
if ptr:
7073
names.add(ptr.name)
7174
else:
7275
break
7376
return names
7477

75-
filters_available = get_filter_names()
76-
7778

79+
filters_available = get_filter_names()
7880
filter_descriptor = wrap_avclass(lib.avfilter_get_class())

av/utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
def _decode(s: cython.pointer[cython.char], encoding, errors) -> str:
1414
return cython.cast(bytes, s).decode(encoding, errors)
1515

16-
17-
@cython.cfunc
18-
def _encode(s, encoding, errors) -> bytes:
19-
return s.encode(encoding, errors)
20-
21-
2216
@cython.cfunc
2317
def avdict_to_dict(
2418
input: cython.pointer[lib.AVDictionary], encoding: str, errors: str

0 commit comments

Comments
 (0)