// ----------------------------------------------------------------------------
-static void
+static int
android_media_AudioRecord_start(JNIEnv *env, jobject thiz)
{
AudioRecord *lpRecorder =
(AudioRecord *)env->GetIntField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
if (lpRecorder == NULL ) {
jniThrowException(env, "java/lang/IllegalStateException", NULL);
- return;
+ return AUDIORECORD_ERROR;
}
- lpRecorder->start();
+ return android_media_translateRecorderErrorCode(lpRecorder->start());
}
// ----------------------------------------------------------------------------
static JNINativeMethod gMethods[] = {
// name, signature, funcPtr
- {"native_start", "()V", (void *)android_media_AudioRecord_start},
+ {"native_start", "()I", (void *)android_media_AudioRecord_start},
{"native_stop", "()V", (void *)android_media_AudioRecord_stop},
{"native_setup", "(Ljava/lang/Object;IIIII)I",
(void *)android_media_AudioRecord_setup},
}
if (mActiveTrack != 0) {
if (mActiveTrack->mState == TrackBase::PAUSING) {
+ if (!mStandby) {
+ mInput->standby();
+ mStandby = true;
+ }
mActiveTrack.clear();
mStartStopCond.broadcast();
} else if (mActiveTrack->mState == TrackBase::RESUMING) {
- mRsmpInIndex = mFrameCount;
if (mReqChannelCount != mActiveTrack->channelCount()) {
mActiveTrack.clear();
- } else {
- mActiveTrack->mState = TrackBase::ACTIVE;
+ mStartStopCond.broadcast();
+ } else if (mBytesRead != 0) {
+ // record start succeeds only if first read from audio input
+ // succeeds
+ if (mBytesRead > 0) {
+ mActiveTrack->mState = TrackBase::ACTIVE;
+ } else {
+ mActiveTrack.clear();
+ }
+ mStartStopCond.broadcast();
}
- mStartStopCond.broadcast();
+ mStandby = false;
}
- mStandby = false;
}
}
if (mActiveTrack != 0) {
- if (mActiveTrack->mState != TrackBase::ACTIVE) {
+ if (mActiveTrack->mState != TrackBase::ACTIVE &&
+ mActiveTrack->mState != TrackBase::RESUMING) {
usleep(5000);
continue;
}
}
}
if (framesOut && mFrameCount == mRsmpInIndex) {
- ssize_t bytesRead;
if (framesOut == mFrameCount &&
(mChannelCount == mReqChannelCount || mFormat != AudioSystem::PCM_16_BIT)) {
- bytesRead = mInput->read(buffer.raw, mInputBytes);
+ mBytesRead = mInput->read(buffer.raw, mInputBytes);
framesOut = 0;
} else {
- bytesRead = mInput->read(mRsmpInBuffer, mInputBytes);
+ mBytesRead = mInput->read(mRsmpInBuffer, mInputBytes);
mRsmpInIndex = 0;
}
- if (bytesRead < 0) {
+ if (mBytesRead < 0) {
LOGE("Error reading audio input");
- sleep(1);
+ if (mActiveTrack->mState == TrackBase::ACTIVE) {
+ sleep(1);
+ }
mRsmpInIndex = mFrameCount;
framesOut = 0;
buffer.frameCount = 0;
if (recordTrack != mActiveTrack.get()) {
status = -EBUSY;
} else if (mActiveTrack->mState == TrackBase::PAUSING) {
- mActiveTrack->mState = TrackBase::RESUMING;
+ mActiveTrack->mState = TrackBase::ACTIVE;
}
return status;
}
return status;
}
mActiveTrack->mState = TrackBase::RESUMING;
+ mRsmpInIndex = mFrameCount;
+ mBytesRead = 0;
// signal thread to start
LOGV("Signal record thread");
mWaitWorkCV.signal();
mLock.unlock();
AudioSystem::stopInput(mId);
mLock.lock();
+ LOGV("Record stopped OK");
}
}
}
int channelCount;
if (framesReady == 0) {
- ssize_t bytesRead = mInput->read(mRsmpInBuffer, mInputBytes);
- if (bytesRead < 0) {
+ mBytesRead = mInput->read(mRsmpInBuffer, mInputBytes);
+ if (mBytesRead < 0) {
LOGE("RecordThread::getNextBuffer() Error reading audio input");
- sleep(1);
+ if (mActiveTrack->mState == TrackBase::ACTIVE) {
+ sleep(1);
+ }
buffer->raw = 0;
buffer->frameCount = 0;
return NOT_ENOUGH_DATA;
if (pFormat) *pFormat = format;
if (pChannels) *pChannels = channels;
if (pLatencyMs) *pLatencyMs = thread->latency();
+
+ return mNextThreadId;
}
- return mNextThreadId;
+ return 0;
}
int AudioFlinger::openDuplicateOutput(int output1, int output2)
if (pChannels) *pChannels = reqChannels;
input->standby();
+
+ return mNextThreadId;
}
- return mNextThreadId;
+ return 0;
}
status_t AudioFlinger::closeInput(int input)