o
    2j                     @   s   d dl mZ d dlZd dlmZ d dlmZ eG dd dZe	e
e
 Zejdejdefd	d
ZejejG dd dZdS )    )	dataclassN)libav)PyBytes_FromStringAndSizec                   @   s&   e Zd ZU eed< eed< dd ZdS )AudioChannelnamedescriptionc                 C   s   d| j  d| j dS )Nz<av.AudioChannel 'z' (z)>)r   r   self r
   J/var/www/html/whisper/venv/lib/python3.10/site-packages/av/audio/layout.py__repr__      zAudioChannel.__repr__N)__name__
__module____qualname__str__annotations__r   r
   r
   r
   r   r      s   
 r   c_layoutreturnc                 C   s   t t}| |_|S )z$Get an AudioLayout from Cython land.)AudioLayout_cinit_bypass_sentinellayout)r   r   r
   r
   r   get_audio_layout   s   r   c                   @   sV   e Zd Zdd Zdd Zdd Zdd Zed	d
 Zedd Z	ede
fddZdS )r   c                 C   s   t t| j d S N)libav_channel_layout_uninitcythonaddressr   r   r
   r
   r   __dealloc__   r   zAudioLayout.__dealloc__c                 C   sx   |t u rd S t|tu r!tt||}|dkr td| nt|t	r.t
t	|j}n	tdt| || _d S )Nr   zInvalid layout: z5layout must be of type: string | av.AudioLayout, got )r   typer   r   av_channel_layout_from_stringr   r   
ValueError
isinstancer   castr   	TypeError)r	   r   r   retr
   r
   r   	__cinit__"   s   

zAudioLayout.__cinit__c                 C   s   d| j j d| jdS )Nz<av. >)	__class__r   r   r   r
   r
   r   r   3   s   zAudioLayout.__repr__c                 C   s:   t |tsdS tt|j}tt| jt|dkS )NFr   )r"   r   r   r#   r   r   av_channel_layout_comparer   )r	   otherc_otherr
   r
   r   __eq__6   s   
zAudioLayout.__eq__c                 C   s   | j jS r   )r   nb_channelsr   r
   r
   r   r.   A   s   zAudioLayout.nb_channelsc              
   C   s   g }t | jjD ]>}t|t|tt| j|}t	|t|tt| j|}|
tt||d dt||d d qt|S )N   zutf-8)ranger   r.   r   av_channel_namer   sizeof$av_channel_layout_channel_from_indexr   av_channel_descriptionappendr   r   decodetuple)r	   resultsindexbufsizebuf2size2r
   r
   r   channelsE   s.   zAudioLayout.channelsr   c                 C   s6   t t| j|t|}|dk rtd| |S )z'The canonical name of the audio layout.r   zFailed to get layout name: )r   av_channel_layout_describer   r   r   r2   RuntimeError)r	   layout_namer%   r
   r
   r   r   c   s   zAudioLayout.nameN)r   r   r   r   r&   r   r-   propertyr.   r>   r   r   r
   r
   r
   r   r      s    

r   )dataclassesr   r   cython.cimportsr   r   cython.cimports.cpython.bytesr   r   declareobjectr   cfuncAVChannelLayoutr   r   finalcclassr
   r
   r
   r   <module>   s    