
    \jT                        d dl Z d dlmZmZ d dlmZmZmZmZ d dl	m
Z
 e j                  e j                   G d d                    Ze j                  dde j                  dedz  fd	       Ze j                   G d
 d             Zy)    N)PyBUF_WRITABLEPyBuffer_FillInfo)PyBUF_SIMPLEPyBuffer_ReleasePyObject_CheckBufferPyObject_GetBuffer)memcpyc                       e Zd Zd Zd Zy)
ByteSourcec                    || _         	 || _        t        |      | _        y # t        $ r Y nw xY wt        |      rt        |t        j                  | j                        t              }|s`d| _        t        j                  t        j                  | j                  j                        | _        | j                  j                  | _        y t	        d      )NTz'expected bytes, bytearray or memoryview)ownerptrlenlength	TypeErrorr   r   cythonaddressviewr   has_viewcastp_ucharbuf)selfr   ress      </root/.hermes/venv/lib/python3.12/site-packages/av/buffer.py	__cinit__zByteSource.__cinit__   s    
	DH e*DK	  		  &$UFNN499,E|TC $!;;v~~tyy}}E"iimmABBs   ! 	--c                 n    | j                   r)t        t        j                  | j                               y y N)r   r   r   r   r   r   s    r   __dealloc__zByteSource.__dealloc__%   s#    ==V^^DII67     N)__name__
__module____qualname__r   r     r!   r   r   r      s    C,8r!   r   
allow_nonereturnc                 F    |r| y t        | t              r| S t        |       S r   )
isinstancer   )objr&   s     r   
bytesourcer+   *   s%    ck	C	$
#r!   c                       e Zd ZdZej
                  dej                  fd       Zdej                  fdZ	dej                  fdZdej                  e   dej                  fdZed	        Zed
        Zd Zy)BufferzxA base class for PyAV objects which support the buffer protocol, such
    as :class:`.Packet` and :class:`.Plane`.

    r'   c                      y)Nr   r%   r   s    r   _buffer_sizezBuffer._buffer_size;   s    r!   c                 "    t         j                  S r   )r   NULLr   s    r   _buffer_ptrzBuffer._buffer_ptr?   s    {{r!   c                      y)NTr%   r   s    r   _buffer_writablezBuffer._buffer_writableB   s    r!   r   flagsc                     |t         z  r| j                         st        d      t        || | j	                         | j                         d|       y )Nbuffer is not writabler   )r   r4   
ValueErrorr   r2   r/   )r   r   r5   s      r   __getbuffer__zBuffer.__getbuffer__E   sF    >!$*?*?*A566$d&6&6&8$:K:K:MqRWXr!   c                 "    | j                         S r   )r/   r   s    r   buffer_sizezBuffer.buffer_sizeK   s      ""r!   c                 f    t        j                  t         j                  | j                               S )z!The memory address of the buffer.)r   r   size_tr2   r   s    r   
buffer_ptrzBuffer.buffer_ptrO   s"     {{6==$*:*:*<==r!   c                    | j                         st        d      t        |      }| j                         }|j                  |k7  rt        d|j                   d| d      t        | j                         |j                  |       y)zReplace the data in this object with the given buffer.

        Accepts anything that supports the `buffer protocol <https://docs.python.org/3/c-api/buffer.html>`_,
        e.g. bytes, NumPy arrays, other :class:`Buffer` objects, etc..

        r7   zgot z bytes; need z bytesN)r4   r8   r+   r/   r   r	   r2   r   )r   inputsourcesizes       r   updatezBuffer.updateT   sw     $$&566'."//1==D tFMM?-vVLMMt!6::t4r!   N)r"   r#   r$   __doc__r   cfuncr=   r/   p_voidr2   bintr4   pointer	Py_bufferintr9   propertyr;   r>   rC   r%   r!   r   r-   r-   4   s    
 \\fmm  V]] &++ Y&.."; YFJJ Y # # > >5r!   r-   )F)r   cython.cimports.cpythonr   r   cython.cimports.cpython.bufferr   r   r   r   cython.cimports.libc.stringr	   finalcclassr   rE   rG   r+   r-   r%   r!   r   <module>rQ      s     E  / 8 8  88  
T8I   /5 /5 /5r!   