am f6936a3a: Merge "RTP: prevent buffer overflow in AudioRecord." into gingerbread

Merge commit 'f6936a3a52b6bb6de27f75d4e38d116e896b7f4d' into gingerbread-plus-aosp

* commit 'f6936a3a52b6bb6de27f75d4e38d116e896b7f4d':
  RTP: prevent buffer overflow in AudioRecord.
This commit is contained in:
Chia-chi Yeh
2010-09-09 02:39:58 -07:00
committed by Android Git Automerger

View File

@@ -588,7 +588,7 @@ bool AudioGroup::set(int sampleRate, int sampleCount)
// Give device socket a reasonable timeout and buffer size. // Give device socket a reasonable timeout and buffer size.
timeval tv; timeval tv;
tv.tv_sec = 0; 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)) || if (setsockopt(pair[0], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) ||
setsockopt(pair[0], SOL_SOCKET, SO_RCVBUF, &output, sizeof(output)) || setsockopt(pair[0], SOL_SOCKET, SO_RCVBUF, &output, sizeof(output)) ||
setsockopt(pair[1], SOL_SOCKET, SO_SNDBUF, &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); status_t status = mRecord.obtainBuffer(&buffer, 1);
if (status == NO_ERROR) { if (status == NO_ERROR) {
int count = (buffer.frameCount < toRead) ? int count = ((int)buffer.frameCount < toRead) ?
buffer.frameCount : toRead; buffer.frameCount : toRead;
memcpy(&input[mSampleCount - toRead], buffer.i8, count * 2); memcpy(&input[mSampleCount - toRead], buffer.i8, count * 2);
toRead -= count; toRead -= count;