fix(qt): release audio at quit and fence late playback
Request output release with the first quit watchdog arm, independently of network teardown. Permanently reject late playback/reinit commands, interrupt abandoned feeders, and await release acknowledgement. Restore the owner queue at Connect shutdown without scheduling playback. cx
This commit is contained in:
4 files changed
+62
-8
No files matched your search
@@ -3824,6 +3824,9 @@ fn apply_interface_scale_preference() {
|
||||
|
||||
// ============================ Shutdown guarantee ==========================
|
||||
|
||||
static OUTPUT_RELEASE_TASK: std::sync::Mutex<Option<std::thread::JoinHandle<Result<(), String>>>> =
|
||||
std::sync::Mutex::new(None);
|
||||
|
||||
/// One-shot latch for [`arm_hard_exit_watchdog`].
|
||||
static HARD_EXIT_ARMED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
|
||||
@@ -3883,6 +3886,14 @@ pub(crate) fn arm_hard_exit_watchdog(source: &'static str) {
|
||||
// see the header above.
|
||||
unsafe { libc::_exit(0) };
|
||||
});
|
||||
// Send release at the first quit request, even if Qt never exits its loop.
|
||||
// The terminal player fence also rejects late Connect/Cast continuations.
|
||||
if let Some(runtime) = APP.get() {
|
||||
let player = runtime.core().player();
|
||||
player.begin_shutdown();
|
||||
playback_qt::cancel_owner_playback_tasks();
|
||||
*OUTPUT_RELEASE_TASK.lock().unwrap() = Some(std::thread::spawn(move || player.release_device()));
|
||||
}
|
||||
}
|
||||
|
||||
/// Is THIS process one of the internal, disposable child processes that
|
||||
@@ -4255,7 +4266,7 @@ fn main() {
|
||||
};
|
||||
match tokio::time::timeout(
|
||||
std::time::Duration::from_secs(3),
|
||||
service.disconnect(),
|
||||
service.disconnect_for_shutdown(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -4305,6 +4316,14 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(task) = OUTPUT_RELEASE_TASK.lock().unwrap().take() {
|
||||
match task.join() {
|
||||
Ok(Ok(())) => log::info!("[shutdown] output-device release acknowledged"),
|
||||
Ok(Err(error)) => log::error!("[shutdown] output-device release failed: {error}"),
|
||||
Err(_) => log::error!("[shutdown] output-device release task panicked"),
|
||||
}
|
||||
}
|
||||
|
||||
// Final full snapshot. QConnect teardown MUST precede this write: a
|
||||
// delegated queue is ephemeral and may never become the owner's saved
|
||||
// session. If bounded teardown failed, preserving the previous saved
|
||||
|
||||
@@ -51,7 +51,7 @@ type Runtime = Arc<AppRuntime<LoggingAdapter>>;
|
||||
pub type QtDelegationCoordinator = DelegationCoordinator<QtDelegationHost>;
|
||||
|
||||
const SHUTDOWN_RESTORE_OWNER: u8 = 0;
|
||||
const SHUTDOWN_DISCARD_OWNER: u8 = 1;
|
||||
const SHUTDOWN_RESTORE_QUEUE_ONLY: u8 = 1;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct OwnerSnapshot {
|
||||
@@ -277,7 +277,7 @@ impl QtDelegationHost {
|
||||
if restore {
|
||||
SHUTDOWN_RESTORE_OWNER
|
||||
} else {
|
||||
SHUTDOWN_DISCARD_OWNER
|
||||
SHUTDOWN_RESTORE_QUEUE_ONLY
|
||||
},
|
||||
Ordering::Release,
|
||||
);
|
||||
@@ -874,8 +874,10 @@ impl DelegationHost for QtDelegationHost {
|
||||
{
|
||||
self.restore_owner_snapshot().await
|
||||
} else if was_delegated || has_owner_snapshot {
|
||||
// Process exit still restores the owner's queue for persistence,
|
||||
// but must never schedule audible playback or reopen the DAC.
|
||||
let _ = self.runtime.core().stop();
|
||||
recover_lock(&self.owner_snapshot).take();
|
||||
let _ = self.restore_owner_snapshot().await;
|
||||
None
|
||||
} else {
|
||||
// A pending candidate may have captured a snapshot, but disabling an
|
||||
|
||||
@@ -2597,6 +2597,11 @@ impl QtQconnectService {
|
||||
self.disconnect_safely().await.map(|_| ())
|
||||
}
|
||||
|
||||
/// Process exit restores ownership bookkeeping, never audible playback.
|
||||
pub async fn disconnect_for_shutdown(&self) -> Result<(), String> {
|
||||
self.disconnect_with_owner_policy(false).await.map(|_| ())
|
||||
}
|
||||
|
||||
pub async fn disconnect_safely(&self) -> Result<QconnectDisconnectOutcome, String> {
|
||||
self.disconnect_with_owner_policy(true).await
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user