Browse Source

Defer source failures and end calls that cannot reserve audio capture

master
evgeny 6 days ago
parent
commit
ce461521e4
  1. 16
      tools/chatgui/src/mainwindow.cpp
  2. 6
      tools/chatgui/src/stream_publish_engine.cpp

16
tools/chatgui/src/mainwindow.cpp

@ -619,7 +619,12 @@ void MainWindow::setupBridgeCallbacks() {
void MainWindow::setupConnects() {
connect(m_messageList, &MessageList::streamPublishRequested, this, [this](quint64 group) {
if (!m_streamPublisher) m_streamPublisher = new StreamPublishEngine(this);
if (!m_streamPublisher) {
m_streamPublisher = new StreamPublishEngine(this);
connect(m_streamPublisher, &StreamPublishEngine::stateChanged, this, [this](const QString& state) {
if (m_trayIcon) m_trayIcon->setToolTip(m_streamPublisher->active() ? QStringLiteral("vibechat · ") + state : QStringLiteral("vibechat"));
});
}
if (m_streamPublishWindow) delete m_streamPublishWindow.data();
m_streamPublishWindow = new StreamPublishWindow(m_streamPublisher, m_streamPublisher->active() ? m_streamPublisher->group() : group, this);
m_streamPublishWindow->show(); m_streamPublishWindow->raise(); m_streamPublishWindow->activateWindow();
@ -772,7 +777,14 @@ void MainWindow::onCallAccepted(quint64 callId) {
CallWindow* w = m_activeCalls.value(callId, nullptr);
if (w) w->setState(CallWindow::Active);
if (!s_mainWindow) return;
CallAudioEngine::instance()->start(callId);
if (CallAudioEngine::instance()->start(callId) != 0) {
DEBUG_WARN(DEBUG_CATEGORY_CALL, "desktop call cannot acquire audio; hangup id=%llu", (unsigned long long)callId);
auto* request = static_cast<call_id_arg*>(u_malloc(sizeof(call_id_arg)));
if (request) { request->inst = gui_bridge_get_inst(); request->call_id = callId; gui_bridge_post_uasync_fn(call_hangup_trampoline, request); }
else DEBUG_ERROR(DEBUG_CATEGORY_CALL, "desktop failed call hangup allocation failed");
closeCallWindow(callId);
QMessageBox::information(this, QStringLiteral("vibechat"), QCoreApplication::translate("ChatGui", "The microphone is used by a call, radio or recording"));
}
}
void MainWindow::onCallEnded(quint64 callId, uint8_t reason) {

6
tools/chatgui/src/stream_publish_engine.cpp

@ -151,7 +151,7 @@ bool StreamPublishEngine::openSource(const StreamPublishConfig& config) {
}
if (best.isNull()) { DEBUG_ERROR(DEBUG_CATEGORY_VIDEO, "desktop camera lacks requested fps=%d", config.video.fps); return false; }
m->camera->setCameraFormat(best); m->session->setCamera(m->camera.get());
connect(m->camera.get(), &QCamera::errorOccurred, this, [failed](QCamera::Error, const QString& error) { failed(error); });
connect(m->camera.get(), &QCamera::errorOccurred, this, [failed](QCamera::Error, const QString& error) { failed(error); }, Qt::QueuedConnection);
m->camera->start();
} else if (config.source.kind == StreamVideoSource::Screen) {
m->screen = std::make_unique<QScreenCapture>();
@ -162,13 +162,13 @@ bool StreamPublishEngine::openSource(const StreamPublishConfig& config) {
m->screen->setScreen(selected);
}
m->session->setScreenCapture(m->screen.get());
connect(m->screen.get(), &QScreenCapture::errorOccurred, this, [failed](QScreenCapture::Error, const QString& error) { failed(error); });
connect(m->screen.get(), &QScreenCapture::errorOccurred, this, [failed](QScreenCapture::Error, const QString& error) { failed(error); }, Qt::QueuedConnection);
m->screen->start();
} else {
auto window = config.source.window.value<QCapturableWindow>();
if (!window.isValid()) { DEBUG_ERROR(DEBUG_CATEGORY_VIDEO, "desktop window is unavailable"); return false; }
m->window = std::make_unique<QWindowCapture>(); m->window->setWindow(window); m->session->setWindowCapture(m->window.get());
connect(m->window.get(), &QWindowCapture::errorOccurred, this, [failed](QWindowCapture::Error, const QString& error) { failed(error); });
connect(m->window.get(), &QWindowCapture::errorOccurred, this, [failed](QWindowCapture::Error, const QString& error) { failed(error); }, Qt::QueuedConnection);
m->window->start();
}
DEBUG_INFO(DEBUG_CATEGORY_VIDEO, "desktop capture started generation=%llu kind=%d source=%s target=%dx%d/%dfps",

Loading…
Cancel
Save