am 274e3b5d: Merge "RTP: Start AudioRecord before AudioTrack to avoid being disabled." into gingerbread

Merge commit '274e3b5d752d1a4fd05352e50ad098d2f5b49a36' into gingerbread-plus-aosp

* commit '274e3b5d752d1a4fd05352e50ad098d2f5b49a36':
  RTP: Start AudioRecord before AudioTrack to avoid being disabled.
This commit is contained in:
Chia-chi Yeh
2010-09-30 18:02:38 -07:00
committed by Android Git Automerger

View File

@@ -776,11 +776,14 @@ bool AudioGroup::DeviceThread::threadLoop()
char c; char c;
while (recv(deviceSocket, &c, 1, MSG_DONTWAIT) == 1); while (recv(deviceSocket, &c, 1, MSG_DONTWAIT) == 1);
// Start your engine! // Start AudioRecord before AudioTrack. This prevents AudioTrack from being
track.start(); // disabled due to buffer underrun while waiting for AudioRecord.
if (mode != MUTED) { if (mode != MUTED) {
record.start(); record.start();
int16_t one;
record.read(&one, sizeof(one));
} }
track.start();
while (!exitPending()) { while (!exitPending()) {
int16_t output[sampleCount]; int16_t output[sampleCount];
@@ -806,34 +809,30 @@ bool AudioGroup::DeviceThread::threadLoop()
track.releaseBuffer(&buffer); track.releaseBuffer(&buffer);
} else if (status != TIMED_OUT && status != WOULD_BLOCK) { } else if (status != TIMED_OUT && status != WOULD_BLOCK) {
LOGE("cannot write to AudioTrack"); LOGE("cannot write to AudioTrack");
break; return true;
} }
} }
if (toRead > 0) { if (toRead > 0) {
AudioRecord::Buffer buffer; AudioRecord::Buffer buffer;
buffer.frameCount = record.frameCount(); buffer.frameCount = toRead;
status_t status = record.obtainBuffer(&buffer, 1); status_t status = record.obtainBuffer(&buffer, 1);
if (status == NO_ERROR) { if (status == NO_ERROR) {
int count = ((int)buffer.frameCount < toRead) ? int offset = sampleCount - toRead;
buffer.frameCount : toRead; memcpy(&input[offset], buffer.i8, buffer.size);
memcpy(&input[sampleCount - toRead], buffer.i8, count * 2); toRead -= buffer.frameCount;
toRead -= count;
if (buffer.frameCount < record.frameCount()) {
buffer.frameCount = count;
}
record.releaseBuffer(&buffer); record.releaseBuffer(&buffer);
} else if (status != TIMED_OUT && status != WOULD_BLOCK) { } else if (status != TIMED_OUT && status != WOULD_BLOCK) {
LOGE("cannot read from AudioRecord"); LOGE("cannot read from AudioRecord");
break; return true;
} }
} }
} }
if (chances <= 0) { if (chances <= 0) {
LOGE("device loop timeout"); LOGW("device loop timeout");
break; while (recv(deviceSocket, &c, 1, MSG_DONTWAIT) == 1);
} }
if (mode != MUTED) { if (mode != MUTED) {