
    djF                         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         G d d                      Ze j        dde j        d	edz  fd
            Ze j         G d d                      ZdS )    N)PyBUF_WRITABLEPyBuffer_FillInfo)PyBUF_SIMPLEPyBuffer_ReleasePyObject_CheckBufferPyObject_GetBuffer)memcpyc                       e Zd Zd Zd ZdS )
ByteSourcec                    || _         	 || _        t          |          | _        d S # t          $ r Y nw xY wt          |          rwt          |t          j        | j	                  t                    }|sHd| _        t          j        t          j        | j	        j                  | _        | j	        j        | _        d S 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      D/home/agentuser/manim-venv/lib/python3.11/site-packages/av/buffer.py	__cinit__zByteSource.__cinit__   s    
	DH e**DKF	  	 	 	D	  && 	$UFN49,E,E|TTC  $!;v~ty}EE"imABBBs   & 
33c                 d    | j         r(t          t          j        | j                             d S d S N)r   r   r   r   r   r   s    r   __dealloc__zByteSource.__dealloc__$   s6    = 	8V^DI6677777	8 	8    N)__name__
__module____qualname__r   r     r!   r   r   r      s5        C C C,8 8 8 8 8r!   r   F
allow_nonereturnc                 Z    |r| d S t          | t                    r| S t          |           S r   )
isinstancer   )objr&   s     r   
bytesourcer+   )   s6     ckt	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dS )BufferzxA base class for PyAV objects which support the buffer protocol, such
    as :class:`.Packet` and :class:`.Plane`.

    r'   c                     dS )Nr   r%   r   s    r   _buffer_sizezBuffer._buffer_size:   s    qr!   c                     t           j        S r   )r   NULLr   s    r   _buffer_ptrzBuffer._buffer_ptr>   s
    {r!   c                     dS )NTr%   r   s    r   _buffer_writablezBuffer._buffer_writableA   s    tr!   r   flagsc                     |t           z  r#|                                 st          d          t          || |                                 |                                 d|           d S )Nbuffer is not writabler   )r   r4   
ValueErrorr   r2   r/   )r   r   r5   s      r   __getbuffer__zBuffer.__getbuffer__D   sh    >! 	7$*?*?*A*A 	75666$d&6&6&8&8$:K:K:M:MqRWXXXXXr!   c                 *    |                                  S r   )r/   r   s    r   buffer_sizezBuffer.buffer_sizeJ   s      """r!   c                 d    t          j        t           j        |                                           S )z!The memory address of the buffer.)r   r   size_tr2   r   s    r   
buffer_ptrzBuffer.buffer_ptrN   s$     {6=$*:*:*<*<===r!   c                 .   |                                  st          d          t          |          }|                                 }|j        |k    rt          d|j         d| d          t          |                                 |j        |           dS )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.updateS   s     $$&& 	75666'.."//11=D  LFMLLLLLMMMt!!6:t44444r!   N)r"   r#   r$   __doc__r   cfuncr=   r/   p_voidr2   bintr4   pointer	Py_bufferintr9   propertyr;   r>   rC   r%   r!   r   r-   r-   3   s         
 \fm    \V]    &+    Y&."; YFJ Y Y Y Y # # X# > > X>5 5 5 5 5r!   r-   )F)r   cython.cimports.cpythonr   r   cython.cimports.cpython.bufferr   r   r   r   cython.cimports.libc.stringr	   cclassr   rE   rG   r+   r-   r%   r!   r   <module>rP      s(    E E E E E E E E            / . . . . . 8 8 8 8 8 8 8 88   
T8I     /5 /5 /5 /5 /5 /5 /5 /5 /5 /5r!   