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 39e3234808
commit 13704b4f53
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()
@@ -671,6 +671,7 @@ void utun_bridge_dm_send_file(const char* conv_id, const char* path, const char*
snprintf(req->conv, sizeof(req->conv), "%s", conv_id);
snprintf(req->path, sizeof(req->path), "%s", path);
req->info.kind = ATTACHMENT_FILE;
req->remove_source = 1; /* PM picker передаёт собственный уникальный cache-файл. */
snprintf(req->info.name, sizeof(req->info.name), "%s", name);
uasync_post(ua, dm_send_file_trampoline, req);
}