FileDocCategorySizeDatePackage
ElapseTime.javaAPI DocJMF 2.1.1e1765Mon May 12 12:20:46 BST 2003com.sun.media.util

ElapseTime

public class ElapseTime extends Object
A utility class to keep track of the passage of time as data buffers are being processed.

Fields Summary
public long
value
Constructors Summary
Methods Summary
public static longaudioLenToTime(long len, javax.media.format.AudioFormat af)
Convert audio: length (bytes) to duration (nanoseconds).

	return af.computeDuration(len);
    
public static longaudioTimeToLen(long duration, javax.media.format.AudioFormat af)
Convert audio: duration (nanoseconds) to length (bytes).


	long units, bytesPerSec;

	if (af.getSampleSizeInBits() > 0) {
	    units = (long)(af.getSampleSizeInBits() * af.getChannels());
	    bytesPerSec = (long)((units * af.getSampleRate()) / 8);
	} else if (af.getFrameSizeInBits() != Format.NOT_SPECIFIED &&
		   af.getFrameRate() != Format.NOT_SPECIFIED) {
	    units = af.getFrameSizeInBits();
	    bytesPerSec = (long)((units * af.getFrameRate()) / 8);
	} else {
	    units = bytesPerSec = 0;
	}

	// The length returned needs to be in multiples of audio sample 
	// chunk unit.
	return (bytesPerSec == 0 ? 0 : 
		(long)((duration * bytesPerSec) / 1000000000) / units * units);
    
public longgetValue()

	return value;
    
public voidsetValue(long t)


        
	value = t;
    
public booleanupdate(int len, long ts, javax.media.Format f)

	if (f instanceof AudioFormat) {
	    long t;
	    if ((t = ((AudioFormat)f).computeDuration(len)) > 0)
	    	value += t;
	    else if (ts > 0)
		value = ts;
	    else
		return false;
	} else if (ts > 0)
	    value = ts;
	else
	    return false;

	return true;