-
Notifications
You must be signed in to change notification settings - Fork 433
Expand file tree
/
Copy pathdescriptor.py
More file actions
75 lines (67 loc) · 2.61 KB
/
descriptor.py
File metadata and controls
75 lines (67 loc) · 2.61 KB
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
import cython
import cython.cimports.libav as lib
from cython.cimports.av.option import (
Option,
OptionChoice,
wrap_option,
wrap_option_choice,
)
_cinit_sentinel = cython.declare(object, object())
@cython.cfunc
def wrap_avclass(ptr: cython.pointer[cython.const[lib.AVClass]]) -> Descriptor | None:
if ptr == cython.NULL:
return None
obj: Descriptor = Descriptor(_cinit_sentinel)
obj.ptr = ptr
return obj
@cython.cclass
class Descriptor:
def __cinit__(self, sentinel):
if sentinel is not _cinit_sentinel:
raise RuntimeError("Cannot construct av.Descriptor")
@property
def name(self):
return self.ptr.class_name if self.ptr.class_name else None
@property
def options(self):
ptr: cython.pointer[cython.const[lib.AVOption]] = self.ptr.option
choice_ptr: cython.pointer[cython.const[lib.AVOption]]
option: Option
option_choice: OptionChoice
choice_is_default: cython.bint
if self._options is None:
options: list = []
ptr = self.ptr.option
while ptr != cython.NULL and ptr.name != cython.NULL:
if ptr.type == lib.AV_OPT_TYPE_CONST:
ptr += 1
continue
choices: list = []
if (
ptr.unit != cython.NULL
): # option has choices (matching const options)
choice_ptr = self.ptr.option
while choice_ptr != cython.NULL and choice_ptr.name != cython.NULL:
if (
choice_ptr.type != lib.AV_OPT_TYPE_CONST
or choice_ptr.unit != ptr.unit
):
choice_ptr += 1
continue
choice_is_default = (
choice_ptr.default_val.i64 == ptr.default_val.i64
or ptr.type == lib.AV_OPT_TYPE_FLAGS
and choice_ptr.default_val.i64 & ptr.default_val.i64
)
option_choice = wrap_option_choice(
choice_ptr, choice_is_default
)
choices.append(option_choice)
choice_ptr += 1
option = wrap_option(tuple(choices), ptr)
options.append(option)
ptr += 1
self._options = tuple(options)
return self._options
def __repr__(self):
return f"<{self.__class__.__name__} {self.name} at 0x{id(self):x}>"