
    Hui'                     n    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             Z
y)    )EAGAINN)FilterContext)Graph)FFmpegErrorc                   L    e Zd ZdZddZej                  dedz  defd       Z	y)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                     |"t        |t              r|n
t        |      | _        |t        |      | _        |rt        |      nd| _        |rt        |      nd| _        d | _        y )Nr   )	
isinstanceAudioFormatformatAudioLayoutlayoutintrate
frame_sizegraph)selfr   r   r   r   s        D/opt/pipecat/venv/lib/python3.12/site-packages/av/audio/resampler.py	__cinit__zAudioResampler.__cinit__   s[    $V[9{6?R K %f-DK!%CI1	-7#j/Q
    framereturnc                    | j                   s|g S | j                  r|gS | j                   sC|| _        | j                  xs |j                  | _        | j                  xs |j                  | _        | j
                  xs |j                  | _        |j                  j                  | j                  j                  k(  rK|j                  | j                  k(  r2|j                  | j
                  k(  r| j                  dk(  r
d| _        |gS t               | _         i }|j                  |j                   |d<    | j                   j                  	 d
|j                   t        |j                        j                  |j                  j                  d|}| j                   j                  d| j
                   | j                  j                  | j                  j                        }| j                   j                  d      }|j                  |       |j                  |       | j                   j                          | j                  dkD  r%| j                   j!                  | j                         ||j                  j                  | j                  j                  j                  k7  sF|j                  | j                  j                  k7  s#|j                  | j                  j
                  k7  rt#        d	      | j                   j%                  |       g }	 	 |j'                  | j                   j)                                +# t*        $ r Y |S t,        $ r}|j.                  t0        k7  r Y d}~|S d}~ww xY w)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)sample_rate
sample_fmtchannel_layoutaformat)sample_ratessample_fmtschannel_layoutsabuffersinkz*Frame does not match AudioResampler setup.)abuffer)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es           r   resamplezAudioResampler.resample"   s    zzemI 7N zz!DM ++5DK++5DK		6U%6%6DI ''4;;+A+AALLDKK/%%2OOq(&*#w DJJ*-2__,=
;'$djjnn$001&u||499$||00	
 G jjnn $		{ KK,, $ 0 0	 % G **..7KOOG$OOK(JJ  ""

//@''4==+?+?+J+JJ<<4==#7#77$$(:(:: !MNN

djjoo/0      77f$s   )M 	M6M6M11M6)NNNN)
__name__
__module____qualname____doc__r   cythonccall
AudioFramelistr4    r   r   r   r   
   s;     \\Wj4/ WD W Wr   r   )r0   r   r9   !cython.cimports.av.filter.contextr   cython.cimports.av.filter.graphr   av.errorr   cclassr   r=   r   r   <module>rB      s4      ; 1   o o or   