diff --git a/jni/redphone/CallAudioManager.h b/jni/redphone/CallAudioManager.h index 2e5d0d7748..408d6f6d03 100644 --- a/jni/redphone/CallAudioManager.h +++ b/jni/redphone/CallAudioManager.h @@ -15,7 +15,7 @@ class CallAudioManager { private: volatile int running; - int finished; + volatile int finished; SLObjectItf engineObject; SLEngineItf engineEngine; AudioCodec audioCodec; diff --git a/jni/redphone/WebRtcJitterBuffer.cpp b/jni/redphone/WebRtcJitterBuffer.cpp index 4b1b25075b..da032932c8 100644 --- a/jni/redphone/WebRtcJitterBuffer.cpp +++ b/jni/redphone/WebRtcJitterBuffer.cpp @@ -1,4 +1,5 @@ #include "WebRtcJitterBuffer.h" +#include #define TAG "WebRtcJitterBuffer" @@ -14,7 +15,9 @@ int WebRtcJitterBuffer::init() { webrtc::NetEq::Config config; config.sample_rate_hz = 8000; + pthread_mutex_lock(&lock); neteq = webrtc::NetEq::Create(config); + pthread_mutex_unlock(&lock); if (neteq == NULL) { __android_log_print(ANDROID_LOG_WARN, TAG, "Failed to construct NetEq!"); @@ -26,8 +29,7 @@ int WebRtcJitterBuffer::init() { return -1; } - pthread_t thread; - pthread_create(&thread, NULL, &WebRtcJitterBuffer::collectStats, this); + pthread_create(&stats, NULL, &WebRtcJitterBuffer::collectStats, this); return 0; } @@ -65,13 +67,21 @@ int WebRtcJitterBuffer::getAudio(short *rawData, int maxRawData) { } void WebRtcJitterBuffer::stop() { + pthread_mutex_lock(&lock); running = 0; + pthread_cond_signal(&condition); + pthread_mutex_unlock(&lock); + + pthread_join(stats, NULL); } void WebRtcJitterBuffer::collectStats() { while (running) { webrtc::NetEqNetworkStatistics stats; + + pthread_mutex_lock(&lock); neteq->NetworkStatistics(&stats); + pthread_mutex_unlock(&lock); __android_log_print(ANDROID_LOG_WARN, "WebRtcJitterBuffer", "Jitter Stats:\n{\n" \ @@ -96,7 +106,22 @@ void WebRtcJitterBuffer::collectStats() { stats.accelerate_rate, stats.clockdrift_ppm, stats.added_zero_samples); - sleep(30); + + struct timespec timeToWait; + struct timeval now; + gettimeofday(&now, NULL); + + timeToWait.tv_sec = now.tv_sec; + timeToWait.tv_nsec = now.tv_usec * 1000; + timeToWait.tv_sec += 30; + + pthread_mutex_lock(&lock); + + if (running) { + pthread_cond_timedwait(&condition, &lock, &timeToWait); + } + + pthread_mutex_unlock(&lock); } } diff --git a/jni/redphone/WebRtcJitterBuffer.h b/jni/redphone/WebRtcJitterBuffer.h index 016704b559..bd93afa668 100644 --- a/jni/redphone/WebRtcJitterBuffer.h +++ b/jni/redphone/WebRtcJitterBuffer.h @@ -18,6 +18,10 @@ private: webrtc::NetEq *neteq; WebRtcCodec webRtcCodec; + pthread_t stats; + pthread_mutex_t lock; + pthread_cond_t condition; + public: WebRtcJitterBuffer(AudioCodec &codec); ~WebRtcJitterBuffer(); diff --git a/libs/armeabi-v7a/libredphone-audio.so b/libs/armeabi-v7a/libredphone-audio.so index ab1af886a6..70e1be6dce 100755 Binary files a/libs/armeabi-v7a/libredphone-audio.so and b/libs/armeabi-v7a/libredphone-audio.so differ diff --git a/libs/armeabi/libredphone-audio.so b/libs/armeabi/libredphone-audio.so index 4e24996bbe..7d4225f470 100755 Binary files a/libs/armeabi/libredphone-audio.so and b/libs/armeabi/libredphone-audio.so differ diff --git a/libs/x86/libredphone-audio.so b/libs/x86/libredphone-audio.so index bb21cd2baf..6eb6a04e1b 100755 Binary files a/libs/x86/libredphone-audio.so and b/libs/x86/libredphone-audio.so differ