Commit 664ab72d by tonihei Committed by Rohit Singh

Remove unneccesary parameter taking Player.Command

The method to dispatch actions in MediaControllerImplBase takes
a Player.Command, but the value is only used to check if we
are setting a surface and need to handle the special blocking
call. This can be cleaned up by removing the parameter and calling
a dedicated blocking method where needed. This also ensures we
have to mention the relevant Player.Command only once in each
method.

PiperOrigin-RevId: 502341862
parent 86a95c2a
...@@ -91,7 +91,6 @@ import java.util.Collections; ...@@ -91,7 +91,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import org.checkerframework.checker.initialization.qual.UnderInitialization; import org.checkerframework.checker.initialization.qual.UnderInitialization;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
...@@ -217,13 +216,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -217,13 +216,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_STOP, (iSession, seq) -> iSession.stop(controllerStub, seq));
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.stop(controllerStub, seq);
}
});
playerInfo = playerInfo =
playerInfo.copyWithSessionPositionInfo( playerInfo.copyWithSessionPositionInfo(
...@@ -306,12 +299,31 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -306,12 +299,31 @@ import org.checkerframework.checker.nullness.qual.NonNull;
void run(IMediaSession iSession, int seq) throws RemoteException; void run(IMediaSession iSession, int seq) throws RemoteException;
} }
private ListenableFuture<SessionResult> dispatchRemoteSessionTaskWithPlayerCommand( private void dispatchRemoteSessionTaskWithPlayerCommand(RemoteSessionTask task) {
@Player.Command int command, RemoteSessionTask task) { flushCommandQueueHandler.sendFlushCommandQueueMessage();
if (command != Player.COMMAND_SET_VIDEO_SURFACE) { dispatchRemoteSessionTask(iSession, task, /* addToPendingMaskingOperations= */ true);
flushCommandQueueHandler.sendFlushCommandQueueMessage(); }
private void dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(RemoteSessionTask task) {
// Do not send a flush command queue message as we are actively waiting for task.
ListenableFuture<SessionResult> future =
dispatchRemoteSessionTask(iSession, task, /* addToPendingMaskingOperations= */ true);
try {
MediaUtils.getFutureResult(future, /* timeoutMs= */ 3_000);
} catch (ExecutionException e) {
// Never happens because future.setException will not be called.
throw new IllegalStateException(e);
} catch (TimeoutException e) {
if (future instanceof SequencedFutureManager.SequencedFuture) {
int sequenceNumber =
((SequencedFutureManager.SequencedFuture<SessionResult>) future).getSequenceNumber();
pendingMaskingSequencedFutureNumbers.remove(sequenceNumber);
sequencedFutureManager.setFutureResult(
sequenceNumber, new SessionResult(SessionResult.RESULT_ERROR_UNKNOWN));
}
Log.w(TAG, "Synchronous command takes too long on the session side.", e);
// TODO(b/188888693): Let developers know the failure in their code.
} }
return dispatchRemoteSessionTask(iSession, task, /* addToPendingMaskingOperations= */ true);
} }
private ListenableFuture<SessionResult> dispatchRemoteSessionTaskWithSessionCommand( private ListenableFuture<SessionResult> dispatchRemoteSessionTaskWithSessionCommand(
...@@ -328,7 +340,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -328,7 +340,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
private ListenableFuture<SessionResult> dispatchRemoteSessionTaskWithSessionCommandInternal( private ListenableFuture<SessionResult> dispatchRemoteSessionTaskWithSessionCommandInternal(
@SessionCommand.CommandCode int commandCode, @SessionCommand.CommandCode int commandCode,
SessionCommand sessionCommand, @Nullable SessionCommand sessionCommand,
RemoteSessionTask task) { RemoteSessionTask task) {
return dispatchRemoteSessionTask( return dispatchRemoteSessionTask(
sessionCommand != null sessionCommand != null
...@@ -339,7 +351,9 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -339,7 +351,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
private ListenableFuture<SessionResult> dispatchRemoteSessionTask( private ListenableFuture<SessionResult> dispatchRemoteSessionTask(
IMediaSession iSession, RemoteSessionTask task, boolean addToPendingMaskingOperations) { @Nullable IMediaSession iSession,
RemoteSessionTask task,
boolean addToPendingMaskingOperations) {
if (iSession != null) { if (iSession != null) {
SequencedFutureManager.SequencedFuture<SessionResult> result = SequencedFutureManager.SequencedFuture<SessionResult> result =
sequencedFutureManager.createSequencedFuture( sequencedFutureManager.createSequencedFuture(
...@@ -373,13 +387,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -373,13 +387,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_PLAY_PAUSE, (iSession, seq) -> iSession.play(controllerStub, seq));
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.play(controllerStub, seq);
}
});
setPlayWhenReady( setPlayWhenReady(
/* playWhenReady= */ true, /* playWhenReady= */ true,
...@@ -394,13 +402,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -394,13 +402,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_PLAY_PAUSE, (iSession, seq) -> iSession.pause(controllerStub, seq));
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.pause(controllerStub, seq);
}
});
setPlayWhenReady( setPlayWhenReady(
/* playWhenReady= */ false, /* playWhenReady= */ false,
...@@ -415,13 +417,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -415,13 +417,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_PREPARE, (iSession, seq) -> iSession.prepare(controllerStub, seq));
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.prepare(controllerStub, seq);
}
});
if (playerInfo.playbackState == Player.STATE_IDLE) { if (playerInfo.playbackState == Player.STATE_IDLE) {
PlayerInfo playerInfo = PlayerInfo playerInfo =
...@@ -447,13 +443,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -447,13 +443,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_DEFAULT_POSITION, (iSession, seq) -> iSession.seekToDefaultPosition(controllerStub, seq));
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.seekToDefaultPosition(controllerStub, seq);
}
});
seekToInternal(getCurrentMediaItemIndex(), /* positionMs= */ C.TIME_UNSET); seekToInternal(getCurrentMediaItemIndex(), /* positionMs= */ C.TIME_UNSET);
} }
...@@ -466,13 +456,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -466,13 +456,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(mediaItemIndex >= 0); checkArgument(mediaItemIndex >= 0);
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_MEDIA_ITEM, (iSession, seq) ->
new RemoteSessionTask() { iSession.seekToDefaultPositionWithMediaItemIndex(controllerStub, seq, mediaItemIndex));
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.seekToDefaultPositionWithMediaItemIndex(controllerStub, seq, mediaItemIndex);
}
});
seekToInternal(mediaItemIndex, /* positionMs= */ C.TIME_UNSET); seekToInternal(mediaItemIndex, /* positionMs= */ C.TIME_UNSET);
} }
...@@ -484,13 +469,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -484,13 +469,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM, (iSession, seq) -> iSession.seekTo(controllerStub, seq, positionMs));
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.seekTo(controllerStub, seq, positionMs);
}
});
seekToInternal(getCurrentMediaItemIndex(), positionMs); seekToInternal(getCurrentMediaItemIndex(), positionMs);
} }
...@@ -503,13 +482,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -503,13 +482,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(mediaItemIndex >= 0); checkArgument(mediaItemIndex >= 0);
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_MEDIA_ITEM, (iSession, seq) ->
new RemoteSessionTask() { iSession.seekToWithMediaItemIndex(controllerStub, seq, mediaItemIndex, positionMs));
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.seekToWithMediaItemIndex(controllerStub, seq, mediaItemIndex, positionMs);
}
});
seekToInternal(mediaItemIndex, positionMs); seekToInternal(mediaItemIndex, positionMs);
} }
...@@ -526,7 +500,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -526,7 +500,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_BACK, (iSession, seq) -> iSession.seekBack(controllerStub, seq)); (iSession, seq) -> iSession.seekBack(controllerStub, seq));
seekToInternalByOffset(-getSeekBackIncrement()); seekToInternalByOffset(-getSeekBackIncrement());
} }
...@@ -543,7 +517,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -543,7 +517,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_FORWARD, (iSession, seq) -> iSession.seekForward(controllerStub, seq)); (iSession, seq) -> iSession.seekForward(controllerStub, seq));
seekToInternalByOffset(getSeekForwardIncrement()); seekToInternalByOffset(getSeekForwardIncrement());
} }
...@@ -560,7 +534,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -560,7 +534,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_PLAY_PAUSE,
(iSession, seq) -> iSession.setPlayWhenReady(controllerStub, seq, playWhenReady)); (iSession, seq) -> iSession.setPlayWhenReady(controllerStub, seq, playWhenReady));
setPlayWhenReady( setPlayWhenReady(
...@@ -697,7 +670,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -697,7 +670,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_SPEED_AND_PITCH,
(iSession, seq) -> (iSession, seq) ->
iSession.setPlaybackParameters(controllerStub, seq, playbackParameters.toBundle())); iSession.setPlaybackParameters(controllerStub, seq, playbackParameters.toBundle()));
...@@ -723,7 +695,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -723,7 +695,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_SPEED_AND_PITCH,
(iSession, seq) -> iSession.setPlaybackSpeed(controllerStub, seq, speed)); (iSession, seq) -> iSession.setPlaybackSpeed(controllerStub, seq, speed));
if (playerInfo.playbackParameters.speed != speed) { if (playerInfo.playbackParameters.speed != speed) {
...@@ -746,24 +717,15 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -746,24 +717,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public ListenableFuture<SessionResult> setRating(String mediaId, Rating rating) { public ListenableFuture<SessionResult> setRating(String mediaId, Rating rating) {
return dispatchRemoteSessionTaskWithSessionCommand( return dispatchRemoteSessionTaskWithSessionCommand(
SessionCommand.COMMAND_CODE_SESSION_SET_RATING, SessionCommand.COMMAND_CODE_SESSION_SET_RATING,
new RemoteSessionTask() { (iSession, seq) ->
@Override iSession.setRatingWithMediaId(controllerStub, seq, mediaId, rating.toBundle()));
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.setRatingWithMediaId(controllerStub, seq, mediaId, rating.toBundle());
}
});
} }
@Override @Override
public ListenableFuture<SessionResult> setRating(Rating rating) { public ListenableFuture<SessionResult> setRating(Rating rating) {
return dispatchRemoteSessionTaskWithSessionCommand( return dispatchRemoteSessionTaskWithSessionCommand(
SessionCommand.COMMAND_CODE_SESSION_SET_RATING, SessionCommand.COMMAND_CODE_SESSION_SET_RATING,
new RemoteSessionTask() { (iSession, seq) -> iSession.setRating(controllerStub, seq, rating.toBundle()));
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.setRating(controllerStub, seq, rating.toBundle());
}
});
} }
@Override @Override
...@@ -785,7 +747,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -785,7 +747,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_MEDIA_ITEM,
(iSession, seq) -> iSession.setMediaItem(controllerStub, seq, mediaItem.toBundle())); (iSession, seq) -> iSession.setMediaItem(controllerStub, seq, mediaItem.toBundle()));
setMediaItemsInternal( setMediaItemsInternal(
...@@ -802,7 +763,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -802,7 +763,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_MEDIA_ITEM,
(iSession, seq) -> (iSession, seq) ->
iSession.setMediaItemWithStartPosition( iSession.setMediaItemWithStartPosition(
controllerStub, seq, mediaItem.toBundle(), startPositionMs)); controllerStub, seq, mediaItem.toBundle(), startPositionMs));
...@@ -821,7 +781,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -821,7 +781,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_MEDIA_ITEM,
(iSession, seq) -> (iSession, seq) ->
iSession.setMediaItemWithResetPosition( iSession.setMediaItemWithResetPosition(
controllerStub, seq, mediaItem.toBundle(), resetPosition)); controllerStub, seq, mediaItem.toBundle(), resetPosition));
...@@ -840,7 +799,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -840,7 +799,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> (iSession, seq) ->
iSession.setMediaItems( iSession.setMediaItems(
controllerStub, controllerStub,
...@@ -861,7 +819,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -861,7 +819,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> (iSession, seq) ->
iSession.setMediaItemsWithResetPosition( iSession.setMediaItemsWithResetPosition(
controllerStub, controllerStub,
...@@ -883,7 +840,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -883,7 +840,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> (iSession, seq) ->
iSession.setMediaItemsWithStartIndex( iSession.setMediaItemsWithStartIndex(
controllerStub, controllerStub,
...@@ -903,7 +859,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -903,7 +859,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_MEDIA_ITEMS_METADATA,
(iSession, seq) -> (iSession, seq) ->
iSession.setPlaylistMetadata(controllerStub, seq, playlistMetadata.toBundle())); iSession.setPlaylistMetadata(controllerStub, seq, playlistMetadata.toBundle()));
...@@ -928,7 +883,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -928,7 +883,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> iSession.addMediaItem(controllerStub, seq, mediaItem.toBundle())); (iSession, seq) -> iSession.addMediaItem(controllerStub, seq, mediaItem.toBundle()));
addMediaItemsInternal( addMediaItemsInternal(
...@@ -943,7 +897,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -943,7 +897,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(index >= 0); checkArgument(index >= 0);
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> (iSession, seq) ->
iSession.addMediaItemWithIndex(controllerStub, seq, index, mediaItem.toBundle())); iSession.addMediaItemWithIndex(controllerStub, seq, index, mediaItem.toBundle()));
...@@ -957,7 +910,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -957,7 +910,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> (iSession, seq) ->
iSession.addMediaItems( iSession.addMediaItems(
controllerStub, controllerStub,
...@@ -975,7 +927,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -975,7 +927,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(index >= 0); checkArgument(index >= 0);
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> (iSession, seq) ->
iSession.addMediaItemsWithIndex( iSession.addMediaItemsWithIndex(
controllerStub, controllerStub,
...@@ -1045,7 +996,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1045,7 +996,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(index >= 0); checkArgument(index >= 0);
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> iSession.removeMediaItem(controllerStub, seq, index)); (iSession, seq) -> iSession.removeMediaItem(controllerStub, seq, index));
removeMediaItemsInternal(/* fromIndex= */ index, /* toIndex= */ index + 1); removeMediaItemsInternal(/* fromIndex= */ index, /* toIndex= */ index + 1);
...@@ -1059,7 +1009,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1059,7 +1009,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(fromIndex >= 0 && toIndex >= fromIndex); checkArgument(fromIndex >= 0 && toIndex >= fromIndex);
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> iSession.removeMediaItems(controllerStub, seq, fromIndex, toIndex)); (iSession, seq) -> iSession.removeMediaItems(controllerStub, seq, fromIndex, toIndex));
removeMediaItemsInternal(fromIndex, toIndex); removeMediaItemsInternal(fromIndex, toIndex);
...@@ -1072,7 +1021,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1072,7 +1021,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> iSession.clearMediaItems(controllerStub, seq)); (iSession, seq) -> iSession.clearMediaItems(controllerStub, seq));
removeMediaItemsInternal(/* fromIndex= */ 0, /* toIndex= */ Integer.MAX_VALUE); removeMediaItemsInternal(/* fromIndex= */ 0, /* toIndex= */ Integer.MAX_VALUE);
...@@ -1224,7 +1172,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1224,7 +1172,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(currentIndex >= 0 && newIndex >= 0); checkArgument(currentIndex >= 0 && newIndex >= 0);
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> iSession.moveMediaItem(controllerStub, seq, currentIndex, newIndex)); (iSession, seq) -> iSession.moveMediaItem(controllerStub, seq, currentIndex, newIndex));
moveMediaItemsInternal( moveMediaItemsInternal(
...@@ -1239,7 +1186,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1239,7 +1186,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(fromIndex >= 0 && fromIndex <= toIndex && newIndex >= 0); checkArgument(fromIndex >= 0 && fromIndex <= toIndex && newIndex >= 0);
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> (iSession, seq) ->
iSession.moveMediaItems(controllerStub, seq, fromIndex, toIndex, newIndex)); iSession.moveMediaItems(controllerStub, seq, fromIndex, toIndex, newIndex));
...@@ -1297,7 +1243,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1297,7 +1243,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM,
(iSession, seq) -> iSession.seekToPreviousMediaItem(controllerStub, seq)); (iSession, seq) -> iSession.seekToPreviousMediaItem(controllerStub, seq));
if (getPreviousMediaItemIndex() != C.INDEX_UNSET) { if (getPreviousMediaItemIndex() != C.INDEX_UNSET) {
...@@ -1312,7 +1257,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1312,7 +1257,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM,
(iSession, seq) -> iSession.seekToNextMediaItem(controllerStub, seq)); (iSession, seq) -> iSession.seekToNextMediaItem(controllerStub, seq));
if (getNextMediaItemIndex() != C.INDEX_UNSET) { if (getNextMediaItemIndex() != C.INDEX_UNSET) {
...@@ -1327,7 +1271,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1327,7 +1271,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_PREVIOUS,
(iSession, seq) -> iSession.seekToPrevious(controllerStub, seq)); (iSession, seq) -> iSession.seekToPrevious(controllerStub, seq));
Timeline timeline = getCurrentTimeline(); Timeline timeline = getCurrentTimeline();
...@@ -1359,7 +1302,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1359,7 +1302,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_NEXT, (iSession, seq) -> iSession.seekToNext(controllerStub, seq)); (iSession, seq) -> iSession.seekToNext(controllerStub, seq));
Timeline timeline = getCurrentTimeline(); Timeline timeline = getCurrentTimeline();
if (timeline.isEmpty() || isPlayingAd()) { if (timeline.isEmpty() || isPlayingAd()) {
...@@ -1387,13 +1330,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1387,13 +1330,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_REPEAT_MODE, (iSession, seq) -> iSession.setRepeatMode(controllerStub, seq, repeatMode));
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.setRepeatMode(controllerStub, seq, repeatMode);
}
});
if (playerInfo.repeatMode != repeatMode) { if (playerInfo.repeatMode != repeatMode) {
playerInfo = playerInfo.copyWithRepeatMode(repeatMode); playerInfo = playerInfo.copyWithRepeatMode(repeatMode);
...@@ -1417,13 +1354,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1417,13 +1354,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_SHUFFLE_MODE, (iSession, seq) -> iSession.setShuffleModeEnabled(controllerStub, seq, shuffleModeEnabled));
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.setShuffleModeEnabled(controllerStub, seq, shuffleModeEnabled);
}
});
if (playerInfo.shuffleModeEnabled != shuffleModeEnabled) { if (playerInfo.shuffleModeEnabled != shuffleModeEnabled) {
playerInfo = playerInfo.copyWithShuffleModeEnabled(shuffleModeEnabled); playerInfo = playerInfo.copyWithShuffleModeEnabled(shuffleModeEnabled);
...@@ -1452,7 +1383,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1452,7 +1383,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_VOLUME,
(iSession, seq) -> iSession.setVolume(controllerStub, seq, volume)); (iSession, seq) -> iSession.setVolume(controllerStub, seq, volume));
if (playerInfo.volume != volume) { if (playerInfo.volume != volume) {
...@@ -1486,7 +1416,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1486,7 +1416,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_DEVICE_VOLUME,
(iSession, seq) -> iSession.setDeviceVolume(controllerStub, seq, volume)); (iSession, seq) -> iSession.setDeviceVolume(controllerStub, seq, volume));
if (playerInfo.deviceVolume != volume) { if (playerInfo.deviceVolume != volume) {
...@@ -1506,7 +1435,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1506,7 +1435,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_ADJUST_DEVICE_VOLUME,
(iSession, seq) -> iSession.increaseDeviceVolume(controllerStub, seq)); (iSession, seq) -> iSession.increaseDeviceVolume(controllerStub, seq));
int newDeviceVolume = playerInfo.deviceVolume + 1; int newDeviceVolume = playerInfo.deviceVolume + 1;
...@@ -1526,7 +1454,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1526,7 +1454,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_ADJUST_DEVICE_VOLUME,
(iSession, seq) -> iSession.decreaseDeviceVolume(controllerStub, seq)); (iSession, seq) -> iSession.decreaseDeviceVolume(controllerStub, seq));
int newDeviceVolume = playerInfo.deviceVolume - 1; int newDeviceVolume = playerInfo.deviceVolume - 1;
...@@ -1546,7 +1473,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1546,7 +1473,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_DEVICE_VOLUME,
(iSession, seq) -> iSession.setDeviceMuted(controllerStub, seq, muted)); (iSession, seq) -> iSession.setDeviceMuted(controllerStub, seq, muted));
if (playerInfo.deviceMuted != muted) { if (playerInfo.deviceMuted != muted) {
...@@ -1575,7 +1501,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1575,7 +1501,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
clearSurfacesAndCallbacks(); clearSurfacesAndCallbacks();
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(/* surface= */ null); /* surface= */ dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, null));
maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
} }
...@@ -1599,7 +1526,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1599,7 +1526,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
clearSurfacesAndCallbacks(); clearSurfacesAndCallbacks();
videoSurface = surface; videoSurface = surface;
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(surface); dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, surface));
int newSurfaceSize = surface == null ? 0 : C.LENGTH_UNSET; int newSurfaceSize = surface == null ? 0 : C.LENGTH_UNSET;
maybeNotifySurfaceSizeChanged(/* width= */ newSurfaceSize, /* height= */ newSurfaceSize); maybeNotifySurfaceSizeChanged(/* width= */ newSurfaceSize, /* height= */ newSurfaceSize);
} }
...@@ -1625,12 +1553,14 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1625,12 +1553,14 @@ import org.checkerframework.checker.nullness.qual.NonNull;
@Nullable Surface surface = surfaceHolder.getSurface(); @Nullable Surface surface = surfaceHolder.getSurface();
if (surface != null && surface.isValid()) { if (surface != null && surface.isValid()) {
videoSurface = surface; videoSurface = surface;
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(surface); dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, surface));
Rect surfaceSize = surfaceHolder.getSurfaceFrame(); Rect surfaceSize = surfaceHolder.getSurfaceFrame();
maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height()); maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height());
} else { } else {
videoSurface = null; videoSurface = null;
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(/* surface= */ null); /* surface= */ dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, null));
maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
} }
} }
...@@ -1688,11 +1618,13 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1688,11 +1618,13 @@ import org.checkerframework.checker.nullness.qual.NonNull;
@Nullable SurfaceTexture surfaceTexture = textureView.getSurfaceTexture(); @Nullable SurfaceTexture surfaceTexture = textureView.getSurfaceTexture();
if (surfaceTexture == null) { if (surfaceTexture == null) {
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(/* surface= */ null); /* surface= */ dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, null));
maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
} else { } else {
videoSurface = new Surface(surfaceTexture); videoSurface = new Surface(surfaceTexture);
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(videoSurface); dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, videoSurface));
maybeNotifySurfaceSizeChanged(textureView.getWidth(), textureView.getHeight()); maybeNotifySurfaceSizeChanged(textureView.getWidth(), textureView.getHeight());
} }
} }
...@@ -1736,7 +1668,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -1736,7 +1668,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
} }
dispatchRemoteSessionTaskWithPlayerCommand( dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_TRACK_SELECTION_PARAMETERS,
(iSession, seq) -> (iSession, seq) ->
iSession.setTrackSelectionParameters(controllerStub, seq, parameters.toBundle())); iSession.setTrackSelectionParameters(controllerStub, seq, parameters.toBundle()));
...@@ -2157,30 +2088,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -2157,30 +2088,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
return true; return true;
} }
private void dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(@Nullable Surface surface) {
Future<SessionResult> future =
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_VIDEO_SURFACE,
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, surface));
try {
MediaUtils.getFutureResult(future, /* timeoutMs= */ 3_000);
} catch (ExecutionException e) {
// Never happens because future.setException will not be called.
throw new IllegalStateException(e);
} catch (TimeoutException e) {
if (future instanceof SequencedFutureManager.SequencedFuture) {
int sequenceNumber =
((SequencedFutureManager.SequencedFuture<SessionResult>) future).getSequenceNumber();
pendingMaskingSequencedFutureNumbers.remove(sequenceNumber);
sequencedFutureManager.setFutureResult(
sequenceNumber, new SessionResult(SessionResult.RESULT_ERROR_UNKNOWN));
}
Log.w(TAG, "set/clearVideoSurface takes too long on the session side.", e);
// TODO(b/188888693): Let developers know the failure in their code.
}
}
private void clearSurfacesAndCallbacks() { private void clearSurfacesAndCallbacks() {
if (videoTextureView != null) { if (videoTextureView != null) {
videoTextureView.setSurfaceTextureListener(null); videoTextureView.setSurfaceTextureListener(null);
...@@ -2988,7 +2895,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -2988,7 +2895,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
return; return;
} }
videoSurface = holder.getSurface(); videoSurface = holder.getSurface();
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(videoSurface); dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, videoSurface));
Rect surfaceSize = holder.getSurfaceFrame(); Rect surfaceSize = holder.getSurfaceFrame();
maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height()); maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height());
} }
...@@ -3007,7 +2915,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -3007,7 +2915,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
return; return;
} }
videoSurface = null; videoSurface = null;
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(/* surface= */ null); /* surface= */ dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, null));
maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
} }
...@@ -3019,7 +2928,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -3019,7 +2928,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
return; return;
} }
videoSurface = new Surface(surfaceTexture); videoSurface = new Surface(surfaceTexture);
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(videoSurface); dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, videoSurface));
maybeNotifySurfaceSizeChanged(width, height); maybeNotifySurfaceSizeChanged(width, height);
} }
...@@ -3037,7 +2947,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; ...@@ -3037,7 +2947,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
return true; return true;
} }
videoSurface = null; videoSurface = null;
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(/* surface= */ null); /* surface= */ dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, null));
maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0); maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment