dLife Home Page

dlife.vision.server
Class VideoFrame

java.lang.Object
  extended by dlife.vision.server.VideoFrame

public class VideoFrame
extends Object

A VideoFrame constructs is useful in two different ways. The first use is to construct a series of DatagramPacket objects for a image frame stored within a ByteBuffer. The image is broken up into DatagramPackets of size 65535 (the max size which can be sent via UDP). The first 10 bytes of each DatagramPacket will contain header information useful for reconstructing the frame. The first 8 bytes are a long which is the frame number. The next two bytes are the sequence number followed by the total number of DatagramPackets for the VideoFrame. A VideoFrame can also be constructed using these broken up DatagramPackets to create a buffered image. The frame number is assigned when the new VideoFrame is created or by using the frame number from the provided DatagramPacket.

Version:
June 25, 2010
Author:
Russell Toris, Dickinson College

Field Summary
static int MAX_PACKET_SIZE
          The maximum packet size that will be sent over UDP.
static int PACKET_HEADER_SIZE
          The size of the header information on each DatagramPacket.
 
Constructor Summary
VideoFrame(ByteBuffer bb)
          Construct a VideoFrame using the image information in the given ByteBuffer.
VideoFrame(DatagramPacket dgp)
          Construct a VideoFrame with the initial DatagramPacket.
 
Method Summary
 void addPacket(DatagramPacket dgp)
          Add a DatagramPacket if we do not already have all the DatagramPackets and if the DatagramPacket belongs to the same frame number as this VideoFrame.
 boolean frameReady()
          Checks if the frame is ready to be constructed.
 DatagramPacket[] getDatagrams(InetAddress address, int port)
          Get an array of DatagramPackets with the information in the provided ByteBuffer.
 BufferedImage getFrame()
          Get the BufferedImage for this video frame if the frame is ready to be constructed.
 long getFrameNumber()
          Get the frame number for this VideoFrame.
static long getFrameNumber(DatagramPacket dgp)
          Get the frame number encoded in the header of a DatagramPacket created by the VideoFrame class.
static byte getSequenceNumber(DatagramPacket dgp)
          Get the sequence number encoded in the header of a DatagramPacket created by the VideoFrame class.
static byte getTotalPackets(DatagramPacket dgp)
          Get the total number of packets encoded in the header of a DatagramPacket created by the VideoFrame class.
static void resetFrameCount()
          Reset the frame count to 0.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PACKET_SIZE

public static final int MAX_PACKET_SIZE
The maximum packet size that will be sent over UDP.

See Also:
Constant Field Values

PACKET_HEADER_SIZE

public static final int PACKET_HEADER_SIZE
The size of the header information on each DatagramPacket.

See Also:
Constant Field Values
Constructor Detail

VideoFrame

public VideoFrame(ByteBuffer bb)
Construct a VideoFrame using the image information in the given ByteBuffer. The frame number is the next sequential number starting from zero.

Parameters:
bb - the ByteBuffer which contains the image data

VideoFrame

public VideoFrame(DatagramPacket dgp)
Construct a VideoFrame with the initial DatagramPacket. Additional DatagramPackets which belong to this frame can be added using the addPacket method.

Parameters:
dgp - the initial DatagramPacket
Method Detail

getFrameNumber

public long getFrameNumber()
Get the frame number for this VideoFrame.

Returns:
the frame number

getDatagrams

public DatagramPacket[] getDatagrams(InetAddress address,
                                     int port)
Get an array of DatagramPackets with the information in the provided ByteBuffer. The image is broken up into DatagramPackets of size MAX_PACKET_SIZE (the max size which can be sent via UDP). The first 10 bytes of each DatagramPacket will contain header information useful for reconstructing the frame. The first 8 bytes are a long which is the frame number. The next two bytes are the sequence number followed by the total number of DatagramPackets for the VideoFrame.

Parameters:
address - the address the DatagramPackets will be sent to
port - the port the DatagramPackets will be sent to
Returns:
a list of broken up DatagramPackets

addPacket

public void addPacket(DatagramPacket dgp)
Add a DatagramPacket if we do not already have all the DatagramPackets and if the DatagramPacket belongs to the same frame number as this VideoFrame.

Parameters:
dgp - the packet to add to this VideoFrame
Throws:
InvalidParameterException - thrown if the DatagramPacket belongs to a different frame or if we already have a DatagramPacket with that sequence number

frameReady

public boolean frameReady()
Checks if the frame is ready to be constructed. This will become true once all the DatagramPackets have been added to the VideoFrame.

Returns:
if the frame is ready to be constructed

getFrame

public BufferedImage getFrame()
                       throws IOException
Get the BufferedImage for this video frame if the frame is ready to be constructed. This will return null if the frame is not ready.

Returns:
a BufferedImage for this VideoFrame or null if the frame is not ready
Throws:
IOException - thrown if there is a problem reading the image data from the DatagramPackets

resetFrameCount

public static void resetFrameCount()
Reset the frame count to 0. The next VideoFrame object created will have its frame number set to 0 and increment there after.


getTotalPackets

public static byte getTotalPackets(DatagramPacket dgp)
Get the total number of packets encoded in the header of a DatagramPacket created by the VideoFrame class. This number is encoded in the 10th byte.

Parameters:
dgp - the DatagramPacket to get the total number of packets that create a full VideoFrame object.
Returns:
the total number of packets for this DatagramPacket that create a full VideoFrame object

getSequenceNumber

public static byte getSequenceNumber(DatagramPacket dgp)
Get the sequence number encoded in the header of a DatagramPacket created by the VideoFrame class. This number is encoded in the 9th byte.

Parameters:
dgp - the DatagramPacket to get the sequence number
Returns:
the sequence number for this DatagramPacket

getFrameNumber

public static long getFrameNumber(DatagramPacket dgp)
Get the frame number encoded in the header of a DatagramPacket created by the VideoFrame class. This number is encoded in the first 8 bytes.

Parameters:
dgp - the DatagramPacket to get the frame number
Returns:
the frame number for this DatagramPacket

dLife Home Page