/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* AbstractDataLine
*
* @author Kara Kytle
*/
// DEFAULTS
// default format
// default buffer size in bytes
private final int defaultBufferSize;
// the lock for synchronization
// STATE
// current format
// current buffer size in bytes
protected int bufferSize;
protected boolean running = false;
private boolean started = false;
private boolean active = false;
/**
* Constructs a new AbstractLine.
*/
}
/**
* Constructs a new AbstractLine.
*/
protected AbstractDataLine(DataLine.Info info, AbstractMixer mixer, Control[] controls, AudioFormat format, int bufferSize) {
// record the default values
} else {
// default CD-quality
}
if (bufferSize > 0) {
} else {
// 0.5 seconds buffer
}
// set the initial values to the defaults
this.format = defaultFormat;
this.bufferSize = defaultBufferSize;
}
// DATA LINE METHODS
//$$fb 2001-10-09: Bug #4517739: avoiding deadlock by synchronizing to mixer !
synchronized (mixer) {
if (Printer.trace) Printer.trace("> AbstractDataLine.open(format, bufferSize) (class: "+getClass().getName());
// if the line is not currently open, try to open it with this format and buffer size
if (!isOpen()) {
// make sure that the format is specified correctly
// $$fb part of fix for 4679187: Clip.open() throws unexpected Exceptions
// reserve mixer resources for this line
//mixer.open(this, format, bufferSize);
try {
// open the data line. may throw LineUnavailableException.
// if we succeeded, set the open state to true and send events
setOpen(true);
} catch (LineUnavailableException e) {
// release mixer resources for this line and then throw the exception
throw e;
}
} else {
// if the line is already open and the requested format differs from the
// current settings, throw an IllegalStateException
//$$fb 2002-04-02: fix for 4661602: Buffersize is checked when re-opening line
" and bufferSize " + getBufferSize());
}
//$$fb 2002-07-26: allow changing the buffersize of already open lines
if (bufferSize > 0) {
}
}
}
}
}
/**
* This implementation always returns 0.
*/
public int available() {
return 0;
}
/**
* This implementation does nothing.
*/
public void drain() {
}
/**
* This implementation does nothing.
*/
public void flush() {
}
public final void start() {
//$$fb 2001-10-09: Bug #4517739: avoiding deadlock by synchronizing to mixer !
synchronized(mixer) {
// $$kk: 06.06.99: if not open, this doesn't work....???
if (isOpen()) {
if (!isStartedRunning()) {
implStart();
running = true;
}
}
}
synchronized(lock) {
}
}
public final void stop() {
//$$fb 2001-10-09: Bug #4517739: avoiding deadlock by synchronizing to mixer !
synchronized(mixer) {
// $$kk: 06.06.99: if not open, this doesn't work.
if (isOpen()) {
if (isStartedRunning()) {
implStop();
running = false;
// $$kk: 11.10.99: this is not exactly correct, but will probably work
setStarted(false);
}
}
}
}
synchronized(lock) {
}
}
// $$jb: 12.10.99: The official API for this is isRunning().
// Per the denied RFE 4297981,
// the change to isStarted() is technically an unapproved API change.
// The 'started' variable is false when playback of data stops.
// It is changed throughout the implementation with setStarted().
// This state is what should be returned by isRunning() in the API.
// Note that the 'running' variable is true between calls to
// start() and stop(). This state is accessed now through the
// isStartedRunning() method, defined below. I have not changed
// the variable names at this point, since 'running' is accessed
// in MixerSourceLine and MixerClip, and I want to touch as little
// code as possible to change isStarted() back to isRunning().
public final boolean isRunning() {
return started;
}
public final boolean isActive() {
return active;
}
public final long getMicrosecondPosition() {
long microseconds = getLongFramePosition();
}
return microseconds;
}
return format;
}
public final int getBufferSize() {
return bufferSize;
}
/**
* This implementation does NOT change the buffer size
*/
return getBufferSize();
}
/**
* This implementation returns AudioSystem.NOT_SPECIFIED.
*/
public final float getLevel() {
return (float)AudioSystem.NOT_SPECIFIED;
}
// HELPER METHODS
/**
* running is true after start is called and before stop is called,
* regardless of whether data is actually being presented.
*/
// $$jb: 12.10.99: calling this method isRunning() conflicts with
// the official API that was once called isStarted(). Since we
// use this method throughout the implementation, I am renaming
// it to isStartedRunning(). This is part of backing out the
// change denied in RFE 4297981.
final boolean isStartedRunning() {
return running;
}
/**
* This method sets the active state and generates
* events if it changes.
*/
//boolean sendEvents = false;
//long position = getLongFramePosition();
synchronized (this) {
//if (Printer.debug) Printer.debug(" AbstractDataLine: setActive: this.active: " + this.active);
//if (Printer.debug) Printer.debug(" active: " + active);
//sendEvents = true;
}
}
//if (Printer.debug) Printer.debug(" this.active: " + this.active);
//if (Printer.debug) Printer.debug(" sendEvents: " + sendEvents);
// $$kk: 11.19.99: take ACTIVE / INACTIVE / EOM events out;
// putting them in is technically an API change.
// do not generate ACTIVE / INACTIVE events for now
// if (sendEvents) {
//
// if (active) {
// sendEvents(new LineEvent(this, LineEvent.Type.ACTIVE, position));
// } else {
// sendEvents(new LineEvent(this, LineEvent.Type.INACTIVE, position));
// }
//}
}
/**
* This method sets the started state and generates
* events if it changes.
*/
boolean sendEvents = false;
long position = getLongFramePosition();
synchronized (this) {
//if (Printer.debug) Printer.debug(" AbstractDataLine: setStarted: this.started: " + this.started);
//if (Printer.debug) Printer.debug(" started: " + started);
sendEvents = true;
}
}
//if (Printer.debug) Printer.debug(" this.started: " + this.started);
//if (Printer.debug) Printer.debug(" sendEvents: " + sendEvents);
if (sendEvents) {
if (started) {
} else {
}
}
}
/**
* This method generates a STOP event and sets the started state to false.
* It is here for historic reasons when an EOM event existed.
*/
final void setEOM() {
//$$fb 2002-04-21: sometimes, 2 STOP events are generated.
// better use setStarted() to send STOP event.
setStarted(false);
}
// OVERRIDES OF ABSTRACT LINE METHODS
/**
* Try to open the line with the current format and buffer size values.
* If the line is not open, these will be the defaults. If the
* line is open, this should return quietly because the values
* requested will match the current ones.
*/
// this may throw a LineUnavailableException.
}
/**
* This should also stop the line. The closed line should not be running or active.
* After we close the line, we reset the format and buffer size to the defaults.
*/
public final void close() {
//$$fb 2001-10-09: Bug #4517739: avoiding deadlock by synchronizing to mixer !
synchronized (mixer) {
if (isOpen()) {
// stop
stop();
// set the open state to false and send events
setOpen(false);
// close resources for this line
implClose();
// release mixer resources for this line
// reset format and buffer size to the defaults
}
}
}
// IMPLEMENTATIONS OF ABSTRACT LINE ABSTRACE METHODS
// ABSTRACT METHODS
abstract void implClose();
abstract void implStart();
abstract void implStop();
}