summaryrefslogtreecommitdiffstats
path: root/voip/jni
diff options
context:
space:
mode:
authorChia-chi Yeh <chiachi@android.com>2010-10-01 08:20:09 +0800
committerChia-chi Yeh <chiachi@android.com>2010-10-01 08:20:09 +0800
commit67ecb5b90c7d944a485ed35f3e968ab0ae49f5b4 (patch)
tree8165ca3e765085e550cb165c3680f3dbe790eb12 /voip/jni
parent20cb2310cffb787c54016d50b9b5fe320fc5b025 (diff)
downloadframeworks_base-67ecb5b90c7d944a485ed35f3e968ab0ae49f5b4.zip
frameworks_base-67ecb5b90c7d944a485ed35f3e968ab0ae49f5b4.tar.gz
frameworks_base-67ecb5b90c7d944a485ed35f3e968ab0ae49f5b4.tar.bz2
RTP: Start AudioRecord before AudioTrack to avoid being disabled.
Change-Id: I96be89fda41d77e2cf5bfc1c2f14e2b109001b57
Diffstat (limited to 'voip/jni')
-rw-r--r--voip/jni/rtp/AudioGroup.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/voip/jni/rtp/AudioGroup.cpp b/voip/jni/rtp/AudioGroup.cpp
index a953d38..5214518 100644
--- a/voip/jni/rtp/AudioGroup.cpp
+++ b/voip/jni/rtp/AudioGroup.cpp
@@ -776,11 +776,14 @@ bool AudioGroup::DeviceThread::threadLoop()
char c;
while (recv(deviceSocket, &c, 1, MSG_DONTWAIT) == 1);
- // Start your engine!
- track.start();
+ // Start AudioRecord before AudioTrack. This prevents AudioTrack from being
+ // disabled due to buffer underrun while waiting for AudioRecord.
if (mode != MUTED) {
record.start();
+ int16_t one;
+ record.read(&one, sizeof(one));
}
+ track.start();
while (!exitPending()) {
int16_t output[sampleCount];
@@ -806,34 +809,30 @@ bool AudioGroup::DeviceThread::threadLoop()
track.releaseBuffer(&buffer);
} else if (status != TIMED_OUT && status != WOULD_BLOCK) {
LOGE("cannot write to AudioTrack");
- break;
+ return true;
}
}
if (toRead > 0) {
AudioRecord::Buffer buffer;
- buffer.frameCount = record.frameCount();
+ buffer.frameCount = toRead;
status_t status = record.obtainBuffer(&buffer, 1);
if (status == NO_ERROR) {
- int count = ((int)buffer.frameCount < toRead) ?
- buffer.frameCount : toRead;
- memcpy(&input[sampleCount - toRead], buffer.i8, count * 2);
- toRead -= count;
- if (buffer.frameCount < record.frameCount()) {
- buffer.frameCount = count;
- }
+ int offset = sampleCount - toRead;
+ memcpy(&input[offset], buffer.i8, buffer.size);
+ toRead -= buffer.frameCount;
record.releaseBuffer(&buffer);
} else if (status != TIMED_OUT && status != WOULD_BLOCK) {
LOGE("cannot read from AudioRecord");
- break;
+ return true;
}
}
}
if (chances <= 0) {
- LOGE("device loop timeout");
- break;
+ LOGW("device loop timeout");
+ while (recv(deviceSocket, &c, 1, MSG_DONTWAIT) == 1);
}
if (mode != MUTED) {