Skip to content

stream.dash: use suggestedPresentationDelay to calculate the live edge for dynamic manifests #5657

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

Merged
merged 2 commits into from
Nov 9, 2023
Merged

Conversation

michaelarnauts
Copy link
Contributor

@michaelarnauts michaelarnauts commented Nov 8, 2023

Follow-up for #5654, also mentioned in #5582

Reworked this PR to calculate the live edge based on the suggestedPresentationDelay.

@michaelarnauts michaelarnauts marked this pull request as draft November 8, 2023 12:37
@bastimeyer bastimeyer added WIP Work in process stream: DASH labels Nov 8, 2023
Copy link
Member

@bastimeyer bastimeyer left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

I don't know how I feel about adding a new separate session option and CLI argument for DASH streams. I'm already in the process of de-duplicating logic between segmented stream implementations (#5601) by using the same options/arguments for all of them.

If we're going to add a live-edge option that's similar to HLS to the DASH implementation, then IMO the right path would be deprecating the HLS option and adding a new common option/argument.

However, I also don't know how useful a live-edge option for DASH actually is that works the same way as the HLS one. What I mean is that it'd be much better to make this based on a time offset, not on a segment count offset. There's already the MPD.minBuffer and MPD.suggestedPresentationDelay attributes. And these attributes are already taken into account for the timeline-based segments, so an option which overrides the MPD's default values would make much more sense. I've already talked about that in one of the issues where the DASH delay was talked about. See:

Implementing a live-edge just for segment-lists doesn't seem right.

@michaelarnauts
Copy link
Contributor Author

I see, thanks for the feedback. I'll try to make it work by calculating the optimal offset based on the segment duration and the suggestedPresentationDelay.

@michaelarnauts michaelarnauts changed the title stream.dash: implement streaming from a specified live edge stream.dash: use suggestedPresentationDelay to calculate the live edge for dynamic manifests Nov 8, 2023
@michaelarnauts
Copy link
Contributor Author

I've reworked this to use the suggestedPresentationDelay to calculate the live edge for dynamic manifests as suggested.

@michaelarnauts
Copy link
Contributor Author

I'm only using the suggestedPresentationDelay, since the minBuffer is already taken in account when giving a value to suggestedPresentationDelay. It would seem strange that a minBuffer of 5 seconds, and a suggestedPresentationDelay of 10 seconds would mean a 15 seconds live edge (and it might be even more due to the segment boundaries). This is what happens in SegmentTemplate though, I think it should be removed there.

I'm not looking at minBuffer now, due to this, but maybe we should use the max value of both values? What do you think?

@michaelarnauts michaelarnauts marked this pull request as ready for review November 9, 2023 08:26
Copy link
Member

@bastimeyer bastimeyer left a comment

Choose a reason for hiding this comment

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

Thanks. Looking good...

The nested if-else-blocks could be flattened to elif-blocks for the sake of having better code, but I don't think this makes sense here, because I will need to add a warning message later anyway when the manifest has skipped segments after a reload (similar to #5607).

The optional segment duration needs to be fixed though before we can merge this...

"""Calculate the optimal segment number to start based on the suggestedPresentationDelay"""
suggested_delay = self.root.suggestedPresentationDelay

offset = max(0, math.ceil(suggested_delay.total_seconds() / self.duration_seconds))
Copy link
Member

@bastimeyer bastimeyer Nov 9, 2023

Choose a reason for hiding this comment

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

self.duration_seconds can be 0.0 if the optional duration attribute is missing (unknown segment duration). This probably will never be the case for dynamic manifests, but we still have to cover this case, or we raise a ZeroDivisionError.

In this case, the method should choose a constant number of segments that's referenced from a class attribute (see MPD.DEFAULT_MINBUFFERTIME for example). Not sure though what would be a good value, maybe 3 (default value of hls-live-edge). In the future, we can make this value, as well as the live-edge offset calculation customizable using a new session option.

My idea is deprecating and renaming the hls-live-edge option. Then we can change it so time values can be set too with a time-unit suffix, instead of just whole segment numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added this check, and also added a test for this scenario.

@bastimeyer bastimeyer removed the WIP Work in process label Nov 9, 2023
@bastimeyer bastimeyer merged commit c5f8f87 into streamlink:master Nov 9, 2023
@bastimeyer
Copy link
Member

Thanks, appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants