U
    ,:%eх                     @  s  d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZ d dlZd dlZd dlmZ ejjdk	rxejjjZejjjZdgZeG dd dZeG d	d
 d
eZeG dd deZdd ZeG dd dZeG dd deZeG dd deZdd ZddddddZdddddddZ G d d! d!ej!Z"eG d"d# d#e"Z#d$d% Z$d&Z%d'Z&d(Z'd)Z(d*Z)d+Z*d,Z+e$e%e&e'e)e*d-Z,e$e%e&e(e)e*e+d.Z-e
d/ed0Z.e
ded0Z/ejj0G d1d dZdS )2    )annotations)	dataclass)BinaryIODictIteratorOptionalTupleTypeVarUnionNtree_mapStreamReaderc                   @  sR   e Zd ZU dZded< ded< ded< ded< ded	< ded
< ded< ded< dS )SourceStreama  The metadata of a source stream, returned by :meth:`~torchaudio.io.StreamReader.get_src_stream_info`.

    This class is used when representing streams of media type other than `audio` or `video`.

    When source stream is `audio` or `video` type, :class:`SourceAudioStream` and
    :class:`SourceVideoStream`, which reports additional media-specific attributes,
    are used respectively.
    str
media_typecodeccodec_long_nameOptional[str]formatOptional[int]bit_rate
num_framesbits_per_sampleDict[str, str]metadataN__name__
__module____qualname____doc____annotations__ r!   r!   [/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/torchaudio/io/_stream_reader.pyr      s   
		r   c                   @  s"   e Zd ZU dZded< ded< dS )SourceAudioStreama  The metadata of an audio source stream, returned by :meth:`~torchaudio.io.StreamReader.get_src_stream_info`.

    This class is used when representing audio stream.

    In addition to the attributes reported by :class:`SourceStream`,
    the following attributes are reported.
    floatsample_rateintnum_channelsNr   r!   r!   r!   r"   r#   M   s   
r#   c                   @  s*   e Zd ZU dZded< ded< ded< dS )SourceVideoStreama  The metadata of a video source stream, returned by :meth:`~torchaudio.io.StreamReader.get_src_stream_info`.

    This class is used when representing video stream.

    In addition to the attributes reported by :class:`SourceStream`,
    the following attributes are reported.
    r&   widthheightr$   
frame_rateNr   r!   r!   r!   r"   r(   ]   s
   
r(   c                 C  s   | j }|dkr>t| j | j| j| j| j| j| j| j| j	| j
d
S |dkrzt| j | j| j| j| j| j| j| j| j| j| jdS t| j | j| jd d d d | jdS )Naudio)
r   r   r   r   r   r   r   r   r%   r'   video)r   r   r   r   r   r   r   r   r)   r*   r+   )r   r   r   r   r   r   r   r   )r   r#   Z
codec_namer   r   r   r   r   r   r%   r'   r(   r)   r*   r+   r   ir   r!   r!   r"   	_parse_sio   sL    r0   c                   @  s2   e Zd ZU dZded< ded< ded< ded< dS )	OutputStreamzOutput stream configured on :class:`StreamReader`,
    returned by :meth:`~torchaudio.io.StreamReader.get_out_stream_info`.
    r&   source_indexr   filter_descriptionr   r   Nr   r!   r!   r!   r"   r1      s   
r1   c                   @  s"   e Zd ZU dZded< ded< dS )OutputAudioStreama*  Information about an audio output stream configured with
    :meth:`~torchaudio.io.StreamReader.add_audio_stream` or
    :meth:`~torchaudio.io.StreamReader.add_basic_audio_stream`.

    In addition to the attributes reported by :class:`OutputStream`,
    the following attributes are reported.
    r$   r%   r&   r'   Nr   r!   r!   r!   r"   r4      s   
r4   c                   @  s*   e Zd ZU dZded< ded< ded< dS )OutputVideoStreama)  Information about a video output stream configured with
    :meth:`~torchaudio.io.StreamReader.add_video_stream` or
    :meth:`~torchaudio.io.StreamReader.add_basic_video_stream`.

    In addition to the attributes reported by :class:`OutputStream`,
    the following attributes are reported.
    r&   r)   r*   r$   r+   Nr   r!   r!   r!   r"   r5      s
   
r5   c              	   C  sv   | j }|dkr.t| j| j| j | j| j| jdS |dkrZt| j| j| j | j| j| j	| j
dS td| j  d|  dd S )Nr,   )r2   r3   r   r   r%   r'   r-   )r2   r3   r   r   r)   r*   r+   zUnexpected media_type: ())r   r4   r2   r3   r   r%   r'   r5   r)   r*   r+   
ValueErrorr.   r!   r!   r"   	_parse_oi   s*    	r9   r   r   )r%   fmtr'   c                 C  s   g }| d k	r| d|   |d k	s,|d k	rxg }|d k	rH| d|  |d k	rb| d| d | dd|  |rd|S d S )Nz
aresample=zsample_fmts=zchannel_layouts=czaformat=:,appendjoin)r%   r:   r'   descspartsr!   r!   r"   _get_afilter_desc   s    rC   Optional[float])r+   r)   r*   r:   c                 C  s   g }| d k	r| d|   g }|d k	r8| d|  |d k	rP| d|  |rj| dd|  |d k	r| d|  |rd|S d S )Nzfps=zwidth=zheight=zscale=r<   zformat=pix_fmts=r=   r>   )r+   r)   r*   r:   rA   scalesr!   r!   r"   _get_vfilter_desc   s    rF   c                      s6   e Zd ZejjZe fddZe	dddZ
  ZS )ChunkTensorBasec                   s   t  | |S N)super__new__)cls_elem_	__class__r!   r"   rJ     s    zChunkTensorBase.__new__r!   Nc                   s"    fdd}|t ||t ||S )Nc                   s   t |  r| jS | S rH   )
isinstancerL   )trK   r!   r"   unwrap  s    z2ChunkTensorBase.__torch_dispatch__.<locals>.unwrapr   )rK   funcrM   argskwargsrS   r!   rR   r"   __torch_dispatch__  s    z"ChunkTensorBase.__torch_dispatch__)r!   N)r   r   r   torchZ_CZ_disabled_torch_function_implZ__torch_function__staticmethodrJ   classmethodrW   __classcell__r!   r!   rN   r"   rG     s
   rG   c                   @  s"   e Zd ZU dZded< ded< dS )ChunkTensora  Decoded media frames with metadata.

    The instance of this class represents the decoded video/audio frames with
    metadata, and the instance itself behave like :py:class:`~torch.Tensor`.

    Client codes can pass instance of this class as-if it's
    :py:class:`~torch.Tensor` class, or call the methods defined on
    :py:class:`~torch.Tensor` class.

    Example:
        >>> # Define input streams
        >>> reader = StreamReader(...)
        >>> reader.add_audio_stream(frames_per_chunk=4000, sample_rate=8000)
        >>> reader.add_video_stream(frames_per_chunk=7, frame_rate=28)
        >>> # Decode the streams and fetch frames
        >>> reader.fill_buffer()
        >>> audio_chunk, video_chunk = reader.pop_chunks()

        >>> # Access metadata
        >>> (audio_chunk.pts, video_chunks.pts)
        (0.0, 0.0)
        >>>
        >>> # The second time the PTS is different
        >>> reader.fill_buffer()
        >>> audio_chunk, video_chunk = reader.pop_chunks()
        >>> (audio_chunk.pts, video_chunks.pts)
        (0.5, 0.25)

        >>> # Call PyTorch ops on chunk
        >>> audio_chunk.shape
        torch.Size([4000, 2]
        >>> power = torch.pow(video_chunk, 2)
        >>>
        >>> # the result is a plain torch.Tensor class
        >>> type(power)
        <class 'torch.Tensor'>
        >>>
        >>> # Metadata is not available on the result
        >>> power.pts
        AttributeError: 'Tensor' object has no attribute 'pts'
    ztorch.TensorrL   r$   ptsNr   r!   r!   r!   r"   r\     s   
+r\   c                    s    fdd}|S )Nc                   s   | j jf  | _ | S rH   )r   r   )objrV   r!   r"   	decoratorU  s    z_format_doc.<locals>.decoratorr!   )rV   r`   r!   r_   r"   _format_docT  s    ra   aK  Number of frames returned as one chunk.
                If the source stream is exhausted before enough frames are buffered,
                then the chunk is returned as-is.

                Providing ``-1`` disables chunking and :py:func:`pop_chunks` method
                will concatenate all the buffered frames and return it.ad  Internal buffer size.
                When the number of chunks buffered exceeds this number, old frames are
                dropped. For example, if ``frames_per_chunk`` is 5 and ``buffer_chunk_size`` is
                3, then frames older than ``15`` are dropped.
                Providing ``-1`` disables this behavior.

                Default: ``3``.zcThe source audio stream index.
                If omitted, :py:attr:`default_audio_stream` is used.zcThe source video stream index.
                If omitted, :py:attr:`default_video_stream` is used.a  The name of the decoder to be used.
                When provided, use the specified decoder instead of the default one.

                To list the available decoders, please use
                :py:func:`~torchaudio.utils.ffmpeg_utils.get_audio_decoders` for audio, and
                :py:func:`~torchaudio.utils.ffmpeg_utils.get_video_decoders` for video.

                Default: ``None``.a  Options passed to decoder.
                Mapping from str to str. (Default: ``None``)

                To list decoder options for a decoder, you can use
                ``ffmpeg -h decoder=<DECODER>`` command.

                |

                In addition to decoder-specific options, you can also pass options related
                to multithreading. They are effective only if the decoder support them.
                If neither of them are provided, StreamReader defaults to single thread.

                ``"threads"``: The number of threads (in str).
                Providing the value ``"0"`` will let FFmpeg decides based on its heuristics.

                ``"thread_type"``: Which multithreading method to use.
                The valid values are ``"frame"`` or ``"slice"``.
                Note that each decoder supports different set of methods.
                If not provided, a default value is used.

                - ``"frame"``: Decode more than one frame at once.
                  Each thread handles one frame.
                  This will increase decoding delay by one frame per thread
                - ``"slice"``: Decode more than one part of a single frame at once.

                |
                a  Enable hardware acceleration.

                When video is decoded on CUDA hardware, for example
                `decoder="h264_cuvid"`, passing CUDA device indicator to `hw_accel`
                (i.e. `hw_accel="cuda:0"`) will make StreamReader place the resulting
                frames directly on the specified CUDA device as CUDA tensor.

                If `None`, the frame will be moved to CPU memory.
                Default: ``None``.)frames_per_chunkbuffer_chunk_sizestream_indexdecoderdecoder_option)rb   rc   rd   re   rf   hw_accelZInputStream)boundc                   @  s  e Zd ZdZdMdddddd	d
Zedd Zedd Zedd Zedd Z	ddddZ
dddddZdddddZdNdd d!d"d#ZedOdddd%ddd&ddd'dddd'd'd(d)d*ZedPdddd+ddddd,ddd'dddd'd'd'dd-
d.d/ZedQddddd0ddd'dddd1d2d3ZedRdddddd4ddd'ddddd5d6d7Zdd8d9d:ZdSd<ddd=d>d?Zd@dA ZdBddCdDZdEddFdGZdTd<ddd=dHdIZdUd<ddJd=dKdLZdS )Vr   aN  Fetch and decode audio/video streams chunk by chunk.

    For the detailed usage of this class, please refer to the tutorial.

    Args:
        src (str, file-like object): The media source.
            If string-type, it must be a resource indicator that FFmpeg can
            handle. This includes a file path, URL, device identifier or
            filter expression. The supported value depends on the FFmpeg found
            in the system.

            If file-like object, it must support `read` method with the signature
            `read(size: int) -> bytes`.
            Additionally, if the file-like object has `seek` method, it uses
            the method when parsing media metadata. This improves the reliability
            of codec detection. The signagure of `seek` method must be
            `seek(offset: int, whence: int) -> int`.

            Please refer to the following for the expected signature and behavior
            of `read` and `seek` method.

            - https://docs.python.org/3/library/io.html#io.BufferedIOBase.read
            - https://docs.python.org/3/library/io.html#io.IOBase.seek

        format (str or None, optional):
            Override the input format, or specify the source sound device.
            Default: ``None`` (no override nor device input).

            This argument serves two different usecases.

            1) Override the source format.
               This is useful when the input data do not contain a header.

            2) Specify the input source device.
               This allows to load media stream from hardware devices,
               such as microphone, camera and screen, or a virtual device.


            .. note::

               This option roughly corresponds to ``-f`` option of ``ffmpeg`` command.
               Please refer to the ffmpeg documentations for the possible values.

               https://ffmpeg.org/ffmpeg-formats.html#Demuxers

               Please use :py:func:`~torchaudio.utils.ffmpeg_utils.get_demuxers` to list the
               demultiplexers available in the current environment.

               For device access, the available values vary based on hardware (AV device) and
               software configuration (ffmpeg build).

               https://ffmpeg.org/ffmpeg-devices.html#Input-Devices

               Please use :py:func:`~torchaudio.utils.ffmpeg_utils.get_input_devices` to list
               the input devices available in the current environment.

        option (dict of str to str, optional):
            Custom option passed when initializing format context (opening source).

            You can use this argument to change the input source before it is passed to decoder.

            Default: ``None``.

        buffer_size (int):
            The internal buffer size in byte. Used only when `src` is file-like object.

            Default: `4096`.
    N   zUnion[str, BinaryIO]r   zOptional[Dict[str, str]]r&   )srcr   optionbuffer_sizec                 C  sz   t |trt|||| _n$t|dr6t||||| _ntd| j }|dk rTd n|| _| j	 }|dk rpd n|| _
d S )Nreadz2`src` must be either a string or file-like object.r   )rP   r   _StreamReader_behasattr_StreamReaderFileObjr8   Zfind_best_audio_stream_default_audio_streamZfind_best_video_stream_default_video_stream)selfrj   r   rk   rl   r/   r!   r!   r"   __init__  s    



zStreamReader.__init__c                 C  s
   | j  S )zRNumber of streams found in the provided media source.

        :type: int
        )ro   num_src_streamsrt   r!   r!   r"   rv     s    zStreamReader.num_src_streamsc                 C  s
   | j  S )zPNumber of output streams configured by client code.

        :type: int
        )ro   num_out_streamsrw   r!   r!   r"   rx     s    zStreamReader.num_out_streamsc                 C  s   | j S )znThe index of default audio stream. ``None`` if there is no audio stream

        :type: Optional[int]
        )rr   rw   r!   r!   r"   default_audio_stream$  s    z!StreamReader.default_audio_streamc                 C  s   | j S )znThe index of default video stream. ``None`` if there is no video stream

        :type: Optional[int]
        )rs   rw   r!   r!   r"   default_video_stream,  s    z!StreamReader.default_video_streamr   )returnc                 C  s
   | j  S )zQGet the metadata of the source media.

        Returns:
            dict
        )ro   get_metadatarw   r!   r!   r"   r|   4  s    zStreamReader.get_metadataInputStreamTypes)r/   r{   c                 C  s   t | j|S )a0  Get the metadata of source stream

        Args:
            i (int): Stream index.
        Returns:
            InputStreamTypes:
                Information about the source stream.
                If the source stream is audio type, then
                :class:`~torchaudio.io._stream_reader.SourceAudioStream` is returned.
                If it is video type, then
                :class:`~torchaudio.io._stream_reader.SourceVideoStream` is returned.
                Otherwise :class:`~torchaudio.io._stream_reader.SourceStream` class is returned.
        )r0   ro   get_src_stream_infort   r/   r!   r!   r"   r~   <  s    z StreamReader.get_src_stream_infoOutputStreamTypesc                 C  s   | j |}t|S )a  Get the metadata of output stream

        Args:
            i (int): Stream index.
        Returns:
            OutputStreamTypes
                Information about the output stream.
                If the output stream is audio type, then
                :class:`~torchaudio.io._stream_reader.OutputAudioStream` is returned.
                If it is video type, then
                :class:`~torchaudio.io._stream_reader.OutputVideoStream` is returned.
        )ro   get_out_stream_infor9   )rt   r/   infor!   r!   r"   r   L  s    z StreamReader.get_out_stream_infopreciser$   r   )	timestampmodec                 C  sF   dddd}||kr0t dt|  d| | j|||  dS )a  Seek the stream to the given timestamp [second]

        Args:
            timestamp (float): Target time in second.
            mode (str): Controls how seek is done.
                Valid choices are;

                * "key": Seek into the nearest key frame before the given timestamp.
                * "any": Seek into any frame (including non-key frames) before the given timestamp.
                * "precise": First seek into the nearest key frame before the given timestamp, then
                  decode frames until it reaches the closes frame to the given timestamp.

                Note:
                   All the modes invalidate and reset the internal state of decoder.
                   When using "any" mode and if it ends up seeking into non-key frame,
                   the image decoded may be invalid due to lack of key frame.
                   Using "precise" will workaround this issue by decoding frames from previous
                   key frame, but will be slower.
        r         )keyanyr   z!The value of mode must be one of z	. Found: N)r8   listkeysro   seek)rt   r   r   modesr!   r!   r"   r   \  s    zStreamReader.seek   Zfltp)rd   re   rf   r   r%   r'   r   )rb   rc   rd   re   rf   r   r%   r'   c          	   
   C  s"   | j |||||t|||d dS )a
  Add output audio stream

        Args:
            frames_per_chunk (int): {frames_per_chunk}

            buffer_chunk_size (int, optional): {buffer_chunk_size}

            stream_index (int or None, optional): {stream_index}

            decoder (str or None, optional): {decoder}

            decoder_option (dict or None, optional): {decoder_option}

            format (str, optional): Output sample format (precision).

                If ``None``, the output chunk has dtype corresponding to
                the precision of the source audio.

                Otherwise, the sample is converted and the output dtype is changed
                as following.

                - ``"u8p"``: The output is ``torch.uint8`` type.
                - ``"s16p"``: The output is ``torch.int16`` type.
                - ``"s32p"``: The output is ``torch.int32`` type.
                - ``"s64p"``: The output is ``torch.int64`` type.
                - ``"fltp"``: The output is ``torch.float32`` type.
                - ``"dblp"``: The output is ``torch.float64`` type.

                Default: ``"fltp"``.

            sample_rate (int or None, optional): If provided, resample the audio.

            num_channels (int, or None, optional): If provided, change the number of channels.
        rd   re   rf   filter_descN)add_audio_streamrC   )	rt   rb   rc   rd   re   rf   r   r%   r'   r!   r!   r"   add_basic_audio_streamy  s    /
z#StreamReader.add_basic_audio_streamZrgb24)rd   re   rf   r   r+   r)   r*   rg   )
rb   rc   rd   re   rf   r   r+   r)   r*   rg   c                C  s&   | j |||||t|||	||
d dS )a'  Add output video stream

        Args:
            frames_per_chunk (int): {frames_per_chunk}

            buffer_chunk_size (int, optional): {buffer_chunk_size}

            stream_index (int or None, optional): {stream_index}

            decoder (str or None, optional): {decoder}

            decoder_option (dict or None, optional): {decoder_option}

            format (str, optional): Change the format of image channels. Valid values are,

                - ``"rgb24"``: 8 bits * 3 channels (R, G, B)
                - ``"bgr24"``: 8 bits * 3 channels (B, G, R)
                - ``"yuv420p"``: 8 bits * 3 channels (Y, U, V)
                - ``"gray"``: 8 bits * 1 channels

                Default: ``"rgb24"``.

            frame_rate (int or None, optional): If provided, change the frame rate.

            width (int or None, optional): If provided, change the image width. Unit: Pixel.

            height (int or None, optional): If provided, change the image height. Unit: Pixel.

            hw_accel (str or None, optional): {hw_accel}
        rd   re   rf   r   rg   N)add_video_streamrF   )rt   rb   rc   rd   re   rf   r   r+   r)   r*   rg   r!   r!   r"   add_basic_video_stream  s    -z#StreamReader.add_basic_video_streamr   )rb   rc   rd   re   rf   r   c                C  s@   |dkr| j n|}|dkr"td| j||||||p8i  dS )ad  Add output audio stream

        Args:
            frames_per_chunk (int): {frames_per_chunk}

            buffer_chunk_size (int, optional): {buffer_chunk_size}

            stream_index (int or None, optional): {stream_index}

            decoder (str or None, optional): {decoder}

            decoder_option (dict or None, optional): {decoder_option}

            filter_desc (str or None, optional): Filter description.
                The list of available filters can be found at
                https://ffmpeg.org/ffmpeg-filters.html
                Note that complex filters are not supported.

        NzThere is no audio stream.)ry   RuntimeErrorro   r   )rt   rb   rc   rd   re   rf   r   r/   r!   r!   r"   r     s    zStreamReader.add_audio_streamr   )rb   rc   rd   re   rf   r   rg   c          	   	   C  sB   |dkr| j n|}|dkr"td| j||||||p8i | dS )a  Add output video stream

        Args:
            frames_per_chunk (int): {frames_per_chunk}

            buffer_chunk_size (int, optional): {buffer_chunk_size}

            stream_index (int or None, optional): {stream_index}

            decoder (str or None, optional): {decoder}

            decoder_option (dict or None, optional): {decoder_option}

            hw_accel (str or None, optional): {hw_accel}

            filter_desc (str or None, optional): Filter description.
                The list of available filters can be found at
                https://ffmpeg.org/ffmpeg-filters.html
                Note that complex filters are not supported.
        NzThere is no video stream.)rz   r   ro   r   )	rt   rb   rc   rd   re   rf   r   rg   r/   r!   r!   r"   r     s     zStreamReader.add_video_stream)r/   c                 C  s   | j | dS )zoRemove an output stream.

        Args:
            i (int): Index of the output stream to be removed.
        N)ro   remove_streamr   r!   r!   r"   r   ?  s    zStreamReader.remove_stream      $@rD   )timeoutbackoffr{   c                 C  s   | j ||S )a  Read the source media and process one packet.

        If a packet is read successfully, then the data in the packet will
        be decoded and passed to corresponding output stream processors.

        If the packet belongs to a source stream that is not connected to
        an output stream, then the data are discarded.

        When the source reaches EOF, then it triggers all the output stream
        processors to enter drain mode. All the output stream processors
        flush the pending frames.

        Args:
            timeout (float or None, optional): Timeout in milli seconds.

                This argument changes the retry behavior when it failed to
                process a packet due to the underlying media resource being
                temporarily unavailable.

                When using a media device such as a microphone, there are cases
                where the underlying buffer is not ready.
                Calling this function in such case would cause the system to report
                `EAGAIN (resource temporarily unavailable)`.

                * ``>=0``: Keep retrying until the given time passes.

                * ``0<``: Keep retrying forever.

                * ``None`` : No retrying and raise an exception immediately.

                Default: ``None``.

                Note:

                    The retry behavior is applicable only when the reason is the
                    unavailable resource. It is not invoked if the reason of failure is
                    other.

            backoff (float, optional): Time to wait before retrying in milli seconds.

                This option is effective only when `timeout` is effective. (not ``None``)

                When `timeout` is effective, this `backoff` controls how long the function
                should wait before retrying. Default: ``10.0``.

        Returns:
            int:
                ``0``
                A packet was processed properly. The caller can keep
                calling this function to buffer more frames.

                ``1``
                The streamer reached EOF. All the output stream processors
                flushed the pending frames. The caller should stop calling
                this method.
        )ro   process_packetrt   r   r   r!   r!   r"   r   G  s    9zStreamReader.process_packetc                 C  s   | j   dS )z%Process packets until it reaches EOF.N)ro   process_all_packetsrw   r!   r!   r"   r     s    z StreamReader.process_all_packetsboolc                 C  s
   | j  S )zFReturns true if all the output streams have at least one chunk filled.)ro   is_buffer_readyrw   r!   r!   r"   r     s    zStreamReader.is_buffer_readyzTuple[Optional[ChunkTensor]]c                 C  s@   g }| j  D ],}|dkr&|d q|t|j|j q|S )zPop one chunk from all the output stream buffers.

        Returns:
            Tuple[Optional[ChunkTensor]]:
                Buffer contents.
                If a buffer does not contain any frame, then `None` is returned instead.
        N)ro   
pop_chunksr?   r\   framesr]   )rt   retchunkr!   r!   r"   r     s    zStreamReader.pop_chunksc                 C  s   | j ||S )a  Keep processing packets until all buffers have at least one chunk

        Arguments:
            timeout (float or None, optional): See
                :py:func:`~StreamReader.process_packet`. (Default: ``None``)

            backoff (float, optional): See
                :py:func:`~StreamReader.process_packet`. (Default: ``10.0``)

        Returns:
            int:
                ``0``
                Packets are processed properly and buffers are
                ready to be popped once.

                ``1``
                The streamer reached EOF. All the output stream processors
                flushed the pending frames. The caller should stop calling
                this method.
        )ro   fill_bufferr   r!   r!   r"   r     s    zStreamReader.fill_bufferz+Iterator[Tuple[Optional[ChunkTensor], ...]]c                 c  sV   | j dkrtd| ||r q,|  V  q|  }tdd |D rJdS |V  q,dS )a  Return an iterator that generates output tensors

        Arguments:
            timeout (float or None, optional): See
                :py:func:`~StreamReader.process_packet`. (Default: ``None``)

            backoff (float, optional): See
                :py:func:`~StreamReader.process_packet`. (Default: ``10.0``)

        Returns:
            Iterator[Tuple[Optional[ChunkTensor], ...]]:
                Iterator that yields a tuple of chunks that correspond to the output
                streams defined by client code.
                If an output stream is exhausted, then the chunk Tensor is substituted
                with ``None``.
                The iterator stops if all the output streams are exhausted.
        r   zNo output stream is configured.c                 s  s   | ]}|d kV  qd S rH   r!   ).0r;   r!   r!   r"   	<genexpr>  s     z&StreamReader.stream.<locals>.<genexpr>N)rx   r   r   r   all)rt   r   r   chunksr!   r!   r"   stream  s    
zStreamReader.stream)NNri   )r   )r   )r   )r   )r   )Nr   )Nr   )Nr   )r   r   r   r   ru   propertyrv   rx   ry   rz   r|   r~   r   r   _format_audio_argsr   _format_video_argsr   r   r   r   r   r   r   r   r   r   r!   r!   r!   r"   r     s   H   



 "7 &6 )  ,;   )1
__future__r   dataclassesr   typingr   r   r   r   r   r	   r
   rX   Z
torchaudioZtorch.utils._pytreer   
_extensionZ_FFMPEG_EXTr   rn   ZStreamReaderFileObjrq   __all__r   r#   r(   r0   r1   r4   r5   r9   rC   rF   ZTensorrG   r\   ra   Z_frames_per_chunkZ_buffer_chunk_sizeZ_audio_stream_indexZ_video_stream_index_decoderZ_decoder_optionZ	_hw_accelr   r   r}   r   Zfail_if_no_ffmpegr!   r!   r!   r"   <module>   sp   $

8)5		
