-
Notifications
You must be signed in to change notification settings - Fork 133
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
[POC] Update Manifest
structure to make HLS implementation possible
#1493
Open
peaBerberian
wants to merge
1
commit into
dev
Choose a base branch
from
misc/hls-manifest
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
peaBerberian
added
work-in-progress
This Pull Request or issue is not finished yet
poc
Proof Of Concept - This is just an attempt to ponder on
Priority: 4 (Very low)
This issue or PR has a very low priority.
labels
Aug 5, 2024
NOTE: This is just a background, low-priority, Proof-Of-Concept. It is not currently functional and is in the middle of its implementation, there's also no HLS code for now, only HLS-related ideas. Overview ======== This PR is a Proof-Of-Concept where I explore whether HLS playback can be natively implemented in the RxPlayer without sacrificing too much the RxPlayer code's readability. This is not the first attempt, but the approach here is different than previous ones. One of the core idea is to keep the RxPlayer API as is, and thus to hide all HLS differences in the RxPlayer code. We already thought of potential HLS compatibility when designing our v4, so there seem to be nothing in our API incompatible with HLS concepts. Also our core code is for the most part protocol-agnostic, so we presumably could keep, and profit from, most of our logic while playing HLS streams. However, this attempt completely changes our internal `Manifest` concept, especially the `Adaptation` subpart of it (which was equivalent to the concept of a "track"). Manifest hierarchy change ========================= The issue --------- One of the main differences between HLS and other protocols handled by the RxPlayer (such as DASH) is the concept of "variant streams" only HLS have. Basically in DASH, you first select your wanted audio + video + text tracks and then select a Representation (i.e. quality) according to your current playback conditions such as your network bandwidth. In HLS however, this is reversed. You first have to select your "variant stream" based on your playback conditions (mainly: network bandwidth) and then see which "media" - including our notion of a track - is available for that variant stream. Because of edge cases, we cannot translate the HLS model into our DASH-like model wihout losing some HLS features. Doing the reverse (adapting DASH model into HLS model, which seems to be what e.g. the shaka-player more-or-less did) could work yet it doesn't seem like an optimal solution (e.g. we would either lose some bandwidth information or creating a huge number of variant streams for all potential combinations). How I tried to fix it --------------------- So what I did here, was to change the Manifest object's hierarchy so it can adapt to both how HLS is treating thing and how DASH is treating things. The Manifest looked like this before this commit: ```ts type Manifest = { periods: Array<{ // Define a particular track adaptations: Record< "audio" | "video" | "text", Array<{ // qualities representations: Array<{ // ... That Representation's metadata }>; // ... The rest of that track's metadata }> >; // ... The rest of that Period's metadata }>; // ... The rest of the Manifest's metadata }; ``` Now it looks like: ```ts type Manifest = { periods: Array<{ tracksMetadata: Record< "audio" | "video" | "text", Record< string, // The track's id { // All qualities linked to that track representations: Record< string, // That Representation's id { // ... That Representation's metadata } >; // ... The rest of that track's metadata } > >; // Groups of available tracks and qualities combinations variantStreams: Array<{ id: string; // bandwidth for that variant, only defined for HLS, others have // only a single variant bandwidth: number | undefined; // Authorized tracks + qualities combinations in that variantStream media: Record< "audio" | "video" | "text", Array<{ // `id` the corresponding track in `tracksMetadata` linkedTrackId: string; // `id` list of the Representations' in `tracksMetadata` representations: string[]; }> >; }>; // ... The rest of that Period's metadata }>; // ... The rest of the Manifest's metadata }; ``` So basically in a Period, we'll now separate a tracks' metadata and the conditions in which we may play them: the former rely on `tracksMetadata`, the latter on `variantStreams`. Note that `variantStreams` only use `id`s to refer to tracks and Representations: it does not contain the metadata directly. This is to avoid having to repeat a track's and representation's metadata already present in the `tracksMetadata`. We cannot just rely on a same-object-reference trick because the Manifest object has to be able to be transmitted through the worker and main tread. Worker compatibility is also the main reason why we're not relyng on `Map` objects to link ids and metadata, though it may seem more logical. This new structure allows to enforce complex HLS features, like restrictions on which tracks and qualities can be played when another unrelated track is selected. Here incompatible tracks would never be present the same variantStream. Though it is very clear that it adds net complexity on top of our Manifest's structure, as those "variant streams" concept do not exist in Smooth or DASH. For Smooth and DASH, only a single `variantStream` will be present, with a `bandwidth` set to `undefined` (Representation-level `bandwidth` is still exploited by our ABR logic) and containing all tracks declared in `tracksMetadata`.
peaBerberian
force-pushed
the
misc/hls-manifest
branch
from
August 29, 2024 19:59
d128786
to
9c77ee0
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
poc
Proof Of Concept - This is just an attempt to ponder on
Priority: 4 (Very low)
This issue or PR has a very low priority.
work-in-progress
This Pull Request or issue is not finished yet
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: This is just a background, low-priority, Proof-Of-Concept. It is not currently functional and is in the middle of its implementation, there's also no HLS code for now, only HLS-related ideas.
Overview
This PR is a Proof-Of-Concept where I explore whether HLS playback can be natively implemented in the RxPlayer without sacrificing too much the RxPlayer code's readability. This is not the first attempt, but the approach here is different than previous ones.
One of the core idea is to keep the RxPlayer API as is, and thus to hide all HLS differences in the RxPlayer code.
We already thought of potential HLS compatibility when designing our v4, so there seem to be nothing in our API incompatible with HLS concepts. Also our core code is for the most part protocol-agnostic, so we presumably could keep, and profit from, most of our logic while playing HLS streams.
However, this attempt completely changes our internal
Manifest
concept, especially theAdaptation
subpart of it (which was equivalent to the concept of a "track").Manifest hierarchy change
The issue
One of the main differences between HLS and other protocols handled by the RxPlayer (such as DASH) is the concept of "variant streams" only HLS have.
Basically in DASH, you first select your wanted audio + video + text tracks and then select a Representation (i.e. quality) according to your current playback conditions such as your network bandwidth.
In HLS however, this is reversed. You first have to select your "variant stream" based on your playback conditions (mainly: network bandwidth) and then see which "media" - including our notion of a track - is available for that variant stream.
Because of edge cases, we cannot translate the HLS model into our DASH-like model wihout losing some HLS features.
Doing the reverse (adapting DASH model into HLS model, which seems to be what e.g. the shaka-player more-or-less did) could work yet it doesn't seem like an optimal solution (e.g. we would either lose some bandwidth information or creating a huge number of variant streams for all potential combinations).
How I tried to fix it
So what I did here, was to change the Manifest object's hierarchy so it can adapt to both how HLS is treating thing and how DASH is treating things.
The Manifest looked like this before this PR:
Now it looks like:
So basically in a Period, we'll now separate a tracks' metadata and the conditions in which we may play them: the former rely on
tracksMetadata
, the latter onvariantStreams
.Note that
variantStreams
only useid
s to refer to tracks and Representations: it does not contain the metadata directly. This is to avoid having to repeat a track's and representation's metadata already present in thetracksMetadata
. We cannot just rely on a same-object-reference trick because the Manifest object has to be able to be transmitted through the worker and main tread. Worker compatibility is also the main reason why we're not relyng onMap
objects to link ids and metadata, though it may seem more logical.This new structure allows to enforce complex HLS features, like restrictions on which tracks and qualities can be played when another unrelated track is selected. Here incompatible tracks would never be present the same variantStream.
Though it is very clear that it adds net complexity on top of our Manifest's structure, as those "variant streams" concept do not exist in Smooth or DASH. For Smooth and DASH, only a single
variantStream
will be present, with abandwidth
set toundefined
(Representation-levelbandwidth
is still exploited by our ABR logic) and containing all tracks declared intracksMetadata
.