Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove circular reference between Graph and FilterContext #1439

Merged
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/context.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from av.filter.graph cimport Graph
cdef class FilterContext:

cdef lib.AVFilterContext *ptr
cdef readonly Graph graph
cdef readonly object _graph
cdef readonly Filter filter

cdef object _inputs
Expand Down
3 changes: 3 additions & 0 deletions av/filter/context.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from av.filter import Graph
from av.frame import Frame

from .pad import FilterContextPad
Expand All @@ -11,5 +12,7 @@ class FilterContext:
def link_to(
self, input_: FilterContext, output_idx: int = 0, input_idx: int = 0
) -> None: ...
@property
def graph(self) -> Graph: ...
def push(self, frame: Frame) -> None: ...
def pull(self) -> Frame: ...
11 changes: 10 additions & 1 deletion av/filter/context.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import weakref

from av.audio.frame cimport alloc_audio_frame
from av.dictionary cimport _Dictionary
from av.dictionary import Dictionary
Expand All @@ -13,7 +15,7 @@ cdef object _cinit_sentinel = object()

cdef FilterContext wrap_filter_context(Graph graph, Filter filter, lib.AVFilterContext *ptr):
cdef FilterContext self = FilterContext(_cinit_sentinel)
self.graph = graph
self._graph = weakref.ref(graph)
self.filter = filter
self.ptr = ptr
return self
Expand Down Expand Up @@ -72,6 +74,13 @@ cdef class FilterContext:

def link_to(self, FilterContext input_, int output_idx=0, int input_idx=0):
err_check(lib.avfilter_link(self.ptr, output_idx, input_.ptr, input_idx))

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

def push(self, Frame frame):
cdef int res
Expand Down
2 changes: 2 additions & 0 deletions av/filter/graph.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ from av.filter.context cimport FilterContext


cdef class Graph:
cdef object __weakref__

cdef lib.AVFilterGraph *ptr

cdef readonly bint configured
Expand Down
Loading