
    Hui#              	          d dl 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 ej                   e e             Zej&                  d	ed
ej*                  ej,                     dedefd       Zej4                   G d d             Zej4                   G d de             Zej4                   G d de             Zy)    )FlagN)libav)	err_check)Packet)avdict_to_dictavrational_to_fractiondict_to_avdictto_avrationalc                   X    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y)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     ;/opt/pipecat/venv/lib/python3.12/site-packages/av/stream.pyr   r      sc    G
CHGFGFOMLLHLHIKJr-   r   	containerc_streamcodec_contextreturnc                 j   | j                   j                  |j                     |k(  sJ ddlm} ddlm} ddlm} |j                  j                  t        j                  k(  r|j                  |t              }n&|j                  j                  t        j                  k(  r|j                  |t              }n|j                  j                  t        j                   k(  r|j                  |t              }n|j                  j                  t        j"                  k(  rt$        j                  t$        t              }nd|j                  j                  t        j&                  k(  rt(        j                  t(        t              }nt*        j                  t*        t              }|j-                  | ||       |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.streamr4   av.subtitles.streamr5   av.video.streamr6   codecpar
codec_typelibAVMEDIA_TYPE_VIDEO__new___cinit_bypass_sentinelAVMEDIA_TYPE_AUDIOAVMEDIA_TYPE_SUBTITLEAVMEDIA_TYPE_ATTACHMENTAttachmentStreamAVMEDIA_TYPE_DATA
DataStreamStream_init)r/   r0   r1   r4   r5   r6   	py_streams          r.   wrap_streamrL   (   s9    ==  0H<<< ,2+##s'='==''5KL					%	%)?)?	?''5KL					%	%)B)B	B"**>;QR					%	%)D)D	D$,,-=?UV					%	%)>)>	>&&z3IJ	NN6+AB	OOIx7r-   c                   z   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y)rI   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                 *    |t         u ry t        d      )Nz"cannot manually instantiate Stream)rB   RuntimeErrorselfnames     r.   	__cinit__zStream.__cinit___   s    ))?@@r-   r/   streamr1   c                    || _         || _        || _        | j                  r|j                  | j                  _        t        |j                  | j                   j                  | j                   j                        | _        y N)encodingerrors)	r/   r7   r1   r9   stream_indexr   r(   metadata_encodingmetadata_errors)rQ   r/   rT   r1   s       r.   rJ   zStream._initd   sb     #*.4llD+&OO^^55>>11
r-   c                     t        | dd       }d| j                  j                   d| j                   d| j                  xs d d|xs d dt        |       d	d
S )NrR   <av. # z<notype>/	<nocodec> at 0xx>)getattr	__class__r   r9   typeidrP   s     r.   __repr__zStream.__repr__x   sb    tVT*4>>**+2djj\499;R
:SST"{#6"T(1Q8	
r-   c                    |dk(  r| j                  |       y |dk(  r|| j                  _        y |dk(  r4t        |t	        j
                  | j                  j                               y | j                  t        | j                  ||       y y )Nrh   disposition	time_base)	_set_idr7   rk   r
   cythonaddressrl   r1   setattr)rQ   rR   values      r.   __setattr__zStream.__setattr__   s|    4<LL= #(DHH ;%0B0B!CD )D&&e4 *r-   c                    t        t        j                  | j                  j                        | j                  | j
                  j                  | j
                  j                         | j                  y | j                  j                  j                  s/| j                  j                  j                  | j                  _	        t        t        j                  | j                  j                  | j                  j                               y rV   )r	   rn   ro   r7   r(   r/   rZ   r[   r1   rl   numr   r?   avcodec_parameters_from_contextr=   rQ   s    r.   _finalize_for_outputzStream._finalize_for_output   s    NN488,,-MM^^55>>11		
 %xx!!%%!%!3!3!7!7!A!ADHH 	//!!4#5#5#9#9	
r-   c                 .    | j                   j                  S )zM
        The format-specific ID of this stream.

        :type: int

        r7   rh   rv   s    r.   rh   z	Stream.id   s     xx{{r-   c                 N    |d| j                   _        y || j                   _        y )Nr   ry   )rQ   rq   s     r.   rm   zStream._set_id   s    =DHHKDHHKr-   c                 J    | j                   r| j                   j                  S g S )zX
        List the available profiles for this stream.

        :type: list[str]
        )r1   profilesrv   s    r.   r|   zStream.profiles   s$     %%...Ir-   c                 H    | j                   r| j                   j                  S y)zA
        The profile of this stream.

        :type: str
        N)r1   profilerv   s    r.   r~   zStream.profile   s"     %%---r-   c                 .    | j                   j                  S )zZ
        The index of this stream in its :class:`.Container`.

        :type: int
        )r7   r9   rv   s    r.   r9   zStream.index   s     xx~~r-   c                 f    t        t        j                  | j                  j                              S )z
        The unit of time (in fractional seconds) in which timestamps are expressed.

        :type: fractions.Fraction | None

        )r   rn   ro   r7   rl   rv   s    r.   rl   zStream.time_base   s"     &fnnTXX5G5G&HIIr-   c                 ~    | j                   j                  t        j                  k7  r| j                   j                  S y)z
        The presentation timestamp in :attr:`time_base` units of the first
        frame in this stream.

        :type: int | None
        N)r7   
start_timer?   AV_NOPTS_VALUErv   s    r.   r   zStream.start_time   s1     88#"4"4488&&& 5r-   c                 ~    | j                   j                  t        j                  k7  r| j                   j                  S y)ze
        The duration of this stream in :attr:`time_base` units.

        :type: int | None

        N)r7   durationr?   r   rv   s    r.   r   zStream.duration   s1     88 2 2288$$$ 3r-   c                 .    | j                   j                  S )z{
        The number of frames this stream contains.

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

        :type: int
        )r7   	nb_framesrv   s    r.   frameszStream.frames   s     xx!!!r-   c                 8    | j                   j                  d      S )zH
        The language of the stream.

        :type: str | None
        languager(   getrv   s    r.   r   zStream.language       }}  ,,r-   c                 @    t        | j                  j                        S N)r   r7   rk   rv   s    r.   rk   zStream.disposition
  s    488//00r-   c                 h    t        j                  | j                  j                  j                        S )zu
        The type of the stream.

        :type: Literal["audio", "video", "subtitle", "data", "attachment"]
        )r?   av_get_media_type_stringr7   r=   r>   rv   s    r.   rg   zStream.type  s%     ++DHH,=,=,H,HIIr-   N)r   r   r   __doc__rS   rn   cfunc	Containerpointerr?   AVStreamCodecContextrJ   ri   rr   rw   propertyrh   rm   r|   r~   r9   rl   r   r   r   r   rk   rg   r,   r-   r.   rI   rI   M   sh    A
 \\

 s||,
 $	
 
&
5 \\
 
*   \\    	 	 	 	   J J ' ' % % " " - - 1 1 J Jr-   rI   c                   "    e Zd Zd Zed        Zy)rH   c           
          d| j                   j                   d| j                   d| j                  xs d dt	        |       dd	S )Nr]   r^   z data/ra   rb   rc   rd   )rf   r   r9   rR   rh   rv   s    r.   ri   zDataStream.__repr__  sG    4>>**+2djj\yy'K(r$xl!=	
r-   c                     t        j                  | j                  j                  j                        }|t
        j                  k(  ry |j                  S r   )r?   avcodec_descriptor_getr7   r=   codec_idrn   NULLrR   )rQ   descs     r.   rR   zDataStream.name   sB     &&txx'8'8'A'AB 	 6;;yyr-   N)r   r   r   ri   r   rR   r,   r-   r.   rH   rH     s    
  r-   rH   c                   @    e Zd ZdZed        Zed        Zed        Zy)rF   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                 8    | j                   j                  d      S )zV
        Returns the file name of the attachment.

        :rtype: str | None
        filenamer   rv   s    r.   rR   zAttachmentStream.name1  r   r-   c                 8    | j                   j                  d      S )zV
        Returns the MIME type of the attachment.

        :rtype: str | None
        mimetyper   rv   s    r.   r   zAttachmentStream.mimetype:  r   r-   c                    | j                   j                  j                  }| j                   j                  j                  }|t        j
                  k(  s|dk  ryt        |      }t        |      D ]
  }||   ||<    t        |      S )z+Return the raw attachment payload as bytes.r   r-   )	r7   r=   	extradataextradata_sizern   r   	bytearrayrangebytes)rQ   r   sizepayloadis        r.   datazAttachmentStream.dataC  sx     %)HH$5$5$?$?	"&(("3"3"B"B#tqyD/t 	&A"1GAJ	& W~r-   N)r   r   r   r   r   rR   r   r   r,   r-   r.   rF   rF   *  sC    
 - - - -  r-   rF   )enumr   rn   cython.cimportsr   r?   cython.cimports.av.errorr   cython.cimports.av.packetr   cython.cimports.av.utilsr   r   r	   r
   r   declareobjectrB   r   r   r   r   r   rI   rL   cclassrH   rF   r,   r-   r.   <module>r      s      ( . , $ , (9  !!nnS\\*!  ! 	! !H GJ GJ GJT   " $v $ $r-   