o
    wiV                     @   sb   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mZ e jG dd deZdS )	    N)libav)
bytesource)	err_check)opaque_container)avrational_to_fractionto_avrationalc                   @   s  e Zd ZdZd:ddZdd Zd:ddZd	d
 Zej	dej
fddZej	dejfddZej	dejfddZdd Zedd Zedd ZejdefddZedd Zejdd Ze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jd*d) Zed+d, Zejd-d, Zed.d/ Zejd0d/ Zed1d2 Zed3d4 Z ed5d6 Z!ed7d8 Z"e"jd9d8 Z"dS );PacketzA 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                 C   s6   t j t | _W d    d S 1 sw   Y  d S N)cythonnogillibav_packet_allocptr)selfinput r   F/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/av/packet.py	__cinit__   s   "zPacket.__cinit__c                 C   s>   t j tt | j W d    d S 1 sw   Y  d S r	   )r
   r   r   av_packet_freeaddressr   r   r   r   r   __dealloc__   s   "zPacket.__dealloc__c                 C   sb   d}d }|d u r
d S t |tr|}nt|}|j}|r$tt| j| |d ur/| | d S d S )Nr   )	
isinstanceintr   lengthr   r   av_new_packetr   update)r   r   sizesourcer   r   r   __init__   s   
zPacket.__init__c                 C   sN   | 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>)	_streamindex	__class____name__dtsptsr   r   idr   streamr   r   r   __repr__/   s   zPacket.__repr__returnc                 C      | j jS r	   r   r   r   r   r   r   _buffer_size7      zPacket._buffer_sizec                 C   r-   r	   )r   datar   r   r   r   _buffer_ptr;   r0   zPacket._buffer_ptrdstc                 C   s\   |j std| jj s|| _d S | jj |j kr | jj|jkr d S t| j| j| || _d S )NzCannot rebase to zero time.)num
ValueError
_time_basedenr   av_packet_rescale_tsr   )r   r3   r   r   r   _rebase_time?   s   
zPacket._rebase_timec                 C   s   | 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   r   r   r   r:   O   s   zPacket.decodec                 C   r-   r	   )r   stream_indexr   r   r   r   r;   V   r0   zPacket.stream_indexc                 C   s   | j S )zC
        The :class:`Stream` this packet was demuxed from.
        )r"   r   r   r   r   r*   Z   s   zPacket.streamr*   c                 C   s   || _ |jj| j_d S r	   )r"   r   r#   r;   r)   r   r   r   r*   a   s   c                 C   s   t t| jS )z
        The unit of time (in fractional seconds) in which timestamps are expressed.

        :type: fractions.Fraction
        )r   r
   r   r6   r   r   r   r   	time_basef   s   zPacket.time_basec                 C   s   t |t| j d S r	   )r   r
   r   r6   )r   valuer   r   r   r<   o   s   c                 C      | j jtjkr| j jS dS )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)r   r'   r   AV_NOPTS_VALUEr   r   r   r   r'   s      	z
Packet.ptsc                 C   "   |d u rt j| j_d S || j_d S r	   )r   r?   r   r'   r   vr   r   r   r'         c                 C   r>   )zo
        The decoding timestamp in :attr:`time_base` units for this packet.

        :type: int | None
        N)r   r&   r   r?   r   r   r   r   r&      s   z
Packet.dtsc                 C   rA   r	   )r   r?   r   r&   rB   r   r   r   r&      rD   c                 C   s   | j jdkr
| j jS dS )z
        The byte position of this packet within the :class:`.Stream`.

        Returns `None` if it is not known.

        :type: int | None
        N)r   posr   r   r   r   rF      s   	z
Packet.posc                 C   r-   )zN
        The size in bytes of this packet's data.

        :type: int
        r.   r   r   r   r   r      s   zPacket.sizec                 C   r>   )z
        The duration in :attr:`time_base` units for this packet.

        Returns `None` if it is not known.

        :type: int
        N)r   durationr   r?   r   r   r   r   rG      r@   zPacket.durationc                 C   rA   r	   )r   r?   r   rG   rB   r   r   r   rG      rD   c                 C      t | jjtj@ S r	   )boolr   flagsr   AV_PKT_FLAG_KEYr   r   r   r   is_keyframe      zPacket.is_keyframec                 C   2   |r| j  jtjO  _d S | j  jtj M  _d S r	   )r   rJ   r   rK   rB   r   r   r   rL         c                 C   rH   r	   )rI   r   rJ   r   AV_PKT_FLAG_CORRUPTr   r   r   r   
is_corrupt   rM   zPacket.is_corruptc                 C   rN   r	   )r   rJ   r   rP   rB   r   r   r   rQ      rO   c                 C   rH   r	   )rI   r   rJ   r   AV_PKT_FLAG_DISCARDr   r   r   r   
is_discard   rM   zPacket.is_discardc                 C   rH   r	   )rI   r   rJ   r   AV_PKT_FLAG_TRUSTEDr   r   r   r   
is_trusted   rM   zPacket.is_trustedc                 C   rH   r	   )rI   r   rJ   r   AV_PKT_FLAG_DISPOSABLEr   r   r   r   is_disposable   rM   zPacket.is_disposablec                 C   s,   | j jtjurtttj| j jjS d S r	   )	r   
opaque_refr
   NULLr   getcastp_charr1   r   r   r   r   opaque   s
   zPacket.opaquec                 C   s2   t t| jj |d u rd S t|| j_d S r	   )r   av_buffer_unrefr
   r   r   rX   r   addrB   r   r   r   r]      s   r	   )#r%   
__module____qualname____doc__r   r   r   r+   r
   cfuncsize_tr/   p_voidr2   r   
AVRationalr9   r:   propertyr;   r*   setterStreamr<   r'   r&   rF   r   rG   rL   rQ   rS   rU   rW   r]   r   r   r   r   r   	   sr    








	












r   )r
   cython.cimportsr   r   cython.cimports.av.bytesourcer   cython.cimports.av.errorr   cython.cimports.av.opaquer   cython.cimports.av.utilsr   r   cclassBufferr   r   r   r   r   <module>   s    