
    \j37              	          d dl mZ d dlmZmZ d dlZd dlmZ d dl	m
Z
mZmZ d dlmZ d dlmZ d dlmZmZ d d	lmZmZ d d
lmZ d dlmZ ed   Zdej8                  defdZdedej8                  fdZej>                  ej@                   G d de
                    Z!ejD                  dejF                  ejH                     dej8                  de!fd       Z%ejD                  ejL                   ejN                  d      dejP                  dejF                  e   dejR                  fd                     Z*ej>                  ej@                   G d de
                    Z+y)    )Iterator)Literalget_argsN)libav)Buffer
ByteSource
bytesource)	err_check)opaque_container)avrational_to_fractionto_avrational)	Py_DECREF	Py_INCREF)uint8_t)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r:   s    </root/.hermes/venv/lib/python3.12/site-packages/av/packet.pypacket_sidedata_type_to_literalrD   =   s    L!&++c5"9::    c                 >    t        t              j                  |       S r=   )r   r>   indexrB   s    rC   !packet_sidedata_type_from_literalrH   A   s    L!''..rE   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_typer;   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`
        )rH   _packet_sidedata_from_packetptr)rK   rL   r:   s      rC   from_packetzPacketSideData.from_packetH   s     2)<+FJJ>>rE   r:   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)r:   r?   nogilr@   p_ucharlib	av_mallocdataNULLMemoryErrorrQ   )selfr:   rQ   s      rC   	__cinit__zPacketSideData.__cinit__W   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r=   )r?   rT   rV   av_freepaddressrX   r[   s    rC   __dealloc__zPacketSideData.__dealloc__b   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   NrS   )rQ   rX   r?   rT   r@   rU   rV   rW   rY   rZ   r   av_packet_add_side_datarO   r:   r
   )r[   rK   rc   rX   ress        rC   	to_packetzPacketSideData.to_packetf   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
        )rD   r:   r`   s    rC   rL   zPacketSideData.data_type   s     /tzz::rE   c                 @    t        j                  | j                        S )zT
        The description of this packet side data type.

        :type: str
        )rV   av_packet_side_data_namer:   r`   s    rC   	data_desczPacketSideData.data_desc   s     ++DJJ77rE   c                     | j                   S )zQ
        The size in bytes of this packet side data.

        :type: int
        rQ   r`   s    rC   	data_sizezPacketSideData.data_size   s     yyrE   c                     | j                   S r=   rm   r`   s    rC   _buffer_sizezPacketSideData._buffer_size       yyrE   c                     | j                   S r=   )rX   r`   s    rC   _buffer_ptrzPacketSideData._buffer_ptr   rq   rE   c                      y)NT r`   s    rC   _buffer_writablezPacketSideData._buffer_writable   s    rE   c                 <    | j                   t        j                  k7  S )zK
        True if this object holds side data.

        :type: bool
        )rX   r?   rY   r`   s    rC   __bool__zPacketSideData.__bool__   s     yyFKK''rE   NF)__name__
__module____qualname__staticmethodPacketr>   rJ   rP   rV   AVPacketSideDataTyper?   size_tr\   ra   bintrg   propertystrrL   rk   rA   rn   cfuncrp   p_voidrs   rv   boolrx   ru   rE   rC   rJ   rJ   E   s*    ?F ?| ? ? ?	s77 	v}} 	4 fkk : ;3 ; ; 83 8 8 3   \\fmm   \\V]]   \\&++  ($ (rE   rJ   rK   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?   rT   rV   av_packet_side_data_get	side_dataside_data_elemsrY   rJ   rQ   r   rX   )rK   r:   c_ptrfoundsdatas        rC   rN   rN      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F)checkopaquerX   c                     | t         j                  k7  r=t         j                  5  t        t        j                  t
        |              d d d        y y # 1 sw Y   y xY wr=   )r?   rY   gilr   r@   object)r   rX   s     rC   _python_freer      sI     ZZ 	3fkk&&12	3 	3 	3 	3s   $AA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)-r~   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r=   )r?   rT   rV   av_packet_allocrO   )r[   inputs     rC   r\   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r=   )r?   rT   rV   av_packet_freer_   rO   r`   s    rC   ra   zPacket.__dealloc__   s9    \\ 	9v~~dhh78	9 	9 	9rb   c           	         d}d }|y t        |t              rQ|}|rLt        t        j                  | j
                  t        j                  t        j                  |                   y y t        |      }|j                  }|rt        |       t        j                  |j
                  |t        t        j                  t        j                  |      d      }|t        j                  k(  rt        |       t!        d      || j
                  _        |j
                  | j
                  _        t        j                  t        j                  |      | j
                  _        y y )Nr   zCould not allocate AVBufferRef)
isinstancerA   r
   rV   av_new_packetrO   r?   r@   r	   lengthr   av_buffer_creater   r   rY   r   rZ   bufrX   rQ   )r[   r   rQ   sourcer   s        rC   __init__zPacket.__init__   s   ! =eS!D#++DHHfkk&**d6STU   &F==D&!**JJ KKv6 &++%f%%&FGG" &

 &FJJ = rE   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>)	_streamrG   	__class__rz   dtsptsrO   rQ   idr[   streams     rC   __repr__zPacket.__repr__  sq    '+||##$..))*%xvdhhZ HHH:Rl2d8A,aI	
rE   r;   c                 .    | j                   j                  S r=   rO   rQ   r`   s    rC   rp   zPacket._buffer_size      xx}}rE   c                 .    | j                   j                  S r=   )rO   rX   r`   s    rC   rs   zPacket._buffer_ptr  r   rE   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
ValueErrorrO   	time_basedenrV   av_packet_rescale_ts)r[   r   s     rC   _rebase_timezPacket._rebase_time  s    ww:;;xx!!%%!$DHH88!!SWW,1C1C1G1G3771R  488+=+=sC rE   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    rC   r   zPacket.decode$  s    
 ||""4((rE   c                 .    | j                   j                  S r=   )rO   stream_indexr`   s    rC   r   zPacket.stream_index+  s    xx$$$rE   c                     | j                   S )zC
        The :class:`Stream` this packet was demuxed from.
        )r   r`   s    rC   r   zPacket.stream/  s    
 ||rE   r   c                 \    || _         |j                  j                  | j                  _        y r=   )r   rO   rG   r   r   s     rC   r   zPacket.stream6  s     &

 0 0rE   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_   rO   r   r`   s    rC   r   zPacket.time_base;  s"     &fnnTXX5G5G&HIIrE   c                 j    t        |t        j                  | j                  j                               y r=   )r   r?   r_   rO   r   )r[   values     rC   r   zPacket.time_baseD  s    eV^^DHH,>,>?@rE   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)rO   r   rV   AV_NOPTS_VALUEr`   s    rC   r   z
Packet.ptsH  s-     88<<3---88<< .rE   c                 j    | t         j                  | j                  _        y || j                  _        y r=   )rV   r   rO   r   r[   vs     rC   r   z
Packet.ptsT  #    9--DHHLDHHLrE   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)rO   r   rV   r   r`   s    rC   r   z
Packet.dts[  s-     88<<3---88<< .rE   c                 j    | t         j                  | j                  _        y || j                  _        y r=   )rV   r   rO   r   r   s     rC   r   z
Packet.dtse  r   rE   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)rO   posr`   s    rC   r   z
Packet.posl  s'     88<<288<< rE   c                 .    | j                   j                  S )zN
        The size in bytes of this packet's data.

        :type: int
        r   r`   s    rC   rQ   zPacket.sizex  s     xx}}rE   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)rO   durationrV   r   r`   s    rC   r   zPacket.duration  s1     88 2 2288$$$ 3rE   c                 j    | t         j                  | j                  _        y || j                  _        y r=   )rV   r   rO   r   r   s     rC   r   zPacket.duration  s%    9 # 2 2DHH !DHHrE   c                 b    t        | j                  j                  t        j                  z        S r=   )r   rO   flagsrV   AV_PKT_FLAG_KEYr`   s    rC   is_keyframezPacket.is_keyframe  s     DHHNNS%8%8899rE   c                     |r.| j                   xj                  t        j                  z  c_        y | j                   xj                  t        j                   z  c_        y r=   )rO   r   rV   r   r   s     rC   r   zPacket.is_keyframe  s8    HHNNc111NHHNN 3 344NrE   c                 b    t        | j                  j                  t        j                  z        S r=   )r   rO   r   rV   AV_PKT_FLAG_CORRUPTr`   s    rC   
is_corruptzPacket.is_corrupt       DHHNNS%<%<<==rE   c                     |r.| j                   xj                  t        j                  z  c_        y | j                   xj                  t        j                   z  c_        y r=   )rO   r   rV   r   r   s     rC   r   zPacket.is_corrupt  s8    HHNNc555NHHNN 7 788NrE   c                 b    t        | j                  j                  t        j                  z        S r=   )r   rO   r   rV   AV_PKT_FLAG_DISCARDr`   s    rC   
is_discardzPacket.is_discard  r   rE   c                 b    t        | j                  j                  t        j                  z        S r=   )r   rO   r   rV   AV_PKT_FLAG_TRUSTEDr`   s    rC   
is_trustedzPacket.is_trusted  r   rE   c                 b    t        | j                  j                  t        j                  z        S r=   )r   rO   r   rV   AV_PKT_FLAG_DISPOSABLEr`   s    rC   is_disposablezPacket.is_disposable  s     DHHNNS%?%??@@rE   c                     | j                   j                  t        j                  urUt	        j
                  t        j                  t        j                  | j                   j                  j                              S y r=   )	rO   
opaque_refr?   rY   r   getr@   p_charrX   r`   s    rC   r   zPacket.opaque  sR    88fkk1#''FMM488+>+>+C+CD  2rE   c                     t        j                  t        j                  | j                  j
                               |y t        j                  |      | j                  _        y r=   )rV   av_buffer_unrefr?   r_   rO   r   r   addr   s     rC   r   zPacket.opaque  sB    FNN488+>+>?@9.2215rE   r:   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
        )rH   rV   r   rO   r   r   r?   rY   )r[   r:   dtype2s      rC   has_sidedatazPacket.has_sidedata  sJ     359''""DHH$<$<f {{	
rE   c                 .    t         j                  | |      S )a  get a copy of the side data

        :param dtype: side data type (:meth:`~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`
        )rJ   rP   )r[   r:   s     rC   get_sidedatazPacket.get_sidedata  s     ))$66rE   sidedatarc   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)rg   )r[   r   rc   s      rC   set_sidedatazPacket.set_sidedata  s     	4&rE   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)rangerO   r   rN   r   type)r[   is     rC   iter_sidedatazPacket.iter_sidedata  sN      txx//0 	UA.txx9K9KA9N9S9STT	Us   AA!r=   ry   ),rz   r{   r|   __doc__r\   ra   r   r   r?   r   r   rp   r   rs   rV   
AVRationalr   r   r   r   r   setterStreamr   r   r   r   rQ   r   r   r   r   r   r   r   r   r   r   rJ   r   r   r   r   r   ru   rE   rC   r~   r~      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rE   r~   ),collections.abcr   typingr   r   r?   cython.cimportsr   rV   cython.cimports.av.bufferr   r   r	   cython.cimports.av.errorr
   cython.cimports.av.opaquer   cython.cimports.av.utilsr   r   cython.cimports.cpython.refr   r   cython.cimports.libc.stdintr   cython.cimports.libc.stringr   r>   r   rD   rH   finalcclassrJ   r   pointerAVPacketrN   rT   	exceptvalr   voidr   r~   ru   rE   rC   <module>r     st   $ $  ( D D . 6 J < / .
 ')X;3+C+C ; ;/\ /c>V>V / k(V k(  k(\ NN3<<(141I1I $ 3MM3
..
!3 [[3   3 ZUV ZU  ZUrE   