ó
    ‡Ó}j;  ã                   óÈ   • % S SK r S SKJr  S SKJr  S SKJr  \ R                  " SSS9r\ R                  \	   \
S'   \S\	S	\S
   4S j5       rS	\	4S jrS\S	S4S jrS	\4S jrg)é    N)Ú	Generator)Úcontextmanager)Ú_coreÚ_CUDA_BACKENDÚdefault)r   ÚbackendÚreturn)NNNc              #   ó  #   • U R                  5       n U S:X  a  Sn U S;  a  [        SU  S35      eU S:X  a  Sn [        R                  U 5      n Sv •  [        R	                  U5        g! [        R	                  U5        f = f7f)aF  Context Manager to set the CUDA backend for :class:`~torchcodec.decoders.VideoDecoder`.

This context manager allows you to specify which CUDA backend implementation
to use when creating :class:`~torchcodec.decoders.VideoDecoder` instances
with CUDA devices.

The default is ``"nvdec"``. An ``"ffmpeg"`` backend is also available.

Only the creation of the decoder needs to be inside the context manager, the
decoding methods can be called outside of it. You still need to pass
``device="cuda"`` when creating the
:class:`~torchcodec.decoders.VideoDecoder` instance. If a CUDA device isn't
specified, this context manager will have no effect. See example below.

This is thread-safe and async-safe.

Args:
    backend (str): The CUDA backend to use. Can be ``"nvdec"`` (default) or
        ``"ffmpeg"``.

Example:
    >>> with set_cuda_backend("ffmpeg"):
    ...     decoder = VideoDecoder("video.mp4", device="cuda")
    ...
    ... # Only the decoder creation needs to be part of the context manager.
    ... # Decoder will use the FFmpeg CUDA implementation:
    ... decoder.get_frame_at(0)
ÚbetaÚnvdec)r   ÚffmpegzInvalid CUDA backend (z-). Supported values are 'nvdec' and 'ffmpeg'.r   N)ÚlowerÚ
ValueErrorr   ÚsetÚreset)r   Úprevious_states     Ú°C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\torchcodec/decoders/_decoder_utils.pyÚset_cuda_backendr      s…   é € ð< �m‰m‹o€GØ�&ÓØˆØÐ)Ó)ÜØ$ W IÐ-ZÐ[ó
ð 	
ð
 �'ÓØˆä"×&Ñ& wÓ/€Nð,Ûä×Ñ˜NÕ+øŒ×Ñ˜NÕ+üs   ‚ABÁA( ÁBÁ(A?Á?Bc                  ó*   • [         R                  5       $ )N)r   Úget© ó    r   Ú_get_cuda_backendr   F   s   € Ü×ÑÓÐr   Úcapacityc                 ó0   • [         R                  " U 5        g)al  Set the maximum number of NVDEC decoders that can be cached (per GPU).

The NVDEC decoder cache stores hardware decoders for reuse, avoiding the
overhead of creating and destructing new decoders for subsequent video
decoding operations on the same GPU. This function sets the capacity of the
cache, i.e. the maximum number of decoders that can be cached per device.
The default capacity is 20 decoders per device. If the cache contains more
decoders than the target ``capacity``, excess decoders will be evicted
using a least-recently-used policy.

Generally, a decoder can be re-used from the cache if it matches the same
codec and frame dimensions.

See also :func:`~torchcodec.decoders.get_nvdec_cache_capacity`.

Args:
    capacity (int): The maximum number of NVDEC decoders that can be cached
        per GPU device. Must be non-negative. Setting to 0 disables caching.
N)r   Úset_nvdec_cache_capacity)r   s    r   r   r   J   s   € ô( 
×"Ò" 8Õ,r   c                  ó,   • [         R                  " 5       $ )zÔGet the capacity of the per-device NVDEC decoder cache.

See also :func:`~torchcodec.decoders.set_nvdec_cache_capacity`.

Returns:
    int: The maximum number of NVDEC decoders that can be cached per GPU device.
)r   Úget_nvdec_cache_capacityr   r   r   r   r   a   s   € ô ×)Ò)Ó+Ð+r   )ÚcontextvarsÚcollections.abcr   Ú
contextlibr   Ú
torchcodecr   Ú
ContextVarr   ÚstrÚ__annotations__r   r   Úintr   r   r   r   r   Ú<module>r'      s�   ðô Ý %Ý %å ð .9×-CÒ-CØ˜Yñ.€ˆ{×%Ñ% cÑ*ó ð
 ð-,˜cð -, iÐ0@Ñ&Aó -,ó ð-,ð`˜3ô ð- sð -¨tô -ð., #õ ,r   