Commit 46fa967b authored by Thomas Guilbert's avatar Thomas Guilbert Committed by Commit Bot

Fix CastSession/FlingingRenderer creation race

The FlingingRenderer needs a MediaController in order to be created.
RemotingMediaRouteProvider signals MediaRoute creation as soon as we
start to launch the RemotingCastSession. This can trigger the creation
of a FlingingRenderer before the CastSession finishes launching, which
means that FlingingRenderer ends up with a null MediaController.

This CL delays the moment at which RemotingMediaRouteProvider completes
the route creation request, to after the RemotingCastSession launches.
This guarantees that we won't create a FlingingRenderer until we have
a valid MediaController to retrieve.

Bug: 790766
Change-Id: Ib74ab54890976f7735140e7eac79548898fbb667
Reviewed-on: https://chromium-review.googlesource.com/1043527
Commit-Queue: Thomas Guilbert <tguilbert@chromium.org>
Reviewed-by: default avatarDerek Cheng <imcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557258}
parent 0e021fc6
......@@ -15,6 +15,7 @@ import org.chromium.chrome.browser.media.router.MediaRouteProvider;
import org.chromium.chrome.browser.media.router.MediaSink;
import org.chromium.chrome.browser.media.router.MediaSource;
import org.chromium.chrome.browser.media.router.cast.BaseMediaRouteProvider;
import org.chromium.chrome.browser.media.router.cast.CastSession;
import org.chromium.chrome.browser.media.router.cast.ChromeCastSessionManager;
import org.chromium.chrome.browser.media.router.cast.CreateRouteRequest;
......@@ -26,6 +27,9 @@ import javax.annotation.Nullable;
public class RemotingMediaRouteProvider extends BaseMediaRouteProvider {
private static final String TAG = "MediaRemoting";
private int mPendingNativeRequestId;
private MediaRoute mPendingMediaRoute;
/**
* @return Initialized {@link RemotingMediaRouteProvider} object.
*/
......@@ -103,12 +107,42 @@ public class RemotingMediaRouteProvider extends BaseMediaRouteProvider {
MediaSink sink = request.getSink();
MediaSource source = request.getSource();
MediaRoute route =
// Calling mManager.onRouteCreated() too early causes some issues. If we call it here
// directly, getMediaController() might be called before onSessionStarted(), which causes
// the FlingingRenderer's creation to fail. Instead, save the route and request ID, and only
// signal the route as having been created when onSessionStarted() is called.
mPendingMediaRoute =
new MediaRoute(sink.getId(), source.getSourceId(), request.getPresentationId());
mRoutes.put(route.id, route);
mManager.onRouteCreated(route.id, route.sinkId, request.getNativeRequestId(), this, true);
mPendingNativeRequestId = request.getNativeRequestId();
}
private void clearPendingRoute() {
mPendingMediaRoute = null;
mPendingNativeRequestId = 0;
}
@Override
public void onSessionStarted(CastSession session) {
super.onSessionStarted(session);
// Continued from onSessionStarting()
mRoutes.put(mPendingMediaRoute.id, mPendingMediaRoute);
mManager.onRouteCreated(mPendingMediaRoute.id, mPendingMediaRoute.sinkId,
mPendingNativeRequestId, this, true);
clearPendingRoute();
}
@Override
public void onSessionStartFailed() {
super.onSessionStartFailed();
mManager.onRouteRequestError(
"Failure to start RemotingCastSession", mPendingNativeRequestId);
clearPendingRoute();
};
@Override
@Nullable
public MediaController getMediaController(String routeId) {
......
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