o
    2j&                  	   @   s   d dl mZmZ d dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZmZ G dd deZG d	d
 d
eZeee Zejdedejej dedefddZejG dd dZejejG dd deZejejG dd deZdS )    )IntEnumIntFlagN)libav)	err_check)wrap_index_entries)avdict_to_dictavrational_to_fractiondict_to_avdictto_avrationalc                   @   sX   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdS )Disposition                   @         i   i   i   i   i   i   i   i   i   i    N)__name__
__module____qualname__defaultduboriginalcommentlyricskaraokeforcedhearing_impairedvisual_impairedclean_effectsattached_pictimed_thumbnailsnon_diegeticcaptionsdescriptionsmetadata	dependentstill_image
multilayer r+   r+   D/var/www/html/whisper/venv/lib/python3.10/site-packages/av/stream.pyr      s(    r   c                   @   s6   e Zd ZejZejZejZ	ej
ZejZejZejZdS )DiscardN)r   r   r   libAVDISCARD_NONEnoneAVDISCARD_DEFAULTr   AVDISCARD_NONREFnonrefAVDISCARD_BIDIRbidirAVDISCARD_NONINTRAnonintraAVDISCARD_NONKEYnonkeyAVDISCARD_ALLallr+   r+   r+   r,   r-   %   s    
r-   	containerc_streamcodec_contextreturnc                 C   s   | j j|j |ksJ ddlm} ddlm} ddlm} |j	j
tjkr+||t}n>|j	j
tjkr9||t}n0|j	j
tjkrG||t}n"|j	j
tjkrUttt}n|j	j
tjkrcttt}nttt}|| || |S )zBuild an av.Stream for an existing AVStream.

    The AVStream MUST be fully constructed and ready for use before this is called.
    r   )AudioStream)SubtitleStream)VideoStream)ptrstreamsindexav.audio.streamr@   av.subtitles.streamrA   av.video.streamrB   codecpar
codec_typer.   AVMEDIA_TYPE_VIDEO__new___cinit_bypass_sentinelAVMEDIA_TYPE_AUDIOAVMEDIA_TYPE_SUBTITLEAVMEDIA_TYPE_ATTACHMENTAttachmentStreamAVMEDIA_TYPE_DATA
DataStreamStream_init)r<   r=   r>   r@   rA   rB   	py_streamr+   r+   r,   wrap_stream2   s"   rW   c                   @   s   e Zd ZdZdd Zejdedeje	j
 defddZd	d
 Zdd Zejdd Zedd Zejdd Zedd Zedd Zedd Zedd Zedd Zedd Zedd  Zed!d" Zed#d$ Zed%d& Zed'd( Zd)S )*rT   a  
    A single stream of audio, video or subtitles within a :class:`.Container`.

    ::

        >>> fh = av.open(video_path)
        >>> stream = fh.streams.video[0]
        >>> stream
        <av.VideoStream #0 h264, yuv420p 1280x720 at 0x...>

    This encapsulates a :class:`.CodecContext`, located at :attr:`Stream.codec_context`.
    Attribute access is passed through to that context when attributes are missing
    on the stream itself. E.g. ``stream.options`` will be the options on the
    context.
    c                 C   s   |t u rd S td)Nz"cannot manually instantiate Stream)rM   RuntimeErrorselfnamer+   r+   r,   	__cinit__i   s   zStream.__cinit__r<   streamr>   c                 C   sL   || _ || _t| j| _|| _| jr|j| j_t|j| j j	| j j
d| _d S N)encodingerrors)r<   rC   r   index_entriesr>   rE   stream_indexr   r'   metadata_encodingmetadata_errors)rZ   r<   r]   r>   r+   r+   r,   rU   n   s   
zStream._initc                 C   sF   t | dd }d| jj d| j d| jpd d|pd dt| d	d
S )Nr[   <av. # z<notype>/	<nocodec> at 0xx>)getattr	__class__r   rE   typeidrY   r+   r+   r,   __repr__   s    zStream.__repr__c                 C   s   |dkr|  | d S |dkr|| j_d S |dkr"t|j| j_d S |dkr2t|t| jj	 d S | j
d ur@t| j
|| d S d S )Nrp   dispositiondiscard	time_base)_set_idrC   rr   r-   valuers   r
   cythonaddressrt   r>   setattr)rZ   r[   rv   r+   r+   r,   __setattr__   s   

zStream.__setattr__c                 C   sf   t t| jj| j| jj| jjd | jd u rd S | jj	j
s%| jjj	| j_	tt| jj| jj d S r^   )r	   rw   rx   rC   r'   r<   rc   rd   r>   rt   numr   r.   avcodec_parameters_from_contextrI   rZ   r+   r+   r,   _finalize_for_output   s   

zStream._finalize_for_outputc                 C      | j jS )zM
        The format-specific ID of this stream.

        :type: int

        rC   rp   r}   r+   r+   r,   rp      s   z	Stream.idc                 C   s    |d u r
d| j _d S || j _d S )Nr   r   )rZ   rv   r+   r+   r,   ru      s   zStream._set_idc                 C   s   | j r| j jS g S )zX
        List the available profiles for this stream.

        :type: list[str]
        )r>   profilesr}   r+   r+   r,   r         zStream.profilesc                 C   s   | j r| j jS dS )zA
        The profile of this stream.

        :type: str
        N)r>   profiler}   r+   r+   r,   r      r   zStream.profilec                 C   r   )zZ
        The index of this stream in its :class:`.Container`.

        :type: int
        )rC   rE   r}   r+   r+   r,   rE      s   zStream.indexc                 C   s   t t| jjS )z
        The unit of time (in fractional seconds) in which timestamps are expressed.

        :type: fractions.Fraction | None

        )r   rw   rx   rC   rt   r}   r+   r+   r,   rt      s   zStream.time_basec                 C      | j jtjkr| j jS dS )z
        The presentation timestamp in :attr:`time_base` units of the first
        frame in this stream.

        :type: int | None
        N)rC   
start_timer.   AV_NOPTS_VALUEr}   r+   r+   r,   r         zStream.start_timec                 C   r   )ze
        The duration of this stream in :attr:`time_base` units.

        :type: int | None

        N)rC   durationr.   r   r}   r+   r+   r,   r      r   zStream.durationc                 C   r   )z{
        The number of frames this stream contains.

        Returns ``0`` if it is not known.

        :type: int
        )rC   	nb_framesr}   r+   r+   r,   frames  s   	zStream.framesc                 C      | j dS )zH
        The language of the stream.

        :type: str | None
        languager'   getr}   r+   r+   r,   r        zStream.languagec                 C      t | jjS N)r   rC   rr   r}   r+   r+   r,   rr     s   zStream.dispositionc                 C   r   )aH  
        Controls which packets of this stream are discarded by the demuxer.

        Set this to e.g. :attr:`Discard.all` on streams you don't need so that
        :meth:`.Container.demux` and :meth:`.Container.seek` skip them, avoiding
        the cost of synchronizing streams you never read.

        :type: Discard
        )r-   rC   rs   r}   r+   r+   r,   rs     s   zStream.discardc                 C   s"   t | jjj}|tjkrdS |S )zu
        The type of the stream.

        :type: Literal["audio", "video", "subtitle", "data", "attachment"]
        unknown)r.   av_get_media_type_stringrC   rI   rJ   rw   NULL)rZ   
media_typer+   r+   r,   ro   )  s   zStream.typeN)r   r   r   __doc__r\   rw   cfunc	Containerpointerr.   AVStreamCodecContextrU   rq   rz   r~   propertyrp   ru   r   r   rE   rt   r   r   r   r   rr   rs   ro   r+   r+   r+   r,   rT   W   sR    


	




	








rT   c                   @   s    e Zd Zdd Zedd ZdS )rS   c              	   C   s0   d| j j d| j d| jpd dt| dd	S )Nre   rf   z data/ri   rj   rk   rl   )rn   r   rE   r[   rp   r}   r+   r+   r,   rq   7  s   zDataStream.__repr__c                 C   s$   t | jjj}|tjkrd S |jS r   )r.   avcodec_descriptor_getrC   rI   codec_idrw   r   r[   )rZ   descr+   r+   r,   r[   =  s
   
zDataStream.nameN)r   r   r   rq   r   r[   r+   r+   r+   r,   rS   4  s    rS   c                   @   s4   e Zd ZdZedd Zedd Zedd ZdS )	rQ   z
    An :class:`AttachmentStream` represents a stream of attachment data within a media container.
    Typically used to attach font files that are referenced in ASS/SSA Subtitle Streams.
    c                 C   r   )zV
        Returns the file name of the attachment.

        :rtype: str | None
        filenamer   r}   r+   r+   r,   r[   O  r   zAttachmentStream.namec                 C   r   )zV
        Returns the MIME type of the attachment.

        :rtype: str | None
        mimetyper   r}   r+   r+   r,   r   X  r   zAttachmentStream.mimetypec                 C   sT   | j jj}| j jj}|tjks|dkrdS t|}t|D ]}|| ||< qt|S )z+Return the raw attachment payload as bytes.r       )	rC   rI   	extradataextradata_sizerw   r   	bytearrayrangebytes)rZ   r   sizepayloadir+   r+   r,   dataa  s   

zAttachmentStream.dataN)r   r   r   r   r   r[   r   r   r+   r+   r+   r,   rQ   G  s    

rQ   ) enumr   r   rw   cython.cimportsr   r.   cython.cimports.av.errorr   cython.cimports.av.indexr   cython.cimports.av.utilsr   r   r	   r
   r   r-   declareobjectrM   r   r   r   r   r   rT   rW   cclassfinalrS   rQ   r+   r+   r+   r,   <module>   s8    

$ ]