it.lilik.capturemjpeg
Class CaptureMJPEG

java.lang.Object
  extended by java.lang.Thread
      extended by it.lilik.capturemjpeg.CaptureMJPEG
All Implemented Interfaces:
Runnable

public class CaptureMJPEG
extends Thread

This class produces JPEG images from Motion JPEG stream.
It searches for a callback function called void captureMJPEGEvent(PImage img) into the parent PApplet

Example

import it.lilik.capturemjpeg.*;

private CaptureMJPEG capture;
private PImage next_img = null;

void setup() {
  size(400, 300);
  background(0);
  capture = new CaptureMJPEG(this,
                        "http://mynetworkcamera/image?speed=20",
                        "admin",
                        "password");
  capture.startCapture();
  frameRate(20);
}

void draw() {
  if (next_img != null) {
    image(next_img, 0, 0);
  }
}

void captureMJPEGEvent(PImage img) {
  next_img = img;
}

Author:
Alessio Caiazza, Cosimo Cecchi

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CaptureMJPEG(PApplet parent, String url)
          Creates a CaptureMJPEG without HTTP Auth credential
CaptureMJPEG(PApplet parent, String url, String username, String password)
          Creates a CaptureMJPEG with HTTP Auth credential
 
Method Summary
 void dispose()
          Callback method.
 PImage getImage()
          Provides the oldest image not yet provided.
 boolean isAdaptFrameSize()
          Sets the adaptive frame size behavior.
 boolean isImageAvailable()
          Return true if there is at least one image available into the internal buffer.
 boolean isStopping()
          Checks if the running thread is in stopping state.
 void run()
           
 void setAdaptFrameSize(boolean adaptFrameSize)
          If true when a stream is initialized the parent size is set to the image size.
 void setCredential(String username, String password)
          Sets username and password for HTTP Auth.
 void setURL(String url)
          Changes the URI.
 void startCapture()
          Starts the capture cycle.
 void stopCapture()
          Stops this thread when the current image if finished
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CaptureMJPEG

public CaptureMJPEG(PApplet parent,
                    String url)
Creates a CaptureMJPEG without HTTP Auth credential


CaptureMJPEG

public CaptureMJPEG(PApplet parent,
                    String url,
                    String username,
                    String password)
Creates a CaptureMJPEG with HTTP Auth credential

Parameters:
parent - the PApplet which uses this object
url - the MJPEG stream URI
username - HTTP AUTH username
password - HTTP AUTH password
Method Detail

isStopping

public boolean isStopping()
Checks if the running thread is in stopping state. If true the thread is stopped or it will stop after the next image was captured.

Returns:
the internal status

startCapture

public void startCapture()
Starts the capture cycle.


stopCapture

public void stopCapture()
Stops this thread when the current image if finished


setURL

public void setURL(String url)
Changes the URI.
A new connection will be performed after a complete image reading.

Parameters:
url - the url of the MJPEG stream

setCredential

public void setCredential(String username,
                          String password)
Sets username and password for HTTP Auth.

Parameters:
username - the username
password - the password

isAdaptFrameSize

public boolean isAdaptFrameSize()
Sets the adaptive frame size behavior.

Returns:
the adaptFrameSize
See Also:
setAdaptFrameSize(boolean)

setAdaptFrameSize

public void setAdaptFrameSize(boolean adaptFrameSize)
If true when a stream is initialized the parent size is set to the image size.

Parameters:
adaptFrameSize - the adaptFrameSize to set

run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread

dispose

public void dispose()
Callback method. It's invoked by processing on stop.


getImage

public PImage getImage()
Provides the oldest image not yet provided. If there's no such image, provides the last provided.

Returns:
a PImage

isImageAvailable

public boolean isImageAvailable()
Return true if there is at least one image available into the internal buffer.

Returns:
the availability status


Copyright © 2008-09 Alessio Caiazza, Cosimo Cecchi All Rights Reserved.