[FragmentedSampleReader] Rework method to find the sample index#1994
[FragmentedSampleReader] Rework method to find the sample index#1994CastagnaIT merged 1 commit intoxbmc:Piersfrom
Conversation
ReviewCritical - Debug logging left in production code (FragmentedSampleReader.cpp) Multiple
The per-sample log inside the loop is a performance regression — it fires for every sample in the table on every seek. Must Fix - The old code passed Must Fix - No The old code looped calling |
1a36eee to
1da088f
Compare
ReviewMust Fix — Operator precedence / logic error in sync sample selection (FragmentedSampleReader.cpp:894) if (syncIndex == indexNoValue || syncCts < ts && syncCts < cts)Two problems:
Likely intended (last sync at-or-before ts): if (cts <= ts && (syncIndex == indexNoValue || cts > syncCts))Must Fix — Potential null dereference after After calling Minor — Trailing whitespace (FragmentedSampleReader.cpp:872)
Minor — LOGWARNING with raw debug string (FragmentedSampleReader.cpp:842)
|
| const AP4_UI64 cts = sample.GetCts(); | ||
| if (sample.IsSync()) | ||
| { | ||
| if (syncIndex == indexNoValue || syncCts < ts && syncCts < cts) |
There was a problem hiding this comment.
Must Fix — Logic error in sync sample update condition.
syncCts < ts && syncCts < cts means once syncCts >= ts (past target), this branch is never entered and a better sync can't replace the current one. Also, there's no guarantee the selected sync is actually near ts — a sync far before the target can be selected and never updated.
If the goal is the latest sync sample at or before ts:
| if (syncIndex == indexNoValue || syncCts < ts && syncCts < cts) | |
| if (cts <= ts && (syncIndex == indexNoValue || cts > syncCts)) |
There was a problem hiding this comment.
nope, the logic must be:
find first sample sync index (doesnt matter about ts), but if the found sample sync has a lower ts than target ts, then try to find a sample sync index equal or higher ts than target (if any), that means the first found, and not go to the last one
|
@claude i updated the PR code, ignore old bot comments and review |
1da088f to
a924398
Compare
|
@claude review |
a924398 to
1f60930
Compare
|
@kodiai please review |
kodiai responseDecision: NOT APPROVED Issues:
|
|
@kodiai for your point 1: |
kodiai responseYou're correct. The current condition at line 905 does handle your requirement: if (syncIndex == indexNoValue || syncCts < ts && cts > syncCts)How it works:
Your scenario (single sync with
My proposed alternative would break your requirement because The current logic is correct for the stated goal. I withdraw point (1) from the review. |
|
@kodiai review again takin in account last comments |
Description
The old method was using two methods sequentially to find the sample index
GetSampleIndexForTimeStamp
GetNearestSyncSampleIndex
this was a method that could sometimes cause problems
the situation example:
target timestamp (TS): 155
list of samples:
GetSampleIndexForTimeStampwill return index 5(if fails execute
Advanceto get next segment)since the above have set index to 5
GetNearestSyncSampleIndexwill try to find a sample sync from index 5 and subsequent, and nothing will returncausing to fails and execute
Advanceto get next segmentIt is understandable that there are several points where Advance could be executed and force a download of more segments,
and so causing a slowdown in the seek, as the data from these downloads needs to be read immediately
this PR will rework this, by try finding a sample sync closer to the target ts (any available) in the current segment
and in case fallback to a sample with closer ts (without sync)
Motivation and context
Found while investigating
i always suspected that Advance method used was one of cause to do some delay on seek but i never looked deeply
so this will improve the video seek speed on mp4 streams
fix #1992
How has this been tested?
test a stream using MP4 container, then while seeking, check downloaded segments
but it is still better to debug the underlying code and check when Advance method is called
Screenshots (if appropriate):
Types of change
Checklist: