FileDocCategorySizeDatePackage
G729AParser.javaAPI DocJMF 2.1.1e5942Mon May 12 12:20:52 BST 2003com.sun.media.parser.audio

G729AParser

public class G729AParser extends BasicPullParser

Fields Summary
private static final int
CODEFRAMESIZE
private static final int
DATAFRAMESIZE
private static final int
FRAMERATE
private Time
duration
private Format
format
private Track[]
tracks
private int
numBuffers
private int
bufferSize
private int
dataSize
private SettableTime
mediaTime
private int
encoding
private String
encodingString
private int
sampleRate
private int
samplesPerBlock
private int
bytesPerSecond
private int
blockSize
private long
minLocation
private long
maxLocation
private PullSourceStream
stream
private static ContentDescriptor[]
supportedFormat
Constructors Summary
Methods Summary
public javax.media.TimegetDuration()

	if ( duration.equals(Duration.DURATION_UNKNOWN) &&
	     ( tracks[0] != null ) ) {
	    long mediaSizeAtEOM = ((BasicTrack) tracks[0]).getMediaSizeAtEOM();
	    if (mediaSizeAtEOM > 0) {
		double durationSeconds = mediaSizeAtEOM / bytesPerSecond;
		duration = new Time(durationSeconds);
	    }
	}
	return duration;
    
public javax.media.TimegetMediaTime()

	return null;
    
public java.lang.StringgetName()
Returns a descriptive name for the plug-in. This is a user readable string.

	return "G.729A Parser";
    
public javax.media.protocol.ContentDescriptor[]getSupportedInputContentDescriptors()


        
	return supportedFormat;
    
public javax.media.Track[]getTracks()


	if (tracks[0] != null)
	    return tracks;
	
	stream = (PullSourceStream) streams[0];
	// Since the readHeader doesn't read anything there
	// is no need to disable buffering
	readHeader();

	// get data a frame at a time
	bufferSize = CODEFRAMESIZE;
	tracks[0] = new G729ATrack((AudioFormat) format,
				/*enabled=*/ true,
				new Time(0),
				numBuffers,
				bufferSize,
				minLocation,
				maxLocation
				);
	return tracks;
    
private voidreadHeader()


	minLocation = getLocation(stream); // Should be zero

	long contentLength = stream.getContentLength();
	if ( contentLength != SourceStream.LENGTH_UNKNOWN ) {
	    double durationSeconds = contentLength / bytesPerSecond;
	    duration = new Time(durationSeconds);
	    maxLocation = contentLength;
	} else {
	    maxLocation = Long.MAX_VALUE;
	}

	format = new AudioFormat(AudioFormat.G729A,
				 8000,
				 16,
				 1,
				 AudioFormat.BIG_ENDIAN,
				 AudioFormat.SIGNED,
				 (CODEFRAMESIZE * 8),
				 FRAMERATE,
				 Format.byteArray);
    
public javax.media.TimesetPosition(javax.media.Time where, int rounding)

	if (! seekable ) {
	    return getMediaTime();
	}

	long time = where.getNanoseconds();
	long newPos;

	if (time < 0)
	    time = 0;

	double newPosd = time * bytesPerSecond / 1000000000.0;
	double remainder = (newPosd % blockSize);
	
	newPos = (long) (newPosd - remainder);

	if (remainder > 0) {
	    switch (rounding) {
	    case Positionable.RoundUp:
		newPos += blockSize;
		break;
	    case Positionable.RoundNearest:
		if (remainder > (blockSize / 2.0))
		    newPos += blockSize;
		break;
	    }
	}

// 	if ( newPos > maxLocation )
// 	    newPos = maxLocation;
	
	newPos += minLocation;
	((BasicTrack) tracks[0]).setSeekLocation(newPos);
	if (cacheStream != null) {
	    synchronized(this) {
		// cacheStream.setPosition(where.getNanoseconds());
		cacheStream.abortRead();
	    }
	}
	return where; // TODO: return the actual time value