o
    2j                     @   s  d dl Z d dl mZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZ e e je	 Ze e je je	  Ze dZe je jG dd	 d	Ze je je jd
dde jdede jde jfddZe je jd
dde jdede jde jfddZe je je jd
dde jdede jde jfddZe je jd
dde jdede jde jfddZe je je jd
dde jdede jdefddZe jde jdede jdefddZe jde jej  de jfdd Z!e jde jej  de jfd!d"Z"dS )#    N)NULL)libav)stash_exception)int64_tuint8_t)memcpyzOint64_t (*seek_func_t)(void *opaque, int64_t offset, int whence) noexcept nogilc                   @   s   e Zd ZdddZdd ZdS )PyIOFileNc              	   C   sb  || _ t}t| j dd }t| j dd }t| j dd }t| j dd | _t| j dd | _t| j dd | _t| j dd | _t| j dd | _| jd urU| jd urU|d u sS| rUt}|d u r^| jd u}|rq| jd u sl|d urp| spt	d	n| jd u s}|d ur| st	d
d| _
d| _ttjt|| _t| j||ttj| tt|| _|rtj| j_|| j_d S )Nreadablewritableseekablereadwriteseektellclosez@File object has no write() method, or writable() returned False.z?File object has no read() method, or readable() returned False.r   T)filer   getattrfreadfwritefseekftellfclose	pyio_seek
ValueErrorpospos_is_validcythoncastp_ucharlib	av_mallocbufferavio_alloc_contextp_void	pyio_read
pyio_write	iocontextAVIO_SEEKABLE_NORMALr   max_packet_size)selfr   buffer_size	writeable	seek_funcr	   r
   r    r-   L/var/www/html/whisper/venv/lib/python3.10/site-packages/av/container/pyio.py	__cinit__   sR   




zPyIOFile.__cinit__c                 C   s|   t j1 | jrtt | jj tt | j ntt | j W d    d S W d    d S 1 s7w   Y  d S N)r   nogilr&   r   av_freepaddressr!   )r)   r-   r-   r.   __dealloc__M   s   "zPyIOFile.__dealloc__r0   )__name__
__module____qualname__r/   r4   r-   r-   r-   r.   r      s    
9r   F)checkopaquebufbuf_sizereturnc                 C   6   t j t| ||W  d    S 1 sw   Y  d S r0   )r   gilpyio_read_gilr9   r:   r;   r-   r-   r.   r$   Z      
$r$   c              	   C   s|   z1t t| }||}t|t t jt t j|t| | jt|7  _|s-t	j
W S t|W S  ty=   t  Y S w r0   )r   r   r   r   r   r#   p_charlenr   r   AVERROR_EOF	Exceptionr   )r9   r:   r;   r)   resr-   r-   r.   r?   b   s   


r?   c                 C   r=   r0   )r   r>   pyio_write_gilr@   r-   r-   r.   r%   u   rA   r%   c                 C   sb   z$t t| }|d | }||}t|tr|n|}| j|7  _|W S  ty0   t  Y S w r0   )	r   r   r   r   
isinstanceintr   rE   r   )r9   r:   r;   r)   bytes_to_write	ret_valuebytes_writtenr-   r-   r.   rG   }   s   

rG   offsetwhencec                 C   sD   |t jkrdS tj t| ||W  d    S 1 sw   Y  d S )N)r   AVSEEK_SIZEr   r>   pyio_seek_gil)r9   rM   rN   r-   r-   r.   r      s
   

$r   c                 C   s   z7t t| }|||}|dkr||_n|dkr!| j|7  _nd|_|d u r5|jr1|j}|W S | }|W S  tyC   t  Y S w )Nr      F)	r   r   r   r   r   r   r   rE   r   )r9   rM   rN   r)   rF   r-   r-   r.   rQ      s"   
rQ   pbc                 C   s&   zt | W S  ty   t  Y S w r0   )r   
avio_closerE   r   )rS   r-   r-   r.   pyio_close_gil   s
   
rU   c                 C   sL   zt t| j}t|  |jd ur|  W dS  ty%   t  Y d S w )Nr   )	r   r   r   r9   r   
avio_flushr   rE   r   )rS   r)   r-   r-   r.   pyio_close_custom_gil   s   

rW   )#r   r   cython.cimportsr   r   cython.cimports.av.errorr   cython.cimports.libc.stdintr   r   cython.cimports.libc.stringr   typedefpointerBufconstBufCseek_func_tfinalcclassr   cfuncr1   	exceptvalr#   rI   r$   r?   r%   rG   r   rQ   AVIOContextrU   rW   r-   r-   r-   r.   <module>   sl   G
&
$
&

$	"