Adds timeout for audio record thread in Java layer
BUG=b/28448866 R=magjed@webrtc.org Review URL: https://codereview.webrtc.org/1933123002 . Cr-Commit-Position: refs/heads/master@{#12590}
This commit is contained in:
@ -21,6 +21,7 @@ import android.media.MediaRecorder.AudioSource;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
|
||||||
import org.webrtc.Logging;
|
import org.webrtc.Logging;
|
||||||
|
import org.webrtc.ThreadUtils;
|
||||||
|
|
||||||
public class WebRtcAudioRecord {
|
public class WebRtcAudioRecord {
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
@ -42,6 +43,10 @@ public class WebRtcAudioRecord {
|
|||||||
// high load.
|
// high load.
|
||||||
private static final int BUFFER_SIZE_FACTOR = 2;
|
private static final int BUFFER_SIZE_FACTOR = 2;
|
||||||
|
|
||||||
|
// The AudioRecordJavaThread is allowed to wait for successful call to join()
|
||||||
|
// but the wait times out afther this amount of time.
|
||||||
|
private static final long AUDIO_RECORD_THREAD_JOIN_TIMEOUT_MS = 2000;
|
||||||
|
|
||||||
private final long nativeAudioRecord;
|
private final long nativeAudioRecord;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
@ -106,15 +111,11 @@ public class WebRtcAudioRecord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void joinThread() {
|
// Stops the inner thread loop and also calls AudioRecord.stop().
|
||||||
|
// Does not block the calling thread.
|
||||||
|
public void stopThread() {
|
||||||
|
Logging.d(TAG, "stopThread");
|
||||||
keepAlive = false;
|
keepAlive = false;
|
||||||
while (isAlive()) {
|
|
||||||
try {
|
|
||||||
join();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// Ignore.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +258,11 @@ public class WebRtcAudioRecord {
|
|||||||
private boolean stopRecording() {
|
private boolean stopRecording() {
|
||||||
Logging.d(TAG, "stopRecording");
|
Logging.d(TAG, "stopRecording");
|
||||||
assertTrue(audioThread != null);
|
assertTrue(audioThread != null);
|
||||||
audioThread.joinThread();
|
audioThread.stopThread();
|
||||||
|
if (!ThreadUtils.joinUninterruptibly(
|
||||||
|
audioThread, AUDIO_RECORD_THREAD_JOIN_TIMEOUT_MS)) {
|
||||||
|
Logging.e(TAG, "Join of AudioRecordJavaThread timed out");
|
||||||
|
}
|
||||||
audioThread = null;
|
audioThread = null;
|
||||||
if (effects != null) {
|
if (effects != null) {
|
||||||
effects.release();
|
effects.release();
|
||||||
|
|||||||
Reference in New Issue
Block a user