Repository navigation
Conversation
… macOS Shared QAudioOutput was created once and reused across QMediaPlayer instances. On macOS/AVFoundation, deleteLater() leaves the old player alive long enough that the new player cannot claim the same audio output, so nothing plays. Fix by creating QAudioOutput as a child of each new QMediaPlayer so it is always fresh and auto-deleted with the player. Also fixes a memory leak: the old audioOutput had no parent and was never deleted. Fixes EdgeTX#7354 Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…utput readiness PR EdgeTX#7516 fixes silent playback on macOS by creating a fresh QAudioOutput per playback instead of reusing one across QMediaPlayer instances. That removes the stale-output issue, but the newly created output may not be immediately ready when play() is called, which can clip the very start of the sound. Poll QMediaPlayer::isAvailable() briefly before starting playback to give the backend a chance to finish attaching.
isAvailable() only reports whether a platform media backend exists at all, not whether this specific source's playback pipeline (and its audio output) has actually finished attaching, so polling it is unlikely to catch the same readiness gap responsible for a clipped start of the previewed sound. Wait for QMediaPlayer::mediaStatus() to reach LoadedMedia before calling play() instead, which reflects source-specific readiness. Kept as a separate commit (rather than amending) so CI results for both approaches remain comparable side by side.
…d preview Neither polling isAvailable() nor waiting for LoadedMedia fixed the clipped start of playback on macOS (~0.5s of audio missing). New data point: playing a track again quickly after the first play produces the full, unclipped audio. That points to a device/route warm-up cost on macOS (CoreAudio/AVFoundation) rather than a Qt-level readiness race: the audio hardware route takes time to open when it has been idle, but reopening shortly after a previous playback reuses the still-warm route. Recreating a new QMediaPlayer + QAudioOutput on every playSound() call (per EdgeTX#7516) forces that route to be closed and reopened every single time, so every preview after any idle gap pays the opening cost and loses its lead-in. Instead, create the QMediaPlayer and its QAudioOutput once, in the constructor, and reuse them for every playSound() call (just swapping the source and calling play() again). This keeps the underlying audio route continuously open for the life of the panel, so only the very first playback (if any) should pay the warm-up cost, not every one of them. Since there is now only ever one QMediaPlayer instance, the signal connections move to the constructor (made once) instead of being redone per playback, and stopSound() no longer needs to disconnect/deleteLater/recreate anything. This also sidesteps the original EdgeTX#7354 failure mode a different way: that bug came from a *new* QMediaPlayer racing to claim a *shared* QAudioOutput while the *previous* QMediaPlayer was still alive pending deleteLater(). With a single long-lived player/output pair there is never a second instance to race against.
…ay cost The persistent QMediaPlayer/QAudioOutput (previous commit) means only the very first preview after opening the panel should pay the audio route warm-up cost, but that first click would still clip. Since the panel takes some time to build its UI after construction, pay that cost during construction instead: do a silent (volume 0), throwaway play of a bundled sound immediately, then stop it and restore the volume shortly after. By the time the user reaches the tab and clicks play, the audio route should already be warm. The playbackStateChanged/errorOccurred handlers are guarded against this warm-up so it doesn't affect the play-button UI state or trigger the "unable to play" error dialog.
New data: with the persistent QMediaPlayer/QAudioOutput from the previous commit, playback still clips after only a couple of seconds idle between plays. That rules out "keep the C++ objects alive" as a fix on its own -- the underlying macOS audio route appears to go cold within a couple of seconds regardless of whether the Qt objects are recreated or reused, and a one-time warm-up when the panel opens (previous commit) is very unlikely to survive that long either. This is a deliberately blunt experiment to isolate the variable: delay every real play() call (not just the first) by a fixed 700ms after setSource(), using a request-id token so a stale delayed play() from a superseded or stopped request doesn't fire. If this alone eliminates the clipping regardless of how much idle time preceded it, that tells us it's purely an elapsed-time cost and not something tied to the specific decode pipeline/content, which would point toward either living with the added latency or (more likely) injecting real silence into the audio content itself so the loss lands on the silence instead of on the real audio.
Owner
Author
|
Closing this experimental branch. Summary of findings while testing on macOS:
Known issue, not pursuing further here. |
pfeerick
added a commit
that referenced
this pull request
Nov 21, 2026
Reverts d20e431. EdgeTX/rs-dfu#23 adds synchronization to the Windows system libs in rs_dfu-config.cmake, so the Companion-side workaround is no longer needed, and leaving it out lets a green Windows link verify #23. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Draft
9 of 10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on top of upstream PR EdgeTX#7516 (fixes EdgeTX#7354 — silent audio preview on macOS by creating a fresh
QAudioOutputper playback instead of reusing a shared one).That fix trades the "stale shared output blocks playback" bug for a possible new one: a freshly constructed
QAudioOutputisn't guaranteed to be immediately ready whenplay()is called, which could clip the very start of the previewed sound (a "cold start" glitch), especially on backends like macOS/AVFoundation where attaching to the audio session isn't necessarily synchronous.This commit adds a
playWhenAvailable()helper that pollsQMediaPlayer::isAvailable()for up to ~200ms (10 x 20ms) before callingplay(), falling back to playing immediately/after the last attempt regardless.For testing: this is meant to validate whether
isAvailable()is sufficient to fix the clipped-start symptom before proposing anything upstream. If it doesn't fully resolve it, the next things to try would be waiting onQMediaPlayer::mediaStatusChangedreachingLoadedMedia/BufferedMediainstead, sinceisAvailable()only reports whether the platform backend exists, not whether the audio pipeline has actually finished attaching.