Commit b5bd6b36 authored by Thomas Guilbert's avatar Thomas Guilbert Committed by Commit Bot

Cleanup temp GMS seeking fix

One of the versions of GMS core had a bug, where seeks timing out would
cause a crash, leading to crbug.com/914072. The fix at the time was to
send manually-crafted 'seek' messages, instead of using the API.

The issue was in a single version of GMS core, and the roll in
crbug.com/958461 should have fixed it.

This CL removes the temp fix, and switches back to using the normal API.

Bug: 918644
Change-Id: I335493d535166f5154f8127f4001192ffbebff53
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134399Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Commit-Queue: Thomas Guilbert <tguilbert@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756428}
parent ddcb2103
...@@ -9,12 +9,6 @@ import androidx.annotation.Nullable; ...@@ -9,12 +9,6 @@ import androidx.annotation.Nullable;
import com.google.android.gms.cast.CastDevice; import com.google.android.gms.cast.CastDevice;
import com.google.android.gms.cast.framework.CastSession; import com.google.android.gms.cast.framework.CastSession;
import com.google.android.gms.cast.framework.media.RemoteMediaClient; import com.google.android.gms.cast.framework.media.RemoteMediaClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.Status;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.chrome.browser.media.router.CastSessionUtil; import org.chromium.chrome.browser.media.router.CastSessionUtil;
...@@ -24,7 +18,6 @@ import org.chromium.chrome.browser.media.router.MediaSource; ...@@ -24,7 +18,6 @@ import org.chromium.chrome.browser.media.router.MediaSource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
/** /**
* A base wrapper for {@link CastSession}, extending its functionality for Chrome MediaRouter. * A base wrapper for {@link CastSession}, extending its functionality for Chrome MediaRouter.
...@@ -49,9 +42,7 @@ public abstract class BaseSessionController { ...@@ -49,9 +42,7 @@ public abstract class BaseSessionController {
void onMetadataUpdated(); void onMetadataUpdated();
} }
private final Random mRequestIdGenerator = new Random();
private CastSession mCastSession; private CastSession mCastSession;
private int mLatestMediaSessionId;
private final CafBaseMediaRouteProvider mProvider; private final CafBaseMediaRouteProvider mProvider;
private CreateRouteRequestInfo mRouteCreationInfo; private CreateRouteRequestInfo mRouteCreationInfo;
private final RemoteMediaClient.Callback mRemoteMediaClientCallback; private final RemoteMediaClient.Callback mRemoteMediaClientCallback;
...@@ -131,44 +122,6 @@ public abstract class BaseSessionController { ...@@ -131,44 +122,6 @@ public abstract class BaseSessionController {
return mCastSession != null && mCastSession.isConnected(); return mCastSession != null && mCastSession.isConnected();
} }
/**
* Safely seek to a position. This is an workaround for an IllegalStateException in
* RemoteMediaClient when a seek command times out. The code should be replaced by a normal
* seek() call when the Google Play services SDK gets updated.
*/
public PendingResult<Status> safelySeek(long position) {
JSONObject json = new JSONObject();
try {
json.put("requestId", mRequestIdGenerator.nextInt(10000));
json.put("mediaSessionId", mLatestMediaSessionId);
json.put("type", "SEEK");
json.put("currentTime", position / 1000.0);
} catch (JSONException e) {
// Ignore.
}
return getSession().sendMessage(CastSessionUtil.MEDIA_NAMESPACE, json.toString());
}
private void updateMediaSessionId(String message) {
try {
JSONObject json = new JSONObject(message);
JSONArray statusArray = json.optJSONArray("status");
if (statusArray == null || statusArray.length() == 0) {
return;
}
JSONObject status = statusArray.optJSONObject(0);
if (status == null) {
return;
}
mLatestMediaSessionId = status.optInt("mediaSessionId", mLatestMediaSessionId);
} catch (JSONException e) {
// Ignore.
}
}
private void updateRemoteMediaClient(String message) { private void updateRemoteMediaClient(String message) {
if (!isConnected()) return; if (!isConnected()) return;
...@@ -219,7 +172,6 @@ public abstract class BaseSessionController { ...@@ -219,7 +172,6 @@ public abstract class BaseSessionController {
"Received message from Cast device: namespace=\"" + namespace + "\" message=\"" "Received message from Cast device: namespace=\"" + namespace + "\" message=\""
+ message + "\""); + message + "\"");
if (CastSessionUtil.MEDIA_NAMESPACE.equals(namespace)) { if (CastSessionUtil.MEDIA_NAMESPACE.equals(namespace)) {
updateMediaSessionId(message);
updateRemoteMediaClient(message); updateRemoteMediaClient(message);
} }
} }
......
...@@ -72,7 +72,7 @@ public class CafExpandedControllerActivity ...@@ -72,7 +72,7 @@ public class CafExpandedControllerActivity
public void seekTo(long pos) { public void seekTo(long pos) {
if (!mSessionController.isConnected()) return; if (!mSessionController.isConnected()) return;
mSessionController.safelySeek(pos); mSessionController.getSession().getRemoteMediaClient().seek(pos);
} }
@Override @Override
......
...@@ -126,7 +126,8 @@ public class FlingingControllerAdapter implements FlingingController, MediaContr ...@@ -126,7 +126,8 @@ public class FlingingControllerAdapter implements FlingingController, MediaContr
return; return;
} }
mSessionController.safelySeek(position).setResultCallback(this::onMediaCommandResult); mSessionController.getRemoteMediaClient().seek(position).setResultCallback(
this::onMediaCommandResult);
mStreamPositionExtrapolator.onSeek(position); mStreamPositionExtrapolator.onSeek(position);
} }
......
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 to comment