[inputstream.adaptive] Fix audio deadlock on quality STREAMCHANGE#1999
[inputstream.adaptive] Fix audio deadlock on quality STREAMCHANGE#1999CastagnaIT merged 2 commits intoxbmc:Piersfrom
Conversation
Kodiai Review SummaryWhat ChangedFixes audio deadlock during adaptive STREAMCHANGE and eliminates false positive screen resolution change detections that caused spurious quality switches. Reviewed: core logic Strengths
ObservationsImpact[MAJOR] src/main.cpp (230-231): Null pointer dereference when reader is null [MAJOR] src/main.cpp (224, 226): Redundant StreamChanged() call creates race condition window [MEDIUM] src/main.cpp (241): Behavior change from false to true may affect callers Preference[MINOR] src/main.cpp (233): Debug log includes redundant streamChanged value Suggestions
Verdict🔴 Address before merging -- 3 blocking issue(s) found Review Details
|
ReviewMust Fix — Unconditional The guard block now returns Minor — Trailing whitespace on blank lines 225 and 232 in Minor — |
9060f8c to
9c528ca
Compare
|
@claude can you review again? |
CastagnaIT
left a comment
There was a problem hiding this comment.
thank you for the detailed explanations about the problems
seems to make sense i will test tonight
i ask you to split the single commit and create two commits, so one for each fix
CRepresentationChooserDefault::CheckResolution() compared the user-configured resolution limit (m_screenWidth) against the actual physical hardware resolution (m_screenCurrentWidth), resulting in perpetual false positives every 10 seconds. Dedicated tracking variables (m_screenLastWidth, m_screenLastHeight) now correctly isolate physical window resize detection from the addon's maximum quality configuration limits.
When a bandwidth fluctuation triggered a representation change, Kodi Core reopened all active streams sequentially. If the first stream (Video) evaluated to no quality change, the m_checkCoreReopen optimization flag short-circuited all further OpenStream callbacks. If a subsequent stream (Audio) did change quality, its Reset() and reconstruction was skipped entirely, leaving it stuck at EVENT_TYPE::REP_CHANGE and permanently blocking segment downloads. This commit hoists a !isStreamChanged conditional to guard the entire m_checkCoreReopen block, guaranteeing that a formally changed stream bypasses the fast-path optimization and executes its native Reset() cycle.
9c528ca to
22abcd5
Compare
Description
This PR resolves two intertwined bugs that result in severe playback stalling and complete audio pipeline failure during DASH/adaptive playback, specifically surfacing when users configure maximum video resolution limits (e.g., 1080p) on higher resolution physical displays (e.g., 4K TVs).
Each fix is in its own commit:
[chooser]Screen Resolution False Positives (src/common/ChooserDefault.cpp,ChooserDefault.h):CRepresentationChooserDefault::CheckResolution()compared the user-configured resolution limit (m_screenWidth) against the actual physical hardware resolution (m_screenCurrentWidth), resulting in perpetual false positives every 10 seconds. Dedicated tracking variables (m_screenLastWidth,m_screenLastHeight) now correctly isolate physical window resize detection from the addon's maximum configured quality limits.[demux]Audio Deadlock during STREAMCHANGE (src/main.cpp):When a bandwidth fluctuation triggered a representation change, Kodi Core reopened all active streams sequentially. If the first stream (Video) evaluated to no quality change, the
m_checkCoreReopenoptimization flag short-circuited all furtherOpenStreamcallbacks. If a subsequent stream (Audio) did change quality, itsReset()and reconstruction was skipped entirely, leaving it stuck atEVENT_TYPE::REP_CHANGEand permanently blocking segment downloads. This commit hoists a!isStreamChangedconditional to guard the entirem_checkCoreReopenblock, guaranteeing that a formally changed stream bypasses the fast-path optimization and executes its nativeReset()cycle.Motivation and context
When playing adaptive streams on displays with a higher physical resolution than the user's Kodi resolution cap (e.g., a 1080p cap on a 4K display), the demuxer would continuously spin false
STREAMCHANGEevents every 10 seconds due to a flawedm_screenWidth != m_screenCurrentWidthcomparison, severely stuttering playback.Even without these false positives, a genuine adaptive bandwidth fluctuation would trigger a legitimate
DEMUX_SPECIALID_STREAMCHANGE. During the subsequent sequentialOpenStreamworkload triggered by Kodi Core, the audio stream'sReset()operation was swallowed due to a sharedm_checkCoreReopenfast-path bypass. Because the audio reader's state was abandoned mid-update (stuck atEVENT_TYPE::REP_CHANGE), it permanently blocked segment queuing.These changes are necessary to allow
inputstream.adaptiveto survive legitimate adaptive bandwidth changes without permanently killing the audio output pipeline.How has this been tested?
plugin.video.youtubeadd-on.DEMUX_SPECIALID_STREAMCHANGEgracefully reconstructs the audio FFmpeg decoders.Log Comparisons
Bug 1: Screen Resolution False Positives (
ChooserDefault.cpp)Before Fix: Kodi routinely and spuriously detects screen resolution changes because
m_screenWidth(config limit) naturally mismatchesm_screenCurrentWidth(hardware rendering).After Fix: The
STREAMCHANGEstorm vanishes. NoScreen resolution has changedlog entries are observed during prolonged, stable 4K playback sessions.Bug 2: Audio Deadlock (
main.cpp)Before Fix: Following a
STREAMCHANGE,OpenStream(1014)(Audio) hits the early-return optimization set by the preceding video stream, skipping stream construction.After Fix: The hoisted
!isStreamChangedconditional allows genuinely changed streams to fall through, successfully rebuilding their FFmpeg instance.Screenshots (if appropriate):
Types of change
Checklist: