Skip to content

Commit

Permalink
define getter for FilterContext.graph
Browse files Browse the repository at this point in the history
  • Loading branch information
moonsikpark committed Jun 26, 2024
1 parent 851ff21 commit efbd3ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 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 object graph
cdef readonly object _graph
cdef readonly Filter filter

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

from .pad import FilterContextPad

Expand All @@ -13,3 +14,4 @@ class FilterContext:
) -> None: ...
def push(self, frame: Frame) -> None: ...
def pull(self) -> Frame: ...
def graph(self) -> Graph: ...
14 changes: 9 additions & 5 deletions av/filter/context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,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 = weakref.ref(graph)
self._graph = weakref.ref(graph)
self.filter = filter
self.ptr = ptr
return self
Expand Down Expand Up @@ -74,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 (gr := self._graph()):
return gr
else:
raise RuntimeError("graph is unallocated")

def push(self, Frame frame):
cdef int res
Expand Down Expand Up @@ -116,10 +123,7 @@ cdef class FilterContext:
raise ValueError("cannot delegate pull without linked output")
return self.outputs[0].linked.context.pull()

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

with nogil:
res = lib.av_buffersink_get_frame(self.ptr, frame.ptr)
Expand Down

0 comments on commit efbd3ed

Please sign in to comment.