Bug 1499224 - p1: keep record of active remote objects in MediaManager. r=jya

Differential Revision: https://phabricator.services.mozilla.com/D23736

--HG--
extra : moz-landing-system : lando
This commit is contained in:
John Lin 2019-03-21 15:49:36 +00:00
parent a3e06efc18
commit 61cf142d51
3 changed files with 31 additions and 0 deletions

View File

@ -15,4 +15,7 @@ interface IMediaManager {
/** Creates a remote IMediaDrmBridge object. */
IMediaDrmBridge createRemoteMediaDrmBridge(in String keySystem,
in String stubId);
/** Called by client to indicate it no longer needs a requested codec or DRM bridge. */
oneway void endRequest();
}

View File

@ -12,15 +12,20 @@ import android.os.Process;
import android.os.RemoteException;
import android.util.Log;
import org.mozilla.geckoview.BuildConfig;
import org.mozilla.gecko.mozglue.GeckoLoader;
public final class MediaManager extends Service {
private static final String LOGTAG = "GeckoMediaManager";
private static final boolean DEBUG = !BuildConfig.MOZILLA_OFFICIAL;
private static boolean sNativeLibLoaded;
private int mNumActiveRequests = 0;
private Binder mBinder = new IMediaManager.Stub() {
@Override
public ICodec createCodec() throws RemoteException {
if (DEBUG) Log.d(LOGTAG, "request codec. Current active requests:" + mNumActiveRequests);
mNumActiveRequests++;
return new Codec();
}
@ -28,8 +33,21 @@ public final class MediaManager extends Service {
public IMediaDrmBridge createRemoteMediaDrmBridge(final String keySystem,
final String stubId)
throws RemoteException {
if (DEBUG) Log.d(LOGTAG, "request DRM bridge. Current active requests:" + mNumActiveRequests);
mNumActiveRequests++;
return new RemoteMediaDrmBridgeStub(keySystem, stubId);
}
@Override
public void endRequest() {
if (DEBUG) Log.d(LOGTAG, "end request. Current active requests:" + mNumActiveRequests);
if (mNumActiveRequests > 0) {
mNumActiveRequests--;
} else {
RuntimeException e = new RuntimeException("unmatched codec/DRM bridge creation and ending calls!");
Log.e(LOGTAG, "Error:", e);
}
}
};
@Override

View File

@ -210,6 +210,11 @@ public final class RemoteManager implements IBinder.DeathRecipient {
proxy.deinit();
synchronized (this) {
if (mCodecs.remove(proxy)) {
try {
mRemote.endRequest();
} catch (RemoteException e) {
Log.e(LOGTAG, "fail to report remote codec disconnection");
}
releaseIfNeeded();
}
}
@ -234,6 +239,11 @@ public final class RemoteManager implements IBinder.DeathRecipient {
synchronized (this) {
if (mDrmBridges.remove(remote)) {
try {
mRemote.endRequest();
} catch (RemoteException e) {
Log.e(LOGTAG, "Fail to report remote DRM bridge disconnection");
}
releaseIfNeeded();
}
}