o
    iL                     @   sx   d dl Z d dlmZmZ d dl mZ d dlmZ dd ZeG dd deZeG d	d
 d
eZ	eG dd deZ
dS )    N)IterableIterator)	dataclass)Tensorc                 C   s^   | j jd }d}t| D ]}|j}t| |}|dkr d}|j}|| | d| d7 }q|S )Nz:
z  datazdata (shape)z: 
)	__class____name__dataclassesfieldsnamegetattrshape)selfsspacesfield
field_name	field_val r   P/home/ubuntu/Irodori-TTS/.venv/lib/python3.10/site-packages/torchcodec/_frame.py_frame_repr   s   
r   c                   @   sV   e Zd ZU dZeed< 	 eed< 	 eed< 	 dd ZdeeeB  fdd	Z	d
d Z
dS )Framez.A single video frame with associated metadata.r   pts_secondsduration_secondsc                 C   s:   | j jdkstd| j jt| j| _t| j| _d S )N   z2data must be 3-dimensional, got self.data.shape = )r   ndim
ValueErrorr   floatr   r   r   r   r   r   __post_init__*      zFrame.__post_init__returnc                 c   $    t | D ]	}t| |jV  qd S Nr
   r   r   r   r   r   r   r   r   __iter__2      zFrame.__iter__c                 C      t | S r$   r   r   r   r   r   __repr__6      zFrame.__repr__N)r	   
__module____qualname____doc__r   __annotations__r   r    r   r'   r+   r   r   r   r   r      s   
 r   c                   @   sd   e Zd ZU dZeed< 	 eed< 	 eed< 	 dd Zded  fdd	Zdd
dZ	dd Z
dd ZdS )
FrameBatcha  Multiple video frames with associated metadata.

    The ``data`` tensor is typically 4D for sequences of frames (NHWC or NCHW),
    or 5D for sequences of clips, as returned by the :ref:`samplers
    <sphx_glr_generated_examples_decoding_sampling.py>`. When ``data`` is 4D (resp.  5D)
    the ``pts_seconds`` and ``duration_seconds`` tensors are 1D (resp. 2D).

    .. note::
        The ``pts_seconds`` and ``duration_seconds`` Tensors are always returned
        on CPU, even if ``data`` is on GPU.
    r   r   r   c              
   C   s~   | j jdk rtd| j j| j jd d }|| jj  kr%| jjks=n td| j jd|d| jjd| jjd	d S )	Nr   z;data must be at least 3-dimensional, got self.data.shape = zjTried to create a FrameBatch but the leading dimensions of the inputs do not match. Got self.data.shape = zS so we expected the shape of pts_seconds and duration_seconds to be leading_dims = z#, but got self.pts_seconds.shape = z# and self.duration_seconds.shape = .)r   r   r   r   r   r   )r   leading_dimsr   r   r   r    O   s$   zFrameBatch.__post_init__r"   c                 c   s4    t | j| j| jD ]\}}}t|||dV  q
d S N)r   r   r   )zipr   r   r   r1   )r   r   r   r   r   r   r   r'   `   s   
zFrameBatch.__iter__c                 C   s    t | j| | j| | j| dS r5   )r1   r   r   r   )r   keyr   r   r   __getitem__j   s
   zFrameBatch.__getitem__c                 C   s
   t | jS r$   )lenr   r   r   r   r   __len__q   s   
zFrameBatch.__len__c                 C   r)   r$   r*   r   r   r   r   r+   t   r,   zFrameBatch.__repr__N)r"   r1   )r	   r-   r.   r/   r   r0   r    r   r'   r8   r:   r+   r   r   r   r   r1   :   s   
 

r1   c                   @   s`   e Zd ZU dZeed< 	 eed< 	 eed< 	 eed< 	 dd Zde	eeB  fd	d
Z
dd ZdS )AudioSamplesz'Audio samples with associated metadata.r   r   r   sample_ratec                 C   s:   | j jdkstd| j jt| j| _t| j| _d S )N   z2data must be 2-dimensional, got self.data.shape = )r   r   r   r   r   r   intr<   r   r   r   r   r       r!   zAudioSamples.__post_init__r"   c                 c   r#   r$   r%   r&   r   r   r   r'      r(   zAudioSamples.__iter__c                 C   r)   r$   r*   r   r   r   r   r+      r,   zAudioSamples.__repr__N)r	   r-   r.   r/   r   r0   r   r>   r    r   r'   r+   r   r   r   r   r;   x   s   
 r;   )r
   collections.abcr   r   r   torchr   r   r   r1   r;   r   r   r   r   <module>   s   =