Skip to content

Fix handling of sender report offsets#731

Merged
milos-lk merged 4 commits intomainfrom
fix-srs-handling
Aug 29, 2025
Merged

Fix handling of sender report offsets#731
milos-lk merged 4 commits intomainfrom
fix-srs-handling

Conversation

@milos-lk
Copy link
Copy Markdown
Contributor

While the recent change made sure packet PTSs don't jump unexpectedly, it also added wrong cumulative handling of offsets.
Desired PTS offset needs to be split in 2 components:

  • basedPTS offset (basically offset from the first track appearance) which needs to be kept constant
  • offset introduced on sender reports - which shouldn't be accumulated but overwritten

In addition to the change adding some synchronizer unit tests to cover basic PTS generation logic.

One is fixed and determined on track start up, the other needs to be updated on SRs
@milos-lk milos-lk requested a review from a team August 29, 2025 12:09
Copy link
Copy Markdown
Contributor

@boks1971 boks1971 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Comment thread go.mod
gopkg.in/yaml.v3 v3.0.1 // indirect
)

tool github.com/maxbrunsfeld/counterfeiter/v6
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this required? Guess it makes things repeatable/consistent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go get -tool github.com/maxbrunsfeld/counterfeiter/v6
is what it got it added there - I think it's fine to have it available there for go tool for this module.

Comment thread pkg/synchronizer/track.go Outdated
// offsets
currentPTSOffset time.Duration // presentation timestamp offset (used for a/v sync)
desiredPTSOffset time.Duration // desired presentation timestamp offset (used for a/v sync)
basePTSOffset time.Duration // component of the desired PTS offset (set initially to preseve initial offset)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:nit: preserve spelling

Comment thread pkg/synchronizer/track.go
return
}

t.desiredPTSOffset += offset
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a chance that PTS can move backward because of this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - it could keep accumulating in both directions depending on SRs. The version before was simply overwriting t.desiredPTSOffset which obviously breaks track starting late.

Comment thread pkg/synchronizer/synchronizer_test.go Outdated

adj0, err := tsync.GetPTS(pkt(ts))
require.NoError(t, err)
near(t, adj0, 0, 5*time.Millisecond)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is 5ms enough? some of our GH runners are super slow. Ideally, using a mock clock would be great, but that is not easy to do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good point - most of variation comes from potentially variable time needed between setting t.startTime and calculating estimatedPTS few instructions later (don't expect huge diff there unless the gh runner is super super slow). I could bump the tolerance a bit higher and keep an eye on this - and if flakiness appear I could introduce mock clock (which due to its invasiveness would like to skip if we can get away without it). wdyt?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, good strategy, mock clock will require a lot of changes.

Most of the time it should be fine. Once in a while, runner is super slow and probably have some noisy neighbour hogging cpu and causing flakiness, but it should be very rare.

@milos-lk milos-lk merged commit bdfda17 into main Aug 29, 2025
5 checks passed
@milos-lk milos-lk deleted the fix-srs-handling branch August 29, 2025 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants