
    ^j&              	          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e          Z G d	 d
e          Z ej        e e                      Zej        dedej        ej                 dedefd            Zej         G d d                      Zej        ej         G d de                                  Zej        ej         G 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                   Z    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     /data/video-pipeline/HaTramAudio/project/018-Hon-Uoc-Khong-Duoc-Phep-Yeu/work/asr-venv/lib/python3.11/site-packages/av/stream.pyr   r      so        G
CHGFGFOMLLHLHIKJJJr.   r   c                   p    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/   r1   r1   %   sF        D#G!FE%H!F

CCCr.   r1   	containerc_streamcodec_contextreturnc                 "   | 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    r|                    |t                    }n|j	        j
        t          j        k    r|                    |t                    }n|j	        j
        t          j        k    r&t$                              t$          t                    }ne|j	        j
        t          j        k    r&t(                              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.streamrE   av.subtitles.streamrF   av.video.streamrG   codecpar
codec_typer2   AVMEDIA_TYPE_VIDEO__new___cinit_bypass_sentinelAVMEDIA_TYPE_AUDIOAVMEDIA_TYPE_SUBTITLEAVMEDIA_TYPE_ATTACHMENTAttachmentStreamAVMEDIA_TYPE_DATA
DataStreamStream_init)r@   rA   rB   rE   rF   rG   	py_streams          r/   wrap_streamr\   2   sf    = 0H<<<< ,+++++222222++++++#s'===''5KLL					%)?	?	?''5KLL					%)B	B	B"**>;QRR					%)D	D	D$,,-=?UVV					%)>	>	>&&z3IJJ		NN6+ABB	OOIx777r.   c                      e Zd ZdZd Zej        dedej        e	j
                 defd            Zd Zd Zej        d	             Zed
             Zej        d             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             ZdS )rY   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                 6    |t           u rd S t          d          )Nz"cannot manually instantiate Stream)rR   RuntimeErrorselfnames     r/   	__cinit__zStream.__cinit__i   s"    )))F?@@@r.   r@   streamrB   c                     || _         || _        t          | j                  | _        || _        | j        r|j        | j        _        t          |j        | j         j	        | j         j
                  | _        d S N)encodingerrors)r@   rH   r   index_entriesrB   rJ   stream_indexr   r)   metadata_encodingmetadata_errors)ra   r@   rd   rB   s       r/   rZ   zStream._initn   ss     #/99* 	;.4lD+&O^5>1
 
 
r.   c                     t          | dd           }d| j        j         d| j         d| j        pd d|pd dt          |           d	d
S )Nrb   <av. # z<notype>/	<nocodec> at 0xx>)getattr	__class__r   rJ   typeidr`   s     r/   __repr__zStream.__repr__   s|    tVT**84>* 8 8dj 8 849;R
 8 8"{8 8*,T((78 8 8	
r.   c                 Z   |dk    r|                      |           d S |dk    r|| j        _        d S |dk    r t          |          j        | j        _        d S |dk    r.t          |t          j        | j        j	                             d S | j
        t          | j
        ||           d S d S )Nry   dispositiondiscard	time_base)_set_idrH   r|   r1   valuer}   r   cythonaddressr~   rB   setattr)ra   rb   r   s      r/   __setattr__zStream.__setattr__   s    4<<LLF=  #(DH F9&u~~3DHF;%0B!C!CDDDF )D&e44444 *)r.   c                 l   t          t          j        | j        j                  | j        | j        j        | j        j                   | j        d S | j        j	        j
        s| j        j        j	        | j        _	        t          t          j        | j        j        | j        j                             d S rf   )r
   r   r   rH   r)   r@   rk   rl   rB   r~   numr   r2   avcodec_parameters_from_contextrN   ra   s    r/   _finalize_for_outputzStream._finalize_for_output   s    N48,--M^5>1		
 	
 	
 	
 %Fx!% 	B!%!3!7!ADH 	/!4#5#9 	
 	
 	
 	
 	
r.   c                     | j         j        S )zM
        The format-specific ID of this stream.

        :type: int

        rH   ry   r   s    r/   ry   z	Stream.id   s     x{r.   c                 >    |d| j         _        d S || j         _        d S )Nr   r   )ra   r   s     r/   r   zStream._set_id   s!    =DHKKKDHKKKr.   c                 ,    | j         r| j         j        S g S )zX
        List the available profiles for this stream.

        :type: list[str]
        )rB   profilesr   s    r/   r   zStream.profiles   s       	%..Ir.   c                 ,    | j         r| j         j        S dS )zA
        The profile of this stream.

        :type: str
        N)rB   profiler   s    r/   r   zStream.profile   s       	%--4r.   c                     | j         j        S )zZ
        The index of this stream in its :class:`.Container`.

        :type: int
        )rH   rJ   r   s    r/   rJ   zStream.index   s     x~r.   c                 X    t          t          j        | j        j                            S )z
        The unit of time (in fractional seconds) in which timestamps are expressed.

        :type: fractions.Fraction | None

        )r	   r   r   rH   r~   r   s    r/   r~   zStream.time_base   s!     &fnTX5G&H&HIIIr.   c                 R    | 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)rH   
start_timer2   AV_NOPTS_VALUEr   s    r/   r   zStream.start_time   s*     8#"4448&& 54r.   c                 R    | j         j        t          j        k    r| j         j        S dS )ze
        The duration of this stream in :attr:`time_base` units.

        :type: int | None

        N)rH   durationr2   r   r   s    r/   r   zStream.duration   s*     8 2228$$ 32r.   c                     | j         j        S )z{
        The number of frames this stream contains.

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

        :type: int
        )rH   	nb_framesr   s    r/   frameszStream.frames  s     x!!r.   c                 6    | j                             d          S )zH
        The language of the stream.

        :type: str | None
        languager)   getr   s    r/   r   zStream.language       }  ,,,r.   c                 4    t          | j        j                  S N)r   rH   r|   r   s    r/   r|   zStream.disposition  s    48/000r.   c                 4    t          | j        j                  S )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
        )r1   rH   r}   r   s    r/   r}   zStream.discard  s     tx'(((r.   c                 p    t          j        | j        j        j                  }|t
          j        k    rdn|S )zu
        The type of the stream.

        :type: Literal["audio", "video", "subtitle", "data", "attachment"]
        unknown)r2   av_get_media_type_stringrH   rN   rO   r   NULL)ra   
media_types     r/   rx   zStream.type)  s2     1$(2C2NOO
&&+55yy:Er.   N)r   r   r   __doc__rc   r   cfunc	Containerpointerr2   AVStreamCodecContextrZ   rz   r   r   propertyry   r   r   r   rJ   r~   r   r   r   r   r|   r}   rx   r-   r.   r/   rY   rY   W   s         A A A
 \

 s|,
 $	
 
 
 \
(
 
 
5 5 5$ \
 
 \
*   X \    \  	 	 X	 	 	 X	   X J J XJ ' ' X' % % X% " " X" - - X- 1 1 X1 
) 
) X
) F F XF F Fr.   rY   c                   *    e Zd Zd Zed             ZdS )rX   c           
      h    d| j         j         d| j         d| j        pd dt	          |           dd	S )Nrn   ro   z data/rr   rs   rt   ru   )rw   r   rJ   rb   ry   r   s    r/   rz   zDataStream.__repr__7  sZ    =4>* = =dj = =y'K= =/1$xx<= = =	
r.   c                 z    t          j        | j        j        j                  }|t
          j        k    rd S |j        S r   )r2   avcodec_descriptor_getrH   rN   codec_idr   r   rb   )ra   descs     r/   rb   zDataStream.name=  s;     &tx'8'ABB 	 6;4yr.   N)r   r   r   rz   r   rb   r-   r.   r/   rX   rX   4  s>        
 
 
   X  r.   rX   c                   T    e Zd ZdZed             Zed             Zed             ZdS )rV   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                 6    | j                             d          S )zV
        Returns the file name of the attachment.

        :rtype: str | None
        filenamer   r   s    r/   rb   zAttachmentStream.nameO  r   r.   c                 6    | j                             d          S )zV
        Returns the MIME type of the attachment.

        :rtype: str | None
        mimetyper   r   s    r/   r   zAttachmentStream.mimetypeX  r   r.   c                     | j         j        j        }| j         j        j        }|t          j        k    s|dk    rdS t          |          }t          |          D ]}||         ||<   t          |          S )z+Return the raw attachment payload as bytes.r   r.   )	rH   rN   	extradataextradata_sizer   r   	bytearrayrangebytes)ra   r   sizepayloadis        r/   datazAttachmentStream.dataa  ss     %)H$5$?	"&("3"B##tqyy3D//t 	& 	&A"1GAJJW~~r.   N)r   r   r   r   r   rb   r   r   r-   r.   r/   rV   rV   G  so         
 - - X- - - X-   X  r.   rV   ) enumr   r   r   cython.cimportsr   r2   cython.cimports.av.errorr   cython.cimports.av.indexr   cython.cimports.av.utilsr   r	   r
   r   r   r1   declareobjectrR   r   r   r   r   r   rY   r\   cclassfinalrX   rV   r-   r.   r/   <module>r      s1   ! ! ! ! ! ! ! !  ( ( ( ( ( ( . . . . . . 7 7 7 7 7 7               '   ,    g    (99  !!nS\*!  ! 	! ! ! !H YF YF YF YF YF YF YF YFx         " $ $ $ $ $v $ $  $ $ $r.   