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

fix: ensure all timelineregionenter events are fired #6713

Merged

Conversation

littlespex
Copy link
Contributor

@littlespex littlespex commented May 30, 2024

We aren't sure if this is the best solution, because we don't entirely understand the original reason for using startTimeOfLoad, the wall clock time that the load started, instead of startTime, the playhead time offset passed to player.load(). We are looking for some clarity and this is our initial fix. This issue results in DAI impressions being missed, especially on lower powered and network constrained devices.

Resolves #6711

@shaka-bot
Copy link
Collaborator

Incremental code coverage: 100.00%

@@ -2405,7 +2405,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
const setupPlayhead = (startTime) => {
this.playhead_ = this.createPlayhead(startTime);
this.playheadObservers_ =
this.createPlayheadObserversForMSE_(startTimeOfLoad);
this.createPlayheadObserversForMSE_(startTime);
Copy link
Member

Choose a reason for hiding this comment

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

I could use more explanation in the PR description. Why is startTime correct and startTimeOfLoad wrong? What's the difference?

Might also be worth a comment here in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are extensive notes in the associated issue #6711

Copy link
Contributor Author

@littlespex littlespex May 30, 2024

Choose a reason for hiding this comment

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

We don't understand why startTimeOfLoad is being used, especially for VOD. The startTimeOfLoad argument is used to set the startsPastZero flag in RegionObserver. The comments there seem to indicate that it is playhead related:

* Whether the asset is expected to start at a time beyond 0 seconds.
* For example, if the asset is a live stream.
* If true, we will not start polling for regions until the playhead has
* moved past 0 seconds, to avoid bad behaviors where the current time is
* briefly 0 before we have enough data to play.
* @private {boolean}

This makes sense. If the user called player.load() with a non-zero start time, the observer should wait until the initial seek has completed. startTimeOfLoad is the wall clock time of when the load operation started. How does that play into how the region observer operates? Before the commit mentioned in the issue, startTimeOfLoad was alway NaN at the time createPlayheadObserversForMSE_, which coincidentally resulted in the correct behavior for VOD.

Copy link
Contributor Author

@littlespex littlespex May 31, 2024

Choose a reason for hiding this comment

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

@theodab Can you provide any insight here? The comments in #5361 state:

This change modifiers the region observer so that it does not start examining regions until the time gets past 0 seconds, except in the case of VOD.

Unfortunately, after the @avelad's state engine refactor, startTimeOfLoad is always greater than zero, which means startsPastZero is always true, regardless of live/vod.

This comments also mention:

This does not happen every time; it's likely based on the exact time it takes the player to start playing.

With startTimeOfLoad being a timestamp, it doesn't seem like the correct value to use here. It suggests a delta like Date.now() / 1000 - startTimeOfLoad. That said, when we test on versions <= 4.5.0, we see startTimeOfLoad always comes in as NaN, so really only this.isLive() has any effect on the observer's startsPastZero flag.

@joeyparrish This fact led us to look into what values makes the most sense to use here, and we determined that load()'s startTime was the answer. When playing live, wait for a the playhead to update before dispatching timeline region events. When playing VOD, the player should also wait for any initial seek operations before tracking timeline region changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think the original code using startTimeOfLoad was a mistake. It's supposed to check for if we were loading partway through the presentation, so that we won't fire region events for regions that the player loads in after the end of. The startTime variable would be the actual variable we want for this.

Honestly, we should probably just rename the startTImeOfLoad variable. It's confusingly similar to startTime, despite the two variables having much different meanings and effects in the loading process.

@avelad avelad added type: bug Something isn't working correctly priority: P1 Big impact or workaround impractical; resolve before feature release labels May 31, 2024
@avelad avelad added this to the v4.10 milestone May 31, 2024
@@ -2405,7 +2405,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
const setupPlayhead = (startTime) => {
this.playhead_ = this.createPlayhead(startTime);
this.playheadObservers_ =
this.createPlayheadObserversForMSE_(startTimeOfLoad);
this.createPlayheadObserversForMSE_(startTime);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think the original code using startTimeOfLoad was a mistake. It's supposed to check for if we were loading partway through the presentation, so that we won't fire region events for regions that the player loads in after the end of. The startTime variable would be the actual variable we want for this.

Honestly, we should probably just rename the startTImeOfLoad variable. It's confusingly similar to startTime, despite the two variables having much different meanings and effects in the loading process.

@avelad avelad requested a review from joeyparrish May 31, 2024 16:47
@avelad avelad merged commit 76863f2 into shaka-project:main May 31, 2024
21 of 22 checks passed
tykus160 pushed a commit to sky-hugolima/shaka-player-contrib that referenced this pull request Jun 3, 2024
@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Jul 30, 2024
@shaka-project shaka-project locked as resolved and limited conversation to collaborators Jul 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
priority: P1 Big impact or workaround impractical; resolve before feature release status: archived Archived and locked; will not be updated type: bug Something isn't working correctly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The timelineregionenter event is not being fired in certain scenarios
5 participants