diff --git a/lib/installer-exclude/ice4j.jar b/lib/installer-exclude/ice4j.jar index 3a24b2876..213ae54e7 100644 Binary files a/lib/installer-exclude/ice4j.jar and b/lib/installer-exclude/ice4j.jar differ diff --git a/src/native/portaudio/AudioQualityImprovement.c b/src/native/portaudio/AudioQualityImprovement.c deleted file mode 100644 index ed6aa3369..000000000 --- a/src/native/portaudio/AudioQualityImprovement.c +++ /dev/null @@ -1,911 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ - -#define AUDIO_QUALITY_IMPROVEMENT_IMPLEMENTATION -#include "AudioQualityImprovement.h" - -#include -#include -#include -#include -#include -#include - -#define MIN_SOUND_PRESSURE_LEVEL 40 -#define MAX_SOUND_PRESSURE_LEVEL 85 - -/** - * - * @param aqi - * @param samples - * @param count the number of samples specified in samples - * @return the sound pressure level in dB of the specified samples - */ -static float AudioQualityImprovement_calculateSoundPressureLevel - (AudioQualityImprovement *aqi, spx_int16_t *samples, spx_uint32_t count); - -/** - * - * @param aqi - * @param buffer - * @param length the length of buffer in bytes - * @return the sound pressure level in dB of the playback which has been matched - * to the specified capture buffer for the purposes of echo - * cancellation if echo suppression is enabled; otherwise, 0 - */ -static float AudioQualityImprovement_cancelEchoFromPlay - (AudioQualityImprovement *aqi, - void *buffer, unsigned long length); -static void AudioQualityImprovement_free(AudioQualityImprovement *aqi); -static AudioQualityImprovement *AudioQualityImprovement_new - (const char *stringID, jlong longID, AudioQualityImprovement *next); -static void AudioQualityImprovement_popFromPlay - (AudioQualityImprovement *aqi, spx_uint32_t sampleCount); -static void AudioQualityImprovement_resampleInPlay - (AudioQualityImprovement *aqi, - double sampleRate, unsigned long sampleSizeInBits, int channels, - void *buffer, unsigned long length); -static void AudioQualityImprovement_retain(AudioQualityImprovement *aqi); -static void AudioQualityImprovement_setFrameSize - (AudioQualityImprovement *aqi, jint frameSize); -static void AudioQualityImprovement_setInputLatency - (AudioQualityImprovement *aqi, jlong inputLatency); -static void AudioQualityImprovement_setOutputLatency - (AudioQualityImprovement *aqi, jlong outputLatency); -static void AudioQualityImprovement_suppressEcho - (AudioQualityImprovement *aqi, - spx_int16_t *buffer, spx_uint32_t length, - float spl); - -/** - * Updates the indicator of the specified AudioQualityImprovement which - * determines whether AudioQualityImprovement#play delays the access to - * it from AudioQualityImprovement#echo. - * - * @param aqi the AudioQualityImprovement of which to update the - * indicator which determines whether AudioQualityImprovement#play - * delays the access to it from AudioQualityImprovement#echo - */ -static void AudioQualityImprovement_updatePlayDelay - (AudioQualityImprovement *aqi); -static void AudioQualityImprovement_updatePlayIsDelaying - (AudioQualityImprovement *aqi); -static void AudioQualityImprovement_updatePreprocess - (AudioQualityImprovement *aqi); - -/** - * Returns the current time in milliseconds (akin to - * java.lang.System#currentTimeMillis()). - * - * @return the current time in milliseconds - */ -static jlong System_currentTimeMillis(); - -static Mutex *AudioQualityImprovement_sharedInstancesMutex = NULL; -static AudioQualityImprovement *AudioQualityImprovement_sharedInstances = NULL; - -/** - * - * @param aqi - * @param samples - * @param count the number of samples specified in samples - * @return the sound pressure level in dB of the specified samples - */ -static float -AudioQualityImprovement_calculateSoundPressureLevel - (AudioQualityImprovement *aqi, spx_int16_t *samples, spx_uint32_t count) -{ - spx_uint32_t i; - float rms; - float spl; - - if (!count) - return 0; - - rms = 0; - for (i = 0; i < count; i++) - { - float sample = samples[i] / (float) SHRT_MAX; - - rms += sample * sample; - } - rms = sqrtf(rms / count); - - spl = (rms > 0) ? 20 * log10f(rms / 0.00002) : -MAX_SOUND_PRESSURE_LEVEL; - return spl; -} - -/** - * - * @param aqi - * @param buffer - * @param length the length of buffer in bytes - * @return the sound pressure level in dB of the playback which has been matched - * to the specified capture buffer for the purposes of echo - * cancellation if echo suppression is enabled; otherwise, 0 - */ -static float -AudioQualityImprovement_cancelEchoFromPlay - (AudioQualityImprovement *aqi, - void *buffer, unsigned long length) -{ - spx_uint32_t sampleCount; - float spl; - - if (aqi->playIsDelaying == JNI_TRUE) - return 0; - - sampleCount = length / sizeof(spx_int16_t); - if (aqi->playLength < sampleCount) - return 0; - - /* - * Ensure that out exists and is large enough to receive the result of the - * echo cancellation. - */ - if (!(aqi->out) || (aqi->outCapacity < length)) - { - spx_int16_t *newOut = realloc(aqi->out, length); - - if (newOut) - { - aqi->out = newOut; - aqi->outCapacity = length; - } - else - return 0; - } - - /* Perform the echo cancellation and return the result in buffer. */ - speex_echo_cancellation(aqi->echo, buffer, aqi->play, aqi->out); - memcpy(buffer, aqi->out, length); - - /* - * Calculate the sound pressure level in dB to be returned (if echo - * suppression is enabled and, thus, needs it). - */ - spl - = (JNI_TRUE == aqi->suppressEcho) - ? AudioQualityImprovement_calculateSoundPressureLevel( - aqi, - aqi->play, sampleCount) - : 0; - - AudioQualityImprovement_popFromPlay(aqi, sampleCount); - - return spl; -} - -static void -AudioQualityImprovement_free(AudioQualityImprovement *aqi) -{ - /* mutex */ - Mutex_free(aqi->mutex); - /* preprocess */ - if (aqi->preprocess) - speex_preprocess_state_destroy(aqi->preprocess); - /* echo */ - if (aqi->echo) - speex_echo_state_destroy(aqi->echo); - /* out */ - if (aqi->out) - free(aqi->out); - /* play */ - if (aqi->play) - free(aqi->play); - /* resampler */ - if (aqi->resampler) - speex_resampler_destroy(aqi->resampler); - /* stringID */ - free(aqi->stringID); - - free(aqi); -} - -AudioQualityImprovement * -AudioQualityImprovement_getSharedInstance(const char *stringID, jlong longID) -{ - AudioQualityImprovement *theSharedInstance = NULL; - - if (!Mutex_lock(AudioQualityImprovement_sharedInstancesMutex)) - { - AudioQualityImprovement *aSharedInstance - = AudioQualityImprovement_sharedInstances; - - while (aSharedInstance) - { - if ((aSharedInstance->longID == longID) - && ((aSharedInstance->stringID == stringID) - || (0 == strcmp(aSharedInstance->stringID, stringID)))) - { - theSharedInstance = aSharedInstance; - break; - } - aSharedInstance = aSharedInstance->next; - } - if (theSharedInstance) - AudioQualityImprovement_retain(theSharedInstance); - else - { - theSharedInstance - = AudioQualityImprovement_new( - stringID, - longID, - AudioQualityImprovement_sharedInstances); - if (theSharedInstance) - AudioQualityImprovement_sharedInstances = theSharedInstance; - } - Mutex_unlock(AudioQualityImprovement_sharedInstancesMutex); - } - return theSharedInstance; -} - -/** Loads the AudioQualityImprovement class. */ -void -AudioQualityImprovement_load() -{ - AudioQualityImprovement_sharedInstancesMutex = Mutex_new(NULL); -} - -static AudioQualityImprovement * -AudioQualityImprovement_new - (const char *stringID, jlong longID, AudioQualityImprovement *next) -{ - AudioQualityImprovement *aqi = calloc(1, sizeof(AudioQualityImprovement)); - - if (aqi) - { - /* stringID */ - size_t slen = strlen(stringID); - aqi->stringID = malloc(slen + 1); - - if (!(aqi->stringID)) - { - AudioQualityImprovement_free(aqi); - return NULL; - } - strncpy(aqi->stringID, stringID, slen); - aqi->stringID[slen] = 0x00; - - /* mutex */ - aqi->mutex = Mutex_new(NULL); - if (!(aqi->mutex)) - { - AudioQualityImprovement_free(aqi); - return NULL; - } - - aqi->inputLatency = -1; - aqi->longID = longID; - aqi->next = next; - aqi->outputLatency = -1; - aqi->retainCount = 1; - aqi->suppressEcho = JNI_TRUE; - } - return aqi; -} - -static void -AudioQualityImprovement_popFromPlay - (AudioQualityImprovement *aqi, spx_uint32_t sampleCount) -{ - spx_uint32_t i; - spx_uint32_t sampleCountToMove = aqi->playLength - sampleCount; - spx_int16_t *playNew = aqi->play; - spx_int16_t *playOld = aqi->play + sampleCount; - - for (i = 0; i < sampleCountToMove; i++) - *playNew++ = *playOld++; - aqi->playLength -= sampleCount; -} - -/** - * - * @param aqi - * @param sampleOrigin - * @param sampleRate - * @param sampleSizeInBits - * @param channels - * @param latency the latency of the stream associated with buffer in - * milliseconds - * @param buffer - * @param length the length of buffer in bytes - */ -void -AudioQualityImprovement_process - (AudioQualityImprovement *aqi, - AudioQualityImprovementSampleOrigin sampleOrigin, - double sampleRate, unsigned long sampleSizeInBits, int channels, - jlong latency, - void *buffer, unsigned long length) -{ - if ((sampleSizeInBits == 16) && (channels == 1) && !Mutex_lock(aqi->mutex)) - { - switch (sampleOrigin) - { - case AUDIO_QUALITY_IMPROVEMENT_SAMPLE_ORIGIN_INPUT: - if (sampleRate == aqi->sampleRate) - { - AudioQualityImprovement_setFrameSize(aqi, length); - if (aqi->preprocess) - { - float spl; - jboolean suppressEcho; - - AudioQualityImprovement_setInputLatency(aqi, latency); - - if (aqi->echo && aqi->play && aqi->playLength) - { - spl - = AudioQualityImprovement_cancelEchoFromPlay( - aqi, - buffer, length); - suppressEcho = aqi->suppressEcho; - } - else - { - spl = 0; - /* - * Let the echo suppression fade out if it's enabled and - * there hasn't been recent playback. - */ - suppressEcho - = (aqi->suppressEcho && !(aqi->playLength)) - ? JNI_TRUE - : JNI_FALSE; - } - - speex_preprocess_run(aqi->preprocess, buffer); - - if (JNI_TRUE == suppressEcho) - AudioQualityImprovement_suppressEcho( - aqi, - buffer, length / sizeof(spx_int16_t), - spl); - } - } - break; - - case AUDIO_QUALITY_IMPROVEMENT_SAMPLE_ORIGIN_OUTPUT: - if (aqi->preprocess && aqi->echo) - { - AudioQualityImprovement_setOutputLatency(aqi, latency); - AudioQualityImprovement_resampleInPlay( - aqi, - sampleRate, sampleSizeInBits, channels, - buffer, length); - } - break; - } - Mutex_unlock(aqi->mutex); - } -} - -void -AudioQualityImprovement_release(AudioQualityImprovement *aqi) -{ - if (!Mutex_lock(AudioQualityImprovement_sharedInstancesMutex)) - { - if (!Mutex_lock(aqi->mutex)) - { - --(aqi->retainCount); - if (aqi->retainCount < 1) - { - if (aqi == AudioQualityImprovement_sharedInstances) - { - AudioQualityImprovement_sharedInstances - = AudioQualityImprovement_sharedInstances->next; - } - else - { - AudioQualityImprovement *prevSharedInstance - = AudioQualityImprovement_sharedInstances; - - while (prevSharedInstance) - { - AudioQualityImprovement *nextSharedInstance - = prevSharedInstance->next; - - if (aqi == nextSharedInstance) - { - prevSharedInstance->next = aqi->next; - break; - } - prevSharedInstance = nextSharedInstance; - } - } - - Mutex_unlock(aqi->mutex); - AudioQualityImprovement_free(aqi); - } - else - Mutex_unlock(aqi->mutex); - } - Mutex_unlock(AudioQualityImprovement_sharedInstancesMutex); - } -} - -/** - * - * @param aqi - * @param sampleRate - * @param sampleSizeInBits - * @param channels - * @param buffer - * @param length the length of buffer in bytes - */ -static void -AudioQualityImprovement_resampleInPlay - (AudioQualityImprovement *aqi, - double sampleRate, unsigned long sampleSizeInBits, int channels, - void *buffer, unsigned long length) -{ - spx_uint32_t playSize; - spx_uint32_t playCapacity; - spx_uint32_t playLength;; - spx_int16_t *play; - - if (sampleRate == aqi->sampleRate) - playSize = length; - else if (length * aqi->sampleRate == aqi->frameSize * sampleRate) - { - if (aqi->resampler) - { - speex_resampler_set_rate( - aqi->resampler, - (spx_uint32_t) sampleRate, (spx_uint32_t) (aqi->sampleRate)); - playSize = aqi->frameSize; - } - else - { - aqi->resampler - = speex_resampler_init( - channels, - (spx_uint32_t) sampleRate, (spx_uint32_t) (aqi->sampleRate), - SPEEX_RESAMPLER_QUALITY_VOIP, - NULL); - if (aqi->resampler) - playSize = aqi->frameSize; - else - { - aqi->playIsDelaying = JNI_TRUE; - aqi->playLength = 0; - return; - } - } - } - else - { - /* - * The specified buffer neither is in the format of the audio capture - * nor can be resampled to it. - */ - aqi->playIsDelaying = JNI_TRUE; - aqi->playLength = 0; - return; - } - - /* Ensure that play exists and is large enough. */ - playCapacity - = ((1 + aqi->playDelay) + 1) * (aqi->frameSize / sizeof(spx_int16_t)); - playLength = playSize / sizeof(spx_int16_t); - if (playCapacity < playLength) - playCapacity = playLength; - if (!(aqi->play) || (aqi->playCapacity < playCapacity)) - { - spx_int16_t *newPlay; - - newPlay = realloc(aqi->play, playCapacity * sizeof(spx_int16_t)); - if (newPlay) - { - if (!(aqi->play)) - { - aqi->playIsDelaying = JNI_TRUE; - aqi->playLength = 0; - } - - aqi->play = newPlay; - aqi->playCapacity = playCapacity; - } - else - { - aqi->playIsDelaying = JNI_TRUE; - aqi->playLength = 0; - return; - } - } - - /* Ensure that there is room for buffer in play. */ - if (aqi->playLength + playLength > aqi->playCapacity) - { - aqi->playIsDelaying = JNI_TRUE; - aqi->playLength = 0; - /* - * We don't have enough room in play for buffer which means that we'll - * have to throw some samples away. But it'll effectively mean that - * we'll enlarge the drift which will disrupt the echo cancellation. So - * it seems the least of two evils to just reset the echo cancellation. - */ - speex_echo_state_reset(aqi->echo); - } - - /* Place buffer in play. */ - play = aqi->play + aqi->playLength; - if (length == aqi->frameSize) - memcpy(play, buffer, playSize); - else - { - unsigned long sampleSizeInBytes = sampleSizeInBits / 8; - spx_uint32_t bufferSampleCount = length / sampleSizeInBytes; - - speex_resampler_process_interleaved_int( - aqi->resampler, - buffer, &bufferSampleCount, play, &playLength); - } - aqi->playLength += playLength; - - /* Take into account the latency. */ - if (aqi->playIsDelaying == JNI_TRUE) - AudioQualityImprovement_updatePlayIsDelaying(aqi); -} - -static void -AudioQualityImprovement_retain(AudioQualityImprovement *aqi) -{ - if (!Mutex_lock(aqi->mutex)) - { - ++(aqi->retainCount); - Mutex_unlock(aqi->mutex); - } -} - -/** - * Sets the indicator which determines whether noise suppression is to be - * performed by the specified AudioQualityImprovement (for captured - * audio). - * - * @param aqi the AudioQualityImprovement on which to set the indicator - * which determines whether it is to perform noise suppression (for captured audio) - * @param denoise JNI_TRUE if the specified aqi is to perform - * noise suppression (for captured audio); otherwise, JNI_FALSE - */ -void -AudioQualityImprovement_setDenoise - (AudioQualityImprovement *aqi, jboolean denoise) -{ - if (!Mutex_lock(aqi->mutex)) - { - if (aqi->denoise != denoise) - { - aqi->denoise = denoise; - AudioQualityImprovement_updatePreprocess(aqi); - } - Mutex_unlock(aqi->mutex); - } -} - -/** - * Sets the filter length in milliseconds of the echo cancellation - * implementation of the specified AudioQualityImprovement. The - * recommended filter length is approximately the third of the room - * reverberation time. For example, in a small room, reverberation time is in - * the order of 300 ms, so a filter length of 100 ms is a good choice (800 - * samples at 8000 Hz sampling rate). - * - * @param aqi the AudioQualityImprovement to set the filter length of - * @param echoFilterLengthInMillis the filter length in milliseconds of the echo - * cancellation of aqi - */ -void -AudioQualityImprovement_setEchoFilterLengthInMillis - (AudioQualityImprovement *aqi, jlong echoFilterLengthInMillis) -{ - if (echoFilterLengthInMillis < 0) - echoFilterLengthInMillis = 0; - if (!Mutex_lock(aqi->mutex)) - { - if (aqi->echoFilterLengthInMillis != echoFilterLengthInMillis) - { - aqi->echoFilterLengthInMillis = echoFilterLengthInMillis; - AudioQualityImprovement_updatePreprocess(aqi); - } - Mutex_unlock(aqi->mutex); - } -} - -static void -AudioQualityImprovement_setFrameSize - (AudioQualityImprovement *aqi, jint frameSize) -{ - if (aqi->frameSize != frameSize) - { - aqi->frameSize = frameSize; - AudioQualityImprovement_updatePreprocess(aqi); - } -} - -static void -AudioQualityImprovement_setInputLatency - (AudioQualityImprovement *aqi, jlong inputLatency) -{ - if (aqi->inputLatency != inputLatency) - { - aqi->inputLatency = inputLatency; - AudioQualityImprovement_updatePlayDelay(aqi); - } -} - -static void -AudioQualityImprovement_setOutputLatency - (AudioQualityImprovement *aqi, jlong outputLatency) -{ - if (aqi->outputLatency != outputLatency) - { - aqi->outputLatency = outputLatency; - AudioQualityImprovement_updatePlayDelay(aqi); - } -} - -void -AudioQualityImprovement_setSampleRate - (AudioQualityImprovement *aqi, int sampleRate) -{ - if (!Mutex_lock(aqi->mutex)) - { - if (aqi->sampleRate != sampleRate) - { - aqi->sampleRate = sampleRate; - AudioQualityImprovement_updatePlayDelay(aqi); - AudioQualityImprovement_updatePreprocess(aqi); - } - Mutex_unlock(aqi->mutex); - } -} -static void -AudioQualityImprovement_suppressEcho - (AudioQualityImprovement *aqi, - spx_int16_t *buffer, spx_uint32_t length, - float spl) -{ - float amplifier; - spx_int16_t i; - - if (spl < MIN_SOUND_PRESSURE_LEVEL) - spl = MIN_SOUND_PRESSURE_LEVEL; - else if (spl > MAX_SOUND_PRESSURE_LEVEL) - spl = MAX_SOUND_PRESSURE_LEVEL; - - /* Decay #suppressEchoSPL. */ - if (aqi->suppressEchoSPLTime - && (aqi->suppressEchoSPL > MIN_SOUND_PRESSURE_LEVEL)) - { - aqi->suppressEchoSPL - -= (System_currentTimeMillis() - aqi->suppressEchoSPLTime) - * aqi->suppressEchoSPLDecay; - if (aqi->suppressEchoSPL <= MIN_SOUND_PRESSURE_LEVEL) - { - aqi->suppressEchoSPLDecay = 0; - aqi->suppressEchoSPLTime = 0; - } - } - - if (spl < aqi->suppressEchoSPL) - spl = aqi->suppressEchoSPL; - else - { - aqi->suppressEchoSPL = spl; - aqi->suppressEchoSPLDecay - = ((MIN_SOUND_PRESSURE_LEVEL == spl) - ? 1 - : (spl - MIN_SOUND_PRESSURE_LEVEL)) - / 1000.0; - aqi->suppressEchoSPLTime = System_currentTimeMillis(); - } - - amplifier - = 1 - - (spl - MIN_SOUND_PRESSURE_LEVEL) - / (float) (MAX_SOUND_PRESSURE_LEVEL - MIN_SOUND_PRESSURE_LEVEL); - - for (i = 0; i < length; i++) - buffer[i] = (spx_int16_t) (amplifier * buffer[i]); -} - -/** Unloads the AudioQualityImprovement class. */ -void -AudioQualityImprovement_unload() -{ - if (AudioQualityImprovement_sharedInstancesMutex) - { - Mutex_free(AudioQualityImprovement_sharedInstancesMutex); - AudioQualityImprovement_sharedInstancesMutex = NULL; - } -} - -static void -AudioQualityImprovement_updatePlayDelay(AudioQualityImprovement *aqi) -{ - spx_uint32_t playDelay; - - if ((aqi->inputLatency < 0) - || (aqi->outputLatency < 0) - || !(aqi->frameSize) - || !(aqi->sampleRate)) - { - playDelay = MIN_PLAY_DELAY_IN_FRAMES; - } - else - { - playDelay - = (aqi->outputLatency * aqi->sampleRate) - / ((aqi->frameSize / sizeof(spx_int16_t)) * 1000); - if (playDelay < MIN_PLAY_DELAY_IN_FRAMES) - playDelay = MIN_PLAY_DELAY_IN_FRAMES; - } - - if (aqi->playDelay != playDelay) - { - aqi->playDelay = playDelay; - if (aqi->play && (aqi->playIsDelaying == JNI_TRUE)) - AudioQualityImprovement_updatePlayIsDelaying(aqi); - } -} - -/** - * Updates the indicator of the specified AudioQualityImprovement which - * determines whether AudioQualityImprovement#play delays the access to - * it from AudioQualityImprovement#echo. - * - * @param aqi the AudioQualityImprovement of which to update the - * indicator which determines whether AudioQualityImprovement#play - * delays the access to it from AudioQualityImprovement#echo - */ -static void -AudioQualityImprovement_updatePlayIsDelaying(AudioQualityImprovement *aqi) -{ - spx_uint32_t playDelay - = aqi->playDelay * (aqi->frameSize / sizeof(spx_int16_t)); - - aqi->playIsDelaying - = ((aqi->playLength < playDelay) && (playDelay <= aqi->playCapacity)) - ? JNI_TRUE - : JNI_FALSE; -} - -static void -AudioQualityImprovement_updatePreprocess(AudioQualityImprovement *aqi) -{ - if (aqi->echo) - { - int frameSize = 0; - - if ((aqi->echoFilterLengthInMillis > 0) - && (aqi->sampleRate > 0) - && speex_echo_ctl( - aqi->echo, - SPEEX_ECHO_GET_FRAME_SIZE, &frameSize)) - frameSize = 0; - if (frameSize - && (aqi->frameSize - == (frameSize * (16 /* sampleSizeInBits */ / 8)))) - { - int echoFilterLength - = (int) - ((aqi->sampleRate * aqi->echoFilterLengthInMillis) - / 1000); - - if (aqi->filterLengthOfEcho != echoFilterLength) - frameSize = 0; - } - else - frameSize = 0; - if (frameSize < 1) - { - if (aqi->preprocess) - { - speex_preprocess_ctl( - aqi->preprocess, - SPEEX_PREPROCESS_SET_ECHO_STATE, NULL); - } - speex_echo_state_destroy(aqi->echo); - aqi->echo = NULL; - } - } - if (aqi->preprocess - && ((aqi->frameSize != aqi->frameSizeOfPreprocess) - || (aqi->sampleRate != aqi->sampleRateOfPreprocess))) - { - speex_preprocess_state_destroy(aqi->preprocess); - aqi->preprocess = NULL; - } - if ((aqi->frameSize > 0) && (aqi->sampleRate > 0)) - { - if (aqi->echoFilterLengthInMillis > 0) - { - if (!(aqi->echo)) - { - int echoFrameSize - = aqi->frameSize / (16 /* sampleSizeInBits */ / 8); - int echoFilterLength - = (int) - ((aqi->sampleRate * aqi->echoFilterLengthInMillis) - / 1000); - - aqi->echo - = speex_echo_state_init(echoFrameSize, echoFilterLength); - aqi->filterLengthOfEcho = echoFilterLength; - /* - * Since echo has just been (re)created, make sure that the - * delay in play will happen again taking into consideration the - * latest frameSize. - */ - if (aqi->play) - AudioQualityImprovement_updatePlayIsDelaying(aqi); - } - if (aqi->echo) - { - speex_echo_ctl( - aqi->echo, - SPEEX_ECHO_SET_SAMPLING_RATE, &(aqi->sampleRate)); - } - } - if (aqi->denoise || aqi->echo) - { - if (!(aqi->preprocess)) - { - aqi->preprocess - = speex_preprocess_state_init( - aqi->frameSize / (16 /* sampleSizeInBits */ / 8), - aqi->sampleRate); - aqi->frameSizeOfPreprocess = aqi->frameSize; - aqi->sampleRateOfPreprocess = aqi->sampleRate; - if (aqi->preprocess) - { - int on = 1; - - speex_preprocess_ctl( - aqi->preprocess, - SPEEX_PREPROCESS_SET_DEREVERB, &on); - speex_preprocess_ctl( - aqi->preprocess, - SPEEX_PREPROCESS_SET_VAD, &on); - } - } - if (aqi->preprocess) - { - int denoise = (aqi->denoise == JNI_TRUE) ? 1 : 0; - - speex_preprocess_ctl( - aqi->preprocess, - SPEEX_PREPROCESS_SET_DENOISE, &denoise); - if (aqi->echo) - { - speex_preprocess_ctl( - aqi->preprocess, - SPEEX_PREPROCESS_SET_ECHO_STATE, aqi->echo); - } - } - } - } -} - -/** - * Returns the current time in milliseconds (akin to - * java.lang.System#currentTimeMillis()). - * - * @return the current time in milliseconds - */ -static jlong -System_currentTimeMillis() -{ - struct timeval tv; - - return - (gettimeofday(&tv, NULL) == 0) - ? ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)) - : -1; -} diff --git a/src/native/portaudio/AudioQualityImprovement.h b/src/native/portaudio/AudioQualityImprovement.h deleted file mode 100644 index 6aa2f83b3..000000000 --- a/src/native/portaudio/AudioQualityImprovement.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ - -#ifndef _NET_JAVA_SIP_COMMUNICATOR_IMPL_NEOMEDIA_PORTAUDIO_AUDIOQUALITYIMPROVEMENT_H_ -#define _NET_JAVA_SIP_COMMUNICATOR_IMPL_NEOMEDIA_PORTAUDIO_AUDIOQUALITYIMPROVEMENT_H_ - -#include - -/** - * The minimum number of frames by which the playback is to be delayed before it - * is accessible to the echo cancellation/capture. - */ -#define MIN_PLAY_DELAY_IN_FRAMES 2 - -#ifndef AUDIO_QUALITY_IMPROVEMENT_IMPLEMENTATION -typedef void *AudioQualityImprovement; -#else /* #ifndef AUDIO_QUALITY_IMPROVEMENT_IMPLEMENTATION */ - -#include "Mutex.h" -#include -#include -#include - -typedef struct _AudioQualityImprovement -{ - jboolean denoise; - SpeexEchoState *echo; - jlong echoFilterLengthInMillis; - - /** The length of the echo cancelling filter of #echo in samples. */ - int filterLengthOfEcho; - jint frameSize; - int frameSizeOfPreprocess; - - /** The capture latency in milliseconds. */ - jlong inputLatency; - jlong longID; - Mutex *mutex; - struct _AudioQualityImprovement *next; - - /** - * The intermediate buffer into which the result of echo cancellation is - * written for a specific buffer of captured audio. - */ - spx_int16_t *out; - - /** The capacity of #out in bytes. */ - spx_uint32_t outCapacity; - - /** The playback latency in milliseconds. */ - jlong outputLatency; - spx_int16_t *play; - - /** - * The number of samples allocated to #play regardless of whether they are - * valid or not. - */ - spx_uint32_t playCapacity; - - /** The number of frames to delay playback with. */ - spx_uint32_t playDelay; - - /** - * The indicator which determines whether #play is currently delaying the - * access to it from #echo. - */ - jboolean playIsDelaying; - - /** The number of valid samples written into #play. */ - spx_uint32_t playLength; - SpeexPreprocessState *preprocess; - SpeexResamplerState *resampler; - int retainCount; - int sampleRate; - int sampleRateOfPreprocess; - char *stringID; - - /** The indicator which determines whether echo suppression is enabled. */ - jboolean suppressEcho; - - /** - * The sound pressure level in dB depending on which the echo suppression, - * if enabled, decreases the sound volume of the captured oudio. - */ - float suppressEchoSPL; - - /** The decay in dB per millisecond of #suppressEchoSPL. */ - float suppressEchoSPLDecay; - - /** - * The time in milliseconds at which #suppressEchoSPL has last been assigned - * a value and thus determines how much #suppressEchoSPLDecay is to be - * applied to #suppressEchoSPL at a certain point in time. - */ - jlong suppressEchoSPLTime; -} AudioQualityImprovement; - -#endif /* #ifndef AUDIO_QUALITY_IMPROVEMENT_IMPLEMENTATION */ - -typedef enum -{ - /** - * The constant which indicates that the associated samples have originated - * from an input stream i.e. capture. - */ - AUDIO_QUALITY_IMPROVEMENT_SAMPLE_ORIGIN_INPUT, - - /** - * The constant which indicates that the associated samples have originated - * from an output stream i.e. playback. - */ - AUDIO_QUALITY_IMPROVEMENT_SAMPLE_ORIGIN_OUTPUT -} AudioQualityImprovementSampleOrigin; - -AudioQualityImprovement *AudioQualityImprovement_getSharedInstance - (const char *stringID, jlong longID); - -/** Loads the AudioQualityImprovement class. */ -void AudioQualityImprovement_load(); -void AudioQualityImprovement_process - (AudioQualityImprovement *aqi, - AudioQualityImprovementSampleOrigin sampleOrigin, - double sampleRate, unsigned long sampleSizeInBits, int channels, - jlong latency, - void *buffer, unsigned long length); -void AudioQualityImprovement_release(AudioQualityImprovement *aqi); - -/** - * Sets the indicator which determines whether noise suppression is to be - * performed by the specified AudioQualityImprovement (for captured - * audio). - * - * @param aqi the AudioQualityImprovement on which to set the indicator - * which determines whether it is to perform noise suppression (for captured audio) - * @param denoise JNI_TRUE if the specified aqi is to perform - * noise suppression (for captured audio); otherwise, JNI_FALSE - */ -void AudioQualityImprovement_setDenoise - (AudioQualityImprovement *aqi, jboolean denoise); - -/** - * Sets the filter length in milliseconds of the echo cancellation - * implementation of the specified AudioQualityImprovement. The - * recommended filter length is approximately the third of the room - * reverberation time. For example, in a small room, reverberation time is in - * the order of 300 ms, so a filter length of 100 ms is a good choice (800 - * samples at 8000 Hz sampling rate). - * - * @param aqi the AudioQualityImprovement to set the filter length of - * @param echoFilterLengthInMillis the filter length in milliseconds of the echo - * cancellation of aqi - */ -void AudioQualityImprovement_setEchoFilterLengthInMillis - (AudioQualityImprovement *aqi, jlong echoFilterLengthInMillis); -void AudioQualityImprovement_setSampleRate - (AudioQualityImprovement *aqi, int sampleRate); - -/** Unloads the AudioQualityImprovement class. */ -void AudioQualityImprovement_unload(); - -#endif /* #ifndef _NET_JAVA_SIP_COMMUNICATOR_IMPL_NEOMEDIA_PORTAUDIO_AUDIOQUALITYIMPROVEMENT_H_ */ diff --git a/src/native/portaudio/ConditionVariable.h b/src/native/portaudio/ConditionVariable.h deleted file mode 100644 index 30a65502f..000000000 --- a/src/native/portaudio/ConditionVariable.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ - -#ifndef _NET_JAVA_SIP_COMMUNICATOR_IMPL_NEOMEDIA_CONDITIONVARIABLE_H_ -#define _NET_JAVA_SIP_COMMUNICATOR_IMPL_NEOMEDIA_CONDITIONVARIABLE_H_ - -#include "Mutex.h" - -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include - -typedef HANDLE ConditionVariable; - -static inline void ConditionVariable_free(ConditionVariable *condVar) -{ - if (CloseHandle(*condVar)) - free(condVar); -} - -static inline ConditionVariable *ConditionVariable_new(void *attr) -{ - ConditionVariable *condVar = malloc(sizeof(ConditionVariable)); - - if (condVar) - { - HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL); - - if (event) - *condVar = event; - else - { - free(condVar); - condVar = NULL; - } - } - return condVar; -} - -static inline int ConditionVariable_notify(ConditionVariable *condVar) -{ - return SetEvent(*condVar) ? 0 : GetLastError(); -} - -static inline int ConditionVariable_wait - (ConditionVariable *condVar, Mutex *mutex) -{ - DWORD waitForSingleObject; - - LeaveCriticalSection(mutex); - waitForSingleObject = WaitForSingleObject(*condVar, INFINITE); - EnterCriticalSection(mutex); - return waitForSingleObject; -} - -#else /* #ifdef _WIN32 */ -#include - -typedef pthread_cond_t ConditionVariable; - -static inline void ConditionVariable_free(ConditionVariable *condVar) -{ - if (!pthread_cond_destroy(condVar)) - free(condVar); -} - -static inline ConditionVariable *ConditionVariable_new(void *attr) -{ - ConditionVariable *condVar = malloc(sizeof(ConditionVariable)); - - if (condVar && pthread_cond_init(condVar, attr)) - { - free(condVar); - condVar = NULL; - } - return condVar; -} - -static inline int ConditionVariable_notify(ConditionVariable *condVar) -{ - return pthread_cond_signal(condVar); -} - -static inline int ConditionVariable_wait - (ConditionVariable *condVar, Mutex *mutex) -{ - return pthread_cond_wait(condVar, mutex); -} -#endif /* #ifdef _WIN32 */ - -#endif /* _NET_JAVA_SIP_COMMUNICATOR_IMPL_NEOMEDIA_CONDITIONVARIABLE_H_ */ diff --git a/src/native/portaudio/Makefile b/src/native/portaudio/Makefile deleted file mode 100644 index f83a7ebed..000000000 --- a/src/native/portaudio/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -PORTAUDIO_HOME?=../../../../portaudio-20101214 -SPEEX_HOME?=../../../../speex-1.2rc1 - -CC=gcc -TARGET_BASENAME=jnportaudio - -OS=$(shell $(CC) -dumpmachine | sed -e s/.*-apple-.*/mac/ -e s/.*-linux-.*/linux/ -e s/.*-.*-mingw32/windows/) -ifeq "$(OS)" "mac" - JAVA_HOME?=/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.5 - CC:=$(CC) -arch i386 -arch ppc -arch x86_64 -mmacosx-version-min=10.4 - CPPFLAGS=-I$(JAVA_HOME)/Headers - LDFLAGS=-dynamiclib - LIBS=-framework AudioToolbox -framework AudioUnit -framework CoreAudio -framework Carbon \ - -lpthread -pthread -lm -dynamic -lportaudio -lspeexdsp - TARGET=../../../lib/native/mac/lib$(TARGET_BASENAME).jnilib -else - ARCH=$(shell $(CC) -dumpmachine | sed -e s/x86_64-.*/-64/ -e s/i.86-.*//) - LDFLAGS=-shared - ifeq "$(OS)" "linux" - JAVA_HOME?=/usr/lib/jvm/java-6-sun - CPPFLAGS=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux - LIBS=-Wl,-Bstatic -lportaudio -lspeexdsp -Wl,-Bdynamic -lrt -lasound -lm -lpthread - TARGET=../../../lib/native/$(OS)$(ARCH)/lib$(TARGET_BASENAME).so - else ifeq "$(OS)" "windows" - DXSDK_HOME?=/c/Users/lyubomir/Downloads/DXSDK_Jun10 - ifeq "$(ARCH)" "-64" - JAVA_HOME?=C:/PROGRA~1/jdk - LIBS=-L$(DXSDK_HOME)/Lib/x64 - else - JAVA_HOME?=C:/PROGRA~2/jdk - LIBS=-L$(DXSDK_HOME)/Lib/x86 - endif - CPPFLAGS=-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/win32 -I$(DXSDK_HOME)/Include - LDFLAGS:=-Wl,--kill-at $(LDFLAGS) - LIBS:=$(LIBS) -static -lportaudio -lspeexdsp -lwinmm -ldsound -lm -lstdc++ -lole32 -luuid - TARGET=../../../lib/native/$(OS)$(ARCH)/$(TARGET_BASENAME).dll - endif -endif - -CPPFLAGS:=-D_JNI_IMPLEMENTATION_ \ - -I$(SPEEX_HOME)/include -I$(PORTAUDIO_HOME)/include \ - -O2 \ - -Wall \ - $(CPPFLAGS) -LDFLAGS:=-fPIC $(LDFLAGS) -LIBS:=-L$(PORTAUDIO_HOME)/lib/.libs -L$(SPEEX_HOME)/libspeex/.libs $(LIBS) - -$(TARGET): net_java_sip_communicator_impl_neomedia_portaudio_PortAudio.c AudioQualityImprovement.c - $(CC) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ $(LIBS) - -strip $(TARGET) diff --git a/src/native/portaudio/Mutex.h b/src/native/portaudio/Mutex.h deleted file mode 100644 index 93ab3ec79..000000000 --- a/src/native/portaudio/Mutex.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ - -#ifndef _NET_JAVA_SIP_COMMUNICATOR_IMPL_NEOMEDIA_PORTAUDIO_MUTEX_H_ -#define _NET_JAVA_SIP_COMMUNICATOR_IMPL_NEOMEDIA_PORTAUDIO_MUTEX_H_ - -#include - -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include - -typedef CRITICAL_SECTION Mutex; - -static inline void Mutex_free(Mutex* mutex) -{ - DeleteCriticalSection(mutex); - free(mutex); -} - -static inline int Mutex_lock(Mutex* mutex) -{ - EnterCriticalSection(mutex); - return 0; -} - -static inline Mutex *Mutex_new(void* attr) -{ - Mutex *mutex = malloc(sizeof(Mutex)); - - (void) attr; - - if (mutex) - InitializeCriticalSection(mutex); - return mutex; -} - -static inline int Mutex_unlock(Mutex* mutex) -{ - LeaveCriticalSection(mutex); - return 0; -} - -#else /* #ifdef _WIN32 */ -#include - -typedef pthread_mutex_t Mutex; - -static inline void Mutex_free(Mutex* mutex) -{ - if (!pthread_mutex_destroy(mutex)) - free(mutex); -} - -static inline int Mutex_lock(Mutex* mutex) -{ - return pthread_mutex_lock(mutex); -} - -static inline Mutex *Mutex_new(void* attr) -{ - Mutex *mutex = malloc(sizeof(Mutex)); - - if (mutex && pthread_mutex_init(mutex, attr)) - { - free(mutex); - mutex = NULL; - } - return mutex; -} - -static inline int Mutex_unlock(Mutex* mutex) -{ - return pthread_mutex_unlock(mutex); -} -#endif /* #ifdef _WIN32 */ - -#endif /* #ifndef _NET_JAVA_SIP_COMMUNICATOR_IMPL_NEOMEDIA_PORTAUDIO_MUTEX_H_ */ diff --git a/src/native/portaudio/README b/src/native/portaudio/README deleted file mode 100644 index 32249088c..000000000 --- a/src/native/portaudio/README +++ /dev/null @@ -1,40 +0,0 @@ -1. portaudio - - Get portaudio-hotplug branch and apply the portaudio-hotplug-os patch: - $ svn -r 1821 co https://subversion.assembla.com/svn/portaudio/portaudio/branches/hotplug - $ patch -p0 < portaudio-hotplug-os.patch - $ autoreconf -i (OS X and Linux only) - - - Linux/FreeBSD - pa_linux_alsa.c-by-Werner.patch (already in portaudio-hotplug-os.patch) - pa_linux_alsa.c-fix-blocked-renderer.patch (already in portaudio-hotplug-os.patch) - $ ./configure --disable-shared --enable-static --with-pic --with-jack=no && make/gmake - - - Mac OS X - $ export MACOSX_DEPLOYMENT_TARGET=10.4 - $ ./configure --disable-shared --enable-static --with-pic && make - - - Windows - Use msys and mingw (A gui installer, use latest - http://sf.net/projects/mingw/files/Installer/mingw-get-inst/ this can - only compile 32bit). - Download directx devpack for MinGW at http://www.dgrigoriadis.net/post/2004/06/26/DirectXDevPak-for-Dev-Cpp.aspx and - extract it. (May neeto to remove the define for WAVEFORMATEXTENSIBLE - (#ifndef _WAVEFORMATEXTENSIBLE_ .....) include/ksmedia.h) - - $ DXDIR=/path/to/directx_dev_pack_directory - $ CFLAGS="-DWINVER=0x501" ./configure --disable-shared --enable-static --with-pic --with-dxdir=$DXDIR --with-winapi=wmme,directx,wdmks && make - -2. speex - - Linux/FreeBSD, Windows - $ ./configure --disable-shared --enable-static --with-pic && make/gmake - - - Mac OS X - $ export MACOSX_DEPLOYMENT_TARGET=10.4 - $ export CC="gcc -arch i386 -arch ppc -arch x86_64 -mmacosx-version-min=10.4" - $ export CPP="gcc -E" - $ ./configure --disable-shared --enable-static --with-pic && make - -3. jportaudio - - Linux/FreeBSD, Mac OS X, Windows - $ make/gmake diff --git a/src/native/portaudio/net_java_sip_communicator_impl_neomedia_portaudio_PortAudio.c b/src/native/portaudio/net_java_sip_communicator_impl_neomedia_portaudio_PortAudio.c deleted file mode 100644 index 629025b80..000000000 --- a/src/native/portaudio/net_java_sip_communicator_impl_neomedia_portaudio_PortAudio.c +++ /dev/null @@ -1,1649 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ - -#include "net_java_sip_communicator_impl_neomedia_portaudio_PortAudio.h" - -#include "AudioQualityImprovement.h" -#include "ConditionVariable.h" -#include "Mutex.h" -#include -#include -#include -#include -#include -#include - -typedef struct -{ - AudioQualityImprovement *audioQualityImprovement; - int channels; - JNIEnv *env; - jboolean finished; - - /** - * The value specified as the framesPerBuffer argument to the - * Pa_OpenStream function call which has opened #stream. - */ - unsigned long framesPerBuffer; - void *input; - size_t inputCapacity; - ConditionVariable *inputCondVar; - long inputFrameSize; - - /** The input latency of #stream. */ - jlong inputLatency; - size_t inputLength; - Mutex *inputMutex; - Mutex *mutex; - void *output; - size_t outputCapacity; - ConditionVariable *outputCondVar; - long outputFrameSize; - - /** The output latency of #stream. */ - jlong outputLatency; - size_t outputLength; - Mutex *outputMutex; - - /** - * The indicator which determines whether this PortAudioStream - * implements the blocking stream interface on top of the non-blocking - * stream interface. - */ - jboolean pseudoBlocking; - jlong retainCount; - double sampleRate; - int sampleSizeInBits; - PaStream *stream; - jobject streamCallback; - jmethodID streamCallbackMethodID; - jmethodID streamFinishedCallbackMethodID; - JavaVM *vm; -} PortAudioStream; - -static void PortAudio_devicesChangedCallback(void *userData); -static PaStreamParameters *PortAudio_fixInputParametersSuggestedLatency - (PaStreamParameters *inputParameters, - jdouble sampleRate, jlong framesPerBuffer, - PaHostApiTypeId hostApiType); -static PaStreamParameters *PortAudio_fixOutputParametersSuggestedLatency - (PaStreamParameters *outputParameters, - jdouble sampleRate, jlong framesPerBuffer, - PaHostApiTypeId hostApiType); -static PaStreamParameters *PortAudio_fixStreamParametersSuggestedLatency - (PaStreamParameters *streamParameters, - jdouble sampleRate, jlong framesPerBuffer, - PaHostApiTypeId hostApiType); -static long PortAudio_getFrameSize(PaStreamParameters *streamParameters); -static unsigned long PortAudio_getSampleSizeInBits - (PaStreamParameters *streamParameters); -static void PortAudio_throwException(JNIEnv *env, PaError errorCode); - -/** - * Allocates (and initializes) the memory and its associated variables for a - * specific buffer to be used by the pseudo-blocking stream interface - * implementation of a PortAudioStream. - * - * @param capacity the number of bytes to be allocated to the buffer - * @param bufferPtr a pointer which specifies where the location of the - * allocated buffer is to be stored - * @param bufferLengthPtr a pointer which specifies where the initial length - * (i.e. zero) is to be stored - * @param bufferCapacityPtr a pointer which specifies where the capacity of the - * allocated buffer is to be stored - * @param bufferMutexPtr a pointer which specifies where the Mute to - * synchronize the access to the allocated buffer is to be stored - * @param bufferCondVarPtr a pointer which specifies where the - * ConditionVariable to synchronize the access to the allocated buffer - * is to be stored - * @return the location of the allocated buffer upon success; otherwise, - * NULL - */ -static void *PortAudioStream_allocPseudoBlockingBuffer - (size_t capacity, - void **bufferPtr, size_t *bufferLengthPtr, size_t *bufferCapacityPtr, - Mutex **bufferMutexPtr, ConditionVariable **bufferCondVarPtr); -static void PortAudioStream_free(JNIEnv *env, PortAudioStream *stream); -static int PortAudioStream_javaCallback - (const void *input, - void *output, - unsigned long frameCount, - const PaStreamCallbackTimeInfo *timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData); -static void PortAudioStream_javaFinishedCallback(void *userData); -static PortAudioStream * PortAudioStream_new - (JNIEnv *env, jobject streamCallback); -static void PortAudioStream_popFromPseudoBlockingBuffer - (void *buffer, size_t length, size_t *bufferLengthPtr); -static int PortAudioStream_pseudoBlockingCallback - (const void *input, - void *output, - unsigned long frameCount, - const PaStreamCallbackTimeInfo *timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData); -static void PortAudioStream_pseudoBlockingFinishedCallback(void *userData); -static void PortAudioStream_release(PortAudioStream *stream); -static void PortAudioStream_retain(PortAudioStream *stream); - -static const char *AUDIO_QUALITY_IMPROVEMENT_STRING_ID = "portaudio"; -#define LATENCY_HIGH net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_LATENCY_HIGH -#define LATENCY_LOW net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_LATENCY_LOW -#define LATENCY_UNSPECIFIED net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_LATENCY_UNSPECIFIED - -static jclass PortAudio_devicesChangedCallbackClass = 0; -static jmethodID PortAudio_devicesChangedCallbackMethodID = 0; -static JavaVM* PortAudio_vm = 0; - -JNIEXPORT void JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_free - (JNIEnv *env, jclass clazz, jlong ptr) -{ - free((void *) (intptr_t) ptr); -} - -JNIEXPORT void JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1AbortStream - (JNIEnv *env, jclass clazz, jlong stream) -{ - PaError errorCode - = Pa_AbortStream(((PortAudioStream *) (intptr_t) stream)->stream); - - if (paNoError != errorCode) - PortAudio_throwException(env, errorCode); -} - -JNIEXPORT void JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1CloseStream - (JNIEnv *env, jclass clazz, jlong stream) -{ - PortAudioStream *portAudioStream = (PortAudioStream *) (intptr_t) stream; - PaError errorCode = Pa_CloseStream(portAudioStream->stream); - - if (paNoError != errorCode) - PortAudio_throwException(env, errorCode); - else if (portAudioStream->pseudoBlocking) - PortAudioStream_release(portAudioStream); - else - PortAudioStream_free(env, portAudioStream); -} - -JNIEXPORT jint JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetDefaultInputDevice - (JNIEnv *env, jclass clazz) -{ - return Pa_GetDefaultInputDevice(); -} - -JNIEXPORT jint JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetDefaultOutputDevice - (JNIEnv *env, jclass clazz) -{ - return Pa_GetDefaultOutputDevice(); -} - -JNIEXPORT jint JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetDeviceCount( - JNIEnv *env, jclass clazz) -{ - PaDeviceIndex deviceCount = Pa_GetDeviceCount(); - - if (deviceCount < 0) - PortAudio_throwException(env, deviceCount); - return deviceCount; -} - -JNIEXPORT jlong JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetDeviceInfo( - JNIEnv *env, jclass clazz, jint deviceIndex) -{ - return (jlong) (intptr_t) Pa_GetDeviceInfo(deviceIndex); -} - -JNIEXPORT jlong JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetHostApiInfo - (JNIEnv *env , jclass clazz, jint hostApiIndex) -{ - return (jlong) (intptr_t) Pa_GetHostApiInfo(hostApiIndex); -} - -JNIEXPORT jint JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetSampleSize - (JNIEnv *env, jclass clazz, jlong format) -{ - return Pa_GetSampleSize(format); -} - -JNIEXPORT jlong JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetStreamReadAvailable - (JNIEnv *env, jclass clazz, jlong stream) -{ - return - Pa_GetStreamReadAvailable( - ((PortAudioStream *) (intptr_t) stream)->stream); -} - -JNIEXPORT jlong JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetStreamWriteAvailable - (JNIEnv *env, jclass clazz, jlong stream) -{ - return - Pa_GetStreamWriteAvailable( - ((PortAudioStream *) (intptr_t) stream)->stream); -} - -JNIEXPORT void JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1Initialize - (JNIEnv *env, jclass clazz) -{ - PaError errorCode = Pa_Initialize(); - - if (paNoError == errorCode) - { - jclass devicesChangedCallbackClass - = (*env)->FindClass( - env, - "net/java/sip/communicator/impl/neomedia/portaudio/PortAudio"); - - if (devicesChangedCallbackClass) - { - devicesChangedCallbackClass - = (*env)->NewGlobalRef(env, devicesChangedCallbackClass); - if (devicesChangedCallbackClass) - { - jmethodID devicesChangedCallbackMethodID - = (*env)->GetStaticMethodID( - env, - devicesChangedCallbackClass, - "devicesChangedCallback", - "()V"); - - if (devicesChangedCallbackMethodID) - { - PortAudio_devicesChangedCallbackClass - = devicesChangedCallbackClass; - PortAudio_devicesChangedCallbackMethodID - = devicesChangedCallbackMethodID; - Pa_SetDevicesChangedCallback( - NULL, - PortAudio_devicesChangedCallback); - } - } - } - } - else - PortAudio_throwException(env, errorCode); -} - -JNIEXPORT jboolean JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1IsFormatSupported - (JNIEnv *env, jclass clazz, - jlong inputParameters, jlong outputParameters, jdouble sampleRate) -{ - if (Pa_IsFormatSupported( - (PaStreamParameters *) (intptr_t) inputParameters, - (PaStreamParameters *) (intptr_t) outputParameters, - sampleRate) - == paFormatIsSupported) - return JNI_TRUE; - else - return JNI_FALSE; -} - -JNIEXPORT jlong JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1OpenStream - (JNIEnv *env, jclass clazz, - jlong inputParameters, jlong outputParameters, - jdouble sampleRate, - jlong framesPerBuffer, - jlong streamFlags, - jobject streamCallback) -{ - PortAudioStream *stream = PortAudioStream_new(env, streamCallback); - PaStreamCallback *effectiveStreamCallback; - PaStreamFinishedCallback *effectiveStreamFinishedCallback; - unsigned long effectiveFramesPerBuffer = framesPerBuffer; - PaHostApiTypeId hostApiType = paInDevelopment; - PaError errorCode; - PaStreamParameters *inputStreamParameters - = (PaStreamParameters *) (intptr_t) inputParameters; - PaStreamParameters *outputStreamParameters - = (PaStreamParameters *) (intptr_t) outputParameters; - - if (!stream) - return 0; - - if (streamCallback) - { - effectiveStreamCallback = PortAudioStream_javaCallback; - effectiveStreamFinishedCallback = PortAudioStream_javaFinishedCallback; - stream->pseudoBlocking = JNI_FALSE; - } - else - { - /* - * Some host APIs such as DirectSound don't really implement the - * blocking stream interface. If we're to ever be able to try them out, - * we'll have to implement the blocking stream interface on top of the - * non-blocking stream interface. - */ - - effectiveStreamCallback = NULL; - effectiveStreamFinishedCallback = NULL; - stream->pseudoBlocking = JNI_FALSE; - - /* - * TODO It should be possible to implement the blocking stream interface - * without a specific framesPerBuffer. - */ - if ((paFramesPerBufferUnspecified != framesPerBuffer) - && (framesPerBuffer > 0)) - { - PaDeviceIndex device; - - if (outputStreamParameters) - device = outputStreamParameters->device; - else if (inputStreamParameters) - device = inputStreamParameters->device; - else - device = paNoDevice; - if (device != paNoDevice) - { - const PaDeviceInfo *deviceInfo = Pa_GetDeviceInfo(device); - - if (deviceInfo) - { - const PaHostApiInfo *hostApiInfo - = Pa_GetHostApiInfo(deviceInfo->hostApi); - - if (hostApiInfo) - { - switch (hostApiInfo->type) - { - case paCoreAudio: - /* - * If we are to ever succeed in requesting a higher - * latency in - * PortAudio_fixOutputParametersSuggestedLatency, we - * have to specify paFramesPerBufferUnspecified. - * Otherwise, the CoreAudio implementation of - * PortAudio will ignore our suggestedLatency. - */ - if (outputStreamParameters - && ((LATENCY_HIGH - == outputStreamParameters - ->suggestedLatency) - || (LATENCY_UNSPECIFIED - == outputStreamParameters - ->suggestedLatency))) - { - effectiveFramesPerBuffer - = paFramesPerBufferUnspecified; - hostApiType = hostApiInfo->type; - } - if (inputStreamParameters - && ((LATENCY_HIGH - == inputStreamParameters - ->suggestedLatency) - || (LATENCY_UNSPECIFIED - == inputStreamParameters - ->suggestedLatency))) - { - effectiveFramesPerBuffer - = paFramesPerBufferUnspecified; - hostApiType = hostApiInfo->type; - } - break; - case paDirectSound: - effectiveStreamCallback - = PortAudioStream_pseudoBlockingCallback; - effectiveStreamFinishedCallback - = PortAudioStream_pseudoBlockingFinishedCallback; - stream->pseudoBlocking = JNI_TRUE; - break; - default: - break; - } - } - } - } - } - } - - if (JNI_TRUE == stream->pseudoBlocking) - { - stream->mutex = Mutex_new(NULL); - errorCode = (stream->mutex) ? paNoError : paInsufficientMemory; - } - else - errorCode = paNoError; - - if (paNoError == errorCode) - { - errorCode - = Pa_OpenStream( - &(stream->stream), - PortAudio_fixInputParametersSuggestedLatency( - inputStreamParameters, - sampleRate, framesPerBuffer, - hostApiType), - PortAudio_fixOutputParametersSuggestedLatency( - outputStreamParameters, - sampleRate, framesPerBuffer, - hostApiType), - sampleRate, - effectiveFramesPerBuffer, - streamFlags, - effectiveStreamCallback, - stream); - } - - if (paNoError == errorCode) - { - stream->framesPerBuffer = effectiveFramesPerBuffer; - stream->inputFrameSize - = PortAudio_getFrameSize(inputStreamParameters); - stream->outputFrameSize - = PortAudio_getFrameSize(outputStreamParameters); - stream->sampleRate = sampleRate; - - if (effectiveStreamFinishedCallback) - { - errorCode - = Pa_SetStreamFinishedCallback( - stream->stream, - effectiveStreamFinishedCallback); - } - - stream->audioQualityImprovement - = AudioQualityImprovement_getSharedInstance( - AUDIO_QUALITY_IMPROVEMENT_STRING_ID, - 0); - if (inputStreamParameters) - { - stream->sampleSizeInBits - = PortAudio_getSampleSizeInBits(inputStreamParameters); - stream->channels = inputStreamParameters->channelCount; - - /* - * Prepare whatever is necessary for the pseudo-blocking stream - * interface implementation. For example, allocate its memory early - * because doing it in the stream callback may introduce latency. - */ - if (stream->pseudoBlocking - && !PortAudioStream_allocPseudoBlockingBuffer( - 2 * framesPerBuffer * (stream->inputFrameSize), - &(stream->input), - &(stream->inputLength), - &(stream->inputCapacity), - &(stream->inputMutex), - &(stream->inputCondVar))) - { - Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1CloseStream( - env, clazz, - (jlong) (intptr_t) stream); - if (JNI_FALSE == (*env)->ExceptionCheck(env)) - { - PortAudio_throwException(env, paInsufficientMemory); - return 0; - } - } - - if (stream->audioQualityImprovement) - { - AudioQualityImprovement_setSampleRate( - stream->audioQualityImprovement, - (int) sampleRate); - - if (stream->pseudoBlocking) - { - const PaStreamInfo *streamInfo; - - streamInfo = Pa_GetStreamInfo(stream->stream); - if (streamInfo) - { - stream->inputLatency - = (jlong) (streamInfo->inputLatency * 1000); - } - } - } - } - if (outputStreamParameters) - { - stream->sampleSizeInBits - = PortAudio_getSampleSizeInBits(outputStreamParameters); - stream->channels = outputStreamParameters->channelCount; - - if (stream->pseudoBlocking - && !PortAudioStream_allocPseudoBlockingBuffer( - 2 * framesPerBuffer * (stream->outputFrameSize), - &(stream->output), - &(stream->outputLength), - &(stream->outputCapacity), - &(stream->outputMutex), - &(stream->outputCondVar))) - { - Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1CloseStream( - env, clazz, - (jlong) (intptr_t) stream); - if (JNI_FALSE == (*env)->ExceptionCheck(env)) - { - PortAudio_throwException(env, paInsufficientMemory); - return 0; - } - } - - if (stream->audioQualityImprovement) - { - const PaStreamInfo *streamInfo; - - streamInfo = Pa_GetStreamInfo(stream->stream); - if (streamInfo) - { - stream->outputLatency - = (jlong) (streamInfo->outputLatency * 1000); - } - } - } - - if (stream->pseudoBlocking) - PortAudioStream_retain(stream); - - return (jlong) (intptr_t) stream; - } - else - { - PortAudioStream_free(env, stream); - PortAudio_throwException(env, errorCode); - return 0; - } -} - -JNIEXPORT void JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1ReadStream - (JNIEnv *env, jclass clazz, jlong stream, jbyteArray buffer, jlong frames) -{ - jbyte* data = (*env)->GetByteArrayElements(env, buffer, NULL); - - if (data) - { - PortAudioStream *portAudioStream - = (PortAudioStream *) (intptr_t) stream; - PaError errorCode; - jlong framesInBytes = frames * portAudioStream->inputFrameSize; - - if (portAudioStream->pseudoBlocking) - { - if (Mutex_lock(portAudioStream->inputMutex)) - errorCode = paInternalError; - else - { - jlong bytesRead = 0; - - errorCode = paNoError; - while (bytesRead < framesInBytes) - { - jlong bytesToRead; - - if (JNI_TRUE == portAudioStream->finished) - { - errorCode = paStreamIsStopped; - break; - } - if (!(portAudioStream->inputLength)) - { - ConditionVariable_wait( - portAudioStream->inputCondVar, - portAudioStream->inputMutex); - continue; - } - - bytesToRead = framesInBytes - bytesRead; - if (bytesToRead > portAudioStream->inputLength) - bytesToRead = portAudioStream->inputLength; - memcpy( - data + bytesRead, - portAudioStream->input, - bytesToRead); - PortAudioStream_popFromPseudoBlockingBuffer( - portAudioStream->input, - bytesToRead, - &(portAudioStream->inputLength)); - bytesRead += bytesToRead; - } - Mutex_unlock(portAudioStream->inputMutex); - } - - /* Improve the audio quality of the input if possible. */ - if ((paNoError == errorCode) - && portAudioStream->audioQualityImprovement) - { - AudioQualityImprovement_process( - portAudioStream->audioQualityImprovement, - AUDIO_QUALITY_IMPROVEMENT_SAMPLE_ORIGIN_INPUT, - portAudioStream->sampleRate, - portAudioStream->sampleSizeInBits, - portAudioStream->channels, - portAudioStream->inputLatency, - data, framesInBytes); - } - } - else - { - errorCode = Pa_ReadStream(portAudioStream->stream, data, frames); - if ((paNoError == errorCode) || (paInputOverflowed == errorCode)) - { - errorCode = paNoError; - - if (portAudioStream->audioQualityImprovement) - { - AudioQualityImprovement_process( - portAudioStream->audioQualityImprovement, - AUDIO_QUALITY_IMPROVEMENT_SAMPLE_ORIGIN_INPUT, - portAudioStream->sampleRate, - portAudioStream->sampleSizeInBits, - portAudioStream->channels, - portAudioStream->inputLatency, - data, framesInBytes); - } - } - } - - if (paNoError == errorCode) - (*env)->ReleaseByteArrayElements(env, buffer, data, 0); - else - { - (*env)->ReleaseByteArrayElements(env, buffer, data, JNI_ABORT); - PortAudio_throwException(env, errorCode); - } - } -} - -JNIEXPORT void JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1StartStream - (JNIEnv *env, jclass clazz, jlong stream) -{ - PortAudioStream *portAudioStream = (PortAudioStream *) (intptr_t) stream; - PaError errorCode; - - if (portAudioStream->pseudoBlocking) - { - PortAudioStream_retain(portAudioStream); - if (Mutex_lock(portAudioStream->mutex)) - errorCode = paInternalError; - else - { - portAudioStream->finished = JNI_FALSE; - errorCode = Pa_StartStream(portAudioStream->stream); - if (paNoError != errorCode) - portAudioStream->finished = JNI_TRUE; - Mutex_unlock(portAudioStream->mutex); - } - if (paNoError != errorCode) - PortAudioStream_release(portAudioStream); - } - else - errorCode = Pa_StartStream(portAudioStream->stream); - if (paNoError != errorCode) - PortAudio_throwException(env, errorCode); -} - -JNIEXPORT void JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1StopStream - (JNIEnv *env, jclass clazz, jlong stream) -{ - PaError errorCode - = Pa_StopStream(((PortAudioStream *) (intptr_t) stream)->stream); - - if (paNoError != errorCode) - PortAudio_throwException(env, errorCode); -} - -JNIEXPORT void JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1WriteStream - (JNIEnv *env, jclass clazz, - jlong stream, - jbyteArray buffer, jint offset, jlong frames, - jint numberOfWrites) -{ - jbyte *bufferBytes; - jbyte* data; - PortAudioStream *portAudioStream; - jint i; - PaError errorCode = paNoError; - jlong framesInBytes; - AudioQualityImprovement *audioQualityImprovement; - double sampleRate; - unsigned long sampleSizeInBits; - int channels; - jlong outputLatency; - - bufferBytes = (*env)->GetByteArrayElements(env, buffer, NULL); - if (!bufferBytes) - return; - data = bufferBytes + offset; - - portAudioStream = (PortAudioStream *) (intptr_t) stream; - framesInBytes = frames * portAudioStream->outputFrameSize; - audioQualityImprovement = portAudioStream->audioQualityImprovement; - sampleRate = portAudioStream->sampleRate; - sampleSizeInBits = portAudioStream->sampleSizeInBits; - channels = portAudioStream->channels; - outputLatency = portAudioStream->outputLatency; - - if (portAudioStream->pseudoBlocking) - { - for (i = 0; i < numberOfWrites; i++) - { - if (Mutex_lock(portAudioStream->outputMutex)) - errorCode = paInternalError; - else - { - jlong bytesWritten = 0; - - errorCode = paNoError; - while (bytesWritten < framesInBytes) - { - size_t outputCapacity - = portAudioStream->outputCapacity - - portAudioStream->outputLength; - jlong bytesToWrite; - - if (JNI_TRUE == portAudioStream->finished) - { - errorCode = paStreamIsStopped; - break; - } - if (outputCapacity < 1) - { - ConditionVariable_wait( - portAudioStream->outputCondVar, - portAudioStream->outputMutex); - continue; - } - - bytesToWrite = framesInBytes - bytesWritten; - if (bytesToWrite > outputCapacity) - bytesToWrite = outputCapacity; - memcpy( - ((jbyte *) portAudioStream->output) - + portAudioStream->outputLength, - data + bytesWritten, - bytesToWrite); - - portAudioStream->outputLength += bytesToWrite; - bytesWritten += bytesToWrite; - } - Mutex_unlock(portAudioStream->outputMutex); - } - - if (paNoError == errorCode) - { - if (audioQualityImprovement) - { - AudioQualityImprovement_process( - audioQualityImprovement, - AUDIO_QUALITY_IMPROVEMENT_SAMPLE_ORIGIN_OUTPUT, - sampleRate, sampleSizeInBits, channels, - outputLatency, - data, framesInBytes); - } - - data += framesInBytes; - } - } - } - else - { - PaStream *paStream = portAudioStream->stream; - - for (i = 0; i < numberOfWrites; i++) - { - errorCode = Pa_WriteStream(paStream, data, frames); - if ((paNoError != errorCode) && (paOutputUnderflowed != errorCode)) - break; - else - { - if (audioQualityImprovement) - { - AudioQualityImprovement_process( - audioQualityImprovement, - AUDIO_QUALITY_IMPROVEMENT_SAMPLE_ORIGIN_OUTPUT, - sampleRate, sampleSizeInBits, channels, - outputLatency, - data, framesInBytes); - } - data += framesInBytes; - } - } - } - - (*env)->ReleaseByteArrayElements(env, buffer, bufferBytes, JNI_ABORT); - - if ((paNoError != errorCode) && (paOutputUnderflowed != errorCode)) - PortAudio_throwException(env, errorCode); -} - -JNIEXPORT jdouble JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getDefaultHighInputLatency - (JNIEnv *env, jclass clazz, jlong deviceInfo) -{ - return ((PaDeviceInfo *) (intptr_t) deviceInfo)->defaultHighInputLatency; -} - -JNIEXPORT jdouble JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getDefaultHighOutputLatency - (JNIEnv *env, jclass clazz, jlong deviceInfo) -{ - return ((PaDeviceInfo *) (intptr_t) deviceInfo)->defaultHighOutputLatency; -} - -JNIEXPORT jdouble JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getDefaultLowInputLatency - (JNIEnv *env, jclass clazz, jlong deviceInfo) -{ - return ((PaDeviceInfo *) (intptr_t) deviceInfo)->defaultLowInputLatency; -} - -JNIEXPORT jdouble JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getDefaultLowOutputLatency - (JNIEnv *env, jclass clazz, jlong deviceInfo) -{ - return ((PaDeviceInfo *) (intptr_t) deviceInfo)->defaultLowOutputLatency; -} - -JNIEXPORT jdouble JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getDefaultSampleRate - (JNIEnv *env, jclass clazz, jlong deviceInfo) -{ - return ((PaDeviceInfo *) (intptr_t) deviceInfo)->defaultSampleRate; -} - -JNIEXPORT jint JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getHostApi - (JNIEnv *env, jclass clazz, jlong deviceInfo) -{ - return ((PaDeviceInfo *) (intptr_t) deviceInfo)->hostApi; -} - -JNIEXPORT jint JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getMaxInputChannels - (JNIEnv *env, jclass clazz, jlong deviceInfo) -{ - return ((PaDeviceInfo *) (intptr_t) deviceInfo)->maxInputChannels; -} - -JNIEXPORT jint JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getMaxOutputChannels - (JNIEnv *env, jclass clazz, jlong deviceInfo) -{ - return ((PaDeviceInfo *) (intptr_t) deviceInfo)->maxOutputChannels; -} - -JNIEXPORT jbyteArray JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getNameBytes - (JNIEnv *env, jclass clazz, jlong deviceInfo) -{ - const char *name = ((PaDeviceInfo *) (intptr_t) deviceInfo)->name; - jbyteArray nameBytes; - - if (name) - { - size_t nameLength = strlen(name); - - nameBytes = (*env)->NewByteArray(env, nameLength); - if (nameBytes && nameLength) - { - (*env)->SetByteArrayRegion( - env, - nameBytes, 0, nameLength, - (jbyte *) name); - } - } - else - nameBytes = NULL; - return nameBytes; -} - -JNIEXPORT jbyteArray JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getTransportTypeBytes - (JNIEnv *env, jclass clazz, jlong deviceInfo) -{ - jbyteArray typeBytes = NULL; - if(((PaDeviceInfo *) (intptr_t) deviceInfo)->structVersion >= 3) - { - const char *type - = ((PaDeviceInfo *) (intptr_t) deviceInfo)->transportType; - - if(type != NULL) - { - size_t typeLength = strlen(type); - - typeBytes = (*env)->NewByteArray(env, typeLength); - if (typeBytes && typeLength) - { - (*env)->SetByteArrayRegion( - env, - typeBytes, 0, typeLength, - (jbyte *) type); - } - } - } - - return typeBytes; -} - -JNIEXPORT jbyteArray JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getDeviceUIDBytes - (JNIEnv *env, jclass clazz, jlong deviceInfo) -{ - jbyteArray uidBytes = NULL; - if(((PaDeviceInfo *) (intptr_t) deviceInfo)->structVersion >= 3) - { - const char *uid - = ((PaDeviceInfo *) (intptr_t) deviceInfo)->deviceUID; - - if (uid) - { - size_t uidLength = strlen(uid); - - uidBytes = (*env)->NewByteArray(env, uidLength); - if (uidBytes && uidLength) - { - (*env)->SetByteArrayRegion( - env, - uidBytes, 0, uidLength, - (jbyte *) uid); - } - } - } - - return uidBytes; -} - -JNIEXPORT jint JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaHostApiInfo_1getDefaultInputDevice - (JNIEnv *env, jclass clazz, jlong hostApi) -{ - return ((PaHostApiInfo *) (intptr_t) hostApi)->defaultInputDevice; -} - -JNIEXPORT jint JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaHostApiInfo_1getDefaultOutputDevice - (JNIEnv *env, jclass clazz, jlong hostApi) -{ - return ((PaHostApiInfo *) (intptr_t) hostApi)->defaultOutputDevice; -} - -JNIEXPORT jint JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaHostApiInfo_1getDeviceCount - (JNIEnv *env, jclass clazz, jlong hostApi) -{ - return ((PaHostApiInfo *) (intptr_t) hostApi)->deviceCount; -} - -JNIEXPORT jstring JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaHostApiInfo_1getName - (JNIEnv *env, jclass clazz, jlong hostApi) -{ - const char *name = ((PaHostApiInfo *) (intptr_t) hostApi)->name; - - /* PaHostApiInfo_GetName has been deprected in the Java source code. */ - return name ? (*env)->NewStringUTF(env, name) : NULL; -} - -JNIEXPORT jint JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaHostApiInfo_1getType - (JNIEnv *env, jclass clazz, jlong hostApi) -{ - return ((PaHostApiInfo *) (intptr_t) hostApi)->type; -} - -JNIEXPORT jlong JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaStreamParameters_1new - (JNIEnv *env, jclass clazz, - jint deviceIndex, - jint channelCount, - jlong sampleFormat, - jdouble suggestedLatency) -{ - PaStreamParameters *streamParameters - = (PaStreamParameters *) malloc(sizeof(PaStreamParameters)); - - if (streamParameters) - { - streamParameters->device = deviceIndex; - streamParameters->channelCount = channelCount; - streamParameters->sampleFormat = sampleFormat; - streamParameters->suggestedLatency = suggestedLatency; - streamParameters->hostApiSpecificStreamInfo = NULL; - } - return (jlong) (intptr_t) streamParameters; -} - -JNIEXPORT void JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_setDenoise - (JNIEnv *env, jclass clazz, jlong stream, jboolean denoise) -{ - AudioQualityImprovement *audioQualityImprovement - = ((PortAudioStream *) (intptr_t) stream)->audioQualityImprovement; - - if (audioQualityImprovement) - AudioQualityImprovement_setDenoise(audioQualityImprovement, denoise); -} - -JNIEXPORT void JNICALL -Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_setEchoFilterLengthInMillis - (JNIEnv *env, jclass clazz, jlong stream, jlong echoFilterLengthInMillis) -{ - AudioQualityImprovement *audioQualityImprovement - = ((PortAudioStream *) (intptr_t) stream)->audioQualityImprovement; - - if (audioQualityImprovement) - { - AudioQualityImprovement_setEchoFilterLengthInMillis( - audioQualityImprovement, - echoFilterLengthInMillis); - } -} - -JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_updateAvailableDeviceList - (JNIEnv *env, jclass clazz) -{ - Pa_UpdateAvailableDeviceList(); -} - -JNIEXPORT jint JNICALL -JNI_OnLoad(JavaVM *vm, void *reserved) -{ - PortAudio_vm = vm; - - AudioQualityImprovement_load(); - - return JNI_VERSION_1_4; -} - -JNIEXPORT void JNICALL -JNI_OnUnload(JavaVM *vm, void *reserved) -{ - AudioQualityImprovement_unload(); - - PortAudio_vm = NULL; -} - -static void -PortAudio_devicesChangedCallback(void *userData) -{ - JavaVM *vm = PortAudio_vm; - JNIEnv *env; - - (void) userData; - - if (!vm - || ((*vm)->AttachCurrentThreadAsDaemon(vm, (void **) &env, NULL) - < 0)) - { - fprintf(stderr, "AttachCurrentThreadAsDaemon\n" ); - fflush(stderr); - } - else - { - jclass clazz = PortAudio_devicesChangedCallbackClass; - jmethodID methodID = PortAudio_devicesChangedCallbackMethodID; - - if (clazz && methodID) - (*env)->CallStaticVoidMethod(env, clazz, methodID); - } -} - -static PaStreamParameters * -PortAudio_fixInputParametersSuggestedLatency - (PaStreamParameters *inputParameters, - jdouble sampleRate, jlong framesPerBuffer, - PaHostApiTypeId hostApiType) -{ - if (inputParameters) - { - const PaDeviceInfo *deviceInfo - = Pa_GetDeviceInfo(inputParameters->device); - - if (deviceInfo) - { - PaTime suggestedLatency = inputParameters->suggestedLatency; - - if (suggestedLatency == LATENCY_LOW) - { - inputParameters->suggestedLatency - = deviceInfo->defaultLowInputLatency; - } - else if ((suggestedLatency == LATENCY_HIGH) - || (suggestedLatency == LATENCY_UNSPECIFIED)) - { - inputParameters->suggestedLatency - = deviceInfo->defaultHighInputLatency; - - /* - * When the input latency is too low, we do not have a great - * chance to perform echo cancellation using it. Since the - * caller does not care about the input latency, try to request - * an input latency which increases our chances. - */ - PortAudio_fixStreamParametersSuggestedLatency( - inputParameters, - sampleRate, framesPerBuffer, - hostApiType); - } - } - } - return inputParameters; -} - -static PaStreamParameters * -PortAudio_fixOutputParametersSuggestedLatency( - PaStreamParameters *outputParameters, - jdouble sampleRate, jlong framesPerBuffer, - PaHostApiTypeId hostApiType) -{ - if (outputParameters) - { - const PaDeviceInfo *deviceInfo - = Pa_GetDeviceInfo(outputParameters->device); - - if (deviceInfo) - { - PaTime suggestedLatency = outputParameters->suggestedLatency; - - if (suggestedLatency == LATENCY_LOW) - { - outputParameters->suggestedLatency - = deviceInfo->defaultLowOutputLatency; - } - else if ((suggestedLatency == LATENCY_HIGH) - || (suggestedLatency == LATENCY_UNSPECIFIED)) - { - outputParameters->suggestedLatency - = deviceInfo->defaultHighOutputLatency; - - /* - * When the output latency is too low, we do not have a great - * chance to perform echo cancellation using it. Since the - * caller does not care about the output latency, try to request - * an output latency which increases our chances. - */ - PortAudio_fixStreamParametersSuggestedLatency( - outputParameters, - sampleRate, framesPerBuffer, - hostApiType); - } - } - } - return outputParameters; -} - -static PaStreamParameters * -PortAudio_fixStreamParametersSuggestedLatency - (PaStreamParameters *streamParameters, - jdouble sampleRate, jlong framesPerBuffer, - PaHostApiTypeId hostApiType) -{ - if ((paCoreAudio == hostApiType) - && sampleRate - && (paFramesPerBufferUnspecified != framesPerBuffer)) - { - PaTime minLatency - = (MIN_PLAY_DELAY_IN_FRAMES - * streamParameters->channelCount - * framesPerBuffer) - / (2 * sampleRate); - - if (streamParameters->suggestedLatency < minLatency) - streamParameters->suggestedLatency = minLatency; - } - return streamParameters; -} - -static long -PortAudio_getFrameSize(PaStreamParameters *streamParameters) -{ - if (streamParameters) - { - PaError sampleSize = Pa_GetSampleSize(streamParameters->sampleFormat); - - if (paSampleFormatNotSupported != sampleSize) - return sampleSize * streamParameters->channelCount; - } - return 0; -} - -static unsigned long -PortAudio_getSampleSizeInBits(PaStreamParameters *streamParameters) -{ - if (streamParameters) - { - PaError sampleSize = Pa_GetSampleSize(streamParameters->sampleFormat); - - if (paSampleFormatNotSupported != sampleSize) - return sampleSize * 8; - } - return 0; -} - -static void -PortAudio_throwException(JNIEnv *env, PaError errorCode) -{ - jclass clazz - = (*env)->FindClass( - env, - "net/java/sip/communicator/impl/neomedia/portaudio/PortAudioException"); - - if(errorCode == paUnanticipatedHostError) - { - // throw new exception with host error info - const PaHostErrorInfo* herr = Pa_GetLastHostErrorInfo(); - if (herr) - { - jmethodID methodID - = (*env)->GetMethodID( - env, - clazz, - "", - "(Ljava/lang/String;IJLjava/lang/String;)V"); - - if (methodID) - { - jstring jmessage; - if (herr->errorText) - jmessage = (*env)->NewStringUTF(env, herr->errorText); - else - jmessage = (*env)->NewStringUTF(env, ""); - - if (jmessage) - { - jobject t - = (*env)->NewObject( - env, - clazz, - methodID, - Pa_GetErrorText(errorCode), - herr->hostApiType, - herr->errorCode, - jmessage); - - if (t) - { - (*env)->Throw(env, (jthrowable) t); - return; - } - } - } - } - } - - if (clazz) - (*env)->ThrowNew(env, clazz, Pa_GetErrorText(errorCode)); -} - -/** - * Allocates (and initializes) the memory and its associated variables for a - * specific buffer to be used by the pseudo-blocking stream interface - * implementation of a PortAudioStream. - * - * @param capacity the number of bytes to be allocated to the buffer - * @param bufferPtr a pointer which specifies where the location of the - * allocated buffer is to be stored - * @param bufferLengthPtr a pointer which specifies where the initial length - * (i.e. zero) is to be stored - * @param bufferCapacityPtr a pointer which specifies where the capacity of the - * allocated buffer is to be stored - * @param bufferMutexPtr a pointer which specifies where the Mute to - * synchronize the access to the allocated buffer is to be stored - * @param bufferCondVarPtr a pointer which specifies where the - * ConditionVariable to synchronize the access to the allocated buffer - * is to be stored - * @return the location of the allocated buffer upon success; otherwise, - * NULL - */ -static void * -PortAudioStream_allocPseudoBlockingBuffer - (size_t capacity, - void **bufferPtr, size_t *bufferLengthPtr, size_t *bufferCapacityPtr, - Mutex **bufferMutexPtr, ConditionVariable **bufferCondVarPtr) -{ - void *buffer = malloc(capacity); - - if (buffer) - { - Mutex *mutex = Mutex_new(NULL); - - if (mutex) - { - ConditionVariable *condVar = ConditionVariable_new(NULL); - - if (condVar) - { - if (bufferPtr) - *bufferPtr = buffer; - if (bufferLengthPtr) - *bufferLengthPtr = 0; - if (bufferCapacityPtr) - *bufferCapacityPtr = capacity; - *bufferMutexPtr = mutex; - *bufferCondVarPtr = condVar; - } - else - { - Mutex_free(mutex); - free(buffer); - buffer = NULL; - } - } - else - { - free(buffer); - buffer = NULL; - } - } - return buffer; -} - -static void -PortAudioStream_free(JNIEnv *env, PortAudioStream *stream) -{ - if (stream->streamCallback) - (*env)->DeleteGlobalRef(env, stream->streamCallback); - - if (stream->inputMutex && !Mutex_lock(stream->inputMutex)) - { - if (stream->input) - free(stream->input); - ConditionVariable_free(stream->inputCondVar); - Mutex_unlock(stream->inputMutex); - Mutex_free(stream->inputMutex); - } - - if (stream->outputMutex && !Mutex_lock(stream->outputMutex)) - { - if (stream->output) - free(stream->output); - ConditionVariable_free(stream->outputCondVar); - Mutex_unlock(stream->outputMutex); - Mutex_free(stream->outputMutex); - } - - if (stream->audioQualityImprovement) - AudioQualityImprovement_release(stream->audioQualityImprovement); - - if (stream->mutex) - Mutex_free(stream->mutex); - - free(stream); -} - -static int -PortAudioStream_javaCallback - (const void *input, - void *output, - unsigned long frameCount, - const PaStreamCallbackTimeInfo *timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData) -{ - PortAudioStream *stream = (PortAudioStream *) userData; - jobject streamCallback = stream->streamCallback; - JNIEnv *env; - jmethodID streamCallbackMethodID; - - if (!streamCallback) - return paContinue; - - env = stream->env; - if (!env) - { - JavaVM *vm = stream->vm; - - if ((*vm)->AttachCurrentThreadAsDaemon(vm, (void **) &env, NULL) < 0) - return paAbort; - else - stream->env = env; - } - streamCallbackMethodID = stream->streamCallbackMethodID; - if (!streamCallbackMethodID) - { - jclass streamCallbackClass - = (*env)->GetObjectClass(env, streamCallback); - - streamCallbackMethodID - = (*env)->GetMethodID( - env, - streamCallbackClass, - "callback", - "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)I"); - if (streamCallbackMethodID) - stream->streamCallbackMethodID = streamCallbackMethodID; - else - return paAbort; - } - - return - (*env)->CallIntMethod( - env, - streamCallback, - streamCallbackMethodID, - input - ? (*env)->NewDirectByteBuffer( - env, - (void *) input, - frameCount * stream->inputFrameSize) - : NULL, - output - ? (*env)->NewDirectByteBuffer( - env, - output, - frameCount * stream->outputFrameSize) - : NULL); -} - -static void -PortAudioStream_javaFinishedCallback(void *userData) -{ - PortAudioStream *stream = (PortAudioStream *) userData; - jobject streamCallback = stream->streamCallback; - JNIEnv *env; - jmethodID streamFinishedCallbackMethodID; - - if (!streamCallback) - return; - - env = stream->env; - if (!env) - { - JavaVM *vm = stream->vm; - - if ((*vm)->AttachCurrentThreadAsDaemon(vm, (void **) &env, NULL) < 0) - return; - else - stream->env = env; - } - streamFinishedCallbackMethodID = stream->streamFinishedCallbackMethodID; - if (!streamFinishedCallbackMethodID) - { - jclass streamCallbackClass - = (*env)->GetObjectClass(env, streamCallback); - - streamFinishedCallbackMethodID - = (*env)->GetMethodID( - env, - streamCallbackClass, - "finishedCallback", - "()V"); - if (streamFinishedCallbackMethodID) - stream->streamFinishedCallbackMethodID - = streamFinishedCallbackMethodID; - else - return; - } - - (*env)->CallVoidMethod(env, streamCallback, streamFinishedCallbackMethodID); -} - -static PortAudioStream * -PortAudioStream_new(JNIEnv *env, jobject streamCallback) -{ - PortAudioStream *stream = calloc(1, sizeof(PortAudioStream)); - - if (!stream) - { - PortAudio_throwException(env, paInsufficientMemory); - return NULL; - } - - if (streamCallback) - { - if ((*env)->GetJavaVM(env, &(stream->vm)) < 0) - { - free(stream); - PortAudio_throwException(env, paInternalError); - return NULL; - } - - stream->streamCallback = (*env)->NewGlobalRef(env, streamCallback); - if (!(stream->streamCallback)) - { - free(stream); - PortAudio_throwException(env, paInsufficientMemory); - return NULL; - } - } - - return stream; -} - -static void -PortAudioStream_popFromPseudoBlockingBuffer - (void *buffer, size_t length, size_t *bufferLengthPtr) -{ - size_t i; - size_t newLength = *bufferLengthPtr - length; - jbyte *oldBuffer = (jbyte *) buffer; - jbyte *newBuffer = ((jbyte *) buffer) + length; - - for (i = 0; i < newLength; i++) - *oldBuffer++ = *newBuffer++; - *bufferLengthPtr = newLength; -} - -static int -PortAudioStream_pseudoBlockingCallback - (const void *input, - void *output, - unsigned long frameCount, - const PaStreamCallbackTimeInfo *timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData) -{ - PortAudioStream *stream = (PortAudioStream *) userData; - - if (input && stream->inputMutex && !Mutex_lock(stream->inputMutex)) - { - size_t inputLength = frameCount * stream->inputFrameSize; - size_t newInputLength; - void *inputInStream; - - /* - * Remember the specified input so that it can be retrieved later on in - * our pseudo-blocking Pa_ReadStream(). - */ - newInputLength = stream->inputLength + inputLength; - if (newInputLength > stream->inputCapacity) - { - PortAudioStream_popFromPseudoBlockingBuffer( - stream->input, - newInputLength - stream->inputCapacity, - &(stream->inputLength)); - } - inputInStream = ((jbyte *) (stream->input)) + stream->inputLength; - memcpy(inputInStream, input, inputLength); - stream->inputLength += inputLength; - - ConditionVariable_notify(stream->inputCondVar); - Mutex_unlock(stream->inputMutex); - } - if (output && stream->outputMutex && !Mutex_lock(stream->outputMutex)) - { - size_t outputLength = frameCount * stream->outputFrameSize; - size_t availableOutputLength = outputLength; - - if (availableOutputLength > stream->outputLength) - availableOutputLength = stream->outputLength; - memcpy(output, stream->output, availableOutputLength); - PortAudioStream_popFromPseudoBlockingBuffer( - stream->output, - availableOutputLength, - &(stream->outputLength)); - if (availableOutputLength < outputLength) - { - memset( - ((jbyte *) output) + availableOutputLength, - 0, - outputLength - availableOutputLength); - } - - ConditionVariable_notify(stream->outputCondVar); - Mutex_unlock(stream->outputMutex); - } - return paContinue; -} - -static void -PortAudioStream_pseudoBlockingFinishedCallback(void *userData) -{ - PortAudioStream *stream = (PortAudioStream *) userData; - - if (!Mutex_lock(stream->mutex)) - { - stream->finished = JNI_TRUE; - if (stream->inputMutex && !Mutex_lock(stream->inputMutex)) - { - ConditionVariable_notify(stream->inputCondVar); - Mutex_unlock(stream->inputMutex); - } - if (stream->outputMutex && !Mutex_lock(stream->outputMutex)) - { - ConditionVariable_notify(stream->outputCondVar); - Mutex_unlock(stream->outputMutex); - } - Mutex_unlock(stream->mutex); - } - PortAudioStream_release(stream); -} - -static void -PortAudioStream_release(PortAudioStream *stream) -{ - if (!Mutex_lock(stream->mutex)) - { - --(stream->retainCount); - if (stream->retainCount < 1) - { - Mutex_unlock(stream->mutex); - PortAudioStream_free(NULL, stream); - } - else - Mutex_unlock(stream->mutex); - } -} - -static void -PortAudioStream_retain(PortAudioStream *stream) -{ - if (!Mutex_lock(stream->mutex)) - { - ++(stream->retainCount); - Mutex_unlock(stream->mutex); - } -} diff --git a/src/native/portaudio/net_java_sip_communicator_impl_neomedia_portaudio_PortAudio.h b/src/native/portaudio/net_java_sip_communicator_impl_neomedia_portaudio_PortAudio.h deleted file mode 100644 index e4c941d15..000000000 --- a/src/native/portaudio/net_java_sip_communicator_impl_neomedia_portaudio_PortAudio.h +++ /dev/null @@ -1,323 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class net_java_sip_communicator_impl_neomedia_portaudio_PortAudio */ - -#ifndef _Included_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio -#define _Included_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio -#ifdef __cplusplus -extern "C" { -#endif -#undef net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_LATENCY_HIGH -#define net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_LATENCY_HIGH -1.0 -#undef net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_LATENCY_LOW -#define net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_LATENCY_LOW -2.0 -#undef net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_LATENCY_UNSPECIFIED -#define net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_LATENCY_UNSPECIFIED 0.0 -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: free - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_free - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_AbortStream - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1AbortStream - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_CloseStream - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1CloseStream - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_GetDefaultInputDevice - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetDefaultInputDevice - (JNIEnv *, jclass); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_GetDefaultOutputDevice - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetDefaultOutputDevice - (JNIEnv *, jclass); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_GetDeviceCount - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetDeviceCount - (JNIEnv *, jclass); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_GetDeviceInfo - * Signature: (I)J - */ -JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetDeviceInfo - (JNIEnv *, jclass, jint); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_GetHostApiInfo - * Signature: (I)J - */ -JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetHostApiInfo - (JNIEnv *, jclass, jint); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_GetSampleSize - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetSampleSize - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_GetStreamReadAvailable - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetStreamReadAvailable - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_GetStreamWriteAvailable - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1GetStreamWriteAvailable - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_Initialize - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1Initialize - (JNIEnv *, jclass); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_IsFormatSupported - * Signature: (JJD)Z - */ -JNIEXPORT jboolean JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1IsFormatSupported - (JNIEnv *, jclass, jlong, jlong, jdouble); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_OpenStream - * Signature: (JJDJJLnet/java/sip/communicator/impl/neomedia/portaudio/PortAudioStreamCallback;)J - */ -JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1OpenStream - (JNIEnv *, jclass, jlong, jlong, jdouble, jlong, jlong, jobject); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_ReadStream - * Signature: (J[BJ)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1ReadStream - (JNIEnv *, jclass, jlong, jbyteArray, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_StartStream - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1StartStream - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_StopStream - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1StopStream - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: Pa_WriteStream - * Signature: (J[BIJI)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_Pa_1WriteStream - (JNIEnv *, jclass, jlong, jbyteArray, jint, jlong, jint); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaDeviceInfo_getDefaultHighInputLatency - * Signature: (J)D - */ -JNIEXPORT jdouble JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getDefaultHighInputLatency - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaDeviceInfo_getDefaultHighOutputLatency - * Signature: (J)D - */ -JNIEXPORT jdouble JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getDefaultHighOutputLatency - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaDeviceInfo_getDefaultLowInputLatency - * Signature: (J)D - */ -JNIEXPORT jdouble JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getDefaultLowInputLatency - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaDeviceInfo_getDefaultLowOutputLatency - * Signature: (J)D - */ -JNIEXPORT jdouble JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getDefaultLowOutputLatency - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaDeviceInfo_getDefaultSampleRate - * Signature: (J)D - */ -JNIEXPORT jdouble JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getDefaultSampleRate - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaDeviceInfo_getHostApi - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getHostApi - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaDeviceInfo_getMaxInputChannels - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getMaxInputChannels - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaDeviceInfo_getMaxOutputChannels - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getMaxOutputChannels - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaDeviceInfo_getNameBytes - * Signature: (J)[B - */ -JNIEXPORT jbyteArray JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getNameBytes - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaDeviceInfo_getTransportTypeBytes - * Signature: (J)[B - */ -JNIEXPORT jbyteArray JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getTransportTypeBytes - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaDeviceInfo_getDeviceUIDBytes - * Signature: (J)[B - */ -JNIEXPORT jbyteArray JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaDeviceInfo_1getDeviceUIDBytes - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaHostApiInfo_getDefaultInputDevice - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaHostApiInfo_1getDefaultInputDevice - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaHostApiInfo_getDefaultOutputDevice - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaHostApiInfo_1getDefaultOutputDevice - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaHostApiInfo_getDeviceCount - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaHostApiInfo_1getDeviceCount - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaHostApiInfo_getName - * Signature: (J)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaHostApiInfo_1getName - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaHostApiInfo_getType - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaHostApiInfo_1getType - (JNIEnv *, jclass, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: PaStreamParameters_new - * Signature: (IIJD)J - */ -JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_PaStreamParameters_1new - (JNIEnv *, jclass, jint, jint, jlong, jdouble); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: setDenoise - * Signature: (JZ)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_setDenoise - (JNIEnv *, jclass, jlong, jboolean); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: setEchoFilterLengthInMillis - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_setEchoFilterLengthInMillis - (JNIEnv *, jclass, jlong, jlong); - -/* - * Class: net_java_sip_communicator_impl_neomedia_portaudio_PortAudio - * Method: updateAvailableDeviceList - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_portaudio_PortAudio_updateAvailableDeviceList - (JNIEnv *, jclass); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/native/portaudio/pa_linux_alsa.c-by-Werner.patch b/src/native/portaudio/pa_linux_alsa.c-by-Werner.patch deleted file mode 100644 index 5c3c60e56..000000000 --- a/src/native/portaudio/pa_linux_alsa.c-by-Werner.patch +++ /dev/null @@ -1,71 +0,0 @@ ---- pa_linux_alsa.c 2009-06-03 21:57:56.000000000 +0300 -+++ pa_linux_alsa.c 2010-04-22 14:26:41.081552093 +0300 -@@ -2735,8 +2735,19 @@ - snd_pcm_sframes_t framesAvail = snd_pcm_avail_update( self->pcm ); - *xrunOccurred = 0; - -- if( -EPIPE == framesAvail ) -- { -+ /* Get pcm_state and check for xrun condition. On playback I often see -+ * xrun but avail_update does not return -EPIPE but framesAvail larger -+ * than bufferSize. In case of xrun status set xrun flag, leave framesize -+ * as reported by avail_update, will be fixed below. In case avail_update -+ * returns -EPIPE process as usual. wd-xxx -+ */ -+ snd_pcm_state_t state = snd_pcm_state( self->pcm ); /* wd-xxx */ -+ if (state == SND_PCM_STATE_XRUN) { -+ // printf("xrun, fav %d\n", framesAvail); fflush(stdout); // DEBUG-WD -+ *xrunOccurred = 1; -+ } -+ if( -EPIPE == framesAvail) { -+ // printf("xrun-1, fav %d\n", framesAvail); fflush(stdout); // DEBUG-WD - *xrunOccurred = 1; - framesAvail = 0; - } -@@ -2745,6 +2756,11 @@ - ENSURE_( framesAvail, paUnanticipatedHostError ); - } - -+ /* Fix frames avail, should not be bigger than bufferSize wd-xxx */ -+ if (framesAvail > self->bufferSize) { -+ // printf("xrun-2, fav %d\n", framesAvail); fflush(stdout); // DEBUG-WD -+ framesAvail = self->bufferSize; -+ } - *numFrames = framesAvail; - - error: -@@ -3457,9 +3472,24 @@ - while( frames > 0 ) - { - int xrun = 0; -- PA_ENSURE( PaAlsaStream_WaitForFrames( stream, &framesAvail, &xrun ) ); -- framesGot = PA_MIN( framesAvail, frames ); -+ PA_ENSURE( PaAlsaStream_WaitForFrames( stream, &framesAvail, &xrun ) ); -+ /* -+ * In case of overrun WaitForFrames leaves the capture stream in STATE_PREPARED -+ * most of the time. handleXrun() restarts the ALSA stream only in case -+ * snd_pcm_recover() fails, which usually does not happen. -+ * Here we start the pcm stream again and go for another try. Another -+ * option is: set result to paOverrun and return to caller. Then -+ * the caller needs to call ReadStream again. This takes more time and -+ * we lose even more frames. -+ */ -+ if (xrun) { /* wd-xxx */ -+ if( snd_pcm_state( stream->capture.pcm ) == SND_PCM_STATE_PREPARED ) { -+ ENSURE_( snd_pcm_start( stream->capture.pcm ), paUnanticipatedHostError ); -+ } -+ continue; -+ } - -+ framesGot = PA_MIN( framesAvail, frames ); - PA_ENSURE( PaAlsaStream_SetUpBuffers( stream, &framesGot, &xrun ) ); - if( framesGot > 0 ) - { -@@ -3580,6 +3610,7 @@ - - PA_ENSURE( PaAlsaStream_HandleXrun( stream ) ); - savail = snd_pcm_avail_update( stream->playback.pcm ); -+ // printf("GSWA xrun, sav: %ld (%lx)\n", savail, savail); fflush(stdout); // DEBUG-WD - - /* savail should not contain -EPIPE now, since PaAlsaStream_HandleXrun will only prepare the pcm */ - ENSURE_( savail, paUnanticipatedHostError ); diff --git a/src/native/portaudio/pa_linux_alsa.c-fix-blocked-renderer.patch b/src/native/portaudio/pa_linux_alsa.c-fix-blocked-renderer.patch deleted file mode 100644 index 1f131bd50..000000000 --- a/src/native/portaudio/pa_linux_alsa.c-fix-blocked-renderer.patch +++ /dev/null @@ -1,39 +0,0 @@ -Index: pa_linux_alsa.c -=================================================================== ---- pa_linux_alsa.c (revision 1418) -+++ pa_linux_alsa.c (working copy) -@@ -315,7 +315,10 @@ - } - - PaUtil_FreeMemory( alsaHostApi ); -- snd_config_update_free_global(); -+// damencho, removed fo compability with pulseaudio versions before 0.9.16 -+// segfault application: -+// bugtrack alsa: 0002124: snd_config_update_free_global kills applications using user space alsa plugins -+// snd_config_update_free_global(); - } - - /** Determine max channels and default latencies. -@@ -1364,7 +1367,7 @@ - - ENSURE_( snd_pcm_sw_params_set_avail_min( self->pcm, swParams, self->framesPerBuffer ), paUnanticipatedHostError ); - ENSURE_( snd_pcm_sw_params_set_xfer_align( self->pcm, swParams, 1 ), paUnanticipatedHostError ); -- ENSURE_( snd_pcm_sw_params_set_tstamp_mode( self->pcm, swParams, SND_PCM_TSTAMP_ENABLE ), paUnanticipatedHostError ); -+ ENSURE_( snd_pcm_sw_params_set_tstamp_mode( self->pcm, swParams, SND_PCM_TSTAMP_MMAP ), paUnanticipatedHostError ); - - /* Set the parameters! */ - ENSURE_( snd_pcm_sw_params( self->pcm, swParams ), paUnanticipatedHostError ); -@@ -2788,6 +2807,13 @@ - - *shouldPoll = 0; - } -+ else -+ { -+ // not actually used -+ unsigned long framesAvail = 0; -+ // now check for xrun -+ PaAlsaStreamComponent_GetAvailableFrames(self, &framesAvail, xrun ); -+ } - - error: - return result; diff --git a/src/native/portaudio/portaudio-hotplug-os.patch b/src/native/portaudio/portaudio-hotplug-os.patch deleted file mode 100644 index 0938066ff..000000000 --- a/src/native/portaudio/portaudio-hotplug-os.patch +++ /dev/null @@ -1,1212 +0,0 @@ -Index: test/patest_update_available_device_list.c -=================================================================== ---- test/patest_update_available_device_list.c (revision 1799) -+++ test/patest_update_available_device_list.c (working copy) -@@ -1,5 +1,6 @@ - #include - #include -+#include - - #include "portaudio.h" - -@@ -33,9 +34,10 @@ - - for(;;){ - printDevices(); -- -+ - printf( "press [enter] to update the device list. or q + [enter] to quit.\n" ); -- if( getchar() == 'q' ) -+ char ch = getchar(); -+ if( ch == 'q' ) - break; - - Pa_UpdateAvailableDeviceList(); -Index: configure -=================================================================== ---- configure (revision 1799) -+++ configure (working copy) -@@ -11341,7 +11341,7 @@ - fi - SHARED_FLAGS="$LIBS -dynamiclib $mac_arches $mac_sysroot $mac_version_min" - CFLAGS="-std=c99 $CFLAGS $mac_arches $mac_sysroot $mac_version_min" -- OTHER_OBJS="src/os/unix/pa_unix_hostapis.o src/os/unix/pa_unix_util.o src/hostapi/coreaudio/pa_mac_core.o src/hostapi/coreaudio/pa_mac_core_utilities.o src/hostapi/coreaudio/pa_mac_core_blocking.o src/common/pa_ringbuffer.o" -+ OTHER_OBJS="src/os/unix/pa_unix_hostapis.o src/os/unix/pa_unix_util.o src/hostapi/coreaudio/pa_mac_core.o src/hostapi/coreaudio/pa_mac_core_utilities.o src/hostapi/coreaudio/pa_mac_core_blocking.o src/common/pa_ringbuffer.o src/os/mac_osx/pa_osx_hotplug.o" - PADLL="libportaudio.dylib" - ;; - -@@ -11373,7 +11373,7 @@ - - if [ "x$with_wdmks" = "xyes" ]; then - DXDIR="$with_dxdir" -- add_objects src/hostapi/wdmks/pa_win_wdmks.o src/os/win/pa_win_hostapis.o src/os/win/pa_win_util.o -+ add_objects src/hostapi/wdmks/pa_win_wdmks.o src/os/win/pa_win_hostapis.o src/os/win/pa_win_util.o src/os/win/pa_win_wdmks_utils.o - LIBS="-lwinmm -lm -luuid -lsetupapi -lole32" - DLL_LIBS="${DLL_LIBS} -lwinmm -lm -L$DXDIR/lib -luuid -lsetupapi -lole32" - #VC98="\"/c/Program Files/Microsoft Visual Studio/VC98/Include\"" -@@ -11610,7 +11610,7 @@ - if [ "$have_alsa" = "yes" ] && [ "$with_alsa" != "no" ] ; then - DLL_LIBS="$DLL_LIBS -lasound" - LIBS="$LIBS -lasound" -- OTHER_OBJS="$OTHER_OBJS src/hostapi/alsa/pa_linux_alsa.o" -+ OTHER_OBJS="$OTHER_OBJS src/hostapi/alsa/pa_linux_alsa.o src/os/unix/pa_linux_hotplug.o" - INCLUDES="$INCLUDES pa_linux_alsa.h" - $as_echo "#define PA_USE_ALSA 1" >>confdefs.h - -Index: Makefile.in -=================================================================== ---- Makefile.in (revision 1799) -+++ Makefile.in (working copy) -@@ -107,6 +107,7 @@ - bin/patest_wire \ - bin/patest_write_sine \ - bin/patest_write_sine_nonint \ -+ bin/patest_update_available_device_list \ - bin/pa_devs \ - bin/pa_fuzz \ - bin/pa_minlat -@@ -146,6 +147,7 @@ - src/hostapi/wdmks \ - src/hostapi/wmme \ - src/os/unix \ -+ src/os/mac_osx \ - src/os/win - - SUBDIRS = -Index: configure.in -=================================================================== ---- configure.in (revision 1799) -+++ configure.in (working copy) -@@ -216,7 +216,7 @@ - fi - SHARED_FLAGS="$LIBS -dynamiclib $mac_arches $mac_sysroot $mac_version_min" - CFLAGS="-std=c99 $CFLAGS $mac_arches $mac_sysroot $mac_version_min" -- OTHER_OBJS="src/os/unix/pa_unix_hostapis.o src/os/unix/pa_unix_util.o src/hostapi/coreaudio/pa_mac_core.o src/hostapi/coreaudio/pa_mac_core_utilities.o src/hostapi/coreaudio/pa_mac_core_blocking.o src/common/pa_ringbuffer.o" -+ OTHER_OBJS="src/os/unix/pa_unix_hostapis.o src/os/unix/pa_unix_util.o src/hostapi/coreaudio/pa_mac_core.o src/hostapi/coreaudio/pa_mac_core_utilities.o src/hostapi/coreaudio/pa_mac_core_blocking.o src/common/pa_ringbuffer.o src/os/mac_osx/pa_osx_hotplug.o" - PADLL="libportaudio.dylib" - ;; - -@@ -230,7 +230,7 @@ - - if [[ "x$with_directx" = "xyes" ]]; then - DXDIR="$with_dxdir" -- add_objects src/hostapi/dsound/pa_win_ds.o src/hostapi/dsound/pa_win_ds_dynlink.o src/os/win/pa_win_hostapis.o src/os/win/pa_win_util.o src/os/win/pa_win_waveformat.o -+ add_objects src/hostapi/dsound/pa_win_ds.o src/hostapi/dsound/pa_win_ds_dynlink.o src/os/win/pa_win_hostapis.o src/os/win/pa_win_util.o src/os/win/pa_win_waveformat.o src/os/win/pa_win_hotplug.o - LIBS="-lwinmm -lm -ldsound -lole32" - DLL_LIBS="${DLL_LIBS} -lwinmm -lm -L$DXDIR/lib -ldsound -lole32" - #VC98="\"/c/Program Files/Microsoft Visual Studio/VC98/Include\"" -@@ -249,7 +249,7 @@ - - if [[ "x$with_wdmks" = "xyes" ]]; then - DXDIR="$with_dxdir" -- add_objects src/hostapi/wdmks/pa_win_wdmks.o src/os/win/pa_win_hostapis.o src/os/win/pa_win_util.o -+ add_objects src/hostapi/wdmks/pa_win_wdmks.o src/os/win/pa_win_hostapis.o src/os/win/pa_win_util.o src/os/win/pa_win_wdmks_utils.o - LIBS="-lwinmm -lm -luuid -lsetupapi -lole32" - DLL_LIBS="${DLL_LIBS} -lwinmm -lm -L$DXDIR/lib -luuid -lsetupapi -lole32" - #VC98="\"/c/Program Files/Microsoft Visual Studio/VC98/Include\"" -@@ -319,7 +319,7 @@ - if [[ "$have_alsa" = "yes" ] && [ "$with_alsa" != "no" ]] ; then - DLL_LIBS="$DLL_LIBS -lasound" - LIBS="$LIBS -lasound" -- OTHER_OBJS="$OTHER_OBJS src/hostapi/alsa/pa_linux_alsa.o" -+ OTHER_OBJS="$OTHER_OBJS src/hostapi/alsa/pa_linux_alsa.o src/os/unix/pa_linux_hotplug.o" - INCLUDES="$INCLUDES pa_linux_alsa.h" - AC_DEFINE(PA_USE_ALSA) - fi -Index: src/os/unix/pa_linux_hotplug.c -=================================================================== ---- src/os/unix/pa_linux_hotplug.c (revision 0) -+++ src/os/unix/pa_linux_hotplug.c (revision 0) -@@ -0,0 +1,147 @@ -+ -+#include "pa_util.h" -+#include "pa_debugprint.h" -+#include "pa_allocation.h" -+#include "pa_linux_alsa.h" -+#include "pa_hostapi.h" -+ -+#include -+ -+#include -+#include -+#include -+ -+/* Implemented in pa_front.c -+ @param first 0 = unknown, 1 = insertion, 2 = removal -+ @param second Host specific device change info (in windows it is the (unicode) device path) -+*/ -+extern void PaUtil_DevicesChanged(unsigned, void*); -+ -+static pthread_t g_thread_id; -+static pthread_mutex_t g_mutex; -+static volatile sig_atomic_t g_run = 0; -+ -+static int device_list_size(void) -+{ -+ snd_ctl_t *handle; -+ int card, err, dev, idx; -+ int nb = 0; -+ snd_ctl_card_info_t *info; -+ snd_pcm_info_t *pcminfo; -+ snd_ctl_card_info_alloca(&info); -+ snd_pcm_info_alloca(&pcminfo); -+ -+ card = -1; -+ if (snd_card_next(&card) < 0 || card < 0) -+ { -+ return nb; -+ } -+ -+ while (card >= 0) -+ { -+ char name[32]; -+ -+ sprintf(name, "hw:%d", card); -+ if ((err = snd_ctl_open(&handle, name, 0)) < 0) -+ { -+ goto next_card; -+ } -+ if ((err = snd_ctl_card_info(handle, info)) < 0) -+ { -+ snd_ctl_close(handle); -+ goto next_card; -+ } -+ dev = -1; -+ while (1) -+ { -+ unsigned int count; -+ int hasPlayback = 0; -+ int hasCapture = 0; -+ -+ snd_ctl_pcm_next_device(handle, &dev); -+ -+ if (dev < 0) -+ break; -+ snd_pcm_info_set_device(pcminfo, dev); -+ snd_pcm_info_set_subdevice(pcminfo, 0); -+ snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_CAPTURE); -+ if ((err = snd_ctl_pcm_info(handle, pcminfo)) >= 0) -+ { -+ hasCapture = 1; -+ } -+ -+ snd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK); -+ if ((err = snd_ctl_pcm_info(handle, pcminfo)) >= 0) -+ { -+ hasPlayback = 1; -+ -+ count = snd_pcm_info_get_subdevices_count(pcminfo); -+ } -+ -+ if(hasPlayback == 0 && hasCapture == 0) -+ continue; -+ -+ nb++; -+ } -+ snd_ctl_close(handle); -+next_card: -+ if (snd_card_next(&card) < 0) -+ { -+ break; -+ } -+ } -+ return nb; -+} -+ -+static void* thread_fcn(void* data) -+{ -+ int currentDevices = 0; -+ -+ currentDevices = device_list_size(); -+ -+ while(g_run) -+ { -+ int count = 0; -+ -+ sleep(1); -+ count = device_list_size(); -+ if(count != currentDevices) -+ { -+ /* 1 = add device, 2 = remove device */ -+ int add = (count > currentDevices) ? 1 : 2; -+ -+ currentDevices = count; -+ -+ PaUtil_DevicesChanged(add, NULL); -+ } -+ } -+ -+ return NULL; -+} -+ -+void PaUtil_InitializeHotPlug() -+{ -+ pthread_mutex_init(&g_mutex, NULL); -+ g_run = 1; -+ pthread_create(&g_thread_id, NULL, thread_fcn, NULL); -+} -+ -+void PaUtil_TerminateHotPlug() -+{ -+ void* ret = NULL; -+ -+ g_run = 0; -+ pthread_join(g_thread_id, &ret); -+ pthread_mutex_destroy(&g_mutex); -+} -+ -+void PaUtil_LockHotPlug() -+{ -+ pthread_mutex_lock(&g_mutex); -+} -+ -+void PaUtil_UnlockHotPlug() -+{ -+ pthread_mutex_unlock(&g_mutex); -+} -+ -Index: src/os/mac_osx/pa_osx_hotplug.c -=================================================================== ---- src/os/mac_osx/pa_osx_hotplug.c (revision 0) -+++ src/os/mac_osx/pa_osx_hotplug.c (revision 0) -@@ -0,0 +1,76 @@ -+ -+#include "pa_util.h" -+#include "pa_debugprint.h" -+#include "pa_allocation.h" -+ -+#include -+ -+#include -+#include -+ -+/* Implemented in pa_front.c -+ @param first 0 = unknown, 1 = insertion, 2 = removal -+ @param second Host specific device change info (in windows it is the (unicode) device path) -+*/ -+extern void PaUtil_DevicesChanged(unsigned, void*); -+ -+/* Callback for audio hardware property changes. */ -+static OSStatus audioPropertyCallback(AudioHardwarePropertyID inPropertyID, -+ void *refCon) -+{ -+ (void)refCon; -+ switch (inPropertyID) -+ { -+ /* -+ * These are the other types of notifications we might receive, however, they are beyond -+ * the scope of this sample and we ignore them. -+ */ -+ case kAudioHardwarePropertyDefaultInputDevice: -+ PA_DEBUG(("audioPropertyCallback: default input device changed\n")); -+ break; -+ case kAudioHardwarePropertyDefaultOutputDevice: -+ PA_DEBUG(("audioPropertyCallback: default output device changed\n")); -+ break; -+ case kAudioHardwarePropertyDefaultSystemOutputDevice: -+ PA_DEBUG(("audioPropertyCallback: default system output device changed\n")); -+ break; -+ case kAudioHardwarePropertyDevices: -+ PA_DEBUG(("audioPropertyCallback: device list changed\n")); -+ PaUtil_DevicesChanged(1, NULL); -+ break; -+ default: -+ PA_DEBUG(("audioPropertyCallback: unknown message id=%08lx\n", inPropertyID)); -+ break; -+ } -+ -+ return noErr; -+} -+ -+void PaUtil_InitializeHotPlug() -+{ -+ AudioHardwareAddPropertyListener(kAudioHardwarePropertyDevices, -+ audioPropertyCallback, NULL); -+ AudioHardwareAddPropertyListener(kAudioHardwarePropertyDefaultInputDevice, -+ audioPropertyCallback, NULL); -+ AudioHardwareAddPropertyListener(kAudioHardwarePropertyDefaultOutputDevice, -+ audioPropertyCallback, NULL); -+} -+ -+void PaUtil_TerminateHotPlug() -+{ -+ AudioHardwareRemovePropertyListener(kAudioHardwarePropertyDevices, -+ audioPropertyCallback); -+ AudioHardwareRemovePropertyListener(kAudioHardwarePropertyDefaultInputDevice, -+ audioPropertyCallback); -+ AudioHardwareRemovePropertyListener(kAudioHardwarePropertyDefaultOutputDevice, -+ audioPropertyCallback); -+} -+ -+void PaUtil_LockHotPlug() -+{ -+} -+ -+void PaUtil_UnlockHotPlug() -+{ -+} -+ -Index: src/os/win/pa_win_hotplug.c -=================================================================== ---- src/os/win/pa_win_hotplug.c (revision 1799) -+++ src/os/win/pa_win_hotplug.c (working copy) -@@ -186,6 +186,8 @@ - { - PA_DEBUG(("Device inserted : %S\n", ptr->dbcc_name)); - InsertDeviceIntoCache(pInfo, ptr->dbcc_name); -+ /* yield some seconds because added device may not be completely configured */ -+ Sleep(2000); - PaUtil_DevicesChanged(1, ptr->dbcc_name); - } - } -@@ -202,6 +204,7 @@ - if (RemoveDeviceFromCache(pInfo, ptr->dbcc_name)) - { - PA_DEBUG(("Device removed : %S\n", ptr->dbcc_name)); -+ Sleep(2000); - PaUtil_DevicesChanged(2, ptr->dbcc_name); - } - } -Index: src/os/win/pa_win_hostapis.c -=================================================================== ---- src/os/win/pa_win_hostapis.c (revision 1799) -+++ src/os/win/pa_win_hostapis.c (working copy) -@@ -81,7 +81,7 @@ - #endif - - #if PA_USE_WDMKS -- PaWinWdm_Initialize, -+ //PaWinWdm_Initialize, - #endif - - #if PA_USE_SKELETON -Index: src/hostapi/alsa/pa_linux_alsa.c -=================================================================== ---- src/hostapi/alsa/pa_linux_alsa.c (revision 1799) -+++ src/hostapi/alsa/pa_linux_alsa.c (working copy) -@@ -668,6 +668,15 @@ - } - PaAlsaDeviceInfo; - -+/* used for tranferring device infos during scanning / rescanning */ -+typedef struct PaLinuxScanDeviceInfosResults -+{ -+ PaDeviceInfo **deviceInfos; -+ PaDeviceIndex defaultInputDevice; -+ PaDeviceIndex defaultOutputDevice; -+ int deviceCount; -+} PaLinuxScanDeviceInfosResults; -+ - /* prototypes for functions declared in this file */ - - static void Terminate( struct PaUtilHostApiRepresentation *hostApi ); -@@ -692,10 +701,17 @@ - static PaError IsStreamActive( PaStream *stream ); - static PaTime GetStreamTime( PaStream *stream ); - static double GetStreamCpuLoad( PaStream* stream ); --static PaError BuildDeviceList( PaAlsaHostApiRepresentation *hostApi ); -+static PaError BuildDeviceList( PaAlsaHostApiRepresentation *hostApi, void** scanResults, int* deviceCount ); - static int SetApproximateSampleRate( snd_pcm_t *pcm, snd_pcm_hw_params_t *hwParams, double sampleRate ); - static int GetExactSampleRate( snd_pcm_hw_params_t *hwParams, double *sampleRate ); - -+static PaError ScanDeviceInfos(struct PaUtilHostApiRepresentation *hostApi, PaHostApiIndex index, -+ void **newDeviceInfos, int *newDeviceCount ); -+static PaError CommitDeviceInfos(struct PaUtilHostApiRepresentation *hostApi, PaHostApiIndex index, -+ void *deviceInfos, int deviceCount); -+static PaError DisposeDeviceInfos(struct PaUtilHostApiRepresentation *hostApi, void *deviceInfos, -+ int deviceCount ); -+ - /* Callback prototypes */ - static void *CallbackThreadFunc( void *userData ); - -@@ -722,6 +738,8 @@ - { - PaError result = paNoError; - PaAlsaHostApiRepresentation *alsaHostApi = NULL; -+ void* scanResults = NULL; -+ int deviceCount = 0; - - /* Try loading Alsa library. */ - if (!PaAlsa_LoadLibrary()) -@@ -733,20 +751,29 @@ - alsaHostApi->hostApiIndex = hostApiIndex; - - *hostApi = (PaUtilHostApiRepresentation*)alsaHostApi; -+ (*hostApi)->deviceInfos = NULL; - (*hostApi)->info.structVersion = 1; - (*hostApi)->info.type = paALSA; - (*hostApi)->info.name = "ALSA"; - -+ (*hostApi)->ScanDeviceInfos = NULL; -+ (*hostApi)->CommitDeviceInfos = NULL; -+ (*hostApi)->DisposeDeviceInfos = NULL; - (*hostApi)->Terminate = Terminate; - (*hostApi)->OpenStream = OpenStream; - (*hostApi)->IsFormatSupported = IsFormatSupported; -+ (*hostApi)->ScanDeviceInfos = ScanDeviceInfos; -+ (*hostApi)->CommitDeviceInfos = CommitDeviceInfos; -+ (*hostApi)->DisposeDeviceInfos = DisposeDeviceInfos; - - /** If AlsaErrorHandler is to be used, do not forget to unregister callback pointer in - Terminate function. - */ - /*ENSURE_( snd_lib_error_set_handler(AlsaErrorHandler), paUnanticipatedHostError );*/ - -- PA_ENSURE( BuildDeviceList( alsaHostApi ) ); -+ ScanDeviceInfos(&alsaHostApi->baseHostApiRep, hostApiIndex, &scanResults, -+ &deviceCount); -+ CommitDeviceInfos(&alsaHostApi->baseHostApiRep, hostApiIndex, scanResults, deviceCount); - - PaUtil_InitializeStreamInterface( &alsaHostApi->callbackStreamInterface, - CloseStream, StartStream, -@@ -1075,7 +1105,7 @@ - } - - static PaError FillInDevInfo( PaAlsaHostApiRepresentation *alsaApi, HwDevInfo* deviceName, int blocking, -- PaAlsaDeviceInfo* devInfo, int* devIdx ) -+ PaAlsaDeviceInfo* devInfo, int* devIdx, PaLinuxScanDeviceInfosResults* out ) - { - PaError result = 0; - PaDeviceInfo *baseDeviceInfo = &devInfo->baseDeviceInfo; -@@ -1128,20 +1158,20 @@ - if( baseDeviceInfo->maxInputChannels > 0 || baseDeviceInfo->maxOutputChannels > 0 ) - { - /* Make device default if there isn't already one or it is the ALSA "default" device */ -- if( (baseApi->info.defaultInputDevice == paNoDevice || !strcmp(deviceName->alsaName, -+ if( (out->defaultInputDevice == paNoDevice || !strcmp(deviceName->alsaName, - "default" )) && baseDeviceInfo->maxInputChannels > 0 ) - { -- baseApi->info.defaultInputDevice = *devIdx; -+ out->defaultInputDevice = *devIdx; - PA_DEBUG(("Default input device: %s\n", deviceName->name)); - } -- if( (baseApi->info.defaultOutputDevice == paNoDevice || !strcmp(deviceName->alsaName, -+ if( (out->defaultOutputDevice == paNoDevice || !strcmp(deviceName->alsaName, - "default" )) && baseDeviceInfo->maxOutputChannels > 0 ) - { -- baseApi->info.defaultOutputDevice = *devIdx; -+ out->defaultOutputDevice = *devIdx; - PA_DEBUG(("Default output device: %s\n", deviceName->name)); - } - PA_DEBUG(("%s: Adding device %s: %d\n", __FUNCTION__, deviceName->name, *devIdx)); -- baseApi->deviceInfos[*devIdx] = (PaDeviceInfo *) devInfo; -+ out->deviceInfos[*devIdx] = (PaDeviceInfo *) devInfo; - (*devIdx) += 1; - } - else -@@ -1154,9 +1184,10 @@ - } - - /* Build PaDeviceInfo list, ignore devices for which we cannot determine capabilities (possibly busy, sigh) */ --static PaError BuildDeviceList( PaAlsaHostApiRepresentation *alsaApi ) -+static PaError BuildDeviceList( PaAlsaHostApiRepresentation *alsaApi, void** scanResults, int* count) - { - PaUtilHostApiRepresentation *baseApi = &alsaApi->baseHostApiRep; -+ PaLinuxScanDeviceInfosResults *outArgument = NULL; - PaAlsaDeviceInfo *deviceInfoArray; - int cardIdx = -1, devIdx = 0; - snd_ctl_card_info_t *cardInfo; -@@ -1171,13 +1202,11 @@ - #ifdef PA_ENABLE_DEBUG_OUTPUT - PaTime startTime = PaUtil_GetTime(); - #endif -+ PaLinuxScanDeviceInfosResults* out = NULL; - - if( getenv( "PA_ALSA_INITIALIZE_BLOCK" ) && atoi( getenv( "PA_ALSA_INITIALIZE_BLOCK" ) ) ) - blocking = 0; - -- /* These two will be set to the first working input and output device, respectively */ -- baseApi->info.defaultInputDevice = paNoDevice; -- baseApi->info.defaultOutputDevice = paNoDevice; - - /* Gather info about hw devices - -@@ -1341,8 +1370,14 @@ - else - PA_DEBUG(( "%s: Iterating over ALSA plugins failed: %s\n", __FUNCTION__, alsa_snd_strerror( res ) )); - -+ out = (PaLinuxScanDeviceInfosResults *) PaUtil_GroupAllocateMemory( -+ alsaApi->allocations, sizeof(PaLinuxScanDeviceInfosResults) ); -+ -+ out->defaultInputDevice = paNoDevice; -+ out->defaultOutputDevice = paNoDevice; -+ - /* allocate deviceInfo memory based on the number of devices */ -- PA_UNLESS( baseApi->deviceInfos = (PaDeviceInfo**)PaUtil_GroupAllocateMemory( -+ PA_UNLESS( out->deviceInfos = (PaDeviceInfo**)PaUtil_GroupAllocateMemory( - alsaApi->allocations, sizeof(PaDeviceInfo*) * (numDeviceNames) ), paInsufficientMemory ); - - /* allocate all device info structs in a contiguous block */ -@@ -1367,7 +1402,7 @@ - continue; - } - -- PA_ENSURE( FillInDevInfo( alsaApi, hwInfo, blocking, devInfo, &devIdx ) ); -+ PA_ENSURE( FillInDevInfo( alsaApi, hwInfo, blocking, devInfo, &devIdx, out ) ); - } - assert( devIdx < numDeviceNames ); - /* Now inspect 'dmix' and 'default' plugins */ -@@ -1381,11 +1416,13 @@ - } - - PA_ENSURE( FillInDevInfo( alsaApi, hwInfo, blocking, devInfo, -- &devIdx ) ); -+ &devIdx, out ) ); - } - free( hwDevInfos ); - -- baseApi->info.deviceCount = devIdx; /* Number of successfully queried devices */ -+ out->deviceCount = devIdx; /* Number of successfully queried devices */ -+ *scanResults = out; -+ *count = out->deviceCount; - - #ifdef PA_ENABLE_DEBUG_OUTPUT - PA_DEBUG(( "%s: Building device list took %f seconds\n", __FUNCTION__, PaUtil_GetTime() - startTime )); -@@ -3693,6 +3754,10 @@ - framesAvail, &xrun ) ); - if( xrun ) - { -+ if(*framesAvail == 0) -+ { -+ result = paInternalError; -+ } - goto end; - } - -@@ -3740,6 +3805,7 @@ - Pa_Sleep( 1 ); /* avoid hot loop */ - continue; - } -+ result = paInternalError; - - /* TODO: Add macro for checking system calls */ - PA_ENSURE( paInternalError ); -@@ -3769,6 +3835,7 @@ - xrun = 1; /* try recovering device */ - - PA_DEBUG(( "%s: poll timed out\n", __FUNCTION__, timeouts )); -+ result = paTimedOut; - goto end;/*PA_ENSURE( paTimedOut );*/ - } - } -@@ -4546,3 +4628,75 @@ - busyRetries_ = retries; - return paNoError; - } -+ -+static PaError ScanDeviceInfos(struct PaUtilHostApiRepresentation *hostApi, PaHostApiIndex hostApiIndex, -+ void **scanResults, int *newDeviceCount) -+{ -+ PaAlsaHostApiRepresentation* alsaHostApi = (PaAlsaHostApiRepresentation*)hostApi; -+ PaError result = paNoError; -+ PA_ENSURE(BuildDeviceList( alsaHostApi, scanResults, newDeviceCount )); -+ -+ return paNoError; -+ -+error: -+ return result; -+} -+ -+static PaError CommitDeviceInfos(struct PaUtilHostApiRepresentation *hostApi, PaHostApiIndex index, -+ void *scanResults, int deviceCount) -+{ -+ PaAlsaHostApiRepresentation* alsaHostApi = (PaAlsaHostApiRepresentation*)hostApi; -+ PaError result = paNoError; -+ -+ /* These two will be set to the first working input and output device, respectively */ -+ hostApi->info.defaultInputDevice = paNoDevice; -+ hostApi->info.defaultOutputDevice = paNoDevice; -+ -+ /* Free any old memory which might be in the device info */ -+ if( hostApi->deviceInfos ) -+ { -+ /* all device info structs are allocated in a block so we can destroy them here */ -+ PaUtil_GroupFreeMemory( alsaHostApi->allocations, hostApi->deviceInfos[0] ); -+ PaUtil_GroupFreeMemory( alsaHostApi->allocations, hostApi->deviceInfos ); -+ hostApi->deviceInfos = NULL; -+ } -+ -+ if( scanResults != NULL ) -+ { -+ PaLinuxScanDeviceInfosResults *scanDeviceInfosResults = ( PaLinuxScanDeviceInfosResults * ) scanResults; -+ -+ if( deviceCount > 0 ) -+ { -+ /* use the array allocated in ScanDeviceInfos() as our deviceInfos */ -+ hostApi->deviceInfos = scanDeviceInfosResults->deviceInfos; -+ hostApi->info.defaultInputDevice = scanDeviceInfosResults->defaultInputDevice; -+ hostApi->info.defaultOutputDevice = scanDeviceInfosResults->defaultOutputDevice; -+ hostApi->info.deviceCount = deviceCount; -+ } -+ -+ PaUtil_GroupFreeMemory( alsaHostApi->allocations, scanDeviceInfosResults ); -+ } -+ -+ return result; -+} -+ -+static PaError DisposeDeviceInfos(struct PaUtilHostApiRepresentation *hostApi, void *scanResults, int deviceCount) -+{ -+ PaAlsaHostApiRepresentation *alsaHostApi = (PaAlsaHostApiRepresentation*)hostApi; -+ -+ if( scanResults != NULL ) -+ { -+ PaLinuxScanDeviceInfosResults *scanDeviceInfosResults = ( PaLinuxScanDeviceInfosResults * ) scanResults; -+ if( scanDeviceInfosResults->deviceInfos ) -+ { -+ /* all device info structs are allocated in a block so we can destroy them here */ -+ PaUtil_GroupFreeMemory( alsaHostApi->allocations, scanDeviceInfosResults->deviceInfos[0] ); -+ PaUtil_GroupFreeMemory( alsaHostApi->allocations, scanDeviceInfosResults->deviceInfos ); -+ } -+ -+ PaUtil_GroupFreeMemory(alsaHostApi->allocations, scanDeviceInfosResults ); -+ } -+ -+ return paNoError; -+} -+ -Index: src/hostapi/oss/pa_unix_oss.c -=================================================================== ---- src/hostapi/oss/pa_unix_oss.c (revision 1799) -+++ src/hostapi/oss/pa_unix_oss.c (working copy) -@@ -256,6 +256,9 @@ - (*hostApi)->Terminate = Terminate; - (*hostApi)->OpenStream = OpenStream; - (*hostApi)->IsFormatSupported = IsFormatSupported; -+ (*hostApi)->ScanDeviceInfos = NULL; -+ (*hostApi)->CommitDeviceInfos = NULL; -+ (*hostApi)->DisposeDeviceInfos = NULL; - - PA_ENSURE( BuildDeviceList( ossHostApi ) ); - -Index: src/hostapi/skeleton/pa_hostapi_skeleton.c -=================================================================== ---- src/hostapi/skeleton/pa_hostapi_skeleton.c (revision 1799) -+++ src/hostapi/skeleton/pa_hostapi_skeleton.c (working copy) -@@ -206,9 +206,15 @@ - } - } - -+ (*hostApi)->ScanDeviceInfos = NULL; -+ (*hostApi)->CommitDeviceInfos = NULL; -+ (*hostApi)->DisposeDeviceInfos = NULL; - (*hostApi)->Terminate = Terminate; - (*hostApi)->OpenStream = OpenStream; - (*hostApi)->IsFormatSupported = IsFormatSupported; -+ (*hostApi)->ScanDeviceInfos = NULL; -+ (*hostApi)->CommitDeviceInfos = NULL; -+ (*hostApi)->DisposeDeviceInfos = NULL; - - PaUtil_InitializeStreamInterface( &skeletonHostApi->callbackStreamInterface, CloseStream, StartStream, - StopStream, AbortStream, IsStreamStopped, IsStreamActive, -Index: src/hostapi/wasapi/pa_win_wasapi.c -=================================================================== ---- src/hostapi/wasapi/pa_win_wasapi.c (revision 1799) -+++ src/hostapi/wasapi/pa_win_wasapi.c (working copy) -@@ -1386,6 +1386,9 @@ - } - } - -+ (*hostApi)->ScanDeviceInfos = NULL; -+ (*hostApi)->CommitDeviceInfos = NULL; -+ (*hostApi)->DisposeDeviceInfos = NULL; - (*hostApi)->Terminate = Terminate; - (*hostApi)->OpenStream = OpenStream; - (*hostApi)->IsFormatSupported = IsFormatSupported; -Index: src/hostapi/wdmks/pa_win_wdmks.c -=================================================================== ---- src/hostapi/wdmks/pa_win_wdmks.c (revision 1799) -+++ src/hostapi/wdmks/pa_win_wdmks.c (working copy) -@@ -1885,6 +1885,9 @@ - - (*hostApi)->info.deviceCount = deviceCount; - -+ (*hostApi)->ScanDeviceInfos = NULL; -+ (*hostApi)->CommitDeviceInfos = NULL; -+ (*hostApi)->DisposeDeviceInfos = NULL; - (*hostApi)->Terminate = Terminate; - (*hostApi)->OpenStream = OpenStream; - (*hostApi)->IsFormatSupported = IsFormatSupported; -@@ -3305,4 +3308,4 @@ - /* IMPLEMENT ME, see portaudio.h for required behavior*/ - PA_LOGL_; - return 0; --} -\ No newline at end of file -+} -Index: src/hostapi/jack/pa_jack.c -=================================================================== ---- src/hostapi/jack/pa_jack.c (revision 1799) -+++ src/hostapi/jack/pa_jack.c (working copy) -@@ -749,6 +749,9 @@ - - /* Register functions */ - -+ (*hostApi)->ScanDeviceInfos = NULL; -+ (*hostApi)->CommitDeviceInfos = NULL; -+ (*hostApi)->DisposeDeviceInfos = NULL; - (*hostApi)->Terminate = Terminate; - (*hostApi)->OpenStream = OpenStream; - (*hostApi)->IsFormatSupported = IsFormatSupported; -Index: src/hostapi/coreaudio/pa_mac_core.c -=================================================================== ---- src/hostapi/coreaudio/pa_mac_core.c (revision 1799) -+++ src/hostapi/coreaudio/pa_mac_core.c (working copy) -@@ -80,7 +80,28 @@ - /* prototypes for functions declared in this file */ - - PaError PaMacCore_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index ); -+static PaError ScanDeviceInfos(struct PaUtilHostApiRepresentation *hostApi, PaHostApiIndex index, -+ void **newDeviceInfos, int *newDeviceCount ); -+static PaError CommitDeviceInfos(struct PaUtilHostApiRepresentation *hostApi, PaHostApiIndex index, -+ void *deviceInfos, int deviceCount); -+static PaError DisposeDeviceInfos(struct PaUtilHostApiRepresentation *hostApi, void *deviceInfos, -+ int deviceCount ); - -+/* structures */ -+ -+/* used for tranferring device infos during scanning / rescanning */ -+typedef struct PaMacScanDeviceInfosResults -+{ -+ PaDeviceInfo **deviceInfos; -+ PaDeviceIndex defaultInputDevice; -+ PaDeviceIndex defaultOutputDevice; -+ -+ AudioDeviceID* devIds; -+ int devCount; -+ AudioDeviceID devInputDevice; -+ AudioDeviceID devOutputDevice; -+} PaMacScanDeviceInfosResults; -+ - /* - * Function declared in pa_mac_core.h. Sets up a PaMacCoreStreamInfoStruct - * with the requested flags and initializes channel map. -@@ -132,7 +153,6 @@ - return NULL; - PaMacAUHAL *macCoreHostApi = (PaMacAUHAL*)hostApi; - AudioDeviceID hostApiDevice = macCoreHostApi->devIds[device]; -- - UInt32 size = 0; - - error = AudioDeviceGetPropertyInfo( hostApiDevice, -@@ -311,46 +331,57 @@ - } - - --/*currently, this is only used in initialization, but it might be modified -- to be used when the list of devices changes.*/ --static PaError gatherDeviceInfo(PaMacAUHAL *auhalHostApi) -+//static PaError gatherDeviceInfo(PaMacAUHAL *auhalHostApi) -+static PaError gatherDeviceInfo(PaMacAUHAL* auhalHostApi, void** scanResults, int* count) - { -- UInt32 size; -- UInt32 propsize; -+ UInt32 propsize = 0; -+ UInt32 size = sizeof(AudioDeviceID); -+ PaMacScanDeviceInfosResults *outArgument = NULL; -+ PaError result = paNoError; -+ - VVDBUG(("gatherDeviceInfo()\n")); -- /* -- free any previous allocations -- */ -- if( auhalHostApi->devIds ) -- PaUtil_GroupFreeMemory(auhalHostApi->allocations, auhalHostApi->devIds); -- auhalHostApi->devIds = NULL; -- - /* -- figure out how many devices there are -- */ - AudioHardwareGetPropertyInfo( kAudioHardwarePropertyDevices, - &propsize, - NULL ); -- auhalHostApi->devCount = propsize / sizeof( AudioDeviceID ); -+ *count = (propsize / sizeof(AudioDeviceID)); - -- VDBUG( ( "Found %ld device(s).\n", auhalHostApi->devCount ) ); -+ VDBUG( ( "Found %ld device(s).\n", *count ) ); - -+ if(*count == 0) -+ return paNoError; -+ -+ /* Allocate the out param for all the info we need */ -+ outArgument = (PaMacScanDeviceInfosResults *) PaUtil_GroupAllocateMemory( -+ auhalHostApi->allocations, sizeof(PaMacScanDeviceInfosResults) ); -+ -+ if( !outArgument ) -+ { -+ result = paInsufficientMemory; -+ return result; -+ } -+ -+ outArgument->devCount = *count; -+ - /* -- copy the device IDs -- */ -- auhalHostApi->devIds = (AudioDeviceID *)PaUtil_GroupAllocateMemory( -+ outArgument->devIds = (AudioDeviceID *)PaUtil_GroupAllocateMemory( - auhalHostApi->allocations, - propsize ); -- if( !auhalHostApi->devIds ) -+ if( !outArgument->devIds ) - return paInsufficientMemory; - AudioHardwareGetProperty( kAudioHardwarePropertyDevices, - &propsize, -- auhalHostApi->devIds ); -+ outArgument->devIds ); - #ifdef MAC_CORE_VERBOSE_DEBUG - { - int i; -- for( i=0; idevCount; ++i ) -- printf( "Device %d\t: %ld\n", i, auhalHostApi->devIds[i] ); -+ for( i=0; idevCount; ++i ) -+ printf( "Device %d\t: %ld\n", i, outArgument->devIds[i] ); - } - #endif - -- size = sizeof(AudioDeviceID); -- auhalHostApi->defaultIn = kAudioDeviceUnknown; -- auhalHostApi->defaultOut = kAudioDeviceUnknown; -+ outArgument->devInputDevice = kAudioDeviceUnknown; -+ outArgument->devOutputDevice = kAudioDeviceUnknown; - - /* determine the default device. */ - /* I am not sure how these calls to AudioHardwareGetProperty() -@@ -358,42 +389,44 @@ - device as the default. */ - if( 0 != AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, - &size, -- &auhalHostApi->defaultIn) ) { -+ &outArgument->devInputDevice) ) { - int i; -- auhalHostApi->defaultIn = kAudioDeviceUnknown; -+ outArgument->devInputDevice = kAudioDeviceUnknown; - VDBUG(("Failed to get default input device from OS.")); - VDBUG((" I will substitute the first available input Device.")); -- for( i=0; idevCount; ++i ) { -+ -+ for( i=0; i< outArgument->devCount; ++i ) { - PaDeviceInfo devInfo; - if( 0 != GetChannelInfo( auhalHostApi, &devInfo, -- auhalHostApi->devIds[i], TRUE ) ) -+ outArgument->devIds[i], TRUE ) ) - if( devInfo.maxInputChannels ) { -- auhalHostApi->defaultIn = auhalHostApi->devIds[i]; -+ outArgument->devInputDevice = outArgument->devIds[i]; - break; - } - } - } - if( 0 != AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, - &size, -- &auhalHostApi->defaultOut) ) { -+ &outArgument->devOutputDevice) ) { - int i; -- auhalHostApi->defaultIn = kAudioDeviceUnknown; -+ outArgument->devOutputDevice = kAudioDeviceUnknown; - VDBUG(("Failed to get default output device from OS.")); - VDBUG((" I will substitute the first available output Device.")); -- for( i=0; idevCount; ++i ) { -+ for( i=0; idevCount; ++i ) { - PaDeviceInfo devInfo; - if( 0 != GetChannelInfo( auhalHostApi, &devInfo, -- auhalHostApi->devIds[i], FALSE ) ) -+ outArgument->devIds[i], FALSE ) ) - if( devInfo.maxOutputChannels ) { -- auhalHostApi->defaultOut = auhalHostApi->devIds[i]; -+ outArgument->devOutputDevice = outArgument->devIds[i]; - break; - } - } - } - -- VDBUG( ( "Default in : %ld\n", auhalHostApi->defaultIn ) ); -- VDBUG( ( "Default out: %ld\n", auhalHostApi->defaultOut ) ); -+ VDBUG( ( "Default in : %ld\n", outArgument->devInputDevice ) ); -+ VDBUG( ( "Default out: %ld\n", outArgument->devOutputDevice ) ); - -+ *scanResults = outArgument; - return paNoError; - } - -@@ -402,9 +435,9 @@ - AudioDeviceID macCoreDeviceId, - int isInput) - { -- UInt32 propSize; -+ UInt32 propSize = 0; - PaError err = paNoError; -- UInt32 i; -+ UInt32 i = 0; - int numChannels = 0; - AudioBufferList *buflist = NULL; - UInt32 frameLatency; -@@ -528,10 +561,10 @@ - PaError PaMacCore_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex hostApiIndex ) - { - PaError result = paNoError; -- int i; - PaMacAUHAL *auhalHostApi = NULL; -- PaDeviceInfo *deviceInfoArray; - int unixErr; -+ void* scanResults = NULL; -+ int deviceCount = 0; - - VVDBUG(("PaMacCore_Initialize(): hostApiIndex=%d\n", hostApiIndex)); - -@@ -572,65 +605,29 @@ - auhalHostApi->devIds = NULL; - auhalHostApi->devCount = 0; - -- /* get the info we need about the devices */ -- result = gatherDeviceInfo( auhalHostApi ); -- if( result != paNoError ) -- goto error; -- - *hostApi = &auhalHostApi->inheritedHostApiRep; - (*hostApi)->info.structVersion = 1; - (*hostApi)->info.type = paCoreAudio; - (*hostApi)->info.name = "Core Audio"; -- -+ -+ (*hostApi)->deviceInfos = NULL; -+ - (*hostApi)->info.defaultInputDevice = paNoDevice; - (*hostApi)->info.defaultOutputDevice = paNoDevice; -- - (*hostApi)->info.deviceCount = 0; - -- if( auhalHostApi->devCount > 0 ) -- { -- (*hostApi)->deviceInfos = (PaDeviceInfo**)PaUtil_GroupAllocateMemory( -- auhalHostApi->allocations, sizeof(PaDeviceInfo*) * auhalHostApi->devCount); -- if( !(*hostApi)->deviceInfos ) -- { -- result = paInsufficientMemory; -- goto error; -- } -+ (*hostApi)->ScanDeviceInfos = ScanDeviceInfos; -+ (*hostApi)->CommitDeviceInfos = CommitDeviceInfos; -+ (*hostApi)->DisposeDeviceInfos = DisposeDeviceInfos; - -- /* allocate all device info structs in a contiguous block */ -- deviceInfoArray = (PaDeviceInfo*)PaUtil_GroupAllocateMemory( -- auhalHostApi->allocations, sizeof(PaDeviceInfo) * auhalHostApi->devCount ); -- if( !deviceInfoArray ) -- { -- result = paInsufficientMemory; -- goto error; -- } -+ result = ScanDeviceInfos(&auhalHostApi->inheritedHostApiRep, hostApiIndex, &scanResults, -+ &deviceCount); - -- for( i=0; i < auhalHostApi->devCount; ++i ) -- { -- int err; -- err = InitializeDeviceInfo( auhalHostApi, &deviceInfoArray[i], -- auhalHostApi->devIds[i], -- hostApiIndex ); -- if (err == paNoError) -- { /* copy some info and set the defaults */ -- (*hostApi)->deviceInfos[(*hostApi)->info.deviceCount] = &deviceInfoArray[i]; -- if (auhalHostApi->devIds[i] == auhalHostApi->defaultIn) -- (*hostApi)->info.defaultInputDevice = (*hostApi)->info.deviceCount; -- if (auhalHostApi->devIds[i] == auhalHostApi->defaultOut) -- (*hostApi)->info.defaultOutputDevice = (*hostApi)->info.deviceCount; -- (*hostApi)->info.deviceCount++; -- } -- else -- { /* there was an error. we need to shift the devices down, so we ignore this one */ -- int j; -- auhalHostApi->devCount--; -- for( j=i; jdevCount; ++j ) -- auhalHostApi->devIds[j] = auhalHostApi->devIds[j+1]; -- i--; -- } -- } -- } -+ if(result != paNoError) -+ goto error; -+ -+ /* FIXME for now we ignore the result of CommitDeviceInfos(), it should probably be an atomic non-failing operation */ -+ CommitDeviceInfos( &auhalHostApi->inheritedHostApiRep, hostApiIndex, scanResults, deviceCount ); - - (*hostApi)->Terminate = Terminate; - (*hostApi)->OpenStream = OpenStream; -@@ -2468,3 +2465,148 @@ - - return PaUtil_GetCpuLoad( &stream->cpuLoadMeasurer ); - } -+ -+static PaError ScanDeviceInfos(struct PaUtilHostApiRepresentation *hostApi, PaHostApiIndex hostApiIndex, -+ void **scanResults, int *newDeviceCount) -+{ -+ PaMacAUHAL* auhalHostApi = (PaMacAUHAL*)hostApi; -+ PaDeviceInfo *deviceInfoArray = NULL; -+ PaError result = paNoError; -+ int i = 0; -+ PaMacScanDeviceInfosResults* out = NULL; -+ -+ /* get the info we need about the devices */ -+ result = gatherDeviceInfo( auhalHostApi, scanResults, newDeviceCount ); -+ -+ if( result != paNoError ) -+ return result; -+ -+ out = (PaMacScanDeviceInfosResults*)*scanResults; -+ -+ if( out->devCount > 0 ) -+ { -+ int count = 0; -+ -+ /* allocate array for pointers to PaDeviceInfo structs */ -+ out->deviceInfos = (PaDeviceInfo**)PaUtil_GroupAllocateMemory( -+ auhalHostApi->allocations, sizeof(PaDeviceInfo*) * out->devCount); -+ if( !out->deviceInfos ) -+ { -+ result = paInsufficientMemory; -+ return result; -+ } -+ -+ /* allocate all device info structs in a contiguous block */ -+ deviceInfoArray = (PaDeviceInfo*)PaUtil_GroupAllocateMemory( -+ auhalHostApi->allocations, sizeof(PaDeviceInfo) * out->devCount ); -+ if( !deviceInfoArray ) -+ { -+ result = paInsufficientMemory; -+ return result; -+ } -+ -+ for( i=0; i < out->devCount; ++i ) -+ { -+ int err; -+ err = InitializeDeviceInfo( auhalHostApi, &deviceInfoArray[i], -+ out->devIds[i], -+ hostApiIndex ); -+ if (err == paNoError) -+ { -+ /* copy some info and set the defaults */ -+ out->deviceInfos[count] = &deviceInfoArray[i]; -+ -+ if (out->devIds[i] == out->devInputDevice) -+ { -+ out->defaultInputDevice = count; -+ } -+ if (out->devIds[i] == out->devOutputDevice) -+ { -+ out->defaultOutputDevice = count; -+ } -+ count++; -+ } -+ else -+ { -+ /* there was an error. we need to shift the devices down, so we ignore this one */ -+ int j; -+ out->devCount--; -+ for( j=i; jdevCount; ++j ) -+ out->devIds[j] = out->devIds[j+1]; -+ i--; -+ } -+ } -+ } -+ *newDeviceCount = out->devCount; -+ -+ return paNoError; -+} -+ -+static PaError CommitDeviceInfos(struct PaUtilHostApiRepresentation *hostApi, PaHostApiIndex index, -+ void *scanResults, int deviceCount) -+{ -+ PaMacAUHAL* auhalHostApi = (PaMacAUHAL*)hostApi; -+ PaError result = paNoError; -+ -+ hostApi->info.deviceCount = 0; -+ hostApi->info.defaultInputDevice = paNoDevice; -+ hostApi->info.defaultOutputDevice = paNoDevice; -+ -+ /* -- free any previous allocations -- */ -+ if( auhalHostApi->devIds ) -+ { -+ PaUtil_GroupFreeMemory(auhalHostApi->allocations, auhalHostApi->devIds); -+ } -+ auhalHostApi->devIds = NULL; -+ -+ /* Free any old memory which might be in the device info */ -+ if( hostApi->deviceInfos ) -+ { -+ PaUtil_GroupFreeMemory( auhalHostApi->allocations, hostApi->deviceInfos[0] ); -+ PaUtil_GroupFreeMemory( auhalHostApi->allocations, hostApi->deviceInfos ); -+ hostApi->deviceInfos = NULL; -+ } -+ -+ if( scanResults != NULL ) -+ { -+ PaMacScanDeviceInfosResults *scanDeviceInfosResults = ( PaMacScanDeviceInfosResults * ) scanResults; -+ -+ if( deviceCount > 0 ) -+ { -+ /* use the array allocated in ScanDeviceInfos() as our deviceInfos */ -+ hostApi->deviceInfos = scanDeviceInfosResults->deviceInfos; -+ hostApi->info.defaultInputDevice = scanDeviceInfosResults->defaultInputDevice; -+ hostApi->info.defaultOutputDevice = scanDeviceInfosResults->defaultOutputDevice; -+ hostApi->info.deviceCount = deviceCount; -+ auhalHostApi->devIds = scanDeviceInfosResults->devIds; -+ auhalHostApi->devCount = scanDeviceInfosResults->devCount; -+ auhalHostApi->defaultIn = scanDeviceInfosResults->devInputDevice; -+ auhalHostApi->defaultOut = scanDeviceInfosResults->devOutputDevice; -+ } -+ -+ PaUtil_GroupFreeMemory( auhalHostApi->allocations, scanDeviceInfosResults ); -+ } -+ -+ return result; -+} -+ -+static PaError DisposeDeviceInfos(struct PaUtilHostApiRepresentation *hostApi, void *scanResults, int deviceCount) -+{ -+ PaMacAUHAL *auhalHostApi = (PaMacAUHAL*)hostApi; -+ -+ if( scanResults != NULL ) -+ { -+ PaMacScanDeviceInfosResults *scanDeviceInfosResults = ( PaMacScanDeviceInfosResults * ) scanResults; -+ if( scanDeviceInfosResults->deviceInfos ) -+ { -+ /* all device info structs are allocated in a block so we can destroy them here */ -+ PaUtil_GroupFreeMemory( auhalHostApi->allocations, scanDeviceInfosResults->deviceInfos[0] ); -+ PaUtil_GroupFreeMemory( auhalHostApi->allocations, scanDeviceInfosResults->deviceInfos ); -+ } -+ -+ PaUtil_GroupFreeMemory(auhalHostApi->allocations, scanDeviceInfosResults ); -+ } -+ -+ return paNoError; -+} -+ -Index: src/hostapi/asio/pa_asio.cpp -=================================================================== ---- src/hostapi/asio/pa_asio.cpp (revision 1799) -+++ src/hostapi/asio/pa_asio.cpp (working copy) -@@ -1315,6 +1315,9 @@ - } - - -+ (*hostApi)->ScanDeviceInfos = NULL; -+ (*hostApi)->CommitDeviceInfos = NULL; -+ (*hostApi)->DisposeDeviceInfos = NULL; - (*hostApi)->Terminate = Terminate; - (*hostApi)->OpenStream = OpenStream; - (*hostApi)->IsFormatSupported = IsFormatSupported; -Index: src/common/pa_front.c -=================================================================== ---- src/common/pa_front.c (revision 1799) -+++ src/common/pa_front.c (working copy) -@@ -737,13 +737,12 @@ - for( i = 0 ; i < paInternalInfo_.hostApisCount_ ; ++i ) - { - PaUtilHostApiRepresentation *hostApi = paInternalInfo_.hostApis_[i]; -+ PA_DEBUG(( "Scanning new device list for host api %d.\n",i)); - if( hostApi->ScanDeviceInfos == NULL ) - continue; - -- PA_DEBUG(( "Scanning new device list for host api %d.\n",i)); - if( hostApi->ScanDeviceInfos( hostApi, i, &scanResults[ i ], &deviceCounts[ i ] ) != paNoError ) - break; -- - } - - /* Check the result of the scan operation */ diff --git a/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java b/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java index 556f1e6fe..8c8c4e03b 100644 --- a/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java @@ -30,6 +30,8 @@ import net.java.sip.communicator.util.skin.*; import net.java.sip.communicator.util.swing.*; +import org.jitsi.service.configuration.*; +import org.jitsi.service.resources.*; import org.osgi.framework.*; /** @@ -37,7 +39,7 @@ * contains "New account". * * @author Yana Stamcheva - * @author Lubomir Marinov + * @author Lyubomir Marinov * @author Adam Netocny */ public class ToolsMenu @@ -92,16 +94,16 @@ public class ToolsMenu * Creates an instance of FileMenu. * @param parentWindow The parent ChatWindow. */ - public ToolsMenu(MainFrame parentWindow) { - - super(GuiActivator.getResources().getI18NString("service.gui.TOOLS")); + public ToolsMenu(MainFrame parentWindow) + { + ResourceManagementService r = GuiActivator.getResources(); - this.setMnemonic( - GuiActivator.getResources().getI18nMnemonic("service.gui.TOOLS")); + setText(r.getI18NString("service.gui.TOOLS")); + setMnemonic(r.getI18nMnemonic("service.gui.TOOLS")); - this.registerMenuItems(); + registerMenuItems(); - this.initPluginComponents(); + initPluginComponents(); } /** @@ -174,13 +176,16 @@ else if (itemName.equals("conference")) confInviteDialog.setVisible(true); } else + { + ResourceManagementService r = GuiActivator.getResources(); + new ErrorDialog( - null, - GuiActivator.getResources().getI18NString( - "service.gui.WARNING"), - GuiActivator.getResources().getI18NString( - "service.gui.NO_ONLINE_CONFERENCING_ACCOUNT")) - .showDialog(); + null, + r.getI18NString("service.gui.WARNING"), + r.getI18NString( + "service.gui.NO_ONLINE_CONFERENCING_ACCOUNT")) + .showDialog(); + } } else if (itemName.equals("showHideOffline")) { @@ -287,36 +292,38 @@ private void registerMenuItems() { // We only add the options button if the property SHOW_OPTIONS_WINDOW // specifies so or if it's not set. + ConfigurationService cfg = GuiActivator.getConfigurationService(); Boolean showOptionsProp - = GuiActivator.getConfigurationService() - .getBoolean(ConfigurationFrame.SHOW_OPTIONS_WINDOW_PROPERTY, - true); + = cfg.getBoolean( + ConfigurationFrame.SHOW_OPTIONS_WINDOW_PROPERTY, + true); if (showOptionsProp.booleanValue()) { UIService uiService = GuiActivator.getUIService(); - if ((uiService == null) || !uiService.useMacOSXScreenMenuBar() - || !registerConfigMenuItemMacOSX()) + + if ((uiService == null) + || !uiService.useMacOSXScreenMenuBar() + || !registerConfigMenuItemMacOSX()) { registerConfigMenuItemNonMacOSX(); } } - conferenceMenuItem = new JMenuItem( - GuiActivator.getResources().getI18NString( - "service.gui.CREATE_CONFERENCE_CALL")); + ResourceManagementService r = GuiActivator.getResources(); - conferenceMenuItem.setMnemonic(GuiActivator.getResources() - .getI18nMnemonic("service.gui.CREATE_CONFERENCE_CALL")); + conferenceMenuItem + = new JMenuItem( + r.getI18NString("service.gui.CREATE_CONFERENCE_CALL")); + conferenceMenuItem.setMnemonic( + r.getI18nMnemonic("service.gui.CREATE_CONFERENCE_CALL")); conferenceMenuItem.setName("conference"); conferenceMenuItem.addActionListener(this); - this.add(conferenceMenuItem); + add(conferenceMenuItem); initVideoBridgeMenu(); - if(!GuiActivator.getConfigurationService().getBoolean( - AUTO_ANSWER_MENU_DISABLED_PROP, - false)) + if(!cfg.getBoolean(AUTO_ANSWER_MENU_DISABLED_PROP, false)) { if(ConfigurationManager.isAutoAnswerDisableSubmenu()) { @@ -337,25 +344,20 @@ private void registerMenuItems() ? "service.gui.HIDE_OFFLINE_CONTACTS" : "service.gui.SHOW_OFFLINE_CONTACTS"; - hideOfflineMenuItem = new JMenuItem( - GuiActivator.getResources().getI18NString(offlineTextKey)); - - hideOfflineMenuItem.setMnemonic(GuiActivator.getResources() - .getI18nMnemonic(offlineTextKey)); + hideOfflineMenuItem = new JMenuItem(r.getI18NString(offlineTextKey)); + hideOfflineMenuItem.setMnemonic(r.getI18nMnemonic(offlineTextKey)); hideOfflineMenuItem.setName("showHideOffline"); hideOfflineMenuItem.addActionListener(this); this.add(hideOfflineMenuItem); // Sound on/off menu item. - String soundTextKey = GuiActivator.getAudioNotifier().isMute() - ? "service.gui.SOUND_ON" - : "service.gui.SOUND_OFF"; - - soundMenuItem = new JMenuItem( - GuiActivator.getResources().getI18NString(soundTextKey)); + String soundTextKey + = GuiActivator.getAudioNotifier().isMute() + ? "service.gui.SOUND_ON" + : "service.gui.SOUND_OFF"; - soundMenuItem.setMnemonic(GuiActivator.getResources() - .getI18nMnemonic(soundTextKey)); + soundMenuItem = new JMenuItem(r.getI18NString(soundTextKey)); + soundMenuItem.setMnemonic(r.getI18nMnemonic(soundTextKey)); soundMenuItem.setName("sound"); soundMenuItem.addActionListener(this); this.add(soundMenuItem); @@ -398,7 +400,7 @@ private List getVideoBridgeProviders() */ private void initVideoBridgeMenu() { - // If already created remove the previous menu in order to reinitialize + // If already created, remove the previous menu in order to reinitialize // it. if (videoBridgeMenuItem != null) { @@ -427,47 +429,53 @@ public void menuCanceled(MenuEvent arg0) {} = getVideoBridgeProviders(); // Add a service listener in order to be notified when a new protocol - // privder is added or removed and the list should be refreshed. + // provider is added or removed and the list should be refreshed. GuiActivator.bundleContext.addServiceListener(this); - if (videoBridgeProviders == null || videoBridgeProviders.size() <= 0) + int videoBridgeProviderCount + = (videoBridgeProviders == null) ? 0 : videoBridgeProviders.size(); + ResourceManagementService r = GuiActivator.getResources(); + + if (videoBridgeProviderCount <= 0) { - videoBridgeMenuItem = new VideoBridgeProviderMenuItem( - GuiActivator.getResources().getI18NString( - "service.gui.CREATE_VIDEO_BRIDGE"), null); + videoBridgeMenuItem + = new VideoBridgeProviderMenuItem( + r.getI18NString("service.gui.CREATE_VIDEO_BRIDGE"), + null); videoBridgeMenuItem.setEnabled(false); } - else if (videoBridgeProviders.size() == 1) + else if (videoBridgeProviderCount == 1) { - videoBridgeMenuItem = new VideoBridgeProviderMenuItem( - GuiActivator.getResources().getI18NString( - "service.gui.CREATE_VIDEO_BRIDGE"), - videoBridgeProviders.get(0)); + videoBridgeMenuItem + = new VideoBridgeProviderMenuItem( + r.getI18NString("service.gui.CREATE_VIDEO_BRIDGE"), + videoBridgeProviders.get(0)); videoBridgeMenuItem.setName("videoBridge"); videoBridgeMenuItem.addActionListener(this); } - else if (videoBridgeProviders.size() > 1) + else if (videoBridgeProviderCount > 1) { - videoBridgeMenuItem = new SIPCommMenu( - GuiActivator.getResources().getI18NString( - "service.gui.CREATE_VIDEO_BRIDGE_MENU")); + videoBridgeMenuItem + = new SIPCommMenu( + r.getI18NString( + "service.gui.CREATE_VIDEO_BRIDGE_MENU")); for (ProtocolProviderService videoBridgeProvider - : videoBridgeProviders) + : videoBridgeProviders) { VideoBridgeProviderMenuItem videoBridgeItem = new VideoBridgeProviderMenuItem(videoBridgeProvider); ((JMenu) videoBridgeMenuItem).add(videoBridgeItem); videoBridgeItem.setIcon( - ImageLoader.getAccountStatusImage(videoBridgeProvider)); + ImageLoader.getAccountStatusImage(videoBridgeProvider)); } } - videoBridgeMenuItem.setIcon(GuiActivator.getResources().getImage( - "service.gui.icons.VIDEO_BRIDGE")); - videoBridgeMenuItem.setMnemonic(GuiActivator.getResources() - .getI18nMnemonic("service.gui.CREATE_VIDEO_BRIDGE")); + videoBridgeMenuItem.setIcon( + r.getImage("service.gui.icons.VIDEO_BRIDGE")); + videoBridgeMenuItem.setMnemonic( + r.getI18nMnemonic("service.gui.CREATE_VIDEO_BRIDGE")); insert(videoBridgeMenuItem, 1); } @@ -487,14 +495,15 @@ private boolean registerConfigMenuItemMacOSX() */ private void registerConfigMenuItemNonMacOSX() { - configMenuItem = new JMenuItem( - GuiActivator.getResources().getI18NString("service.gui.SETTINGS"), - GuiActivator.getResources().getImage( - "service.gui.icons.CONFIGURE_ICON")); - - this.add(configMenuItem); - configMenuItem.setMnemonic(GuiActivator.getResources() - .getI18nMnemonic("service.gui.SETTINGS")); + ResourceManagementService r = GuiActivator.getResources(); + + configMenuItem + = new JMenuItem( + r.getI18NString("service.gui.SETTINGS"), + r.getImage("service.gui.icons.CONFIGURE_ICON")); + add(configMenuItem); + configMenuItem.setMnemonic( + r.getI18nMnemonic("service.gui.SETTINGS")); configMenuItem.setName("config"); configMenuItem.addActionListener(this); } @@ -504,19 +513,23 @@ private void registerConfigMenuItemNonMacOSX() */ public void loadSkin() { - conferenceMenuItem.setIcon(GuiActivator.getResources().getImage( - "service.gui.icons.CONFERENCE_CALL")); - videoBridgeMenuItem.setIcon(GuiActivator.getResources().getImage( - "service.gui.icons.VIDEO_BRIDGE")); - hideOfflineMenuItem.setIcon(GuiActivator.getResources().getImage( - "service.gui.icons.SHOW_HIDE_OFFLINE_ICON")); - soundMenuItem.setIcon(GuiActivator.getResources().getImage( - "service.gui.icons.SOUND_MENU_ICON")); - - if(configMenuItem != null) + ResourceManagementService r = GuiActivator.getResources(); + + conferenceMenuItem.setIcon( + r.getImage("service.gui.icons.CONFERENCE_CALL")); + if (configMenuItem != null) + { + configMenuItem.setIcon( + r.getImage("service.gui.icons.CONFIGURE_ICON")); + } + hideOfflineMenuItem.setIcon( + r.getImage("service.gui.icons.SHOW_HIDE_OFFLINE_ICON")); + soundMenuItem.setIcon( + r.getImage("service.gui.icons.SOUND_MENU_ICON")); + if (videoBridgeMenuItem != null) { - configMenuItem.setIcon(GuiActivator.getResources().getImage( - "service.gui.icons.CONFIGURE_ICON")); + videoBridgeMenuItem.setIcon( + r.getImage("service.gui.icons.VIDEO_BRIDGE")); } }