
    ^j-*                     >   d Z ddddgg dgddddgg dgdd	dd
gg dgddddgg ddgddg dg g dddddgdgdgddddgg dgddddgg dgdddgg dgddg dg d d!gdd"dgg d#gdd$Zh d%Z G d& d'          Z G d( d)          Zd* Zd+ Z G d, d-          Zd.S )/a#  
Responsibilities

    Defines the events that modify media_player state
    Defines which events are potential defects
    Gives the low level support to extract info from the recorded data
    For new code here, keep accepting and returning only data structures,
    never paths or files.
g?zmedia_player crashed.evnamesample)crash	small.mp4)descupdate_namesother_fields
test_casesPlay)mp.im   r   zStart playing	wall_time)p.P._spGz?Seekseek_to_time)p.P.skr   )r   NzEnter update_texture)r   	pyglet_dtcurrent_time
audio_timer   ))
p.P.ut.1.0{Gz?{Gz@=
ףp=@\(\?)r   r   Nr   r   )r   Nr   r   r   zDiscard video frame too old,
video_timer   )
p.P.ut.1.5r   zCurrent video frame,)
p.P.ut.1.6r   zCEarly return doing nothing because video_time is None (likely EOV),rescheduling_time)
p.P.ut.1.7r   zImage frame is None (?))
p.P.ut.1.8zRe-scheduling,)r   r   next_video_time)
p.P.ut.1.9r   N)r"   r   g@z>>> play ends)p.P.oe)versionr   r   r   r   r   r   r   r   r    r"   r#   >   r   r   r   r    c                   V    e Zd ZdZddddddddddddddZedfdZd Zd Zd	 Z	d
 Z
dS )MediaPlayerStateIteratora  Exposes for analysis the sequence of media_player states

    Typical use
        mp_states = MediaPlayerStateIterator()
        for st in mp_states:
            do something with st, the current media_player state.

    If desired a callback can be called just before processing an event, the
    signature is
        fn_pre_event(event, state_before_event)

    The mp state is handled as a dict, with keys in cls.fields
    N    )r   evnumr   r   r   r   r   r   r   r   r!   pyglet_time	frame_numc                     || _         t          | j                  | _        || _        t          |          | _        t          | j                  }|d| j        d         fk    sJ d S )Nr$   )fn_pre_eventdictfieldsstateevents_definitioniteriter_eventsnext)selfrecorded_eventsr1   r-   version_argss        W/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/media/instrumentation.py__init__z!MediaPlayerStateIterator.__init__   sg    ($+&&
!200D,--	4+A)+LMMMMMMM    c                     | S N )r5   s    r8   __iter__z!MediaPlayerStateIterator.__iter__   s    r:   c                     t          | j                  }| j        |                     || j                   |                     |          }|                     |           | j        S r<   )r4   r3   r-   r0   event_as_dictupdate)r5   event
event_dicts      r8   __next__z!MediaPlayerStateIterator.__next__   s`    T%&&(eTZ000''..
Jzr:   c                 l    | j         |d                  d         }d t          ||          D             }|S )Nr(   r   c                     i | ]\  }}||	S r=   r=   ).0abs      r8   
<dictcomp>z:MediaPlayerStateIterator.event_as_dict.<locals>.<dictcomp>   s    666DAq1a666r:   )r1   zip)r5   rB   namesupdateds       r8   r@   z&MediaPlayerStateIterator.event_as_dict   s:    &uQx0@66Cu$5$5666r:   c                     | j                             |           | j         dxx         dz  cc<   |d         }|dk    r| j         dxx         |d         z  cc<   d S |dk    s|dk    r| j         d	xx         dz  cc<   d S d S )
Nr)      r   r   r*   r   r   r"   r+   )r0   rA   )r5   rC   r   s      r8   rA   zMediaPlayerStateIterator.update   s    
*%%%
7q H%\!!J}%%%K)@@%%%%%|##v'='=J{###q(##### (>'=r:   )__name__
__module____qualname____doc__r/   	mp_eventsr9   r>   rD   r@   rA   r=   r:   r8   r&   r&   g   s          !
 
F$ ;DRV N N N N      
) ) ) ) )r:   r&   c                   (    e Zd ZdZefdZd Zd ZdS )TimelineBuildera^  At each call to player.Player.update_texture we capture selected player
    state, before accepting the changes in the event. This is the same as
    capturing the state at the end of previous update call.
    Output is a sequence of tuples capturing the desired fields.
    Meant to extract info on behalf of other sw, especially visualization.
    c                 N    t          ||| j                  }|| _        g | _        d S r<   )r&   premp_state_iteratortimeline)r5   r6   r1   mps       r8   r9   zTimelineBuilder.__init__   s)    %o7H$(SS!#r:   c                     |d         dk    rH|d         |d         |d         |d         |d         |d         f}| j                             |           d S d S )	Nr(   r   r   r*   r   r   r+   r   )rZ   append)r5   rB   stps       r8   rX   zTimelineBuilder.pre   sh    8|##K"]"3R5EN#R_b9L6MOAM  ##### $#r:   c                 4    | j         D ]}| j        dd         S )z.remember video_time and audio_time can be NonerO   N)rY   rZ   )r5   r^   s     r8   get_timelinezTimelineBuilder.get_timeline   s*     ( 	 	B}QRR  r:   N)rP   rQ   rR   rS   rT   r9   rX   ra   r=   r:   r8   rV   rV      sV          ;D    
$ $ $! ! ! ! !r:   rV   c           	          g }g }d}d}g }| D ]`\  }}}}	}
}|	|}	|                     ||f           n|	}||}|                     ||f           n|}|                     ||||	|
|f           a|||fS )z Eliminates Nones in timeline so other software don't error.
        Extra lists are built for the vars with nones, each list with one point
        for each None in the form (wall_time, prev_value).
    r(   )r]   )rZ   current_time_nonesaudio_time_nonesold_current_timeold_audio_timefiltered_timeliner   ptr   r   fnumrtcurrent_time_times                r8   timeline_postprocessingrl      s    
 N=E V V9	2z<r+L%%y2B&CDDDD ,'J##Y$?@@@@'N  )R\4QS!TUUUU02BBBr:   c                 *    | d         d         dk    }|S )Nr'   r(   r#   r=   )r6   crasheds     r8   crash_detectedro      s    b!!$0GNr:   c                   0    e Zd ZdZeefdZd Zd Zd Z	dS )	CountBadsar  Helper to report anomalies in the media_player states seen when playing
     a sample.

        - provides .anomalies_description, a dict <anomaly>: <description>
        - calling .count_bads(recorded_events) will return a dict of
          anomaly: <count times anomaly detected>
        - preprocessing: ad-hoc prefiltering the events stream for noise reduction
     c                 T    || _         || _        |                                 | _        d S r<   )r1   badsbuild_anomalies_descriptionanomalies_description)r5   r1   rs   s      r8   r9   zCountBads.__init__   s+    !2	%)%E%E%G%G"""r:   c                 F    | j         fd| j        D             }d|d<   |S )z%builds descriptions for the anomaliesc                 .    i | ]}||         d          S )r   r=   )rG   r   ds     r8   rJ   z9CountBads.build_anomalies_description.<locals>.<dictcomp>   s$     S S Sv66): S S Sr:   zScheduling in the pastscheduling_in_past)r1   rs   )r5   ru   rx   s     @r8   rt   z%CountBads.build_anomalies_description   s9    " S S S S S S S6N23$$r:   c                    t          |          }t          |          dk    r@|d         d         dk    r.|d         d         dk    r|d         d         dk    r
|d= |d= |d= nft          |          dk    r+|d         d         dk    r|d         d         dk    r|d= |d= n(t          |          dk    r|d         d         dk    r|d= |S )	a9  
        I see all recordings ending with some potential anomalies in the few
        frames just before the '>>> play ends'; visually the play is perfect so
        I assume they are false positives if just at EOF. Deleting the offending
        events (only if near EOL) to reduce noise in summarize.py
        	   r(   r   ii      )listlen)r5   r6   s     r8   preprocessingzCountBads.preprocessing   s    //  1$$#A&,66#A&,66$Q'<77$###/""Q&&b!!$44b!!$44###!!A%%/"*=a*@L*P*P#r:   c                    |                      |          }d | j        D             }d}t          || j                  }|D ]9}|d         }||v r||xx         dz  cc<   	 |d         |d         dk     r|dz  }:||d<   |S )	zreturns counts of anomalies as a dict of anomaly: count

        recorded_events: media_player events recorded while playing a sample

        Notice that 'counters' has one more key than 'bads': "scheduling_in_past"
        c                     i | ]}|d S )r(   r=   )rG   ks     r8   rJ   z(CountBads.count_bads.<locals>.<dictcomp>  s    ,,,QAq,,,r:   r(   r   rO   r"   r   Nry   )r   rs   r&   r1   )r5   r6   counterscnt_scheduling_in_past	mp_statesr^   r   s          r8   
count_badszCountBads.count_bads  s     ,,_==,,$),,,!",_d>TUU	 	, 	,B\F!!   A%    ,()5()A--&!+&)?%&r:   N)
rP   rQ   rR   rS   rT   mp_badsr9   rt   r   r   r=   r:   r8   rq   rq      sj        	 	 *3 H H H H
% % %  6    r:   rq   N)rS   rT   r   r&   rV   rl   ro   rq   r=   r:   r8   <module>r      sT     (!8,-.	
 
 !8,01	
 
  !;/()	
 
 !>2')9:	
 
 '4 4 4? ? ?
 
 /!<0'(+,	
 
 '!<0+,	
 
 V!#67+,	
 
 *!
&'	
 
 !JJJ13LM	
 
  !
"m	
 
_U U	p >
=
=?) ?) ?) ?) ?) ?) ?) ?)D! ! ! ! ! ! ! !6C C C:  
D D D D D D D D D Dr:   