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;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import org.checkerframework.checker.initialization.qual.UnderInitialization;
import org.checkerframework.checker.nullness.qual.NonNull;
......@@ -217,13 +216,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_STOP,
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.stop(controllerStub, seq);
}
});
(iSession, seq) -> iSession.stop(controllerStub, seq));
playerInfo =
playerInfo.copyWithSessionPositionInfo(
......@@ -306,12 +299,31 @@ import org.checkerframework.checker.nullness.qual.NonNull;
void run(IMediaSession iSession, int seq) throws RemoteException;
}
private ListenableFuture<SessionResult> dispatchRemoteSessionTaskWithPlayerCommand(
@Player.Command int command, RemoteSessionTask task) {
if (command != Player.COMMAND_SET_VIDEO_SURFACE) {
flushCommandQueueHandler.sendFlushCommandQueueMessage();
private void dispatchRemoteSessionTaskWithPlayerCommand(RemoteSessionTask task) {
flushCommandQueueHandler.sendFlushCommandQueueMessage();
dispatchRemoteSessionTask(iSession, task, /* addToPendingMaskingOperations= */ true);
}
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(
......@@ -328,7 +340,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
private ListenableFuture<SessionResult> dispatchRemoteSessionTaskWithSessionCommandInternal(
@SessionCommand.CommandCode int commandCode,
SessionCommand sessionCommand,
@Nullable SessionCommand sessionCommand,
RemoteSessionTask task) {
return dispatchRemoteSessionTask(
sessionCommand != null
......@@ -339,7 +351,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
private ListenableFuture<SessionResult> dispatchRemoteSessionTask(
IMediaSession iSession, RemoteSessionTask task, boolean addToPendingMaskingOperations) {
@Nullable IMediaSession iSession,
RemoteSessionTask task,
boolean addToPendingMaskingOperations) {
if (iSession != null) {
SequencedFutureManager.SequencedFuture<SessionResult> result =
sequencedFutureManager.createSequencedFuture(
......@@ -373,13 +387,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_PLAY_PAUSE,
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.play(controllerStub, seq);
}
});
(iSession, seq) -> iSession.play(controllerStub, seq));
setPlayWhenReady(
/* playWhenReady= */ true,
......@@ -394,13 +402,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_PLAY_PAUSE,
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.pause(controllerStub, seq);
}
});
(iSession, seq) -> iSession.pause(controllerStub, seq));
setPlayWhenReady(
/* playWhenReady= */ false,
......@@ -415,13 +417,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_PREPARE,
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.prepare(controllerStub, seq);
}
});
(iSession, seq) -> iSession.prepare(controllerStub, seq));
if (playerInfo.playbackState == Player.STATE_IDLE) {
PlayerInfo playerInfo =
......@@ -447,13 +443,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_DEFAULT_POSITION,
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.seekToDefaultPosition(controllerStub, seq);
}
});
(iSession, seq) -> iSession.seekToDefaultPosition(controllerStub, seq));
seekToInternal(getCurrentMediaItemIndex(), /* positionMs= */ C.TIME_UNSET);
}
......@@ -466,13 +456,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(mediaItemIndex >= 0);
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_MEDIA_ITEM,
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.seekToDefaultPositionWithMediaItemIndex(controllerStub, seq, mediaItemIndex);
}
});
(iSession, seq) ->
iSession.seekToDefaultPositionWithMediaItemIndex(controllerStub, seq, mediaItemIndex));
seekToInternal(mediaItemIndex, /* positionMs= */ C.TIME_UNSET);
}
......@@ -484,13 +469,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM,
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.seekTo(controllerStub, seq, positionMs);
}
});
(iSession, seq) -> iSession.seekTo(controllerStub, seq, positionMs));
seekToInternal(getCurrentMediaItemIndex(), positionMs);
}
......@@ -503,13 +482,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(mediaItemIndex >= 0);
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_MEDIA_ITEM,
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.seekToWithMediaItemIndex(controllerStub, seq, mediaItemIndex, positionMs);
}
});
(iSession, seq) ->
iSession.seekToWithMediaItemIndex(controllerStub, seq, mediaItemIndex, positionMs));
seekToInternal(mediaItemIndex, positionMs);
}
......@@ -526,7 +500,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_BACK, (iSession, seq) -> iSession.seekBack(controllerStub, seq));
(iSession, seq) -> iSession.seekBack(controllerStub, seq));
seekToInternalByOffset(-getSeekBackIncrement());
}
......@@ -543,7 +517,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_FORWARD, (iSession, seq) -> iSession.seekForward(controllerStub, seq));
(iSession, seq) -> iSession.seekForward(controllerStub, seq));
seekToInternalByOffset(getSeekForwardIncrement());
}
......@@ -560,7 +534,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_PLAY_PAUSE,
(iSession, seq) -> iSession.setPlayWhenReady(controllerStub, seq, playWhenReady));
setPlayWhenReady(
......@@ -697,7 +670,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_SPEED_AND_PITCH,
(iSession, seq) ->
iSession.setPlaybackParameters(controllerStub, seq, playbackParameters.toBundle()));
......@@ -723,7 +695,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_SPEED_AND_PITCH,
(iSession, seq) -> iSession.setPlaybackSpeed(controllerStub, seq, speed));
if (playerInfo.playbackParameters.speed != speed) {
......@@ -746,24 +717,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public ListenableFuture<SessionResult> setRating(String mediaId, Rating rating) {
return dispatchRemoteSessionTaskWithSessionCommand(
SessionCommand.COMMAND_CODE_SESSION_SET_RATING,
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.setRatingWithMediaId(controllerStub, seq, mediaId, rating.toBundle());
}
});
(iSession, seq) ->
iSession.setRatingWithMediaId(controllerStub, seq, mediaId, rating.toBundle()));
}
@Override
public ListenableFuture<SessionResult> setRating(Rating rating) {
return dispatchRemoteSessionTaskWithSessionCommand(
SessionCommand.COMMAND_CODE_SESSION_SET_RATING,
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.setRating(controllerStub, seq, rating.toBundle());
}
});
(iSession, seq) -> iSession.setRating(controllerStub, seq, rating.toBundle()));
}
@Override
......@@ -785,7 +747,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_MEDIA_ITEM,
(iSession, seq) -> iSession.setMediaItem(controllerStub, seq, mediaItem.toBundle()));
setMediaItemsInternal(
......@@ -802,7 +763,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_MEDIA_ITEM,
(iSession, seq) ->
iSession.setMediaItemWithStartPosition(
controllerStub, seq, mediaItem.toBundle(), startPositionMs));
......@@ -821,7 +781,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_MEDIA_ITEM,
(iSession, seq) ->
iSession.setMediaItemWithResetPosition(
controllerStub, seq, mediaItem.toBundle(), resetPosition));
......@@ -840,7 +799,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) ->
iSession.setMediaItems(
controllerStub,
......@@ -861,7 +819,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) ->
iSession.setMediaItemsWithResetPosition(
controllerStub,
......@@ -883,7 +840,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) ->
iSession.setMediaItemsWithStartIndex(
controllerStub,
......@@ -903,7 +859,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_MEDIA_ITEMS_METADATA,
(iSession, seq) ->
iSession.setPlaylistMetadata(controllerStub, seq, playlistMetadata.toBundle()));
......@@ -928,7 +883,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> iSession.addMediaItem(controllerStub, seq, mediaItem.toBundle()));
addMediaItemsInternal(
......@@ -943,7 +897,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(index >= 0);
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) ->
iSession.addMediaItemWithIndex(controllerStub, seq, index, mediaItem.toBundle()));
......@@ -957,7 +910,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) ->
iSession.addMediaItems(
controllerStub,
......@@ -975,7 +927,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(index >= 0);
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) ->
iSession.addMediaItemsWithIndex(
controllerStub,
......@@ -1045,7 +996,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(index >= 0);
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> iSession.removeMediaItem(controllerStub, seq, index));
removeMediaItemsInternal(/* fromIndex= */ index, /* toIndex= */ index + 1);
......@@ -1059,7 +1009,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(fromIndex >= 0 && toIndex >= fromIndex);
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> iSession.removeMediaItems(controllerStub, seq, fromIndex, toIndex));
removeMediaItemsInternal(fromIndex, toIndex);
......@@ -1072,7 +1021,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> iSession.clearMediaItems(controllerStub, seq));
removeMediaItemsInternal(/* fromIndex= */ 0, /* toIndex= */ Integer.MAX_VALUE);
......@@ -1224,7 +1172,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(currentIndex >= 0 && newIndex >= 0);
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) -> iSession.moveMediaItem(controllerStub, seq, currentIndex, newIndex));
moveMediaItemsInternal(
......@@ -1239,7 +1186,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
checkArgument(fromIndex >= 0 && fromIndex <= toIndex && newIndex >= 0);
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_CHANGE_MEDIA_ITEMS,
(iSession, seq) ->
iSession.moveMediaItems(controllerStub, seq, fromIndex, toIndex, newIndex));
......@@ -1297,7 +1243,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM,
(iSession, seq) -> iSession.seekToPreviousMediaItem(controllerStub, seq));
if (getPreviousMediaItemIndex() != C.INDEX_UNSET) {
......@@ -1312,7 +1257,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM,
(iSession, seq) -> iSession.seekToNextMediaItem(controllerStub, seq));
if (getNextMediaItemIndex() != C.INDEX_UNSET) {
......@@ -1327,7 +1271,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_PREVIOUS,
(iSession, seq) -> iSession.seekToPrevious(controllerStub, seq));
Timeline timeline = getCurrentTimeline();
......@@ -1359,7 +1302,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SEEK_TO_NEXT, (iSession, seq) -> iSession.seekToNext(controllerStub, seq));
(iSession, seq) -> iSession.seekToNext(controllerStub, seq));
Timeline timeline = getCurrentTimeline();
if (timeline.isEmpty() || isPlayingAd()) {
......@@ -1387,13 +1330,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_REPEAT_MODE,
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.setRepeatMode(controllerStub, seq, repeatMode);
}
});
(iSession, seq) -> iSession.setRepeatMode(controllerStub, seq, repeatMode));
if (playerInfo.repeatMode != repeatMode) {
playerInfo = playerInfo.copyWithRepeatMode(repeatMode);
......@@ -1417,13 +1354,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_SHUFFLE_MODE,
new RemoteSessionTask() {
@Override
public void run(IMediaSession iSession, int seq) throws RemoteException {
iSession.setShuffleModeEnabled(controllerStub, seq, shuffleModeEnabled);
}
});
(iSession, seq) -> iSession.setShuffleModeEnabled(controllerStub, seq, shuffleModeEnabled));
if (playerInfo.shuffleModeEnabled != shuffleModeEnabled) {
playerInfo = playerInfo.copyWithShuffleModeEnabled(shuffleModeEnabled);
......@@ -1452,7 +1383,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_VOLUME,
(iSession, seq) -> iSession.setVolume(controllerStub, seq, volume));
if (playerInfo.volume != volume) {
......@@ -1486,7 +1416,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_DEVICE_VOLUME,
(iSession, seq) -> iSession.setDeviceVolume(controllerStub, seq, volume));
if (playerInfo.deviceVolume != volume) {
......@@ -1506,7 +1435,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_ADJUST_DEVICE_VOLUME,
(iSession, seq) -> iSession.increaseDeviceVolume(controllerStub, seq));
int newDeviceVolume = playerInfo.deviceVolume + 1;
......@@ -1526,7 +1454,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_ADJUST_DEVICE_VOLUME,
(iSession, seq) -> iSession.decreaseDeviceVolume(controllerStub, seq));
int newDeviceVolume = playerInfo.deviceVolume - 1;
......@@ -1546,7 +1473,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_DEVICE_VOLUME,
(iSession, seq) -> iSession.setDeviceMuted(controllerStub, seq, muted));
if (playerInfo.deviceMuted != muted) {
......@@ -1575,7 +1501,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
clearSurfacesAndCallbacks();
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(/* surface= */ null);
/* surface= */ dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, null));
maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
}
......@@ -1599,7 +1526,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
clearSurfacesAndCallbacks();
videoSurface = surface;
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(surface);
dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, surface));
int newSurfaceSize = surface == null ? 0 : C.LENGTH_UNSET;
maybeNotifySurfaceSizeChanged(/* width= */ newSurfaceSize, /* height= */ newSurfaceSize);
}
......@@ -1625,12 +1553,14 @@ import org.checkerframework.checker.nullness.qual.NonNull;
@Nullable Surface surface = surfaceHolder.getSurface();
if (surface != null && surface.isValid()) {
videoSurface = surface;
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(surface);
dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, surface));
Rect surfaceSize = surfaceHolder.getSurfaceFrame();
maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height());
} else {
videoSurface = null;
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(/* surface= */ null);
/* surface= */ dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, null));
maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
}
}
......@@ -1688,11 +1618,13 @@ import org.checkerframework.checker.nullness.qual.NonNull;
@Nullable SurfaceTexture surfaceTexture = textureView.getSurfaceTexture();
if (surfaceTexture == null) {
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(/* surface= */ null);
/* surface= */ dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, null));
maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
} else {
videoSurface = new Surface(surfaceTexture);
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(videoSurface);
dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, videoSurface));
maybeNotifySurfaceSizeChanged(textureView.getWidth(), textureView.getHeight());
}
}
......@@ -1736,7 +1668,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
}
dispatchRemoteSessionTaskWithPlayerCommand(
Player.COMMAND_SET_TRACK_SELECTION_PARAMETERS,
(iSession, seq) ->
iSession.setTrackSelectionParameters(controllerStub, seq, parameters.toBundle()));
......@@ -2157,30 +2088,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
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() {
if (videoTextureView != null) {
videoTextureView.setSurfaceTextureListener(null);
......@@ -2988,7 +2895,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
return;
}
videoSurface = holder.getSurface();
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(videoSurface);
dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, videoSurface));
Rect surfaceSize = holder.getSurfaceFrame();
maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height());
}
......@@ -3007,7 +2915,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
return;
}
videoSurface = null;
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(/* surface= */ null);
/* surface= */ dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, null));
maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
}
......@@ -3019,7 +2928,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
return;
}
videoSurface = new Surface(surfaceTexture);
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(videoSurface);
dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, videoSurface));
maybeNotifySurfaceSizeChanged(width, height);
}
......@@ -3037,7 +2947,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
return true;
}
videoSurface = null;
dispatchRemoteSetVideoSurfaceTaskAndWaitForFuture(/* surface= */ null);
/* surface= */ dispatchRemoteSessionTaskWithPlayerCommandAndWaitForFuture(
(iSession, seq) -> iSession.setVideoSurface(controllerStub, seq, null));
maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
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