1- cimport libav as lib
2- from libc.errno cimport EAGAIN
3-
4- from av.error cimport err_check
5- from av.packet cimport Packet
6- from av.stream cimport Stream
7-
8-
9- cdef class BitStreamFilterContext:
1+ import cython
2+ import cython . cimports . libav as lib
3+ from cython . cimports . libc . errno import EAGAIN
4+ from cython . cimports . av .error import err_check
5+ from cython . cimports . av .packet import Packet
6+ from cython . cimports . av .stream import Stream
7+
8+ @ cython . cclass
9+ class BitStreamFilterContext :
1010 """
1111 Initializes a bitstream filter: a way to directly modify packet data.
1212
1515 :param Stream in_stream: A stream that defines the input codec for the bitfilter.
1616 :param Stream out_stream: A stream whose codec is overwritten using the output parameters from the bitfilter.
1717 """
18- def __cinit__ (self , filter_description , Stream in_stream = None , Stream out_stream = None ):
19- cdef int res
20- cdef char * filter_str = filter_description
18+ def __cinit__ (self , filter_description , in_stream : Stream | None = None , out_stream : Stream | None = None ):
19+ res : cython . int
20+ filter_str : cython . p_char = filter_description
2121
22- with nogil:
23- res = lib.av_bsf_list_parse_str(filter_str, & self .ptr)
22+ with cython . nogil :
23+ res = lib .av_bsf_list_parse_str (filter_str , cython . address ( self .ptr ) )
2424 err_check (res )
2525
2626 if in_stream is not None :
27- with nogil:
27+ with cython . nogil :
2828 res = lib .avcodec_parameters_copy (self .ptr .par_in , in_stream .ptr .codecpar )
2929 err_check (res )
3030
31- with nogil:
31+ with cython . nogil :
3232 res = lib .av_bsf_init (self .ptr )
3333 err_check (res )
3434
3535 if out_stream is not None :
36- with nogil:
36+ with cython . nogil :
3737 res = lib .avcodec_parameters_copy (out_stream .ptr .codecpar , self .ptr .par_out )
3838 err_check (res )
3939 lib .avcodec_parameters_to_context (out_stream .codec_context .ptr , out_stream .ptr .codecpar )
4040
4141 def __dealloc__ (self ):
4242 if self .ptr :
43- lib.av_bsf_free(& self .ptr)
43+ lib .av_bsf_free (cython . address ( self .ptr ) )
4444
45- cpdef filter (self , Packet packet = None ):
45+ @cython .ccall
46+ def filter (self , packet : Packet | None = None ):
4647 """
4748 Processes a packet based on the filter_description set during initialization.
4849 Multiple packets may be created.
4950
5051 :type: list[Packet]
5152 """
52- cdef int res
53- cdef Packet new_packet
53+ res : cython . int
54+ new_packet : Packet
5455
55- with nogil:
56- res = lib.av_bsf_send_packet(self .ptr, packet.ptr if packet is not None else NULL )
56+ with cython . nogil :
57+ res = lib .av_bsf_send_packet (self .ptr , packet .ptr if packet is not None else cython . NULL )
5758 err_check (res )
5859
59- output = []
60+ output : list = []
6061 while True :
6162 new_packet = Packet ()
62- with nogil:
63+ with cython . nogil :
6364 res = lib .av_bsf_receive_packet (self .ptr , new_packet .ptr )
6465
6566 if res == - EAGAIN or res == lib .AVERROR_EOF :
@@ -71,20 +72,22 @@ def __dealloc__(self):
7172
7273 output .append (new_packet )
7374
74- cpdef flush(self ):
75+ @cython .ccall
76+ def flush (self ):
7577 """
7678 Reset the internal state of the filter.
7779 Should be called e.g. when seeking.
7880 Can be used to make the filter usable again after draining it with EOF marker packet.
7981 """
8082 lib .av_bsf_flush (self .ptr )
8183
82- cdef get_filter_names():
83- names = set ()
84- cdef const lib.AVBitStreamFilter * ptr
85- cdef void * opaque = NULL
84+ @cython .cfunc
85+ def get_filter_names () -> set :
86+ names : set = set ()
87+ ptr : cython .pointer [cython .const [lib .AVBitStreamFilter ]]
88+ opaque : cython .p_void = cython .NULL
8689 while True :
87- ptr = lib.av_bsf_iterate(& opaque)
90+ ptr = lib .av_bsf_iterate (cython . address ( opaque ) )
8891 if ptr :
8992 names .add (ptr .name )
9093 else :
0 commit comments