o
    2j                     @   s|   d dl Z d dlmZ d dlmZmZ d dlmZm	Z	 d dl
mZmZ d dlmZ d dlmZ e je jG dd	 d	eZdS )
    N)libav)AudioFormatget_audio_format)
AudioFramealloc_audio_frame)AudioLayoutget_audio_layout)Frame)Packetc                   @   s   e Zd ZejdedB defddZejdefddZejded	e	fd
dZ
edd Zedd ZejdejfddZedd Zejdd Zedd Zedd Zejdd Zedd Zejdd ZdS )AudioCodecContextinput_frameNreturnc                 C   sb   |}| j jjtj@ }| js t| j| j| j j	|rd n| j j
d| _| j|}|d u r/|d  |S )N)formatlayoutrate
frame_size)ptrcodeccapabilitieslib AV_CODEC_CAP_VARIABLE_FRAME_SIZE	resamplerAudioResamplerr   r   sample_rater   resampleappend)selfr   frameallow_var_frame_sizeframes r    P/var/www/html/whisper/venv/lib/python3.10/site-packages/av/audio/codeccontext.py_prepare_frames_for_encode   s   
z,AudioCodecContext._prepare_frames_for_encodec                 C   s   t  S N)r   r   r    r    r!   _alloc_next_frame#   s   z#AudioCodecContext._alloc_next_framer   packetc                 C   s   t | || |}|  d S r#   )CodecContext_setup_decoded_frame_init_user_attributes)r   r   r&   aframer    r    r!   r(   '   s   z&AudioCodecContext._setup_decoded_framec                 C      | j jS )zV
        Number of samples per channel in an audio frame.

        :type: int
        )r   r   r$   r    r    r!   r   -      zAudioCodecContext.frame_sizec                 C   r+   )z[
        Sample rate of the audio data, in samples per second.

        :type: int
        r   r   r$   r    r    r!   r   6   r,   zAudioCodecContext.sample_ratevaluec                 C   s   || j _d S r#   r-   r   r.   r    r    r!   r   ?   s   c                 C   s   | j S )z%Another name for :attr:`sample_rate`.r   r$   r    r    r!   r   C   s   zAudioCodecContext.ratec                 C   s
   || _ d S r#   r0   r/   r    r    r!   r   H   s   
c                 C   r+   r#   )r   nb_channelsr$   r    r    r!   channelsL   s   zAudioCodecContext.channelsc                 C      t | jjS )zG
        The audio channel layout.

        :type: AudioLayout
        )r   r   	ch_layoutr$   r    r    r!   r   P      zAudioCodecContext.layoutc                 C   s   t |}|j| j_d S r#   )r   r   r   r4   )r   r.   r   r    r    r!   r   Y      c                 C   r3   )zF
        The audio sample format.

        :type: AudioFormat
        )r   r   
sample_fmtr$   r    r    r!   r   ^   r5   zAudioCodecContext.formatc                 C   s   t |}|j| j_d S r#   )r   r7   r   )r   r.   r   r    r    r!   r   g   r6   )__name__
__module____qualname__cythoncfuncr	   listr"   r%   r
   r(   propertyr   r   setterintr   r2   r   r   r    r    r    r!   r   
   s6    







r   )r;   cython.cimportsr   r   cython.cimports.av.audio.formatr   r   cython.cimports.av.audio.framer   r   cython.cimports.av.audio.layoutr   r   cython.cimports.av.framer	   cython.cimports.av.packetr
   finalcclassr'   r   r    r    r    r!   <module>   s    