1- from cpython cimport PyBUF_WRITABLE, PyBuffer_FillInfo
2- from libc.string cimport memcpy
1+ import cython
2+ from cython .cimports .av .bytesource import ByteSource , bytesource
3+ from cython .cimports .cpython import PyBUF_WRITABLE , PyBuffer_FillInfo
4+ from cython .cimports .libc .string import memcpy
35
4- from av.bytesource cimport ByteSource, bytesource
56
6-
7- cdef class Buffer:
7+ @ cython . cclass
8+ class Buffer :
89 """A base class for PyAV objects which support the buffer protocol, such
910 as :class:`.Packet` and :class:`.Plane`.
1011
1112 """
1213
13- cdef size_t _buffer_size(self ):
14+ @cython .cfunc
15+ def _buffer_size (self ) -> cython .size_t :
1416 return 0
1517
16- cdef void * _buffer_ptr(self ):
17- return NULL
18+ def _buffer_ptr (self ) -> cython . p_void :
19+ return cython . NULL
1820
19- cdef bint _buffer_writable(self ):
21+ def _buffer_writable (self ) -> cython . bint :
2022 return True
2123
22- def __getbuffer__ (self , Py_buffer * view , int flags ):
24+ def __getbuffer__ (self , view : cython . pointer [ Py_buffer ], flags : cython . int ):
2325 if flags & PyBUF_WRITABLE and not self ._buffer_writable ():
2426 raise ValueError ("buffer is not writable" )
2527
@@ -33,20 +35,20 @@ def buffer_size(self):
3335 @property
3436 def buffer_ptr (self ):
3537 """The memory address of the buffer."""
36- return < size_t> self ._buffer_ptr()
38+ return cython . cast ( cython . size_t , self ._buffer_ptr () )
3739
3840 def update (self , input ):
3941 """Replace the data in this object with the given buffer.
4042
4143 Accepts anything that supports the `buffer protocol <https://docs.python.org/3/c-api/buffer.html>`_,
42- e.g. bytes, Numpy arrays, other :class:`Buffer` objects, etc..
44+ e.g. bytes, NumPy arrays, other :class:`Buffer` objects, etc..
4345
4446 """
4547 if not self ._buffer_writable ():
4648 raise ValueError ("buffer is not writable" )
4749
48- cdef ByteSource source = bytesource(input )
49- cdef size_t size = self ._buffer_size()
50+ source : ByteSource = bytesource (input )
51+ size : cython . size_t = self ._buffer_size ()
5052
5153 if source .length != size :
5254 raise ValueError (f"got { source .length } bytes; need { size } bytes" )
0 commit comments