org.vigia.server.driver.camera
Class JMFCapture

java.lang.Object
  extended by org.vigia.server.driver.camera.JMFCapture
All Implemented Interfaces:
javax.media.ControllerListener

public class JMFCapture
extends java.lang.Object
implements javax.media.ControllerListener

Author:
Jesus

Field Summary
private  javax.media.util.BufferToImage bufferToImage
          BufferToImage object
private static java.lang.String CAP_DEVICE
          Common name in WinXP/Vista
private  boolean closedDevice
          closed device indication
private  javax.media.control.FrameGrabbingControl fg
          FrameGrabbingControl object
private static int MAX_TRIES
          tries used while waiting for the BufferToImage object to be initialized
private  javax.media.Player p
          Player object
private  boolean stateTransitionOK
          used for waiting until the player has started
private static int TRY_PERIOD
          period used while waiting for the BufferToImage object to be initialized
private  java.lang.Object waitSync
          used for waiting until the player has started
 
Constructor Summary
JMFCapture()
          JMFCapture constructor
 
Method Summary
 void close()
          close() and grabImage() are synchronized so that it's not possible to close down the player while a frame is being snapped.
 void controllerUpdate(javax.media.ControllerEvent evt)
          respond to events
 java.awt.image.BufferedImage grabImage()
          Capture an image/frame.
private  boolean hasBufferToImage()
          The BufferToImage object is initialized here, so that when grabImage() is called later, the snap can be quickly changed to an image.
 boolean isClosed()
          is closed the device?
private  java.awt.image.BufferedImage makeBIM(java.awt.Image im)
          Make a BufferedImage copy of im, assuming no alpha channel.
private  void waitForBufferToImage()
          Wait for the BufferToImage object to be initialized.
private  boolean waitForStart()
          wait for the player to enter its Started state
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CAP_DEVICE

private static final java.lang.String CAP_DEVICE
Common name in WinXP/Vista

See Also:
Constant Field Values

MAX_TRIES

private static final int MAX_TRIES
tries used while waiting for the BufferToImage object to be initialized

See Also:
Constant Field Values

TRY_PERIOD

private static final int TRY_PERIOD
period used while waiting for the BufferToImage object to be initialized

See Also:
Constant Field Values

p

private javax.media.Player p
Player object


fg

private javax.media.control.FrameGrabbingControl fg
FrameGrabbingControl object


bufferToImage

private javax.media.util.BufferToImage bufferToImage
BufferToImage object


closedDevice

private boolean closedDevice
closed device indication


waitSync

private java.lang.Object waitSync
used for waiting until the player has started


stateTransitionOK

private boolean stateTransitionOK
used for waiting until the player has started

Constructor Detail

JMFCapture

public JMFCapture()
JMFCapture constructor

Method Detail

waitForStart

private boolean waitForStart()
wait for the player to enter its Started state

Returns:
state

waitForBufferToImage

private void waitForBufferToImage()
Wait for the BufferToImage object to be initialized. May take several seconds to initialize this object, so this method makes up to MAX_TRIES attempts


hasBufferToImage

private boolean hasBufferToImage()
The BufferToImage object is initialized here, so that when grabImage() is called later, the snap can be quickly changed to an image. The object is initialized by taking a snap, which may be an actual picture or be 'empty'. An 'empty' snap is a Buffer object with no video information, as detected by examining its component VideoFormat data. An 'empty' snap is caused by the delay in the player, which although in its started state may still take several seconds to start capturing. The dimensions of the snap are used to calculate the scale factor from the original image size to size*size.

Returns:
state

grabImage

public java.awt.image.BufferedImage grabImage()
Capture an image/frame. The frame is converted from Buffer object to Image, and finally to BufferedImage.

Returns:
a BufferedImage object contains the frame

makeBIM

private java.awt.image.BufferedImage makeBIM(java.awt.Image im)
Make a BufferedImage copy of im, assuming no alpha channel. Resize it to fit into size dimensions.

Parameters:
im - Image object
Returns:
a BufferedImage object

close

public void close()
close() and grabImage() are synchronized so that it's not possible to close down the player while a frame is being snapped.


isClosed

public boolean isClosed()
is closed the device?

Returns:
true if device is closed

controllerUpdate

public void controllerUpdate(javax.media.ControllerEvent evt)
respond to events

Specified by:
controllerUpdate in interface javax.media.ControllerListener
See Also:
ControllerListener.controllerUpdate(javax.media.ControllerEvent)