Move Qt recording buffers to background preparation without copies
This commit is contained in:
1 parent
ba409427c6
commit
0d3f2952c1
2 files changed
+19
-2
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#include "audiorecorder.h"
|
||||
#include "media_async/attachment_send.h"
|
||||
#include "miniaudio.h"
|
||||
#include "sound_manager.h"
|
||||
|
||||
@@ -163,8 +164,6 @@ void AudioRecorder::stopRecording() {
|
||||
}
|
||||
m_recording = false;
|
||||
|
||||
if (m_compressor && m_compressorEnabled) audio_compressor_flush(m_compressor);
|
||||
|
||||
int duration = m_elapsedMs;
|
||||
size_t bufSize = (m_compressor && m_compressorEnabled) ? audio_compressor_output_size(m_compressor) : m_pcmBuffer.size();
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "recording stopped, duration=%dms, pcmSamples=%zu, compressor=%d",
|
||||
@@ -177,6 +176,22 @@ int AudioRecorder::durationMs() const {
|
||||
return m_elapsedMs;
|
||||
}
|
||||
|
||||
/* Worker получает владельца буфера; новая запись имеет отдельное состояние. */
|
||||
bool AudioRecorder::takeRecording(struct attachment_send_req* request) {
|
||||
if (!request || m_recording) { DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "recorder: cannot detach active recording"); return false; }
|
||||
if (m_compressor && m_compressorEnabled) {
|
||||
auto* replacement = audio_compressor_clone_config(m_compressor);
|
||||
if (!replacement) return false;
|
||||
request->compressor = m_compressor;
|
||||
m_compressor = replacement;
|
||||
} else {
|
||||
auto* samples = new std::vector<int16_t>(std::move(m_pcmBuffer));
|
||||
request->pcm = samples->data(); request->pcm_count = samples->size(); request->pcm_owner = samples;
|
||||
request->pcm_release = [](void* owner) { delete static_cast<std::vector<int16_t>*>(owner); };
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
float AudioRecorder::peakLevel() const {
|
||||
float v = m_peakLevel;
|
||||
m_peakLevel = 0.0f;
|
||||
|
||||
Reference in new issue
Block a user