diff --git a/lib/native/windows-64/jnwasapi.dll b/lib/native/windows-64/jnwasapi.dll index 9e38b6178897ce15c3afa250be0509dc83a08ddb..4d689d1fe772362e9022dc1c2c5637a14b25530a 100644 Binary files a/lib/native/windows-64/jnwasapi.dll and b/lib/native/windows-64/jnwasapi.dll differ diff --git a/lib/native/windows/jnwasapi.dll b/lib/native/windows/jnwasapi.dll index 9ffc7d48ce36a3cee077c6f29a4b45baa52e03d5..09100d3e7dedf772402cddb1eb85cd5c12ae8f5d 100644 Binary files a/lib/native/windows/jnwasapi.dll and b/lib/native/windows/jnwasapi.dll differ diff --git a/src/native/windows/wasapi/org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP.c b/src/native/windows/wasapi/org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP.c index e0e2b63e8e5361e3cb5243dc113f73a74b7e91d8..661c156859f929ec6041bef15e84d5ea8293151c 100644 --- a/src/native/windows/wasapi/org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP.c +++ b/src/native/windows/wasapi/org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP.c @@ -195,6 +195,17 @@ Java_org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_IMedia WASAPI_throwNewHResultException(env, hr, __func__, __LINE__); } +JNIEXPORT jint JNICALL +Java_org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_IMediaObject_1Flush + (JNIEnv *env, jclass clazz, jlong thiz) +{ + HRESULT hr = IMediaObject_Flush((IMediaObject *) (intptr_t) thiz); + + if (FAILED(hr)) + WASAPI_throwNewHResultException(env, hr, __func__, __LINE__); + return (jint) hr; +} + JNIEXPORT jint JNICALL Java_org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_IMediaObject_1GetInputStatus (JNIEnv *env, jclass clazz, jlong thiz, jint dwInputStreamIndex) diff --git a/src/native/windows/wasapi/org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP.h b/src/native/windows/wasapi/org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP.h index 3aabf9caf86e1899f4d67ee813af90e34e7b2637..0867625bbf1d057be85c2af8b5d4cf27508194e6 100644 --- a/src/native/windows/wasapi/org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP.h +++ b/src/native/windows/wasapi/org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP.h @@ -7,16 +7,6 @@ #ifdef __cplusplus extern "C" { #endif -#undef org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_DMO_E_NOTACCEPTING -#define org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_DMO_E_NOTACCEPTING -2147220988L -#undef org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_DMO_INPUT_STATUSF_ACCEPT_DATA -#define org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_DMO_INPUT_STATUSF_ACCEPT_DATA 1L -#undef org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_DMO_OUTPUT_DATA_BUFFERF_INCOMPLETE -#define org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_DMO_OUTPUT_DATA_BUFFERF_INCOMPLETE 16777216L -#undef org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_DMO_SET_TYPEF_TEST_ONLY -#define org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_DMO_SET_TYPEF_TEST_ONLY 1L -#undef org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_SINGLE_CHANNEL_AEC -#define org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_SINGLE_CHANNEL_AEC 0L /* * Class: org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP * Method: DMO_MEDIA_TYPE_fill @@ -129,6 +119,14 @@ JNIEXPORT jint JNICALL Java_org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi JNIEXPORT void JNICALL Java_org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_IMediaBuffer_1SetLength (JNIEnv *, jclass, jlong, jint); +/* + * Class: org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP + * Method: IMediaObject_Flush + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP_IMediaObject_1Flush + (JNIEnv *, jclass, jlong); + /* * Class: org_jitsi_impl_neomedia_jmfext_media_protocol_wasapi_VoiceCaptureDSP * Method: IMediaObject_GetInputStatus diff --git a/src/org/jitsi/impl/neomedia/jmfext/media/protocol/wasapi/AudioCaptureClient.java b/src/org/jitsi/impl/neomedia/jmfext/media/protocol/wasapi/AudioCaptureClient.java index 07f7b48e2938ba3526dabc25b1887c35cb4759af..962fb9b2673e387da30df3f92c31df992e11ff9b 100644 --- a/src/org/jitsi/impl/neomedia/jmfext/media/protocol/wasapi/AudioCaptureClient.java +++ b/src/org/jitsi/impl/neomedia/jmfext/media/protocol/wasapi/AudioCaptureClient.java @@ -117,6 +117,12 @@ public class AudioCaptureClient */ private long iAudioClient; + /** + * The <tt>AudioFormat</tt> of the data output by this + * <tt>AudioCaptureClient</tt>. + */ + final AudioFormat outFormat; + private byte[] remainder; private int remainderLength; @@ -266,6 +272,7 @@ public AudioCaptureClient( this.iAudioCaptureClient = iAudioCaptureClient; iAudioCaptureClient = 0; + this.outFormat = outFormat; this.transferHandler = transferHandler; } finally diff --git a/src/org/jitsi/impl/neomedia/jmfext/media/protocol/wasapi/VoiceCaptureDSP.java b/src/org/jitsi/impl/neomedia/jmfext/media/protocol/wasapi/VoiceCaptureDSP.java index fac7536f7160a5f7afaf0ce7553337d378e3448e..de8d7e7cf68145e8552272c4d491ed9c503fe896 100644 --- a/src/org/jitsi/impl/neomedia/jmfext/media/protocol/wasapi/VoiceCaptureDSP.java +++ b/src/org/jitsi/impl/neomedia/jmfext/media/protocol/wasapi/VoiceCaptureDSP.java @@ -179,6 +179,9 @@ public static native int IMediaBuffer_GetMaxLength(long thiz) public static native void IMediaBuffer_SetLength(long thiz, int cbLength) throws HResultException; + public static native int IMediaObject_Flush(long thiz) + throws HResultException; + public static native int IMediaObject_GetInputStatus( long thiz, int dwInputStreamIndex) diff --git a/src/org/jitsi/impl/neomedia/jmfext/media/protocol/wasapi/WASAPIStream.java b/src/org/jitsi/impl/neomedia/jmfext/media/protocol/wasapi/WASAPIStream.java index db411f5bc9af5543320d64e696b409a37e1cac3d..8baac621ba440d57e02dd134313409174869a450 100644 --- a/src/org/jitsi/impl/neomedia/jmfext/media/protocol/wasapi/WASAPIStream.java +++ b/src/org/jitsi/impl/neomedia/jmfext/media/protocol/wasapi/WASAPIStream.java @@ -10,6 +10,7 @@ import static org.jitsi.impl.neomedia.jmfext.media.protocol.wasapi.WASAPI.*; import java.io.*; +import java.util.*; import javax.media.*; import javax.media.control.*; @@ -845,6 +846,43 @@ private int processInput(int dwInputStreamIndex) processed += written; } } + + if (dwInputStreamIndex == 1) + { + int length; + + try + { + length = IMediaBuffer_GetLength(pBuffer); + } + catch (HResultException hre) + { + hresult = hre.getHResult(); + length = 0; + logger.error("IMediaBuffer_GetLength", hre); + } + + int silence = maxLength - length; + + if (silence > 0) + { + if ((processInputBuffer == null) + || (processInputBuffer.length < silence)) + processInputBuffer = new byte[silence]; + Arrays.fill(processInputBuffer, 0, silence, (byte) 0); + try + { + MediaBuffer_push( + pBuffer, + processInputBuffer, 0, silence); + } + catch (HResultException hre) + { + logger.error("MediaBuffer_push", hre); + } + } + } + try { hresult @@ -992,10 +1030,8 @@ else if (cause instanceof IOException) private BufferTransferHandler runInProcessThread() { // ProcessInput - int numProcessedCapture = processInput(/* capture */ 0); - int numProcessedRender = processInput(/* render */ 1); -if ((numProcessedCapture > 0) || (numProcessedRender > 0)) - System.err.println("WASAPIStream.runInProcessThread: capture " + numProcessedCapture + ", render " + numProcessedRender); + processInput(/* capture */ 0); + processInput(/* render */ 1); // ProcessOutput int dwStatus = 0; @@ -1009,8 +1045,6 @@ private BufferTransferHandler runInProcessThread() /* dwFlags */ 0, 1, dmoOutputDataBuffer); - dwStatus - = DMO_OUTPUT_DATA_BUFFER_getDwStatus(dmoOutputDataBuffer); } catch (HResultException hre) { @@ -1053,6 +1087,30 @@ private BufferTransferHandler runInProcessThread() while ((dwStatus & DMO_OUTPUT_DATA_BUFFERF_INCOMPLETE) == DMO_OUTPUT_DATA_BUFFERF_INCOMPLETE); + /* + * IMediaObject::ProcessOutput has completed which means that, as far as + * it is concerned, it does not have any input data to process. Make + * sure that the states of the IMediaBuffer instances are in accord. + */ + try + { + /* + * XXX Make sure that the IMediaObject releases any IMediaBuffer + * references it holds. + */ + int hresult = IMediaObject_Flush(iMediaObject); + + if (SUCCEEDED(hresult)) + { + IMediaBuffer_SetLength(captureIMediaBuffer, 0); + IMediaBuffer_SetLength(renderIMediaBuffer, 0); + } + } + catch (HResultException hre) + { + logger.error("IMediaBuffer_SetLength", hre); + } + return (processedLength >= bufferMaxLength) ? transferHandler : null; }