FileDocCategorySizeDatePackage
FramePositioningAdapter.javaAPI DocJMF 2.1.1e4612Mon May 12 12:20:56 BST 2003com.sun.media.controls

FramePositioningAdapter

public class FramePositioningAdapter extends Object implements Reparentable, FramePositioningControl
The FramePositioningControl is the interface to control precise positioning to a video frame for Players and Processors.

Fields Summary
Object
owner
Player
player
Track
master
long
frameStep
Constructors Summary
public FramePositioningAdapter(Player p, Track track)



         
	this.player = p;
	this.master = track;

	// Base on the frame rate, compute the inter-frame duration.
	// This is not very accurate since the frame rate reported is not
	// very accurate anyway.
	Format f = track.getFormat();
	if (f instanceof VideoFormat) {
	    float rate = ((VideoFormat)f).getFrameRate();
	    if (rate != Format.NOT_SPECIFIED && rate != 0f)
		frameStep = (long)(Time.ONE_SECOND / rate);
	}
    
Methods Summary
public java.awt.ComponentgetControlComponent()

	return null;
    
public static javax.media.TrackgetMasterTrack(javax.media.Track[] tracks)

	Track master = null;
	Format f;
	float rate = Format.NOT_SPECIFIED;

	for (int i = 0; i < tracks.length; i++) {

	    if (tracks[i] == null || ((f = tracks[i].getFormat()) == null))
		continue;

	    if (!(f instanceof VideoFormat))
		continue;

	    master = tracks[i];

	    if ((rate = ((VideoFormat)f).getFrameRate()) != Format.NOT_SPECIFIED &&
		rate != 0f) {

		return master;
	    }
	}

	if (master != null &&
	    master.mapTimeToFrame(new Time(0)) != FramePositioningControl.FRAME_UNKNOWN)
	    return master;
	else
	    return null;
    
public java.lang.ObjectgetOwner()

	if (owner == null)
	    return this;
	else
	    return owner;
    
public javax.media.TimemapFrameToTime(int frameNumber)
Converts the given frame number to the corresponding media time.

param
frameNumber the input frame number for the conversion.
return
the converted media time for the given frame. If the conversion fails, TIME_UNKNOWN is returned.

	return master.mapFrameToTime(frameNumber);
    
public intmapTimeToFrame(javax.media.Time mediaTime)
Converts the given media time to the corresponding frame number.

The frame returned is the nearest frame that has a media time less than or equal to the given media time.

param
mediaTime the input media time for the conversion.
return
the converted frame number the given media time. If the conversion fails, FRAME_UNKNOWN is returned.

	return master.mapTimeToFrame(mediaTime);
    
public intseek(int frameNumber)
Seek to a given video frame.

param
frameNumber the frame to seek to.
return
the actual frame that the Player has seeked to.

	Time seekTo = master.mapFrameToTime(frameNumber);
	if (seekTo != null && seekTo != FramePositioningControl.TIME_UNKNOWN) {
	    player.setMediaTime(seekTo);
	    return master.mapTimeToFrame(seekTo);
	} else {
	    // Can't do any thing if mapFrameToTime fails.
	    return FramePositioningControl.FRAME_UNKNOWN;
	}
    
public voidsetOwner(java.lang.Object newOwner)

	owner = newOwner;
    
public intskip(int framesToSkip)
Skip a given number of frames from the current position.

param
framesToSkip the number of frames to skip from the current position. If framesToSkip is positive, it will seek forward by framesToSkip number of frames. If framesToSkip is negative, it will seek backward by framesToSkip number of frames. e.g. skip(-1) will step backward one frame.
return
the actual number of frames skipped.

	if (frameStep != -1) {
	    // Use interframe duration.
	    long t = player.getMediaNanoseconds() + (framesToSkip * frameStep);
	    player.setMediaTime(new Time(t));
	    return framesToSkip;

	} else {
	    int currentFrame = master.mapTimeToFrame(player.getMediaTime());
	    if (currentFrame != 0 &&
		currentFrame != FramePositioningControl.FRAME_UNKNOWN) {
		int newFrame = seek(currentFrame+framesToSkip);
		return newFrame - currentFrame;
	    } else {
		// Ran out of options.
		return FramePositioningControl.FRAME_UNKNOWN;
	    }
	}