
    Hui3                        d dl mZ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 d dlmZ d dlmZmZ d d	lmZ ed
   Zdej,                  defdZdedej,                  fdZej2                   G d de	             Zej6                  dej8                  ej:                     dej,                  defd       Zej2                   G d de	             Zy)    )IteratorLiteralget_argsN)libav)Buffer)
bytesource)	err_check)opaque_container)avrational_to_fractionto_avrational)memcpy)(palettenew_extradataparam_changeh263_mb_inforeplay_gaindisplay_matrix	stereo_3daudio_service_typequality_statsfallback_trackcpb_propertiesskip_samplesjp_dual_monostrings_metadatasubtitle_positionmatroska_block_additionalwebvtt_identifierwebvtt_settingsmetadata_updatempegts_stream_idmastering_display_metadata	sphericalcontent_light_levela53_ccencryption_init_infoencryption_infoafdprfticc_profile	dovi_confs12m_timecodedynamic_hdr10_plusiamf_mix_gain_paramiamf_info_paramiamf_recon_gain_info_paramambient_viewing_environmentframe_croppinglcevc3d_reference_displaysrtcp_srdtypereturnc                 V    t        t              t        j                  t        |          S N)r   PktSideDataTcythoncastintr6   s    ;/opt/pipecat/venv/lib/python3.12/site-packages/av/packet.pypacket_sidedata_type_to_literalr@   ;   s    L!&++c5"9::    c                 >    t        t              j                  |       S r9   )r   r:   indexr>   s    r?   !packet_sidedata_type_from_literalrD   ?   s    L!''..rA   c                      e Zd Zedededefd       Zdej                  de
j                  fdZd Zdded	e
j                  fd
Zedefd       Zedefd       Zedefd       Ze
j,                  de
j                  fd       Ze
j,                  de
j0                  fd       Ze
j,                  de
j                  fd       ZdefdZy)PacketSideDatapacket	data_typer7   c                 D    t        |      }t        | j                  |      S )a  create new PacketSideData by copying an existing packet's side data

        :param packet: Source packet
        :type packet: :class:`~av.packet.Packet`
        :param data_type: side data type
        :return: newly created copy of the side data if the side data of the
                 requested type is found in the packet, else an empty object
        :rtype: :class:`~av.packet.PacketSideData`
        )rD   _packet_sidedata_from_packetptr)rG   rH   r6   s      r?   from_packetzPacketSideData.from_packetE   s     2)<+FJJ>>rA   r6   sizec                 n   || _         t        j                  5  |rdt        j                  t        j                  t        j                  |            | _        | j                  t        j                  k(  r t        d      t        j                  | _        d d d        || _
        y # 1 sw Y   || _
        y xY w)NFailed to allocate memory)r6   r;   nogilr<   p_ucharlib	av_mallocdataNULLMemoryErrorrM   )selfr6   rM   s      r?   	__cinit__zPacketSideData.__cinit__T   s{    
\\ 	("KKd8KL	99+%&ABB"KK		( 		( 	s   A<B$$B4c                     t         j                  5  t        j                  t        j                  | j
                               d d d        y # 1 sw Y   y xY wr9   )r;   rP   rR   av_freepaddressrT   rW   s    r?   __dealloc__zPacketSideData.__dealloc___   s7    \\ 	4LL		23	4 	4 	4   3AAmovec                 J   | j                   dk(  ry| j                  }t        j                  5  |st        j                  t        j
                  t        j                  | j                               }|t        j                  k(  rt        d      t        || j                  | j                          t        j                  |j                  | j                  || j                         }ddd       t               |rt        j                  | _        d| _         yy# 1 sw Y   4xY w)a  copy or move side data to the specified packet

        :param packet: Target packet
        :type packet: :class:`~av.packet.Packet`
        :param move: True to move the data from this object to the packet,
                     defaults to False.
        :type move: bool
        r   NrO   )rM   rT   r;   rP   r<   rQ   rR   rS   rU   rV   r   av_packet_add_side_datarK   r6   r	   )rW   rG   r_   rT   ress        r?   	to_packetzPacketSideData.to_packetc   s     99>yy\\ 	W{{6>>3==3KL6;;&%&ABBtTYY		2--fjj$**dDIIVC	W 	#DIDI 	W 	Ws   B9DD"c                 ,    t        | j                        S )zH
        The type of this packet side data.

        :type: str
        )r@   r6   r\   s    r?   rH   zPacketSideData.data_type   s     /tzz::rA   c                 @    t        j                  | j                        S )zT
        The description of this packet side data type.

        :type: str
        )rR   av_packet_side_data_namer6   r\   s    r?   	data_desczPacketSideData.data_desc   s     ++DJJ77rA   c                     | j                   S )zQ
        The size in bytes of this packet side data.

        :type: int
        rM   r\   s    r?   	data_sizezPacketSideData.data_size   s     yyrA   c                     | j                   S r9   ri   r\   s    r?   _buffer_sizezPacketSideData._buffer_size       yyrA   c                     | j                   S r9   )rT   r\   s    r?   _buffer_ptrzPacketSideData._buffer_ptr   rm   rA   c                      y)NT r\   s    r?   _buffer_writablezPacketSideData._buffer_writable   s    rA   c                 <    | j                   t        j                  k7  S )zK
        True if this object holds side data.

        :type: bool
        )rT   r;   rU   r\   s    r?   __bool__zPacketSideData.__bool__   s     yyFKK''rA   NF)__name__
__module____qualname__staticmethodPacketr:   rF   rL   rR   AVPacketSideDataTyper;   size_trX   r]   bintrc   propertystrrH   rg   r=   rj   cfuncrl   p_voidro   rr   boolrt   rq   rA   r?   rF   rF   C   s(   ?F ?| ? ? ?	s77 	v}} 	4 fkk : ;3 ; ; 83 8 8 3   \\fmm   \\V]]   \\&++  ($ (rA   rF   rG   c                    t         j                  5  t        j                  | j                  | j
                  |      }|t         j                  k7  }d d d        t        |rj                  nd      }t         j                  5  |r+t        |j                  j                  |j                         d d d        |S # 1 sw Y   kxY w# 1 sw Y   |S xY wNr   )r;   rP   rR   av_packet_side_data_get	side_dataside_data_elemsrU   rF   rM   r   rT   )rG   r6   c_ptrfoundsdatas        r?   rJ   rJ      s     
 2++f44e
 #fkk1	2 5%**1=E	 75::uzz5::67 L2 27 Ls   ?B:.C:CCc                   J   e Zd ZdZd+dZd Zd+dZd Zej                  dej                  fd       Zej                  dej                  fd	       Zej                  d
ej                  fd       Zd Zed        Zed        Zej*                  defd       Zed        Zej*                  d        Zed        Zej*                  d        Zed        Zej*                  d        Zed        Zed        Zed        Zej*                  d        Ze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"j*                  d#        Z"d$e#de$fd%Z%d$e#de&fd&Z'd,d'e&d(ejP                  fd)Z)de*e&   fd*Z+y)-rz   zA packet of encoded data within a :class:`~av.format.Stream`.

    This may, or may not include a complete object within a stream.
    :meth:`decode` must be called to extract encoded data.
    Nc                     t         j                  5  t        j                         | _        d d d        y # 1 sw Y   y xY wr9   )r;   rP   rR   av_packet_allocrK   )rW   inputs     r?   rX   zPacket.__cinit__   s.    \\ 	-**,DH	- 	- 	-s   4=c                     t         j                  5  t        j                  t        j                  | j
                               d d d        y # 1 sw Y   y xY wr9   )r;   rP   rR   av_packet_freer[   rK   r\   s    r?   r]   zPacket.__dealloc__   s9    \\ 	9v~~dhh78	9 	9 	9r^   c                     d}d }|y t        |t              r|}nt        |      }|j                  }|r)t	        t        j                  | j                  |             || j                  |       y y r   )	
isinstancer=   r   lengthr	   rR   av_new_packetrK   update)rW   r   rM   sources       r?   __init__zPacket.__init__   si    !=eS!D&F==Dc''$78KK rA   c                     | j                   r| j                   j                  nd}d| j                  j                   d| d| j                   d| j
                   d| j                  j                   dt        |       dd	S )
Nr   zav.z of #z, dts=z, pts=z; z bytes at 0xx>)	_streamrC   	__class__rv   dtsptsrK   rM   idrW   streams     r?   __repr__zPacket.__repr__   sq    '+||##$..))*%xvdhhZ HHH:Rl2d8A,aI	
rA   r7   c                 .    | j                   j                  S r9   rK   rM   r\   s    r?   rl   zPacket._buffer_size       xx}}rA   c                 .    | j                   j                  S r9   )rK   rT   r\   s    r?   ro   zPacket._buffer_ptr   r   rA   dstc                    |j                   st        d      | j                  j                  j                   s|| j                  _        y | j                  j                  j                   |j                   k(  r.| j                  j                  j                  |j                  k(  ry t        j                  | j                  | j                  j                  |       || j                  _        y )NzCannot rebase to zero time.)num
ValueErrorrK   	time_basedenrR   av_packet_rescale_ts)rW   r   s     r?   _rebase_timezPacket._rebase_time   s    ww:;;xx!!%%!$DHH88!!SWW,1C1C1G1G3771R  488+=+=sC rA   c                 8    | j                   j                  |       S )z
        Send the packet's data to the decoder and return a list of
        :class:`.AudioFrame`, :class:`.VideoFrame` or :class:`.SubtitleSet`.
        )r   decoder\   s    r?   r   zPacket.decode
  s    
 ||""4((rA   c                 .    | j                   j                  S r9   )rK   stream_indexr\   s    r?   r   zPacket.stream_index  s    xx$$$rA   c                     | j                   S )zC
        The :class:`Stream` this packet was demuxed from.
        )r   r\   s    r?   r   zPacket.stream  s    
 ||rA   r   c                 \    || _         |j                  j                  | j                  _        y r9   )r   rK   rC   r   r   s     r?   r   zPacket.stream  s     &

 0 0rA   c                 f    t        t        j                  | j                  j                              S )z
        The unit of time (in fractional seconds) in which timestamps are expressed.

        :type: fractions.Fraction
        )r   r;   r[   rK   r   r\   s    r?   r   zPacket.time_base!  s"     &fnnTXX5G5G&HIIrA   c                 j    t        |t        j                  | j                  j                               y r9   )r   r;   r[   rK   r   )rW   values     r?   r   zPacket.time_base*  s    eV^^DHH,>,>?@rA   c                 ~    | j                   j                  t        j                  k7  r| j                   j                  S y)z
        The presentation timestamp in :attr:`time_base` units for this packet.

        This is the time at which the packet should be shown to the user.

        :type: int | None
        N)rK   r   rR   AV_NOPTS_VALUEr\   s    r?   r   z
Packet.pts.  s-     88<<3---88<< .rA   c                 j    | t         j                  | j                  _        y || j                  _        y r9   )rR   r   rK   r   rW   vs     r?   r   z
Packet.pts:  #    9--DHHLDHHLrA   c                 ~    | j                   j                  t        j                  k7  r| j                   j                  S y)zo
        The decoding timestamp in :attr:`time_base` units for this packet.

        :type: int | None
        N)rK   r   rR   r   r\   s    r?   r   z
Packet.dtsA  s-     88<<3---88<< .rA   c                 j    | t         j                  | j                  _        y || j                  _        y r9   )rR   r   rK   r   r   s     r?   r   z
Packet.dtsK  r   rA   c                 b    | j                   j                  dk7  r| j                   j                  S y)z
        The byte position of this packet within the :class:`.Stream`.

        Returns `None` if it is not known.

        :type: int | None
        N)rK   posr\   s    r?   r   z
Packet.posR  s'     88<<288<< rA   c                 .    | j                   j                  S )zN
        The size in bytes of this packet's data.

        :type: int
        r   r\   s    r?   rM   zPacket.size^  s     xx}}rA   c                 ~    | j                   j                  t        j                  k7  r| j                   j                  S y)z
        The duration in :attr:`time_base` units for this packet.

        Returns `None` if it is not known.

        :type: int
        N)rK   durationrR   r   r\   s    r?   r   zPacket.durationg  s1     88 2 2288$$$ 3rA   c                 j    | t         j                  | j                  _        y || j                  _        y r9   )rR   r   rK   r   r   s     r?   r   zPacket.durations  s%    9 # 2 2DHH !DHHrA   c                 b    t        | j                  j                  t        j                  z        S r9   )r   rK   flagsrR   AV_PKT_FLAG_KEYr\   s    r?   is_keyframezPacket.is_keyframez  s     DHHNNS%8%8899rA   c                     |r.| j                   xj                  t        j                  z  c_        y | j                   xj                  t        j                   z  c_        y r9   )rK   r   rR   r   r   s     r?   r   zPacket.is_keyframe~  s8    HHNNc111NHHNN 3 344NrA   c                 b    t        | j                  j                  t        j                  z        S r9   )r   rK   r   rR   AV_PKT_FLAG_CORRUPTr\   s    r?   
is_corruptzPacket.is_corrupt       DHHNNS%<%<<==rA   c                     |r.| j                   xj                  t        j                  z  c_        y | j                   xj                  t        j                   z  c_        y r9   )rK   r   rR   r   r   s     r?   r   zPacket.is_corrupt  s8    HHNNc555NHHNN 7 788NrA   c                 b    t        | j                  j                  t        j                  z        S r9   )r   rK   r   rR   AV_PKT_FLAG_DISCARDr\   s    r?   
is_discardzPacket.is_discard  r   rA   c                 b    t        | j                  j                  t        j                  z        S r9   )r   rK   r   rR   AV_PKT_FLAG_TRUSTEDr\   s    r?   
is_trustedzPacket.is_trusted  r   rA   c                 b    t        | j                  j                  t        j                  z        S r9   )r   rK   r   rR   AV_PKT_FLAG_DISPOSABLEr\   s    r?   is_disposablezPacket.is_disposable  s     DHHNNS%?%??@@rA   c                     | j                   j                  t        j                  urUt	        j
                  t        j                  t        j                  | j                   j                  j                              S y r9   )	rK   
opaque_refr;   rU   r
   getr<   p_charrT   r\   s    r?   opaquezPacket.opaque  sR    88fkk1#''FMM488+>+>+C+CD  2rA   c                     t        j                  t        j                  | j                  j
                               |y t        j                  |      | j                  _        y r9   )rR   av_buffer_unrefr;   r[   rK   r   r
   addr   s     r?   r   zPacket.opaque  sB    FNN488+>+>?@9.2215rA   r6   c                     t        |      }t        j                  | j                  j                  | j                  j
                  |      t        j                  k7  S )zwTrue if this packet has the specified side data

        :param dtype: side data type
        :type dtype: str
        )rD   rR   r   rK   r   r   r;   rU   )rW   r6   dtype2s      r?   has_sidedatazPacket.has_sidedata  sJ     359''""DHH$<$<f {{	
rA   c                 .    t         j                  | |      S )a  get a copy of the side data

        :param dtype: side data type (:method:`~av.packet.PacketSideData.sidedata_types` for the full list of options)
        :type dtype: str
        :return: newly created copy of the side data if the side data of the
                 requested type is found in the packet, else an empty object
        :rtype: :class:`~av.packet.PacketSideData`
        )rF   rL   )rW   r6   s     r?   get_sidedatazPacket.get_sidedata  s     ))$66rA   sidedatar_   c                 (    |j                  | |       y)a
  copy or move side data to this packet

        :param sidedata: Source packet side data
        :type sidedata: :class:`~av.packet.PacketSideData`
        :param move: If True, move the data from `sidedata` object, defaults to False
        :type move: bool
        N)rc   )rW   r   r_   s      r?   set_sidedatazPacket.set_sidedata  s     	4&rA   c              #      K   t        | j                  j                        D ];  }t        | j                  | j                  j                  |   j
                         = yw)zjiterate over side data of this packet.

        :yield: :class:`~av.packet.PacketSideData` object
        N)rangerK   r   rJ   r   type)rW   is     r?   iter_sidedatazPacket.iter_sidedata  sN      txx//0 	UA.txx9K9KA9N9S9STT	Us   AA!r9   ru   ),rv   rw   rx   __doc__rX   r]   r   r   r;   r   r|   rl   r   ro   rR   
AVRationalr   r   r~   r   r   setterStreamr   r   r   r   rM   r   r   r   r   r   r   r   r   r   r   rF   r   r}   r   r   r   rq   rA   r?   rz   rz      s   -9 ,
 \\fmm   \\V]]   \\! ! !) % %   ]]1V 1 1 J J A A 	  	  	ZZ      	ZZ  	  	    	% 	% __" " : : 5 5 > > 9 9 > > > > A A   ]]6 6
# 
$ 
	7# 	7. 	7'^ '6;; 'Ux7 UrA   rz   ) typingr   r   r   r;   cython.cimportsr   rR   cython.cimports.av.bufferr   cython.cimports.av.bytesourcer   cython.cimports.av.errorr	   cython.cimports.av.opaquer
   cython.cimports.av.utilsr   r   cython.cimports.libc.stringr   r:   r{   r@   rD   cclassrF   r   pointerAVPacketrJ   rz   rq   rA   r?   <module>r      s    . .  ( , 4 . 6 J .
 ')X;3+C+C ; ;/\ /c>V>V / k(V k( k(\ NN3<<(141I1I $ PUV PU PUrA   