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

feat(playlist): remove MediaSource range #4564

Merged
merged 4 commits into from
Aug 16, 2018
Merged

feat(playlist): remove MediaSource range #4564

merged 4 commits into from
Aug 16, 2018

Conversation

BrainCrumbz
Copy link
Contributor

See #4542 for related discussion

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@BrainCrumbz
Copy link
Contributor Author

CLA added for all commit authors

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@GiuseppePiscopo
Copy link
Contributor

I confirm I'm ok with that.

@ojw28 ojw28 requested a review from tonihei July 24, 2018 12:22
Copy link
Collaborator

@tonihei tonihei left a comment

Choose a reason for hiding this comment

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

Looks good in general. Just a couple of formatting issues and minor changes.

@@ -50,6 +50,7 @@
private static final int MSG_ADD = 0;
private static final int MSG_ADD_MULTIPLE = 1;
private static final int MSG_REMOVE = 2;
private static final int MSG_REMOVE_RANGE = 200;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you renumber this to be 3 and change the numbers below accordingly?

* @param fromIndex The initial range index, pointing to the first media source that will be
* removed. This index must be in the range of 0 <= index < {@link #getSize()}.
* @param toIndex The final range index, pointing to the first media source that will be left
* untouched. The last media source to be removed is at index {@code toIndex} - 1.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"The last media source to be removed is at index {@code toIndex} - 1." - That seems redundant and can be removed.

* is thrown.
*
* @param fromIndex The initial range index, pointing to the first media source that will be
* removed. This index must be in the range of 0 <= index < {@link #getSize()}.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Both ranges should be "in the range of 0 <= index <= {@link #getSize()}." That is, including the getSize index.
Otherwise you wouldn't be able to do removeMediaSourceRange(getSize(), getSize()) as an edge case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At a given time, "occupied" track indices are 0, 1, ... getSize() - 1. fromIndex should point to an occupied index, as the initial range index is included in the range. How can one remove the track at index getSize(), if there's no track at that index? Just trying to understand

Copy link
Collaborator

Choose a reason for hiding this comment

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

As the end index is exclusive, the method must allow getSize() as end index.

And to support the example you gave in the issue, to keep an element at index N only, it would be nice to be able to call
removeMediaSourceRange(0, N) followed by removeMediaSourceRange(1,getSize()). If this is supposed to remove the last element, the second call will result in removeMediaSourceRange(1, 1) which should be a no-op.

Copy link
Contributor Author

@BrainCrumbz BrainCrumbz Jul 25, 2018

Choose a reason for hiding this comment

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

We've abandoned the "simplicity" implied by initial issue example when we "gave up" on API tolerance (so to say). Since then, the idea seemed: have a clear API with errors when arguments are not correct. And for fromIndex to be equal to getSize() seems not correct. Of course we noticed that you cannot call removeMediaSourceRange(getSize(), getSize()) anymore. And also you cannot call removeMediaSourceRange(1, getSize()) in issue second call, that would throw too.

Staying consistent with allowed param values in signature seems quite a thing. By allowing passing getIndex() in fromIndex, it seems to go back to the "tolerant" approach somehow, which is fine anyway. Don't know, your call.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd say it's best to follow the existing behaviour of List.subList and the like. That is, throwing if startIndex<0, endIndex>size or startIndex>endIndex. This ensures the operation is valid, but is also tolerant enough to support common use cases like "remove everything behind element N" with removeRange(N, size) which will work even if N is the last element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. Just to tease a little bit, in case like "remove everything behind element N" when N is the last element, then N = size - 1, and removeMediaSourceRange(size - 1, size) already works as is. What instead currently throws (and probably looks not tolerant) is removeMediaSourceRange(size, size). Right?

Anyway, changes are coming

Copy link
Collaborator

Choose a reason for hiding this comment

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

removeMediaSourceRange(size - 1, size) would remove the element at N = size - 1 though, right?

And if I'm not mistaken removeMediaSourceRange(size, size) won't throw too because List.subList doesn't throw for this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Q1: correct, current implementation would remove element at size - 1, i.e. "the last element"

Q2: removeMediaSourceRange(size, size) throws in current (<=> initial version) of this PR. It will not throw after applying your proposed changes, as List.subList(size, size) does not throw. I was referring to current implementation.

Cool

* @throws IndexOutOfBoundsException when either index is out of playlist bounds, i.e. {@code
* fromIndex} &lt; 0 or &gt;= {@link #getSize()}, {@code toIndex} &lt; 0 or &gt; {@link
* #getSize()}
* @throws IndexOutOfBoundsException when range is malformed, i.e. {@code fromIndex} &gt;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you combine them in one @throws doc? Maybe just as "When the range is malformed, i.e. {@code fromIndex} < 0, {@code toIndex} > {@link #getSize()}, or {@code fromIndex} > {@code toIndex}."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree with grouping. Are you also suggesting to slim down the number of (broken) examples provided in JavaDoc?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. As we already require fromIndex>lastIndex, the other two examples are not needed.


/**
* Removes a range of {@link MediaSource}s from the playlist, by specifying an initial index
* (included) and a final index (excluded), and executes a custom action on completion..
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove second full stop.

* #getSize()}
* @throws IndexOutOfBoundsException when range is malformed, i.e. {@code fromIndex} &gt;
* {@code toIndex}
* @param actionOnCompletion A {@link Runnable} which is executed immediately after the media
Copy link
Collaborator

Choose a reason for hiding this comment

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

This param should be together with the other params above.

* @param toIndex The final range index, pointing to the first media source that will be left
* untouched. The last media source to be removed is at index {@code toIndex} - 1.
* This index must be in the range of 0 &lt;= index &lt; {@link #getSize()}.
*
Copy link
Collaborator

Choose a reason for hiding this comment

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

We usually leave no empty line between @param and @throws.

}
return;
}
mediaSourcesPublic.subList(fromIndex, toIndex).clear();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you replace that with Util.removeRange(mediaSourcesPublic, fromIndex, toIndex)? That calls the same method but is slightly more readable.

Also move it above the if(fromIndex == toIndex) check to ensure the exceptions are thrown first.

*/
public final synchronized void removeMediaSourceRange(
int fromIndex, int toIndex, @Nullable Runnable actionOnCompletion) {
if (fromIndex < 0 || fromIndex >= mediaSourcesPublic.size()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to do the explicit bound checks here. As soon as you call the subList method, the IndexOutOfBoundsException will be thrown anyway.

mediaSourcesPublic.subList(fromIndex, toIndex).clear();
if (player != null) {
player
.createMessage(this)
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should be indented by 4 spaces (relative to "player")

@ojw28
Copy link
Contributor

ojw28 commented Jul 25, 2018

No particular need to fix it for this contribution, but for future contributions it's preferable to configure git to use the same email as the one you specified when signing the CLA (setting user.email is described here).

@ojw28 ojw28 added cla: yes and removed cla: no labels Jul 25, 2018
@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

@ojw28
Copy link
Contributor

ojw28 commented Jul 25, 2018

CLA status was manually verified for the committing username (GiuseppePiscopo), as the commits use a @users.noreply.github.com email address.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot
Copy link

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

@tonihei
Copy link
Collaborator

tonihei commented Jul 25, 2018

Thanks! Looks good now :)

@BrainCrumbz
Copy link
Contributor Author

Not sure what's happening re. CLA. The other commit author account (GiuseppePiscopo) has registered google CLA with the same email address also associated to Github profile.

Can that be related to the "keep my address private" option in github profile?

@ojw28
Copy link
Contributor

ojw28 commented Jul 26, 2018

I think it's because the email address the CLA is signed under doesn't match the email address on the commits (which is a @users.noreply.github.com address). See my comment above (#4564 (comment)) for how to fix that for future commits. It could well be that the "keep my address private" option overrides whatever address you configure, so yes, that could be related!

For this commit we manually verified the username against our CLA records, so it's not a blocking issue.

@BrainCrumbz
Copy link
Contributor Author

Thanks for feedback, yes we read that. Do you know if CLA can be signed under a @users.noreply.github.com address?

@ojw28
Copy link
Contributor

ojw28 commented Jul 27, 2018

Unsure. It seems a bit strange to do that :). We should probably just make the googlebot clever enough to look at the username as well. I'll try and get someone to do that internally!

@ojw28
Copy link
Contributor

ojw28 commented Jul 31, 2018

Turns out the issue with the CLA is that the account sending the pull request is different to the account whose commits are included within it. Hence we need to manually confirm that the commit author is OK with their changes being part of the pull request, under their signed CLA. If we didn't do this, it would be possible for someone to try and contribute commits by an author who has signed a CLA, but does not want the commits in question to be contributed.

Please could you confirm with account @GiuseppePiscopo that you're OK with all commits that are part of this pull request being submitted (you'll need to do this again whenever a new commit is added).

In future, using the same account for commits and pull requests, which is an account with a signed CLA, would help streamline this process.

@BrainCrumbz
Copy link
Contributor Author

BrainCrumbz commented Jul 31, 2018

Hi there. Yes, we were aware of this distinction between pull request opener and commit authors, thanks for clarifying. Could not find more info on how to get a user confirmation, so we just added this comment here above. Does that count as a confirmation?

Re. CLA, @GiuseppePiscopo also has a signed CLA in google, using the same email address associated with Github. Problem is (we think), email preference on Github is set to private, hence commits appear authored by a [email protected], and it's not possible to sign a CLA under that "dummy" email address.

If one wants to keep distinct commit authors, it seems there's no way to also keep Github email private. Anyway, for the next time we'll try to switch user so that all commits show up under same account as PR creator.

@ojw28
Copy link
Contributor

ojw28 commented Jul 31, 2018

Re. CLA, @GiuseppePiscopo also has a signed CLA in google, using the same email address associated with Github. Problem is (we think), email preference on Github is set to private, hence commits appear authored by a [email protected], and it's not possible to sign a CLA under that "dummy" email address.

It turned out this was not the problem. The CLA bot is clever enough to look at the username in this case. The problem is solely that the pull request opener is different to the commit author. In this case there is no automated way for the CLA bot to validate that the commit author is OK with their commit being included in the pull request, which is why manual validation is necessary. Them having signed the CLA is not sufficient (since they might have signed it to contribute some completely unrelated change to another Google project).

We need the commit author to manually confirm they are OK with their commits being included in this case. Since additional commits were added after the comment you reference, we need the commit author to comment again on this thread, to cover the additional commits since that comment. Thanks!

@GiuseppePiscopo
Copy link
Contributor

I confirm I'm ok with including those additional commits as well

@ojw28 ojw28 merged commit 52b6b3b into google:dev-v2 Aug 16, 2018
@BrainCrumbz BrainCrumbz deleted the feat/playlist-remove-range branch August 16, 2018 16:35
@BrainCrumbz
Copy link
Contributor Author

How can we track when this PR will be included in a public release? Thanks

@ojw28
Copy link
Contributor

ojw28 commented Aug 17, 2018

It will be in 2.9.0 (for which we don't yet have a solid eta).

@google google locked and limited conversation to collaborators Dec 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants