Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate playback rate and limiting #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

dylanmei
Copy link
Contributor

@dylanmei dylanmei commented Dec 23, 2022

Discussed in #14, playback rates less than 1.0 are running as quickly as possible.

This change introduces a limiter to propose the best delay based on the record time shift and the delta between current and next record timestamps.

Additionally, I had trouble getting Git to see new kt files. I've trimmed the .gitignore to just what is required.

} else if (playbackRate > 1.0f) {
val delta = Duration.between(previousTimestamp ?: Instant.now(clock), shiftedTimestamp)
Duration.ofMillis((delta.toMillis() / playbackRate).toLong()).also {
previousTimestamp = shiftedTimestamp.plus(it)
Copy link
Contributor

Choose a reason for hiding this comment

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

why we make previousTimestamp=shiftedTimestamp.plus(delay) when playbackRate > 1.0? I feel it should be the same as previousTimestamp = shiftedTimestamp. 🤔 For example:

When playback rate is 2.0, and earliest record timestamp is 00:00, now time is 01:00, timeshiftNanos is 1 hr. Then for the records consumed from a cassette file in order, the calculated key properties will be:

recordTimestamp shiftedTimestamp delta(line 26) delay(return value) previousTimestamp
00:00 01:00 N/A null 01:00
00:10 01:10 10s 5s 01:15 (should be 01:10)
00:20 01:20 5s (should be 10s) 2.5s (should be 5s) 01:22.5 (should be 01:20)

And for the corresponding test, it should pass correctly for two records, but if with three and more records, I suspect it may surface some problem.

How do you think? Or Maybe I misunderstand something here?

previousTimestamp = shiftedTimestamp.plus(it)
}
} else {
Duration.between(previousTimestamp, shiftedTimestamp)
Copy link
Contributor

Choose a reason for hiding this comment

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

When playback rate is 1.0 here, should we update previousTimestamp as well? Otherwise previousTimestamp will always be the first record shiftedTimestamp, and for the third record and forward records, the calculated delay will be not correct.

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.

2 participants