[sip-comm-dev] Re: svn commit: r6647 - trunk/src: native/portaudio net/java/sip/communicator/impl/neomedia/device net/java/sip/communicator/impl/neomedia/portaudio ne...


#1

The following don't seem right in this commit:

- InputPortAudioStream#stop calls MasterPortAudioStream#setStopping
i.e. a single slave causes the master to return no audio to all
slaves.

- The static constructor of the PortAudio class swallows any exception
when loading the JNI library thus pretending that all native functions
exposed by it are available and then relies on calling
PortAudioManager#getInstance() to throw an UnsatisfiedLinkException in
order to discover that it's not available.

···

On Tue, Jan 19, 2010 at 1:04 PM, <damencho@dev.java.net> wrote:

Author: damencho
Date: 2010-01-19 11:04:17+0000
New Revision: 6647

Modified:
trunk/src/native/portaudio/README
trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java

Log:
Fix delay on closing portaudio DataSource. If portaudio binary is missing this prevents loading neomedia service, its now fixed.

Modified: trunk/src/native/portaudio/README
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/native/portaudio/README?view=diff&rev=6647&p1=trunk/src/native/portaudio/README&p2=trunk/src/native/portaudio/README&r1=6646&r2=6647

--- trunk/src/native/portaudio/README (original)
+++ trunk/src/native/portaudio/README 2010-01-19 11:04:17+0000
@@ -1,9 +1,9 @@
1. portaudio
- Linux
- \./configure \-\-enable\-static \-\-disable\-shared \-\-with\-jack=no &amp; make \+ ./configure --enable-static --disable-shared --with-jack=no && make

\- Linux amd64

- ./configure --enable-static --disable-shared --with-pic --with-jack=no & make
+ ./configure --enable-static --disable-shared --with-pic --with-jack=no && make

\- Mac OS X
$\./configure  \-\-enable\-static \-\-disable\-shared &amp;&amp; make

Modified: trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java?view=diff&rev=6647&p1=trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java&p2=trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java&r1=6646&r2=6647

--- trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java (original)
+++ trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java 2010-01-19 11:04:17+0000
@@ -222,12 +222,38 @@
+ " capture devices: " + audioCaptureDevices);

        String audioDevName = config\.getString\(PROP\_AUDIO\_DEVICE\);

+ boolean errorStartingPA = false;
+
+ try
+ {
+ // as here is the first entry when starting up
+ // we will create the instance of portaudio manager
+ // and if there are exceptions like missing binary
+ // will be back to javasound
+
+ // this will create portaudio instance
+ PortAudioManager.getInstance().isEnabledEchoCancel();
+ }
+ catch (Throwable e)
+ {
+ errorStartingPA = true;
+ }

        if\(audioDevName == null\)
        \{
            // the default behaviour if nothing set is to use javasound
            // this will also choose the capture device

- setAudioSystem(AUDIO_SYSTEM_PORTAUDIO, null, false);
+ if(!errorStartingPA)
+ {
+ setAudioSystem(AUDIO_SYSTEM_PORTAUDIO, null, false);
+ }
+ else
+ {
+ setAudioPlaybackDevice(null, false);
+ setAudioNotifyDevice(null, false);
+ setAudioCaptureDevice(null, false);
+ setAudioSystem(AUDIO_SYSTEM_JAVASOUND, null, false);
+ }
}
else
{
@@ -241,11 +267,11 @@
}
}

- if(getAudioSystem() == null)
+ if(getAudioSystem() == null || errorStartingPA)
{
logger.warn("Computer sound config changed or " +
"there is a problem since last config was saved, " +
- "will back to default javasound");
+ "will back to javasound");
setAudioPlaybackDevice(null, false);
setAudioNotifyDevice(null, false);
setAudioCaptureDevice(null, false);
@@ -257,39 +283,42 @@
+ " as an audio capture device.");

        // now extract other sound related configs

- try
+ if(!errorStartingPA)
{
- boolean echoCancelEnabled =
- config.getBoolean(PROP_AUDIO_ECHOCANCEL_ENABLED,
- PortAudioManager.getInstance().isEnabledEchoCancel());
- if(echoCancelEnabled)
- {
- int echoCancelTail =
- config.getInt(PROP_AUDIO_ECHOCANCEL_TAIL,
- PortAudioManager.getInstance().getFilterLength());
- PortAudioManager.getInstance().setEchoCancel(
- echoCancelEnabled,
- PortAudioManager.getInstance().getFrameSize(),
- echoCancelTail);
- }
-
- boolean denoiseEnabled =
- config.getBoolean(PROP_AUDIO_DENOISE_ENABLED,
- PortAudioManager.getInstance().isEnabledDeNoise());
- PortAudioManager.getInstance().setDeNoise(denoiseEnabled);
-
- // suggested latency is saved in configuration as
- // milliseconds but PortAudioManager use it as seconds
- int audioLatency = config.getInt(PROP_AUDIO_LATENCY,
- (int)(PortAudioManager.getSuggestedLatency()*1000));
- if(audioLatency !=
- (int)PortAudioManager.getSuggestedLatency()*1000)
- PortAudioManager.setSuggestedLatency(
- (double)audioLatency/1000d);
- }
- catch (Exception e)
- {
- logger.error("Error parsing audio config", e);
+ try
+ {
+ boolean echoCancelEnabled =
+ config.getBoolean(PROP_AUDIO_ECHOCANCEL_ENABLED,
+ PortAudioManager.getInstance().isEnabledEchoCancel());
+ if(echoCancelEnabled)
+ {
+ int echoCancelTail =
+ config.getInt(PROP_AUDIO_ECHOCANCEL_TAIL,
+ PortAudioManager.getInstance().getFilterLength());
+ PortAudioManager.getInstance().setEchoCancel(
+ echoCancelEnabled,
+ PortAudioManager.getInstance().getFrameSize(),
+ echoCancelTail);
+ }
+
+ boolean denoiseEnabled =
+ config.getBoolean(PROP_AUDIO_DENOISE_ENABLED,
+ PortAudioManager.getInstance().isEnabledDeNoise());
+ PortAudioManager.getInstance().setDeNoise(denoiseEnabled);
+
+ // suggested latency is saved in configuration as
+ // milliseconds but PortAudioManager use it as seconds
+ int audioLatency = config.getInt(PROP_AUDIO_LATENCY,
+ (int)(PortAudioManager.getSuggestedLatency()*1000));
+ if(audioLatency !=
+ (int)PortAudioManager.getSuggestedLatency()*1000)
+ PortAudioManager.setSuggestedLatency(
+ (double)audioLatency/1000d);
+ }
+ catch (Exception e)
+ {
+ logger.error("Error parsing audio config", e);
+ }
}
}

Modified: trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java?view=diff&rev=6647&p1=trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java&p2=trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java&r1=6646&r2=6647

--- trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java (original)
+++ trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java 2010-01-19 11:04:17+0000
@@ -14,7 +14,14 @@
{
static
{
- System.loadLibrary("jportaudio");
+ try
+ {
+ System.loadLibrary("jportaudio");
+ }
+ catch (Throwable e)
+ {
+ System.out.println("Missing portaudio binary");
+ }
}

/\*\*

Modified: trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java?view=diff&rev=6647&p1=trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java&p2=trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java&r1=6646&r2=6647

--- trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java (original)
+++ trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java 2010-01-19 11:04:17+0000
@@ -78,6 +78,7 @@
{
if(started)
{
+ parentStream.setStopping(true);
parentStream.stop(this);
started = false;
}

Modified: trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java?view=diff&rev=6647&p1=trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java&p2=trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java&r1=6646&r2=6647

--- trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java (original)
+++ trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java 2010-01-19 11:04:17+0000
@@ -59,6 +59,15 @@
private Object connectedToStreamSync = new Object();

/\*\*

+ * Other using MasterPortAudioStream may inform us that will stop us.
+ * This is unprotected field which will stop any further reading,
+ * as read is synchronized sometimes there maybe some delay
+ * before we are stopped, as reading is too aggressive stopping thread may
+ * even wait more than 20 seconds.
+ */
+ private boolean stopping = false;
+
+ /**
* The <tt>InputPortAudioStream</tt>s which read audio from this
* <tt>MasterPortAudioStream</tt>s.
*/
@@ -169,6 +178,7 @@
PortAudio.Pa_CloseStream(stream);
stream = 0;
started = false;
+ stopping = false;
PortAudioManager.getInstance().stoppedInputPortAudioStream(this);
}
}
@@ -197,24 +207,30 @@
* @return the bytes that a read from underlying stream.
* @throws PortAudioException if an error occurs while reading.
*/
- public synchronized byte[] read()
+ public byte[] read()
throws PortAudioException
{
- if(!started)
+ if(stopping)
return new byte[0];

- byte[] bytebuff = new byte[PortAudioManager.NUM_SAMPLES*frameSize];
-
- synchronized(connectedToStreamSync)
+ synchronized(this)
{
- PortAudio.Pa_ReadStream(
- stream, bytebuff, PortAudioManager.NUM_SAMPLES);
- }
+ if(!started)
+ return new byte[0];
+
+ byte[] bytebuff = new byte[PortAudioManager.NUM_SAMPLES*frameSize];

- for(InputPortAudioStream slave : slaves)
- slave.setBuffer(bytebuff);
+ synchronized(connectedToStreamSync)
+ {
+ PortAudio.Pa_ReadStream(
+ stream, bytebuff, PortAudioManager.NUM_SAMPLES);
+ }

- return bytebuff;
+ for(InputPortAudioStream slave : slaves)
+ slave.setBuffer(bytebuff);
+
+ return bytebuff;
+ }
}

/\*\*

@@ -244,4 +260,13 @@
deNoiseEnabled,
echoCancelEnabled, frameSize, filterLength);
}
+
+ /**
+ * Inform that we will be stopping this stream.
+ * @param stopping the stopping to set
+ */
+ public void setStopping(boolean stopping)
+ {
+ this.stopping = stopping;
+ }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: commits-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net


#2

Hi,

The following don't seem right in this commit:

- InputPortAudioStream#stop calls MasterPortAudioStream#setStopping
i.e. a single slave causes the master to return no audio to all
slaves.

Yes you are right :slight_smile: I was thinking it and testing it in situation with only
one slave. I'll take a look, thanks.

- The static constructor of the PortAudio class swallows any exception
when loading the JNI library thus pretending that all native functions
exposed by it are available and then relies on calling
PortAudioManager#getInstance() to throw an UnsatisfiedLinkException in
order to discover that it's not available.

Before the commit if the portaudio library is missing or cannot be loaded
for some reason this prevents from loading the whole neomedia bundle, cause
exception is thrown and the class PortAudio cannot be loaded and loading of
bundle is stopped. I didn't wanted to load the library on different place
than that where all native functions are, and so I got the exception where
all settings of devices first take place when loading the bundle.
But you are right that if the library cannot be loaded and PortAudio class
also is not supposed to be loaded and used as its only purpose is exposing
the native functions, I will also take a look at this.

Thanks
damencho

···

On Tue, Jan 19, 2010 at 7:20 PM, Lubomir Marinov <lubo@sip-communicator.org>wrote:

On Tue, Jan 19, 2010 at 1:04 PM, <damencho@dev.java.net> wrote:
> Author: damencho
> Date: 2010-01-19 11:04:17+0000
> New Revision: 6647
>
> Modified:
> trunk/src/native/portaudio/README
>
trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java
>
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java
>
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java
>
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java
>
> Log:
> Fix delay on closing portaudio DataSource. If portaudio binary is missing
this prevents loading neomedia service, its now fixed.
>
> Modified: trunk/src/native/portaudio/README
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/native/portaudio/README?view=diff&rev=6647&p1=trunk/src/native/portaudio/README&p2=trunk/src/native/portaudio/README&r1=6646&r2=6647
>

> --- trunk/src/native/portaudio/README (original)
> +++ trunk/src/native/portaudio/README 2010-01-19 11:04:17+0000
> @@ -1,9 +1,9 @@
> 1. portaudio
> - Linux
> - \./configure \-\-enable\-static \-\-disable\-shared \-\-with\-jack=no &amp; make &gt; \+ ./configure --enable-static --disable-shared --with-jack=no && make
>
> - Linux amd64
> - ./configure --enable-static --disable-shared --with-pic
--with-jack=no & make
> + ./configure --enable-static --disable-shared --with-pic
--with-jack=no && make
>
> - Mac OS X
> $./configure --enable-static --disable-shared && make
>
> Modified:
trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java?view=diff&rev=6647&p1=trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java&p2=trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java&r1=6646&r2=6647
>

> ---
trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java
  (original)
> +++
trunk/src/net/java/sip/communicator/impl/neomedia/device/DeviceConfiguration.java
  2010-01-19 11:04:17+0000
> @@ -222,12 +222,38 @@
> + " capture devices: " + audioCaptureDevices);
>
> String audioDevName = config.getString(PROP_AUDIO_DEVICE);
> + boolean errorStartingPA = false;
> +
> + try
> + {
> + // as here is the first entry when starting up
> + // we will create the instance of portaudio manager
> + // and if there are exceptions like missing binary
> + // will be back to javasound
> +
> + // this will create portaudio instance
> + PortAudioManager.getInstance().isEnabledEchoCancel();
> + }
> + catch (Throwable e)
> + {
> + errorStartingPA = true;
> + }
>
> if(audioDevName == null)
> {
> // the default behaviour if nothing set is to use
javasound
> // this will also choose the capture device
> - setAudioSystem(AUDIO_SYSTEM_PORTAUDIO, null, false);
> + if(!errorStartingPA)
> + {
> + setAudioSystem(AUDIO_SYSTEM_PORTAUDIO, null, false);
> + }
> + else
> + {
> + setAudioPlaybackDevice(null, false);
> + setAudioNotifyDevice(null, false);
> + setAudioCaptureDevice(null, false);
> + setAudioSystem(AUDIO_SYSTEM_JAVASOUND, null, false);
> + }
> }
> else
> {
> @@ -241,11 +267,11 @@
> }
> }
>
> - if(getAudioSystem() == null)
> + if(getAudioSystem() == null || errorStartingPA)
> {
> logger.warn("Computer sound config changed or " +
> "there is a problem since last config was saved,
" +
> - "will back to default javasound");
> + "will back to javasound");
> setAudioPlaybackDevice(null, false);
> setAudioNotifyDevice(null, false);
> setAudioCaptureDevice(null, false);
> @@ -257,39 +283,42 @@
> + " as an audio capture device.");
>
> // now extract other sound related configs
> - try
> + if(!errorStartingPA)
> {
> - boolean echoCancelEnabled =
> - config.getBoolean(PROP_AUDIO_ECHOCANCEL_ENABLED,
> -
PortAudioManager.getInstance().isEnabledEchoCancel());
> - if(echoCancelEnabled)
> - {
> - int echoCancelTail =
> - config.getInt(PROP_AUDIO_ECHOCANCEL_TAIL,
> -
PortAudioManager.getInstance().getFilterLength());
> - PortAudioManager.getInstance().setEchoCancel(
> - echoCancelEnabled,
> - PortAudioManager.getInstance().getFrameSize(),
> - echoCancelTail);
> - }
> -
> - boolean denoiseEnabled =
> - config.getBoolean(PROP_AUDIO_DENOISE_ENABLED,
> -
PortAudioManager.getInstance().isEnabledDeNoise());
> -
PortAudioManager.getInstance().setDeNoise(denoiseEnabled);
> -
> - // suggested latency is saved in configuration as
> - // milliseconds but PortAudioManager use it as seconds
> - int audioLatency = config.getInt(PROP_AUDIO_LATENCY,
> - (int)(PortAudioManager.getSuggestedLatency()*1000));
> - if(audioLatency !=
> - (int)PortAudioManager.getSuggestedLatency()*1000)
> - PortAudioManager.setSuggestedLatency(
> - (double)audioLatency/1000d);
> - }
> - catch (Exception e)
> - {
> - logger.error("Error parsing audio config", e);
> + try
> + {
> + boolean echoCancelEnabled =
> + config.getBoolean(PROP_AUDIO_ECHOCANCEL_ENABLED,
> +
PortAudioManager.getInstance().isEnabledEchoCancel());
> + if(echoCancelEnabled)
> + {
> + int echoCancelTail =
> + config.getInt(PROP_AUDIO_ECHOCANCEL_TAIL,
> +
PortAudioManager.getInstance().getFilterLength());
> + PortAudioManager.getInstance().setEchoCancel(
> + echoCancelEnabled,
> +
PortAudioManager.getInstance().getFrameSize(),
> + echoCancelTail);
> + }
> +
> + boolean denoiseEnabled =
> + config.getBoolean(PROP_AUDIO_DENOISE_ENABLED,
> +
PortAudioManager.getInstance().isEnabledDeNoise());
> +
PortAudioManager.getInstance().setDeNoise(denoiseEnabled);
> +
> + // suggested latency is saved in configuration as
> + // milliseconds but PortAudioManager use it as
seconds
> + int audioLatency = config.getInt(PROP_AUDIO_LATENCY,
> +
(int)(PortAudioManager.getSuggestedLatency()*1000));
> + if(audioLatency !=
> +
(int)PortAudioManager.getSuggestedLatency()*1000)
> + PortAudioManager.setSuggestedLatency(
> + (double)audioLatency/1000d);
> + }
> + catch (Exception e)
> + {
> + logger.error("Error parsing audio config", e);
> + }
> }
> }
>
>
> Modified:
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java?view=diff&rev=6647&p1=trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java&p2=trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java&r1=6646&r2=6647
>

> ---
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java
(original)
> +++
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/PortAudio.java
2010-01-19 11:04:17+0000
> @@ -14,7 +14,14 @@
> {
> static
> {
> - System.loadLibrary("jportaudio");
> + try
> + {
> + System.loadLibrary("jportaudio");
> + }
> + catch (Throwable e)
> + {
> + System.out.println("Missing portaudio binary");
> + }
> }
>
> /**
>
> Modified:
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java?view=diff&rev=6647&p1=trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java&p2=trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java&r1=6646&r2=6647
>

> ---
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java
      (original)
> +++
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/InputPortAudioStream.java
      2010-01-19 11:04:17+0000
> @@ -78,6 +78,7 @@
> {
> if(started)
> {
> + parentStream.setStopping(true);
> parentStream.stop(this);
> started = false;
> }
>
> Modified:
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java
> Url:
https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java?view=diff&rev=6647&p1=trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java&p2=trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java&r1=6646&r2=6647
>

> ---
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java
     (original)
> +++
trunk/src/net/java/sip/communicator/impl/neomedia/portaudio/streams/MasterPortAudioStream.java
     2010-01-19 11:04:17+0000
> @@ -59,6 +59,15 @@
> private Object connectedToStreamSync = new Object();
>
> /**
> + * Other using MasterPortAudioStream may inform us that will stop
us.
> + * This is unprotected field which will stop any further reading,
> + * as read is synchronized sometimes there maybe some delay
> + * before we are stopped, as reading is too aggressive stopping
thread may
> + * even wait more than 20 seconds.
> + */
> + private boolean stopping = false;
> +
> + /**
> * The <tt>InputPortAudioStream</tt>s which read audio from this
> * <tt>MasterPortAudioStream</tt>s.
> */
> @@ -169,6 +178,7 @@
> PortAudio.Pa_CloseStream(stream);
> stream = 0;
> started = false;
> + stopping = false;
>
PortAudioManager.getInstance().stoppedInputPortAudioStream(this);
> }
> }
> @@ -197,24 +207,30 @@
> * @return the bytes that a read from underlying stream.
> * @throws PortAudioException if an error occurs while reading.
> */
> - public synchronized byte[] read()
> + public byte[] read()
> throws PortAudioException
> {
> - if(!started)
> + if(stopping)
> return new byte[0];
>
> - byte[] bytebuff = new
byte[PortAudioManager.NUM_SAMPLES*frameSize];
> -
> - synchronized(connectedToStreamSync)
> + synchronized(this)
> {
> - PortAudio.Pa_ReadStream(
> - stream, bytebuff, PortAudioManager.NUM_SAMPLES);
> - }
> + if(!started)
> + return new byte[0];
> +
> + byte[] bytebuff = new
byte[PortAudioManager.NUM_SAMPLES*frameSize];
>
> - for(InputPortAudioStream slave : slaves)
> - slave.setBuffer(bytebuff);
> + synchronized(connectedToStreamSync)
> + {
> + PortAudio.Pa_ReadStream(
> + stream, bytebuff, PortAudioManager.NUM_SAMPLES);
> + }
>
> - return bytebuff;
> + for(InputPortAudioStream slave : slaves)
> + slave.setBuffer(bytebuff);
> +
> + return bytebuff;
> + }
> }
>
> /**
> @@ -244,4 +260,13 @@
> deNoiseEnabled,
> echoCancelEnabled, frameSize, filterLength);
> }
> +
> + /**
> + * Inform that we will be stopping this stream.
> + * @param stopping the stopping to set
> + */
> + public void setStopping(boolean stopping)
> + {
> + this.stopping = stopping;
> + }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
commits-unsubscribe@sip-communicator.dev.java.net
> For additional commands, e-mail:
commits-help@sip-communicator.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net