o
    2j                     @   s   d dl Z d dlZd dlm  mZ d dlmZ G dd dZej	dej
ej defddZd	edee fd
dZd	edee fddZd	edee fddZdS )    N)	err_checkc                
   @   sf   e Zd ZU dZeed< eed< eed< ee ed< dedededee ddf
dd	Zdefd
dZ	dS )
DeviceInfoa  Information about an input or output device.

    :param str name: The device identifier, for use as the first argument to :func:`av.open`.
    :param str description: Human-readable description of the device.
    :param bool is_default: Whether this is the default device.
    :param list media_types: Media types this device provides, e.g. ``["video"]``, ``["audio"]``,
        or ``["video", "audio"]``.

    namedescription
is_defaultmedia_typesreturnNc                 C   s   || _ || _|| _|| _d S )Nr   r   r   r   )selfr   r   r   r    r   D/var/www/html/whisper/venv/lib/python3.10/site-packages/av/device.py__init__   s   
zDeviceInfo.__init__c                 C   s(   | j rdnd}d| jd| j| dS )Nz
 (default) z<av.DeviceInfo  >)r   r   r   )r
   defaultr   r   r   __repr__$   s   zDeviceInfo.__repr__)
__name__
__module____qualname____doc__str__annotations__boollistr   r   r   r   r   r   r      s$   
 

r   device_listr   c              	   C   s   g }t | jD ]H}| j| }g }t |jD ]}|j| }t|}|r(|| q|t|j	r8t
t|j	 nd|jrEt
t|j nd|| jk|d q|S )Nr   r	   )range
nb_devicesdevicesnb_media_typesr   libav_get_media_type_stringappendr   device_namecythoncastbytesdecodedevice_descriptiondefault_device)r   r   idevice_infor   jmtsr   r   r   _build_device_list)   s.   



r/   format_namec                 C   sZ  ddl m} t| }tj}tt|ddd tj}| }|	|j
 g }zv|  }tt|d|t| |rFtt| W d   n1 sPw   Y  d}|D ]5\}	}
}| }d| v rkd}qYd	| v rtd
}qYtd|}|r|t|d|dd|gd qYW |	| tt| |S |	| tt| w )zFallback for formats (e.g. avfoundation) that log devices instead of
    implementing get_device_list. Opens the format with list_devices=1 and
    parses the INFO log output.r   )loggings   list_devices   1    Nvideozvideo deviceszaudio devicesaudioz\[(\d+)\] (.+)      Fr	   )avr1   r    av_find_input_formatr$   NULLav_dict_setaddress	get_level	set_levelINFOCaptureavformat_open_inputavformat_close_inputstriplowerrematchr"   r   groupav_dict_free)r0   	avloggingfmtoptsctx	old_levelr   logscurrent_media_type_level_namemessagemr   r   r   _enumerate_via_log_fallbackL   sR   


rT   c                 C   s   t | }|std| tj}z4ztt |tjtjt| t|W W t 	t| S  t
yE   t|  Y W t 	t| S w t 	t| w )a  List the available input devices for a given format.

    :param str format_name: The format name, e.g. ``"avfoundation"``, ``"dshow"``, ``"v4l2"``.
    :rtype: list[DeviceInfo]
    :raises ValueError: If *format_name* is not a known input format.
    :raises av.FFmpegError: If the device does not support enumeration.

    Example::

        for device in av.enumerate_input_devices("avfoundation"):
            print(device.name, device.description)

    zno such input format: )r    r9   
ValueErrorr$   r:   r   avdevice_list_input_sourcesr<   r/   avdevice_free_list_devicesNotImplementedErrorrT   r0   rJ   r   r   r   r   enumerate_input_devices~   s&   
rZ   c                 C   sv   t | tjtj}|std| tj}tt |tjtjt| zt|W t 	t| S t 	t| w )a.  List the available output devices for a given format.

    :param str format_name: The format name, e.g. ``"audiotoolbox"``.
    :rtype: list[DeviceInfo]
    :raises ValueError: If *format_name* is not a known output format.
    :raises av.FFmpegError: If the device does not support enumeration.

    zno such output format: )
r    av_guess_formatr$   r:   rU   r   avdevice_list_output_sinksr<   r/   rW   rY   r   r   r   enumerate_output_devices   s   	
$r]   )rE   r$   cython.cimports.libavcimportslibavr    cython.cimports.av.errorr   r   cfuncpointerAVDeviceInfoListr   r/   r   rT   rZ   r]   r   r   r   r   <module>   s    !"2$