
    \j                         d dl mZ d dlZd dlmZ d dlmZ ej                  ej                   G d d                    Z	y)    )EAGAINN)Graph)FFmpegErrorc                   N    e Zd ZdZ	 ddZej                  dedz  defd       Z	y)AudioResamplera  AudioResampler(format=None, layout=None, rate=None, frame_size=None, options=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.
    :param int frame_size: The number of samples per output frame.
    :param dict options: ``libswresample`` options passed to the underlying
        ``aresample`` filter (e.g. ``{"resampler": "soxr", "precision": "28"}``).
        See the `FFmpeg resampler documentation
        <https://ffmpeg.org/ffmpeg-resampler.html>`_ for the full list.
    Nc                 X   |"t        |t              r|n
t        |      | _        |t        |      | _        |rt        |      nd| _        |rt        |      nd| _        |r6|j                         D ci c]  \  }}t        |      t        |       c}}ni | _
        d | _        y c c}}w )Nr   )
isinstanceAudioFormatformatAudioLayoutlayoutintrate
frame_sizeitemsstroptionsgraph)selfr   r   r   r   r   kvs           E/root/.hermes/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GN7==?C41aAACTV
 Ds   4B&framereturnc                    | j                   s|g S | j                  r|gS | j                   s|| _        | 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                  rI | j                   j                  di | j                  }|j                  |       |j                  |       n|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}|j0                  t2        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)	aresample)r   is_passthroughtemplater   r   r   r   r   r   r   r   addr
   namer   link_to	configureset_audio_frame_size
ValueErrorpushappendpullEOFErrorr   errnor   )	r   r   
extra_argsr&   r!   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
 ||*DJJNNG$,,G		*!!'*(OOK(JJ  ""

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

djjoo/0      77f$s   .)N 	O$O,OO)NNNNN)
__name__
__module____qualname____doc__r   cythonccall
AudioFramelistr8        r   r   r   	   sB     MQ  \\aj4/ aD a arB   r   )
r4   r   r=   cython.cimports.av.filter.graphr   av.errorr   finalcclassr   rA   rB   r   <module>rG      s=      1   A A  ArB   