From 557b04de23238fb496b5ca58e21331c842e95660 Mon Sep 17 00:00:00 2001 From: Chia-chi Yeh Date: Wed, 8 Sep 2010 09:56:02 +0800 Subject: [PATCH] RTP: prevent buffer overflow in AudioRecord. This change simply reduces the receive timeout of DeviceSocket. It works because AudioRecord will block us till there is enough data, which makes AudioSocket overlap AudioRecord. Change-Id: I4700224fb407e148ef359a9d99279e10240128d0 --- voip/jni/rtp/AudioGroup.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/voip/jni/rtp/AudioGroup.cpp b/voip/jni/rtp/AudioGroup.cpp index bb45a9ac7a38e..3433dcf44f7a7 100644 --- a/voip/jni/rtp/AudioGroup.cpp +++ b/voip/jni/rtp/AudioGroup.cpp @@ -588,7 +588,7 @@ bool AudioGroup::set(int sampleRate, int sampleCount) // Give device socket a reasonable timeout and buffer size. timeval tv; tv.tv_sec = 0; - tv.tv_usec = 1000 * sampleCount / sampleRate * 1000; + tv.tv_usec = 1000 * sampleCount / sampleRate * 500; if (setsockopt(pair[0], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) || setsockopt(pair[0], SOL_SOCKET, SO_RCVBUF, &output, sizeof(output)) || setsockopt(pair[1], SOL_SOCKET, SO_SNDBUF, &output, sizeof(output))) { @@ -793,7 +793,7 @@ bool AudioGroup::deviceLoop() status_t status = mRecord.obtainBuffer(&buffer, 1); if (status == NO_ERROR) { - int count = (buffer.frameCount < toRead) ? + int count = ((int)buffer.frameCount < toRead) ? buffer.frameCount : toRead; memcpy(&input[mSampleCount - toRead], buffer.i8, count * 2); toRead -= count;