Holger's
Java API

com.antelmann.image
Class MJPEGHandler

java.lang.Object
  extended by com.antelmann.image.MJPEGHandler
All Implemented Interfaces:
Handler<byte[],IOException>, ValueRetriever<BufferedImage>

public class MJPEGHandler
extends Object
implements ValueRetriever<BufferedImage>, Handler<byte[],IOException>

a convenient implementation that provides images from the stream that are created asynchronously

See Also:
MJPEGReader

Field Summary
protected  ThreadWorker worker
           
 
Constructor Summary
MJPEGHandler()
           
MJPEGHandler(int cacheSize)
           
MJPEGHandler(int cacheSize, int idleTimeInMillis)
           
 
Method Summary
 boolean addAlertTask(Task<?> alertTask)
          note that the alert task is performed before this handler enters the alert status; so if this instance is in alert status when the task is performed; it was from the previous alert.
 boolean addImageHandler(Handler<BufferedImage,?> imageHandler)
          allows to add a handler that is called each time a new image is set
protected  double calculateMotion(BufferedImage image1, BufferedImage image2)
           
 BufferedImage createImage(byte[] bytes)
          responsible for extracting an image from the given bytes This method is internally called in a thread spawned by handle(Object, byte[]).
protected  void finalize()
           
 long getAlertPeriod()
           
 byte[][] getCachedImages()
           
 long getCount()
          returns how many image data frames have been received by the handling method handle(Object, byte[]) (including those that were not successfully be converted into an image)
 BufferedImage getCurrentImage()
           
 double getFramesPerSecond()
           
 long getFramesTimePeriod()
          the time period (milliseconds) that is considered when calculating frames per seconds rate
 int getIdleTime()
           
 long getImageCount()
          returns how many images were actually processed
 Processor<BufferedImage,IOException> getImageProcessor()
           
 long getLastAlert()
           
 Logger getLogger()
           
 MotionDetector getMotionDetector()
           
 BufferedImage getRelevantValue()
          returns the relevant value for this instance at the time of calling
 long getTimestamp()
           
 void handle(Object source, byte[] bytes)
          returns immediately and processes the creation/handling of the image in a new thread
 boolean isEnableMotionLogging()
          if enabled and a MotionDetector is present, the difference is logged for each image change and sent to the logger (with Level.INFO and the difference is given as the first parameter)
 boolean isInAlert()
           
protected  void notifyAlert()
           
protected  void notifyImageHandler(BufferedImage image)
           
 boolean removeAlertTask(Task<?> alertTask)
           
 boolean removeImageHandler(Handler<BufferedImage,?> imageHandler)
           
 void resetCount()
           
 void resetImageCount()
           
 void setAlertPeriod(long alertPeriod)
          sets the minimum time period that passes before an alert is triggered after another
 void setEnableMotionLogging(boolean flag)
           
 void setFramesTimePeriod(long millis)
           
 void setIdleTime(int millis)
          allows to specify the time perid the image handling thread is pausing between images
 void setImageProcessor(Processor<BufferedImage,IOException> imageProcessor)
           
 void setMotionDetector(MotionDetector motionDetector)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

worker

protected final ThreadWorker worker
Constructor Detail

MJPEGHandler

public MJPEGHandler()

MJPEGHandler

public MJPEGHandler(int cacheSize)

MJPEGHandler

public MJPEGHandler(int cacheSize,
                    int idleTimeInMillis)
Method Detail

getLogger

public Logger getLogger()

isEnableMotionLogging

public boolean isEnableMotionLogging()
if enabled and a MotionDetector is present, the difference is logged for each image change and sent to the logger (with Level.INFO and the difference is given as the first parameter)


setEnableMotionLogging

public void setEnableMotionLogging(boolean flag)

addImageHandler

public boolean addImageHandler(Handler<BufferedImage,?> imageHandler)
allows to add a handler that is called each time a new image is set


removeImageHandler

public boolean removeImageHandler(Handler<BufferedImage,?> imageHandler)

getAlertPeriod

public long getAlertPeriod()

getIdleTime

public int getIdleTime()

setIdleTime

public void setIdleTime(int millis)
allows to specify the time perid the image handling thread is pausing between images


setAlertPeriod

public void setAlertPeriod(long alertPeriod)
sets the minimum time period that passes before an alert is triggered after another

Parameters:
alertPeriod - a positive number representing milliseconds

getMotionDetector

public MotionDetector getMotionDetector()

setMotionDetector

public void setMotionDetector(MotionDetector motionDetector)

addAlertTask

public boolean addAlertTask(Task<?> alertTask)
note that the alert task is performed before this handler enters the alert status; so if this instance is in alert status when the task is performed; it was from the previous alert.


removeAlertTask

public boolean removeAlertTask(Task<?> alertTask)

getLastAlert

public long getLastAlert()

isInAlert

public boolean isInAlert()

getCount

public long getCount()
returns how many image data frames have been received by the handling method handle(Object, byte[]) (including those that were not successfully be converted into an image)


resetCount

public void resetCount()

getImageCount

public long getImageCount()
returns how many images were actually processed


resetImageCount

public void resetImageCount()

getFramesTimePeriod

public long getFramesTimePeriod()
the time period (milliseconds) that is considered when calculating frames per seconds rate


setFramesTimePeriod

public void setFramesTimePeriod(long millis)

getFramesPerSecond

public double getFramesPerSecond()

getRelevantValue

public BufferedImage getRelevantValue()
                               throws IOException
Description copied from interface: ValueRetriever
returns the relevant value for this instance at the time of calling

Specified by:
getRelevantValue in interface ValueRetriever<BufferedImage>
Throws:
IOException - if any resource to fulfill the request is not accessible

getCurrentImage

public BufferedImage getCurrentImage()

getTimestamp

public long getTimestamp()

getCachedImages

public byte[][] getCachedImages()

getImageProcessor

public Processor<BufferedImage,IOException> getImageProcessor()

setImageProcessor

public void setImageProcessor(Processor<BufferedImage,IOException> imageProcessor)

createImage

public BufferedImage createImage(byte[] bytes)
                          throws IOException
responsible for extracting an image from the given bytes This method is internally called in a thread spawned by handle(Object, byte[]). If this method returns null, the data is ignored.

Throws:
IOException

calculateMotion

protected double calculateMotion(BufferedImage image1,
                                 BufferedImage image2)

notifyImageHandler

protected void notifyImageHandler(BufferedImage image)

notifyAlert

protected void notifyAlert()

handle

public void handle(Object source,
                   byte[] bytes)
            throws IOException
returns immediately and processes the creation/handling of the image in a new thread

Specified by:
handle in interface Handler<byte[],IOException>
Parameters:
source - the object that initiated this call-back
bytes - the item to be handled by this instance
Throws:
IOException
See Also:
createImage(byte[])

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads