Mercurial > hg > release > icedtea6-1.4.1
changeset 1206:92b3adc8a186
2008-11-10 Omair Majid <omajid@redhat.com>
* pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Debug.java
New class containing debugging functions.
* pulseaudio/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java
(run): Print some debugging info.
(update): Likewise.
* pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java
(ClipThread.writeFrames): Likewise.
(close): Likewise.
(open): Likewise.
* pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java
(PulseAudioMixer): Likewise.
(getLine): Likewise.
(close): Likewise.
(open): Likewise.
* pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixerProvider.java
(PulseAudioMixerProvider): Initialize Debug class.
* pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java
(open): Print some debug info.
(close): Likewise.
* pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
(open): Likewise.
(close): Likewise.
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Mon, 10 Nov 2008 14:48:22 -0500 |
parents | 58f7eb173fe0 |
children | 28203509220a |
files | ChangeLog pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Debug.java pulseaudio/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixerProvider.java pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java |
diffstat | 8 files changed, 196 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Nov 10 13:47:29 2008 -0500 +++ b/ChangeLog Mon Nov 10 14:48:22 2008 -0500 @@ -1,3 +1,28 @@ +2008-11-10 Omair Majid <omajid@redhat.com> + + * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Debug.java + New class containing debugging functions. + * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java + (run): Print some debugging info. + (update): Likewise. + * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java + (ClipThread.writeFrames): Likewise. + (close): Likewise. + (open): Likewise. + * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java + (PulseAudioMixer): Likewise. + (getLine): Likewise. + (close): Likewise. + (open): Likewise. + * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixerProvider.java + (PulseAudioMixerProvider): Initialize Debug class. + * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java + (open): Print some debug info. + (close): Likewise. + * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java + (open): Likewise. + (close): Likewise. + 2008-11-10 Omair Majid <omajid@redhat.com> * pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/Debug.java Mon Nov 10 14:48:22 2008 -0500 @@ -0,0 +1,104 @@ +/* EventLoop.java + Copyright (C) 2008 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + */ + +package org.classpath.icedtea.pulseaudio; + +public class Debug { + + public enum DebugLevel { + Verbose, Debug, Info, Warning, Error, None + } + + private static DebugLevel currentDebugLevel = DebugLevel.None; + + public static void initialize() { + // 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; + } + + DebugLevel wantedLevel; + try { + wantedLevel = DebugLevel.valueOf(systemSetting); + + } catch (IllegalArgumentException e) { + wantedLevel = DebugLevel.Info; + } catch (NullPointerException e) { + wantedLevel = DebugLevel.None; + } + + currentDebugLevel = wantedLevel; + println(DebugLevel.Info, "Using debug level: " + currentDebugLevel); + } + + public static void println(String string) { + println(DebugLevel.Info, string); + } + + public 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 + } + } + + public 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 + } + } + +}
--- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java Mon Nov 10 13:47:29 2008 -0500 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java Mon Nov 10 14:48:22 2008 -0500 @@ -42,6 +42,7 @@ import java.util.concurrent.Semaphore; import org.classpath.icedtea.pulseaudio.ContextEvent.Type; +import org.classpath.icedtea.pulseaudio.Debug.DebugLevel; /* * any methods that can obstruct the behaviour of pa_mainloop should run @@ -55,7 +56,6 @@ /* * the threadLock object is the object used for synchronizing the * non-thread-safe operations of pulseaudio's c api - * */ public Object threadLock = new Object(); @@ -79,7 +79,6 @@ * * Do not synchronize the individual functions, synchronize * block/method/lines around the call - * */ private native void native_setup(String appName, String server); @@ -92,8 +91,6 @@ /* * These fields hold pointers - * - * */ @SuppressWarnings("unused") private byte[] contextPointer; @@ -132,6 +129,8 @@ public void run() { native_setup(this.name, this.serverString); + 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 @@ -144,14 +143,15 @@ if (Thread.interrupted()) { native_shutdown(); - // System.out.println(this.getClass().getName() - // + ": shutting down"); // clean up the listeners synchronized (contextListeners) { contextListeners.clear(); } + Debug.println(DebugLevel.Info, + "EventLoop.run(): event loop terminated"); + return; } @@ -197,7 +197,8 @@ break; case 5: fireEvent(new ContextEvent(Type.FAILED)); - System.out.println("context failed"); + Debug.println(DebugLevel.Warning, + "EventLoop.update(): Context failed"); break; case 6: fireEvent(new ContextEvent(Type.TERMINATED));
--- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Mon Nov 10 13:47:29 2008 -0500 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Mon Nov 10 14:48:22 2008 -0500 @@ -46,6 +46,7 @@ import javax.sound.sampled.DataLine; import javax.sound.sampled.LineUnavailableException; +import org.classpath.icedtea.pulseaudio.Debug.DebugLevel; import org.classpath.icedtea.pulseaudio.Stream.WriteListener; public class PulseAudioClip extends PulseAudioDataLine implements Clip, @@ -145,6 +146,9 @@ stream.addWriteListener(writeListener); + Debug.println(DebugLevel.Verbose, + "PulseAudioClip$ClipThread.writeFrames(): Writing"); + int remainingFrames = lastFrame - startingFrame - 1; while (remainingFrames > 0) { synchronized (eventLoop.threadLock) { @@ -250,6 +254,9 @@ super.close(); + Debug.println(DebugLevel.Verbose, "PulseAudioClip.close(): " + + "Clip closed"); + } /* @@ -416,6 +423,7 @@ mixer.addSourceLine(this); isOpen = true; + Debug.println(DebugLevel.Verbose, "PulseAudioClip.open(): Clip opened"); }
--- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java Mon Nov 10 13:47:29 2008 -0500 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java Mon Nov 10 14:48:22 2008 -0500 @@ -67,6 +67,8 @@ import javax.sound.sampled.AudioFormat.Encoding; import javax.sound.sampled.Control.Type; +import org.classpath.icedtea.pulseaudio.Debug.DebugLevel; + public class PulseAudioMixer implements javax.sound.sampled.Mixer { // singleton @@ -92,6 +94,10 @@ private final List<LineListener> lineListeners = new ArrayList<LineListener>(); private PulseAudioMixer() { + + Debug.println(DebugLevel.Verbose, "PulseAudioMixer.PulseAudioMixer(): " + + "Contructing PulseAudioMixer..."); + AudioFormat[] formats = getSupportedFormats(); staticSourceLineInfos.add(new DataLine.Info(SourceDataLine.class, @@ -107,6 +113,9 @@ refreshSourceAndTargetLines(); + Debug.println(DebugLevel.Verbose, "PulseAudioMixer.PulseAudioMixer(): " + + "Finished constructing PulseAudioMixer"); + } synchronized public static PulseAudioMixer getInstance() { @@ -126,7 +135,9 @@ * 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 + * http://git.0pointer.de/?p=pulseaudio.git;a=blob + * ;f=src/pulse/sample.c;h=93da2465f4301e27af4976e82737c3a048124a68;hb= + * 82ea8dde8abc51165a781c69bc3b38034d62d969#l63 */ /* @@ -135,7 +146,6 @@ * * 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 }; @@ -322,6 +332,9 @@ } } + Debug.println(DebugLevel.Info, "PulseAudioMixer.getLine(): " + + "No matching line supported by PulseAudio"); + throw new IllegalArgumentException("No matching lines found"); } @@ -486,11 +499,14 @@ List<Line> linesToClose = new LinkedList<Line>(); linesToClose.addAll(sourceLines); if (sourceLines.size() > 0) { + + 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()) { - System.out - .println("PulseAudioMixer: DEBUG: some source lines have not been closed"); line.close(); } } @@ -498,11 +514,13 @@ linesToClose.clear(); 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()) { - System.out - .println("PulseAudioMixer: DEBUG: some target lines have not been closed"); line.close(); } } @@ -521,12 +539,13 @@ + ": interrupted while waiting for eventloop to finish"); } - // System.out.println(this.getClass().getName() + ": closed"); - isOpen = false; refreshSourceAndTargetLines(); + Debug.println(DebugLevel.Verbose, "PulseAudioMixer.close(): " + + "Mixer closed"); + } @Override @@ -691,6 +710,9 @@ targetLineInfos.add(new Port.Info(Port.class, portName, false)); } + Debug.println(DebugLevel.Debug, "PulseAudioMixer.open(): " + + "Mixer opened"); + } @Override
--- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixerProvider.java Mon Nov 10 13:47:29 2008 -0500 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixerProvider.java Mon Nov 10 14:48:22 2008 -0500 @@ -43,6 +43,10 @@ public class PulseAudioMixerProvider extends javax.sound.sampled.spi.MixerProvider { + public PulseAudioMixerProvider() { + Debug.initialize(); + } + @Override public Mixer getMixer(Info info) { // System.out.println("DEBUG: getMixer called");
--- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Mon Nov 10 13:47:29 2008 -0500 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Mon Nov 10 14:48:22 2008 -0500 @@ -41,11 +41,12 @@ import javax.sound.sampled.AudioFormat; import javax.sound.sampled.DataLine; -import javax.sound.sampled.AudioPermission; import javax.sound.sampled.LineListener; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; +import org.classpath.icedtea.pulseaudio.Debug.DebugLevel; + public class PulseAudioSourceDataLine extends PulseAudioDataLine implements SourceDataLine, PulseAudioPlaybackLine { @@ -78,6 +79,9 @@ PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); parentMixer.addSourceLine(this); + Debug.println(DebugLevel.Verbose, "PulseAudioSourceDataLine.open(): " + + "line opened"); + } @Override @@ -327,6 +331,10 @@ parent.removeSourceLine(this); super.close(); + + Debug.println(DebugLevel.Verbose, "PulseAudioSourceDataLine.close():" + + " line closed"); + } public javax.sound.sampled.Line.Info getLineInfo() {
--- a/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Mon Nov 10 13:47:29 2008 -0500 +++ b/pulseaudio/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Mon Nov 10 14:48:22 2008 -0500 @@ -44,6 +44,8 @@ import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.TargetDataLine; +import org.classpath.icedtea.pulseaudio.Debug.DebugLevel; + public class PulseAudioTargetDataLine extends PulseAudioDataLine implements TargetDataLine { @@ -84,6 +86,9 @@ parentMixer.removeTargetLine(this); super.close(); + + Debug.println(DebugLevel.Verbose, "PulseAudioTargetDataLine.close(): " + + "Line closed"); } @Override @@ -107,6 +112,9 @@ /* add this open line to the mixer */ PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); parentMixer.addTargetLine(this); + + Debug.println(DebugLevel.Verbose, "PulseAudioTargetDataLine.open(): " + + "Line opened"); } @Override