o
    ]i'                     @   sP   d dl mZ d dlZd dlmZ d dlmZ d dlmZ ej	G dd dZ
dS )    )EAGAINN)FilterContext)Graph)FFmpegErrorc                   @   s6   e Zd ZdZd	ddZejdedB defddZ	dS )
AudioResampleraB  AudioResampler(format=None, layout=None, rate=None)

    :param AudioFormat format: The target format, or string that parses to one
        (e.g. ``"s16"``).
    :param AudioLayout layout: The target layout, or an int/string that parses
        to one (e.g. ``"stereo"``).
    :param int rate: The target sample rate.
    Nc                 C   s`   |d urt |tr|nt|| _|d urt|| _|rt|nd| _|r(t|nd| _d | _d S )Nr   )	
isinstanceAudioFormatformatAudioLayoutlayoutintrate
frame_sizegraph)selfr	   r   r   r    r   F/home/ubuntu/.local/lib/python3.10/site-packages/av/audio/resampler.py	__cinit__   s   

zAudioResampler.__cinit__framereturnc              
   C   s  | j s	|du r	g S | jr|gS | j s|| _| jp|j| _| jp!|j| _| jp(|j| _|jj| jjkrI|j| jkrI|j| jkrI| jdkrId| _|gS t	 | _ i }|j
durZ|j
 |d< | j j	d|j t|jj|jjd|}| j jd| j | jj| jjd}| j d	}|| || | j   | jdkr| j | j |dur|jj| jjjks|j| jjks|j| jjkrtd
| j | g }	 z
|| j   W n" ty   Y |S  ty } z|jtkr W Y d}~|S d}~ww q)ao  resample(frame)

        Convert the ``sample_rate``, ``channel_layout`` and/or ``format`` of
        a :class:`~.AudioFrame`.

        :param AudioFrame frame: The frame to convert or `None` to flush.
        :returns: A list of :class:`AudioFrame` in new parameters. If the nothing is to be done return the same frame
            as a single element list.

        Nr   T	time_baseabuffer)sample_rate
sample_fmtchannel_layoutaformat)sample_ratessample_fmtschannel_layoutsabuffersinkz*Frame does not match AudioResampler setup.)r   )r   is_passthroughtemplater	   r   r   r   r   r   r   r   addr   namelink_to	configureset_audio_frame_size
ValueErrorpushappendpullEOFErrorr   errnor   )r   r   
extra_argsr   r   r   outputer   r   r   resample"   sz   








zAudioResampler.resample)NNNN)
__name__
__module____qualname____doc__r   cythonccall
AudioFramelistr0   r   r   r   r   r   
   s
    
	r   )r,   r   r5   !cython.cimports.av.filter.contextr   cython.cimports.av.filter.graphr   av.errorr   cclassr   r   r   r   r   <module>   s    