1- from libc.stdint cimport int32_t
2-
31from collections .abc import Mapping
42from enum import Enum
53
4+ import cython
5+ from cython .cimports .libc .stdint import int32_t
6+
67from av .sidedata .encparams import VideoEncParams
78from av .sidedata .motionvectors import MotionVectors
89
9-
10- cdef object _cinit_bypass_sentinel = object ()
10+ _cinit_bypass_sentinel = cython .declare (object , object ())
1111
1212
1313class Type (Enum ):
@@ -17,6 +17,7 @@ class Type(Enum):
1717
1818 From: https://github.com/FFmpeg/FFmpeg/blob/master/libavutil/frame.h
1919 """
20+
2021 PANSCAN = lib .AV_FRAME_DATA_PANSCAN
2122 A53_CC = lib .AV_FRAME_DATA_A53_CC
2223 STEREO3D = lib .AV_FRAME_DATA_STEREO3D
@@ -47,7 +48,8 @@ class Type(Enum):
4748 VIDEO_HINT = lib .AV_FRAME_DATA_VIDEO_HINT
4849
4950
50- cdef SideData wrap_side_data(Frame frame, int index):
51+ @cython .cfunc
52+ def wrap_side_data (frame : Frame , index : cython .int ) -> SideData :
5153 if frame .ptr .side_data [index ].type == lib .AV_FRAME_DATA_MOTION_VECTORS :
5254 return MotionVectors (_cinit_bypass_sentinel , frame , index )
5355 elif frame .ptr .side_data [index ].type == lib .AV_FRAME_DATA_VIDEO_ENC_PARAMS :
@@ -56,46 +58,60 @@ class Type(Enum):
5658 return SideData (_cinit_bypass_sentinel , frame , index )
5759
5860
59- cdef int get_display_rotation(Frame frame):
61+ @cython .cfunc
62+ def get_display_rotation (frame : Frame ) -> cython .int :
6063 for i in range (frame .ptr .nb_side_data ):
6164 if frame .ptr .side_data [i ].type == lib .AV_FRAME_DATA_DISPLAYMATRIX :
62- return int (lib.av_display_rotation_get(< const int32_t * > frame.ptr.side_data[i].data))
65+ return int (
66+ lib .av_display_rotation_get (
67+ cython .cast (
68+ cython .pointer [cython .const [int32_t ]],
69+ frame .ptr .side_data [i ].data ,
70+ )
71+ )
72+ )
6373 return 0
6474
6575
66- cdef class SideData(Buffer):
67- def __init__ (self , sentinel , Frame frame , int index ):
76+ @cython .cclass
77+ class SideData (Buffer ):
78+ def __init__ (self , sentinel , frame : Frame , index : cython .int ):
6879 if sentinel is not _cinit_bypass_sentinel :
69- raise RuntimeError (" cannot manually instantiate SideData" )
80+ raise RuntimeError ("cannot manually instatiate SideData" )
7081 self .frame = frame
7182 self .ptr = frame .ptr .side_data [index ]
7283 self .metadata = wrap_dictionary (self .ptr .metadata )
7384
74- cdef size_t _buffer_size(self ):
85+ @cython .cfunc
86+ def _buffer_size (self ) -> cython .size_t :
7587 return self .ptr .size
7688
77- cdef void * _buffer_ptr(self ):
89+ @cython .cfunc
90+ def _buffer_ptr (self ) -> cython .p_void :
7891 return self .ptr .data
7992
80- cdef bint _buffer_writable(self ):
93+ @cython .cfunc
94+ def _buffer_writable (self ) -> cython .bint :
8195 return False
8296
8397 def __repr__ (self ):
84- return f" <av.sidedata.{self.__class__.__name__} {self.ptr.size} bytes of {self.type} at 0x{<unsigned int> self.ptr.data:0x}>"
98+ return f"<av.sidedata.{ self .__class__ .__name__ } { self .ptr .size } bytes of { self .type } at 0x{ cython . cast ( cython . uint , self .ptr .data ) :0x} >"
8599
86100 @property
87101 def type (self ):
88102 return Type (self .ptr .type )
89103
90104
91- cdef class _SideDataContainer:
92- def __init__ (self , Frame frame ):
105+ @cython .cclass
106+ class _SideDataContainer :
107+ def __init__ (self , frame : Frame ):
93108 self .frame = frame
94- self ._by_index = []
95- self ._by_type = {}
109+ self ._by_index : list = []
110+ self ._by_type : dict = {}
111+
112+ i : cython .Py_ssize_t
113+ data : SideData
96114
97- cdef int i
98- cdef SideData data
99115 for i in range (self .frame .ptr .nb_side_data ):
100116 data = wrap_side_data (frame , i )
101117 self ._by_index .append (data )
0 commit comments