Bug 1306185-[Part3] Provide LocalMediaDrmBrdige as an intermediate which is the entry to actual GeckoMediaDrmBridge implementation. r=cpearce,jchen
☠☠ backed out by 42e6e9452daa ☠ ☠
authorKilik Kuo <kikuo@mozilla.com>
Tue, 01 Nov 2016 19:16:17 +0800
changeset 347174 2d8d0579cb0dcd9d1f04d194a9686db6023e7227
parent 347173 a40cb9ae8d074a7758a9adceee3723f28134ee35
child 347175 4eab781604ad49d78b6a0c496567e8dee0d7157b
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, jchen
bugs1306185
milestone52.0a1
Bug 1306185-[Part3] Provide LocalMediaDrmBrdige as an intermediate which is the entry to actual GeckoMediaDrmBridge implementation. r=cpearce,jchen MozReview-Commit-ID: I9NH0ibGdEn
mobile/android/base/java/org/mozilla/gecko/media/LocalMediaDrmBridge.java
mobile/android/base/moz.build
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/media/LocalMediaDrmBridge.java
@@ -0,0 +1,162 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.media;
+import org.mozilla.gecko.AppConstants;
+
+import android.media.MediaCrypto;
+import android.util.Log;
+
+final class LocalMediaDrmBridge implements GeckoMediaDrm {
+    private static final String LOGTAG = "GeckoLocalMediaDrmBridge";
+    private static final boolean DEBUG = false;
+    private GeckoMediaDrm mBridge = null;
+    private CallbacksForwarder mCallbacksFwd;
+
+    // Forward the callback calls from GeckoMediaDrmBridgeV{21,23}
+    // to the callback MediaDrmProxy.Callbacks.
+    private class CallbacksForwarder implements GeckoMediaDrm.Callbacks {
+        private final GeckoMediaDrm.Callbacks mProxyCallbacks;
+
+        CallbacksForwarder(GeckoMediaDrm.Callbacks callbacks) {
+            assertTrue(callbacks != null);
+            mProxyCallbacks = callbacks;
+        }
+
+        @Override
+        public void onSessionCreated(int createSessionToken,
+                                     int promiseId,
+                                     byte[] sessionId,
+                                     byte[] request) {
+            assertTrue(mProxyCallbacks != null);
+            mProxyCallbacks.onSessionCreated(createSessionToken,
+                                             promiseId,
+                                             sessionId,
+                                             request);
+        }
+
+        @Override
+        public void onSessionUpdated(int promiseId, byte[] sessionId) {
+            assertTrue(mProxyCallbacks != null);
+            mProxyCallbacks.onSessionUpdated(promiseId, sessionId);
+        }
+
+        @Override
+        public void onSessionClosed(int promiseId, byte[] sessionId) {
+            assertTrue(mProxyCallbacks != null);
+            mProxyCallbacks.onSessionClosed(promiseId, sessionId);
+        }
+
+        @Override
+        public void onSessionMessage(byte[] sessionId,
+                                     int sessionMessageType,
+                                     byte[] request) {
+            assertTrue(mProxyCallbacks != null);
+            mProxyCallbacks.onSessionMessage(sessionId, sessionMessageType, request);
+        }
+
+        @Override
+        public void onSessionError(byte[] sessionId,
+                                   String message) {
+            assertTrue(mProxyCallbacks != null);
+            mProxyCallbacks.onSessionError(sessionId, message);
+        }
+
+        @Override
+        public void onSessionBatchedKeyChanged(byte[] sessionId,
+                                               SessionKeyInfo[] keyInfos) {
+            assertTrue(mProxyCallbacks != null);
+            mProxyCallbacks.onSessionBatchedKeyChanged(sessionId, keyInfos);
+        }
+
+        @Override
+        public void onRejectPromise(int promiseId, String message) {
+            if (DEBUG) Log.d(LOGTAG, message);
+            assertTrue(mProxyCallbacks != null);
+            mProxyCallbacks.onRejectPromise(promiseId, message);
+        }
+    } // CallbacksForwarder
+
+    private static void assertTrue(boolean condition) {
+        if (DEBUG && !condition) {
+          throw new AssertionError("Expected condition to be true");
+        }
+      }
+
+    LocalMediaDrmBridge(String keySystem) throws Exception {
+        if (AppConstants.Versions.preLollipop) {
+            mBridge = null;
+        } else if (AppConstants.Versions.feature21Plus &&
+                   AppConstants.Versions.preMarshmallow) {
+            mBridge = new GeckoMediaDrmBridgeV21(keySystem);
+        } else {
+            mBridge = new GeckoMediaDrmBridgeV23(keySystem);
+        }
+    }
+
+    @Override
+    public synchronized void setCallbacks(Callbacks callbacks) {
+        if (DEBUG) Log.d(LOGTAG, "setCallbacks()");
+        mCallbacksFwd = new CallbacksForwarder(callbacks);
+        assertTrue(mBridge != null);
+        mBridge.setCallbacks(mCallbacksFwd);
+    }
+
+    @Override
+    public synchronized void createSession(int createSessionToken,
+                                           int promiseId,
+                                           String initDataType,
+                                           byte[] initData) {
+        if (DEBUG) Log.d(LOGTAG, "createSession()");
+        assertTrue(mCallbacksFwd != null);
+        try {
+            mBridge.createSession(createSessionToken, promiseId, initDataType, initData);
+        } catch (Exception e) {
+            Log.e(LOGTAG, "Failed to createSession.", e);
+            mCallbacksFwd.onRejectPromise(promiseId, "Failed to createSession.");
+        }
+    }
+
+    @Override
+    public synchronized void updateSession(int promiseId, String sessionId, byte[] response) {
+        if (DEBUG) Log.d(LOGTAG, "updateSession()");
+        assertTrue(mCallbacksFwd != null);
+        try {
+            mBridge.updateSession(promiseId, sessionId, response);
+        } catch (Exception e) {
+            Log.e(LOGTAG, "Failed to updateSession.", e);
+            mCallbacksFwd.onRejectPromise(promiseId, "Failed to updateSession.");
+        }
+    }
+
+    @Override
+    public synchronized void closeSession(int promiseId, String sessionId) {
+        if (DEBUG) Log.d(LOGTAG, "closeSession()");
+        assertTrue(mCallbacksFwd != null);
+        try {
+            mBridge.closeSession(promiseId, sessionId);
+        } catch (Exception e) {
+            Log.e(LOGTAG, "Failed to closeSession.", e);
+            mCallbacksFwd.onRejectPromise(promiseId, "Failed to closeSession.");
+        }
+    }
+
+    @Override
+    public synchronized void release() {
+        if (DEBUG) Log.d(LOGTAG, "release()");
+        try {
+            mBridge.release();
+            mBridge = null;
+            mCallbacksFwd = null;
+        } catch (Exception e) {
+            Log.e(LOGTAG, "Failed to release", e);
+        }
+    }
+
+    @Override
+    public synchronized MediaCrypto getMediaCrypto() {
+        if (DEBUG) Log.d(LOGTAG, "getMediaCrypto()");
+        return mBridge != null ? mBridge.getMediaCrypto() : null;
+    }
+}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -551,17 +551,20 @@ gbjar.sources += ['java/org/mozilla/geck
     'mdns/MulticastDNSManager.java',
     'media/AsyncCodec.java',
     'media/AsyncCodecFactory.java',
     'media/AudioFocusAgent.java',
     'media/Codec.java',
     'media/CodecProxy.java',
     'media/FormatParam.java',
     'media/GeckoMediaDrm.java',
+    'media/GeckoMediaDrmBridgeV21.java',
+    'media/GeckoMediaDrmBridgeV23.java',
     'media/JellyBeanAsyncCodec.java',
+    'media/LocalMediaDrmBridge.java',
     'media/MediaControlService.java',
     'media/MediaDrmProxy.java',
     'media/MediaManager.java',
     'media/RemoteManager.java',
     'media/Sample.java',
     'media/SamplePool.java',
     'media/SessionKeyInfo.java',
     'media/VideoPlayer.java',