
    cjhB                    h   U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z
ddlZddlZddlZddlZddlmZmZmZmZmZmZ ddlmZ ddlmZ er ed      Zed	   Zed
   Z G d de      Z G d de      ZdZ ej@                  e!      Z" ejF                  ejH                        Z% ejF                  ejL                        Z' ejF                  ejP                        Z)da* G d dejV                        Z, G d dejV                        Z- ejF                  e,      Z. ejF                  e-      Z/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:dZ;dd d!d"d#d	Z<de=d$<   d%d&d'd
Z>de=d(<   dPd)Z?dQd*Z@d+g ej                  dfd,ejH                  gej                  dfd-ejH                  gejH                  dfd.ejH                  ejH                  ejH                  e%ge.e@fd/e.e'ejH                  ej                  ej                  gej                  e?fd0e.e)ejH                  ej                  ej                  gej                  e?fd1e.ejH                  gej                  e?fd2e.gddfd3ejH                  gejH                  dfd4ejH                  ejH                  e%ge/e@fd5e/ej                  ej                  e'ejH                  ejH                  gejH                  e?fd6e/ej                  ej                  e)ejH                  ejH                  gejH                  e?fd7e/ejH                  gej                  e?fd8e/gddfd9e/ej                  ej                  gejH                  e?fd:ej                  gejH                  e?fd;ej                  gejH                  e?fd<ej                  ejH                  gejH                  e?fd=ej                  ejH                  gejH                  e?fgZCd>e=d?<   dRd@ZDdSdAZEdTdBZFdSdCZG G dD dEe      ZH G dF dGe      ZI G dH dI      ZJ G dJ dKeJ      ZK G dL dMeJ      ZL G dN dOej                  eJ      ZNy)Uae  
The MIT License (MIT)

Copyright (c) 2015-2021 Rapptz
Copyright (c) 2021-present Pycord Development

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    )annotationsN)TYPE_CHECKINGAnyCallableLiteral	TypedDictTypeVar   )DiscordException)RawDataT)narrowmediumwide	superwidefull)autovoicemusicc                  @    e Zd ZU ded<   ded<   ded<   ded<   ded<   y)BandCtlintr   r   r   r   r   N__name__
__module____qualname____annotations__     ?/var/www/html/venv/lib/python3.12/site-packages/discord/opus.pyr   r   2   s    KK
IN
Ir   r   c                  ,    e Zd ZU ded<   ded<   ded<   y)	SignalCtlr   r   r   r   Nr   r   r   r    r"   r"   :   s    
IJJr   r"   )EncoderDecoderDecodeManager	OpusErrorOpusNotLoadedc                      e Zd Zy)EncoderStructNr   r   r   r   r   r    r)   r)   Q       r   r)   c                      e Zd Zy)DecoderStructNr*   r   r   r    r-   r-   U   r+   r   r-   i  i   i  i  i  i  i  i  i  i  iM  iN  iO  iP  iQ  band_ctlii  i  
signal_ctlc                n    | t         k  r+t        j                  d|j                         t	        |       | S )Nerror has happened in %s)OK_loginfor   r&   )resultfuncargss      r    _err_ltr9      s,    {		,dmm<Mr   c                    |d   j                   }|j                  t        k7  r5t        j	                  d|j
                         t        |j                        | S )Nr.   r2   )_objvaluer3   r4   r5   r   r&   )r6   r7   r8   rets       r    _err_ner>      sA    
r(--C
yyB		,dmm<		""Mr   opus_get_version_stringopus_strerroropus_encoder_get_sizeopus_encoder_createopus_encodeopus_encode_floatopus_encoder_ctlopus_encoder_destroyopus_decoder_get_sizeopus_decoder_createopus_decodeopus_decode_floatopus_decoder_ctlopus_decoder_destroyopus_decoder_get_nb_samplesopus_packet_get_bandwidthopus_packet_get_nb_channelsopus_packet_get_nb_frames!opus_packet_get_samples_per_framezlist[tuple[Any, ...]]exported_functionsc                4   t         j                  j                  |       }t        D ];  }t	        ||d         }	 |d   r
|d   |_        |d   |_        	 |d   r
|d   |_        = |S # t        $ r Y w xY w# t        $ r t        j                  d|       Y pw xY w)Nr   r
         z$Error assigning check function to %s)ctypescdllLoadLibraryrR   getattrargtypesrestypeKeyErrorerrcheckr4   	exception)namelibitemr7   s       r    libopus_loaderrb      s    
++
!
!$
'C # IsDG$	Aw $Q7DL	IAw $QI" J  		  	INNA4H	Is#   A&A5&	A21A25BBc                    	 t         j                  dk(  rt        j                  j	                  t        j                  j                  t                    } t        j                  d      dz  }|dkD  rdnd}t        j                  j                  | dd| d	      }t        |      an(t        t        j                  j                  d
            at        d uS # t        $ r d aY t        d uS w xY w)Nwin32P       x64x86binz
libopus-0.z.dllopus)sysplatformospathdirnameabspath__file__structcalcsizejoinrb   _librV   utilfind_library	Exception)_basedir_bitness_target	_filenames       r    _load_defaultr~     s    
<<7"wwrwwx'@AHs+a/H'"}e%GXu
7)46PQI!),D!&++":":6"BCD t  ts   CC C,+C,c                    t        |       ay)a  Loads the libopus shared library for use with voice.

    If this function is not called then the library uses the function
    :func:`ctypes.util.find_library` and then loads that one if available.

    Not loading a library and attempting to use PCM based AudioSources will
    lead to voice not working.

    This function propagates the exceptions thrown.

    .. warning::

        The bitness of the library must match the bitness of your python
        interpreter. If the library is 64-bit then your python interpreter
        must be 64-bit as well. Usually if there's a mismatch in bitness then
        the load will throw an exception.

    .. note::

        On Windows, this function should not need to be called as the binaries
        are automatically loaded.

    .. note::

        On Windows, the .dll extension is not necessary. However, on Linux
        the full extension is required to load the library, e.g. ``libopus.so.1``.
        On Linux however, :func:`ctypes.util.find_library` will usually find the library automatically
        without you having to call this.

    Parameters
    ----------
    name: :class:`str`
        The filename of the shared library.
    N)rb   rv   )r_   s    r    	load_opusr     s    H $Dr   c                     t         duS )a  Function to check if opus lib is successfully loaded either
    via the :func:`ctypes.util.find_library` call of :func:`load_opus`.

    This must return ``True`` for voice to work.

    Returns
    -------
    :class:`bool`
        Indicates if the opus library has been loaded.
    N)rv   r   r   r    	is_loadedr   ;  s     tr   c                  $     e Zd ZdZd fdZ xZS )r&   zAn exception that is thrown for libopus related errors.

    Attributes
    ----------
    code: :class:`int`
        The error code returned.
    c                    || _         t        j                  | j                         j                  d      }t        j                  d|       t        |   |       y )Nutf-8z"%s" has happened)coderv   r@   decoder4   r5   super__init__)selfr   msg	__class__s      r    r   zOpusError.__init__S  sE    	  +227;		%s+r   )r   r   )r   r   r   __doc__r   __classcell__r   s   @r    r&   r&   J  s     r   r&   c                      e Zd ZdZy)r'   z;An exception that is thrown for when libopus is not loaded.N)r   r   r   r   r   r   r    r'   r'   Z  s    Er   r'   c                  z    e Zd ZdZdZdZ ej                  d      ez  Z e	edz  ez        Z
e
ez  Zedd       Zy)	_OpusStructi  rT      hi  c                     t               st               s
t               t        j	                         j                  d      S )Nr   )r   r~   r'   rv   r?   r   r   r   r    get_opus_versionz_OpusStruct.get_opus_versiong  s-    {=?/!++-44W==r   N)returnstr)r   r   r   SAMPLING_RATECHANNELSFRAME_LENGTHrs   rt   SAMPLE_SIZEr   SAMPLES_PER_FRAME
FRAME_SIZEstaticmethodr   r   r   r    r   r   ^  sW    MHL!&//#&1KMD0<?@"[0J> >r   r   c                  Z    e Zd ZefddZddZddZddZddZddZ	dddZ
ddZdd	Zy
)r#   c                   t         j                          || _        | j                         | _        | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y )N   Tg333333?r   r   )
r   r   application_create_state_stateset_bitrateset_fec set_expected_packet_loss_percentset_bandwidthset_signal_type)r   r   s     r    r   zEncoder.__init__p  sj    $$& +%)%7%7%9T--d36"V$r   c                j    t        | d      r't        j                  | j                         d | _        y y Nr   )hasattrrv   rF   r   r   s    r    __del__zEncoder.__del__{  s*    4"%%dkk2DK #r   c                    t        j                         }t        j                  | j                  | j
                  | j                  t        j                  |            S N)rV   c_intrv   rB   r   r   r   byrefr   r=   s     r    r   zEncoder._create_state  sB    lln''t/?/?cAR
 	
r   c           	         t        dt        dt        |                  }t        j	                  | j
                  t        |dz         |S )Ni      i   )minmaxr   rv   rE   r   CTL_SET_BITRATE)r   kbpss     r    r   zEncoder.set_bitrate  s8    3BD	*+dkk?D4KHr   c                    |t         vr#t        |ddj                  t                      t         |   }t        j	                  | j
                  t        |       y Nz/ is not a valid bandwidth setting. Try one of: ,)r/   r\   ru   rv   rE   r   CTL_SET_BANDWIDTHr   reqks      r    r   zEncoder.set_bandwidth  sW    h' HHX&') 
 SMdkk+<a@r   c                    |t         vr#t        |ddj                  t                      t         |   }t        j	                  | j
                  t        |       y r   )r0   r\   ru   rv   rE   r   CTL_SET_SIGNALr   s      r    r   zEncoder.set_signal_type  sV    j ' HHZ()+ 
 sOdkk>1=r   c                `    t         j                  | j                  t        |rd       y d       y )Nr
   r   )rv   rE   r   CTL_SET_FEC)r   enableds     r    r   zEncoder.set_fec  s    dkk;WL!Lr   c                    t         j                  | j                  t        t	        dt        dt        |dz                           y )Nd   r   )rv   rE   r   CTL_SET_PLPr   r   r   )r   
percentages     r    r   z(Encoder.set_expected_packet_loss_percent  s1    dkk;CQJY\L\H]A^8_`r   c                   t        |      }t        j                  |t              }t        j                  |z         }t
        j                  | j                  ||||      }t        j                  d|d |       j                         S )Nb)
lenrV   castc_int16_ptrc_charrv   rC   r   arraytobytes)r   pcm
frame_sizemax_data_bytespcm_ptrdatar=   s          r    encodezEncoder.encode  sj    S++c;/.1t{{GZ~V {{3Tc
+3355r   N)r   r   )r   None)r   r)   )r   r   r   r   )r   BAND_CTLr   r   )r   
SIGNAL_CTLr   r   )T)r   boolr   r   )r   floatr   r   )r   bytesr   r   r   r   )r   r   r   APPLICATION_AUDIOr   r   r   r   r   r   r   r   r   r   r   r    r#   r#   o  s5    *; 	%
A>Ma	6r   r#   c                  r    e Zd Zd Zd Zd Zed        Zed        Ze	d        Z
d Zd Zd	 Zd
 ZdddZy)r$   c                V    t         j                          | j                         | _        y r   )r   r   r   r   r   s    r    r   zDecoder.__init__  s    $$&((*r   c                j    t        | d      r't        j                  | j                         d | _        y y r   )r   rv   rL   r   r   s    r    r   zDecoder.__del__  s*    4"%%dkk2DK #r   c                    t        j                         }t        j                  | j                  | j
                  t        j                  |            S r   )rV   r   rv   rH   r   r   r   r   s     r    r   zDecoder._create_state  s:    lln''v||C/@
 	
r   c                @    t         j                  | t        |             S )z+Gets the number of frames in an Opus packet)rv   rP   r   r   s    r    packet_get_nb_frameszDecoder.packet_get_nb_frames  s     --dCI>>r   c                ,    t         j                  |       S )z-Gets the number of channels in an Opus packet)rv   rO   r   s    r    packet_get_nb_channelszDecoder.packet_get_nb_channels  s     //55r   c                B    t         j                  || j                        S )z8Gets the number of samples per frame from an Opus packet)rv   rQ   r   )clsr   s     r    packet_get_samples_per_framez$Decoder.packet_get_samples_per_frame  s     55dC<M<MNNr   c                L    t         j                  | j                  t        |      S )a  Configures decoder gain adjustment.
        Scales the decoded output by a factor specified in Q8 dB units.
        This has a maximum range of -32768 to 32767 inclusive, and returns
        OPUS_BAD_ARG (-1) otherwise. The default is zero indicating no adjustment.
        This setting survives decoder reset (irrelevant for now).
        gain = 10**x/(20.0*256)
        (from opus_defines.h)
        )rv   rK   r   CTL_SET_GAIN)r   
adjustments     r    	_set_gainzDecoder._set_gain  s     $$T[[,
KKr   c           
     h    t        dt        dt        |dz                    }| j                  |      S )z.Sets the decoder gain in dB, from -128 to 128.i i     )r   r   roundr   )r   dBdB_Q8s      r    set_gainzDecoder.set_gain  s.     FCuR#X78~~e$$r   c                P    | j                  dt        j                  |      z        S )zPSets the output volume as a float percent, i.e. 0.5 for 50%, 1.75 for 175%, etc.r   )r   mathlog10)r   mults     r    
set_volumezDecoder.set_volume  s    }}R$**T"2233r   c                    t        j                         }t        j                  | j                  t
        t        j                  |             |j                  S )zTGets the duration (in samples) of the last packet successfully decoded or concealed.)rV   c_int32rv   rK   r   CTL_LAST_PACKET_DURATIONr   r<   r   s     r    _get_last_packet_durationz!Decoder._get_last_packet_duration  s;     nndkk+CV\\RUEVWyyr   F)fecc               F   ||rt        d      |+| j                         xs | j                  }| j                  }n3| j	                  |      }| j                  }| j                  |      }||z  }t        j                  ||z  t        j                  t        j                        z  z         }t        j                  |t              }t        j                  | j                  ||rt        |      nd|||      }	t        j                  d|d |	|z         j!                         S )Nz4Invalid arguments: FEC cannot be used with null datar   r   )r&   r   r   r   r   r   rV   c_int16sizeofr   r   rv   rI   r   r   r   r   )
r   r   r   r   channel_countframessamples_per_framer   r   r=   s
             r    r   zDecoder.decode  s   <CRSS<779ST=S=SJ MMM..t4F MMM $ A A$ G"33J NNM)FMM&..,IIK ++c;/KKDs4ya*c
 {{3$9cM&9 :;CCEEr   N)r   r   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r   r   r    r$   r$     so    +


 ? ? 6 6 O O	L%4 #( Fr   r$   c                  F     e Zd Z fdZd Zd Zd Zd Zed        Z	 xZ
S )r%   c                    t         |   dd       || _        g | _        i | _        t        j                         | _        y )NTr%   )daemonr_   )r   r   clientdecode_queuedecoder	threadingEvent_end_thread)r   r
  r   s     r    r   zDecodeManager.__init__
  s:    ?;$??,r   c                p    t        |t              st        d      | j                  j	                  |       y )Nz&opus_frame should be a RawData object.)
isinstancer   	TypeErrorr  append)r   
opus_frames     r    r   zDecodeManager.decode  s,    *g.DEE  ,r   c                   | j                   j                         s	 | j                  j                  d      }	 |j                  D| j                  |j                        j                  |j                        |_        	 | j                  j                  |       | j                   j                         sy y # t        $ r t        j                  d       Y w xY w# t        $ r t        d       Y w xY w)Nr   gMbP?z)Error occurred while decoding opus frame.)r  is_setr  pop
IndexErrortimesleepdecrypted_dataget_decoderssrcr   decoded_datar&   printr
  recv_decoded_audio)r   r   s     r    runzDecodeManager.run  s    ""))+((,,Q/
	&&.(,(8(8(C(J(J++)D% KK**40% ""))+  

5!  ABs(   B7 C 9C 7CCC21C2c                    | j                   rHt        j                  d       i | _        t	        j
                          t        d       | j                   rH| j                  j                          y )Ng?zDecoder Process Killed)	decodingr  r  r  gccollectr  r  setr   s    r    stopzDecodeManager.stop.  sJ    mmJJsODLJJL*+	 mm
 	r   c                    | j                   j                  |      }||S t               | j                   |<   | j                   |   S r   )r  getr$   )r   r  ds      r    r  zDecodeManager.get_decoder6  s?    LLT"=H$YT||D!!r   c                ,    t        | j                        S r   )r   r  r   s    r    r#  zDecodeManager.decoding=  s    D%%&&r   )r   r   r   r   r   r!  r'  r  propertyr#  r   r   s   @r    r%   r%   	  s0    --
1*" ' 'r   r%   )r6   r   r7   r   r8   listr   r   )r6   r   r7   r   r8   r-  r   r   )r_   r   r   r   )r   r   )r_   r   r   r   )Or   
__future__r   r   rV   ctypes.utilr$  loggingr   os.pathrn   rs   rl   r  r  typingr   r   r   r   r   r	   errorsr   sinksr   r   r   r   r   r"   __all__	getLoggerr   r4   POINTERr   	c_int_ptrr  r   c_floatc_float_ptrrv   	Structurer)   r-   EncoderStructPtrDecoderStructPtrr3   BAD_ARGr   APPLICATION_VOIPAPPLICATION_LOWDELAYr   r   r   r   r   r   r   r/   r   r0   r9   r>   c_char_pr   rR   rb   r~   r   r   r&   r'   r   r#   r$   Threadr%   r   r   r    <module>rC     s  2 #    	     
   L L $ AFGH12Ji 	  w"FNN6<<(	fnnV^^,fnnV^^,	F$$ 		F$$ 	 "6>>-0 !6>>-0 
 
        '  
I  FOOT:v||nfoot<v||nfllDA	v||V\\9=	 		;foov~~V	 		;foov~~V	 *FLL96>>7S./t<v||nfllDA	v||Y/	 	OONNLLLL	
 	 	OONNLLLL	
 	 *FLL96>>7S./t<%	6??FNN;	 !6??"3V\\7K"V__$5v||WM#	&,,'	 	,	&,,'	[S- ) Sl2"$ N   F$ F> >"A6k A6HSFk SFl6'I$$k 6'r   