o
    ]i                     @   sT   d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	 e j
G dd dZdS )    N)	err_check)opaque_container)avrational_to_fractionto_avrational)SideDataContainerc                   @   s0  e Zd ZdZdd Zdd Zdd Zejd-d	e	d
ej
fddZejdd Zejdej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jdd Zed d! Zed"d# Zejd$d# Zed%d& Zd'd( Zed)d* Zejd+d* Zd,S ).Framez
    Base class for audio and video frames.

    See also :class:`~av.audio.frame.AudioFrame` and :class:`~av.video.frame.VideoFrame`.
    c                 O   s6   t j t | _W d    d S 1 sw   Y  d S N)cythonnogillibav_frame_allocptr)selfargskwargs r   </home/ubuntu/.local/lib/python3.10/site-packages/av/frame.py	__cinit__   s   "zFrame.__cinit__c                 C   s>   t j tt | j W d    d S 1 sw   Y  d S r   )r	   r
   r   av_frame_freeaddressr   r   r   r   r   __dealloc__   s   "zFrame.__dealloc__c                 C   s$   d| j j d| j dt| ddS )Nz<av.z pts=z at 0xx>)	__class____name__ptsidr   r   r   r   __repr__   s   $zFrame.__repr__Tsourcedata_layoutc                 C   sT   |j | _ t| j|j |r(|jj| j_|jj| j_|jj| j_|jj| j_d S d S r   )
_time_baser   av_frame_copy_propsr   formatwidthheight	ch_layout)r   r   r    r   r   r   _copy_internal_attributes   s   zFrame._copy_internal_attributesc                 C   s   d S r   r   r   r   r   r   _init_user_attributes(   s   zFrame._init_user_attributesdstc                 C   s   |j std| jj s|| _d S | jj |j kr | jj|jkr d S | jjtjkr3t| jj| j|| j_| jj	dkrEt| jj	| j|| j_	|| _d S )NzCannot rebase to zero time.r   )
num
ValueErrorr!   denr   r   r   AV_NOPTS_VALUEav_rescale_qduration)r   r)   r   r   r   _rebase_time,   s   
zFrame._rebase_timec                 C      | j jtjkr	dS | j jS )aL  
        The decoding timestamp copied from the :class:`~av.packet.Packet` that triggered returning this frame in :attr:`time_base` units.

        (if frame threading isn't used) This is also the Presentation time of this frame calculated from only :attr:`.Packet.dts` values without pts values.

        :type: int | None
        N)r   pkt_dtsr   r-   r   r   r   r   dtsB      	z	Frame.dtsc                 C   "   |d u rt j| j_d S || j_d S r   )r   r-   r   r2   r   valuer   r   r   r3   O      c                 C   r1   )z
        The presentation timestamp in :attr:`time_base` units for this frame.

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

        :type: int | None
        N)r   r   r   r-   r   r   r   r   r   V   r4   z	Frame.ptsc                 C   r5   r   )r   r-   r   r   r6   r   r   r   r   c   r8   c                 C   s   | j jS )zZ
        The duration of the frame in :attr:`time_base` units

        :type: int
        r   r/   r   r   r   r   r/   j   s   zFrame.durationc                 C   s   || j _d S r   r9   r6   r   r   r   r/   s   s   c                 C   s.   | j jtjkr	dS t| j j| jj | jj S )z
        The presentation time in seconds for this frame.

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

        :type: float | None
        N)r   r   r   r-   floatr!   r*   r,   r   r   r   r   timew   s   	z
Frame.timec                 C   s   | j jrtt| j S dS )z
        The unit of time (in fractional seconds) in which timestamps are expressed.

        :type: fractions.Fraction | None
        N)r!   r*   r   r	   r   r   r   r   r   	time_base   s   zFrame.time_basec                 C   s   t |t| j d S r   )r   r	   r   r!   r6   r   r   r   r<      s   c                 C   s   | j jdkpt| j jtj@ S )z=
        Is this frame corrupt?

        :type: bool
        r   )r   decode_error_flagsboolflagsr   AV_FRAME_FLAG_CORRUPTr   r   r   r   
is_corrupt   s   zFrame.is_corruptc                 C   s   t | jjtj@ S )zPIs this frame a key frame?

        Wraps :ffmpeg:`AVFrame.key_frame`.

        )r>   r   r?   r   AV_FRAME_FLAG_KEYr   r   r   r   	key_frame   s   zFrame.key_framec                 C   s2   |r| j  jtjO  _d S | j  jtj M  _d S r   )r   r?   r   rB   r   vr   r   r   rC      s   c                 C   s   | j d u r
t| | _ | j S r   )
_side_datar   r   r   r   r   	side_data   s   

zFrame.side_datac                 C   s   t | j}t| dS )z
        Ensures that the frame data is writable. Copy the data to new buffer if it is not.
        This is a wrapper around :ffmpeg:`av_frame_make_writable`.
        N)r   av_frame_make_writabler   r   )r   retr   r   r   make_writable   s   zFrame.make_writablec                 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_chardatar   r   r   r   opaque   s
   zFrame.opaquec                 C   s2   t t| jj |d urt|| j_d S d S r   )r   av_buffer_unrefr	   r   r   rK   r   addrD   r   r   r   rQ      s   N)T)r   
__module____qualname____doc__r   r   r   r	   cfuncr   bintr'   r(   r   
AVRationalr0   propertyr3   setterr   r/   r;   r<   rA   rC   rG   rJ   rQ   r   r   r   r   r   	   sT    








	






r   )r	   cython.cimports.av.errorr   cython.cimports.av.opaquer   cython.cimports.av.utilsr   r   av.sidedata.sidedatar   cclassr   r   r   r   r   <module>   s    