From b5f0e84418eb2ce745e4ebc0032de6f959f649d3 Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov <lyubomir.marinov@jitsi.org> Date: Tue, 20 Nov 2012 20:44:48 +0000 Subject: [PATCH] Fixes an IllegalArgumentException in the constructor of PortAudioException (on the Java side). --- src/native/build.xml | 54 +++++++-------- .../org_jitsi_impl_neomedia_portaudio_Pa.c | 4 +- .../protocol/portaudio/PortAudioStream.java | 12 ++-- .../renderer/audio/PortAudioRenderer.java | 6 +- src/org/jitsi/impl/neomedia/portaudio/Pa.java | 23 +++---- .../portaudio/PortAudioException.java | 68 +++++++++++-------- 6 files changed, 86 insertions(+), 81 deletions(-) diff --git a/src/native/build.xml b/src/native/build.xml index 494c3bdd..5071e585 100644 --- a/src/native/build.xml +++ b/src/native/build.xml @@ -364,28 +364,28 @@ <fail message="speex repository not set!" unless="is.speex.set" /> <cc outtype="shared" name="gcc" outfile="${native_install_dir}/jnportaudio" objdir="${obj}"> - <!-- common compiler flags --> - <compilerarg value="-std=c99" /> - <compilerarg value="-Wall" /> - <compilerarg value="-O2" /> + <!-- Common flags --> + <compilerarg value="-m32" if="cross_32" unless="is.running.macos" /> + <compilerarg value="-m64" if="cross_64" unless="is.running.macos" /> + <compilerarg value="-D_JNI_IMPLEMENTATION_" /> + <compilerarg value="-fPIC" /> <compilerarg value="-I${portaudio}/include" /> <compilerarg value="-I${speex}/include" /> - <compilerarg value="-D_JNI_IMPLEMENTATION_" /> + <compilerarg value="-I${system.JAVA_HOME}/include" unless="is.running.macos" /> + <compilerarg value="-O2" /> + <compilerarg value="-std=c99" /> + <compilerarg value="-Wall" /> - <linkerarg value="-L${speex}/libspeex/.libs" /> + <linkerarg value="-m32" if="cross_32" unless="is.running.macos" /> + <linkerarg value="-m64" if="cross_64" unless="is.running.macos" /> <linkerarg value="-L${portaudio}/lib/.libs" /> + <linkerarg value="-L${speex}/libspeex/.libs" /> - <!-- Linux specific flags --> - <compilerarg value="-m32" if="cross_32" unless="is.running.macos" /> - <compilerarg value="-m64" if="cross_64" unless="is.running.macos" /> - <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.linux" /> + <!-- Linux-specific flags --> <compilerarg value="-I${system.JAVA_HOME}/include/linux" if="is.running.linux" /> - <linkerarg value="-m32" if="cross_32" unless="is.running.macos" /> - <linkerarg value="-m64" if="cross_64" unless="is.running.macos" /> - - <!-- static libraries MUST be at the end otherwise - they will not be added to shared library + <!-- Static libraries MUST be at the end; otherwise, they will not be + added to shared library. --> <linkerarg value="-Wl,-Bstatic" location="end" if="is.running.linux" /> <linkerarg value="-lportaudio" location="end" if="is.running.linux" /> @@ -397,21 +397,21 @@ <linkerarg value="-lm" location="end" if="is.running.linux" /> <linkerarg value="-lpthread" location="end" if="is.running.linux" /> - <!-- Mac OS X specific flags --> - <compilerarg value="-mmacosx-version-min=10.5" if="is.running.macos"/> + <!-- OS X-specific flags --> <compilerarg value="-arch" if="is.running.macos" /> - <compilerarg value="x86_64" if="is.running.macos" /> - <compilerarg value="-arch" if="is.running.macos" /> <compilerarg value="i386" if="is.running.macos" /> + <compilerarg value="-arch" if="is.running.macos" /> + <compilerarg value="x86_64" if="is.running.macos" /> + <compilerarg value="-mmacosx-version-min=10.4" if="is.running.macos"/> <compilerarg value="-I/System/Library/Frameworks/JavaVM.framework/Headers" if="is.running.macos" /> - <linkerarg value="-o" location="end" if="is.running.macos" /> - <linkerarg value="libjnportaudio.jnilib" location="end" if="is.running.macos" /> - <linkerarg value="-dynamiclib" if="is.running.macos" /> - <linkerarg value="-arch" if="is.running.macos" /> - <linkerarg value="x86_64" if="is.running.macos" /> <linkerarg value="-arch" if="is.running.macos" /> <linkerarg value="i386" if="is.running.macos" /> + <linkerarg value="-arch" if="is.running.macos" /> + <linkerarg value="x86_64" if="is.running.macos" /> + <linkerarg value="-dynamiclib" if="is.running.macos" /> + <linkerarg value="-o" location="end" if="is.running.macos" /> + <linkerarg value="libjnportaudio.jnilib" location="end" if="is.running.macos" /> <linkerarg value="-framework" location="end" if="is.running.macos" /> <linkerarg value="AudioToolbox" location="end" if="is.running.macos" /> <linkerarg value="-framework" location="end" if="is.running.macos" /> @@ -425,11 +425,11 @@ <linkerarg value="-dynamic" location="end" if="is.running.macos" /> <linkerarg value="-lpthread" location="end" if="is.running.macos" /> - <!-- Windows specific flags --> - <compilerarg value="-I${system.JAVA_HOME}/include" if="is.running.windows" /> + <!-- Windows-specific flags --> + <compilerarg value="-D_WIN32_WINNT=0x0502" if="is.running.windows" /> + <compilerarg value="-DWINVER=0x0502" if="is.running.windows" /> <compilerarg value="-I${system.JAVA_HOME}/include/win32" if="is.running.windows" /> - <linkerarg value="-L${pthread}" if="is.running.windows" /> <linkerarg value="-ojnportaudio.dll" if="is.running.windows" /> <linkerarg value="-Wl,--kill-at" if="is.running.windows" /> <linkerarg value="-Wl,-Bstatic" location="end" if="is.running.windows" /> diff --git a/src/native/portaudio/org_jitsi_impl_neomedia_portaudio_Pa.c b/src/native/portaudio/org_jitsi_impl_neomedia_portaudio_Pa.c index be7d1e4f..1d391495 100644 --- a/src/native/portaudio/org_jitsi_impl_neomedia_portaudio_Pa.c +++ b/src/native/portaudio/org_jitsi_impl_neomedia_portaudio_Pa.c @@ -1292,8 +1292,8 @@ PortAudio_throwException(JNIEnv *env, PaError err) clazz, methodID, jmessage, - hostErr->errorCode, - hostErr->hostApiType); + (jlong) (hostErr->errorCode), + (jint) (hostErr->hostApiType)); if (t) (*env)->Throw(env, (jthrowable) t); diff --git a/src/org/jitsi/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java b/src/org/jitsi/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java index 9e0362bb..4270a1f3 100644 --- a/src/org/jitsi/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java +++ b/src/org/jitsi/impl/neomedia/jmfext/media/protocol/portaudio/PortAudioStream.java @@ -254,7 +254,6 @@ private void connect() catch (PortAudioException paex) { logger.error("Failed to open " + getClass().getSimpleName(), paex); - paex.printHostErrorInfo(); IOException ioex = new IOException(paex.getLocalizedMessage()); @@ -389,7 +388,7 @@ public void read(Buffer buffer) } catch (PortAudioException paex) { - paex.printHostErrorInfo(); + logger.error("Failed to read from PortAudio stream.", paex); IOException ioex = new IOException(paex.getLocalizedMessage()); @@ -460,7 +459,6 @@ synchronized void setDeviceIndex(int deviceIndex) logger.error( "Failed to close " + getClass().getSimpleName(), paex); - paex.printHostErrorInfo(); IOException ioex = new IOException(paex.getLocalizedMessage()); @@ -523,8 +521,8 @@ public synchronized void start() catch (PortAudioException paex) { logger.error( - "Failed to start " + getClass().getSimpleName(), paex); - paex.printHostErrorInfo(); + "Failed to start " + getClass().getSimpleName(), + paex); IOException ioex = new IOException(paex.getLocalizedMessage()); @@ -556,8 +554,8 @@ public synchronized void stop() catch (PortAudioException paex) { logger.error( - "Failed to stop " + getClass().getSimpleName(), paex); - paex.printHostErrorInfo(); + "Failed to stop " + getClass().getSimpleName(), + paex); IOException ioex = new IOException(paex.getLocalizedMessage()); diff --git a/src/org/jitsi/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java b/src/org/jitsi/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java index aa5b4418..1c176cee 100644 --- a/src/org/jitsi/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java +++ b/src/org/jitsi/impl/neomedia/jmfext/media/renderer/audio/PortAudioRenderer.java @@ -311,7 +311,6 @@ public synchronized void close() catch (PortAudioException paex) { logger.error("Failed to close PortAudio stream.", paex); - paex.printHostErrorInfo(); } } if ((stream == 0) && (outputParameters != 0)) @@ -571,7 +570,7 @@ private void doOpen() } catch (PortAudioException paex) { - paex.printHostErrorInfo(); + logger.error("Failed to open PortAudio stream.", paex); throw new ResourceUnavailableException(paex.getMessage()); } finally @@ -681,7 +680,6 @@ public int process(Buffer buffer) catch (PortAudioException paex) { logger.error("Failed to process Buffer.", paex); - paex.printHostErrorInfo(); } finally { @@ -797,7 +795,6 @@ public synchronized void start() catch (PortAudioException paex) { logger.error("Failed to start PortAudio stream.", paex); - paex.printHostErrorInfo(); } } } @@ -821,7 +818,6 @@ public synchronized void stop() catch (PortAudioException paex) { logger.error("Failed to close PortAudio stream.", paex); - paex.printHostErrorInfo(); } } } diff --git a/src/org/jitsi/impl/neomedia/portaudio/Pa.java b/src/org/jitsi/impl/neomedia/portaudio/Pa.java index ca15cab9..703c89f3 100644 --- a/src/org/jitsi/impl/neomedia/portaudio/Pa.java +++ b/src/org/jitsi/impl/neomedia/portaudio/Pa.java @@ -169,8 +169,7 @@ public final class Pa } catch (PortAudioException paex) { - paex.printHostErrorInfo(); - + logger.error("Failed to initialize the PortAudio library.", paex); throw new UndeclaredThrowableException(paex); } } @@ -778,20 +777,20 @@ private Pa() */ public static enum HostApiTypeId { - paAL(9), - paALSA(8), - paASIO(3), - paAudioScienceHPI(14), - paBeOS(10), - paCoreAudio(5), - paDirectSound(1), paInDevelopment(0) /* use while developing support for a new host API */, - paJACK(12), + paDirectSound(1), paMME(2), - paOSS(7), + paASIO(3), paSoundManager(4), + paCoreAudio(5), + paOSS(7), + paALSA(8), + paAL(9), + paBeOS(10), + paWDMKS(11), + paJACK(12), paWASAPI(13), - paWDMKS(11); + paAudioScienceHPI(14); /** * Returns the <tt>PaHostApiTypeId</tt> which has a specific value or diff --git a/src/org/jitsi/impl/neomedia/portaudio/PortAudioException.java b/src/org/jitsi/impl/neomedia/portaudio/PortAudioException.java index 521fdd31..6d6c5212 100644 --- a/src/org/jitsi/impl/neomedia/portaudio/PortAudioException.java +++ b/src/org/jitsi/impl/neomedia/portaudio/PortAudioException.java @@ -6,9 +6,6 @@ */ package org.jitsi.impl.neomedia.portaudio; -import org.jitsi.impl.neomedia.portaudio.Pa.*; -import org.jitsi.util.*; - /** * Implements <tt>Exception</tt> for the PortAudio capture and playback system. * @@ -18,13 +15,6 @@ public class PortAudioException extends Exception { - /** - * The <tt>Logger</tt> used by the <tt>PortAudioException</tt> class and its - * instances for logging output. - */ - private static final Logger logger - = Logger.getLogger(PortAudioException.class); - /** * Serial version UID. */ @@ -67,15 +57,8 @@ public PortAudioException(String message, long errorCode, int hostApiType) super(message); this.errorCode = errorCode; - - if (-1 == hostApiType) - this.hostApiType = null; - else - { - this.hostApiType = Pa.HostApiTypeId.valueOf(hostApiType); - if (this.hostApiType == null) - throw new IllegalArgumentException("hostApiType"); - } + this.hostApiType + = (hostApiType < 0) ? null : Pa.HostApiTypeId.valueOf(hostApiType); } /** @@ -104,19 +87,48 @@ public Pa.HostApiTypeId getHostApiType() } /** - * Logs an ERROR message with the respective details if this - * <tt>PortAudioException</tt> represents a <tt>PaHostErrorInfo</tt> (as - * defined by the native PortAudio library). + * Returns a human-readable representation/description of this + * <tt>Throwable</tt>. + * + * @return a human-readable representation/description of this + * <tt>Throwable</tt> */ - public void printHostErrorInfo() + @Override + public String toString() { - HostApiTypeId hostApiType = getHostApiType(); + String s = super.toString(); + + long errorCode = getErrorCode(); + String errorCodeStr + = (errorCode == Pa.paNoError) ? null : Long.toString(errorCode); + + Pa.HostApiTypeId hostApiType = getHostApiType(); + String hostApiTypeStr + = (hostApiType == null) ? null : hostApiType.toString(); - if (hostApiType != null) + if ((errorCodeStr !=null) || (hostApiTypeStr != null)) { - logger.error( - getMessage() + " (hostApiType: " + hostApiType - + ", errorCode: " + getErrorCode() + ")"); + StringBuilder sb = new StringBuilder(s); + + sb.append(": "); + if (errorCodeStr != null) + { + sb.append("errorCode= "); + sb.append(errorCodeStr); + sb.append(';'); + } + if (hostApiTypeStr != null) + { + if (errorCodeStr != null) + sb.append(' '); + sb.append("hostApiType= "); + sb.append(hostApiTypeStr); + sb.append(';'); + } + + s = sb.toString(); } + + return s; } } -- GitLab