
    m i                         d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
  e            Ze j        defd            Zd	d	d
d
ddddddd
Ze j         G d de                      ZdS )    N)get_audio_format)get_audio_layout
AudioPlane)	err_check)check_ndarrayreturnc                  *    t          t                    S N)
AudioFrame_cinit_bypass_sentinel     N/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/av/audio/frame.pyalloc_audio_framer      s    ,---r   f8f4i2i4u1)
dbldblpfltfltps16s16ps32s32pu8u8pc            	       V   e Zd ZdZddZej        dej        dej	        d	ej
        d
ej
        fd            Zd Zej        d             Zd Zedd            Zed             Zed             Zed             Zej        d             Zed             Zej        d             Zd ZdS )r   zA frame of audio.r   stereor      c                     |t           u rd S t          |          }t          |          }|                     |j        |j        ||           d S r   )r   AudioFormatAudioLayout_init
sample_fmtlayout)selfformatr)   samplesalign	cy_format	cy_layouts          r   	__cinit__zAudioFrame.__cinit__"   sQ    +++F!,V!4!4	!,V!4!4	

9')97EJJJJJr   r+   r)   
nb_samplesr-   c           
      ,   || j         _        || j         _        || j         _        |                                  | j        j        dk    rH|rGt                              t          j
        | j                             t          t                              t          j        | j        j        |||                    | _        t          j        t          j        t$                   t                              | j                            | _        | j        st)          d          t          t                              | j         | j        j        t          j        t          j        | j         j                  | j        | j        |                     d S d S d S )Nr   z!cannot allocate AudioFrame buffer)ptrr1   r+   	ch_layout_init_user_attributesr)   nb_channelslibav_freepcythonaddress_bufferr   av_samples_get_buffer_sizeNULL_buffer_sizecastpointeruint8_t	av_mallocMemoryErroravcodec_fill_audio_frameAVSampleFormat)r*   r+   r)   r1   r-   s        r   r'   zAudioFrame._init*   s]    ) # 	""$$$;"a''J'LL55666 !*..K!8*fe ! !D
 ";w't7H)I)I DL < G!"EFFF ,,HK+K 2DHODDL% 	 	 	 	 	# ('''r   c                 h    t                               t          j        | j                             d S r   )r7   r8   r9   r:   r;   r*   s    r   __dealloc__zAudioFrame.__dealloc__U   s&    V^DL1122222r   c                     t          | j        j                  | _        t	          t          j        t          j        | j        j	                            | _	        d S r   )
r   r3   r4   r)   r   r9   r?   r7   rE   r+   rG   s    r   r5   z AudioFrame._init_user_attributesX   s<    &tx'9::&v{33Etx'W'WXXr   c                     d| j         j         d| j         d| j         d| j         d| j        j         d| j        j         dt          |           ddS )	Nz<av.z pts=z, z samples at zHz, z at 0xx>)		__class____name__ptsr,   rater)   namer+   idrG   s    r   __repr__zAudioFrame.__repr__]   s    c4>* c c c cT\ c c)c c)-)9c c=A[=Mc cUWX\U]U]bc c c	
r   c                    ddl }t          |t                    r|nt          |          }t          |t                    r|nt          |          }|j        }	 |                    t          |                   }n!# t          $ r t          d| d          w xY w|j	        }t          | |d           |j        r@| j        d         |k    r!t          d| d| j        d          d          | j        d	         }n?| j        d         d	k    rt          d
| j        d          d          | j        d	         |z  }t          |||          }	t          |	j                  D ]$\  }
}|                    | |
ddf                    %|	S )z7
        Construct a frame from a numpy array.
        r   Nz)Conversion from numpy array with format `z` is not yet supported   z+Expected planar `array.shape[0]` to equal `z` but got ``r#   z7Expected packed `array.shape[0]` to equal `1` but got `)r+   r)   r,   )numpy
isinstancer%   r&   rQ   dtypeformat_dtypesKeyError
ValueErrorr6   r   	is_planarshaper   	enumerateplanesupdate)arrayr+   r)   np	py_format	py_layoutrY   r6   r,   frameiplanes               r   from_ndarrayzAudioFrame.from_ndarrayc   s   
 	(==VFF;vCVCV	(==VFF;vCVCV		HH]6233EE 	 	 	ZFZZZ  	  +eUA&&& 	4{1~,, k+kkZ_ZefgZhkkk   k!nGG{1~"" _ekZ[n___   k!n3G)IwOOO!%,// 	& 	&HAuLLq!!!t%%%%s    A: :Bc                      d} j         j        |         r|dz  } j         j        |         t           fdt          |          D                       S )zW
        A tuple of :class:`~av.audio.plane.AudioPlane`.

        :type: tuple
        r   r#   c                 0    g | ]}t          |          S r   r   ).0rg   r*   s     r   
<listcomp>z%AudioFrame.planes.<locals>.<listcomp>   s#    FFFajq))FFFr   )r3   extended_datatuplerange)r*   plane_counts   ` r   r`   zAudioFrame.planes   sg     #$h$[1 	1K h$[1 	 FFFF53E3EFFFGGGr   c                     | j         j        S )zL
        Number of audio samples (per channel).

        :type: int
        )r3   r1   rG   s    r   r,   zAudioFrame.samples   s     x""r   c                     | j         j        S )z[
        Sample rate of the audio data, in samples per second.

        :type: int
        r3   sample_raterG   s    r   ru   zAudioFrame.sample_rate   s     x##r   c                     || j         _        d S r   rt   r*   values     r   ru   zAudioFrame.sample_rate       $r   c                     | j         j        S )z%Another name for :attr:`sample_rate`.rt   rG   s    r   rP   zAudioFrame.rate   s     x##r   c                     || j         _        d S r   rt   rw   s     r   rP   zAudioFrame.rate   ry   r   c                 ^   ddl 	                     t          | j        j                           n+# t
          $ r t          d| j        j        d          w xY w| j        j        r| j        n| j        | j	        j
        z                      fd| j        D                       S )zVGet a numpy array of this frame.

        .. note:: Numpy must be installed.

        r   NzConversion from z( format to numpy array is not supported.c                 @    g | ]}                     |           S ))rY   count)
frombuffer)rl   rK   r~   rY   rc   s     r   rm   z)AudioFrame.to_ndarray.<locals>.<listcomp>   s+    MMMAR]]1E]77MMMr   )rW   rY   rZ   r+   rQ   r[   r\   r]   r,   r)   r6   vstackr`   )r*   r~   rY   rc   s    @@@r   
to_ndarrayzAudioFrame.to_ndarray   s     		HH]4;+;<==EE 	 	 	_4;#3___  	
 ;  	;LEEL4;#::EyyMMMMMMMMM
 
 	
s	   *4 (AN)r   r"   r   r#   )r   r"   )rN   
__module____qualname____doc__r0   r9   cfuncr7   rE   AVChannelLayoutuintr'   rH   r5   rS   staticmethodri   propertyr`   r,   ru   setterrP   r   r   r   r   r   r      s       K K K K \("( #( K	(
 {( ( ( \(T3 3 3 \Y Y \Y
 
 
 % % % \%N 
H 
H X
H # # X# $ $ X$ % % % $ $ X$ 
[% % [%
 
 
 
 
r   r   )r9   cython.cimports.av.audio.formatr   cython.cimports.av.audio.layoutr   cython.cimports.av.audio.planer   cython.cimports.av.errorr   cython.cimports.av.utilsr   objectr   r   r   r   rZ   cclassFramer   r   r   <module>r      s    < < < < < < < < < < < < 5 5 5 5 5 5 . . . . . . 2 2 2 2 2 2  .: . . . .
 
  n
 n
 n
 n
 n
 n
 n
 n
 n
 n
r   