Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion av/filter/link.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from av.filter.link cimport FilterContextPad, FilterLink


cdef class FilterLink:
cdef readonly Graph graph
cdef object _graph
cdef lib.AVFilterLink *ptr

cdef FilterContextPad _input
Expand Down
17 changes: 14 additions & 3 deletions av/filter/link.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import weakref

import cython
import cython.cimports.libav as lib
from cython.cimports.av.filter.graph import Graph
Expand All @@ -12,6 +14,13 @@ def __cinit__(self, sentinel):
if sentinel is not _cinit_sentinel:
raise RuntimeError("cannot instantiate FilterLink")

@property
def graph(self) -> Graph:
if g := self._graph():
return g
else:
raise RuntimeError("graph is unallocated")

@property
def input(self):
if self._input:
Expand All @@ -23,7 +32,8 @@ def input(self):
break
else: # nobreak
raise RuntimeError("could not find link in context")
ctx = self.graph._context_by_ptr[cython.cast(cython.long, cctx)]
graph: Graph = self.graph
ctx = graph._context_by_ptr[cython.cast(cython.long, cctx)]
self._input = ctx.outputs[i]
return self._input

Expand All @@ -39,7 +49,8 @@ def output(self):
else:
raise RuntimeError("could not find link in context")
try:
ctx = self.graph._context_by_ptr[cython.cast(cython.long, cctx)]
graph: Graph = self.graph
ctx = graph._context_by_ptr[cython.cast(cython.long, cctx)]
except KeyError:
raise RuntimeError(
"could not find context in graph", (cctx.name, cctx.filter.name)
Expand All @@ -51,7 +62,7 @@ def output(self):
@cython.cfunc
def wrap_filter_link(graph: Graph, ptr: cython.pointer[lib.AVFilterLink]) -> FilterLink:
link: FilterLink = FilterLink(_cinit_sentinel)
link.graph = graph
link._graph = weakref.ref(graph)
link.ptr = ptr
return link

Expand Down
Loading