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-20 22:26:21 +00:00
Родитель 47e70b9c38
Коммит fdd8992351
3 изменённых файлов: 31 добавлений и 0 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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