Keep voice recording from opening an already owned microphone

This commit is contained in:
evgeny committed 2026-10-14 02:54:30 +02:00
1 parent b3c698be25
commit ce46677dfb
2 files changed
+6 -2

No files matched your search

+4 -2
View File
@@ -114,13 +114,14 @@ void AudioRecorder::shutdown() {
void AudioRecorder::startRecording(bool meterOnly) {
if (m_recording) return;
if (!m_initialized) { DEBUG_ERROR(DEBUG_CATEGORY_CALL, "recorder: not initialized"); return; }
if (!m_microphone.acquire()) { DEBUG_WARN(DEBUG_CATEGORY_CALL, "recorder: microphone owned by another operation"); return; }
m_pcmBuffer.clear(); m_meterOnly = meterOnly;
m_captureQueue.reset(); m_captureFailed = false;
m_recordedFrames = 0; m_elapsedMs = 0; m_peakLevel = 0;
m_captureCompressorEnabled = !meterOnly && m_compressorEnabled;
if (m_compressor) {
if (audio_compressor_configure(m_compressor, &m_compressorConfig) != 0) {
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "recorder: cannot configure compressor"); return;
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "recorder: cannot configure compressor"); m_microphone.release(); return;
}
audio_compressor_set_enabled(m_compressor, m_captureCompressorEnabled);
audio_compressor_reset(m_compressor);
@@ -129,7 +130,7 @@ void AudioRecorder::startRecording(bool meterOnly) {
try { m_recordWorker = std::thread(&AudioRecorder::recordLoop, this); }
catch (const std::system_error& error) {
m_workerRunning = false;
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "recorder: worker start failed reason=%s", error.what()); return;
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "recorder: worker start failed reason=%s", error.what()); m_microphone.release(); return;
}
m_recording = true;
m_capture.retryNow();
@@ -173,6 +174,7 @@ void AudioRecorder::stopRecording() {
m_capture.close();
m_workerRunning = false; m_wake.notify_one();
if (m_recordWorker.joinable()) m_recordWorker.join();
m_microphone.release();
m_elapsedMs = (int)(m_recordedFrames.load() * 1000 / m_sampleRate);
int duration = m_elapsedMs;
size_t samples = m_compressor && m_captureCompressorEnabled ? audio_compressor_output_size(m_compressor) : m_pcmBuffer.size();