
    3j                      t    S SK r S SKJr  S SKJr  \ R
                  \ R                   " S S5      5       5       rg)    N)alloc_audio_frame)	err_checkc                   N   \ rS rSrSrS rS r\R                  S\	S-  4S j5       r
\R                  SS\R                  S	\R                  4S
 jj5       r\R                  SS\R                  S	\R                  4S jj5       r\S 5       r\S 5       r\S 5       r\S 5       rSrg)	AudioFifo   z7A simple audio sample FIFO (First In First Out) buffer.c                 .    SU R                   R                   SU R                   SU R                   SU R                   SU R
                   S[        U 5      S S3nU$ ! [         a+    SU R                   R                   S[        U 5      S S3n U$ f = f)	Nz<av. z samples of zhz z at 0xx>z, uninitialized, use fifo.write(frame), at 0x)	__class____name__samplessample_ratelayoutformatidAttributeError)selfresults     G/home/wildlama/miniconda3/lib/python3.13/site-packages/av/audio/fifo.py__repr__AudioFifo.__repr__   s    		t~~../ql##$C}Adkk]&DRSTUW    	t~~../ 0D!A'  	s   AA 1BBc                 f    U R                   (       a   [        R                  U R                   5        g g )N)ptrlibav_audio_fifo_freer   s    r   __dealloc__AudioFifo.__dealloc__   s     88""488,     frameNc           	         Uc  [        S5      eUR                  R                  (       d  gU R                  (       Gd  [        5       U l        U R                  R                  U5        U R                  R                  5         UR                  R                  (       a  UR                  R                  (       ae  UR                  R                  [        UR                  R                  5      -  U l        U =R                  UR                  R                  -  sl        OSU l        [        R                  [        R                   " [        R"                  UR                  R$                  5      UR&                  R(                  UR                  R                  S-  5      U l        U R                  (       d  [+        S5      eGO+UR                  R$                  U R                  R                  R$                  :w  d  UR                  R                  U R                  R                  R                  :w  d  UR                  R                  (       a  U R                  R                  R                  (       a{  UR                  R                  U R                  R                  R                  :w  d8  UR                  R                  U R                  R                  R                  :w  a  [-        S5      e[        R.                  " [0        5      nU R                  (       a  UR                  R2                  [        R4                  :w  ap  [        R                   " [0        U R                  U R6                  -  5      nUR                  R2                  U:w  a$  [-        SUR                  R2                  U4-  5      e[9        [        R;                  U R                  [        R                   " [        R<                  [        R>                     UR                  R@                  5      UR                  R                  5      5        U =R6                  UR                  R                  -  sl        g)a  write(frame)

Push a frame of samples into the queue.

:param AudioFrame frame: The frame of samples to push.

The FIFO will remember the attributes from the first frame, and use those
to populate all output frames.

If there is a :attr:`~.Frame.pts` and :attr:`~.Frame.time_base` and
:attr:`~.AudioFrame.sample_rate`, then the FIFO will assert that the incoming
timestamps are continuous.

Nz&AudioFifo must be given an AudioFrame.r      zCould not allocate AVAudioFifo.z*Frame does not match AudioFifo parameters.z4Frame.pts (%d) != expected (%d); fix or set to None.)!	TypeErrorr   
nb_samplesr   template_copy_internal_attributes_init_user_attributes
_time_basenumr   denfloatpts_per_sampler   av_audio_fifo_alloccythoncastAVSampleFormatr   r   nb_channelsRuntimeError
ValueErrordeclareint64_tptsAV_NOPTS_VALUEsamples_writtenr   av_audio_fifo_writepointerp_voidextended_data)r   r!   expected_ptss      r   writeAudioFifo.write   s   " =DEEyy##xxx ./DMMM33E:MM//1 ##		(=(=&+&6&6&:&:U5CSCSCWCW=X&X###uyy'<'<<#&'#..C..		0@0@A((		$$DH 88"#DEE 
 II 1 1 8 88yy$$(9(9(E(EE  $$MM,,00$$((DMM,D,D,H,HH''++t}}/G/G/K/KK IJJ ~~g.599==C4F4F#F!;;,,t/C/CCL yy}}, Jyy}}l34 
 	##FNN6==9599;R;RS		$$	
 			 4 44r    r   partialc           	         U R                   (       d  g[        R                  U R                   5      nUS:  a  gU=(       d    UnX1:  a  U(       a  UnOg[        5       nUR	                  U R
                  5        UR                  [        R                  " [        R                  U R
                  R                   R                  5      [        R                  " [        R                  U R
                  R                   R                  5      US5        [        [        R                  U R                   [        R                  " [        R                  [        R                      UR                   R"                  5      U5      5        U R$                  (       aB  [        R                  " [&        U R$                  U R(                  -  5      UR                   l        O[        R,                  UR                   l        U =R(                  U-  sl        U$ )a  read(samples=0, partial=False)

Read samples from the queue.

:param int samples: The number of samples to pull; 0 gets all.
:param bool partial: Allow returning less than requested.
:returns: New :class:`AudioFrame` or ``None`` (if empty).

If the incoming frames had valid a :attr:`~.Frame.time_base`,
:attr:`~.AudioFrame.sample_rate` and :attr:`~.Frame.pts`, the returned frames
will have accurate timing.

N   )r   r   av_audio_fifo_sizer   r'   r&   _initr/   r0   r1   r   AVChannelLayout	ch_layoutr   av_audio_fifo_readr;   r<   r=   r-   uint64_tsamples_readr7   r8   )r   r   rA   buffered_samplesr!   s        r   readAudioFifo.readp   sc     xx'*'='=dhh'Ga--%*-/''6KK**DMM,=,=,D,DEKK++T]]->->-H-HI		
 	""FNN6==9599;R;RS	
 "KK$--0A0AAEIIM  ..EIIMW$r    c                 Z    / n U R                  XS9nUb  UR                  U5        O U$ M)  )zread_many(samples, partial=False)

Read as many frames as we can.

:param int samples: How large for the frames to be.
:param bool partial: If we should return a partial frame.
:returns: A ``list`` of :class:`AudioFrame`.

)rA   )rL   append)r   r   rA   framesr!   s        r   	read_manyAudioFifo.read_many   s;     IIgI7E e$ r    c                 v    U R                   (       d  [        S[         S35      eU R                  R                  $ )z'The :class:`.AudioFormat` of this FIFO.'z,.AudioFifo' object has no attribute 'format')r   r   r   r&   r   r   s    r   r   AudioFifo.format   7     xx H:IJ  }}###r    c                 v    U R                   (       d  [        S[         S35      eU R                  R                  $ )z'The :class:`.AudioLayout` of this FIFO.rT   z,.AudioFifo' object has no attribute 'layout')r   r   r   r&   r   r   s    r   r   AudioFifo.layout   rV   r    c                 v    U R                   (       d  [        S[         S35      eU R                  R                  $ )NrT   z1.AudioFifo' object has no attribute 'sample_rate')r   r   r   r&   r   r   s    r   r   AudioFifo.sample_rate   s5    xx H:NO  }}(((r    c                 f    U R                   (       a  [        R                  U R                   5      $ S$ )z4Number of audio samples (per channel) in the buffer.r   )r   r   rD   r   s    r   r   AudioFifo.samples   s$     4888s%%dhh/BBr    )r   r-   r&   )r   F)F)r   
__module____qualname____firstlineno____doc__r   r   r/   ccall
AudioFramer?   intbintrL   rQ   propertyr   r   r   r   __static_attributes__ r    r   r   r      s     B- \\Q5:, Q5 Q5f \\7FJJ 7V[[ 7 7r \\ fkk  , $ $ $ $ ) ) C Cr    r   )r/   cython.cimports.av.audio.framer   cython.cimports.av.errorr   finalcclassr   rg   r    r   <module>rl      s=     < . VC VC  VCr    