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

Expose peakBitrate property in Format #6706

Closed
wants to merge 1 commit into from

Conversation

julioz
Copy link
Contributor

@julioz julioz commented Nov 27, 2019

Fixes #2863

Exposes peakBitrate value when both BANDWIDTH and AVERAGE-BANDWIDTH attributes are available.
The bitrate property will always carry the average bandwidth of the Format instance, while peakBitrate
will carry the value for the respective attribute, when present; according to
tools.ietf.org/html/draft-pantos-http-live-streaming-23#page-28

Fixes google#2863

Exposes `peakBitrate` value when both `BANDWIDTH` and `AVERAGE-BANDWIDTH` attributes are available.
The `bitrate` property will always carry the average bandwidth of the `Format` instance, while `peakBitrate`
will carry the value for the respective attribute, when present; according to
tools.ietf.org/html/draft-pantos-http-live-streaming-23#page-28
assertThat(variants.get(1).format.bitrate).isEqualTo(1270000);
assertThat(variants.get(1).format.peakBitrate).isEqualTo(1280000);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the example case for the presence of the attribute.

@@ -236,14 +236,17 @@ public void testParseMasterPlaylist() throws IOException {
}

@Test
public void testMasterPlaylistWithBandwdithAverage() throws IOException {
public void testMasterPlaylistWithBandwidthAverage() throws IOException {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed typo.

@julioz
Copy link
Contributor Author

julioz commented Nov 27, 2019

When running locally, some Extractor tests fail; I can't figure out why. I assume it's one of the (innumerous) Format constructors (or factory methods) that take in bitrate and didn't take in peakBitrate. Please advise before we merge this (or; feel free to fix and commit on top of this branch).

@icbaker icbaker requested a review from AquilesCanta November 29, 2019 18:12
@icbaker
Copy link
Collaborator

icbaker commented Nov 29, 2019

Mind taking a look Santiago?

@AquilesCanta
Copy link
Contributor

I think this is for @ojw28 to look at.

@AquilesCanta AquilesCanta assigned ojw28 and unassigned AquilesCanta Dec 2, 2019
@AquilesCanta
Copy link
Contributor

On my side, I think it's unfortunate we are using the Format.bitrate field for both BANDWIDTH and AVERAGE-BANDWIDTH. Adding the peak bitrate adds a bit of confusion to the mix.

Aside, I think it would be helpful for us to know why/how having both average and peak bitrates could be of use.

@julioz
Copy link
Contributor Author

julioz commented Dec 2, 2019

@AquilesCanta Please check the referred issue #2863 for context.

@AquilesCanta
Copy link
Contributor

AquilesCanta commented Dec 2, 2019

My bad, didn't see the link. However, the referenced issue makes the same question I made above. And an answer is still not available. It's worth looking into the issue first.

EDIT: @ojw28 removed the need more info tag from the issue, so I'm assuming he understands the use case. Thanks for your patience!

@tonihei
Copy link
Collaborator

tonihei commented Dec 2, 2019

I think the peak bitrate is preferable for adaptive track selection to be on the safe side, especially when the peak is much higher than the average. Otherwise, the ABR algorithm may run into issues during complex scenes.

So, if available, we should probably just populate the Format bitrate by BANDWIDTH in all cases?

@julioz
Copy link
Contributor Author

julioz commented Dec 2, 2019

@tonihei That is for sure. The BANDWIDTH attribute is mandatory, while the AVERAGE-BANDWIDTH attribute is optional.
The change in 2795269 exposes the AVERAGE-BANDWIDTH value overriding the BANDWIDTH one, but that means we hide away the latter. For advanced ABR algorithms that might need to introspect into that value, this becomes an issue; which this PR fixes.

Let me know if hiding one of the values is by design. If that's the case, we should document it publicly somewhere, I assume others might hit the same limitation in the future.

@AquilesCanta
Copy link
Contributor

To provide some context: Back when AVERAGE-BANDWIDTH was added to the HLS spec, preferring AVERAGE-BANDWIDTH (which is option) over BANDWIDTH (which is mandatory) was a design decision. @tonihei, please feel free to take whichever approach you think is most suitable for ABR.

@ojw28
Copy link
Contributor

ojw28 commented Dec 2, 2019

I think the peak bitrate is preferable for adaptive track selection to be on the safe side, especially when the peak is much higher than the average. Otherwise, the ABR algorithm may run into issues during complex scenes.

Presumably using both is preferable, else there wouldn't be value in them both existing. I agree that if we were to use just one, then peak bitrate is preferable, and so 53b52e7 was probably a mistake.

I think we should expose both in Format, and use peak bitrate for ABR decisions for as long as we're only using one of them. I can sort this out whilst merging this pull request. I will separately propose a small fix to use peak bitrate ahead of merging the whole change.

@ojw28
Copy link
Contributor

ojw28 commented Dec 2, 2019

For what it's worth, the DASH specification gives a more nuanced definition of bitrate, that seems much more useful than either "peak" or "average". I guess it's closer to "peak" in practice:

Consider a hypothetical constant bitrate channel of bandwidth with the value of this attribute in bits per second (bps). Then, if the Representation is continuously delivered at this bitrate, starting at any SAP that is indicated either by @startWithSAP or by any Segment Index box, a client can be assured of having enough data for continuous playout providing playout begins after @minBufferTime * @bandwidth bits have been received (i.e. at time @minBufferTime after the first bit is received).

Meanwhile the HLS authoring specification seems to allow you to specify average and peak bitrates that are wrong by up to 10%, whilst referencing another section that doesn't exist. Why?

1.26. For VOD content, the average segment bit rate MUST be within 10% of the AVERAGE-BANDWIDTH attribute. (See Declared versus measured values of bandwidths.)
1.27. For VOD content, the measured peak bit rate MUST be within 10% of the BANDWIDTH attribute.

marcbaechinger pushed a commit that referenced this pull request Dec 4, 2019
This is a minor change ahead of merging a full variant of
#6706, to make
re-buffers less likely.

Also remove variable substitution when parsing
AVERAGE-BANDWIDTH (it's not required for integer attributes)

PiperOrigin-RevId: 283554106
ojw28 added a commit that referenced this pull request Dec 6, 2019
This is a minor change ahead of merging a full variant of
#6706, to make
re-buffers less likely.

Also remove variable substitution when parsing
AVERAGE-BANDWIDTH (it's not required for integer attributes)

PiperOrigin-RevId: 283554106
@julioz
Copy link
Contributor Author

julioz commented Dec 16, 2019

@ojw28 @marcbaechinger It seems like we have opted for exposing the peak bitrate when available, super-seeding the avg bitrate data, which hinders more advanced ABR algorithms.
As this PR starts to get conflicts with dev-v2, I'm tempted to close it. As a side-note, it might be worth extracting some of the constructor calls with default values from many test suites into a test fixture class that can provide sensible values and still builders for further specialization if need be in tests. I didn't do it as part of this PR since I couldn't find other fixture classes in the codebase, but would gladly introduce this pattern as it has proven to be useful for us at SoundCloud.

Let me know what you think.

@ojw28
Copy link
Contributor

ojw28 commented Dec 16, 2019

Please leave it open. We'll resolve the conflict when we merge. Thanks!

@ojw28
Copy link
Contributor

ojw28 commented Feb 3, 2020

We need to make some bigger changes to land this, which we're working on now. These changes will land separately of this pull request, so I'll go ahead and close it. Please follow the tracking bug for updates. Thanks!

@ojw28 ojw28 closed this Feb 3, 2020
@google google locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants