
    \j                         d dl Z d dlZd dlmc mZ d dlmZ  G d d      Zej                  dej                  ej                     defd       Zdedee   fd	Zdedee   fd
Zdedee   fdZy)    N)	err_checkc            
       n    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Zdefd	Z	y)

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                 <    || _         || _        || _        || _        y )Nr   r   r   r	   )selfr   r   r   r	   s        </root/.hermes/venv/lib/python3.12/site-packages/av/device.py__init__zDeviceInfo.__init__   s"     	&$&    c                 `    | j                   rdnd}d| j                  d| j                  | dS )Nz
 (default) z<av.DeviceInfo  >)r   r   r   )r   defaults     r   __repr__zDeviceInfo.__repr__$   s3    "&//,r Qt/?/?.B7)1MMr   )
__name__
__module____qualname____doc__str__annotations__boollistr   r    r   r   r   r      sk     Ic
'
' 
' 	
'
 #Y
' 

'N# Nr   r   device_listr
   c           
      V   g }t        | j                        D ]  }| j                  |   }g }t        |j                        D ]:  }|j                  |   }t        j                  |      }|s*|j                  |       < |j                  t        |j                  r2t        j                  t        |j                        j                         nd|j                  r2t        j                  t        |j                        j                         nd|| j                  k(  |              |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ss           r   _build_device_listr5   )   s   G ;))* 
!))!,{112 	&A((+B,,R0A""1%		& 	** [[(?(?@GGI11 #KK{/M/MNUUW!;!;;'		

. Nr   format_namec           	      r   ddl m} t        j                  |       }t        j
                  }t        j                  t	        j                  |      ddd       t        j
                  }|j                         }|j                  |j                         g }	 |j                         5 }t        j                  t	        j                  |      d|t	        j                  |             |r(t        j                  t	        j                  |             ddd       d}D ]  \  }	}
}|j                         }d|j                         v rd},d	|j                         v rd
}At!        j"                  d|      }|sZ|j%                  t'        |j)                  d      |j)                  d      d|g              	 |j                  |       t        j*                  t	        j                  |             |S # 1 sw Y   xY w# |j                  |       t        j*                  t	        j                  |             w xY 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   1r   Nvideozvideo deviceszaudio devicesaudioz\[(\d+)\] (.+)      Fr   )avr8   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)r6   	avloggingfmtoptsctx	old_levelr$   logscurrent_media_type_level_namemessagems                r   _enumerate_via_log_fallbackrZ   L   s    (;>;S;S<C .4[[DOOFNN4(/4C/5{{C ##%I	' "G/  	>D##FNN3$7c6>>RVCWX(()<=	>
 %&* 	"FE7mmoG'--/1%," GMMO3%,"HH.8NN"!"()
',);(<		$ 	I&-.N7	> 	>0 	I&-.s,   G; %A)G/A%G; 4?G; /G84G; ;;H6c           
      R   t        j                  |       }|st        d|       t        j                  }	 t        t        j                  |t        j                  t        j                  t        j                  |                   t        |      t        j                  t        j                  |             S # t        $ r6 t        |       cY t        j                  t        j                  |             S w xY w# t        j                  t        j                  |             w xY 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&   r?   
ValueErrorr*   r@   r   avdevice_list_input_sourcesrB   r5   avdevice_free_list_devicesNotImplementedErrorrZ   r6   rP   r    s      r   enumerate_input_devicesra   ~   s     <?;S;S<C 1+ABB8>KD++V[[&++v~~k/J	

 "+. 	&&v~~k'BC  8 +;77&&v~~k'BC8
 	&&v~~k'BCs$   AB: :C9C< 8C99C< <*D&c           
      
   t        j                  | t        j                  t        j                        }|st	        d|       t        j                  }t        t        j                  |t        j                  t        j                  t        j                  |                   	 t        |      t        j                  t        j                  |             S # t        j                  t        j                  |             w xY 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@   r\   r   avdevice_list_output_sinksrB   r5   r^   r`   s      r   enumerate_output_devicesre      s     =@<O<OV[[&++=C 2;/BCC8>K&&fkk6>>++F	
D!+.&&v~~k'BC&&v~~k'BCs   %
C *D)rK   r*   cython.cimports.libavcimportslibavr&   cython.cimports.av.errorr   r   cfuncpointerAVDeviceInfoListr   r5   r   rZ   ra   re   r   r   r   <module>rm      s    	  # # .N NB FNN33G3G$H T  D/S /T*5E /d!D !Dj1A !DHD# D$z2B Dr   