Quiesce Android capture before detaching PCM and consume PM cache files

This commit is contained in:
evgeny committed 2026-10-01 18:41:17 +03:00
1 parent 79f0f2a07f
commit 72233d2365
2 files changed
+10 -10

No files matched your search

@@ -75,13 +75,14 @@ class AudioRecorderManager {
isRecording = true
LogManager.addLog("INFO", "AudioRecorder", "started ch=$channelId bufferSize=$bufferSize")
audioRecord?.startRecording()
val device = audioRecord ?: return false
recordingThread = Thread {
val buffer = ShortArray(FRAME_SAMPLES)
var totalRead = 0L
while (isRecording && audioRecord?.recordingState == AudioRecord.RECORDSTATE_RECORDING) {
val read = audioRecord?.read(buffer, 0, FRAME_SAMPLES) ?: break
while (isRecording && device.recordingState == AudioRecord.RECORDSTATE_RECORDING) {
val read = device.read(buffer, 0, FRAME_SAMPLES)
if (read <= 0) break
NativeLib.voiceFeed(buffer.copyOf(read))
totalRead += read
@@ -99,13 +100,12 @@ class AudioRecorderManager {
if (!isRecording) return 0
isRecording = false
recordingThread?.join(1000)
recordingThread = null
audioRecord?.apply {
try { stop() } catch (_: Exception) {}
release()
}
recordingThread?.join()
recordingThread = null
audioRecord?.release()
audioRecord = null
val duration = NativeLib.voiceStop()
@@ -117,13 +117,12 @@ class AudioRecorderManager {
if (!isRecording) return
isRecording = false
recordingThread?.join(1000)
recordingThread = null
audioRecord?.apply {
try { stop() } catch (_: Exception) {}
release()
}
recordingThread?.join()
recordingThread = null
audioRecord?.release()
audioRecord = null
NativeLib.voiceCancel()