
    ^j                        d dl mZ d dlZd dlZd dlmZmZ d dlZd dlm	Z	 erd dl
mZ  e	d          Z G d dej                  ZdS )	    )annotationsN)TYPE_CHECKINGSet)debug_print)AbstractAudioPlayerdebug_mediac                  P     e Zd ZdZdZd fdZddZddZddZddZ	ddZ
 xZS )PlayerWorkerThreadaW  Worker thread for refilling audio players.

    This thread manages calling the ``work`` method on low level AudioPlayer
    instances (not the high level Player instances). This allows the players
    to keep their buffers filled (and perform event dispatching tasks), but
    does not block the main thread.

    This thread will sleep for a small period between updates, but provides a
    :py:meth:`~notify` method to allow waking it immediately. A :py:meth:`~stop`
    method is provided to terminate the thread, but under normal operation it
    will exit cleanly on interpreter shutdown.
    g{Gz?returnNonec                    t                                          d           t          j                    | _        t          j                    | _        d| _        t                      | _	        d S )NT)daemonF)
super__init__	threadingEvent_rest_eventLock_operation_lock_stoppedsetplayers)self	__class__s    \/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/media/player_worker_thread.pyr   zPlayerWorkerThread.__init__%   sT    %%%$?,,(~//14    c                   t           j        d         rt          j                     d }	 t          d|dnd|            sJ | j                            |           | j                                         t          dt          j                               sJ | j        rnO| j	        5  | j
        r&| j        }| j
        D ]}|                                 nd }d d d            n# 1 swxY w Y   t          d          sJ d S )Ndebug_traceTz'PlayerWorkerThread.run: Going to sleep zindefinitely; no active playerszfor z!PlayerWorkerThread.run: woke up @zPlayerWorkerThread.run: exiting)pygletoptions_install_trace_debugr   waitcleartimer   r   r   	_nap_timework)r   
sleep_timeplayers      r   runzPlayerWorkerThread.run.   s   >-( 	$!###
	& pBLBT>>ZmakZmZmp p q q q q q!!*---""$$$KdikkKKLLLLL} % & &< &!%J"&, & && "&J& & & & & & & & & & & & & & &	&& 89999999s   +0C''C+.C+c                    t          d          sJ d| _        | j                                         	 |                                  dS # t
          $ r Y dS w xY w)a&  Stop the thread and wait for it to terminate.

        The ``stop`` instance variable is set to ``True`` and the rest event
        is set.  It is the responsibility of the ``run`` method to check
        the value of ``_stopped`` after each sleep or wait and to return if
        set.
        zPlayerWorkerThread.stop()TN)r"   r   r   r   joinRuntimeErrorr   s    r   stopzPlayerWorkerThread.stopI   sm     122222	IIKKKKK 	 	 	DD	s   A	 	
AAc                Z    t          d          sJ | j                                         dS )a"  Interrupt the current sleep operation.

        If the thread is currently sleeping, it will be woken immediately
        instead of waiting the full duration of the timeout.
        If the thread is not sleeping, it will run again as soon as it is
        done with its operation.
        zPlayerWorkerThread.notify()N)r"   r   r   r.   s    r   notifyzPlayerWorkerThread.notifyZ   s4     344444r   r)   r   c                    |J t          d          sJ | j        5  | j                            |           ddd           n# 1 swxY w Y   |                                  dS )zAdd a player to the PlayerWorkerThread, and call :py:meth:`~notify`.

        When a player is added, it's ``work`` method will be called regularly.

        .. note:: Do not call this method from within the thread, as it will deadlock.
        Nz PlayerWorkerThread: player added)r"   r   r   addr1   r   r)   s     r   r3   zPlayerWorkerThread.adde   s     !!!899999! 	% 	%LV$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	s   AAAc                    t          d          sJ || j        v r<| j        5  | j                            |           ddd           dS # 1 swxY w Y   dS dS )zRemove a player from the PlayerWorkerThread.

        This call has no effect if the player does not exist.

        .. note:: Do not call this method from within the thread, as it will deadlock.
        z"PlayerWorkerThread: player removedN)r"   r   r   remover4   s     r   r6   zPlayerWorkerThread.removet   s     :;;;;;T\!!% , ,##F+++, , , , , , , , , , , , , , , , , , "!s   A

AA)r   r   )r)   r   r   r   )__name__
__module____qualname____doc__r&   r   r*   r/   r1   r3   r6   __classcell__)r   s   @r   r
   r
      s          I7 7 7 7 7 7: : : :6   "	 	 	 	   , , , , , , , ,r   r
   )
__future__r   r%   r   typingr   r   r   pyglet.utilr   pyglet.media.drivers.baser   r"   Threadr
    r   r   <module>rB      s    " " " " " "      % % % % % % % %  # # # # # # >====== 
]	#	#l, l, l, l, l,) l, l, l, l, l,r   