Test shared microphone lifecycle and stream priority

This commit is contained in:
evgeny committed 2026-10-16 01:06:59 +02:00
1 parent 95942382bc
commit d4eb1da233
3 files changed
+63 -10

No files matched your search

+7 -7
View File
@@ -15,7 +15,7 @@ struct AudioCapture::Session {
};
AudioDevice device;
QString key;
std::array<Slot, 2> slots;
std::array<Slot, 2> consumers;
bool streamProfile = false;
int requestedChannels = 1, channels = 1;
uint64_t tag = 0;
@@ -36,12 +36,12 @@ struct AudioCapture::Session {
}
void stop() {
device.close(); // join до stopped: workers больше не получат PCM старого формата.
for (auto& slot : slots) if (slot.client) detach(slot);
for (auto& slot : consumers) if (slot.client) detach(slot);
}
void prepare() {
if (clock.elapsed() < prepareAt) return;
prepareAt = clock.elapsed() + 250;
for (auto& slot : slots) {
for (auto& slot : consumers) {
auto* client = slot.client;
if (!client || client->m_prepared) continue;
if (!client->m_ready(channels, device.device()->capture.internalChannels)) {
@@ -75,7 +75,7 @@ struct AudioCapture::Session {
Frame frame{static_cast<const int16_t*>(in), frames, channels, device.callbackTimeUs(),
device.route(), device.timingMeasured(), device.captureMissing()};
// Трансляция получает исходный PCM первой; оба callback только копируют данные в свои очереди.
for (auto& slot : slots) {
for (auto& slot : consumers) {
slot.readers.fetch_add(1);
if (auto* client = slot.active.load()) client->m_callback(frame);
slot.readers.fetch_sub(1);
@@ -112,7 +112,7 @@ bool AudioCapture::open(const QString& input, Role role, int channels, uint64_t
}
if (!m_session) { m_session = std::make_shared<Session>(key); sessions.push_back(m_session); }
auto& session = *m_session;
auto& slot = session.slots[role == Role::Stream ? 0 : 1];
auto& slot = session.consumers[role == Role::Stream ? 0 : 1];
if (slot.client) {
DEBUG_ERROR(DEBUG_CATEGORY_CALL, "capture: duplicate consumer role=%s", role == Role::Stream ? "stream" : "radio");
m_session.reset(); return false;
@@ -131,10 +131,10 @@ bool AudioCapture::open(const QString& input, Role role, int channels, uint64_t
void AudioCapture::close() {
if (!m_session) return;
auto& slot = m_session->slots[m_role == Role::Stream ? 0 : 1];
auto& slot = m_session->consumers[m_role == Role::Stream ? 0 : 1];
m_session->detach(slot); slot.client = nullptr;
DEBUG_INFO(DEBUG_CATEGORY_CALL, "capture: detached role=%s remaining=%d", m_role == Role::Stream ? "stream" : "radio",
int(m_session->slots[0].client != nullptr) + int(m_session->slots[1].client != nullptr));
int(m_session->consumers[0].client != nullptr) + int(m_session->consumers[1].client != nullptr));
m_session.reset(); m_callback = {}; m_ready = {}; m_stopped = {};
}