1- from libc.stdint cimport int32_t
2-
31from collections .abc import Mapping
42from enum import Enum
53
6- from av.sidedata.encparams import VideoEncParams
7- from av.sidedata.motionvectors import MotionVectors
4+ import cython
5+ from cython . cimports . libc . stdint import int32_t
86
7+ from av .sidedata .motionvectors import MotionVectors
98
10- cdef object _cinit_bypass_sentinel = object ( )
9+ _cinit_bypass_sentinel = cython . declare ( object , object () )
1110
1211
1312class Type (Enum ):
@@ -17,6 +16,7 @@ class Type(Enum):
1716
1817 From: https://github.com/FFmpeg/FFmpeg/blob/master/libavutil/frame.h
1918 """
19+
2020 PANSCAN = lib .AV_FRAME_DATA_PANSCAN
2121 A53_CC = lib .AV_FRAME_DATA_A53_CC
2222 STEREO3D = lib .AV_FRAME_DATA_STEREO3D
@@ -47,7 +47,8 @@ class Type(Enum):
4747 VIDEO_HINT = lib .AV_FRAME_DATA_VIDEO_HINT
4848
4949
50- cdef SideData wrap_side_data(Frame frame, int index):
50+ @cython .cfunc
51+ def wrap_side_data (frame : Frame , index : cython .int ) -> SideData :
5152 if frame .ptr .side_data [index ].type == lib .AV_FRAME_DATA_MOTION_VECTORS :
5253 return MotionVectors (_cinit_bypass_sentinel , frame , index )
5354 elif frame .ptr .side_data [index ].type == lib .AV_FRAME_DATA_VIDEO_ENC_PARAMS :
@@ -56,46 +57,60 @@ class Type(Enum):
5657 return SideData (_cinit_bypass_sentinel , frame , index )
5758
5859
59- cdef int get_display_rotation(Frame frame):
60+ @cython .cfunc
61+ def get_display_rotation (frame : Frame ) -> cython .int :
6062 for i in range (frame .ptr .nb_side_data ):
6163 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))
64+ return int (
65+ lib .av_display_rotation_get (
66+ cython .cast (
67+ cython .pointer [cython .const [int32_t ]],
68+ frame .ptr .side_data [i ].data ,
69+ )
70+ )
71+ )
6372 return 0
6473
6574
66- cdef class SideData(Buffer):
67- def __init__ (self , sentinel , Frame frame , int index ):
75+ @cython .cclass
76+ class SideData (Buffer ):
77+ def __init__ (self , sentinel , frame : Frame , index : cython .int ):
6878 if sentinel is not _cinit_bypass_sentinel :
69- raise RuntimeError (" cannot manually instantiate SideData" )
79+ raise RuntimeError ("cannot manually instatiate SideData" )
7080 self .frame = frame
7181 self .ptr = frame .ptr .side_data [index ]
7282 self .metadata = wrap_dictionary (self .ptr .metadata )
7383
74- cdef size_t _buffer_size(self ):
84+ @cython .cfunc
85+ def _buffer_size (self ) -> cython .size_t :
7586 return self .ptr .size
7687
77- cdef void * _buffer_ptr(self ):
88+ @cython .cfunc
89+ def _buffer_ptr (self ) -> cython .p_void :
7890 return self .ptr .data
7991
80- cdef bint _buffer_writable(self ):
92+ @cython .cfunc
93+ def _buffer_writable (self ) -> cython .bint :
8194 return False
8295
8396 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}>"
97+ return f"<av.sidedata.{ self .__class__ .__name__ } { self .ptr .size } bytes of { self .type } at 0x{ cython . cast ( cython . uint , self .ptr .data ) :0x} >"
8598
8699 @property
87100 def type (self ):
88101 return Type (self .ptr .type )
89102
90103
91- cdef class _SideDataContainer:
92- def __init__ (self , Frame frame ):
104+ @cython .cclass
105+ class _SideDataContainer :
106+ def __init__ (self , frame : Frame ):
93107 self .frame = frame
94- self ._by_index = []
95- self ._by_type = {}
108+ self ._by_index : list = []
109+ self ._by_type : dict = {}
110+
111+ i : cython .Py_ssize_t
112+ data : SideData
96113
97- cdef int i
98- cdef SideData data
99114 for i in range (self .frame .ptr .nb_side_data ):
100115 data = wrap_side_data (frame , i )
101116 self ._by_index .append (data )
0 commit comments