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

Set actual duration for dynamic contents whose future end is already known #1235

Merged
merged 2 commits into from
Apr 11, 2023

Conversation

peaBerberian
Copy link
Collaborator

What to set as a duration attribute of the MediaSource and by extension to the HTMLMediaElement is not that simple.

For static contents (contents that won't evolve with time) like VoD contents, we just set it to the actual known end of the content (technically it is a little more complex as each track might lead to different durations, but still).
However the problem is with dynamic contents which do evolve.

Traditionally, and like many other players, we've set a very high duration attribute when playing dynamic content to prevent encountering side effects of setting that attribute to a lower value, such as not being able to seek to far in the content.

The current HTML WHATWG specification actually recommends setting it to Infinity, but as we've had some issues with that value, we prefer to set it in most cases to 2^32 instead, which has the best result with most platforms.

However when doing those developments, I forgot that there are some cases where the content is dynamic but the actual future end of the content is already known. It can happen with DASH, but it mostly happened with the "local" transport, which allows to play content downloaded locally on the device.

Here a content that was being played while it was still being loaded would report 2^32 through the getVideoDuration API, where we could actually be smarter and set the already-known future end of the content instead.

This commit fixes that.

What it does it to detect when the duration reported by the ContentTimeBoundariesObserver is the actual end of the content, and if it is, indicate it through its durationUpdate event.

This event's payload is then given to the MediaDurationUpdater, which will now know whether this is the actual end or whether setting a very high duration is here preferred.

…known

What to set as a `duration` attribute of the MediaSource and by extension to the
HTMLMediaElement is not that simple.

For static contents (contents that won't evolve with time) like VoD
contents, we just set it to the actual known end of the content
(technically it is a little more complex as each track might lead to
different durations, but still).
However the problem is with dynamic contents which do evolve.

Traditionally, and like many other players, we've set a very high
`duration` attribute when playing dynamic content to prevent
encountering side effects of setting that attribute to a lower value,
such as not being able to seek to far in the content.

The current HTML WHATWG specification actually recommends setting it to
`Infinity`, but as we've had some issues with that value, we prefer to
set it in most cases to 2^32 instead, which has the best result with
most platforms.

However when doing those developments, I forgot that there are some
cases where the content is dynamic but the actual future end of the
content is already known. It can happen with DASH, but it mostly
happened with the `"local"` transport, which allows to play content
downloaded locally on the device.

Here a content that was being played while it was still being loaded
would report 2^32 through the `getVideoDuration` API, where we could
actually be smarter and set the already-known future end of the
content instead.

This commit fixes that.

What it does it to detect when the duration reported by the
`ContentTimeBoundariesObserver` is the actual end of the content, and if
it is, indicate it through its `durationUpdate` event.

This event's payload is then given to the `MediaDurationUpdater`, which
will now know whether this is the actual end or whether setting a very
high duration is here preferred.
@peaBerberian peaBerberian added the Performance checks Performance tests are run on this issue / PR label Mar 28, 2023
@peaBerberian peaBerberian added this to the 3.30.1 milestone Mar 28, 2023
@peaBerberian peaBerberian force-pushed the fix/dynamic-but-terminated-content-duration branch from 121ca22 to 1103835 Compare March 28, 2023 16:41
@peaBerberian peaBerberian merged commit 288d4ce into master Apr 11, 2023
@peaBerberian peaBerberian mentioned this pull request Jun 13, 2023
@peaBerberian peaBerberian modified the milestones: 3.30.1, 3.31.0 Jun 13, 2023
@peaBerberian peaBerberian deleted the fix/dynamic-but-terminated-content-duration branch July 6, 2023 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance checks Performance tests are run on this issue / PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant