# HG changeset patch # User Denis Lila # Date 1307742138 14400 # Node ID fa76bb3356e5079c12c86bfd5a1904a0863acafe # Parent 134b146280880fe8b91934b1db235454c6e417dc PR1741: Fix whitespace. diff -r 134b14628088 -r fa76bb3356e5 ChangeLog --- a/ChangeLog Mon Feb 22 06:17:58 2016 +0000 +++ b/ChangeLog Fri Jun 10 17:42:18 2011 -0400 @@ -1,3 +1,7 @@ +2011-06-10 Denis Lila + + * pulseaudio/*: Fix whitespace. + 2016-02-21 Andrew John Hughes Bump to icedtea-3.0.0pre09. diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/ContextEvent.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/ContextEvent.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/ContextEvent.java Fri Jun 10 17:42:18 2011 -0400 @@ -47,22 +47,22 @@ class ContextEvent { - /** - * Basically, what is the new state of the context - * - */ - public static enum Type { - UNCONNECTED, CONNECTING, AUTHORIZING, SETTING_NAME, READY, FAILED, TERMINATED - } + /** + * Basically, what is the new state of the context + * + */ + public static enum Type { + UNCONNECTED, CONNECTING, AUTHORIZING, SETTING_NAME, READY, FAILED, TERMINATED + } - private Type type; + private Type type; - public ContextEvent(Type type) { - this.type = type; - } + public ContextEvent(Type type) { + this.type = type; + } - public Type getType() { - return type; - } + public Type getType() { + return type; + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/ContextListener.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/ContextListener.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/ContextListener.java Fri Jun 10 17:42:18 2011 -0400 @@ -45,6 +45,6 @@ interface ContextListener { - void update(ContextEvent e); + void update(ContextEvent e); } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Debug.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Debug.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Debug.java Fri Jun 10 17:42:18 2011 -0400 @@ -49,66 +49,66 @@ class Debug { - enum DebugLevel { - Verbose, Debug, Info, Warning, Error, None - } + enum DebugLevel { + Verbose, Debug, Info, Warning, Error, None + } - private static DebugLevel currentDebugLevel = DebugLevel.None; + private static DebugLevel currentDebugLevel = DebugLevel.None; - static { - // System.out.println("PulseAudio: initializing Debug"); + static { + // System.out.println("PulseAudio: initializing Debug"); - String systemSetting; - try { - systemSetting = System.getProperty("pulseaudio.debugLevel"); - } catch (SecurityException e) { - // sigh, we cant read that property - systemSetting = null; - } + String systemSetting; + try { + systemSetting = System.getProperty("pulseaudio.debugLevel"); + } catch (SecurityException e) { + // sigh, we cant read that property + systemSetting = null; + } - DebugLevel wantedLevel; - try { - wantedLevel = DebugLevel.valueOf(systemSetting); + DebugLevel wantedLevel; + try { + wantedLevel = DebugLevel.valueOf(systemSetting); - } catch (IllegalArgumentException e) { - wantedLevel = DebugLevel.Info; - } catch (NullPointerException e) { - wantedLevel = DebugLevel.None; - } + } catch (IllegalArgumentException e) { + wantedLevel = DebugLevel.Info; + } catch (NullPointerException e) { + wantedLevel = DebugLevel.None; + } - currentDebugLevel = wantedLevel; - println(DebugLevel.Info, "Using debug level: " + currentDebugLevel); - } + currentDebugLevel = wantedLevel; + println(DebugLevel.Info, "Using debug level: " + currentDebugLevel); + } - static void println(String string) { - println(DebugLevel.Info, string); - } + static void println(String string) { + println(DebugLevel.Info, string); + } - static void print(DebugLevel level, String string) { - int result = level.compareTo(currentDebugLevel); - if (result >= 0) { - if (level.compareTo(DebugLevel.Error) >= 0) { - System.err.print(string); - } else { - System.out.print(string); - } - } else { - // do nothing - } - } + static void print(DebugLevel level, String string) { + int result = level.compareTo(currentDebugLevel); + if (result >= 0) { + if (level.compareTo(DebugLevel.Error) >= 0) { + System.err.print(string); + } else { + System.out.print(string); + } + } else { + // do nothing + } + } - static void println(DebugLevel level, String string) { + static void println(DebugLevel level, String string) { - int result = level.compareTo(currentDebugLevel); - if (result >= 0) { - if (level.compareTo(DebugLevel.Error) >= 0) { - System.err.println("DEBUG: pulse-java: " + string); - } else { - System.out.println("DEBUG: pulse-java: " + string); - } - } else { - // do nothing - } - } + int result = level.compareTo(currentDebugLevel); + if (result >= 0) { + if (level.compareTo(DebugLevel.Error) >= 0) { + System.err.println("DEBUG: pulse-java: " + string); + } else { + System.out.println("DEBUG: pulse-java: " + string); + } + } else { + // do nothing + } + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java Fri Jun 10 17:42:18 2011 -0400 @@ -52,231 +52,231 @@ final class EventLoop implements Runnable { - /* - * any methods that can obstruct the behaviour of pa_mainloop should run - * synchronized - */ + /* + * any methods that can obstruct the behaviour of pa_mainloop should run + * synchronized + */ - /* - * the threadLock object is the object used for synchronizing the - * non-thread-safe operations of pulseaudio's c api - */ - final Object threadLock = new Object(); + /* + * the threadLock object is the object used for synchronizing the + * non-thread-safe operations of pulseaudio's c api + */ + final Object threadLock = new Object(); - private static EventLoop instance = null; + private static EventLoop instance = null; - private List contextListeners; - // private List lines; - private String appName; - private String serverString; + private List contextListeners; + // private List lines; + private String appName; + private String serverString; - private int status; - // private boolean eventLoopIsRunning = false; + private int status; + // private boolean eventLoopIsRunning = false; - private List targetPortNameList = new ArrayList(); - private List sourcePortNameList = new ArrayList(); + private List targetPortNameList = new ArrayList(); + private List sourcePortNameList = new ArrayList(); - /* - * JNI stuff - * - * Do not synchronize the individual functions, synchronize - * block/method/lines around the call - */ + /* + * JNI stuff + * + * Do not synchronize the individual functions, synchronize + * block/method/lines around the call + */ - private native void native_setup(String appName, String server); + private native void native_setup(String appName, String server); - private native int native_iterate(int timeout); + private native int native_iterate(int timeout); - private native void native_shutdown(); + private native void native_shutdown(); - private native void native_set_sink_volume(byte[] streamPointer, int volume); + private native void native_set_sink_volume(byte[] streamPointer, int volume); - /* - * These fields hold pointers - */ - private byte[] contextPointer; - private byte[] mainloopPointer; + /* + * These fields hold pointers + */ + private byte[] contextPointer; + private byte[] mainloopPointer; - /* - * - */ + /* + * + */ - static { - SecurityWrapper.loadNativeLibrary(); - } + static { + SecurityWrapper.loadNativeLibrary(); + } - private EventLoop() { - contextListeners = new ArrayList(); - } + private EventLoop() { + contextListeners = new ArrayList(); + } - synchronized static EventLoop getEventLoop() { - if (instance == null) { - instance = new EventLoop(); - } - return instance; - } + synchronized static EventLoop getEventLoop() { + if (instance == null) { + instance = new EventLoop(); + } + return instance; + } - void setAppName(String appName) { - this.appName = appName; - } + void setAppName(String appName) { + this.appName = appName; + } - void setServer(String serverString) { - this.serverString = serverString; - } + void setServer(String serverString) { + this.serverString = serverString; + } - @Override - public void run() { - native_setup(this.appName, this.serverString); + @Override + public void run() { + native_setup(this.appName, this.serverString); - Debug.println(DebugLevel.Info, "Eventloop.run(): eventloop starting"); + Debug.println(DebugLevel.Info, "Eventloop.run(): eventloop starting"); - /* - * Perhaps this loop should be written in C doing a Java to C call on - * every iteration of the loop might be slow - */ - while (true) { - synchronized (threadLock) { - // timeout is in milliseconds - // timout = 0 means dont block - native_iterate(100); + /* + * Perhaps this loop should be written in C doing a Java to C call on + * every iteration of the loop might be slow + */ + while (true) { + synchronized (threadLock) { + // timeout is in milliseconds + // timout = 0 means dont block + native_iterate(100); - if (Thread.interrupted()) { - native_shutdown(); + if (Thread.interrupted()) { + native_shutdown(); - // clean up the listeners - synchronized (contextListeners) { - contextListeners.clear(); - } + // clean up the listeners + synchronized (contextListeners) { + contextListeners.clear(); + } - Debug.println(DebugLevel.Info, - "EventLoop.run(): event loop terminated"); + Debug.println(DebugLevel.Info, + "EventLoop.run(): event loop terminated"); - return; + return; - } - } - } + } + } + } - } + } - void addContextListener(ContextListener contextListener) { - synchronized (contextListeners) { - contextListeners.add(contextListener); - } - } + void addContextListener(ContextListener contextListener) { + synchronized (contextListeners) { + contextListeners.add(contextListener); + } + } - void removeContextListener(ContextListener contextListener) { - synchronized (contextListeners) { - contextListeners.remove(contextListener); - } - } + void removeContextListener(ContextListener contextListener) { + synchronized (contextListeners) { + contextListeners.remove(contextListener); + } + } - int getStatus() { - return this.status; - } + int getStatus() { + return this.status; + } - void update(int status) { - synchronized (threadLock) { - // System.out.println(this.getClass().getName() - // + ".update() called! status = " + status); - this.status = status; - switch (status) { - case 0: - fireEvent(new ContextEvent(Type.UNCONNECTED)); - break; - case 1: - fireEvent(new ContextEvent(Type.CONNECTING)); - break; - case 2: - // no op - break; - case 3: - // no op - break; - case 4: - fireEvent(new ContextEvent(Type.READY)); - break; - case 5: - fireEvent(new ContextEvent(Type.FAILED)); - Debug.println(DebugLevel.Warning, - "EventLoop.update(): Context failed"); - break; - case 6: - fireEvent(new ContextEvent(Type.TERMINATED)); - break; - default: + void update(int status) { + synchronized (threadLock) { + // System.out.println(this.getClass().getName() + // + ".update() called! status = " + status); + this.status = status; + switch (status) { + case 0: + fireEvent(new ContextEvent(Type.UNCONNECTED)); + break; + case 1: + fireEvent(new ContextEvent(Type.CONNECTING)); + break; + case 2: + // no op + break; + case 3: + // no op + break; + case 4: + fireEvent(new ContextEvent(Type.READY)); + break; + case 5: + fireEvent(new ContextEvent(Type.FAILED)); + Debug.println(DebugLevel.Warning, + "EventLoop.update(): Context failed"); + break; + case 6: + fireEvent(new ContextEvent(Type.TERMINATED)); + break; + default: - } - } - } + } + } + } - private void fireEvent(final ContextEvent e) { - // System.out.println(this.getClass().getName() + "firing event: " - // + e.getType().toString()); + private void fireEvent(final ContextEvent e) { + // System.out.println(this.getClass().getName() + "firing event: " + // + e.getType().toString()); - synchronized (contextListeners) { - // System.out.println(contextListeners.size()); - for (ContextListener listener : contextListeners) { - listener.update(e); - } - } + synchronized (contextListeners) { + // System.out.println(contextListeners.size()); + for (ContextListener listener : contextListeners) { + listener.update(e); + } + } - } + } - void setVolume(byte[] streamPointer, int volume) { - synchronized (threadLock) { - native_set_sink_volume(streamPointer, volume); - } - } + void setVolume(byte[] streamPointer, int volume) { + synchronized (threadLock) { + native_set_sink_volume(streamPointer, volume); + } + } - byte[] getContextPointer() { - return contextPointer; - } + byte[] getContextPointer() { + return contextPointer; + } - byte[] getMainLoopPointer() { - return mainloopPointer; - } + byte[] getMainLoopPointer() { + return mainloopPointer; + } - private native byte[] nativeUpdateTargetPortNameList(); + private native byte[] nativeUpdateTargetPortNameList(); - private native byte[] nativeUpdateSourcePortNameList(); + private native byte[] nativeUpdateSourcePortNameList(); - synchronized List updateTargetPortNameList() { - targetPortNameList = new ArrayList(); - Operation op; - synchronized (this.threadLock) { - op = new Operation(nativeUpdateTargetPortNameList()); - } + synchronized List updateTargetPortNameList() { + targetPortNameList = new ArrayList(); + Operation op; + synchronized (this.threadLock) { + op = new Operation(nativeUpdateTargetPortNameList()); + } - op.waitForCompletion(); + op.waitForCompletion(); - assert (op.getState() == Operation.State.Done); + assert (op.getState() == Operation.State.Done); - op.releaseReference(); - return targetPortNameList; - } + op.releaseReference(); + return targetPortNameList; + } - protected synchronized List updateSourcePortNameList() { - sourcePortNameList = new ArrayList(); - Operation op; - synchronized (this.threadLock) { - op = new Operation(nativeUpdateSourcePortNameList()); - } + protected synchronized List updateSourcePortNameList() { + sourcePortNameList = new ArrayList(); + Operation op; + synchronized (this.threadLock) { + op = new Operation(nativeUpdateSourcePortNameList()); + } - op.waitForCompletion(); + op.waitForCompletion(); - assert (op.getState() == Operation.State.Done); + assert (op.getState() == Operation.State.Done); - op.releaseReference(); - return sourcePortNameList; - } + op.releaseReference(); + return sourcePortNameList; + } - public void source_callback(String name) { - sourcePortNameList.add(name); - } + public void source_callback(String name) { + sourcePortNameList.add(name); + } - public void sink_callback(String name) { - targetPortNameList.add(name); - } + public void sink_callback(String name) { + targetPortNameList.add(name); + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Operation.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Operation.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Operation.java Fri Jun 10 17:42:18 2011 -0400 @@ -54,109 +54,109 @@ class Operation { - private byte[] operationPointer; - private EventLoop eventLoop; + private byte[] operationPointer; + private EventLoop eventLoop; - public enum State { - Running, Done, Cancelled, - } + public enum State { + Running, Done, Cancelled, + } - static { - SecurityWrapper.loadNativeLibrary(); - } + static { + SecurityWrapper.loadNativeLibrary(); + } - private native void native_ref(); + private native void native_ref(); - private native void native_unref(); + private native void native_unref(); - private native int native_get_state(); + private native int native_get_state(); - Operation(byte[] operationPointer) { - assert (operationPointer != null); - this.operationPointer = operationPointer; - this.eventLoop = EventLoop.getEventLoop(); - } + Operation(byte[] operationPointer) { + assert (operationPointer != null); + this.operationPointer = operationPointer; + this.eventLoop = EventLoop.getEventLoop(); + } - @Override - protected void finalize() throws Throwable { - // might catch operations which havent been released - assert (operationPointer == null); - super.finalize(); - } + @Override + protected void finalize() throws Throwable { + // might catch operations which havent been released + assert (operationPointer == null); + super.finalize(); + } - /** - * Increase reference count by 1 - */ - void addReference() { - assert (operationPointer != null); - synchronized (eventLoop.threadLock) { - native_ref(); - } - } + /** + * Increase reference count by 1 + */ + void addReference() { + assert (operationPointer != null); + synchronized (eventLoop.threadLock) { + native_ref(); + } + } - /** - * Decrease reference count by 1. If the count reaches 0, object will be freed - */ - void releaseReference() { - assert (operationPointer != null); - synchronized (eventLoop.threadLock) { - native_unref(); - } - operationPointer = null; - } + /** + * Decrease reference count by 1. If the count reaches 0, object will be freed + */ + void releaseReference() { + assert (operationPointer != null); + synchronized (eventLoop.threadLock) { + native_unref(); + } + operationPointer = null; + } - // FIXME broken function - boolean isNull() { - if (operationPointer == null) { - return true; - } - return false; - } + // FIXME broken function + boolean isNull() { + if (operationPointer == null) { + return true; + } + return false; + } - State getState() { - assert (operationPointer != null); - int state; - synchronized (eventLoop.threadLock) { - state = native_get_state(); - } - switch (state) { - case 0: - return State.Running; - case 1: - return State.Done; - case 2: - return State.Cancelled; - default: - throw new IllegalStateException("Invalid operation State"); - } + State getState() { + assert (operationPointer != null); + int state; + synchronized (eventLoop.threadLock) { + state = native_get_state(); + } + switch (state) { + case 0: + return State.Running; + case 1: + return State.Done; + case 2: + return State.Cancelled; + default: + throw new IllegalStateException("Invalid operation State"); + } - } + } - /** - * Block until the operation has completed - * - */ - void waitForCompletion() { - assert (operationPointer != null); + /** + * Block until the operation has completed + * + */ + void waitForCompletion() { + assert (operationPointer != null); - boolean interrupted = false; - do { - synchronized (eventLoop.threadLock) { - if (getState() == Operation.State.Done) { - return; - } - try { - eventLoop.threadLock.wait(); - } catch (InterruptedException e) { - // ingore the interrupt for now - interrupted = true; - } - } - } while (getState() != State.Done); + boolean interrupted = false; + do { + synchronized (eventLoop.threadLock) { + if (getState() == Operation.State.Done) { + return; + } + try { + eventLoop.threadLock.wait(); + } catch (InterruptedException e) { + // ingore the interrupt for now + interrupted = true; + } + } + } while (getState() != State.Done); - // let the caller know about the interrupt - if (interrupted) { - Thread.currentThread().interrupt(); - } - } + // let the caller know about the interrupt + if (interrupted) { + Thread.currentThread().interrupt(); + } + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Fri Jun 10 17:42:18 2011 -0400 @@ -51,524 +51,524 @@ import org.classpath.icedtea.pulseaudio.Stream.WriteListener; public final class PulseAudioClip extends PulseAudioDataLine implements Clip, - PulseAudioPlaybackLine { + PulseAudioPlaybackLine { - private byte[] data = null; + private byte[] data = null; - // these are frame indices. so counted from 0 - // the current frame index - private int currentFrame = 0; + // these are frame indices. so counted from 0 + // the current frame index + private int currentFrame = 0; - // total number of frames in this clip - private int frameCount = 0; + // total number of frames in this clip + private int frameCount = 0; - // the starting frame of the loop - private int startFrame = 0; - // the ending frame of the loop - private int endFrame = 0; + // the starting frame of the loop + private int startFrame = 0; + // the ending frame of the loop + private int endFrame = 0; - public static final String DEFAULT_CLIP_NAME = "Audio Clip"; + public static final String DEFAULT_CLIP_NAME = "Audio Clip"; - private Object clipLock = new Object(); - private int loopsLeft = 0; + private Object clipLock = new Object(); + private int loopsLeft = 0; - // private Semaphore clipSemaphore = new Semaphore(1); + // private Semaphore clipSemaphore = new Semaphore(1); - /** - * This thread runs - * - */ - private final class ClipThread extends Thread { - @Override - public void run() { + /** + * This thread runs + * + */ + private final class ClipThread extends Thread { + @Override + public void run() { - /* - * The while loop below only works with LOOP_CONTINUOUSLY because we - * abuse the fact that loopsLeft's initial value is -1 - * (=LOOP_CONTINUOUSLY) and it keeps on going lower without hitting - * 0. So do a sanity check - */ - if (Clip.LOOP_CONTINUOUSLY != -1) { - throw new UnsupportedOperationException( - "LOOP_CONTINUOUSLY has changed; things are going to break"); - } + /* + * The while loop below only works with LOOP_CONTINUOUSLY because we + * abuse the fact that loopsLeft's initial value is -1 + * (=LOOP_CONTINUOUSLY) and it keeps on going lower without hitting + * 0. So do a sanity check + */ + if (Clip.LOOP_CONTINUOUSLY != -1) { + throw new UnsupportedOperationException( + "LOOP_CONTINUOUSLY has changed; things are going to break"); + } - while (true) { - writeFrames(currentFrame, endFrame + 1); - if (Thread.interrupted()) { - // Thread.currentThread().interrupt(); - // System.out.println("returned from interrupted - // writeFrames"); - break; - } + while (true) { + writeFrames(currentFrame, endFrame + 1); + if (Thread.interrupted()) { + // Thread.currentThread().interrupt(); + // System.out.println("returned from interrupted + // writeFrames"); + break; + } - // if loop(0) has been called from the mainThread, - // wait until loopsLeft has been set - if (loopsLeft == 0) { - // System.out.println("Reading to the end of the file"); - // System.out.println("endFrame: " + endFrame); - writeFrames(endFrame, getFrameLength()); - break; - } else { - synchronized (clipLock) { - currentFrame = startFrame; - if (loopsLeft != Integer.MIN_VALUE) { - loopsLeft--; - } - } - } + // if loop(0) has been called from the mainThread, + // wait until loopsLeft has been set + if (loopsLeft == 0) { + // System.out.println("Reading to the end of the file"); + // System.out.println("endFrame: " + endFrame); + writeFrames(endFrame, getFrameLength()); + break; + } else { + synchronized (clipLock) { + currentFrame = startFrame; + if (loopsLeft != Integer.MIN_VALUE) { + loopsLeft--; + } + } + } - } + } - // drain - Operation operation; + // drain + Operation operation; - synchronized (eventLoop.threadLock) { - operation = stream.drain(); - } + synchronized (eventLoop.threadLock) { + operation = stream.drain(); + } - operation.waitForCompletion(); - operation.releaseReference(); + operation.waitForCompletion(); + operation.releaseReference(); - } - } + } + } - private ClipThread clipThread; + private ClipThread clipThread; - private void writeFrames(int startingFrame, int lastFrame) { + private void writeFrames(int startingFrame, int lastFrame) { - WriteListener writeListener = new WriteListener() { - @Override - public void update() { - synchronized (eventLoop.threadLock) { - eventLoop.threadLock.notifyAll(); - } - } - }; + WriteListener writeListener = new WriteListener() { + @Override + public void update() { + synchronized (eventLoop.threadLock) { + eventLoop.threadLock.notifyAll(); + } + } + }; - stream.addWriteListener(writeListener); + stream.addWriteListener(writeListener); - Debug.println(DebugLevel.Verbose, - "PulseAudioClip$ClipThread.writeFrames(): Writing"); + Debug.println(DebugLevel.Verbose, + "PulseAudioClip$ClipThread.writeFrames(): Writing"); - int remainingFrames = lastFrame - startingFrame - 1; - while (remainingFrames > 0) { - synchronized (eventLoop.threadLock) { - int availableSize; + int remainingFrames = lastFrame - startingFrame - 1; + while (remainingFrames > 0) { + synchronized (eventLoop.threadLock) { + int availableSize; - do { - availableSize = stream.getWritableSize(); - if (availableSize < 0) { - Thread.currentThread().interrupt(); - stream.removeWriteListener(writeListener); - return; - } - if (availableSize == 0) { - try { - eventLoop.threadLock.wait(); - } catch (InterruptedException e) { - // System.out - // .println("interrupted while waiting for - // getWritableSize"); - // clean up and return - Thread.currentThread().interrupt(); - stream.removeWriteListener(writeListener); - return; - } - } + do { + availableSize = stream.getWritableSize(); + if (availableSize < 0) { + Thread.currentThread().interrupt(); + stream.removeWriteListener(writeListener); + return; + } + if (availableSize == 0) { + try { + eventLoop.threadLock.wait(); + } catch (InterruptedException e) { + // System.out + // .println("interrupted while waiting for + // getWritableSize"); + // clean up and return + Thread.currentThread().interrupt(); + stream.removeWriteListener(writeListener); + return; + } + } - } while (availableSize == 0); + } while (availableSize == 0); - int framesToWrite = Math.min(remainingFrames, availableSize - / getFormat().getFrameSize()); - stream.write(data, currentFrame * getFormat().getFrameSize(), - framesToWrite * getFormat().getFrameSize()); - remainingFrames -= framesToWrite; - currentFrame += framesToWrite; - framesSinceOpen += framesToWrite; - if (Thread.interrupted()) { - Thread.currentThread().interrupt(); - break; - } - // System.out.println("remaining frames" + remainingFrames); - // System.out.println("currentFrame: " + currentFrame); - // System.out.println("framesSinceOpen: " + framesSinceOpen); - } - } + int framesToWrite = Math.min(remainingFrames, availableSize + / getFormat().getFrameSize()); + stream.write(data, currentFrame * getFormat().getFrameSize(), + framesToWrite * getFormat().getFrameSize()); + remainingFrames -= framesToWrite; + currentFrame += framesToWrite; + framesSinceOpen += framesToWrite; + if (Thread.interrupted()) { + Thread.currentThread().interrupt(); + break; + } + // System.out.println("remaining frames" + remainingFrames); + // System.out.println("currentFrame: " + currentFrame); + // System.out.println("framesSinceOpen: " + framesSinceOpen); + } + } - stream.removeWriteListener(writeListener); - } + stream.removeWriteListener(writeListener); + } - PulseAudioClip(AudioFormat[] formats, AudioFormat defaultFormat) { - this.supportedFormats = formats; - this.defaultFormat = defaultFormat; - this.currentFormat = defaultFormat; - this.streamName = DEFAULT_CLIP_NAME; + PulseAudioClip(AudioFormat[] formats, AudioFormat defaultFormat) { + this.supportedFormats = formats; + this.defaultFormat = defaultFormat; + this.currentFormat = defaultFormat; + this.streamName = DEFAULT_CLIP_NAME; - clipThread = new ClipThread(); + clipThread = new ClipThread(); - } + } - @Override - protected void connectLine(int bufferSize, Stream masterStream) - throws LineUnavailableException { - StreamBufferAttributes bufferAttributes = new StreamBufferAttributes( - bufferSize, bufferSize / 4, bufferSize / 8, - ((bufferSize / 10) > 100 ? bufferSize / 10 : 100), 0); + @Override + protected void connectLine(int bufferSize, Stream masterStream) + throws LineUnavailableException { + StreamBufferAttributes bufferAttributes = new StreamBufferAttributes( + bufferSize, bufferSize / 4, bufferSize / 8, + ((bufferSize / 10) > 100 ? bufferSize / 10 : 100), 0); - if (masterStream != null) { - synchronized (eventLoop.threadLock) { - stream.connectForPlayback(Stream.DEFAULT_DEVICE, - bufferAttributes, masterStream.getStreamPointer()); - } - } else { - synchronized (eventLoop.threadLock) { - stream.connectForPlayback(Stream.DEFAULT_DEVICE, - bufferAttributes, null); - } - } - } + if (masterStream != null) { + synchronized (eventLoop.threadLock) { + stream.connectForPlayback(Stream.DEFAULT_DEVICE, + bufferAttributes, masterStream.getStreamPointer()); + } + } else { + synchronized (eventLoop.threadLock) { + stream.connectForPlayback(Stream.DEFAULT_DEVICE, + bufferAttributes, null); + } + } + } - @Override - public int available() { - return 0; // a clip always returns 0 - } + @Override + public int available() { + return 0; // a clip always returns 0 + } - @Override - public void close() { + @Override + public void close() { - if (!isOpen) { - throw new IllegalStateException("line already closed"); - } + if (!isOpen) { + throw new IllegalStateException("line already closed"); + } - clipThread.interrupt(); + clipThread.interrupt(); - try { - clipThread.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } + try { + clipThread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } - currentFrame = 0; - framesSinceOpen = 0; + currentFrame = 0; + framesSinceOpen = 0; - PulseAudioMixer mixer = PulseAudioMixer.getInstance(); - mixer.removeSourceLine(this); + PulseAudioMixer mixer = PulseAudioMixer.getInstance(); + mixer.removeSourceLine(this); - super.close(); + super.close(); - Debug.println(DebugLevel.Verbose, "PulseAudioClip.close(): " - + "Clip closed"); + Debug.println(DebugLevel.Verbose, "PulseAudioClip.close(): " + + "Clip closed"); - } + } - /* - * - * drain() on a Clip should block until the entire clip has finished playing - * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4732218 - */ - @Override - public void drain() { - if (!isOpen) { - throw new IllegalStateException("line not open"); - } + /* + * + * drain() on a Clip should block until the entire clip has finished playing + * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4732218 + */ + @Override + public void drain() { + if (!isOpen) { + throw new IllegalStateException("line not open"); + } - while (clipThread != null && clipThread.isAlive()) { - try { - clipThread.join(); - } catch (InterruptedException e) { - // ignore - } - } + while (clipThread != null && clipThread.isAlive()) { + try { + clipThread.join(); + } catch (InterruptedException e) { + // ignore + } + } - Operation operation; + Operation operation; - synchronized (eventLoop.threadLock) { - operation = stream.drain(); - } + synchronized (eventLoop.threadLock) { + operation = stream.drain(); + } - operation.waitForCompletion(); - operation.releaseReference(); + operation.waitForCompletion(); + operation.releaseReference(); - } + } - @Override - public void flush() { - if (!isOpen) { - throw new IllegalStateException("line not open"); - } + @Override + public void flush() { + if (!isOpen) { + throw new IllegalStateException("line not open"); + } - Operation operation; - synchronized (eventLoop.threadLock) { - operation = stream.flush(); - operation.waitForCompletion(); - } - operation.releaseReference(); + Operation operation; + synchronized (eventLoop.threadLock) { + operation = stream.flush(); + operation.waitForCompletion(); + } + operation.releaseReference(); - } + } - @Override - public int getFrameLength() { - if (!isOpen) { - return AudioSystem.NOT_SPECIFIED; - } + @Override + public int getFrameLength() { + if (!isOpen) { + return AudioSystem.NOT_SPECIFIED; + } - return frameCount; - } + return frameCount; + } - @Override - public int getFramePosition() { - if (!isOpen) { - throw new IllegalStateException("Line not open"); - } - synchronized (clipLock) { - return (int) framesSinceOpen; - } - } + @Override + public int getFramePosition() { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } + synchronized (clipLock) { + return (int) framesSinceOpen; + } + } - @Override - public long getLongFramePosition() { - if (!isOpen) { - throw new IllegalStateException("Line not open"); - } + @Override + public long getLongFramePosition() { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } - synchronized (clipLock) { - return framesSinceOpen; - } - } + synchronized (clipLock) { + return framesSinceOpen; + } + } - @Override - public long getMicrosecondLength() { - if (!isOpen) { - return AudioSystem.NOT_SPECIFIED; - } - synchronized (clipLock) { - return (long) (frameCount / currentFormat.getFrameRate() * 1000); - } - } + @Override + public long getMicrosecondLength() { + if (!isOpen) { + return AudioSystem.NOT_SPECIFIED; + } + synchronized (clipLock) { + return (long) (frameCount / currentFormat.getFrameRate() * 1000); + } + } - @Override - public long getMicrosecondPosition() { - if (!isOpen) { - throw new IllegalStateException("Line not open"); - } + @Override + public long getMicrosecondPosition() { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } - synchronized (clipLock) { - return (long) (framesSinceOpen / currentFormat.getFrameRate() * 1000); - } - } + synchronized (clipLock) { + return (long) (framesSinceOpen / currentFormat.getFrameRate() * 1000); + } + } - @Override - public void loop(int count) { - if (!isOpen) { - throw new IllegalStateException("Line not open"); - } + @Override + public void loop(int count) { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } - if (count < 0 && count != LOOP_CONTINUOUSLY) { - throw new IllegalArgumentException("invalid value for count:" - + count); - } + if (count < 0 && count != LOOP_CONTINUOUSLY) { + throw new IllegalArgumentException("invalid value for count:" + + count); + } - if (clipThread.isAlive() && count != 0) { - // Do nothing; behavior not specified by the Java API - return; - } + if (clipThread.isAlive() && count != 0) { + // Do nothing; behavior not specified by the Java API + return; + } - super.start(); + super.start(); - synchronized (clipLock) { - if (currentFrame > endFrame) { - loopsLeft = 0; - } else { - loopsLeft = count; - } - } - if (!clipThread.isAlive()) { - clipThread = new ClipThread(); - clipThread.start(); - } + synchronized (clipLock) { + if (currentFrame > endFrame) { + loopsLeft = 0; + } else { + loopsLeft = count; + } + } + if (!clipThread.isAlive()) { + clipThread = new ClipThread(); + clipThread.start(); + } - } + } - @Override - public void open() throws LineUnavailableException { - throw new IllegalArgumentException("open() on a Clip is not allowed"); - } + @Override + public void open() throws LineUnavailableException { + throw new IllegalArgumentException("open() on a Clip is not allowed"); + } - @Override - public void open(AudioFormat format, byte[] data, int offset, int bufferSize) - throws LineUnavailableException { + @Override + public void open(AudioFormat format, byte[] data, int offset, int bufferSize) + throws LineUnavailableException { - super.open(format); - this.data = new byte[bufferSize]; - System.arraycopy(data, offset, this.data, 0, bufferSize); + super.open(format); + this.data = new byte[bufferSize]; + System.arraycopy(data, offset, this.data, 0, bufferSize); - frameCount = bufferSize / format.getFrameSize(); - currentFrame = 0; - framesSinceOpen = 0; - startFrame = 0; - endFrame = frameCount - 1; - loopsLeft = 0; + frameCount = bufferSize / format.getFrameSize(); + currentFrame = 0; + framesSinceOpen = 0; + startFrame = 0; + endFrame = frameCount - 1; + loopsLeft = 0; - PulseAudioVolumeControl volumeControl = new PulseAudioVolumeControl( - this, eventLoop); - controls.add(volumeControl); + PulseAudioVolumeControl volumeControl = new PulseAudioVolumeControl( + this, eventLoop); + controls.add(volumeControl); - PulseAudioMixer mixer = PulseAudioMixer.getInstance(); - mixer.addSourceLine(this); + PulseAudioMixer mixer = PulseAudioMixer.getInstance(); + mixer.addSourceLine(this); - isOpen = true; - Debug.println(DebugLevel.Verbose, "PulseAudioClip.open(): Clip opened"); + isOpen = true; + Debug.println(DebugLevel.Verbose, "PulseAudioClip.open(): Clip opened"); - } + } - // FIXME - @Override - public byte[] native_set_volume(float value) { - return stream.native_set_volume(value); - } + // FIXME + @Override + public byte[] native_set_volume(float value) { + return stream.native_set_volume(value); + } - public byte[] native_update_volume() { - return stream.native_update_volume(); - } + public byte[] native_update_volume() { + return stream.native_update_volume(); + } - @Override - public float getCachedVolume() { - return stream.getCachedVolume(); - } + @Override + public float getCachedVolume() { + return stream.getCachedVolume(); + } - @Override - public void setCachedVolume(float value) { - stream.setCachedVolume(value); + @Override + public void setCachedVolume(float value) { + stream.setCachedVolume(value); - } + } - @Override - public void open(AudioInputStream stream) throws LineUnavailableException, - IOException { - byte[] buffer = new byte[(int) (stream.getFrameLength() * stream - .getFormat().getFrameSize())]; - stream.read(buffer, 0, buffer.length); + @Override + public void open(AudioInputStream stream) throws LineUnavailableException, + IOException { + byte[] buffer = new byte[(int) (stream.getFrameLength() * stream + .getFormat().getFrameSize())]; + stream.read(buffer, 0, buffer.length); - open(stream.getFormat(), buffer, 0, buffer.length); + open(stream.getFormat(), buffer, 0, buffer.length); - } + } - @Override - public void setFramePosition(int frames) { - if (!isOpen) { - throw new IllegalStateException("Line not open"); - } + @Override + public void setFramePosition(int frames) { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } - if (frames < 0 || frames > frameCount) { - throw new IllegalArgumentException("incorreft frame value"); - } + if (frames < 0 || frames > frameCount) { + throw new IllegalArgumentException("incorreft frame value"); + } - synchronized (clipLock) { - currentFrame = frames; - } + synchronized (clipLock) { + currentFrame = frames; + } - } + } - @Override - public void setLoopPoints(int start, int end) { - if (!isOpen) { - throw new IllegalStateException("Line not open"); - } + @Override + public void setLoopPoints(int start, int end) { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } - if (end == -1) { - end = frameCount - 1; - } + if (end == -1) { + end = frameCount - 1; + } - if (end < start) { - throw new IllegalArgumentException( - "ending point must be greater than or equal to the starting point"); - } + if (end < start) { + throw new IllegalArgumentException( + "ending point must be greater than or equal to the starting point"); + } - if (start < 0) { - throw new IllegalArgumentException( - "starting point must be greater than or equal to 0"); - } + if (start < 0) { + throw new IllegalArgumentException( + "starting point must be greater than or equal to 0"); + } - synchronized (clipLock) { - startFrame = start; - endFrame = end; - } + synchronized (clipLock) { + startFrame = start; + endFrame = end; + } - } + } - @Override - public void setMicrosecondPosition(long microseconds) { - if (!isOpen) { - throw new IllegalStateException("Line not open"); - } + @Override + public void setMicrosecondPosition(long microseconds) { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } - float frameIndex = microseconds * currentFormat.getFrameRate() / 1000; + float frameIndex = microseconds * currentFormat.getFrameRate() / 1000; - /* make frameIndex positive */ - while (frameIndex < 0) { - frameIndex += frameCount; - } + /* make frameIndex positive */ + while (frameIndex < 0) { + frameIndex += frameCount; + } - /* frameIndex is in the range [0, frameCount-1], inclusive */ - frameIndex = frameIndex % frameCount; + /* frameIndex is in the range [0, frameCount-1], inclusive */ + frameIndex = frameIndex % frameCount; - synchronized (clipLock) { - currentFrame = (int) frameIndex; - } + synchronized (clipLock) { + currentFrame = (int) frameIndex; + } - } + } - @Override - public void start() { - if (isStarted) { - return; - } + @Override + public void start() { + if (isStarted) { + return; + } - super.start(); + super.start(); - if (!clipThread.isAlive()) { - synchronized (clipLock) { - loopsLeft = 0; - } - clipThread = new ClipThread(); - clipThread.start(); - } + if (!clipThread.isAlive()) { + synchronized (clipLock) { + loopsLeft = 0; + } + clipThread = new ClipThread(); + clipThread.start(); + } - } + } - @Override - public void stop() { - if (!isOpen) { - throw new IllegalStateException("Line not open"); - } + @Override + public void stop() { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } - /* do what start does and ignore if called at the wrong time */ - if (!isStarted) { - return; - } + /* do what start does and ignore if called at the wrong time */ + if (!isStarted) { + return; + } - if (clipThread.isAlive()) { - clipThread.interrupt(); - } - try { - clipThread.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - synchronized (clipLock) { - loopsLeft = 0; - } + if (clipThread.isAlive()) { + clipThread.interrupt(); + } + try { + clipThread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + synchronized (clipLock) { + loopsLeft = 0; + } - super.stop(); + super.stop(); - } + } - @Override - public Line.Info getLineInfo() { - return new DataLine.Info(Clip.class, supportedFormats, - StreamBufferAttributes.MIN_VALUE, - StreamBufferAttributes.MAX_VALUE); - } + @Override + public Line.Info getLineInfo() { + return new DataLine.Info(Clip.class, supportedFormats, + StreamBufferAttributes.MIN_VALUE, + StreamBufferAttributes.MAX_VALUE); + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Fri Jun 10 17:42:18 2011 -0400 @@ -55,450 +55,450 @@ */ abstract class PulseAudioDataLine extends PulseAudioLine implements DataLine { - protected static final int DEFAULT_BUFFER_SIZE = StreamBufferAttributes.SANE_DEFAULT; + protected static final int DEFAULT_BUFFER_SIZE = StreamBufferAttributes.SANE_DEFAULT; - // override this to set the stream name - protected String streamName; + // override this to set the stream name + protected String streamName; - // true between start() and stop() - protected boolean isStarted = false; + // true between start() and stop() + protected boolean isStarted = false; - // true between a started and an underflow callback - protected boolean dataWritten = false; + // true between a started and an underflow callback + protected boolean dataWritten = false; - // true if a stream has been paused - // protected boolean isPaused = false; + // true if a stream has been paused + // protected boolean isPaused = false; - protected AudioFormat[] supportedFormats = null; - protected AudioFormat currentFormat = null; - protected AudioFormat defaultFormat = null; - protected boolean sendEvents = true; + protected AudioFormat[] supportedFormats = null; + protected AudioFormat currentFormat = null; + protected AudioFormat defaultFormat = null; + protected boolean sendEvents = true; - protected int bufferSize = 0; - // the total number of frames played since this line was opened - protected long framesSinceOpen = 0; + protected int bufferSize = 0; + // the total number of frames played since this line was opened + protected long framesSinceOpen = 0; - protected EventLoop eventLoop = null; - protected Semaphore semaphore = new Semaphore(0); - protected Stream stream; - boolean writeInterrupted = false; + protected EventLoop eventLoop = null; + protected Semaphore semaphore = new Semaphore(0); + protected Stream stream; + boolean writeInterrupted = false; - protected void open(AudioFormat format, int bufferSize) - throws LineUnavailableException { + protected void open(AudioFormat format, int bufferSize) + throws LineUnavailableException { - if (isOpen()) { - throw new IllegalStateException("Line is already open"); - } + if (isOpen()) { + throw new IllegalStateException("Line is already open"); + } - PulseAudioMixer mixer = PulseAudioMixer.getInstance(); - if (!mixer.isOpen()) { - mixer.open(); - } + PulseAudioMixer mixer = PulseAudioMixer.getInstance(); + if (!mixer.isOpen()) { + mixer.open(); + } - eventLoop = EventLoop.getEventLoop(); + eventLoop = EventLoop.getEventLoop(); - createStream(format); - addStreamListeners(); - connect(null, bufferSize); - } + createStream(format); + addStreamListeners(); + connect(null, bufferSize); + } - private void createStream(AudioFormat format) - throws LineUnavailableException { + private void createStream(AudioFormat format) + throws LineUnavailableException { - for (AudioFormat myFormat : supportedFormats) { - if (format.matches(myFormat)) { - /* - * A few issues with format: - * - * To match: SAME encoding: safe because its a java enum. SAME - * number of channels: safe because myFormat has specific - * values. SAME bits per sample (aka sampleSize) and bytes per - * frame (aka frameSize): safe because myFormat has specific - * values. SAME sample rate: _not_ safe because myFormat uses - * AudioSystem.NOT_SPECIFIED. SAME frame rate: safe because we - * _ignore_ it completely ;) - */ + for (AudioFormat myFormat : supportedFormats) { + if (format.matches(myFormat)) { + /* + * A few issues with format: + * + * To match: SAME encoding: safe because its a java enum. SAME + * number of channels: safe because myFormat has specific + * values. SAME bits per sample (aka sampleSize) and bytes per + * frame (aka frameSize): safe because myFormat has specific + * values. SAME sample rate: _not_ safe because myFormat uses + * AudioSystem.NOT_SPECIFIED. SAME frame rate: safe because we + * _ignore_ it completely ;) + */ - float sampleRate = format.getSampleRate(); - if (sampleRate == (float) AudioSystem.NOT_SPECIFIED) { - /* pick a random sample rate */ - sampleRate = 44100.0f; - } + float sampleRate = format.getSampleRate(); + if (sampleRate == (float) AudioSystem.NOT_SPECIFIED) { + /* pick a random sample rate */ + sampleRate = 44100.0f; + } - String formatString = (String) myFormat - .getProperty(PulseAudioMixer.PULSEAUDIO_FORMAT_KEY); - synchronized (eventLoop.threadLock) { + String formatString = (String) myFormat + .getProperty(PulseAudioMixer.PULSEAUDIO_FORMAT_KEY); + synchronized (eventLoop.threadLock) { - stream = new Stream(eventLoop.getContextPointer(), - streamName, Stream.Format.valueOf(formatString), - (int) sampleRate, myFormat.getChannels()); + stream = new Stream(eventLoop.getContextPointer(), + streamName, Stream.Format.valueOf(formatString), + (int) sampleRate, myFormat.getChannels()); - } - currentFormat = format; - isOpen = true; - } - } + } + currentFormat = format; + isOpen = true; + } + } - if (!isOpen()) { - throw new IllegalArgumentException("Invalid format"); - } + if (!isOpen()) { + throw new IllegalArgumentException("Invalid format"); + } - // System.out.println("Stream " + stream + " created"); + // System.out.println("Stream " + stream + " created"); - } + } - /** - * This method adds the listeners used to find out when the stream has - * connected/disconnected etc to the actual stream. - */ - private void addStreamListeners() { - Stream.StateListener openCloseListener = new Stream.StateListener() { + /** + * This method adds the listeners used to find out when the stream has + * connected/disconnected etc to the actual stream. + */ + private void addStreamListeners() { + Stream.StateListener openCloseListener = new Stream.StateListener() { - @Override - public void update() { - synchronized (eventLoop.threadLock) { + @Override + public void update() { + synchronized (eventLoop.threadLock) { - /* - * Note the order: first we notify all the listeners, and - * then return. this means no race conditions when the - * listeners are removed before they get called by close - * - * eg: - * - * line.close(); line.removeLineListener(listener) - * - * the listener is guaranteed to have run - */ + /* + * Note the order: first we notify all the listeners, and + * then return. this means no race conditions when the + * listeners are removed before they get called by close + * + * eg: + * + * line.close(); line.removeLineListener(listener) + * + * the listener is guaranteed to have run + */ - if (stream.getState() == Stream.State.READY) { - if (sendEvents) { - fireLineEvent(new LineEvent( - PulseAudioDataLine.this, - LineEvent.Type.OPEN, framesSinceOpen)); - } - semaphore.release(); + if (stream.getState() == Stream.State.READY) { + if (sendEvents) { + fireLineEvent(new LineEvent( + PulseAudioDataLine.this, + LineEvent.Type.OPEN, framesSinceOpen)); + } + semaphore.release(); - } else if (stream.getState() == Stream.State.TERMINATED - || stream.getState() == Stream.State.FAILED) { - if (sendEvents) { - fireLineEvent((new LineEvent( - PulseAudioDataLine.this, - LineEvent.Type.CLOSE, framesSinceOpen))); - } - synchronized (this) { - this.notifyAll(); - } - semaphore.release(); + } else if (stream.getState() == Stream.State.TERMINATED + || stream.getState() == Stream.State.FAILED) { + if (sendEvents) { + fireLineEvent((new LineEvent( + PulseAudioDataLine.this, + LineEvent.Type.CLOSE, framesSinceOpen))); + } + synchronized (this) { + this.notifyAll(); + } + semaphore.release(); - } - } - } - }; + } + } + } + }; - stream.addStateListener(openCloseListener); + stream.addStateListener(openCloseListener); - Stream.UnderflowListener stoppedListener = new Stream.UnderflowListener() { - @Override - public void update() { - dataWritten = false; + Stream.UnderflowListener stoppedListener = new Stream.UnderflowListener() { + @Override + public void update() { + dataWritten = false; - // always send a STOP event on an underflow (assumption: - // an underflow can't happen while the stream is corked) - fireLineEvent(new LineEvent(PulseAudioDataLine.this, - LineEvent.Type.STOP, framesSinceOpen)); - } - }; - stream.addUnderflowListener(stoppedListener); + // always send a STOP event on an underflow (assumption: + // an underflow can't happen while the stream is corked) + fireLineEvent(new LineEvent(PulseAudioDataLine.this, + LineEvent.Type.STOP, framesSinceOpen)); + } + }; + stream.addUnderflowListener(stoppedListener); - Stream.PlaybackStartedListener startedListener = new Stream.PlaybackStartedListener() { - @Override - public void update() { - if (!dataWritten) { - fireLineEvent(new LineEvent(PulseAudioDataLine.this, - LineEvent.Type.START, framesSinceOpen)); - synchronized (this) { - this.notifyAll(); - } - } - dataWritten = true; + Stream.PlaybackStartedListener startedListener = new Stream.PlaybackStartedListener() { + @Override + public void update() { + if (!dataWritten) { + fireLineEvent(new LineEvent(PulseAudioDataLine.this, + LineEvent.Type.START, framesSinceOpen)); + synchronized (this) { + this.notifyAll(); + } + } + dataWritten = true; - } - }; + } + }; - stream.addPlaybackStartedListener(startedListener); + stream.addPlaybackStartedListener(startedListener); - WriteListener writeNotifier = new WriteListener() { + WriteListener writeNotifier = new WriteListener() { - @Override - public void update() { - synchronized (eventLoop.threadLock) { - eventLoop.threadLock.notifyAll(); - } - } + @Override + public void update() { + synchronized (eventLoop.threadLock) { + eventLoop.threadLock.notifyAll(); + } + } - }; - stream.addWriteListener(writeNotifier); + }; + stream.addWriteListener(writeNotifier); - Stream.CorkListener corkListener = new Stream.CorkListener() { + Stream.CorkListener corkListener = new Stream.CorkListener() { - @Override - public void update() { - synchronized (eventLoop.threadLock) { - eventLoop.threadLock.notifyAll(); - } - } + @Override + public void update() { + synchronized (eventLoop.threadLock) { + eventLoop.threadLock.notifyAll(); + } + } - }; - stream.addCorkListener(corkListener); - } + }; + stream.addCorkListener(corkListener); + } - private void connect(Stream masterStream, int bufferSize) - throws LineUnavailableException { + private void connect(Stream masterStream, int bufferSize) + throws LineUnavailableException { - try { - synchronized (eventLoop.threadLock) { - connectLine(bufferSize, masterStream); - } - } catch (LineUnavailableException e) { - // error connecting to the server! - // stream.removePlaybackStartedListener(startedListener); - // stream.removeUnderflowListener(stoppedListener); - // stream.removeStateListener(openCloseListener); - stream.free(); - stream = null; - throw e; + try { + synchronized (eventLoop.threadLock) { + connectLine(bufferSize, masterStream); + } + } catch (LineUnavailableException e) { + // error connecting to the server! + // stream.removePlaybackStartedListener(startedListener); + // stream.removeUnderflowListener(stoppedListener); + // stream.removeStateListener(openCloseListener); + stream.free(); + stream = null; + throw e; - } - this.bufferSize = bufferSize; - try { - semaphore.acquire(); - synchronized (eventLoop.threadLock) { - if (stream.getState() != Stream.State.READY) { - stream.disconnect(); - stream.free(); - throw new LineUnavailableException( - "unable to obtain a line"); - } - } - } catch (InterruptedException e) { - throw new LineUnavailableException("unable to prepare stream"); - } - } + } + this.bufferSize = bufferSize; + try { + semaphore.acquire(); + synchronized (eventLoop.threadLock) { + if (stream.getState() != Stream.State.READY) { + stream.disconnect(); + stream.free(); + throw new LineUnavailableException( + "unable to obtain a line"); + } + } + } catch (InterruptedException e) { + throw new LineUnavailableException("unable to prepare stream"); + } + } - protected void open(AudioFormat format) throws LineUnavailableException { - open(format, DEFAULT_BUFFER_SIZE); + protected void open(AudioFormat format) throws LineUnavailableException { + open(format, DEFAULT_BUFFER_SIZE); - } + } - @Override - public void open() throws LineUnavailableException { - assert (defaultFormat != null); - open(defaultFormat, DEFAULT_BUFFER_SIZE); - } + @Override + public void open() throws LineUnavailableException { + assert (defaultFormat != null); + open(defaultFormat, DEFAULT_BUFFER_SIZE); + } - @Override - public void close() { + @Override + public void close() { - if (!isOpen()) { - // For whatever reason, we are being asked to close - // a line that is not even open. - return; - } + if (!isOpen()) { + // For whatever reason, we are being asked to close + // a line that is not even open. + return; + } - synchronized (eventLoop.threadLock) { - stream.disconnect(); - } + synchronized (eventLoop.threadLock) { + stream.disconnect(); + } - try { - semaphore.acquire(); - } catch (InterruptedException e) { - throw new RuntimeException("unable to prepare stream"); - } + try { + semaphore.acquire(); + } catch (InterruptedException e) { + throw new RuntimeException("unable to prepare stream"); + } - synchronized (eventLoop.threadLock) { - stream.free(); - } + synchronized (eventLoop.threadLock) { + stream.free(); + } - super.close(); + super.close(); - isStarted = false; - } + isStarted = false; + } - void reconnectforSynchronization(Stream masterStream) - throws LineUnavailableException { - sendEvents = false; - drain(); + void reconnectforSynchronization(Stream masterStream) + throws LineUnavailableException { + sendEvents = false; + drain(); - synchronized (eventLoop.threadLock) { - stream.disconnect(); - } - try { - semaphore.acquire(); - } catch (InterruptedException e) { - throw new RuntimeException("unable to prepare stream"); - } + synchronized (eventLoop.threadLock) { + stream.disconnect(); + } + try { + semaphore.acquire(); + } catch (InterruptedException e) { + throw new RuntimeException("unable to prepare stream"); + } - createStream(getFormat()); - addStreamListeners(); - connect(masterStream, getBufferSize()); + createStream(getFormat()); + addStreamListeners(); + connect(masterStream, getBufferSize()); - sendEvents = true; - } + sendEvents = true; + } - @Override - public void start() { - if (!isOpen()) { - throw new IllegalStateException( - "Line must be open()ed before it can be start()ed"); - } + @Override + public void start() { + if (!isOpen()) { + throw new IllegalStateException( + "Line must be open()ed before it can be start()ed"); + } - if (isStarted) { - return; + if (isStarted) { + return; - } - if (dataWritten && (!isStarted)) { - fireLineEvent(new LineEvent(PulseAudioDataLine.this, - LineEvent.Type.START, framesSinceOpen)); - } + } + if (dataWritten && (!isStarted)) { + fireLineEvent(new LineEvent(PulseAudioDataLine.this, + LineEvent.Type.START, framesSinceOpen)); + } - Operation op; - synchronized (eventLoop.threadLock) { - op = stream.unCork(); - } + Operation op; + synchronized (eventLoop.threadLock) { + op = stream.unCork(); + } - op.waitForCompletion(); - op.releaseReference(); - synchronized (this) { - this.notifyAll(); - } - isStarted = true; + op.waitForCompletion(); + op.releaseReference(); + synchronized (this) { + this.notifyAll(); + } + isStarted = true; - } + } - @Override - public synchronized void stop() { - if (!isOpen()) { - // For some reason, we are being asked to stop a line - // that isn't even open. - return; - } - writeInterrupted = true; - if (!isStarted) { - return; - } + @Override + public synchronized void stop() { + if (!isOpen()) { + // For some reason, we are being asked to stop a line + // that isn't even open. + return; + } + writeInterrupted = true; + if (!isStarted) { + return; + } - Operation op; - synchronized (eventLoop.threadLock) { - op = stream.cork(); - // if there are no data on the line when stop was called, - // don't send a stop event - if (dataWritten && (isStarted)) { - fireLineEvent(new LineEvent(PulseAudioDataLine.this, - LineEvent.Type.STOP, framesSinceOpen)); - } - } + Operation op; + synchronized (eventLoop.threadLock) { + op = stream.cork(); + // if there are no data on the line when stop was called, + // don't send a stop event + if (dataWritten && (isStarted)) { + fireLineEvent(new LineEvent(PulseAudioDataLine.this, + LineEvent.Type.STOP, framesSinceOpen)); + } + } - op.waitForCompletion(); - op.releaseReference(); + op.waitForCompletion(); + op.releaseReference(); - isStarted = false; - } + isStarted = false; + } - /* - * TODO - * - * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4791152 : - * - * a line is active in between calls to start() and stop(). In that sense, - * active means that the line is ready to take or give data. Running is - * tightly bound to data flow in the line. I.e. when you start a - * SourceDataLine but never write data to it, the line should not be - * running. This also means that a line should become not running on buffer - * underrun/overflow. - * - * - * HOWEVER, the javadocs say the opposite thing! (need help from the jck = - * official spec) - */ - @Override - public boolean isActive() { - return isStarted; - } + /* + * TODO + * + * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4791152 : + * + * a line is active in between calls to start() and stop(). In that sense, + * active means that the line is ready to take or give data. Running is + * tightly bound to data flow in the line. I.e. when you start a + * SourceDataLine but never write data to it, the line should not be + * running. This also means that a line should become not running on buffer + * underrun/overflow. + * + * + * HOWEVER, the javadocs say the opposite thing! (need help from the jck = + * official spec) + */ + @Override + public boolean isActive() { + return isStarted; + } - @Override - public boolean isRunning() { - return isStarted && dataWritten; - } + @Override + public boolean isRunning() { + return isStarted && dataWritten; + } - protected abstract void connectLine(int bufferSize, Stream masterStream) - throws LineUnavailableException; + protected abstract void connectLine(int bufferSize, Stream masterStream) + throws LineUnavailableException; - public Stream getStream() { - if (!isOpen()) { - throw new IllegalStateException("Line must be open"); - } + public Stream getStream() { + if (!isOpen()) { + throw new IllegalStateException("Line must be open"); + } - return stream; - } + return stream; + } - @Override - public int getBufferSize() { - if (!isOpen()) { - return DEFAULT_BUFFER_SIZE; - } - return bufferSize; - } + @Override + public int getBufferSize() { + if (!isOpen()) { + return DEFAULT_BUFFER_SIZE; + } + return bufferSize; + } - @Override - public AudioFormat getFormat() { - if (!isOpen()) { - return defaultFormat; - } - return currentFormat; - } + @Override + public AudioFormat getFormat() { + if (!isOpen()) { + return defaultFormat; + } + return currentFormat; + } - @Override - public float getLevel() { - return AudioSystem.NOT_SPECIFIED; - } + @Override + public float getLevel() { + return AudioSystem.NOT_SPECIFIED; + } - /** - * - * @param streamName - * the name of this audio stream - */ - public void setName(String streamName) { - if (isOpen()) { + /** + * + * @param streamName + * the name of this audio stream + */ + public void setName(String streamName) { + if (isOpen()) { - Operation o; - synchronized (eventLoop.threadLock) { - o = stream.setName(streamName); - } - o.waitForCompletion(); - o.releaseReference(); + Operation o; + synchronized (eventLoop.threadLock) { + o = stream.setName(streamName); + } + o.waitForCompletion(); + o.releaseReference(); - } + } - this.streamName = streamName; + this.streamName = streamName; - } + } - /** - * - * @return the name of this audio stream/clip - */ - public String getName() { - return streamName; - } + /** + * + * @return the name of this audio stream/clip + */ + public String getName() { + return streamName; + } - public int getBytesInBuffer() { - Operation o; - synchronized (eventLoop.threadLock) { - o = stream.updateTimingInfo(); - } - o.waitForCompletion(); - o.releaseReference(); - return stream.bytesInBuffer(); - } + public int getBytesInBuffer() { + Operation o; + synchronized (eventLoop.threadLock) { + o = stream.updateTimingInfo(); + } + o.waitForCompletion(); + o.releaseReference(); + return stream.bytesInBuffer(); + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioLine.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioLine.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioLine.java Fri Jun 10 17:42:18 2011 -0400 @@ -48,77 +48,77 @@ abstract class PulseAudioLine implements Line { - protected List lineListeners = new ArrayList(); - protected List controls = new ArrayList(); + protected List lineListeners = new ArrayList(); + protected List controls = new ArrayList(); - // true between open() and close(). ie represents when a line has acquire - // resources - protected boolean isOpen = false; + // true between open() and close(). ie represents when a line has acquire + // resources + protected boolean isOpen = false; - @Override - public void addLineListener(LineListener listener) { - this.lineListeners.add(listener); - } + @Override + public void addLineListener(LineListener listener) { + this.lineListeners.add(listener); + } - @Override - public void close() { - if (!isOpen()) { - throw new IllegalStateException("Line is not open"); - } + @Override + public void close() { + if (!isOpen()) { + throw new IllegalStateException("Line is not open"); + } - lineListeners.clear(); + lineListeners.clear(); - isOpen = false; - } + isOpen = false; + } - protected void fireLineEvent(LineEvent e) { - for (LineListener lineListener : lineListeners) { - lineListener.update(e); - } - } + protected void fireLineEvent(LineEvent e) { + for (LineListener lineListener : lineListeners) { + lineListener.update(e); + } + } - @Override - public Control getControl(Type control) { - if (isOpen()) { - for (Control aControl : controls) { - if (aControl.getType() == control) { - return aControl; - } - } - } - throw new IllegalArgumentException(control.toString() - + " not supported"); - } + @Override + public Control getControl(Type control) { + if (isOpen()) { + for (Control aControl : controls) { + if (aControl.getType() == control) { + return aControl; + } + } + } + throw new IllegalArgumentException(control.toString() + + " not supported"); + } - @Override - public Control[] getControls() { - if (!isOpen()) { - return new Control[] {}; - } + @Override + public Control[] getControls() { + if (!isOpen()) { + return new Control[] {}; + } - return (Control[]) controls.toArray(new Control[0]); - } + return (Control[]) controls.toArray(new Control[0]); + } - @Override - public boolean isControlSupported(Type control) { - for (Control myControl : controls) { - //Control.Type's known descendants keep a set of - //static Types. - if (myControl.getType().equals(control)) { - return true; - } - } - return false; - } + @Override + public boolean isControlSupported(Type control) { + for (Control myControl : controls) { + //Control.Type's known descendants keep a set of + //static Types. + if (myControl.getType().equals(control)) { + return true; + } + } + return false; + } - @Override - public boolean isOpen() { - return isOpen; - } + @Override + public boolean isOpen() { + return isOpen; + } - @Override - public void removeLineListener(LineListener listener) { - lineListeners.remove(listener); - } + @Override + public void removeLineListener(LineListener listener) { + lineListeners.remove(listener); + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java Fri Jun 10 17:42:18 2011 -0400 @@ -66,728 +66,728 @@ import org.classpath.icedtea.pulseaudio.Debug.DebugLevel; public final class PulseAudioMixer implements Mixer { - // singleton + // singleton - private Thread eventLoopThread; + private Thread eventLoopThread; - private List sourceLineInfos = new ArrayList(); - private List staticSourceLineInfos = new ArrayList(); + private List sourceLineInfos = new ArrayList(); + private List staticSourceLineInfos = new ArrayList(); - private List targetLineInfos = new ArrayList(); - private List staticTargetLineInfos = new ArrayList(); + private List targetLineInfos = new ArrayList(); + private List staticTargetLineInfos = new ArrayList(); - private static PulseAudioMixer _instance = null; + private static PulseAudioMixer _instance = null; - private static final String DEFAULT_APP_NAME = "Java"; - static final String PULSEAUDIO_FORMAT_KEY = "PulseAudioFormatKey"; + private static final String DEFAULT_APP_NAME = "Java"; + static final String PULSEAUDIO_FORMAT_KEY = "PulseAudioFormatKey"; - private boolean isOpen = false; + private boolean isOpen = false; - private final List sourceLines = new ArrayList(); - private final List targetLines = new ArrayList(); + private final List sourceLines = new ArrayList(); + private final List targetLines = new ArrayList(); - private final List lineListeners = new ArrayList(); + private final List lineListeners = new ArrayList(); - private PulseAudioMixer() { + private PulseAudioMixer() { - Debug.println(DebugLevel.Verbose, "PulseAudioMixer.PulseAudioMixer(): " - + "Contructing PulseAudioMixer..."); + Debug.println(DebugLevel.Verbose, "PulseAudioMixer.PulseAudioMixer(): " + + "Contructing PulseAudioMixer..."); - AudioFormat[] formats = getSupportedFormats(); + AudioFormat[] formats = getSupportedFormats(); - staticSourceLineInfos.add(new DataLine.Info(SourceDataLine.class, - formats, StreamBufferAttributes.MIN_VALUE, - StreamBufferAttributes.MAX_VALUE)); - staticSourceLineInfos.add(new DataLine.Info(Clip.class, formats, - StreamBufferAttributes.MIN_VALUE, - StreamBufferAttributes.MAX_VALUE)); + staticSourceLineInfos.add(new DataLine.Info(SourceDataLine.class, + formats, StreamBufferAttributes.MIN_VALUE, + StreamBufferAttributes.MAX_VALUE)); + staticSourceLineInfos.add(new DataLine.Info(Clip.class, formats, + StreamBufferAttributes.MIN_VALUE, + StreamBufferAttributes.MAX_VALUE)); - staticTargetLineInfos.add(new DataLine.Info(TargetDataLine.class, - formats, StreamBufferAttributes.MIN_VALUE, - StreamBufferAttributes.MAX_VALUE)); + staticTargetLineInfos.add(new DataLine.Info(TargetDataLine.class, + formats, StreamBufferAttributes.MIN_VALUE, + StreamBufferAttributes.MAX_VALUE)); - refreshSourceAndTargetLines(); + refreshSourceAndTargetLines(); - Debug.println(DebugLevel.Verbose, "PulseAudioMixer.PulseAudioMixer(): " - + "Finished constructing PulseAudioMixer"); + Debug.println(DebugLevel.Verbose, "PulseAudioMixer.PulseAudioMixer(): " + + "Finished constructing PulseAudioMixer"); - } + } - synchronized public static PulseAudioMixer getInstance() { - if (_instance == null) { - _instance = new PulseAudioMixer(); - } - return _instance; - } + synchronized public static PulseAudioMixer getInstance() { + if (_instance == null) { + _instance = new PulseAudioMixer(); + } + return _instance; + } - private AudioFormat[] getSupportedFormats() { + private AudioFormat[] getSupportedFormats() { - List supportedFormats = new ArrayList(); + List supportedFormats = new ArrayList(); - Map properties; + Map properties; - /* - * frameSize = sample size (in bytes, not bits) x # of channels - * - * From PulseAudio's sources - * http://git.0pointer.de/?p=pulseaudio.git;a=blob - * ;f=src/pulse/sample.c;h=93da2465f4301e27af4976e82737c3a048124a68;hb= - * 82ea8dde8abc51165a781c69bc3b38034d62d969#l63 - */ + /* + * frameSize = sample size (in bytes, not bits) x # of channels + * + * From PulseAudio's sources + * http://git.0pointer.de/?p=pulseaudio.git;a=blob + * ;f=src/pulse/sample.c;h=93da2465f4301e27af4976e82737c3a048124a68;hb= + * 82ea8dde8abc51165a781c69bc3b38034d62d969#l63 + */ - /* - * technically, PulseAudio supports up to 16 channels, but things get - * interesting with channel maps - * - * PA_CHANNEL_MAP_DEFAULT (=PA_CHANNEL_MAP_AIFF) supports 1,2,3,4,5 or 6 - * channels only - */ - int[] channelSizes = new int[] { 1, 2, 3, 4, 5, 6 }; + /* + * technically, PulseAudio supports up to 16 channels, but things get + * interesting with channel maps + * + * PA_CHANNEL_MAP_DEFAULT (=PA_CHANNEL_MAP_AIFF) supports 1,2,3,4,5 or 6 + * channels only + */ + int[] channelSizes = new int[] { 1, 2, 3, 4, 5, 6 }; - for (int channelSize : channelSizes) { - properties = new HashMap(); - properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_ALAW"); + for (int channelSize : channelSizes) { + properties = new HashMap(); + properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_ALAW"); - int sampleSize = 8; - final AudioFormat PA_SAMPLE_ALAW = new AudioFormat(Encoding.ALAW, // encoding - AudioSystem.NOT_SPECIFIED, // sample rate - sampleSize, // sample size - channelSize, // channels - sampleSize / 8 * channelSize, // frame size - AudioSystem.NOT_SPECIFIED, // frame rate - false, // big endian? - properties); + int sampleSize = 8; + final AudioFormat PA_SAMPLE_ALAW = new AudioFormat(Encoding.ALAW, // encoding + AudioSystem.NOT_SPECIFIED, // sample rate + sampleSize, // sample size + channelSize, // channels + sampleSize / 8 * channelSize, // frame size + AudioSystem.NOT_SPECIFIED, // frame rate + false, // big endian? + properties); - supportedFormats.add(PA_SAMPLE_ALAW); - } + supportedFormats.add(PA_SAMPLE_ALAW); + } - for (int channelSize : channelSizes) { - properties = new HashMap(); - properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_ULAW"); + for (int channelSize : channelSizes) { + properties = new HashMap(); + properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_ULAW"); - int sampleSize = 8; - final AudioFormat PA_SAMPLE_ULAW = new AudioFormat(Encoding.ULAW, // encoding - AudioSystem.NOT_SPECIFIED, // sample rate - sampleSize, // sample size - channelSize, // channels - sampleSize / 8 * channelSize, // frame size - AudioSystem.NOT_SPECIFIED, // frame rate - false, // big endian? - properties); + int sampleSize = 8; + final AudioFormat PA_SAMPLE_ULAW = new AudioFormat(Encoding.ULAW, // encoding + AudioSystem.NOT_SPECIFIED, // sample rate + sampleSize, // sample size + channelSize, // channels + sampleSize / 8 * channelSize, // frame size + AudioSystem.NOT_SPECIFIED, // frame rate + false, // big endian? + properties); - supportedFormats.add(PA_SAMPLE_ULAW); - } + supportedFormats.add(PA_SAMPLE_ULAW); + } - for (int channelSize : channelSizes) { - properties = new HashMap(); - properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_S16BE"); + for (int channelSize : channelSizes) { + properties = new HashMap(); + properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_S16BE"); - int sampleSize = 16; - final AudioFormat PA_SAMPLE_S16BE = new AudioFormat( - Encoding.PCM_SIGNED, // encoding - AudioSystem.NOT_SPECIFIED, // sample rate - sampleSize, // sample size - channelSize, // channels - sampleSize / 8 * channelSize, // frame size - AudioSystem.NOT_SPECIFIED, // frame rate - true, // big endian? - properties); + int sampleSize = 16; + final AudioFormat PA_SAMPLE_S16BE = new AudioFormat( + Encoding.PCM_SIGNED, // encoding + AudioSystem.NOT_SPECIFIED, // sample rate + sampleSize, // sample size + channelSize, // channels + sampleSize / 8 * channelSize, // frame size + AudioSystem.NOT_SPECIFIED, // frame rate + true, // big endian? + properties); - supportedFormats.add(PA_SAMPLE_S16BE); - } + supportedFormats.add(PA_SAMPLE_S16BE); + } - for (int channelSize : channelSizes) { - properties = new HashMap(); - properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_S16LE"); + for (int channelSize : channelSizes) { + properties = new HashMap(); + properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_S16LE"); - int sampleSize = 16; - final AudioFormat A_SAMPLE_S16LE = new AudioFormat( - Encoding.PCM_SIGNED, // encoding - AudioSystem.NOT_SPECIFIED, // sample rate - sampleSize, // sample size - channelSize, // channels - sampleSize / 8 * channelSize, // frame size - AudioSystem.NOT_SPECIFIED, // frame rate - false, // big endian? - properties); + int sampleSize = 16; + final AudioFormat A_SAMPLE_S16LE = new AudioFormat( + Encoding.PCM_SIGNED, // encoding + AudioSystem.NOT_SPECIFIED, // sample rate + sampleSize, // sample size + channelSize, // channels + sampleSize / 8 * channelSize, // frame size + AudioSystem.NOT_SPECIFIED, // frame rate + false, // big endian? + properties); - supportedFormats.add(A_SAMPLE_S16LE); - } + supportedFormats.add(A_SAMPLE_S16LE); + } - for (int channelSize : channelSizes) { - properties = new HashMap(); - properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_S32BE"); + for (int channelSize : channelSizes) { + properties = new HashMap(); + properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_S32BE"); - int sampleSize = 32; - final AudioFormat PA_SAMPLE_S32BE = new AudioFormat( - Encoding.PCM_SIGNED, // encoding - AudioSystem.NOT_SPECIFIED, // sample rate - sampleSize, // sample size - channelSize, // channels - sampleSize / 8 * channelSize, // frame size - AudioSystem.NOT_SPECIFIED, // frame rate - true, // big endian? - properties); + int sampleSize = 32; + final AudioFormat PA_SAMPLE_S32BE = new AudioFormat( + Encoding.PCM_SIGNED, // encoding + AudioSystem.NOT_SPECIFIED, // sample rate + sampleSize, // sample size + channelSize, // channels + sampleSize / 8 * channelSize, // frame size + AudioSystem.NOT_SPECIFIED, // frame rate + true, // big endian? + properties); - supportedFormats.add(PA_SAMPLE_S32BE); - } + supportedFormats.add(PA_SAMPLE_S32BE); + } - for (int channelSize : channelSizes) { - properties = new HashMap(); - properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_S32LE"); + for (int channelSize : channelSizes) { + properties = new HashMap(); + properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_S32LE"); - int sampleSize = 32; - final AudioFormat PA_SAMPLE_S32LE = new AudioFormat( - Encoding.PCM_SIGNED, // encoding - AudioSystem.NOT_SPECIFIED, // sample rate - sampleSize, // sample size - channelSize, // channels - sampleSize / 8 * channelSize, // frame size - AudioSystem.NOT_SPECIFIED, // frame rate - false, // big endian? - properties); + int sampleSize = 32; + final AudioFormat PA_SAMPLE_S32LE = new AudioFormat( + Encoding.PCM_SIGNED, // encoding + AudioSystem.NOT_SPECIFIED, // sample rate + sampleSize, // sample size + channelSize, // channels + sampleSize / 8 * channelSize, // frame size + AudioSystem.NOT_SPECIFIED, // frame rate + false, // big endian? + properties); - supportedFormats.add(PA_SAMPLE_S32LE); - } + supportedFormats.add(PA_SAMPLE_S32LE); + } - for (int channelSize : channelSizes) { - properties = new HashMap(); - properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_U8"); + for (int channelSize : channelSizes) { + properties = new HashMap(); + properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_U8"); - int sampleSize = 8; // in bits - AudioFormat PA_SAMPLE_U8 = new AudioFormat(Encoding.PCM_UNSIGNED, // encoding - AudioSystem.NOT_SPECIFIED, // sample rate - sampleSize, // sample size - channelSize, // channels - sampleSize / 8 * channelSize, // frame size in bytes - AudioSystem.NOT_SPECIFIED, // frame rate - false, // big endian? - properties); + int sampleSize = 8; // in bits + AudioFormat PA_SAMPLE_U8 = new AudioFormat(Encoding.PCM_UNSIGNED, // encoding + AudioSystem.NOT_SPECIFIED, // sample rate + sampleSize, // sample size + channelSize, // channels + sampleSize / 8 * channelSize, // frame size in bytes + AudioSystem.NOT_SPECIFIED, // frame rate + false, // big endian? + properties); - supportedFormats.add(PA_SAMPLE_U8); - } + supportedFormats.add(PA_SAMPLE_U8); + } - return supportedFormats.toArray(new AudioFormat[0]); - } + return supportedFormats.toArray(new AudioFormat[0]); + } - @Override - public Line getLine(Line.Info info) throws LineUnavailableException { + @Override + public Line getLine(Line.Info info) throws LineUnavailableException { - if (!isLineSupported(info)) { - throw new IllegalArgumentException("Line unsupported: " + info); - } + if (!isLineSupported(info)) { + throw new IllegalArgumentException("Line unsupported: " + info); + } - AudioFormat[] formats = null; - AudioFormat defaultFormat = null; + AudioFormat[] formats = null; + AudioFormat defaultFormat = null; - if (DataLine.Info.class.isInstance(info)) { - ArrayList formatList = new ArrayList(); - AudioFormat[] requestedFormats = ((DataLine.Info) info) - .getFormats(); - for (int i = 0; i < requestedFormats.length; i++) { - AudioFormat f1 = requestedFormats[i]; - for (AudioFormat f2 : getSupportedFormats()) { + if (DataLine.Info.class.isInstance(info)) { + ArrayList formatList = new ArrayList(); + AudioFormat[] requestedFormats = ((DataLine.Info) info) + .getFormats(); + for (int i = 0; i < requestedFormats.length; i++) { + AudioFormat f1 = requestedFormats[i]; + for (AudioFormat f2 : getSupportedFormats()) { - if (f1.matches(f2)) { - formatList.add(f2); - defaultFormat = f1; - } - } - } - formats = formatList.toArray(new AudioFormat[0]); + if (f1.matches(f2)) { + formatList.add(f2); + defaultFormat = f1; + } + } + } + formats = formatList.toArray(new AudioFormat[0]); - } else { - formats = getSupportedFormats(); - defaultFormat = new AudioFormat(Encoding.PCM_UNSIGNED, 44100, 8, 2, - 2, AudioSystem.NOT_SPECIFIED, false); - } + } else { + formats = getSupportedFormats(); + defaultFormat = new AudioFormat(Encoding.PCM_UNSIGNED, 44100, 8, 2, + 2, AudioSystem.NOT_SPECIFIED, false); + } - if ((info.getLineClass() == SourceDataLine.class)) { - return new PulseAudioSourceDataLine(formats, defaultFormat); - } + if ((info.getLineClass() == SourceDataLine.class)) { + return new PulseAudioSourceDataLine(formats, defaultFormat); + } - if ((info.getLineClass() == TargetDataLine.class)) { - /* check for permission to record audio */ - AudioPermission perm = new AudioPermission("record", null); - perm.checkGuard(null); + if ((info.getLineClass() == TargetDataLine.class)) { + /* check for permission to record audio */ + AudioPermission perm = new AudioPermission("record", null); + perm.checkGuard(null); - return new PulseAudioTargetDataLine(formats, defaultFormat); - } + return new PulseAudioTargetDataLine(formats, defaultFormat); + } - if ((info.getLineClass() == Clip.class)) { - return new PulseAudioClip(formats, defaultFormat); - } + if ((info.getLineClass() == Clip.class)) { + return new PulseAudioClip(formats, defaultFormat); + } - if (Port.Info.class.isInstance(info)) { - Port.Info portInfo = (Port.Info) info; - if (portInfo.isSource()) { - /* check for permission to record audio */ - AudioPermission perm = new AudioPermission("record", null); - perm.checkGuard(null); + if (Port.Info.class.isInstance(info)) { + Port.Info portInfo = (Port.Info) info; + if (portInfo.isSource()) { + /* check for permission to record audio */ + AudioPermission perm = new AudioPermission("record", null); + perm.checkGuard(null); - return new PulseAudioSourcePort(portInfo.getName()); - } else { - return new PulseAudioTargetPort(portInfo.getName()); - } - } + return new PulseAudioSourcePort(portInfo.getName()); + } else { + return new PulseAudioTargetPort(portInfo.getName()); + } + } - Debug.println(DebugLevel.Info, "PulseAudioMixer.getLine(): " - + "No matching line supported by PulseAudio"); + Debug.println(DebugLevel.Info, "PulseAudioMixer.getLine(): " + + "No matching line supported by PulseAudio"); - throw new IllegalArgumentException("No matching lines found"); + throw new IllegalArgumentException("No matching lines found"); - } + } - @Override - public int getMaxLines(Line.Info info) { - /* - * PulseAudio supports (theoretically) unlimited number of streams for - * supported formats - */ - if (isLineSupported(info)) { - return AudioSystem.NOT_SPECIFIED; - } + @Override + public int getMaxLines(Line.Info info) { + /* + * PulseAudio supports (theoretically) unlimited number of streams for + * supported formats + */ + if (isLineSupported(info)) { + return AudioSystem.NOT_SPECIFIED; + } - return 0; - } + return 0; + } - @Override - public Info getMixerInfo() { - return PulseAudioMixerInfo.getInfo(); - } + @Override + public Info getMixerInfo() { + return PulseAudioMixerInfo.getInfo(); + } - public Line.Info[] getSourceLineInfo() { - return sourceLineInfos.toArray(new Line.Info[0]); - } + public Line.Info[] getSourceLineInfo() { + return sourceLineInfos.toArray(new Line.Info[0]); + } - @Override - public Line.Info[] getSourceLineInfo(Line.Info info) { - ArrayList infos = new ArrayList(); + @Override + public Line.Info[] getSourceLineInfo(Line.Info info) { + ArrayList infos = new ArrayList(); - for (Line.Info supportedInfo : sourceLineInfos) { - if (info.matches(supportedInfo)) { - infos.add(supportedInfo); - } - } - return infos.toArray(new Line.Info[0]); - } + for (Line.Info supportedInfo : sourceLineInfos) { + if (info.matches(supportedInfo)) { + infos.add(supportedInfo); + } + } + return infos.toArray(new Line.Info[0]); + } - @Override - public Line[] getSourceLines() { - return sourceLines.toArray(new Line[0]); + @Override + public Line[] getSourceLines() { + return sourceLines.toArray(new Line[0]); - } + } - @Override - public Line.Info[] getTargetLineInfo() { - return targetLineInfos.toArray(new Line.Info[0]); - } + @Override + public Line.Info[] getTargetLineInfo() { + return targetLineInfos.toArray(new Line.Info[0]); + } - @Override - public Line.Info[] getTargetLineInfo(Line.Info info) { - ArrayList infos = new ArrayList(); + @Override + public Line.Info[] getTargetLineInfo(Line.Info info) { + ArrayList infos = new ArrayList(); - for (Line.Info supportedInfo : targetLineInfos) { - if (info.matches(supportedInfo)) { - infos.add(supportedInfo); - } - } - return infos.toArray(new Line.Info[0]); - } + for (Line.Info supportedInfo : targetLineInfos) { + if (info.matches(supportedInfo)) { + infos.add(supportedInfo); + } + } + return infos.toArray(new Line.Info[0]); + } - @Override - public Line[] getTargetLines() { + @Override + public Line[] getTargetLines() { - /* check for permission to record audio */ - AudioPermission perm = new AudioPermission("record", null); - perm.checkGuard(null); + /* check for permission to record audio */ + AudioPermission perm = new AudioPermission("record", null); + perm.checkGuard(null); - return (Line[]) targetLines.toArray(new Line[0]); - } + return (Line[]) targetLines.toArray(new Line[0]); + } - @Override - public boolean isLineSupported(Line.Info info) { - if (info != null) { - for (Line.Info myInfo : sourceLineInfos) { - if (info.matches(myInfo)) { - return true; - } - } + @Override + public boolean isLineSupported(Line.Info info) { + if (info != null) { + for (Line.Info myInfo : sourceLineInfos) { + if (info.matches(myInfo)) { + return true; + } + } - for (Line.Info myInfo : targetLineInfos) { - if (info.matches(myInfo)) { - return true; - } - } + for (Line.Info myInfo : targetLineInfos) { + if (info.matches(myInfo)) { + return true; + } + } - } - return false; + } + return false; - } + } - @Override - public boolean isSynchronizationSupported(Line[] lines, boolean maintainSync) { + @Override + public boolean isSynchronizationSupported(Line[] lines, boolean maintainSync) { - return false; - } + return false; + } - @Override - public void synchronize(Line[] lines, boolean maintainSync) { + @Override + public void synchronize(Line[] lines, boolean maintainSync) { - throw new IllegalArgumentException( - "Mixer does not support synchronizing lines"); + throw new IllegalArgumentException( + "Mixer does not support synchronizing lines"); - // Line masterStream = null; - // for (Line line : lines) { - // if (line.isOpen()) { - // masterStream = line; - // break; - // } - // } - // if (masterStream == null) { - // // for now, can't synchronize lines if none of them is open (no - // // stream pointer to pass) - // // will see what to do about this later - // throw new IllegalArgumentException(); - // } - // - // try { - // - // for (Line line : lines) { - // if (line != masterStream) { - // - // ((PulseAudioDataLine) line) - // .reconnectforSynchronization(((PulseAudioDataLine) masterStream) - // .getStream()); - // - // } - // } - // } catch (LineUnavailableException e) { - // // we couldn't reconnect, so tell the user we failed by throwing an - // // exception - // throw new IllegalArgumentException(e); - // } + // Line masterStream = null; + // for (Line line : lines) { + // if (line.isOpen()) { + // masterStream = line; + // break; + // } + // } + // if (masterStream == null) { + // // for now, can't synchronize lines if none of them is open (no + // // stream pointer to pass) + // // will see what to do about this later + // throw new IllegalArgumentException(); + // } + // + // try { + // + // for (Line line : lines) { + // if (line != masterStream) { + // + // ((PulseAudioDataLine) line) + // .reconnectforSynchronization(((PulseAudioDataLine) masterStream) + // .getStream()); + // + // } + // } + // } catch (LineUnavailableException e) { + // // we couldn't reconnect, so tell the user we failed by throwing an + // // exception + // throw new IllegalArgumentException(e); + // } - } + } - @Override - public void unsynchronize(Line[] lines) { - // FIXME should be able to implement this - throw new IllegalArgumentException(); - } + @Override + public void unsynchronize(Line[] lines) { + // FIXME should be able to implement this + throw new IllegalArgumentException(); + } - @Override - public void addLineListener(LineListener listener) { - lineListeners.add(listener); - } + @Override + public void addLineListener(LineListener listener) { + lineListeners.add(listener); + } - @Override - synchronized public void close() { + @Override + synchronized public void close() { - /* - * only allow the mixer to be controlled if either playback or recording - * is allowed - */ + /* + * only allow the mixer to be controlled if either playback or recording + * is allowed + */ - if (!this.isOpen) { - throw new IllegalStateException("Mixer is not open; cant close"); - } + if (!this.isOpen) { + throw new IllegalStateException("Mixer is not open; cant close"); + } - List linesToClose = new LinkedList(); - linesToClose.addAll(sourceLines); - if (sourceLines.size() > 0) { + List linesToClose = new LinkedList(); + linesToClose.addAll(sourceLines); + if (sourceLines.size() > 0) { - Debug.println(DebugLevel.Warning, "PulseAudioMixer.close(): " - + linesToClose.size() - + " source lines were not closed. closing them now."); + Debug.println(DebugLevel.Warning, "PulseAudioMixer.close(): " + + linesToClose.size() + + " source lines were not closed. closing them now."); - linesToClose.addAll(sourceLines); - for (Line line : linesToClose) { - if (line.isOpen()) { - line.close(); - } - } - } - linesToClose.clear(); + linesToClose.addAll(sourceLines); + for (Line line : linesToClose) { + if (line.isOpen()) { + line.close(); + } + } + } + linesToClose.clear(); - if (targetLines.size() > 0) { - Debug.println(DebugLevel.Warning, "PulseAudioMixer.close(): " - + linesToClose.size() - + " target lines have not been closed"); + if (targetLines.size() > 0) { + Debug.println(DebugLevel.Warning, "PulseAudioMixer.close(): " + + linesToClose.size() + + " target lines have not been closed"); - linesToClose.addAll(targetLines); - for (Line line : linesToClose) { - if (line.isOpen()) { - line.close(); - } - } - } + linesToClose.addAll(targetLines); + for (Line line : linesToClose) { + if (line.isOpen()) { + line.close(); + } + } + } - synchronized (lineListeners) { - lineListeners.clear(); - } + synchronized (lineListeners) { + lineListeners.clear(); + } - eventLoopThread.interrupt(); + eventLoopThread.interrupt(); - try { - eventLoopThread.join(); - } catch (InterruptedException e) { - System.out.println(this.getClass().getName() - + ": interrupted while waiting for eventloop to finish"); - } + try { + eventLoopThread.join(); + } catch (InterruptedException e) { + System.out.println(this.getClass().getName() + + ": interrupted while waiting for eventloop to finish"); + } - isOpen = false; + isOpen = false; - refreshSourceAndTargetLines(); + refreshSourceAndTargetLines(); - Debug.println(DebugLevel.Verbose, "PulseAudioMixer.close(): " - + "Mixer closed"); + Debug.println(DebugLevel.Verbose, "PulseAudioMixer.close(): " + + "Mixer closed"); - } + } - @Override - public Control getControl(Type control) { - // mixer supports no controls - throw new IllegalArgumentException(); - } + @Override + public Control getControl(Type control) { + // mixer supports no controls + throw new IllegalArgumentException(); + } - @Override - public Control[] getControls() { - // mixer supports no controls; return an array of length 0 - return new Control[] {}; - } + @Override + public Control[] getControls() { + // mixer supports no controls; return an array of length 0 + return new Control[] {}; + } - @Override - public javax.sound.sampled.Line.Info getLineInfo() { - // System.out.println("DEBUG: PulseAudioMixer.getLineInfo() called"); - return new Line.Info(PulseAudioMixer.class); - } + @Override + public javax.sound.sampled.Line.Info getLineInfo() { + // System.out.println("DEBUG: PulseAudioMixer.getLineInfo() called"); + return new Line.Info(PulseAudioMixer.class); + } - @Override - public boolean isControlSupported(Type control) { - // mixer supports no controls - return false; - } + @Override + public boolean isControlSupported(Type control) { + // mixer supports no controls + return false; + } - @Override - public boolean isOpen() { - return isOpen; - } + @Override + public boolean isOpen() { + return isOpen; + } - @Override - public void open() throws LineUnavailableException { - openLocal(); + @Override + public void open() throws LineUnavailableException { + openLocal(); - } + } - public void openLocal() throws LineUnavailableException { - openLocal(DEFAULT_APP_NAME); - } + public void openLocal() throws LineUnavailableException { + openLocal(DEFAULT_APP_NAME); + } - public void openLocal(String appName) throws LineUnavailableException { - openImpl(appName, null); - } + public void openLocal(String appName) throws LineUnavailableException { + openImpl(appName, null); + } - public void openRemote(String appName, String host) - throws UnknownHostException, LineUnavailableException { - if (host == null) { - throw new NullPointerException("hostname"); - } - - final int PULSEAUDIO_DEFAULT_PORT = 4713; - - /* - * If trying to connect to a remote machine, check for permissions - */ - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkConnect(host,PULSEAUDIO_DEFAULT_PORT ); - } - - openImpl(appName, host); - } + public void openRemote(String appName, String host) + throws UnknownHostException, LineUnavailableException { + if (host == null) { + throw new NullPointerException("hostname"); + } + + final int PULSEAUDIO_DEFAULT_PORT = 4713; + + /* + * If trying to connect to a remote machine, check for permissions + */ + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkConnect(host,PULSEAUDIO_DEFAULT_PORT ); + } + + openImpl(appName, host); + } - public void openRemote(String appName, String host, int port) - throws UnknownHostException, LineUnavailableException { + public void openRemote(String appName, String host, int port) + throws UnknownHostException, LineUnavailableException { - if ((port < 1) && (port != -1)) { - throw new IllegalArgumentException("Invalid value for port"); - } + if ((port < 1) && (port != -1)) { + throw new IllegalArgumentException("Invalid value for port"); + } - if (host == null) { - throw new NullPointerException("hostname"); - } + if (host == null) { + throw new NullPointerException("hostname"); + } - /* - * If trying to connect to a remote machine, check for permissions - */ - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkConnect(host, port); - } + /* + * If trying to connect to a remote machine, check for permissions + */ + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkConnect(host, port); + } - InetAddress addr = InetAddress.getAllByName(host)[0]; + InetAddress addr = InetAddress.getAllByName(host)[0]; - host = addr.getHostAddress(); - host = host + ":" + String.valueOf(port); + host = addr.getHostAddress(); + host = host + ":" + String.valueOf(port); - openImpl(appName, host); - - } + openImpl(appName, host); + + } - /* - * - * @param appName name of the application - * - * @param hostAndIp a string consisting of the host and ip address of the - * server to connect to. Format: ":". Set to null to indicate a - * local connection - */ - synchronized private void openImpl(String appName, String hostAndIp) - throws LineUnavailableException { + /* + * + * @param appName name of the application + * + * @param hostAndIp a string consisting of the host and ip address of the + * server to connect to. Format: ":". Set to null to indicate a + * local connection + */ + synchronized private void openImpl(String appName, String hostAndIp) + throws LineUnavailableException { - if (isOpen) { - throw new IllegalStateException("Mixer is already open"); - } + if (isOpen) { + throw new IllegalStateException("Mixer is already open"); + } - EventLoop eventLoop; - eventLoop = EventLoop.getEventLoop(); - eventLoop.setAppName(appName); - eventLoop.setServer(hostAndIp); + EventLoop eventLoop; + eventLoop = EventLoop.getEventLoop(); + eventLoop.setAppName(appName); + eventLoop.setServer(hostAndIp); - ContextListener generalEventListener = new ContextListener() { - @Override - public void update(ContextEvent e) { - if (e.getType() == ContextEvent.Type.READY) { - fireEvent(new LineEvent(PulseAudioMixer.this, - LineEvent.Type.OPEN, AudioSystem.NOT_SPECIFIED)); - } else if (e.getType() == ContextEvent.Type.FAILED - || e.getType() == ContextEvent.Type.TERMINATED) { - fireEvent(new LineEvent(PulseAudioMixer.this, - LineEvent.Type.CLOSE, AudioSystem.NOT_SPECIFIED)); - } - } - }; + ContextListener generalEventListener = new ContextListener() { + @Override + public void update(ContextEvent e) { + if (e.getType() == ContextEvent.Type.READY) { + fireEvent(new LineEvent(PulseAudioMixer.this, + LineEvent.Type.OPEN, AudioSystem.NOT_SPECIFIED)); + } else if (e.getType() == ContextEvent.Type.FAILED + || e.getType() == ContextEvent.Type.TERMINATED) { + fireEvent(new LineEvent(PulseAudioMixer.this, + LineEvent.Type.CLOSE, AudioSystem.NOT_SPECIFIED)); + } + } + }; - eventLoop.addContextListener(generalEventListener); + eventLoop.addContextListener(generalEventListener); - final Semaphore ready = new Semaphore(0); + final Semaphore ready = new Semaphore(0); - ContextListener initListener = new ContextListener() { + ContextListener initListener = new ContextListener() { - @Override - public void update(ContextEvent e) { - if (e.getType() == ContextEvent.Type.READY - || e.getType() == ContextEvent.Type.FAILED - || e.getType() == ContextEvent.Type.TERMINATED) { - ready.release(); - } - } + @Override + public void update(ContextEvent e) { + if (e.getType() == ContextEvent.Type.READY + || e.getType() == ContextEvent.Type.FAILED + || e.getType() == ContextEvent.Type.TERMINATED) { + ready.release(); + } + } - }; + }; - eventLoop.addContextListener(initListener); + eventLoop.addContextListener(initListener); - eventLoopThread = new Thread(eventLoop, "PulseAudio Eventloop Thread"); + eventLoopThread = new Thread(eventLoop, "PulseAudio Eventloop Thread"); - /* - * Make the thread exit if by some weird error it is the only thread - * running. The application should be able to exit if the main thread - * doesn't or can't (perhaps an assert?) do a mixer.close(). - */ - eventLoopThread.setDaemon(true); - eventLoopThread.start(); + /* + * Make the thread exit if by some weird error it is the only thread + * running. The application should be able to exit if the main thread + * doesn't or can't (perhaps an assert?) do a mixer.close(). + */ + eventLoopThread.setDaemon(true); + eventLoopThread.start(); - try { - // System.out.println("waiting..."); - ready.acquire(); - if (eventLoop.getStatus() != 4) { - /* - * when exiting, wait for the thread to end otherwise we get one - * thread that inits the singleton with new data and the old - * thread then cleans up the singleton asserts fail all over the - * place - */ - eventLoop.removeContextListener(initListener); - eventLoopThread.interrupt(); - eventLoopThread.join(); - throw new LineUnavailableException(); - } - eventLoop.removeContextListener(initListener); - // System.out.println("got signal"); - } catch (InterruptedException e) { - System.out - .println("PulseAudioMixer: got interrupted while waiting for the EventLoop to initialize"); - } + try { + // System.out.println("waiting..."); + ready.acquire(); + if (eventLoop.getStatus() != 4) { + /* + * when exiting, wait for the thread to end otherwise we get one + * thread that inits the singleton with new data and the old + * thread then cleans up the singleton asserts fail all over the + * place + */ + eventLoop.removeContextListener(initListener); + eventLoopThread.interrupt(); + eventLoopThread.join(); + throw new LineUnavailableException(); + } + eventLoop.removeContextListener(initListener); + // System.out.println("got signal"); + } catch (InterruptedException e) { + System.out + .println("PulseAudioMixer: got interrupted while waiting for the EventLoop to initialize"); + } - // System.out.println(this.getClass().getName() + ": ready"); + // System.out.println(this.getClass().getName() + ": ready"); - this.isOpen = true; + this.isOpen = true; - // sourceLineInfo and targetLineInfo need to be updated with - // port infos, which can only be obtained after EventLoop had started + // sourceLineInfo and targetLineInfo need to be updated with + // port infos, which can only be obtained after EventLoop had started - refreshSourceAndTargetLines(); + refreshSourceAndTargetLines(); - for (String portName : eventLoop.updateSourcePortNameList()) { - sourceLineInfos.add(new Port.Info(Port.class, portName, true)); - } + for (String portName : eventLoop.updateSourcePortNameList()) { + sourceLineInfos.add(new Port.Info(Port.class, portName, true)); + } - for (String portName : eventLoop.updateTargetPortNameList()) { - targetLineInfos.add(new Port.Info(Port.class, portName, false)); - } + for (String portName : eventLoop.updateTargetPortNameList()) { + targetLineInfos.add(new Port.Info(Port.class, portName, false)); + } - Debug.println(DebugLevel.Debug, "PulseAudioMixer.open(): " - + "Mixer opened"); + Debug.println(DebugLevel.Debug, "PulseAudioMixer.open(): " + + "Mixer opened"); - } + } - @Override - public void removeLineListener(LineListener listener) { - lineListeners.remove(listener); - } + @Override + public void removeLineListener(LineListener listener) { + lineListeners.remove(listener); + } - /* - * Should this method be synchronized? I had a few reasons, but i forgot - * them Pros: - Thread safety? - * - * Cons: - eventListeners are run from other threads, if those then call - * fireEvent while a method is waiting on a listener, this synchronized - * block wont be entered: deadlock! - */ - private void fireEvent(final LineEvent e) { - synchronized (lineListeners) { - for (LineListener lineListener : lineListeners) { - lineListener.update(e); - } - } - } + /* + * Should this method be synchronized? I had a few reasons, but i forgot + * them Pros: - Thread safety? + * + * Cons: - eventListeners are run from other threads, if those then call + * fireEvent while a method is waiting on a listener, this synchronized + * block wont be entered: deadlock! + */ + private void fireEvent(final LineEvent e) { + synchronized (lineListeners) { + for (LineListener lineListener : lineListeners) { + lineListener.update(e); + } + } + } - void addSourceLine(PulseAudioLine line) { - sourceLines.add(line); - } + void addSourceLine(PulseAudioLine line) { + sourceLines.add(line); + } - void removeSourceLine(PulseAudioLine line) { - sourceLines.remove(line); - } + void removeSourceLine(PulseAudioLine line) { + sourceLines.remove(line); + } - void addTargetLine(PulseAudioLine line) { - targetLines.add(line); - } + void addTargetLine(PulseAudioLine line) { + targetLines.add(line); + } - void removeTargetLine(PulseAudioLine line) { - targetLines.remove(line); - } + void removeTargetLine(PulseAudioLine line) { + targetLines.remove(line); + } - void refreshSourceAndTargetLines() { + void refreshSourceAndTargetLines() { - sourceLineInfos.clear(); - targetLineInfos.clear(); + sourceLineInfos.clear(); + targetLineInfos.clear(); - sourceLineInfos.addAll(staticSourceLineInfos); + sourceLineInfos.addAll(staticSourceLineInfos); - targetLineInfos.addAll(staticTargetLineInfos); + targetLineInfos.addAll(staticTargetLineInfos); - } + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixerInfo.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixerInfo.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixerInfo.java Fri Jun 10 17:42:18 2011 -0400 @@ -40,23 +40,23 @@ import javax.sound.sampled.Mixer; public final class PulseAudioMixerInfo extends Mixer.Info { - // singleton + // singleton - private static PulseAudioMixerInfo _instance = null; + private static PulseAudioMixerInfo _instance = null; - protected PulseAudioMixerInfo(String name, String vendor, - String description, String version) { - super(name, vendor, description, version); - } + protected PulseAudioMixerInfo(String name, String vendor, + String description, String version) { + super(name, vendor, description, version); + } - // the "getInstance()" method - synchronized public static PulseAudioMixerInfo getInfo() { - if (_instance == null) { - _instance = new PulseAudioMixerInfo("PulseAudio Mixer", "IcedTea", - "the ear-candy mixer", "0.02"); - } + // the "getInstance()" method + synchronized public static PulseAudioMixerInfo getInfo() { + if (_instance == null) { + _instance = new PulseAudioMixerInfo("PulseAudio Mixer", "IcedTea", + "the ear-candy mixer", "0.02"); + } - return _instance; - } + return _instance; + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixerProvider.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixerProvider.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixerProvider.java Fri Jun 10 17:42:18 2011 -0400 @@ -41,23 +41,23 @@ import javax.sound.sampled.Mixer.Info; public class PulseAudioMixerProvider extends - javax.sound.sampled.spi.MixerProvider { + javax.sound.sampled.spi.MixerProvider { - @Override - public Mixer getMixer(Info info) { - // System.out.println("DEBUG: getMixer called"); - if (info.equals(PulseAudioMixerInfo.getInfo())) { - return PulseAudioMixer.getInstance(); - } else { - throw new IllegalArgumentException("Mixer type not supported"); - } - } + @Override + public Mixer getMixer(Info info) { + // System.out.println("DEBUG: getMixer called"); + if (info.equals(PulseAudioMixerInfo.getInfo())) { + return PulseAudioMixer.getInstance(); + } else { + throw new IllegalArgumentException("Mixer type not supported"); + } + } - @Override - public Info[] getMixerInfo() { - // System.out.println("DEBUG: get mixer info called"); - Mixer.Info[] m = { PulseAudioMixerInfo.getInfo() }; - return m; - } + @Override + public Info[] getMixerInfo() { + // System.out.println("DEBUG: get mixer info called"); + Mixer.Info[] m = { PulseAudioMixerInfo.getInfo() }; + return m; + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPlaybackLine.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPlaybackLine.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPlaybackLine.java Fri Jun 10 17:42:18 2011 -0400 @@ -42,44 +42,44 @@ */ interface PulseAudioPlaybackLine { - /** - * Set the volume of the Line (ie, sink input, source, or sink) - * - * @return an Operation object which can be used to check if the operation - * has completed - */ - byte[] native_set_volume(float value); + /** + * Set the volume of the Line (ie, sink input, source, or sink) + * + * @return an Operation object which can be used to check if the operation + * has completed + */ + byte[] native_set_volume(float value); - /** - * - * Update the volume information of a Line (sink input, source or sink) - * - * @return an Operation object which can be used to check if the operation - * has been completed - */ - byte[] native_update_volume(); - - - /** - * Gets the cached volume. To get the current volume, call - * native_update_volume, and then call this method to get the updated - * volume. - * - * @return the cached volume of the Line - */ - float getCachedVolume(); + /** + * + * Update the volume information of a Line (sink input, source or sink) + * + * @return an Operation object which can be used to check if the operation + * has been completed + */ + byte[] native_update_volume(); + + + /** + * Gets the cached volume. To get the current volume, call + * native_update_volume, and then call this method to get the updated + * volume. + * + * @return the cached volume of the Line + */ + float getCachedVolume(); - /** - * Set the cached value of a line - * - */ - void setCachedVolume(float volume); + /** + * Set the cached value of a line + * + */ + void setCachedVolume(float volume); - /** - * Check if a line is open - * - * @return true if line is open - */ - boolean isOpen(); + /** + * Check if a line is open + * + * @return true if line is open + */ + boolean isOpen(); } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java Fri Jun 10 17:42:18 2011 -0400 @@ -43,119 +43,119 @@ import javax.sound.sampled.Port; abstract class PulseAudioPort extends PulseAudioLine implements Port, - PulseAudioPlaybackLine { + PulseAudioPlaybackLine { - private String name; + private String name; - /* - * Variable used in native code - */ - @SuppressWarnings("unused") - private byte[] contextPointer; - @SuppressWarnings("unused") - private int channels; + /* + * Variable used in native code + */ + @SuppressWarnings("unused") + private byte[] contextPointer; + @SuppressWarnings("unused") + private int channels; - private EventLoop eventLoop; + private EventLoop eventLoop; - private float cachedVolume; + private float cachedVolume; - private PulseAudioVolumeControl volumeControl; + private PulseAudioVolumeControl volumeControl; - static { - SecurityWrapper.loadNativeLibrary(); - } + static { + SecurityWrapper.loadNativeLibrary(); + } - PulseAudioPort(String portName) { - this.name = portName; - this.eventLoop = EventLoop.getEventLoop(); - this.contextPointer = eventLoop.getContextPointer(); + PulseAudioPort(String portName) { + this.name = portName; + this.eventLoop = EventLoop.getEventLoop(); + this.contextPointer = eventLoop.getContextPointer(); - updateVolumeInfo(); + updateVolumeInfo(); - volumeControl = new PulseAudioVolumeControl(this, eventLoop); - controls.add(volumeControl); + volumeControl = new PulseAudioVolumeControl(this, eventLoop); + controls.add(volumeControl); - /* - * unlike other lines, Ports must either be open or close - * - * close = no sound. open = sound - */ - open(); + /* + * unlike other lines, Ports must either be open or close + * + * close = no sound. open = sound + */ + open(); - // System.out.println("Opened Target Port " + name); - } + // System.out.println("Opened Target Port " + name); + } - // FIXME why public - @Override - public abstract byte[] native_set_volume(float newValue); + // FIXME why public + @Override + public abstract byte[] native_set_volume(float newValue); - /** - * - * @see {@link update_channels_and_volume} - */ - // FIXME why public - public abstract byte[] native_update_volume(); + /** + * + * @see {@link update_channels_and_volume} + */ + // FIXME why public + public abstract byte[] native_update_volume(); - @Override - public float getCachedVolume() { - return this.cachedVolume; - } + @Override + public float getCachedVolume() { + return this.cachedVolume; + } - @Override - public void setCachedVolume(float value) { - this.cachedVolume = value; + @Override + public void setCachedVolume(float value) { + this.cachedVolume = value; - } + } - private void updateVolumeInfo() { - Operation op; - synchronized (eventLoop.threadLock) { - op = new Operation(native_update_volume()); - } + private void updateVolumeInfo() { + Operation op; + synchronized (eventLoop.threadLock) { + op = new Operation(native_update_volume()); + } - op.waitForCompletion(); - op.releaseReference(); - } + op.waitForCompletion(); + op.releaseReference(); + } - /** - * Callback used by JNI when native_update_volume completes - * - * @param channels - * the number of channels - * @param cachedVolume - * the new volume - */ - @SuppressWarnings("unused") - void update_channels_and_volume(int channels, float volume) { - this.channels = channels; - this.cachedVolume = volume; - } + /** + * Callback used by JNI when native_update_volume completes + * + * @param channels + * the number of channels + * @param cachedVolume + * the new volume + */ + @SuppressWarnings("unused") + void update_channels_and_volume(int channels, float volume) { + this.channels = channels; + this.cachedVolume = volume; + } - @Override - public void close() { + @Override + public void close() { - native_set_volume((float) 0); - isOpen = false; - fireLineEvent(new LineEvent(this, LineEvent.Type.CLOSE, - AudioSystem.NOT_SPECIFIED)); - } + native_set_volume((float) 0); + isOpen = false; + fireLineEvent(new LineEvent(this, LineEvent.Type.CLOSE, + AudioSystem.NOT_SPECIFIED)); + } - @Override - public abstract Line.Info getLineInfo(); + @Override + public abstract Line.Info getLineInfo(); - @Override - public void open() { - if (isOpen) { - return; - } - native_set_volume(cachedVolume); - isOpen = true; - fireLineEvent(new LineEvent(this, LineEvent.Type.OPEN, - AudioSystem.NOT_SPECIFIED)); - } + @Override + public void open() { + if (isOpen) { + return; + } + native_set_volume(cachedVolume); + isOpen = true; + fireLineEvent(new LineEvent(this, LineEvent.Type.OPEN, + AudioSystem.NOT_SPECIFIED)); + } - public String getName() { - return this.name; - } + public String getName() { + return this.name; + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Fri Jun 10 17:42:18 2011 -0400 @@ -49,294 +49,294 @@ import org.classpath.icedtea.pulseaudio.Debug.DebugLevel; public final class PulseAudioSourceDataLine extends PulseAudioDataLine - implements SourceDataLine, PulseAudioPlaybackLine { + implements SourceDataLine, PulseAudioPlaybackLine { - private PulseAudioVolumeControl volumeControl; + private PulseAudioVolumeControl volumeControl; - public static final String DEFAULT_SOURCEDATALINE_NAME = "Audio Stream"; + public static final String DEFAULT_SOURCEDATALINE_NAME = "Audio Stream"; - /* - * Package-private constructor only called by PulseAudioMixer - */ - PulseAudioSourceDataLine(AudioFormat[] formats, AudioFormat defaultFormat) { + /* + * Package-private constructor only called by PulseAudioMixer + */ + PulseAudioSourceDataLine(AudioFormat[] formats, AudioFormat defaultFormat) { - this.supportedFormats = formats; - this.lineListeners = new ArrayList(); - this.defaultFormat = defaultFormat; - this.currentFormat = defaultFormat; - this.streamName = DEFAULT_SOURCEDATALINE_NAME; + this.supportedFormats = formats; + this.lineListeners = new ArrayList(); + this.defaultFormat = defaultFormat; + this.currentFormat = defaultFormat; + this.streamName = DEFAULT_SOURCEDATALINE_NAME; - } + } - @Override - synchronized public void open(AudioFormat format, int bufferSize) - throws LineUnavailableException { + @Override + synchronized public void open(AudioFormat format, int bufferSize) + throws LineUnavailableException { - super.open(format, bufferSize); + super.open(format, bufferSize); - volumeControl = new PulseAudioVolumeControl(this, eventLoop); - controls.add(volumeControl); + volumeControl = new PulseAudioVolumeControl(this, eventLoop); + controls.add(volumeControl); - PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); - parentMixer.addSourceLine(this); + PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); + parentMixer.addSourceLine(this); - Debug.println(DebugLevel.Verbose, "PulseAudioSourceDataLine.open(): " - + "line opened"); + Debug.println(DebugLevel.Verbose, "PulseAudioSourceDataLine.open(): " + + "line opened"); - } + } - @Override - public void open(AudioFormat format) throws LineUnavailableException { - open(format, DEFAULT_BUFFER_SIZE); - } + @Override + public void open(AudioFormat format) throws LineUnavailableException { + open(format, DEFAULT_BUFFER_SIZE); + } - // FIXME - public byte[] native_set_volume(float value) { - synchronized (eventLoop.threadLock) { - return stream.native_set_volume(value); - } - } + // FIXME + public byte[] native_set_volume(float value) { + synchronized (eventLoop.threadLock) { + return stream.native_set_volume(value); + } + } - public byte[] native_update_volume() { - synchronized (eventLoop.threadLock) { - return stream.native_update_volume(); - } - } - - @Override - public float getCachedVolume() { - return stream.getCachedVolume(); - } + public byte[] native_update_volume() { + synchronized (eventLoop.threadLock) { + return stream.native_update_volume(); + } + } + + @Override + public float getCachedVolume() { + return stream.getCachedVolume(); + } - @Override - synchronized public void setCachedVolume(float value) { - stream.setCachedVolume(value); - } + @Override + synchronized public void setCachedVolume(float value) { + stream.setCachedVolume(value); + } - @Override - protected void connectLine(int bufferSize, Stream masterStream) - throws LineUnavailableException { - StreamBufferAttributes bufferAttributes = new StreamBufferAttributes( + @Override + protected void connectLine(int bufferSize, Stream masterStream) + throws LineUnavailableException { + StreamBufferAttributes bufferAttributes = new StreamBufferAttributes( - bufferSize, bufferSize / 4, bufferSize / 8, - ((bufferSize / 10) > 100 ? bufferSize / 10 : 100), 0); + bufferSize, bufferSize / 4, bufferSize / 8, + ((bufferSize / 10) > 100 ? bufferSize / 10 : 100), 0); - if (masterStream != null) { - synchronized (eventLoop.threadLock) { - stream.connectForPlayback(Stream.DEFAULT_DEVICE, - bufferAttributes, masterStream.getStreamPointer()); - } - } else { - synchronized (eventLoop.threadLock) { - stream.connectForPlayback(Stream.DEFAULT_DEVICE, - bufferAttributes, null); - } - } - } + if (masterStream != null) { + synchronized (eventLoop.threadLock) { + stream.connectForPlayback(Stream.DEFAULT_DEVICE, + bufferAttributes, masterStream.getStreamPointer()); + } + } else { + synchronized (eventLoop.threadLock) { + stream.connectForPlayback(Stream.DEFAULT_DEVICE, + bufferAttributes, null); + } + } + } - @Override - public int write(byte[] data, int offset, int length) { - // can't call write() without open()ing first, but can call write() - // without start()ing - synchronized (this) { - writeInterrupted = false; - } + @Override + public int write(byte[] data, int offset, int length) { + // can't call write() without open()ing first, but can call write() + // without start()ing + synchronized (this) { + writeInterrupted = false; + } - if (!isOpen()) { - // A closed line can write exactly 0 bytes. - return 0; - } + if (!isOpen()) { + // A closed line can write exactly 0 bytes. + return 0; + } - int frameSize = currentFormat.getFrameSize(); - if (length % frameSize != 0) { - throw new IllegalArgumentException( - "amount of data to write does not represent an integral number of frames"); - } - - if (length < 0) { - throw new IllegalArgumentException("length is negative"); - } - - if (length < 0 || offset < 0 || offset > data.length - length) { - throw new ArrayIndexOutOfBoundsException( - "Overflow condition: buffer.length=" + data.length + - " offset= " + offset + " length=" + length ); - } + int frameSize = currentFormat.getFrameSize(); + if (length % frameSize != 0) { + throw new IllegalArgumentException( + "amount of data to write does not represent an integral number of frames"); + } + + if (length < 0) { + throw new IllegalArgumentException("length is negative"); + } + + if (length < 0 || offset < 0 || offset > data.length - length) { + throw new ArrayIndexOutOfBoundsException( + "Overflow condition: buffer.length=" + data.length + + " offset= " + offset + " length=" + length ); + } - int position = offset; - int remainingLength = length; - int availableSize = 0; + int position = offset; + int remainingLength = length; + int availableSize = 0; - int sizeWritten = 0; + int sizeWritten = 0; - boolean interrupted = false; + boolean interrupted = false; - while (remainingLength != 0) { + while (remainingLength != 0) { - synchronized (eventLoop.threadLock) { + synchronized (eventLoop.threadLock) { - do { - if (writeInterrupted) { - return sizeWritten; - } + do { + if (writeInterrupted) { + return sizeWritten; + } - if (availableSize == -1) { - return sizeWritten; - } - availableSize = stream.getWritableSize(); + if (availableSize == -1) { + return sizeWritten; + } + availableSize = stream.getWritableSize(); - if (availableSize == 0) { - try { - eventLoop.threadLock.wait(100); - } catch (InterruptedException e) { - // ignore for now - interrupted = true; - } + if (availableSize == 0) { + try { + eventLoop.threadLock.wait(100); + } catch (InterruptedException e) { + // ignore for now + interrupted = true; + } - } + } - } while (availableSize == 0); + } while (availableSize == 0); - if (availableSize > remainingLength) { - availableSize = remainingLength; - } + if (availableSize > remainingLength) { + availableSize = remainingLength; + } - // only write entire frames, so round down avialableSize to - // a multiple of frameSize - availableSize = (availableSize / frameSize) * frameSize; + // only write entire frames, so round down avialableSize to + // a multiple of frameSize + availableSize = (availableSize / frameSize) * frameSize; - synchronized (this) { - if (writeInterrupted) { - return sizeWritten; - } - /* write a little bit of the buffer */ - stream.write(data, position, availableSize); - } + synchronized (this) { + if (writeInterrupted) { + return sizeWritten; + } + /* write a little bit of the buffer */ + stream.write(data, position, availableSize); + } - sizeWritten += availableSize; - position += availableSize; - remainingLength -= availableSize; + sizeWritten += availableSize; + position += availableSize; + remainingLength -= availableSize; - framesSinceOpen += availableSize / frameSize; + framesSinceOpen += availableSize / frameSize; - } - } + } + } - // all the data should have been played by now - assert (sizeWritten == length); + // all the data should have been played by now + assert (sizeWritten == length); - if (interrupted) { - Thread.currentThread().interrupt(); - } + if (interrupted) { + Thread.currentThread().interrupt(); + } - return sizeWritten; - } + return sizeWritten; + } - @Override - public int available() { - synchronized (eventLoop.threadLock) { - return stream.getWritableSize(); - } - }; + @Override + public int available() { + synchronized (eventLoop.threadLock) { + return stream.getWritableSize(); + } + }; - @Override - public int getFramePosition() { - return (int) framesSinceOpen; - } + @Override + public int getFramePosition() { + return (int) framesSinceOpen; + } - @Override - public long getLongFramePosition() { - return framesSinceOpen; - } + @Override + public long getLongFramePosition() { + return framesSinceOpen; + } - @Override - public long getMicrosecondPosition() { + @Override + public long getMicrosecondPosition() { - float frameRate = currentFormat.getFrameRate(); - float time = framesSinceOpen / frameRate; // seconds - long microseconds = (long) (time * 1000); - return microseconds; - } + float frameRate = currentFormat.getFrameRate(); + float time = framesSinceOpen / frameRate; // seconds + long microseconds = (long) (time * 1000); + return microseconds; + } - @Override - public void drain() { + @Override + public void drain() { - synchronized (this) { - writeInterrupted = true; - } + synchronized (this) { + writeInterrupted = true; + } - do { - synchronized (this) { - if (!isOpen()) { - return; - } - if (getBytesInBuffer() == 0) { - return; - } - if (isStarted) { - break; - } - try { - this.wait(100); - } catch (InterruptedException e) { - return; - } - } - } while (!isStarted); + do { + synchronized (this) { + if (!isOpen()) { + return; + } + if (getBytesInBuffer() == 0) { + return; + } + if (isStarted) { + break; + } + try { + this.wait(100); + } catch (InterruptedException e) { + return; + } + } + } while (!isStarted); - Operation operation; + Operation operation; - synchronized (eventLoop.threadLock) { - operation = stream.drain(); - } + synchronized (eventLoop.threadLock) { + operation = stream.drain(); + } - operation.waitForCompletion(); - operation.releaseReference(); + operation.waitForCompletion(); + operation.releaseReference(); - } + } - @Override - public void flush() { - synchronized (this) { - writeInterrupted = true; - } + @Override + public void flush() { + synchronized (this) { + writeInterrupted = true; + } - if (isOpen()) { - Operation operation; - synchronized (eventLoop.threadLock) { - operation = stream.flush(); - } + if (isOpen()) { + Operation operation; + synchronized (eventLoop.threadLock) { + operation = stream.flush(); + } - operation.waitForCompletion(); - operation.releaseReference(); - } + operation.waitForCompletion(); + operation.releaseReference(); + } - } + } - @Override - synchronized public void close() { + @Override + synchronized public void close() { - if (!isOpen()) { - return; - } + if (!isOpen()) { + return; + } - writeInterrupted = true; + writeInterrupted = true; - PulseAudioMixer parent = PulseAudioMixer.getInstance(); - parent.removeSourceLine(this); + PulseAudioMixer parent = PulseAudioMixer.getInstance(); + parent.removeSourceLine(this); - super.close(); + super.close(); - Debug.println(DebugLevel.Verbose, "PulseAudioSourceDataLine.close():" - + " line closed"); + Debug.println(DebugLevel.Verbose, "PulseAudioSourceDataLine.close():" + + " line closed"); - } + } - @Override - public Line.Info getLineInfo() { - return new DataLine.Info(SourceDataLine.class, supportedFormats, - StreamBufferAttributes.MIN_VALUE, - StreamBufferAttributes.MAX_VALUE); - } + @Override + public Line.Info getLineInfo() { + return new DataLine.Info(SourceDataLine.class, supportedFormats, + StreamBufferAttributes.MIN_VALUE, + StreamBufferAttributes.MAX_VALUE); + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java Fri Jun 10 17:42:18 2011 -0400 @@ -43,53 +43,53 @@ final class PulseAudioSourcePort extends PulseAudioPort { - /* aka mic */ + /* aka mic */ - static { - SecurityWrapper.loadNativeLibrary(); - } + static { + SecurityWrapper.loadNativeLibrary(); + } - PulseAudioSourcePort(String name) { - super(name); - } + PulseAudioSourcePort(String name) { + super(name); + } - public void open() { + public void open() { - /* check for permission to record audio */ - AudioPermission perm = new AudioPermission("record", null); - perm.checkGuard(null); + /* check for permission to record audio */ + AudioPermission perm = new AudioPermission("record", null); + perm.checkGuard(null); - super.open(); + super.open(); - PulseAudioMixer parent = PulseAudioMixer.getInstance(); - parent.addSourceLine(this); - } + PulseAudioMixer parent = PulseAudioMixer.getInstance(); + parent.addSourceLine(this); + } - public void close() { + public void close() { - /* check for permission to record audio */ - AudioPermission perm = new AudioPermission("record", null); - perm.checkGuard(null); + /* check for permission to record audio */ + AudioPermission perm = new AudioPermission("record", null); + perm.checkGuard(null); - if (!isOpen) { - throw new IllegalStateException("Port is not open; so cant close"); - } + if (!isOpen) { + throw new IllegalStateException("Port is not open; so cant close"); + } - PulseAudioMixer parent = PulseAudioMixer.getInstance(); - parent.removeSourceLine(this); + PulseAudioMixer parent = PulseAudioMixer.getInstance(); + parent.removeSourceLine(this); - super.close(); - } + super.close(); + } - // FIXME - public native byte[] native_set_volume(float newValue); + // FIXME + public native byte[] native_set_volume(float newValue); - // FIXME - public native byte[] native_update_volume(); + // FIXME + public native byte[] native_update_volume(); - @Override - public Line.Info getLineInfo() { - return new Port.Info(Port.class, getName(), false); - } + @Override + public Line.Info getLineInfo() { + return new Port.Info(Port.class, getName(), false); + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Fri Jun 10 17:42:18 2011 -0400 @@ -48,348 +48,348 @@ import org.classpath.icedtea.pulseaudio.Debug.DebugLevel; public final class PulseAudioTargetDataLine extends PulseAudioDataLine - implements TargetDataLine { + implements TargetDataLine { - /* - * This contains the data from the PulseAudio buffer that has since been - * dropped. If 20 bytes of a fragment of size 200 are read, the other 180 - * are dumped in this - */ - private byte[] fragmentBuffer; + /* + * This contains the data from the PulseAudio buffer that has since been + * dropped. If 20 bytes of a fragment of size 200 are read, the other 180 + * are dumped in this + */ + private byte[] fragmentBuffer; - /* - * these are set to true only by the respective functions (flush(), drain()) - * set to false only by read() - */ - private boolean flushed = false; - private boolean drained = false; + /* + * these are set to true only by the respective functions (flush(), drain()) + * set to false only by read() + */ + private boolean flushed = false; + private boolean drained = false; - public static final String DEFAULT_TARGETDATALINE_NAME = "Audio Stream"; + public static final String DEFAULT_TARGETDATALINE_NAME = "Audio Stream"; - PulseAudioTargetDataLine(AudioFormat[] formats, AudioFormat defaultFormat) { - this.supportedFormats = formats; - this.defaultFormat = defaultFormat; - this.currentFormat = defaultFormat; - this.streamName = DEFAULT_TARGETDATALINE_NAME; + PulseAudioTargetDataLine(AudioFormat[] formats, AudioFormat defaultFormat) { + this.supportedFormats = formats; + this.defaultFormat = defaultFormat; + this.currentFormat = defaultFormat; + this.streamName = DEFAULT_TARGETDATALINE_NAME; - } + } - @Override - synchronized public void close() { - if (!isOpen()) { - // Probably due to some programmer error, we are being - // asked to close an already closed line. Oh well. - Debug.println(DebugLevel.Verbose, - "PulseAudioTargetDataLine.close(): " - + "Line closed that wasn't open."); - return; - } + @Override + synchronized public void close() { + if (!isOpen()) { + // Probably due to some programmer error, we are being + // asked to close an already closed line. Oh well. + Debug.println(DebugLevel.Verbose, + "PulseAudioTargetDataLine.close(): " + + "Line closed that wasn't open."); + return; + } - /* check for permission to record audio */ - AudioPermission perm = new AudioPermission("record", null); - perm.checkGuard(null); + /* check for permission to record audio */ + AudioPermission perm = new AudioPermission("record", null); + perm.checkGuard(null); - PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); - parentMixer.removeTargetLine(this); + PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); + parentMixer.removeTargetLine(this); - super.close(); + super.close(); - Debug.println(DebugLevel.Verbose, "PulseAudioTargetDataLine.close(): " - + "Line closed"); - } + Debug.println(DebugLevel.Verbose, "PulseAudioTargetDataLine.close(): " + + "Line closed"); + } - @Override - synchronized public void open(AudioFormat format, int bufferSize) - throws LineUnavailableException { - /* check for permission to record audio */ - AudioPermission perm = new AudioPermission("record", null); - perm.checkGuard(null); + @Override + synchronized public void open(AudioFormat format, int bufferSize) + throws LineUnavailableException { + /* check for permission to record audio */ + AudioPermission perm = new AudioPermission("record", null); + perm.checkGuard(null); - if (isOpen()) { - throw new IllegalStateException("already open"); - } - super.open(format, bufferSize); + if (isOpen()) { + throw new IllegalStateException("already open"); + } + super.open(format, bufferSize); - /* initialize all the member variables */ - framesSinceOpen = 0; - fragmentBuffer = null; - flushed = false; - drained = false; + /* initialize all the member variables */ + framesSinceOpen = 0; + fragmentBuffer = null; + flushed = false; + drained = false; - /* add this open line to the mixer */ - PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); - parentMixer.addTargetLine(this); + /* add this open line to the mixer */ + PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); + parentMixer.addTargetLine(this); - Debug.println(DebugLevel.Verbose, "PulseAudioTargetDataLine.open(): " - + "Line opened"); - } + Debug.println(DebugLevel.Verbose, "PulseAudioTargetDataLine.open(): " + + "Line opened"); + } - @Override - synchronized public void open(AudioFormat format) - throws LineUnavailableException { - open(format, DEFAULT_BUFFER_SIZE); - } + @Override + synchronized public void open(AudioFormat format) + throws LineUnavailableException { + open(format, DEFAULT_BUFFER_SIZE); + } - @Override - protected void connectLine(int bufferSize, Stream masterStream) - throws LineUnavailableException { - int fragmentSize = bufferSize / 10 > 500 ? bufferSize / 10 : 500; - StreamBufferAttributes bufferAttributes = new StreamBufferAttributes( - bufferSize, 0, 0, 0, fragmentSize); - synchronized (eventLoop.threadLock) { - stream.connectForRecording(Stream.DEFAULT_DEVICE, bufferAttributes); - } - } + @Override + protected void connectLine(int bufferSize, Stream masterStream) + throws LineUnavailableException { + int fragmentSize = bufferSize / 10 > 500 ? bufferSize / 10 : 500; + StreamBufferAttributes bufferAttributes = new StreamBufferAttributes( + bufferSize, 0, 0, 0, fragmentSize); + synchronized (eventLoop.threadLock) { + stream.connectForRecording(Stream.DEFAULT_DEVICE, bufferAttributes); + } + } - @Override - public int read(byte[] data, int offset, int length) { + @Override + public int read(byte[] data, int offset, int length) { - /* check state and inputs */ + /* check state and inputs */ - if (!isOpen()) { - // A closed line can produce zero bytes of data. - return 0; - } + if (!isOpen()) { + // A closed line can produce zero bytes of data. + return 0; + } - int frameSize = currentFormat.getFrameSize(); + int frameSize = currentFormat.getFrameSize(); - if (length % frameSize != 0) { - throw new IllegalArgumentException( - "amount of data to read does not represent an integral number of frames"); - } + if (length % frameSize != 0) { + throw new IllegalArgumentException( + "amount of data to read does not represent an integral number of frames"); + } - if (length < 0) { - throw new IllegalArgumentException("length is negative"); - } - - if ( offset < 0 || offset > data.length - length) { - throw new ArrayIndexOutOfBoundsException("array size: " + data.length - + " offset:" + offset + " length:" + length ); - } + if (length < 0) { + throw new IllegalArgumentException("length is negative"); + } + + if ( offset < 0 || offset > data.length - length) { + throw new ArrayIndexOutOfBoundsException("array size: " + data.length + + " offset:" + offset + " length:" + length ); + } - /* everything ok */ + /* everything ok */ - int position = offset; - int remainingLength = length; - int sizeRead = 0; + int position = offset; + int remainingLength = length; + int sizeRead = 0; - /* bytes read on each iteration of loop */ - int bytesRead; + /* bytes read on each iteration of loop */ + int bytesRead; - flushed = false; - drained = false; + flushed = false; + drained = false; - /* - * to read, we first take stuff from the fragmentBuffer - */ + /* + * to read, we first take stuff from the fragmentBuffer + */ - /* on first read() of the line, fragmentBuffer is null */ - if (fragmentBuffer != null) { - synchronized (this) { + /* on first read() of the line, fragmentBuffer is null */ + if (fragmentBuffer != null) { + synchronized (this) { - boolean fragmentBufferSmaller = fragmentBuffer.length < length; - int smallerBufferLength = Math.min(fragmentBuffer.length, - length); - System.arraycopy(fragmentBuffer, 0, data, position, - smallerBufferLength); - framesSinceOpen += smallerBufferLength - / currentFormat.getFrameSize(); + boolean fragmentBufferSmaller = fragmentBuffer.length < length; + int smallerBufferLength = Math.min(fragmentBuffer.length, + length); + System.arraycopy(fragmentBuffer, 0, data, position, + smallerBufferLength); + framesSinceOpen += smallerBufferLength + / currentFormat.getFrameSize(); - if (!fragmentBufferSmaller) { - /* - * if fragment was larger, then we already have all the data - * we need. clean up the buffer before returning. Make a new - * fragmentBuffer from the remaining bytes - */ - int remainingBytesInFragment = (fragmentBuffer.length - length); - byte[] newFragmentBuffer = new byte[remainingBytesInFragment]; - System.arraycopy(fragmentBuffer, length, newFragmentBuffer, - 0, newFragmentBuffer.length); - fragmentBuffer = newFragmentBuffer; - return length; - } + if (!fragmentBufferSmaller) { + /* + * if fragment was larger, then we already have all the data + * we need. clean up the buffer before returning. Make a new + * fragmentBuffer from the remaining bytes + */ + int remainingBytesInFragment = (fragmentBuffer.length - length); + byte[] newFragmentBuffer = new byte[remainingBytesInFragment]; + System.arraycopy(fragmentBuffer, length, newFragmentBuffer, + 0, newFragmentBuffer.length); + fragmentBuffer = newFragmentBuffer; + return length; + } - /* done with fragment buffer, remove it */ - bytesRead = smallerBufferLength; - sizeRead += bytesRead; - position += bytesRead; - remainingLength -= bytesRead; - fragmentBuffer = null; + /* done with fragment buffer, remove it */ + bytesRead = smallerBufferLength; + sizeRead += bytesRead; + position += bytesRead; + remainingLength -= bytesRead; + fragmentBuffer = null; - } - } + } + } - /* - * if we need to read more data, then we read from PulseAudio's buffer - */ - while (remainingLength != 0) { - synchronized (this) { + /* + * if we need to read more data, then we read from PulseAudio's buffer + */ + while (remainingLength != 0) { + synchronized (this) { - if (!isOpen() || !isStarted) { - return sizeRead; - } + if (!isOpen() || !isStarted) { + return sizeRead; + } - if (flushed) { - flushed = false; - return sizeRead; - } + if (flushed) { + flushed = false; + return sizeRead; + } - if (drained) { - drained = false; - return sizeRead; - } + if (drained) { + drained = false; + return sizeRead; + } - byte[] currentFragment; - synchronized (eventLoop.threadLock) { + byte[] currentFragment; + synchronized (eventLoop.threadLock) { - /* read a fragment, and drop it from the server */ - currentFragment = stream.peek(); + /* read a fragment, and drop it from the server */ + currentFragment = stream.peek(); - stream.drop(); - if (currentFragment == null) { - Debug.println(DebugLevel.Verbose, - "PulseAudioTargetDataLine.read(): " - + " error in stream.peek()"); - continue; - } + stream.drop(); + if (currentFragment == null) { + Debug.println(DebugLevel.Verbose, + "PulseAudioTargetDataLine.read(): " + + " error in stream.peek()"); + continue; + } - bytesRead = Math.min(currentFragment.length, - remainingLength); + bytesRead = Math.min(currentFragment.length, + remainingLength); - /* - * we read more than we required, save the rest of the data - * in the fragmentBuffer - */ - if (bytesRead < currentFragment.length) { - /* allocate a buffer to store unsaved data */ - fragmentBuffer = new byte[currentFragment.length - - bytesRead]; + /* + * we read more than we required, save the rest of the data + * in the fragmentBuffer + */ + if (bytesRead < currentFragment.length) { + /* allocate a buffer to store unsaved data */ + fragmentBuffer = new byte[currentFragment.length + - bytesRead]; - /* copy over the unsaved data */ - System.arraycopy(currentFragment, bytesRead, - fragmentBuffer, 0, currentFragment.length - - bytesRead); - } + /* copy over the unsaved data */ + System.arraycopy(currentFragment, bytesRead, + fragmentBuffer, 0, currentFragment.length + - bytesRead); + } - System.arraycopy(currentFragment, 0, data, position, - bytesRead); + System.arraycopy(currentFragment, 0, data, position, + bytesRead); - sizeRead += bytesRead; - position += bytesRead; - remainingLength -= bytesRead; - framesSinceOpen += bytesRead / currentFormat.getFrameSize(); - } - } - } + sizeRead += bytesRead; + position += bytesRead; + remainingLength -= bytesRead; + framesSinceOpen += bytesRead / currentFormat.getFrameSize(); + } + } + } - // all the data should have been played by now - assert (sizeRead == length); + // all the data should have been played by now + assert (sizeRead == length); - return sizeRead; + return sizeRead; - } + } - @Override - public void drain() { + @Override + public void drain() { - // blocks when there is data on the line - // http://www.jsresources.org/faq_audio.html#stop_drain_tdl - while (true) { - synchronized (this) { - if (!isStarted || !isOpen()) { - break; - } - } - try { - //TODO: Is this the best length of sleep? - //Maybe in case this loop runs for a long time - //it would be good to switch to a longer - //sleep. Like bump it up each iteration after - //the Nth iteration, up to a MAXSLEEP length. - Thread.sleep(100); - } catch (InterruptedException e) { - // do nothing - } - } + // blocks when there is data on the line + // http://www.jsresources.org/faq_audio.html#stop_drain_tdl + while (true) { + synchronized (this) { + if (!isStarted || !isOpen()) { + break; + } + } + try { + //TODO: Is this the best length of sleep? + //Maybe in case this loop runs for a long time + //it would be good to switch to a longer + //sleep. Like bump it up each iteration after + //the Nth iteration, up to a MAXSLEEP length. + Thread.sleep(100); + } catch (InterruptedException e) { + // do nothing + } + } - synchronized (this) { - drained = true; - } + synchronized (this) { + drained = true; + } - } + } - @Override - public void flush() { - if (isOpen()) { + @Override + public void flush() { + if (isOpen()) { - /* flush the buffer on pulseaudio's side */ - Operation operation; - synchronized (eventLoop.threadLock) { - operation = stream.flush(); - } - operation.waitForCompletion(); - operation.releaseReference(); - } + /* flush the buffer on pulseaudio's side */ + Operation operation; + synchronized (eventLoop.threadLock) { + operation = stream.flush(); + } + operation.waitForCompletion(); + operation.releaseReference(); + } - synchronized (this) { - flushed = true; - /* flush the partial fragment we stored */ - fragmentBuffer = null; - } - } + synchronized (this) { + flushed = true; + /* flush the partial fragment we stored */ + fragmentBuffer = null; + } + } - @Override - public int available() { - if (!isOpen()) { - // a closed line has 0 bytes available. - return 0; - } + @Override + public int available() { + if (!isOpen()) { + // a closed line has 0 bytes available. + return 0; + } - synchronized (eventLoop.threadLock) { - return stream.getReableSize(); - } - } + synchronized (eventLoop.threadLock) { + return stream.getReableSize(); + } + } - @Override - public int getFramePosition() { - return (int) framesSinceOpen; - } + @Override + public int getFramePosition() { + return (int) framesSinceOpen; + } - @Override - public long getLongFramePosition() { - return framesSinceOpen; - } + @Override + public long getLongFramePosition() { + return framesSinceOpen; + } - @Override - public long getMicrosecondPosition() { - return (long) (framesSinceOpen / currentFormat.getFrameRate()); - } + @Override + public long getMicrosecondPosition() { + return (long) (framesSinceOpen / currentFormat.getFrameRate()); + } - /* - * A TargetData starts when we ask it to and continues playing until we ask - * it to stop. There are no buffer underruns/overflows or anything so we - * will just fire the LineEvents manually - */ + /* + * A TargetData starts when we ask it to and continues playing until we ask + * it to stop. There are no buffer underruns/overflows or anything so we + * will just fire the LineEvents manually + */ - @Override - synchronized public void start() { - super.start(); + @Override + synchronized public void start() { + super.start(); - fireLineEvent(new LineEvent(this, LineEvent.Type.START, framesSinceOpen)); - } + fireLineEvent(new LineEvent(this, LineEvent.Type.START, framesSinceOpen)); + } - @Override - synchronized public void stop() { - super.stop(); + @Override + synchronized public void stop() { + super.stop(); - fireLineEvent(new LineEvent(this, LineEvent.Type.STOP, framesSinceOpen)); - } + fireLineEvent(new LineEvent(this, LineEvent.Type.STOP, framesSinceOpen)); + } - @Override - public Line.Info getLineInfo() { - return new DataLine.Info(TargetDataLine.class, supportedFormats, - StreamBufferAttributes.MIN_VALUE, - StreamBufferAttributes.MAX_VALUE); - } + @Override + public Line.Info getLineInfo() { + return new DataLine.Info(TargetDataLine.class, supportedFormats, + StreamBufferAttributes.MIN_VALUE, + StreamBufferAttributes.MAX_VALUE); + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java Fri Jun 10 17:42:18 2011 -0400 @@ -42,47 +42,47 @@ final class PulseAudioTargetPort extends PulseAudioPort { - /* aka speaker */ + /* aka speaker */ - static { - SecurityWrapper.loadNativeLibrary(); - } + static { + SecurityWrapper.loadNativeLibrary(); + } - PulseAudioTargetPort(String name) { - super(name); - } + PulseAudioTargetPort(String name) { + super(name); + } - @Override - public void open() { + @Override + public void open() { - super.open(); + super.open(); - PulseAudioMixer parent = PulseAudioMixer.getInstance(); - parent.addTargetLine(this); - } + PulseAudioMixer parent = PulseAudioMixer.getInstance(); + parent.addTargetLine(this); + } - @Override - public void close() { + @Override + public void close() { - if (!isOpen) { - throw new IllegalStateException("not open, so cant close Port"); - } + if (!isOpen) { + throw new IllegalStateException("not open, so cant close Port"); + } - PulseAudioMixer parent = PulseAudioMixer.getInstance(); - parent.removeTargetLine(this); + PulseAudioMixer parent = PulseAudioMixer.getInstance(); + parent.removeTargetLine(this); - super.close(); - } + super.close(); + } - // FIXME - public native byte[] native_set_volume(float newValue); + // FIXME + public native byte[] native_set_volume(float newValue); - // FIXME - public native byte[] native_update_volume(); + // FIXME + public native byte[] native_update_volume(); - @Override - public Line.Info getLineInfo() { - return new Port.Info(Port.class, getName(), false); - } + @Override + public Line.Info getLineInfo() { + return new Port.Info(Port.class, getName(), false); + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.java Fri Jun 10 17:42:18 2011 -0400 @@ -41,61 +41,61 @@ final class PulseAudioVolumeControl extends FloatControl { - static final int MAX_VOLUME = 65536; - static final int MIN_VOLUME = 0; + static final int MAX_VOLUME = 65536; + static final int MIN_VOLUME = 0; - protected PulseAudioVolumeControl(PulseAudioPlaybackLine line, - EventLoop eventLoop) { + protected PulseAudioVolumeControl(PulseAudioPlaybackLine line, + EventLoop eventLoop) { - /* - * the initial volume is ignored by pulseaudio. - */ - super(FloatControl.Type.VOLUME, MIN_VOLUME, MAX_VOLUME, 1, -1, line - .getCachedVolume(), "pulseaudio units", "Volume Off", - "Default Volume", "Full Volume"); - this.line = line; - this.eventLoop = eventLoop; - } + /* + * the initial volume is ignored by pulseaudio. + */ + super(FloatControl.Type.VOLUME, MIN_VOLUME, MAX_VOLUME, 1, -1, line + .getCachedVolume(), "pulseaudio units", "Volume Off", + "Default Volume", "Full Volume"); + this.line = line; + this.eventLoop = eventLoop; + } - private EventLoop eventLoop; - private PulseAudioPlaybackLine line; + private EventLoop eventLoop; + private PulseAudioPlaybackLine line; - @Override - public synchronized void setValue(float newValue) { - if (newValue > MAX_VOLUME || newValue < MIN_VOLUME) { - throw new IllegalArgumentException("invalid value"); - } + @Override + public synchronized void setValue(float newValue) { + if (newValue > MAX_VOLUME || newValue < MIN_VOLUME) { + throw new IllegalArgumentException("invalid value"); + } - if (!line.isOpen()) { - return; - } + if (!line.isOpen()) { + return; + } - setStreamVolume(newValue); + setStreamVolume(newValue); - line.setCachedVolume(newValue); - } + line.setCachedVolume(newValue); + } - protected synchronized void setStreamVolume(float newValue) { - Operation op; - synchronized (eventLoop.threadLock) { - op = new Operation(line.native_set_volume(newValue)); - } + protected synchronized void setStreamVolume(float newValue) { + Operation op; + synchronized (eventLoop.threadLock) { + op = new Operation(line.native_set_volume(newValue)); + } - op.waitForCompletion(); - op.releaseReference(); + op.waitForCompletion(); + op.releaseReference(); - } + } - public synchronized float getValue() { - Operation op; - synchronized (eventLoop.threadLock) { - op = new Operation(line.native_update_volume()); - } + public synchronized float getValue() { + Operation op; + synchronized (eventLoop.threadLock) { + op = new Operation(line.native_update_volume()); + } - op.waitForCompletion(); - op.releaseReference(); + op.waitForCompletion(); + op.releaseReference(); - return line.getCachedVolume(); - } + return line.getCachedVolume(); + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/SecurityWrapper.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/SecurityWrapper.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/SecurityWrapper.java Fri Jun 10 17:42:18 2011 -0400 @@ -9,23 +9,23 @@ */ final class SecurityWrapper { - static void loadNativeLibrary() { + static void loadNativeLibrary() { - if (System.getSecurityManager() != null) { - PrivilegedAction action = new PrivilegedAction() { - @Override - public Boolean run() { - System.loadLibrary("pulse-java"); - return true; - } + if (System.getSecurityManager() != null) { + PrivilegedAction action = new PrivilegedAction() { + @Override + public Boolean run() { + System.loadLibrary("pulse-java"); + return true; + } - }; + }; - AccessController.doPrivileged(action); + AccessController.doPrivileged(action); - } else { - System.loadLibrary("pulse-java"); - } + } else { + System.loadLibrary("pulse-java"); + } - } + } } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Stream.java --- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Stream.java Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Stream.java Fri Jun 10 17:42:18 2011 -0400 @@ -54,742 +54,742 @@ */ final class Stream { - public interface StateListener { - public void update(); - } + public interface StateListener { + public void update(); + } - public interface CorkListener { - public void update(); - } + public interface CorkListener { + public void update(); + } - public interface WriteListener { - public void update(); - } + public interface WriteListener { + public void update(); + } - public interface ReadListener { - public void update(); - } + public interface ReadListener { + public void update(); + } - public interface OverflowListener { - public void update(); - } + public interface OverflowListener { + public void update(); + } - public interface UnderflowListener { - public void update(); - } + public interface UnderflowListener { + public void update(); + } - public interface PlaybackStartedListener { - public void update(); - } + public interface PlaybackStartedListener { + public void update(); + } - public interface LatencyUpdateListener { - public void update(); - } + public interface LatencyUpdateListener { + public void update(); + } - public interface MovedListener { - public void update(); - } + public interface MovedListener { + public void update(); + } - public interface UpdateTimingInfoListener { - public void update(); - } + public interface UpdateTimingInfoListener { + public void update(); + } - public interface SuspendedListener { - public void update(); - } + public interface SuspendedListener { + public void update(); + } - public static enum State { - UNCONNECTED, CREATING, READY, FAILED, TERMINATED, - } + public static enum State { + UNCONNECTED, CREATING, READY, FAILED, TERMINATED, + } - public static enum Format { - PA_SAMPLE_U8, PA_SAMPLE_ULAW, PA_SAMPLE_ALAW, PA_SAMPLE_S16LE, PA_SAMPLE_S16BE, PA_SAMPLE_FLOAT32LE, PA_SAMPLE_FLOAT32BE, PA_SAMPLE_S32LE, PA_SAMPLE_S32BE - } + public static enum Format { + PA_SAMPLE_U8, PA_SAMPLE_ULAW, PA_SAMPLE_ALAW, PA_SAMPLE_S16LE, PA_SAMPLE_S16BE, PA_SAMPLE_FLOAT32LE, PA_SAMPLE_FLOAT32BE, PA_SAMPLE_S32LE, PA_SAMPLE_S32BE + } - public static final String DEFAULT_DEVICE = null; + public static final String DEFAULT_DEVICE = null; - private byte[] streamPointer; + private byte[] streamPointer; - static { - SecurityWrapper.loadNativeLibrary(); - } + static { + SecurityWrapper.loadNativeLibrary(); + } - private Format format; - private float cachedVolume; + private Format format; + private float cachedVolume; - private List stateListeners; - private List writeListeners; - private List readListeners; - private List overflowListeners; - private List underflowListeners; - private List playbackStartedListeners; - private List latencyUpdateListeners; - private List movedListeners; - private List suspendedListeners; - private List corkListeners; + private List stateListeners; + private List writeListeners; + private List readListeners; + private List overflowListeners; + private List underflowListeners; + private List playbackStartedListeners; + private List latencyUpdateListeners; + private List movedListeners; + private List suspendedListeners; + private List corkListeners; - private native void native_pa_stream_new(byte[] contextPointer, - String name, String format, int sampleRate, int channels); + private native void native_pa_stream_new(byte[] contextPointer, + String name, String format, int sampleRate, int channels); - private native void native_pa_stream_unref(); + private native void native_pa_stream_unref(); - private native int native_pa_stream_get_state(); + private native int native_pa_stream_get_state(); - private native byte[] native_pa_stream_get_context(); + private native byte[] native_pa_stream_get_context(); - private native int native_pa_stream_get_index(); + private native int native_pa_stream_get_index(); - private native int native_pa_stream_get_device_index(); + private native int native_pa_stream_get_device_index(); - private native String native_pa_stream_get_device_name(); + private native String native_pa_stream_get_device_name(); - private native int native_pa_stream_is_suspended(); + private native int native_pa_stream_is_suspended(); - private native int native_pa_stream_connect_playback(String name, - int bufferMaxLength, int bufferTargetLength, - int bufferPreBuffering, int bufferMinimumRequest, - int bufferFragmentSize, int flags, byte[] volumePointer, - byte[] sync_streamPointer); + private native int native_pa_stream_connect_playback(String name, + int bufferMaxLength, int bufferTargetLength, + int bufferPreBuffering, int bufferMinimumRequest, + int bufferFragmentSize, int flags, byte[] volumePointer, + byte[] sync_streamPointer); - private native int native_pa_stream_connect_record(String name, - int bufferMaxLength, int bufferTargetLength, - int bufferPreBuffering, int bufferMinimumRequest, - int bufferFragmentSize, int flags, byte[] volumePointer, - byte[] sync_streamPointer); + private native int native_pa_stream_connect_record(String name, + int bufferMaxLength, int bufferTargetLength, + int bufferPreBuffering, int bufferMinimumRequest, + int bufferFragmentSize, int flags, byte[] volumePointer, + byte[] sync_streamPointer); - private native int native_pa_stream_disconnect(); + private native int native_pa_stream_disconnect(); - private native int native_pa_stream_write(byte[] data, int offset, - int length); + private native int native_pa_stream_write(byte[] data, int offset, + int length); - private native byte[] native_pa_stream_peek(); + private native byte[] native_pa_stream_peek(); - private native int native_pa_stream_drop(); + private native int native_pa_stream_drop(); - private native int native_pa_stream_writable_size(); + private native int native_pa_stream_writable_size(); - private native int native_pa_stream_readable_size(); + private native int native_pa_stream_readable_size(); - private native byte[] native_pa_stream_drain(); + private native byte[] native_pa_stream_drain(); - private native byte[] native_pa_stream_updateTimingInfo(); + private native byte[] native_pa_stream_updateTimingInfo(); - public native int bytesInBuffer(); + public native int bytesInBuffer(); - /* - * pa_operation pa_stream_update_timing_info (pa_streamp, - * pa_stream_success_cb_t cb, voiduserdata) Request a timing info structure - * update for a stream. - */ + /* + * pa_operation pa_stream_update_timing_info (pa_streamp, + * pa_stream_success_cb_t cb, voiduserdata) Request a timing info structure + * update for a stream. + */ - private native int native_pa_stream_is_corked(); + private native int native_pa_stream_is_corked(); - private native byte[] native_pa_stream_cork(int b); + private native byte[] native_pa_stream_cork(int b); - private native byte[] native_pa_stream_flush(); + private native byte[] native_pa_stream_flush(); - /* - * pa_operation pa_stream_prebuf (pa_streams, pa_stream_success_cb_t cb, - * voiduserdata) Reenable prebuffering as specified in the pa_buffer_attr - * structure. - */ + /* + * pa_operation pa_stream_prebuf (pa_streams, pa_stream_success_cb_t cb, + * voiduserdata) Reenable prebuffering as specified in the pa_buffer_attr + * structure. + */ - private native byte[] native_pa_stream_trigger(); + private native byte[] native_pa_stream_trigger(); - /* returns an operationPointer */ - private native byte[] native_pa_stream_set_name(String name); + /* returns an operationPointer */ + private native byte[] native_pa_stream_set_name(String name); - /* Return the current playback/recording time */ - private native long native_pa_stream_get_time(); + /* Return the current playback/recording time */ + private native long native_pa_stream_get_time(); - /* Return the total stream latency */ - private native long native_pa_stream_get_latency(); + /* Return the total stream latency */ + private native long native_pa_stream_get_latency(); - /* - * const pa_timing_info pa_stream_get_timing_info (pa_streams) Return the - * latest raw timing data structure. - */ + /* + * const pa_timing_info pa_stream_get_timing_info (pa_streams) Return the + * latest raw timing data structure. + */ - private native StreamSampleSpecification native_pa_stream_get_sample_spec(); + private native StreamSampleSpecification native_pa_stream_get_sample_spec(); - /* - * const pa_channel_map pa_stream_get_channel_map (pa_streams) Return a - * pointer to the stream's channel map. const - */ - private native StreamBufferAttributes native_pa_stream_get_buffer_attr(); + /* + * const pa_channel_map pa_stream_get_channel_map (pa_streams) Return a + * pointer to the stream's channel map. const + */ + private native StreamBufferAttributes native_pa_stream_get_buffer_attr(); - private native byte[] native_pa_stream_set_buffer_attr( - StreamBufferAttributes info); + private native byte[] native_pa_stream_set_buffer_attr( + StreamBufferAttributes info); - private native byte[] native_pa_stream_update_sample_rate(int rate); + private native byte[] native_pa_stream_update_sample_rate(int rate); - native byte[] native_set_volume(float newValue); + native byte[] native_set_volume(float newValue); - native byte[] native_update_volume(); + native byte[] native_update_volume(); - /* - * pa_operation pa_stream_proplist_update (pa_streams, pa_update_mode_t - * mode, pa_proplistp, pa_stream_success_cb_t cb, voiduserdata) Update the - * property list of the sink input/source output of this stream, adding new - * entries. pa_operation pa_stream_proplist_remove (pa_streams, const char - * const keys[], pa_stream_success_cb_t cb, voiduserdata) Update the - * property list of the sink input/source output of this stream, remove - * entries. int pa_stream_set_monitor_stream (pa_streams, uint32_t - * sink_input_idx) For record streams connected to a monitor source: monitor - * only a very specific sink input of the sink. uint32_t - * pa_stream_get_monitor_stream (pa_streams) Return what has been set with - * pa_stream_set_monitor_stream() ebfore. - */ + /* + * pa_operation pa_stream_proplist_update (pa_streams, pa_update_mode_t + * mode, pa_proplistp, pa_stream_success_cb_t cb, voiduserdata) Update the + * property list of the sink input/source output of this stream, adding new + * entries. pa_operation pa_stream_proplist_remove (pa_streams, const char + * const keys[], pa_stream_success_cb_t cb, voiduserdata) Update the + * property list of the sink input/source output of this stream, remove + * entries. int pa_stream_set_monitor_stream (pa_streams, uint32_t + * sink_input_idx) For record streams connected to a monitor source: monitor + * only a very specific sink input of the sink. uint32_t + * pa_stream_get_monitor_stream (pa_streams) Return what has been set with + * pa_stream_set_monitor_stream() ebfore. + */ - Stream(byte[] contextPointer, String name, Format format, int sampleRate, - int channels) { - // System.out.println("format: " + format.toString()); + Stream(byte[] contextPointer, String name, Format format, int sampleRate, + int channels) { + // System.out.println("format: " + format.toString()); - stateListeners = new LinkedList(); - writeListeners = new LinkedList(); - readListeners = new LinkedList(); - overflowListeners = new LinkedList(); - underflowListeners = new LinkedList(); - playbackStartedListeners = new LinkedList(); - latencyUpdateListeners = new LinkedList(); - movedListeners = new LinkedList(); - suspendedListeners = new LinkedList(); - corkListeners = new LinkedList(); - this.format = format; + stateListeners = new LinkedList(); + writeListeners = new LinkedList(); + readListeners = new LinkedList(); + overflowListeners = new LinkedList(); + underflowListeners = new LinkedList(); + playbackStartedListeners = new LinkedList(); + latencyUpdateListeners = new LinkedList(); + movedListeners = new LinkedList(); + suspendedListeners = new LinkedList(); + corkListeners = new LinkedList(); + this.format = format; - StreamSampleSpecification spec = new StreamSampleSpecification(format, - sampleRate, channels); + StreamSampleSpecification spec = new StreamSampleSpecification(format, + sampleRate, channels); - native_pa_stream_new(contextPointer, name, spec.getFormat().toString(), - spec.getRate(), spec.getChannels()); - } + native_pa_stream_new(contextPointer, name, spec.getFormat().toString(), + spec.getRate(), spec.getChannels()); + } - void addStateListener(StateListener listener) { - synchronized (stateListeners) { - stateListeners.add(listener); - } - } + void addStateListener(StateListener listener) { + synchronized (stateListeners) { + stateListeners.add(listener); + } + } - void removeStateListener(StateListener listener) { - synchronized (stateListeners) { - stateListeners.remove(listener); - } + void removeStateListener(StateListener listener) { + synchronized (stateListeners) { + stateListeners.remove(listener); + } - } + } - void addWriteListener(WriteListener listener) { - synchronized (writeListeners) { - writeListeners.add(listener); - } - } + void addWriteListener(WriteListener listener) { + synchronized (writeListeners) { + writeListeners.add(listener); + } + } - void removeWriteListener(WriteListener listener) { - synchronized (writeListeners) { - writeListeners.remove(listener); - } - } + void removeWriteListener(WriteListener listener) { + synchronized (writeListeners) { + writeListeners.remove(listener); + } + } - void addReadListener(ReadListener listener) { - synchronized (readListeners) { - readListeners.add(listener); - } - } + void addReadListener(ReadListener listener) { + synchronized (readListeners) { + readListeners.add(listener); + } + } - void removeReadListener(ReadListener listener) { - synchronized (readListeners) { - readListeners.remove(listener); - } - } + void removeReadListener(ReadListener listener) { + synchronized (readListeners) { + readListeners.remove(listener); + } + } - void addOverflowListener(OverflowListener listener) { - synchronized (overflowListeners) { - overflowListeners.add(listener); - } - } + void addOverflowListener(OverflowListener listener) { + synchronized (overflowListeners) { + overflowListeners.add(listener); + } + } - void removeOverflowListener(OverflowListener listener) { - synchronized (overflowListeners) { - overflowListeners.remove(listener); - } - } + void removeOverflowListener(OverflowListener listener) { + synchronized (overflowListeners) { + overflowListeners.remove(listener); + } + } - void addUnderflowListener(UnderflowListener listener) { - synchronized (underflowListeners) { - underflowListeners.add(listener); - } - } + void addUnderflowListener(UnderflowListener listener) { + synchronized (underflowListeners) { + underflowListeners.add(listener); + } + } - void removeUnderflowListener(UnderflowListener listener) { - synchronized (underflowListeners) { - underflowListeners.remove(listener); - } - } + void removeUnderflowListener(UnderflowListener listener) { + synchronized (underflowListeners) { + underflowListeners.remove(listener); + } + } - void addCorkListener(CorkListener listener) { - synchronized (corkListeners) { - corkListeners.add(listener); - } - } + void addCorkListener(CorkListener listener) { + synchronized (corkListeners) { + corkListeners.add(listener); + } + } - void removeCorkListener(CorkListener listener) { - synchronized (corkListeners) { - corkListeners.remove(listener); - } - } + void removeCorkListener(CorkListener listener) { + synchronized (corkListeners) { + corkListeners.remove(listener); + } + } - void addPlaybackStartedListener(PlaybackStartedListener listener) { - synchronized (playbackStartedListeners) { - playbackStartedListeners.add(listener); - } - } + void addPlaybackStartedListener(PlaybackStartedListener listener) { + synchronized (playbackStartedListeners) { + playbackStartedListeners.add(listener); + } + } - void removePlaybackStartedListener(PlaybackStartedListener listener) { - synchronized (playbackStartedListeners) { - playbackStartedListeners.remove(listener); - } - } + void removePlaybackStartedListener(PlaybackStartedListener listener) { + synchronized (playbackStartedListeners) { + playbackStartedListeners.remove(listener); + } + } - void addLatencyUpdateListener(LatencyUpdateListener listener) { - synchronized (latencyUpdateListeners) { - latencyUpdateListeners.add(listener); - } - } + void addLatencyUpdateListener(LatencyUpdateListener listener) { + synchronized (latencyUpdateListeners) { + latencyUpdateListeners.add(listener); + } + } - void removeLatencyUpdateListener(LatencyUpdateListener listener) { - synchronized (playbackStartedListeners) { - latencyUpdateListeners.remove(listener); - } - } + void removeLatencyUpdateListener(LatencyUpdateListener listener) { + synchronized (playbackStartedListeners) { + latencyUpdateListeners.remove(listener); + } + } - void addMovedListener(MovedListener listener) { - synchronized (movedListeners) { - movedListeners.add(listener); - } - } + void addMovedListener(MovedListener listener) { + synchronized (movedListeners) { + movedListeners.add(listener); + } + } - void removeMovedListener(MovedListener listener) { - synchronized (movedListeners) { - movedListeners.remove(listener); - } - } + void removeMovedListener(MovedListener listener) { + synchronized (movedListeners) { + movedListeners.remove(listener); + } + } - void addSuspendedListener(SuspendedListener listener) { - synchronized (suspendedListeners) { - suspendedListeners.add(listener); - } - } + void addSuspendedListener(SuspendedListener listener) { + synchronized (suspendedListeners) { + suspendedListeners.add(listener); + } + } - void removeSuspendedListener(SuspendedListener listener) { - synchronized (suspendedListeners) { - suspendedListeners.remove(listener); - } - } + void removeSuspendedListener(SuspendedListener listener) { + synchronized (suspendedListeners) { + suspendedListeners.remove(listener); + } + } - Stream.State getState() { - int state = native_pa_stream_get_state(); - switch (state) { - case 0: - return State.UNCONNECTED; - case 1: - return State.CREATING; - case 2: - return State.READY; - case 3: - return State.FAILED; - case 4: - return State.TERMINATED; - default: - throw new IllegalStateException("invalid stream state"); - } + Stream.State getState() { + int state = native_pa_stream_get_state(); + switch (state) { + case 0: + return State.UNCONNECTED; + case 1: + return State.CREATING; + case 2: + return State.READY; + case 3: + return State.FAILED; + case 4: + return State.TERMINATED; + default: + throw new IllegalStateException("invalid stream state"); + } - } + } - byte[] getContextPointer() { - return native_pa_stream_get_context(); - } + byte[] getContextPointer() { + return native_pa_stream_get_context(); + } - int getSinkInputIndex() { - return native_pa_stream_get_index(); - } + int getSinkInputIndex() { + return native_pa_stream_get_index(); + } - /** - * - * @return the index of the sink or source this stream is connected to in - * the server - */ - int getDeviceIndex() { - return native_pa_stream_get_device_index(); - } + /** + * + * @return the index of the sink or source this stream is connected to in + * the server + */ + int getDeviceIndex() { + return native_pa_stream_get_device_index(); + } - /** - * - * @return the name of the sink or source this stream is connected to in the - * server - */ - String getDeviceName() { - return native_pa_stream_get_device_name(); - } + /** + * + * @return the name of the sink or source this stream is connected to in the + * server + */ + String getDeviceName() { + return native_pa_stream_get_device_name(); + } - /** - * if the sink or source this stream is connected to has been suspended. - * - * @return - */ - boolean isSuspended() { - return (native_pa_stream_is_suspended() != 0); - } + /** + * if the sink or source this stream is connected to has been suspended. + * + * @return + */ + boolean isSuspended() { + return (native_pa_stream_is_suspended() != 0); + } - /** - * Connect the stream to a sink - * - * @param deviceName - * the device to connect to. use - * nullnullFindClass(env, name); - if (cls != NULL) { - (*env)->ThrowNew(env, cls, msg); - return; - } + jclass cls = (*env)->FindClass(env, name); + if (cls != NULL) { + (*env)->ThrowNew(env, cls, msg); + return; + } } jint getJavaIntField(JNIEnv* env, jobject obj, char* fieldName) { - jclass cls = (*env)->GetObjectClass(env, obj); - assert(cls); - jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "I"); - assert(fid); - jint value = (*env)->GetIntField(env, obj, fid); - return value; + jclass cls = (*env)->GetObjectClass(env, obj); + assert(cls); + jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "I"); + assert(fid); + jint value = (*env)->GetIntField(env, obj, fid); + return value; } void setJavaIntField(JNIEnv *env, jobject obj, char *fieldName, jint value) { - jclass cls = (*env)->GetObjectClass(env, obj); - assert(cls); - jfieldID fid =(*env)->GetFieldID(env, cls, fieldName, "I"); - assert(fid); - (*env)->SetIntField(env, obj, fid, value); + jclass cls = (*env)->GetObjectClass(env, obj); + assert(cls); + jfieldID fid =(*env)->GetFieldID(env, cls, fieldName, "I"); + assert(fid); + (*env)->SetIntField(env, obj, fid, value); } jlong getJavaLongField(JNIEnv* env, jobject obj, char* name) { - jclass cls = (*env)->GetObjectClass(env, obj); - assert(cls); - jfieldID fid = (*env)->GetFieldID(env, cls, name, "J"); - assert(fid); - jint value = (*env)->GetLongField(env, obj, fid); - return value; + jclass cls = (*env)->GetObjectClass(env, obj); + assert(cls); + jfieldID fid = (*env)->GetFieldID(env, cls, name, "J"); + assert(fid); + jint value = (*env)->GetLongField(env, obj, fid); + return value; } void setJavaLongField(JNIEnv* env, jobject obj, char* name, jlong value) { - jclass cls = (*env)->GetObjectClass(env, obj); - assert(cls); - jfieldID fid =(*env)->GetFieldID(env, cls, name, "J"); - assert(fid); - (*env)->SetLongField(env, obj, fid, value); + jclass cls = (*env)->GetObjectClass(env, obj); + assert(cls); + jfieldID fid =(*env)->GetFieldID(env, cls, name, "J"); + assert(fid); + (*env)->SetLongField(env, obj, fid, value); } jbyteArray getJavaByteArrayField(JNIEnv* env, jobject obj, char* name) { - jclass cls = (*env)->GetObjectClass(env, obj); - assert(cls); - jfieldID fid = (*env)->GetFieldID(env, cls, name, "[B"); - assert(fid); - jbyteArray array = (*env)->GetObjectField(env, obj, fid); - assert(array); - return array; + jclass cls = (*env)->GetObjectClass(env, obj); + assert(cls); + jfieldID fid = (*env)->GetFieldID(env, cls, name, "[B"); + assert(fid); + jbyteArray array = (*env)->GetObjectField(env, obj, fid); + assert(array); + return array; } void setJavaByteArrayField(JNIEnv* env, jobject obj, char* name, - jbyteArray array) { + jbyteArray array) { - jclass cls = (*env)->GetObjectClass(env, obj); - assert(cls); - jfieldID fid = (*env)->GetFieldID(env, cls, name, "[B"); - assert(fid); + jclass cls = (*env)->GetObjectClass(env, obj); + assert(cls); + jfieldID fid = (*env)->GetFieldID(env, cls, name, "[B"); + assert(fid); - (*env)->SetObjectField(env, obj, fid, array); - return; + (*env)->SetObjectField(env, obj, fid, array); + return; } void callJavaVoidMethod(JNIEnv* env, jobject obj, const char* method_name) { - jclass cls = (*env)->GetObjectClass(env, obj); - if (cls == NULL) { - printf("unable to get class of object"); - return; - } - jmethodID mid = (*env)->GetMethodID(env, cls, method_name, "()V"); - if (mid == NULL) { - printf("unable to get method %s\n", method_name); - return; + jclass cls = (*env)->GetObjectClass(env, obj); + if (cls == NULL) { + printf("unable to get class of object"); + return; + } + jmethodID mid = (*env)->GetMethodID(env, cls, method_name, "()V"); + if (mid == NULL) { + printf("unable to get method %s\n", method_name); + return; - } - (*env)->CallVoidMethod(env, obj, mid); + } + (*env)->CallVoidMethod(env, obj, mid); - return; + return; } jobject getLockObject(JNIEnv* env) { - const char* eventLoopClassName = - "org/classpath/icedtea/pulseaudio/EventLoop"; + const char* eventLoopClassName = + "org/classpath/icedtea/pulseaudio/EventLoop"; - jclass eventLoopClass = (*env)->FindClass(env, eventLoopClassName); - assert(eventLoopClass); + jclass eventLoopClass = (*env)->FindClass(env, eventLoopClassName); + assert(eventLoopClass); - const char* getEventLoopIDSignature = - "()Lorg/classpath/icedtea/pulseaudio/EventLoop;"; - jmethodID getEventLoopID = (*env)->GetStaticMethodID(env, eventLoopClass, "getEventLoop", - getEventLoopIDSignature); - assert(getEventLoopID); + const char* getEventLoopIDSignature = + "()Lorg/classpath/icedtea/pulseaudio/EventLoop;"; + jmethodID getEventLoopID = (*env)->GetStaticMethodID(env, eventLoopClass, "getEventLoop", + getEventLoopIDSignature); + assert(getEventLoopID); - jobject eventLoop = (*env)->CallStaticObjectMethod(env, eventLoopClass, getEventLoopID); - assert(eventLoop); + jobject eventLoop = (*env)->CallStaticObjectMethod(env, eventLoopClass, getEventLoopID); + assert(eventLoop); - jfieldID lockID = (*env)->GetFieldID(env, eventLoopClass, "threadLock", - "Ljava/lang/Object;"); - assert(lockID); + jfieldID lockID = (*env)->GetFieldID(env, eventLoopClass, "threadLock", + "Ljava/lang/Object;"); + assert(lockID); - jobject lockObject = (*env)->GetObjectField(env, eventLoop, lockID); - assert(lockObject); - return lockObject; + jobject lockObject = (*env)->GetObjectField(env, eventLoop, lockID); + assert(lockObject); + return lockObject; } void notifyWaitingOperations(JNIEnv* env) { - jobject lockObject = getLockObject(env); + jobject lockObject = getLockObject(env); - (*env)->MonitorEnter(env, lockObject); + (*env)->MonitorEnter(env, lockObject); - jclass objectClass = (*env)->FindClass(env, "java/lang/Object"); - assert(objectClass); - jmethodID notifyAllID = (*env)->GetMethodID(env, objectClass, "notifyAll", "()V"); - assert(notifyAllID); + jclass objectClass = (*env)->FindClass(env, "java/lang/Object"); + assert(objectClass); + jmethodID notifyAllID = (*env)->GetMethodID(env, objectClass, "notifyAll", "()V"); + assert(notifyAllID); - (*env)->CallObjectMethod(env, lockObject, notifyAllID); + (*env)->CallObjectMethod(env, lockObject, notifyAllID); - (*env)->MonitorExit(env, lockObject); + (*env)->MonitorExit(env, lockObject); } void* getJavaPointer(JNIEnv* env, jobject obj, char* name) { - jbyteArray array = getJavaByteArrayField(env, obj, name); - assert(array); - void* value = convertJavaPointerToNative(env, array); - // allow returning NULL values - return value; + jbyteArray array = getJavaByteArrayField(env, obj, name); + assert(array); + void* value = convertJavaPointerToNative(env, array); + // allow returning NULL values + return value; } void setJavaPointer(JNIEnv* env, jobject obj, char* name, void* value) { - // allow NULL for value - jbyteArray array = convertNativePointerToJava(env, value); - assert(array); - setJavaByteArrayField(env, obj, name, array); - return; + // allow NULL for value + jbyteArray array = convertNativePointerToJava(env, value); + assert(array); + setJavaByteArrayField(env, obj, name, array); + return; } void* convertJavaPointerToNative(JNIEnv* env, jbyteArray pointer) { - // printf("convertJavaPointerToNative(): entering method\n"); + // printf("convertJavaPointerToNative(): entering method\n"); - void* returnPointer = NULL; + void* returnPointer = NULL; - // this is not the pointer, but the container of the pointer - assert(pointer); + // this is not the pointer, but the container of the pointer + assert(pointer); - jsize len = (*env)->GetArrayLength(env, pointer); - assert(len); - assert(len == sizeof(returnPointer)); + jsize len = (*env)->GetArrayLength(env, pointer); + assert(len); + assert(len == sizeof(returnPointer)); - jbyte* data = (*env)->GetByteArrayElements(env, pointer, NULL); - if (data == NULL) { - return NULL; // oome; - } - memcpy(&returnPointer, data, sizeof(returnPointer)); - (*env)->ReleaseByteArrayElements(env, pointer, data, 0); + jbyte* data = (*env)->GetByteArrayElements(env, pointer, NULL); + if (data == NULL) { + return NULL; // oome; + } + memcpy(&returnPointer, data, sizeof(returnPointer)); + (*env)->ReleaseByteArrayElements(env, pointer, data, 0); - // printf("convertJavaPointerToNative(): leaving method\n"); - return returnPointer; + // printf("convertJavaPointerToNative(): leaving method\n"); + return returnPointer; } jbyteArray convertNativePointerToJava(JNIEnv* env, void* pointer) { - // printf("convertNativePointerToJava(): entering method\n"); + // printf("convertNativePointerToJava(): entering method\n"); - jbyteArray array = (*env)->NewByteArray(env, sizeof(pointer)); - if (array == NULL) { - return 0; // oome? - } + jbyteArray array = (*env)->NewByteArray(env, sizeof(pointer)); + if (array == NULL) { + return 0; // oome? + } - jbyte* data = (*env)->GetByteArrayElements(env, array, NULL); - if (data == NULL) { - return 0; // oome - } + jbyte* data = (*env)->GetByteArrayElements(env, array, NULL); + if (data == NULL) { + return 0; // oome + } - memcpy(data, &pointer, sizeof(pointer)); - (*env)->ReleaseByteArrayElements(env, array, data, 0); + memcpy(data, &pointer, sizeof(pointer)); + (*env)->ReleaseByteArrayElements(env, array, data, 0); - // printf("convertNativePointerToJava(): leaving method\n"); + // printf("convertNativePointerToJava(): leaving method\n"); - return array; + return array; } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/native/jni-common.h --- a/pulseaudio/src/native/jni-common.h Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/native/jni-common.h Fri Jun 10 17:42:18 2011 -0400 @@ -45,14 +45,14 @@ */ typedef struct java_context_t { - JNIEnv* env; - jobject obj; + JNIEnv* env; + jobject obj; } java_context_t; /* Exception Handling */ void throwByName(JNIEnv* const env, const char* const name, - const char* const msg); + const char* const msg); #define ILLEGAL_ARGUMENT_EXCEPTION "java/lang/IllegalArgumentException" #define ILLEGAL_STATE_EXCEPTION "java/lang/IllegalStateException" @@ -72,7 +72,7 @@ jbyteArray getJavaByteArrayField(JNIEnv* env, jobject obj, char* name); void setJavaByteArrayField(JNIEnv* env, jobject obj, char* name, - jbyteArray array); + jbyteArray array); /* Pointers and Java */ diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/native/org_classpath_icedtea_pulseaudio_EventLoop.c --- a/pulseaudio/src/native/org_classpath_icedtea_pulseaudio_EventLoop.c Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/native/org_classpath_icedtea_pulseaudio_EventLoop.c Fri Jun 10 17:42:18 2011 -0400 @@ -50,82 +50,82 @@ JNIEnv* pulse_thread_env = NULL; void sink_list_success_cb(pa_context *context, const pa_sink_info *i, int eol, - void *userdata) { + void *userdata) { - if (eol == 0) { - jclass cls = (*pulse_thread_env)->GetObjectClass(pulse_thread_env, - java_context->obj); - assert(cls); - jstring name = (*pulse_thread_env)->NewStringUTF(pulse_thread_env, i->name); - assert(name); - jmethodID mid1 = (*pulse_thread_env)->GetMethodID(pulse_thread_env, cls, - "sink_callback", "(Ljava/lang/String;)V"); - assert(mid1); - (*pulse_thread_env)->CallVoidMethod(pulse_thread_env, - java_context->obj, mid1, name) ; - } else { - assert(pulse_thread_env); - notifyWaitingOperations(pulse_thread_env); - } + if (eol == 0) { + jclass cls = (*pulse_thread_env)->GetObjectClass(pulse_thread_env, + java_context->obj); + assert(cls); + jstring name = (*pulse_thread_env)->NewStringUTF(pulse_thread_env, i->name); + assert(name); + jmethodID mid1 = (*pulse_thread_env)->GetMethodID(pulse_thread_env, cls, + "sink_callback", "(Ljava/lang/String;)V"); + assert(mid1); + (*pulse_thread_env)->CallVoidMethod(pulse_thread_env, + java_context->obj, mid1, name) ; + } else { + assert(pulse_thread_env); + notifyWaitingOperations(pulse_thread_env); + } } void source_list_success_cb(pa_context *context, const pa_source_info *i, - int eol, void *userdata) { + int eol, void *userdata) { - if (eol == 0) { - jclass cls = (*pulse_thread_env)->GetObjectClass(pulse_thread_env, - java_context->obj); - assert(cls); - jstring name = (*pulse_thread_env)->NewStringUTF(pulse_thread_env, i->name); - assert(name); - jmethodID mid1 = (*pulse_thread_env)->GetMethodID(pulse_thread_env, cls, - "source_callback", "(Ljava/lang/String;)V"); - assert(mid1); - (*pulse_thread_env)->CallVoidMethod(pulse_thread_env, - java_context->obj, mid1, name) ; - } else { - assert(pulse_thread_env); - notifyWaitingOperations(pulse_thread_env); - } + if (eol == 0) { + jclass cls = (*pulse_thread_env)->GetObjectClass(pulse_thread_env, + java_context->obj); + assert(cls); + jstring name = (*pulse_thread_env)->NewStringUTF(pulse_thread_env, i->name); + assert(name); + jmethodID mid1 = (*pulse_thread_env)->GetMethodID(pulse_thread_env, cls, + "source_callback", "(Ljava/lang/String;)V"); + assert(mid1); + (*pulse_thread_env)->CallVoidMethod(pulse_thread_env, + java_context->obj, mid1, name) ; + } else { + assert(pulse_thread_env); + notifyWaitingOperations(pulse_thread_env); + } } static void context_change_callback(pa_context* context, void* userdata) { - assert(context); - assert(userdata == NULL); + assert(context); + assert(userdata == NULL); - //java_context_t* java_context = (java_context_t*)userdata; - JNIEnv* env = java_context->env; - jobject obj = java_context->obj; + //java_context_t* java_context = (java_context_t*)userdata; + JNIEnv* env = java_context->env; + jobject obj = java_context->obj; - // printf("context state changed to %d\n", pa_context_get_state(context)); + // printf("context state changed to %d\n", pa_context_get_state(context)); - /* Call the EventLoop.update method in java - * to handle all java-side events - */ - jclass cls = (*env)->GetObjectClass(env, obj); - assert(cls); - jmethodID mid = (*env)->GetMethodID(env, cls, "update", "(I)V"); - assert(mid); - (*env)->CallVoidMethod(env, obj, mid, pa_context_get_state(context)); - return; + /* Call the EventLoop.update method in java + * to handle all java-side events + */ + jclass cls = (*env)->GetObjectClass(env, obj); + assert(cls); + jmethodID mid = (*env)->GetMethodID(env, cls, "update", "(I)V"); + assert(mid); + (*env)->CallVoidMethod(env, obj, mid, pa_context_get_state(context)); + return; } static int poll_function(struct pollfd *ufds, unsigned long nfds, int timeout, - void *userdata) { + void *userdata) { - JNIEnv* env = pulse_thread_env; - assert(env); - jobject lockObject = getLockObject(env); + JNIEnv* env = pulse_thread_env; + assert(env); + jobject lockObject = getLockObject(env); - (*env)->MonitorExit(env, lockObject); + (*env)->MonitorExit(env, lockObject); - int value = poll(ufds, nfds, timeout); + int value = poll(ufds, nfds, timeout); - (*env)->MonitorEnter(env, lockObject); - return value; + (*env)->MonitorEnter(env, lockObject); + return value; } /* @@ -136,62 +136,62 @@ JNIEXPORT void JNICALL Java_org_classpath_icedtea_pulseaudio_EventLoop_native_1setup (JNIEnv* env, jobject obj, jstring appName, jstring server) { - assert(appName != NULL); + assert(appName != NULL); - // printf("native_setup() called\n"); - pa_mainloop *mainloop = pa_mainloop_new(); - assert(mainloop != NULL); - pa_mainloop_api *mainloop_api = pa_mainloop_get_api(mainloop); - assert(mainloop != NULL); + // printf("native_setup() called\n"); + pa_mainloop *mainloop = pa_mainloop_new(); + assert(mainloop != NULL); + pa_mainloop_api *mainloop_api = pa_mainloop_get_api(mainloop); + assert(mainloop != NULL); - pa_context *context = NULL; + pa_context *context = NULL; - const char* string_appName; - string_appName = (*env)->GetStringUTFChars(env, appName, NULL); - if (string_appName == NULL) { - return; /* a OutOfMemoryError thrown by vm */ - } - // printf("using appName : %s\n", string_appName); - context = pa_context_new(mainloop_api, string_appName); - assert(mainloop != NULL); - (*env)->ReleaseStringUTFChars(env, appName, string_appName); + const char* string_appName; + string_appName = (*env)->GetStringUTFChars(env, appName, NULL); + if (string_appName == NULL) { + return; /* a OutOfMemoryError thrown by vm */ + } + // printf("using appName : %s\n", string_appName); + context = pa_context_new(mainloop_api, string_appName); + assert(mainloop != NULL); + (*env)->ReleaseStringUTFChars(env, appName, string_appName); - obj = (*env)->NewGlobalRef(env, obj); + obj = (*env)->NewGlobalRef(env, obj); - java_context = malloc(sizeof(java_context_t)); - java_context->env = env; - pulse_thread_env = env; - java_context->obj = obj; + java_context = malloc(sizeof(java_context_t)); + java_context->env = env; + pulse_thread_env = env; + java_context->obj = obj; - pa_context_set_state_callback(context, context_change_callback, NULL); + pa_context_set_state_callback(context, context_change_callback, NULL); - if (server != NULL) { - /* obtain the server from the caller */ - const char* string_server = NULL; - string_server = (*env)->GetStringUTFChars(env, server, NULL); - if (string_server == NULL) { - /* error, so clean up */ - (*env)->DeleteGlobalRef(env, java_context->obj); - pa_context_disconnect(context); - pa_mainloop_free(mainloop); - free(java_context); - return; /* OutOfMemoryError */ - } - // printf("About to connect to server: %s\n", string_server); - pa_context_connect(context, string_server, 0, NULL); - (*env)->ReleaseStringUTFChars(env, appName, string_server); - } else { - // printf("using default server\n"); - pa_context_connect(context, NULL, 0, NULL); - } + if (server != NULL) { + /* obtain the server from the caller */ + const char* string_server = NULL; + string_server = (*env)->GetStringUTFChars(env, server, NULL); + if (string_server == NULL) { + /* error, so clean up */ + (*env)->DeleteGlobalRef(env, java_context->obj); + pa_context_disconnect(context); + pa_mainloop_free(mainloop); + free(java_context); + return; /* OutOfMemoryError */ + } + // printf("About to connect to server: %s\n", string_server); + pa_context_connect(context, string_server, 0, NULL); + (*env)->ReleaseStringUTFChars(env, appName, string_server); + } else { + // printf("using default server\n"); + pa_context_connect(context, NULL, 0, NULL); + } - // set polling function - pa_mainloop_set_poll_func(mainloop, poll_function, NULL); + // set polling function + pa_mainloop_set_poll_func(mainloop, poll_function, NULL); - setJavaPointer(env, obj, "mainloopPointer", mainloop); - setJavaPointer(env, obj, "contextPointer", context); - // printf("native_setup() returning\n"); - return; + setJavaPointer(env, obj, "mainloopPointer", mainloop); + setJavaPointer(env, obj, "contextPointer", context); + // printf("native_setup() returning\n"); + return; } /* @@ -202,24 +202,24 @@ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_EventLoop_native_1iterate (JNIEnv* env, jobject obj, jint timeout) { - pa_mainloop* mainloop = (pa_mainloop*) getJavaPointer(env, obj, "mainloopPointer"); - assert(mainloop); + pa_mainloop* mainloop = (pa_mainloop*) getJavaPointer(env, obj, "mainloopPointer"); + assert(mainloop); - int returnval; + int returnval; - returnval = pa_mainloop_prepare(mainloop, timeout); - if ( returnval < 0) { - return -1; - } - returnval = pa_mainloop_poll(mainloop); - if ( returnval < 0) { - return -1; - } - returnval = pa_mainloop_dispatch(mainloop); - if ( returnval < 0) { - return -1; - } - return returnval; + returnval = pa_mainloop_prepare(mainloop, timeout); + if ( returnval < 0) { + return -1; + } + returnval = pa_mainloop_poll(mainloop); + if ( returnval < 0) { + return -1; + } + returnval = pa_mainloop_dispatch(mainloop); + if ( returnval < 0) { + return -1; + } + return returnval; } @@ -231,11 +231,11 @@ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_EventLoop_nativeUpdateTargetPortNameList (JNIEnv* env, jobject obj) { - pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); - assert(context); - pa_operation *o = pa_context_get_sink_info_list(context, sink_list_success_cb, NULL); - assert(o); - return convertNativePointerToJava(env, o); + pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); + assert(context); + pa_operation *o = pa_context_get_sink_info_list(context, sink_list_success_cb, NULL); + assert(o); + return convertNativePointerToJava(env, o); } @@ -246,15 +246,15 @@ */ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_EventLoop_nativeUpdateSourcePortNameList (JNIEnv * env, jobject obj) { - pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); - assert(context); - pa_operation *o = pa_context_get_source_info_list(context, source_list_success_cb, NULL); - assert(o); - return convertNativePointerToJava(env, o); + pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); + assert(context); + pa_operation *o = pa_context_get_source_info_list(context, source_list_success_cb, NULL); + assert(o); + return convertNativePointerToJava(env, o); } static void context_drain_complete_callback(pa_context* context, void* userdata) { - pa_context_disconnect(context); + pa_context_disconnect(context); } @@ -266,32 +266,32 @@ JNIEXPORT void JNICALL Java_org_classpath_icedtea_pulseaudio_EventLoop_native_1shutdown (JNIEnv *env, jobject obj) { - // printf("native_shutdown() starting\n"); + // printf("native_shutdown() starting\n"); - pa_mainloop* mainloop = (pa_mainloop*) getJavaPointer(env, obj, "mainloopPointer"); - assert(mainloop != NULL); + pa_mainloop* mainloop = (pa_mainloop*) getJavaPointer(env, obj, "mainloopPointer"); + assert(mainloop != NULL); - pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); - assert(context != NULL); + pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); + assert(context != NULL); - pa_operation* o = pa_context_drain(context, context_drain_complete_callback, NULL); - if ( o == NULL) { - pa_context_disconnect(context); - pa_mainloop_free(mainloop); - } else { - pa_operation_unref(o); - } - - pa_context_unref(context); - (*env)->DeleteGlobalRef(env, java_context->obj); + pa_operation* o = pa_context_drain(context, context_drain_complete_callback, NULL); + if ( o == NULL) { + pa_context_disconnect(context); + pa_mainloop_free(mainloop); + } else { + pa_operation_unref(o); + } + + pa_context_unref(context); + (*env)->DeleteGlobalRef(env, java_context->obj); - free(java_context); - java_context = NULL; + free(java_context); + java_context = NULL; - setJavaPointer(env, obj, "mainloopPointer", NULL); - setJavaPointer(env, obj, "contextPointer", NULL); + setJavaPointer(env, obj, "mainloopPointer", NULL); + setJavaPointer(env, obj, "contextPointer", NULL); - // printf("native_shutdown() returning\n"); + // printf("native_shutdown() returning\n"); } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/native/org_classpath_icedtea_pulseaudio_Operation.c --- a/pulseaudio/src/native/org_classpath_icedtea_pulseaudio_Operation.c Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/native/org_classpath_icedtea_pulseaudio_Operation.c Fri Jun 10 17:42:18 2011 -0400 @@ -48,9 +48,9 @@ JNIEXPORT void JNICALL Java_org_classpath_icedtea_pulseaudio_Operation_native_1ref (JNIEnv* env, jobject obj) { - pa_operation* operation = (pa_operation*) getJavaPointer(env, obj, "operationPointer"); - assert(operation); - pa_operation_ref(operation); + pa_operation* operation = (pa_operation*) getJavaPointer(env, obj, "operationPointer"); + assert(operation); + pa_operation_ref(operation); } @@ -62,9 +62,9 @@ JNIEXPORT void JNICALL Java_org_classpath_icedtea_pulseaudio_Operation_native_1unref (JNIEnv* env, jobject obj) { - pa_operation* operation = (pa_operation*) getJavaPointer(env, obj, "operationPointer"); - assert(operation); - pa_operation_unref(operation); + pa_operation* operation = (pa_operation*) getJavaPointer(env, obj, "operationPointer"); + assert(operation); + pa_operation_unref(operation); } @@ -76,8 +76,8 @@ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Operation_native_1get_1state (JNIEnv *env, jobject obj) { - pa_operation* operation = (pa_operation*) getJavaPointer(env, obj, "operationPointer"); - assert(operation); - int state = pa_operation_get_state(operation); - return state; + pa_operation* operation = (pa_operation*) getJavaPointer(env, obj, "operationPointer"); + assert(operation); + int state = pa_operation_get_state(operation); + return state; } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/native/org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.c --- a/pulseaudio/src/native/org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.c Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/native/org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.c Fri Jun 10 17:42:18 2011 -0400 @@ -4,37 +4,37 @@ #include typedef struct java_context { - JNIEnv* env; - jobject obj; + JNIEnv* env; + jobject obj; } java_context; extern JNIEnv* pulse_thread_env; void source_callback(pa_context *context, int success, void *userdata) { - assert(context); - assert(pulse_thread_env); - notifyWaitingOperations(pulse_thread_env); + assert(context); + assert(pulse_thread_env); + notifyWaitingOperations(pulse_thread_env); } void get_source_volume_callback(pa_context *context, const pa_source_info *i, - int eol, void *userdata) { - assert(context); - assert(pulse_thread_env); - - if (eol == 0) { - // printf("%s\n", i->name); - jobject obj = (jobject) userdata; - assert(obj); - jclass cls = (*pulse_thread_env)->GetObjectClass(pulse_thread_env, obj); - assert(cls); - jmethodID mid1 = (*pulse_thread_env)->GetMethodID(pulse_thread_env, cls, - "update_channels_and_volume", "(IF)V"); - assert(mid1); - (*pulse_thread_env)->CallVoidMethod(pulse_thread_env, obj, mid1, - (int) (i->volume).channels, (float) (i->volume).values[0]) ; - } else { - notifyWaitingOperations(pulse_thread_env); - } + int eol, void *userdata) { + assert(context); + assert(pulse_thread_env); + + if (eol == 0) { + // printf("%s\n", i->name); + jobject obj = (jobject) userdata; + assert(obj); + jclass cls = (*pulse_thread_env)->GetObjectClass(pulse_thread_env, obj); + assert(cls); + jmethodID mid1 = (*pulse_thread_env)->GetMethodID(pulse_thread_env, cls, + "update_channels_and_volume", "(IF)V"); + assert(mid1); + (*pulse_thread_env)->CallVoidMethod(pulse_thread_env, obj, mid1, + (int) (i->volume).channels, (float) (i->volume).values[0]) ; + } else { + notifyWaitingOperations(pulse_thread_env); + } } /* @@ -44,23 +44,23 @@ */ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_PulseAudioSourcePort_native_1update_1volume (JNIEnv *env, jobject obj) { - jclass cls = (*env)->GetObjectClass(env, obj); - assert(cls); - jfieldID fid = (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;"); - assert(fid); - jstring jstr = (*env)->GetObjectField(env, obj, fid); - assert(jstr); - const char *name = (*env)->GetStringUTFChars(env, jstr, NULL); - if (name == NULL) { - return NULL; // oome - } - - pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); - assert(context); - obj = (*env)->NewGlobalRef(env, obj); - pa_operation *o = pa_context_get_source_info_by_name (context, (char*) name, get_source_volume_callback, obj); - assert(o); - return convertNativePointerToJava(env, o); + jclass cls = (*env)->GetObjectClass(env, obj); + assert(cls); + jfieldID fid = (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;"); + assert(fid); + jstring jstr = (*env)->GetObjectField(env, obj, fid); + assert(jstr); + const char *name = (*env)->GetStringUTFChars(env, jstr, NULL); + if (name == NULL) { + return NULL; // oome + } + + pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); + assert(context); + obj = (*env)->NewGlobalRef(env, obj); + pa_operation *o = pa_context_get_source_info_by_name (context, (char*) name, get_source_volume_callback, obj); + assert(o); + return convertNativePointerToJava(env, o); } /* @@ -70,33 +70,33 @@ */ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_PulseAudioSourcePort_native_1set_1volume (JNIEnv *env, jobject obj, jfloat value) { - jclass cls = (*env)->GetObjectClass(env, obj); - assert(cls); - - jfieldID fid = (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;"); - assert(fid); - - jstring jstr = (*env)->GetObjectField(env, obj, fid); - assert(jstr); - - const char *name = (*env)->GetStringUTFChars(env, jstr, NULL); - if (name == NULL) { - return NULL; // oome - } - - pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); - assert(context); - - obj = (*env)->NewGlobalRef(env, obj); - fid = (*env)->GetFieldID(env, cls, "channels", "I"); - assert(fid); - - jint channels = (*env)->GetIntField(env, obj, fid); - pa_cvolume cv; - - pa_operation *o = pa_context_set_source_volume_by_name (context, (char*) name,pa_cvolume_set(&cv, channels, value), source_callback, obj); - assert(o); - - return convertNativePointerToJava(env, o); + jclass cls = (*env)->GetObjectClass(env, obj); + assert(cls); + + jfieldID fid = (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;"); + assert(fid); + + jstring jstr = (*env)->GetObjectField(env, obj, fid); + assert(jstr); + + const char *name = (*env)->GetStringUTFChars(env, jstr, NULL); + if (name == NULL) { + return NULL; // oome + } + + pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); + assert(context); + + obj = (*env)->NewGlobalRef(env, obj); + fid = (*env)->GetFieldID(env, cls, "channels", "I"); + assert(fid); + + jint channels = (*env)->GetIntField(env, obj, fid); + pa_cvolume cv; + + pa_operation *o = pa_context_set_source_volume_by_name (context, (char*) name,pa_cvolume_set(&cv, channels, value), source_callback, obj); + assert(o); + + return convertNativePointerToJava(env, o); } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/native/org_classpath_icedtea_pulseaudio_PulseAudioTargetPort.c --- a/pulseaudio/src/native/org_classpath_icedtea_pulseaudio_PulseAudioTargetPort.c Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/native/org_classpath_icedtea_pulseaudio_PulseAudioTargetPort.c Fri Jun 10 17:42:18 2011 -0400 @@ -5,35 +5,35 @@ #include typedef struct java_context { - JNIEnv* env; - jobject obj; + JNIEnv* env; + jobject obj; } java_context; extern JNIEnv* pulse_thread_env; static void sink_callback(pa_context *context, int success, void *userdata) { - notifyWaitingOperations(pulse_thread_env); + notifyWaitingOperations(pulse_thread_env); } static void get_sink_volume_callback(pa_context *context, const pa_sink_info *i, - int eol, void *userdata) { - assert(context); - assert(pulse_thread_env); + int eol, void *userdata) { + assert(context); + assert(pulse_thread_env); - if (eol == 0) { - // printf("%s\n", i->name); - jobject obj = (jobject) userdata; - assert(obj); - jclass cls = (*pulse_thread_env)->GetObjectClass(pulse_thread_env, obj); - assert(cls); - jmethodID mid1 = (*pulse_thread_env)->GetMethodID(pulse_thread_env, cls, - "update_channels_and_volume", "(IF)V"); - assert(mid1); - (*pulse_thread_env)->CallVoidMethod(pulse_thread_env, obj, mid1, - (int) (i->volume).channels, (float) (i->volume).values[0]) ; - } else { - notifyWaitingOperations(pulse_thread_env); - } + if (eol == 0) { + // printf("%s\n", i->name); + jobject obj = (jobject) userdata; + assert(obj); + jclass cls = (*pulse_thread_env)->GetObjectClass(pulse_thread_env, obj); + assert(cls); + jmethodID mid1 = (*pulse_thread_env)->GetMethodID(pulse_thread_env, cls, + "update_channels_and_volume", "(IF)V"); + assert(mid1); + (*pulse_thread_env)->CallVoidMethod(pulse_thread_env, obj, mid1, + (int) (i->volume).channels, (float) (i->volume).values[0]) ; + } else { + notifyWaitingOperations(pulse_thread_env); + } } @@ -45,29 +45,29 @@ */ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_PulseAudioTargetPort_native_1update_1volume (JNIEnv *env, jobject obj) { - jclass cls = (*env)->GetObjectClass(env, obj); - assert(cls); - - jfieldID fid = (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;"); - assert(fid); - - jstring jstr = (*env)->GetObjectField(env, obj, fid); - assert(jstr); - - const char *name = (*env)->GetStringUTFChars(env, jstr, NULL); - if (name == NULL) { - return NULL; // oome - } - - pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); - assert(context); - - obj = (*env)->NewGlobalRef(env, obj); - - pa_operation *o = pa_context_get_sink_info_by_name (context, (char*) name, get_sink_volume_callback, obj); - assert(o); - - return convertNativePointerToJava(env, o); + jclass cls = (*env)->GetObjectClass(env, obj); + assert(cls); + + jfieldID fid = (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;"); + assert(fid); + + jstring jstr = (*env)->GetObjectField(env, obj, fid); + assert(jstr); + + const char *name = (*env)->GetStringUTFChars(env, jstr, NULL); + if (name == NULL) { + return NULL; // oome + } + + pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); + assert(context); + + obj = (*env)->NewGlobalRef(env, obj); + + pa_operation *o = pa_context_get_sink_info_by_name (context, (char*) name, get_sink_volume_callback, obj); + assert(o); + + return convertNativePointerToJava(env, o); } /* @@ -77,31 +77,31 @@ */ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_PulseAudioTargetPort_native_1set_1volume (JNIEnv *env, jobject obj, jfloat value) { - jclass cls = (*env)->GetObjectClass(env, obj); - assert(cls); - - jfieldID fid = (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;"); - assert(fid); - - jstring jstr = (*env)->GetObjectField(env, obj, fid); - assert(jstr); - - const char *name = (*env)->GetStringUTFChars(env, jstr, NULL); - if (name == NULL) { - return NULL; // return oome - } - - pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); - assert(context); - - obj = (*env)->NewGlobalRef(env, obj); - fid = (*env)->GetFieldID(env, cls, "channels", "I"); - assert(fid); - - jint channels = (*env)->GetIntField(env, obj, fid); - pa_cvolume cv; - pa_operation *o = pa_context_set_sink_volume_by_name (context, (char*) name,pa_cvolume_set(&cv, channels, value), sink_callback, obj); - assert(o); - - return convertNativePointerToJava(env, o); + jclass cls = (*env)->GetObjectClass(env, obj); + assert(cls); + + jfieldID fid = (*env)->GetFieldID(env, cls, "name", "Ljava/lang/String;"); + assert(fid); + + jstring jstr = (*env)->GetObjectField(env, obj, fid); + assert(jstr); + + const char *name = (*env)->GetStringUTFChars(env, jstr, NULL); + if (name == NULL) { + return NULL; // return oome + } + + pa_context* context = (pa_context*) getJavaPointer(env, obj, "contextPointer"); + assert(context); + + obj = (*env)->NewGlobalRef(env, obj); + fid = (*env)->GetFieldID(env, cls, "channels", "I"); + assert(fid); + + jint channels = (*env)->GetIntField(env, obj, fid); + pa_cvolume cv; + pa_operation *o = pa_context_set_sink_volume_by_name (context, (char*) name,pa_cvolume_set(&cv, channels, value), sink_callback, obj); + assert(o); + + return convertNativePointerToJava(env, o); } diff -r 134b14628088 -r fa76bb3356e5 pulseaudio/src/native/org_classpath_icedtea_pulseaudio_Stream.c --- a/pulseaudio/src/native/org_classpath_icedtea_pulseaudio_Stream.c Mon Feb 22 06:17:58 2016 +0000 +++ b/pulseaudio/src/native/org_classpath_icedtea_pulseaudio_Stream.c Fri Jun 10 17:42:18 2011 -0400 @@ -8,235 +8,235 @@ #define CONTEXT_POINTER "contextPointer" typedef struct java_context { - JNIEnv* env; - jobject obj; + JNIEnv* env; + jobject obj; } java_context; extern JNIEnv* pulse_thread_env; static void set_sink_input_volume_callback(pa_context* context, int success, - void* userdata) { - notifyWaitingOperations(pulse_thread_env); + void* userdata) { + notifyWaitingOperations(pulse_thread_env); } const char* getStringFromFormat(pa_sample_format_t format) { - const char* value; + const char* value; - if (format == PA_SAMPLE_U8) { - value = "PA_SAMPLE_U8"; - } else if (format == PA_SAMPLE_ALAW) { - value = "PA_SAMPLE_ALAW"; - } else if (format == PA_SAMPLE_ULAW) { - value = "PA_SAMPLE_ULAW"; - } else if (format == PA_SAMPLE_S16BE) { - value = "PA_SAMPLE_S16BE"; - } else if (format == PA_SAMPLE_S16LE) { - value = "PA_SAMPLE_S16LE"; - } else if (format == PA_SAMPLE_S32BE) { - value = "PA_SAMPLE_S32BE"; - } else if (format == PA_SAMPLE_S32LE) { - value = "PA_SAMPLE_S32LE"; - } else { - value = "PA_SAMPLE_INVALID"; - } + if (format == PA_SAMPLE_U8) { + value = "PA_SAMPLE_U8"; + } else if (format == PA_SAMPLE_ALAW) { + value = "PA_SAMPLE_ALAW"; + } else if (format == PA_SAMPLE_ULAW) { + value = "PA_SAMPLE_ULAW"; + } else if (format == PA_SAMPLE_S16BE) { + value = "PA_SAMPLE_S16BE"; + } else if (format == PA_SAMPLE_S16LE) { + value = "PA_SAMPLE_S16LE"; + } else if (format == PA_SAMPLE_S32BE) { + value = "PA_SAMPLE_S32BE"; + } else if (format == PA_SAMPLE_S32LE) { + value = "PA_SAMPLE_S32LE"; + } else { + value = "PA_SAMPLE_INVALID"; + } - return value; + return value; } pa_sample_format_t getFormatFromString(const char* encoding) { - pa_sample_format_t format; + pa_sample_format_t format; - if (strcmp(encoding, "PA_SAMPLE_U8") == 0) { - format = PA_SAMPLE_U8; - } else if (strcmp(encoding, "PA_SAMPLE_ALAW") == 0) { - format = PA_SAMPLE_ALAW; - } else if (strcmp(encoding, "PA_SAMPLE_ULAW;") == 0) { - format = PA_SAMPLE_ULAW; - } else if (strcmp(encoding, "PA_SAMPLE_S16BE") == 0) { - format = PA_SAMPLE_S16BE; - } else if (strcmp(encoding, "PA_SAMPLE_S16LE") == 0) { - format = PA_SAMPLE_S16LE; - } else if (strcmp(encoding, "PA_SAMPLE_S32BE") == 0) { - format = PA_SAMPLE_S32BE; - } else if (strcmp(encoding, "PA_SAMPLE_S32LE") == 0) { - format = PA_SAMPLE_S32LE; - } else { - format = PA_SAMPLE_INVALID; - } + if (strcmp(encoding, "PA_SAMPLE_U8") == 0) { + format = PA_SAMPLE_U8; + } else if (strcmp(encoding, "PA_SAMPLE_ALAW") == 0) { + format = PA_SAMPLE_ALAW; + } else if (strcmp(encoding, "PA_SAMPLE_ULAW;") == 0) { + format = PA_SAMPLE_ULAW; + } else if (strcmp(encoding, "PA_SAMPLE_S16BE") == 0) { + format = PA_SAMPLE_S16BE; + } else if (strcmp(encoding, "PA_SAMPLE_S16LE") == 0) { + format = PA_SAMPLE_S16LE; + } else if (strcmp(encoding, "PA_SAMPLE_S32BE") == 0) { + format = PA_SAMPLE_S32BE; + } else if (strcmp(encoding, "PA_SAMPLE_S32LE") == 0) { + format = PA_SAMPLE_S32LE; + } else { + format = PA_SAMPLE_INVALID; + } - return format; + return format; } static void stream_state_callback(pa_stream* stream, void *userdata) { - //printf("stream_state_callback called\n"); + //printf("stream_state_callback called\n"); - java_context* context = userdata; - assert(stream); - assert(context); - assert(context->env); - assert(context->obj); + java_context* context = userdata; + assert(stream); + assert(context); + assert(context->env); + assert(context->obj); - if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { - callJavaVoidMethod(context->env, context->obj, "stateCallback"); - } else { - callJavaVoidMethod(pulse_thread_env, context->obj, "stateCallback"); - } + if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { + callJavaVoidMethod(context->env, context->obj, "stateCallback"); + } else { + callJavaVoidMethod(pulse_thread_env, context->obj, "stateCallback"); + } } static void stream_write_callback(pa_stream *stream, size_t length, - void *userdata) { - // printf("stream_write_callback called\n"); + void *userdata) { + // printf("stream_write_callback called\n"); - java_context* context = userdata; - assert(stream); - assert(context); - assert(context->env); - assert(context->obj); + java_context* context = userdata; + assert(stream); + assert(context); + assert(context->env); + assert(context->obj); - if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { - callJavaVoidMethod(context->env, context->obj, "writeCallback"); - } else { - callJavaVoidMethod(pulse_thread_env, context->obj, "writeCallback"); - } + if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { + callJavaVoidMethod(context->env, context->obj, "writeCallback"); + } else { + callJavaVoidMethod(pulse_thread_env, context->obj, "writeCallback"); + } } static void stream_read_callback(pa_stream *stream, size_t length, - void *userdata) { - // printf("stream_read_callback called\n"); + void *userdata) { + // printf("stream_read_callback called\n"); - java_context* context = userdata; - assert(stream); - assert(context); - assert(context->env); - assert(context->obj); + java_context* context = userdata; + assert(stream); + assert(context); + assert(context->env); + assert(context->obj); - if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { - callJavaVoidMethod(context->env, context->obj, "readCallback"); - } else { - callJavaVoidMethod(pulse_thread_env, context->obj, "readCallback"); - } + if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { + callJavaVoidMethod(context->env, context->obj, "readCallback"); + } else { + callJavaVoidMethod(pulse_thread_env, context->obj, "readCallback"); + } } static void stream_overflow_callback(pa_stream *stream, void *userdata) { - //printf("stream_overflow_callback called\n"); + //printf("stream_overflow_callback called\n"); - java_context* context = userdata; - assert(stream); - assert(context); - assert(context->env); - assert(context->obj); + java_context* context = userdata; + assert(stream); + assert(context); + assert(context->env); + assert(context->obj); - if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { - callJavaVoidMethod(context->env, context->obj, "overflowCallback"); - } else { - callJavaVoidMethod(pulse_thread_env, context->obj, "overflowCallback"); - } + if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { + callJavaVoidMethod(context->env, context->obj, "overflowCallback"); + } else { + callJavaVoidMethod(pulse_thread_env, context->obj, "overflowCallback"); + } } static void stream_underflow_callback(pa_stream *stream, void *userdata) { - // printf("stream_underflow_callback called\n"); + // printf("stream_underflow_callback called\n"); - java_context* context = userdata; - assert(stream); - assert(context); - assert(context->env); - assert(context->obj); + java_context* context = userdata; + assert(stream); + assert(context); + assert(context->env); + assert(context->obj); - if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { - callJavaVoidMethod(context->env, context->obj, "underflowCallback"); - } else { - callJavaVoidMethod(pulse_thread_env, context->obj, "underflowCallback"); - } + if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { + callJavaVoidMethod(context->env, context->obj, "underflowCallback"); + } else { + callJavaVoidMethod(pulse_thread_env, context->obj, "underflowCallback"); + } } static void update_timing_info_callback(pa_stream* stream, int success, void* userdata) { - assert(stream); - JNIEnv* env = pulse_thread_env; - assert(env); + assert(stream); + JNIEnv* env = pulse_thread_env; + assert(env); - notifyWaitingOperations(env); + notifyWaitingOperations(env); - if (success == 0) { - throwByName(env, ILLEGAL_STATE_EXCEPTION, "drain failed"); - } + if (success == 0) { + throwByName(env, ILLEGAL_STATE_EXCEPTION, "drain failed"); + } } // requires pulseaudio 0.9.11 :( static void stream_started_callback(pa_stream *stream, void *userdata) { - // printf("stream_started_callback called\n"); - java_context* context = userdata; - assert(stream); - assert(context); - assert(context->env); - assert(context->obj); + // printf("stream_started_callback called\n"); + java_context* context = userdata; + assert(stream); + assert(context); + assert(context->env); + assert(context->obj); - if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { - callJavaVoidMethod(context->env, context->obj, - "playbackStartedCallback"); - } else { - callJavaVoidMethod(pulse_thread_env, context->obj, - "playbackStartedCallback"); - } + if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { + callJavaVoidMethod(context->env, context->obj, + "playbackStartedCallback"); + } else { + callJavaVoidMethod(pulse_thread_env, context->obj, + "playbackStartedCallback"); + } } static void stream_latency_update_callback(pa_stream *stream, void *userdata) { - // printf("stream_latency_update_callback called\n"); + // printf("stream_latency_update_callback called\n"); - java_context* context = userdata; - assert(stream); - assert(context); - assert(context->env); - assert(context->obj); + java_context* context = userdata; + assert(stream); + assert(context); + assert(context->env); + assert(context->obj); - if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { - callJavaVoidMethod(context->env, context->obj, "latencyUpdateCallback"); - } else { - callJavaVoidMethod(pulse_thread_env, context->obj, - "latencyUpdateCallback"); - } + if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { + callJavaVoidMethod(context->env, context->obj, "latencyUpdateCallback"); + } else { + callJavaVoidMethod(pulse_thread_env, context->obj, + "latencyUpdateCallback"); + } } static void stream_moved_callback(pa_stream *stream, void *userdata) { - // printf("stream_moved_callback called\n"); + // printf("stream_moved_callback called\n"); - java_context* context = userdata; - assert(stream); - assert(context); - assert(context->env); - assert(context->obj); + java_context* context = userdata; + assert(stream); + assert(context); + assert(context->env); + assert(context->obj); - if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { - callJavaVoidMethod(context->env, context->obj, "movedCallback"); - } else { - callJavaVoidMethod(pulse_thread_env, context->obj, "movedCallback"); - } + if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { + callJavaVoidMethod(context->env, context->obj, "movedCallback"); + } else { + callJavaVoidMethod(pulse_thread_env, context->obj, "movedCallback"); + } } static void stream_suspended_callback(pa_stream *stream, void *userdata) { - // printf("stream_suspended_callback called\n"); + // printf("stream_suspended_callback called\n"); - java_context* context = userdata; - assert(stream); - assert(context); - assert(context->env); - assert(context->obj); + java_context* context = userdata; + assert(stream); + assert(context); + assert(context->env); + assert(context->obj); - if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { - callJavaVoidMethod(context->env, context->obj, "suspendedCallback"); - } else { - callJavaVoidMethod(pulse_thread_env, context->obj, "suspendedCallback"); - } + if (pa_stream_get_state(stream) == PA_STREAM_CREATING) { + callJavaVoidMethod(context->env, context->obj, "suspendedCallback"); + } else { + callJavaVoidMethod(pulse_thread_env, context->obj, "suspendedCallback"); + } } @@ -247,72 +247,72 @@ */ JNIEXPORT void JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1new (JNIEnv* env, jobject obj, jbyteArray contextPointer, jstring nameString, - jstring encodingString, jint sampleRate, jint channels) { + jstring encodingString, jint sampleRate, jint channels) { - // printf("creating a new PulseAudio stream\n"); + // printf("creating a new PulseAudio stream\n"); - java_context* j_context = malloc(sizeof(java_context)); - assert(j_context); - j_context->env = env; - j_context->obj = (*env)->NewGlobalRef(env, obj); + java_context* j_context = malloc(sizeof(java_context)); + assert(j_context); + j_context->env = env; + j_context->obj = (*env)->NewGlobalRef(env, obj); - pa_context* context = convertJavaPointerToNative(env, contextPointer); - assert(context); + pa_context* context = convertJavaPointerToNative(env, contextPointer); + assert(context); - const char* name = NULL; - if (nameString) { - name = (*env)->GetStringUTFChars(env,nameString, NULL); - if (name == NULL) { - (*env)->DeleteGlobalRef(env, obj); - free(j_context); - return; // oome thrown - } - } + const char* name = NULL; + if (nameString) { + name = (*env)->GetStringUTFChars(env,nameString, NULL); + if (name == NULL) { + (*env)->DeleteGlobalRef(env, obj); + free(j_context); + return; // oome thrown + } + } - const char *encoding = (*env)->GetStringUTFChars(env, encodingString, NULL); - if( encoding == NULL) { - return; //oome thrown - } + const char *encoding = (*env)->GetStringUTFChars(env, encodingString, NULL); + if( encoding == NULL) { + return; //oome thrown + } - pa_sample_spec sample_spec; + pa_sample_spec sample_spec; - sample_spec.format = getFormatFromString(encoding); - sample_spec.rate = sampleRate; - sample_spec.channels = channels; + sample_spec.format = getFormatFromString(encoding); + sample_spec.rate = sampleRate; + sample_spec.channels = channels; - if ( !pa_sample_spec_valid(&sample_spec)) { - throwByName(env, "java/lang/IllegalArgumentException", "Invalid format"); - (*env)->ReleaseStringUTFChars(env, encodingString, encoding); - if (name) { - (*env)->ReleaseStringUTFChars(env, nameString,name); - } - return; - } + if ( !pa_sample_spec_valid(&sample_spec)) { + throwByName(env, "java/lang/IllegalArgumentException", "Invalid format"); + (*env)->ReleaseStringUTFChars(env, encodingString, encoding); + if (name) { + (*env)->ReleaseStringUTFChars(env, nameString,name); + } + return; + } - pa_stream* stream = pa_stream_new(context, name, &sample_spec, NULL); - assert(stream); - if (name) { - (*env)->ReleaseStringUTFChars(env, nameString,name); - } + pa_stream* stream = pa_stream_new(context, name, &sample_spec, NULL); + assert(stream); + if (name) { + (*env)->ReleaseStringUTFChars(env, nameString,name); + } - setJavaPointer(env, obj, "streamPointer", stream); + setJavaPointer(env, obj, "streamPointer", stream); - /* - * - * The stream has been created; now setup the callbacks - * so we can do somethig about them - * - */ + /* + * + * The stream has been created; now setup the callbacks + * so we can do somethig about them + * + */ - pa_stream_set_state_callback (stream, stream_state_callback, j_context); - pa_stream_set_write_callback (stream, stream_write_callback, j_context); - pa_stream_set_read_callback (stream, stream_read_callback, j_context); - pa_stream_set_overflow_callback (stream, stream_overflow_callback, j_context); - pa_stream_set_underflow_callback (stream, stream_underflow_callback, j_context); - pa_stream_set_started_callback (stream, stream_started_callback, j_context); - pa_stream_set_latency_update_callback (stream, stream_latency_update_callback, j_context); - pa_stream_set_moved_callback (stream, stream_moved_callback, j_context); - pa_stream_set_suspended_callback (stream, stream_suspended_callback, j_context); + pa_stream_set_state_callback (stream, stream_state_callback, j_context); + pa_stream_set_write_callback (stream, stream_write_callback, j_context); + pa_stream_set_read_callback (stream, stream_read_callback, j_context); + pa_stream_set_overflow_callback (stream, stream_overflow_callback, j_context); + pa_stream_set_underflow_callback (stream, stream_underflow_callback, j_context); + pa_stream_set_started_callback (stream, stream_started_callback, j_context); + pa_stream_set_latency_update_callback (stream, stream_latency_update_callback, j_context); + pa_stream_set_moved_callback (stream, stream_moved_callback, j_context); + pa_stream_set_suspended_callback (stream, stream_suspended_callback, j_context); } @@ -323,10 +323,10 @@ */ JNIEXPORT void JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1unref (JNIEnv* env, jobject obj) { - pa_stream* stream = getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - pa_stream_unref(stream); - setJavaPointer(env, obj, "streamPointer", NULL); + pa_stream* stream = getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + pa_stream_unref(stream); + setJavaPointer(env, obj, "streamPointer", NULL); } /* @@ -336,9 +336,9 @@ */ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1get_1state (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - return pa_stream_get_state(stream); + pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + return pa_stream_get_state(stream); } /* @@ -349,11 +349,11 @@ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1get_1context (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - pa_context* context = pa_stream_get_context(stream); - assert(context); - return convertNativePointerToJava(env, context); + pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + pa_context* context = pa_stream_get_context(stream); + assert(context); + return convertNativePointerToJava(env, context); } /* @@ -363,9 +363,9 @@ */ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1get_1index (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - return pa_stream_get_index(stream); + pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + return pa_stream_get_index(stream); } /* @@ -375,9 +375,9 @@ */ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1get_1device_1index (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - return pa_stream_get_device_index(stream); + pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + return pa_stream_get_device_index(stream); } /* @@ -387,11 +387,11 @@ */ JNIEXPORT jstring JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1get_1device_1name (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - const char* name = pa_stream_get_device_name(stream); - assert(name); - return (*env)->NewStringUTF(env, name); + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + const char* name = pa_stream_get_device_name(stream); + assert(name); + return (*env)->NewStringUTF(env, name); } /* @@ -401,9 +401,9 @@ */ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1is_1suspended (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - return pa_stream_is_suspended(stream); + pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + return pa_stream_is_suspended(stream); } /* @@ -413,54 +413,54 @@ */ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1connect_1playback (JNIEnv* env, jobject obj, jstring device, jint bufferMaxLength, - jint bufferTargetLength, jint bufferPreBuffering, - jint bufferMinimumRequest, jint bufferFragmentSize, jint flags, - jbyteArray volumePointer, jbyteArray sync_streamPointer) { + jint bufferTargetLength, jint bufferPreBuffering, + jint bufferMinimumRequest, jint bufferFragmentSize, jint flags, + jbyteArray volumePointer, jbyteArray sync_streamPointer) { - pa_stream *sync_stream; - if(sync_streamPointer != NULL) { - sync_stream = convertJavaPointerToNative(env, sync_streamPointer); - printf("Master stream is %p\n", sync_stream); - } else { - sync_stream = NULL; - } + pa_stream *sync_stream; + if(sync_streamPointer != NULL) { + sync_stream = convertJavaPointerToNative(env, sync_streamPointer); + printf("Master stream is %p\n", sync_stream); + } else { + sync_stream = NULL; + } - pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); + pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); - pa_buffer_attr buffer_attr; + pa_buffer_attr buffer_attr; - memset(&buffer_attr, 0, sizeof(buffer_attr)); + memset(&buffer_attr, 0, sizeof(buffer_attr)); - buffer_attr.maxlength = (uint32_t) bufferMaxLength; - buffer_attr.tlength = (uint32_t) bufferTargetLength; - buffer_attr.prebuf = (uint32_t) bufferPreBuffering; - buffer_attr.minreq = (uint32_t) bufferMinimumRequest; + buffer_attr.maxlength = (uint32_t) bufferMaxLength; + buffer_attr.tlength = (uint32_t) bufferTargetLength; + buffer_attr.prebuf = (uint32_t) bufferPreBuffering; + buffer_attr.minreq = (uint32_t) bufferMinimumRequest; - /* - printf("buffer maxlength: %u\n", buffer_attr.maxlength); - printf("buffer tlength: %u\n", buffer_attr.tlength); - printf("buffer prebuf: %u\n", buffer_attr.prebuf); - printf("buffer minreq: %u\n", buffer_attr.minreq); - printf("buffer fragsize: %u\n", buffer_attr.fragsize); - */ + /* + printf("buffer maxlength: %u\n", buffer_attr.maxlength); + printf("buffer tlength: %u\n", buffer_attr.tlength); + printf("buffer prebuf: %u\n", buffer_attr.prebuf); + printf("buffer minreq: %u\n", buffer_attr.minreq); + printf("buffer fragsize: %u\n", buffer_attr.fragsize); + */ - const char* dev = NULL; - if (device != NULL) { - dev = (*env)->GetStringUTFChars(env, device, NULL); - if (dev == NULL) { - return -1; // oome thrown - } - } - /* Set flags to 0 to fix problem with draining before calling start, might need to - be changed back to PA_STREAM_START_CORKED in the future, if we'll be able to implement - synchronization*/ - int value = pa_stream_connect_playback(stream, dev, &buffer_attr, PA_STREAM_START_CORKED, NULL, sync_stream); + const char* dev = NULL; + if (device != NULL) { + dev = (*env)->GetStringUTFChars(env, device, NULL); + if (dev == NULL) { + return -1; // oome thrown + } + } + /* Set flags to 0 to fix problem with draining before calling start, might need to + be changed back to PA_STREAM_START_CORKED in the future, if we'll be able to implement + synchronization*/ + int value = pa_stream_connect_playback(stream, dev, &buffer_attr, PA_STREAM_START_CORKED, NULL, sync_stream); - if (dev != NULL) { - (*env)->ReleaseStringUTFChars(env, device, dev); - dev = NULL; - } - return value; + if (dev != NULL) { + (*env)->ReleaseStringUTFChars(env, device, dev); + dev = NULL; + } + return value; } /* @@ -470,41 +470,41 @@ */ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1connect_1record (JNIEnv* env, jobject obj, jstring device, jint bufferMaxLength, - jint bufferTargetLength, jint bufferPreBuffereing, - jint bufferMinimumRequest, jint bufferFragmentSize, jint flags, - jbyteArray volumePointer, jbyteArray sync_streamPointer) { + jint bufferTargetLength, jint bufferPreBuffereing, + jint bufferMinimumRequest, jint bufferFragmentSize, jint flags, + jbyteArray volumePointer, jbyteArray sync_streamPointer) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); - pa_buffer_attr buffer_attr; - memset(&buffer_attr, 0 , sizeof(buffer_attr)); - buffer_attr.maxlength = (uint32_t) bufferMaxLength; - buffer_attr.fragsize = (uint32_t) bufferFragmentSize; + pa_buffer_attr buffer_attr; + memset(&buffer_attr, 0 , sizeof(buffer_attr)); + buffer_attr.maxlength = (uint32_t) bufferMaxLength; + buffer_attr.fragsize = (uint32_t) bufferFragmentSize; - /* - printf("buffer maxlength: %u\n", buffer_attr.maxlength); - printf("buffer tlength: %u\n", buffer_attr.tlength); - printf("buffer prebuf: %u\n", buffer_attr.prebuf); - printf("buffer minreq: %u\n", buffer_attr.minreq); - printf("buffer fragsize: %u\n", buffer_attr.fragsize); - */ + /* + printf("buffer maxlength: %u\n", buffer_attr.maxlength); + printf("buffer tlength: %u\n", buffer_attr.tlength); + printf("buffer prebuf: %u\n", buffer_attr.prebuf); + printf("buffer minreq: %u\n", buffer_attr.minreq); + printf("buffer fragsize: %u\n", buffer_attr.fragsize); + */ - const char* dev = NULL; - if (device != NULL) { - dev = (*env)->GetStringUTFChars(env, device, NULL); - if (dev == NULL) { - return -1; // oome thrown - } - } + const char* dev = NULL; + if (device != NULL) { + dev = (*env)->GetStringUTFChars(env, device, NULL); + if (dev == NULL) { + return -1; // oome thrown + } + } - int value = pa_stream_connect_record(stream, dev, &buffer_attr, flags); + int value = pa_stream_connect_record(stream, dev, &buffer_attr, flags); - if (dev != NULL) { - (*env)->ReleaseStringUTFChars(env, device, dev); - dev = NULL; - } - return value; + if (dev != NULL) { + (*env)->ReleaseStringUTFChars(env, device, dev); + dev = NULL; + } + return value; } @@ -515,11 +515,11 @@ */ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1disconnect (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - int return_value = pa_stream_disconnect(stream); + pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + int return_value = pa_stream_disconnect(stream); - return return_value; + return return_value; } /* @@ -529,16 +529,16 @@ */ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1write (JNIEnv* env, jobject obj, jbyteArray data, jint offset, jint data_length) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - jbyte* data_buffer = (*env)->GetByteArrayElements(env, data, NULL); - if (data_buffer == NULL) { - return -1; // oome thrown - } - jbyte* buffer_start = data_buffer + offset; - int value = pa_stream_write(stream, buffer_start, data_length, NULL, 0, PA_SEEK_RELATIVE); - (*env)->ReleaseByteArrayElements(env, data, data_buffer, 0); - return value; + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + jbyte* data_buffer = (*env)->GetByteArrayElements(env, data, NULL); + if (data_buffer == NULL) { + return -1; // oome thrown + } + jbyte* buffer_start = data_buffer + offset; + int value = pa_stream_write(stream, buffer_start, data_length, NULL, 0, PA_SEEK_RELATIVE); + (*env)->ReleaseByteArrayElements(env, data, data_buffer, 0); + return value; } /* @@ -549,29 +549,29 @@ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1peek (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - const void* startLocation; - size_t count; + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + const void* startLocation; + size_t count; - if ( pa_stream_peek(stream, &startLocation, &count) < 0 ) { - return NULL; - } + if ( pa_stream_peek(stream, &startLocation, &count) < 0 ) { + return NULL; + } - /* no data available */ - if (startLocation == NULL) { - return NULL; - } + /* no data available */ + if (startLocation == NULL) { + return NULL; + } - jsize length = count; - jbyteArray data = (*env)->NewByteArray(env, length); + jsize length = count; + jbyteArray data = (*env)->NewByteArray(env, length); - if ( data == NULL) { - return NULL; // oome thrown - } + if ( data == NULL) { + return NULL; // oome thrown + } - (*env)->SetByteArrayRegion(env, data, 0, count, startLocation); - return data; + (*env)->SetByteArrayRegion(env, data, 0, count, startLocation); + return data; } /* @@ -581,9 +581,9 @@ */ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1drop (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - return pa_stream_drop(stream); + pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + return pa_stream_drop(stream); } /* @@ -593,12 +593,12 @@ */ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1writable_1size (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - if(!stream) { - return 0; - } - size_t size = pa_stream_writable_size(stream); - return size; + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + if(!stream) { + return 0; + } + size_t size = pa_stream_writable_size(stream); + return size; } @@ -609,22 +609,22 @@ */ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1readable_1size (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - return pa_stream_readable_size(stream); + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + return pa_stream_readable_size(stream); } static void drain_callback(pa_stream* stream, int success, void* userdata) { - assert(stream); - JNIEnv* env = pulse_thread_env; - assert(env); + assert(stream); + JNIEnv* env = pulse_thread_env; + assert(env); - notifyWaitingOperations(env); + notifyWaitingOperations(env); - if (success == 0) { - throwByName(env, ILLEGAL_STATE_EXCEPTION, "drain failed"); - } + if (success == 0) { + throwByName(env, ILLEGAL_STATE_EXCEPTION, "drain failed"); + } } @@ -635,11 +635,11 @@ */ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1drain (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - pa_operation* operation = pa_stream_drain(stream, drain_callback, NULL); - assert(operation); - return convertNativePointerToJava(env, operation); + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + pa_operation* operation = pa_stream_drain(stream, drain_callback, NULL); + assert(operation); + return convertNativePointerToJava(env, operation); } /* @@ -649,23 +649,23 @@ */ JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1is_1corked (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - return pa_stream_is_corked(stream); + pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + return pa_stream_is_corked(stream); } static void cork_callback(pa_stream* stream, int success, void* userdata) { - java_context* context = userdata; - assert(stream); - assert(context); - JNIEnv* env = pulse_thread_env; - assert(env); - notifyWaitingOperations(env); + java_context* context = userdata; + assert(stream); + assert(context); + JNIEnv* env = pulse_thread_env; + assert(env); + notifyWaitingOperations(env); - if (success == 0) { - throwByName(env, ILLEGAL_STATE_EXCEPTION, "cork failed"); - } + if (success == 0) { + throwByName(env, ILLEGAL_STATE_EXCEPTION, "cork failed"); + } } @@ -676,26 +676,26 @@ */ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1cork (JNIEnv* env, jobject obj, jint yes) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - java_context* j_context = malloc(sizeof(java_context)); - assert(j_context); - j_context->env = env; - j_context->obj = (*env)->NewGlobalRef(env, obj); - pa_operation* operation = pa_stream_cork(stream, yes, cork_callback, j_context); - assert(operation); - return convertNativePointerToJava(env, operation); + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + java_context* j_context = malloc(sizeof(java_context)); + assert(j_context); + j_context->env = env; + j_context->obj = (*env)->NewGlobalRef(env, obj); + pa_operation* operation = pa_stream_cork(stream, yes, cork_callback, j_context); + assert(operation); + return convertNativePointerToJava(env, operation); } static void flush_callback(pa_stream* stream, int success, void* userdata) { - assert(stream); - JNIEnv* env = pulse_thread_env; - assert(env); - notifyWaitingOperations(env); + assert(stream); + JNIEnv* env = pulse_thread_env; + assert(env); + notifyWaitingOperations(env); - if (success == 0) { - throwByName(env, ILLEGAL_STATE_EXCEPTION, "flush failed"); - } + if (success == 0) { + throwByName(env, ILLEGAL_STATE_EXCEPTION, "flush failed"); + } } @@ -706,22 +706,22 @@ */ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1flush (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - pa_operation* operation = pa_stream_flush(stream, flush_callback, NULL); - assert(operation); - return convertNativePointerToJava(env, operation); + pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + pa_operation* operation = pa_stream_flush(stream, flush_callback, NULL); + assert(operation); + return convertNativePointerToJava(env, operation); } static void trigger_callback(pa_stream* stream, int success, void* userdata) { - assert(stream); - JNIEnv* env = pulse_thread_env; - assert(env); - notifyWaitingOperations(env); + assert(stream); + JNIEnv* env = pulse_thread_env; + assert(env); + notifyWaitingOperations(env); - if (success == 0) { - throwByName(env, ILLEGAL_STATE_EXCEPTION, "trigger failed"); - } + if (success == 0) { + throwByName(env, ILLEGAL_STATE_EXCEPTION, "trigger failed"); + } } @@ -732,21 +732,21 @@ */ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1trigger (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - pa_operation* operation = pa_stream_trigger(stream, trigger_callback, NULL); - assert(operation); - return convertNativePointerToJava(env, operation); + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + pa_operation* operation = pa_stream_trigger(stream, trigger_callback, NULL); + assert(operation); + return convertNativePointerToJava(env, operation); } static void set_name_callback(pa_stream* stream, int success, void* userdata) { - assert(stream); - JNIEnv* env = pulse_thread_env; - notifyWaitingOperations(env); + assert(stream); + JNIEnv* env = pulse_thread_env; + notifyWaitingOperations(env); - if (success == 0) { - throwByName(env, ILLEGAL_STATE_EXCEPTION, "set_name failed"); - } + if (success == 0) { + throwByName(env, ILLEGAL_STATE_EXCEPTION, "set_name failed"); + } } /* @@ -756,20 +756,20 @@ */ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1set_1name (JNIEnv* env, jobject obj, jstring newName) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); - const char* name; - name = (*env)->GetStringUTFChars(env, newName, NULL); - if (name == NULL) { - return 0; // OutOfMemoryError already thrown - } + const char* name; + name = (*env)->GetStringUTFChars(env, newName, NULL); + if (name == NULL) { + return 0; // OutOfMemoryError already thrown + } - pa_operation* operation = pa_stream_set_name(stream, name, set_name_callback, NULL); - assert(operation); - (*env)->ReleaseStringUTFChars(env, newName, name); + pa_operation* operation = pa_stream_set_name(stream, name, set_name_callback, NULL); + assert(operation); + (*env)->ReleaseStringUTFChars(env, newName, name); - return convertNativePointerToJava(env, operation); + return convertNativePointerToJava(env, operation); } /* @@ -779,14 +779,14 @@ */ JNIEXPORT jlong JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1get_1time (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); - pa_usec_t time = 0; - int result = pa_stream_get_time (stream,&time); - assert(result == 0); + pa_usec_t time = 0; + int result = pa_stream_get_time (stream,&time); + assert(result == 0); - return time; + return time; } @@ -797,14 +797,14 @@ */ JNIEXPORT jlong JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1get_1latency (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - pa_usec_t returnValue = 0; - int negative = 0; - int result = pa_stream_get_latency ( stream, &returnValue, &negative); - assert(result == 0); - assert(negative == 0); - return returnValue; + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + pa_usec_t returnValue = 0; + int negative = 0; + int result = pa_stream_get_latency ( stream, &returnValue, &negative); + assert(result == 0); + assert(negative == 0); + return returnValue; } /* @@ -814,30 +814,30 @@ */ JNIEXPORT jobject JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1get_1sample_1spec (JNIEnv* env, jobject obj) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); - const pa_sample_spec* sample_spec = pa_stream_get_sample_spec(stream); - assert(sample_spec); + const pa_sample_spec* sample_spec = pa_stream_get_sample_spec(stream); + assert(sample_spec); - char* name = "Lorg/classpath/icedtea/pulseaudio/StreamSampleSpecification;"; - jclass cls = (*env)->FindClass(env, name); - assert(cls); - jmethodID constructor_mid = (*env)->GetMethodID(env, cls, "", "V"); - assert(constructor_mid); + char* name = "Lorg/classpath/icedtea/pulseaudio/StreamSampleSpecification;"; + jclass cls = (*env)->FindClass(env, name); + assert(cls); + jmethodID constructor_mid = (*env)->GetMethodID(env, cls, "", "V"); + assert(constructor_mid); - const char* formatString = getStringFromFormat(sample_spec->format); - assert(formatString); - int rate = sample_spec->rate; - int channels = sample_spec->channels; + const char* formatString = getStringFromFormat(sample_spec->format); + assert(formatString); + int rate = sample_spec->rate; + int channels = sample_spec->channels; - jstring format = (*env)->NewStringUTF(env, formatString); - if ( format == NULL) { - return NULL; // oome - } - jobject return_object = (*env)->NewObject(env, cls, constructor_mid, format, rate, channels); + jstring format = (*env)->NewStringUTF(env, formatString); + if ( format == NULL) { + return NULL; // oome + } + jobject return_object = (*env)->NewObject(env, cls, constructor_mid, format, rate, channels); - return return_object; + return return_object; } /* @@ -848,41 +848,41 @@ JNIEXPORT jobject JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1get_1buffer_1attr (JNIEnv* env, jobject obj) { - // printf("in native_pa_stream_get_buffer_attributes"); + // printf("in native_pa_stream_get_buffer_attributes"); - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - const pa_buffer_attr* buffer = pa_stream_get_buffer_attr(stream); - assert(buffer); + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + const pa_buffer_attr* buffer = pa_stream_get_buffer_attr(stream); + assert(buffer); - const char* class_name = "Lorg/classpath/icedtea/pulseaudio/StreamBufferAttributes;"; - jclass cls = (*env)->FindClass(env, class_name); - assert(cls); - jmethodID constructor_mid = (*env)->GetMethodID(env, cls, "", "(IIIII)V"); - assert(constructor_mid); - jint maxLength = buffer->maxlength; - jint targetLength = buffer->tlength; - jint preBuffering = buffer->prebuf; - jint minimumRequest = buffer->minreq; - jint fragmentSize = buffer->fragsize; + const char* class_name = "Lorg/classpath/icedtea/pulseaudio/StreamBufferAttributes;"; + jclass cls = (*env)->FindClass(env, class_name); + assert(cls); + jmethodID constructor_mid = (*env)->GetMethodID(env, cls, "", "(IIIII)V"); + assert(constructor_mid); + jint maxLength = buffer->maxlength; + jint targetLength = buffer->tlength; + jint preBuffering = buffer->prebuf; + jint minimumRequest = buffer->minreq; + jint fragmentSize = buffer->fragsize; - jobject return_object = (*env)->NewObject(env, cls, constructor_mid, maxLength, targetLength, - preBuffering, minimumRequest, fragmentSize); + jobject return_object = (*env)->NewObject(env, cls, constructor_mid, maxLength, targetLength, + preBuffering, minimumRequest, fragmentSize); - return return_object; + return return_object; } static void set_buffer_attr_callback(pa_stream* stream, int success, - void* userdata) { + void* userdata) { - assert(stream); - JNIEnv* env = pulse_thread_env; - assert(env); - notifyWaitingOperations(env); + assert(stream); + JNIEnv* env = pulse_thread_env; + assert(env); + notifyWaitingOperations(env); - if (success == 0) { - throwByName(env, ILLEGAL_STATE_EXCEPTION, "set_buffer_attr failed"); - } + if (success == 0) { + throwByName(env, ILLEGAL_STATE_EXCEPTION, "set_buffer_attr failed"); + } } /* @@ -893,58 +893,58 @@ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1set_1buffer_1attr (JNIEnv* env, jobject obj, jobject bufferAttributeObject) { - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); - jclass cls = (*env)->GetObjectClass(env, bufferAttributeObject); - assert(cls); + jclass cls = (*env)->GetObjectClass(env, bufferAttributeObject); + assert(cls); - pa_buffer_attr buffer; + pa_buffer_attr buffer; - jmethodID getMaxLengthID = (*env)->GetMethodID(env,cls,"getMaxLength","()I"); - assert(getMaxLengthID); - buffer.maxlength = (uint32_t) (*env)->CallIntMethod(env, bufferAttributeObject, getMaxLengthID); + jmethodID getMaxLengthID = (*env)->GetMethodID(env,cls,"getMaxLength","()I"); + assert(getMaxLengthID); + buffer.maxlength = (uint32_t) (*env)->CallIntMethod(env, bufferAttributeObject, getMaxLengthID); - jmethodID getTargetLengthID = (*env)->GetMethodID(env,cls,"getTargetLength","()I"); - assert(getTargetLengthID); - buffer.tlength = (uint32_t) (*env)->CallIntMethod(env, bufferAttributeObject, getTargetLengthID); + jmethodID getTargetLengthID = (*env)->GetMethodID(env,cls,"getTargetLength","()I"); + assert(getTargetLengthID); + buffer.tlength = (uint32_t) (*env)->CallIntMethod(env, bufferAttributeObject, getTargetLengthID); - jmethodID getPreBufferingID = (*env)->GetMethodID(env,cls,"getPreBuffering","()I"); - assert(getPreBufferingID); - buffer.prebuf = (uint32_t) (*env)->CallIntMethod(env, bufferAttributeObject, getPreBufferingID); + jmethodID getPreBufferingID = (*env)->GetMethodID(env,cls,"getPreBuffering","()I"); + assert(getPreBufferingID); + buffer.prebuf = (uint32_t) (*env)->CallIntMethod(env, bufferAttributeObject, getPreBufferingID); - jmethodID getMinimumRequestID = (*env)->GetMethodID(env, cls, "getMinimumRequest", "()I"); - assert(getMinimumRequestID); - buffer.minreq = (uint32_t) (*env)->CallIntMethod(env, bufferAttributeObject, getMinimumRequestID ); + jmethodID getMinimumRequestID = (*env)->GetMethodID(env, cls, "getMinimumRequest", "()I"); + assert(getMinimumRequestID); + buffer.minreq = (uint32_t) (*env)->CallIntMethod(env, bufferAttributeObject, getMinimumRequestID ); - jmethodID getFragmentSizeID = (*env)->GetMethodID(env,cls,"getFragmentSize","()I"); - assert(getFragmentSizeID); - buffer.fragsize = (uint32_t) (*env)->CallIntMethod(env, bufferAttributeObject, getFragmentSizeID ); + jmethodID getFragmentSizeID = (*env)->GetMethodID(env,cls,"getFragmentSize","()I"); + assert(getFragmentSizeID); + buffer.fragsize = (uint32_t) (*env)->CallIntMethod(env, bufferAttributeObject, getFragmentSizeID ); - /* - const pa_buffer_attr* old_buffer = pa_stream_get_buffer_attr(stream); + /* + const pa_buffer_attr* old_buffer = pa_stream_get_buffer_attr(stream); - printf("old buffer values: %u %u %u %u %u\n", old_buffer->maxlength, old_buffer->tlength, old_buffer->prebuf, old_buffer->minreq, old_buffer->fragsize); + printf("old buffer values: %u %u %u %u %u\n", old_buffer->maxlength, old_buffer->tlength, old_buffer->prebuf, old_buffer->minreq, old_buffer->fragsize); - printf("want these values: %u %u %u %u %u\n", buffer.maxlength, buffer.tlength, buffer.prebuf, buffer.minreq, buffer.fragsize); - */ + printf("want these values: %u %u %u %u %u\n", buffer.maxlength, buffer.tlength, buffer.prebuf, buffer.minreq, buffer.fragsize); + */ - pa_operation* operation = pa_stream_set_buffer_attr(stream, &buffer, set_buffer_attr_callback, NULL); + pa_operation* operation = pa_stream_set_buffer_attr(stream, &buffer, set_buffer_attr_callback, NULL); - assert(operation); - return convertNativePointerToJava(env,operation); + assert(operation); + return convertNativePointerToJava(env,operation); } static void update_sample_rate_callback(pa_stream* stream, int success, - void* userdata) { - assert(stream); - JNIEnv* env = pulse_thread_env; - assert(env); - notifyWaitingOperations(env); + void* userdata) { + assert(stream); + JNIEnv* env = pulse_thread_env; + assert(env); + notifyWaitingOperations(env); - if (success == 0) { - throwByName(env, ILLEGAL_STATE_EXCEPTION, "update_sampl_rate failed"); - } + if (success == 0) { + throwByName(env, ILLEGAL_STATE_EXCEPTION, "update_sampl_rate failed"); + } } /* @@ -955,13 +955,13 @@ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1update_1sample_1rate (JNIEnv* env, jobject obj, jint newRate) { - uint32_t rate = (uint32_t) newRate; + uint32_t rate = (uint32_t) newRate; - pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - pa_operation* operation = pa_stream_update_sample_rate(stream,rate, update_sample_rate_callback, NULL); - assert(operation); - return convertNativePointerToJava(env, operation); + pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + pa_operation* operation = pa_stream_update_sample_rate(stream,rate, update_sample_rate_callback, NULL); + assert(operation); + return convertNativePointerToJava(env, operation); } @@ -973,45 +973,45 @@ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1set_1volume (JNIEnv *env, jobject obj, jfloat new_volume) { - pa_stream *stream = getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - pa_context *context = pa_stream_get_context(stream); - assert(context); + pa_stream *stream = getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + pa_context *context = pa_stream_get_context(stream); + assert(context); - int stream_id = pa_stream_get_index(stream); - int channels = pa_stream_get_sample_spec(stream)->channels; - pa_cvolume cv; + int stream_id = pa_stream_get_index(stream); + int channels = pa_stream_get_sample_spec(stream)->channels; + pa_cvolume cv; - pa_operation* o = pa_context_set_sink_input_volume(context, stream_id, pa_cvolume_set(&cv, channels, new_volume), set_sink_input_volume_callback, NULL); - assert(o); + pa_operation* o = pa_context_set_sink_input_volume(context, stream_id, pa_cvolume_set(&cv, channels, new_volume), set_sink_input_volume_callback, NULL); + assert(o); - return convertNativePointerToJava(env, o); + return convertNativePointerToJava(env, o); } static void get_sink_input_volume_callback(pa_context *context, const pa_sink_input_info *i, - int eol, void *userdata) { + int eol, void *userdata) { - JNIEnv* env = pulse_thread_env; + JNIEnv* env = pulse_thread_env; - assert(context); - assert(env); - jobject obj = (jobject) userdata; - assert(obj); + assert(context); + assert(env); + jobject obj = (jobject) userdata; + assert(obj); - if (eol == 0) { - jclass cls = (*pulse_thread_env)->GetObjectClass(pulse_thread_env, obj); - assert(cls); - jmethodID mid1 = (*pulse_thread_env)->GetMethodID(pulse_thread_env, cls, - "update_channels_and_volume", "(IF)V"); - assert(mid1); - (*pulse_thread_env)->CallVoidMethod(pulse_thread_env, obj, mid1, - (int) (i->volume).channels, (float) (i->volume).values[0]) ; - } else { - notifyWaitingOperations(pulse_thread_env); - (*env)->DeleteGlobalRef(env, obj); - } + if (eol == 0) { + jclass cls = (*pulse_thread_env)->GetObjectClass(pulse_thread_env, obj); + assert(cls); + jmethodID mid1 = (*pulse_thread_env)->GetMethodID(pulse_thread_env, cls, + "update_channels_and_volume", "(IF)V"); + assert(mid1); + (*pulse_thread_env)->CallVoidMethod(pulse_thread_env, obj, mid1, + (int) (i->volume).channels, (float) (i->volume).values[0]) ; + } else { + notifyWaitingOperations(pulse_thread_env); + (*env)->DeleteGlobalRef(env, obj); + } } /* @@ -1022,37 +1022,37 @@ JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1update_1volume (JNIEnv* env, jobject obj) { - pa_stream* stream = getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); + pa_stream* stream = getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); - int sink_input_index = pa_stream_get_index(stream); + int sink_input_index = pa_stream_get_index(stream); - pa_context* context = pa_stream_get_context(stream); - assert(context); + pa_context* context = pa_stream_get_context(stream); + assert(context); - obj = (*env)->NewGlobalRef(env, obj); - pa_operation *o = pa_context_get_sink_input_info(context, sink_input_index , get_sink_input_volume_callback, obj); - assert(o); - return convertNativePointerToJava(env, o); + obj = (*env)->NewGlobalRef(env, obj); + pa_operation *o = pa_context_get_sink_input_info(context, sink_input_index , get_sink_input_volume_callback, obj); + assert(o); + return convertNativePointerToJava(env, o); } JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_bytesInBuffer(JNIEnv *env, jobject obj) { - pa_stream *stream = getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - const pa_timing_info *timing_info = pa_stream_get_timing_info(stream); - int write_index = timing_info->write_index; - int read_index = timing_info->read_index; - return write_index - read_index; + pa_stream *stream = getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + const pa_timing_info *timing_info = pa_stream_get_timing_info(stream); + int write_index = timing_info->write_index; + int read_index = timing_info->read_index; + return write_index - read_index; } JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1updateTimingInfo(JNIEnv* env, jobject obj) { - pa_stream *stream = getJavaPointer(env, obj, STREAM_POINTER); - assert(stream); - pa_operation* o = pa_stream_update_timing_info(stream, update_timing_info_callback, NULL); - assert(o); - return convertNativePointerToJava(env, o); + pa_stream *stream = getJavaPointer(env, obj, STREAM_POINTER); + assert(stream); + pa_operation* o = pa_stream_update_timing_info(stream, update_timing_info_callback, NULL); + assert(o); + return convertNativePointerToJava(env, o); }