FileDocCategorySizeDatePackage
Buffer.javaAPI DocJMF 2.1.1e18340Mon May 12 12:20:38 BST 2003javax.media

Buffer

public class Buffer extends Object
A Buffer is a media-data container that carries media data from one processing stage to the next inside of a Player or Processor. Buffer objects are also used to carry data between a buffer stream and its handler.

A Buffer object maintains information such as the time stamp, length, and Format of the data it carries, as well as any header information that might be required to process the media data.

see
PlugIn
see
javax.media.protocol.PushBufferStream
see
javax.media.protocol.PullBufferStream
since
JMF 2.0

Fields Summary
protected long
timeStamp
The time stamp of the data held in this Buffer, in nanoseconds. The time stamp marks the time when presentation of this Buffer is to begin. If the start time for this Buffer is not known, this time stamp is set to TIME_UNKNOWN.
protected long
duration
The duration of the data held in this Buffer, in nanoseconds. The duration specifies how long it will take for this Buffer to be presented when the playback rate is 1.0. If the duration for this Buffer is not known, it is set to TIME_UNKNOWN.
protected Format
format
The Format of the chunk of data in this Buffer.
protected int
flags
A flag mask that describes the boolean attributes enabled for this Buffer. This mask is set to the logical sum of all of the flags that are set.
protected Object
data
The object that actually holds the media data chunk for this Buffer. It can be an array type (such as byte[]) or any other type of object. Use instanceOf to determine what type it is.
protected Object
header
Header information (such as RTP header) for this data chunk. It can be of any type. Use instanceOf to determine what type it is.
protected int
length
For array data type, states how many samples are valid in the array. (The array might be larger than the actual media length).
protected int
offset
For array data type, points to the starting point (offset) into the array where the valid data begins.
protected long
sequenceNumber
The sequence number of this Buffer. The sequence number of adjacent Buffer objects in a sequence should differ by 1: positive 1 if the media is playing forward, negative 1 if the media is played in reverse. If the sequence number is not known, SEQUENCE_UNKNOWN is specified.
public static final int
FLAG_EOM
Indicates that this Buffer marks the end of media for the data stream. The Buffer might or might not contain valid data to be processed. The length and data attributes need to be examined to determine whether or not this Buffer contains valid data.
public static final int
FLAG_DISCARD
Indicates that the media data in this Buffer should be ignored.
public static final int
FLAG_SILENCE
Indicates that this Buffer contains only silence frames.
public static final int
FLAG_SID
Indicates that this Buffer contains only SID (silence information description) frames.
public static final int
FLAG_KEY_FRAME
Indicates that this Buffer starts with a key frame.
public static final int
FLAG_NO_DROP
Indicates that this Buffer will not be dropped even if the frame is behind the presentation schedule.
public static final int
FLAG_NO_WAIT
Indicates that this Buffer will not be waited on even if the frame is ahead of the presentation schedule.
public static final int
FLAG_NO_SYNC
Indicates that this Buffer is not to be presented in sync with the scheduled presentation time. In other words, the Buffer will not be dropped or waited on if it's behind or ahead of schedule.
public static final int
FLAG_SYSTEM_TIME
Indicates that the Buffer carries a time stamp that's relative to the SystemTimeBase. This flag is generally set for data transferred from hardware capture DataSources that uses the system clock.
public static final int
FLAG_RELATIVE_TIME
Indicates that the Buffer carries a time stamp that's in relative time units. This means that individual time stamps are not measured against any indentifiable absolute origin--only the difference between the time stamps of two consecutive buffers carries useful information. (This is the time difference between the two packets.)
public static final int
FLAG_FLUSH
This is a marker bit used by the system. When this flag is set, it marks a zero-length Buffer generated by the system to flush the data path. Do not attempt to use or overwrite this flag.
public static final int
FLAG_SYSTEM_MARKER
This is a marker bit used by the system. Do not attempt to use or overwrite this flag.
public static final int
FLAG_RTP_MARKER
This is a marker bit for RTP. Indicates that the Buffer is the last packet of a video frame.
public static final int
FLAG_RTP_TIME
Indicates that the Buffer carries a time stamp that's in RTP (NTP) time units.
public static final int
FLAG_BUF_OVERFLOWN
Indicates that some buffer queue in the data flow path from where this buffer comes from is overflown. When such condition occurs, the processing element should attempt to speed up the procesing of this buffer object to reduce the overflow.
public static final int
FLAG_BUF_UNDERFLOWN
Indicates that some buffer queue in the data flow path from where this buffer comes from is underflown. When such condition occurs, the processing element should attempt to speed up the procesing of this buffer object to reduce the underflow.
public static final int
FLAG_LIVE_DATA
Indicates that the data is arriving from a live (real-time) source.
public static final long
TIME_UNKNOWN
The getTimeStamp method return this value if the time stamp of the media is not known.
public static final long
SEQUENCE_UNKNOWN
The getSequenceNumber method returns this value if the sequence number is not known.
Constructors Summary
Methods Summary
public java.lang.Objectclone()
Clone a buffer.

	Buffer buf = new Buffer();
	Object data = getData();
	
	if (data != null) {
	    if (data instanceof byte[])
		buf.data = ((byte[])data).clone();
	    else if (data instanceof int[])
		buf.data = ((int[])data).clone();
	    else if (data instanceof short[])
		buf.data = ((short[])data).clone();
	    else
		buf.data = data;
	}
	if (header != null) {
	    if (header instanceof byte[])
		buf.header = ((byte[])header).clone();
	    else if (header instanceof int[])
		buf.header = ((int[])header).clone();
	    else if (header instanceof short[])
		buf.header = ((short[])header).clone();
	    else
		buf.header = header;
	}
	buf.format = format;
	buf.length = length;
	buf.offset = offset;
	buf.timeStamp = timeStamp;
	buf.duration = duration;
	buf.sequenceNumber = sequenceNumber;
	buf.flags = flags;

	return buf;
    
public voidcopy(javax.media.Buffer buffer)
Copy the attributes from the specified Buffer into this Buffer

param
buffer The input Buffer the copy the attributes from.

	copy(buffer, false);
    
public voidcopy(javax.media.Buffer buffer, boolean swapData)
Copy the attributes from the specified Buffer into this Buffer. If swapData is true, the data values are swapped between the buffers, otherwise the data value is copied.

param
buffer The input Buffer the copy the attributes from.
param
swapData Specifies whether the data objects are to be swapped.

	if (swapData) {
	    Object temp = data;
	    data = buffer.data;
	    buffer.data = temp;
	} else {
	    data = buffer.data;
	}
	header = buffer.header;
	format = buffer.format;
	length = buffer.length;
	offset = buffer.offset;
	timeStamp = buffer.timeStamp;
	duration = buffer.duration;
	sequenceNumber = buffer.sequenceNumber;
	flags = buffer.flags;
    
public java.lang.ObjectgetData()
Gets the internal data object that holds the media chunk contained in this Buffer.

return
The data object that holds the media chunk for this Buffer. It can be an array type (such as byte[]) or any other type of object. Use instanceOf to determine what type it is.
see
#data

        return data;
    
public longgetDuration()
Gets the duration of this Buffer.

return
The Buffer duration, in nanoseconds.
see
#duration

        return duration;
    
public intgetFlags()
Gets the mask of the flags set for this Buffer. The integer value of the mask is equal to the logical sum of the flags that are set.

see
#FLAG_EOM
see
#FLAG_DISCARD
see
#FLAG_SILENCE
see
#FLAG_SID
see
#FLAG_KEY_FRAME
see
#FLAG_NO_DROP
see
#FLAG_NO_WAIT
see
#FLAG_NO_SYNC
see
#FLAG_RELATIVE_TIME
see
#FLAG_FLUSH
see
#FLAG_SYSTEM_MARKER
see
#FLAG_RTP_MARKER

	return flags;
    
public javax.media.FormatgetFormat()
Get the Format of the data in this Buffer.


                  
       
        return format;
    
public java.lang.ObjectgetHeader()
Gets the header information for the media chunk contained in this Buffer.

return
The object that holds the header information. Use instanceOf to determine what type the header object is.
see
#header

        return header;
    
public intgetLength()
Gets the length of the valid data in this Buffer if the data is held in an array.

return
The length of the valid data in the data array that holds the media chunk for this Buffer.
see
#length

        return length;
    
public intgetOffset()
If the media chunk for this Buffer is held in an array, gets the offset into the data array where the valid data begins.

	return offset;
    
public longgetSequenceNumber()
Gets the sequence number of this Buffer.

return
The sequence number of this Buffer.
see
#sequenceNumber

	return sequenceNumber;
    
public longgetTimeStamp()
Gets the time stamp of this Buffer.

return
The Buffer time stamp, in nanoseconds.
see
#timeStamp

        return timeStamp;
    
public booleanisDiscard()
Checks whether or not this Buffer is to be discarded.

This method provides a convenient alternative to using getFlags to check the DISCARD flag.

return
true if the DISCARD flag is enabled, false if it is not.
see
#getFlags
see
#FLAG_DISCARD

	return (flags & FLAG_DISCARD) != 0;
    
public booleanisEOM()
Checks whether or not this Buffer marks the end of the media stream. Even it isEOM returns true, the Buffer might still contain valid data--check the length of the Buffer.

This method provides a convenient alternative to using getFlags to check the EOM flag.

return
true if the EOM flag is enabled, false if it is not.
see
#getFlags
see
#FLAG_EOM

	return (flags & FLAG_EOM) != 0;
    
public voidsetData(java.lang.Object data)
Sets the internal data object that holds the media chunk.

param
data The data object that holds the media data chunk for this Buffer. It can be an array type (such as byte[]) or any other type of object.
see
#data

        this.data = data;
    
public voidsetDiscard(boolean discard)
Sets the DISCARD flag for this Buffer. If the DISCARD flag is enabled, this Buffer is to be discarded.

This method provides a convenient alternative to using setFlags to enable or disable the DISCARD flag.

param
discard A boolean value that contains the DISCARD status of the Buffer. Set to true to enable the EOM flag, false to disable the flag.
see
#setFlags
see
#FLAG_DISCARD

	if (discard)
	    flags |= FLAG_DISCARD;
	else
	    flags &= ~FLAG_DISCARD;
    
public voidsetDuration(long duration)
Sets the duration of this Buffer.

param
duration The duration for the Buffer, in nanoseconds.
see
#duration

        this.duration = duration;
    
public voidsetEOM(boolean eom)
Sets the EOM flag for this Buffer. If the EOM flag is enabled, this is the last Buffer in the media stream.

This method provides a convenient alternative to using setFlags to enable or disable the EOM flag.

param
eom A boolean value that contains the EOM status of the Buffer. Set to true to enable the EOM flag, false to disable the flag.
see
#setFlags
see
#FLAG_EOM

	if (eom)
	    flags |= FLAG_EOM;
	else
	    flags &= ~FLAG_EOM;
    
public voidsetFlags(int flags)
Sets the flag mask for this Buffer. The integer value of the mask is equal to the logical sum of the flags that are set.

see
#FLAG_EOM
see
#FLAG_DISCARD
see
#FLAG_SILENCE
see
#FLAG_SID
see
#FLAG_KEY_FRAME
see
#FLAG_NO_DROP
see
#FLAG_NO_WAIT
see
#FLAG_NO_SYNC
see
#FLAG_RELATIVE_TIME
see
#FLAG_FLUSH
see
#FLAG_SYSTEM_MARKER
see
#FLAG_RTP_MARKER

	this.flags = flags;
    
public voidsetFormat(javax.media.Format format)
Sets the Format of the data in this Buffer.

param
format The Format of the data.

        this.format=format;
    
public voidsetHeader(java.lang.Object header)
Sets the header information for the media chunk.

param
header The header object that holds the media data chunk for this Buffer.
see
#header

        this.header = header;
    
public voidsetLength(int length)
Sets the length of the valid data stored in this Buffer if the data is held in an array.

param
length The length of the valid data in the data array that holds the media chunk for this Buffer.
see
#length

        this.length=length;
    
public voidsetOffset(int offset)
If the media chunk for this Buffer is held in an array, sets the offset into the array where the valid data begins.

param
offset The starting point for the valid data.
see
#offset

	this.offset = offset;
    
public voidsetSequenceNumber(long number)
Sets the sequence number of this Buffer. Sequence numbers increase or decrease by 1 for each sequential Buffer, indicating the order in which the data is to be processed. Can be used to identify lost samples of data.

param
number The sequence number for the Buffer.
see
#sequenceNumber

	sequenceNumber = number;
    
public voidsetTimeStamp(long timeStamp)
Sets the time stamp of this Buffer.

param
timeStamp The time stamp for the Buffer, in nanoseconds.
see
#timeStamp

        this.timeStamp = timeStamp;