jAER project on SourceForge

net.sf.jaer
Class JAERViewer.SyncPlayer

java.lang.Object
  extended by net.sf.jaer.JAERViewer.SyncPlayer
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener, AEPlayerInterface, PlayerInterface
Enclosing class:
JAERViewer

public class JAERViewer.SyncPlayer
extends java.lang.Object
implements AEPlayerInterface, java.beans.PropertyChangeListener

Synchronized playback and control of such playback is not totally straightforward because of the bursty nature of AER - there are no frames to synchronize on and you obviously cannot sync on event number.

This class sychronizes multiple viewer players. It assumes one is the master (whichever the user controls) and coordinates viewers synchrnously so that all viewers can present a consistent view.

To achieve this, each viewer encapsulates its playback functionality on an AEPlayer inner class instance that is controlled either by the Viewer GUI (the user) or by JAERViewer through its own SyncPlayer. The Players share a common interface so this is achieved by returning the correct object within AEViewer depending on whether the views are synchronized.

The individual threads doing the rendering in each AEViewer are barricaded by the CyclicBarrier here. Each time an AEViewer asks for synchronized events, the call here to SyncPlayer blocks until all threads asking for events have gotten them. Then rendering in each thread happens normally.


Constructor Summary
JAERViewer.SyncPlayer()
           
 
Method Summary
 void doSingleStep(AEViewer viewer)
           
 AEFileInputStream getAEInputStream()
          always returns null, bince this is a sync player for multiple viewers
 float getFractionalPosition()
           
 AEPacketRaw getNextPacket()
           
 AEPacketRaw getNextPacket(AEPlayerInterface player)
          returns next packet of AE data to the caller, which is a particular AEPlayer inner class of AEViewer.
 int getSampleNumEvents()
           
 int getSamplePeriodUs()
           
 int getTime()
          Return time in us in player
 boolean isChoosingFile()
          returns true if user is choosing a file
 boolean isPaused()
          returns true if the viewers are paused
 boolean isPlayingForwards()
           
 void mark()
           
 void openAEInputFileDialog()
          this call shows a file chooser for index files: files containing information on which AE data files go together
 void pause()
          pauses all players
 int position()
           
 int position(AEFileInputStreamInterface stream)
           
 void position(int event, AEFileInputStreamInterface stream)
           
 void propertyChange(java.beans.PropertyChangeEvent evt)
          JAERViewer gets PropertyChangeEvent from the AEPlayer in the AEViewers.
 AEPacketRaw readPacketByNumber(int n)
           
 AEPacketRaw readPacketByNumber(int n, AEFileInputStreamInterface stream)
           
 AEPacketRaw readPacketByTime(int dt)
           
 AEPacketRaw readPacketByTime(int dt, AEFileInputStreamInterface stream)
           
 void resume()
          resumes all players
 void rewind()
          rewinds all players
 void setFractionalPosition(float frac)
           
 void setPaused(boolean yes)
          pauses/unpauses all viewers
 void setSampleNumEvents(int sampleNumEvents)
           
 void setSamplePeriodUs(int samplePeriodUs)
           
 void setTime(int time)
          Sets all viewers to the same time.
 long size()
           
 long size(AEFileInputStream stream)
           
 void slowDown()
           
 void speedUp()
           
 void startPlayback(java.io.File indexFile)
          this call starts playback on the supplied index file, starting playback in each viewer appropriately.
 void stopPlayback()
          stops playback on all players
 void toggleDirection()
           
 void unmark()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JAERViewer.SyncPlayer

public JAERViewer.SyncPlayer()
Method Detail

isChoosingFile

public boolean isChoosingFile()
Description copied from interface: PlayerInterface
returns true if user is choosing a file

Specified by:
isChoosingFile in interface PlayerInterface

openAEInputFileDialog

public void openAEInputFileDialog()
this call shows a file chooser for index files: files containing information on which AE data files go together

Specified by:
openAEInputFileDialog in interface AEPlayerInterface

startPlayback

public void startPlayback(java.io.File indexFile)
                   throws java.io.IOException
this call starts playback on the supplied index file, starting playback in each viewer appropriately. If the file is not an index file, then the first available viewer is called to start playback of the data file.

Specified by:
startPlayback in interface PlayerInterface
Parameters:
indexFile - the .index file containing the filenames to play
Throws:
java.io.IOException

stopPlayback

public void stopPlayback()
stops playback on all players

Specified by:
stopPlayback in interface PlayerInterface

rewind

public void rewind()
rewinds all players

Specified by:
rewind in interface PlayerInterface

pause

public void pause()
pauses all players

Specified by:
pause in interface PlayerInterface

resume

public void resume()
resumes all players

Specified by:
resume in interface PlayerInterface

isPaused

public boolean isPaused()
returns true if the viewers are paused

Specified by:
isPaused in interface PlayerInterface

setPaused

public void setPaused(boolean yes)
pauses/unpauses all viewers

Specified by:
setPaused in interface PlayerInterface

getNextPacket

public AEPacketRaw getNextPacket(AEPlayerInterface player)
returns next packet of AE data to the caller, which is a particular AEPlayer inner class of AEViewer. The packet is sychronized in event time if sychronized playback is enabled.

Specified by:
getNextPacket in interface AEPlayerInterface
Returns:
a raw packet of events

toggleDirection

public void toggleDirection()
Specified by:
toggleDirection in interface PlayerInterface

speedUp

public void speedUp()
Specified by:
speedUp in interface AEPlayerInterface

slowDown

public void slowDown()
Specified by:
slowDown in interface AEPlayerInterface

isPlayingForwards

public boolean isPlayingForwards()
Specified by:
isPlayingForwards in interface PlayerInterface

getFractionalPosition

public float getFractionalPosition()

mark

public void mark()
          throws java.io.IOException
Specified by:
mark in interface PlayerInterface
Throws:
java.io.IOException

position

public int position(AEFileInputStreamInterface stream)

position

public int position()

position

public void position(int event,
                     AEFileInputStreamInterface stream)

readPacketByNumber

public AEPacketRaw readPacketByNumber(int n)
                               throws java.io.IOException
Throws:
java.io.IOException

readPacketByNumber

public AEPacketRaw readPacketByNumber(int n,
                                      AEFileInputStreamInterface stream)
                               throws java.io.IOException
Throws:
java.io.IOException

readPacketByTime

public AEPacketRaw readPacketByTime(int dt)
                             throws java.io.IOException
Throws:
java.io.IOException

readPacketByTime

public AEPacketRaw readPacketByTime(int dt,
                                    AEFileInputStreamInterface stream)
                             throws java.io.IOException
Throws:
java.io.IOException

size

public long size(AEFileInputStream stream)

size

public long size()

unmark

public void unmark()
Specified by:
unmark in interface PlayerInterface

setFractionalPosition

public void setFractionalPosition(float frac)

setTime

public void setTime(int time)
Sets all viewers to the same time.

Specified by:
setTime in interface PlayerInterface
Parameters:
time - current playback time relative to start in us

getTime

public int getTime()
Description copied from interface: PlayerInterface
Return time in us in player

Specified by:
getTime in interface PlayerInterface
Returns:
current playback time relative to start in us

getNextPacket

public AEPacketRaw getNextPacket()
Specified by:
getNextPacket in interface AEPlayerInterface

getSamplePeriodUs

public int getSamplePeriodUs()
Specified by:
getSamplePeriodUs in interface AEPlayerInterface

setSamplePeriodUs

public void setSamplePeriodUs(int samplePeriodUs)

getSampleNumEvents

public int getSampleNumEvents()
Specified by:
getSampleNumEvents in interface AEPlayerInterface

setSampleNumEvents

public void setSampleNumEvents(int sampleNumEvents)

getAEInputStream

public AEFileInputStream getAEInputStream()
always returns null, bince this is a sync player for multiple viewers

Specified by:
getAEInputStream in interface AEPlayerInterface

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
JAERViewer gets PropertyChangeEvent from the AEPlayer in the AEViewers. This method presently only logs this event.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener

doSingleStep

public void doSingleStep(AEViewer viewer)

jAER project on SourceForge