Skip to content

Commit

Permalink
remove circular reference between Graph and FilterContext
Browse files Browse the repository at this point in the history
  • Loading branch information
moonsikpark committed Jun 24, 2024
1 parent 96a0527 commit 851ff21
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
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
9 changes: 7 additions & 2 deletions 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 @@ -114,7 +116,10 @@ cdef class FilterContext:
raise ValueError("cannot delegate pull without linked output")
return self.outputs[0].linked.context.pull()

self.graph.configure()
if (gr := self.graph()):
gr.configure()
else:
raise RuntimeError("graph is dead")

with nogil:
res = lib.av_buffersink_get_frame(self.ptr, frame.ptr)
Expand Down
1 change: 1 addition & 0 deletions av/filter/graph.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from av.filter.context cimport FilterContext


cdef class Graph:
cdef object __weakref__

cdef lib.AVFilterGraph *ptr

Expand Down

0 comments on commit 851ff21

Please sign in to comment.