From eb35a8ab7e32623b84b7b331683f0c39560e7bc9 Mon Sep 17 00:00:00 2001 From: Kilik Kuo Date: Tue, 1 Nov 2016 19:11:38 +0800 Subject: [PATCH] Bug 1306185-[Part1] Provide Java interface to bridge Gecko's gmp-decryption-like API and MediaDrm API r=cpearce,jchen MozReview-Commit-ID: 3jxofUxcTA9 --HG-- extra : rebase_source : c00f4d79aeca0fbee0cdf16789a7a6ceadab0317 --- .../mozilla/gecko/media/GeckoMediaDrm.java | 35 +++++++++ .../mozilla/gecko/media/SessionKeyInfo.java | 18 +++++ mobile/android/base/moz.build | 2 + widget/android/fennec/FennecJNIWrappers.cpp | 37 +++++++++ widget/android/fennec/FennecJNIWrappers.h | 75 +++++++++++++++++++ 5 files changed, 167 insertions(+) create mode 100644 mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaDrm.java create mode 100644 mobile/android/base/java/org/mozilla/gecko/media/SessionKeyInfo.java diff --git a/mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaDrm.java b/mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaDrm.java new file mode 100644 index 000000000000..7b3bda3fd72d --- /dev/null +++ b/mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaDrm.java @@ -0,0 +1,35 @@ +/* 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 android.media.MediaCrypto; + +public interface GeckoMediaDrm { + public interface Callbacks { + void onSessionCreated(int createSessionToken, + int promiseId, + byte[] sessionId, + byte[] request); + void onSessionUpdated(int promiseId, byte[] sessionId); + void onSessionClosed(int promiseId, byte[] sessionId); + void onSessionMessage(byte[] sessionId, + int sessionMessageType, + byte[] request); + void onSessionError(byte[] sessionId, String message); + void onSessionBatchedKeyChanged(byte[] sessionId, + SessionKeyInfo[] keyInfos); + // All failure cases should go through this function. + void onRejectPromise(int promiseId, String message); + } + void setCallbacks(Callbacks callbacks); + void createSession(int createSessionToken, + int promiseId, + String initDataType, + byte[] initData); + void updateSession(int promiseId, String sessionId, byte[] response); + void closeSession(int promiseId, String sessionId); + void release(); + MediaCrypto getMediaCrypto(); +} diff --git a/mobile/android/base/java/org/mozilla/gecko/media/SessionKeyInfo.java b/mobile/android/base/java/org/mozilla/gecko/media/SessionKeyInfo.java new file mode 100644 index 000000000000..969cd605104c --- /dev/null +++ b/mobile/android/base/java/org/mozilla/gecko/media/SessionKeyInfo.java @@ -0,0 +1,18 @@ +/* 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.annotation.WrapForJNI; + +@WrapForJNI +public final class SessionKeyInfo { + public byte[] keyId; + public int status; + + public SessionKeyInfo(byte[] keyId, int status) { + this.keyId = keyId; + this.status = status; + } +} diff --git a/mobile/android/base/moz.build b/mobile/android/base/moz.build index c9ea2c2f16d1..10b9d393bc09 100644 --- a/mobile/android/base/moz.build +++ b/mobile/android/base/moz.build @@ -555,6 +555,7 @@ gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [ 'media/Codec.java', 'media/CodecProxy.java', 'media/FormatParam.java', + 'media/GeckoMediaDrm.java', 'media/JellyBeanAsyncCodec.java', 'media/MediaControlService.java', 'media/MediaDrmProxy.java', @@ -562,6 +563,7 @@ gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [ 'media/RemoteManager.java', 'media/Sample.java', 'media/SamplePool.java', + 'media/SessionKeyInfo.java', 'media/VideoPlayer.java', 'MediaCastingBar.java', 'MemoryMonitor.java', diff --git a/widget/android/fennec/FennecJNIWrappers.cpp b/widget/android/fennec/FennecJNIWrappers.cpp index f1ae22e6e597..c75c52e5a1fe 100644 --- a/widget/android/fennec/FennecJNIWrappers.cpp +++ b/widget/android/fennec/FennecJNIWrappers.cpp @@ -311,6 +311,43 @@ auto Sample::Info(mozilla::jni::Object::Param a0) const -> void return mozilla::jni::Field::Set(Sample::mCtx, nullptr, a0); } +const char SessionKeyInfo::name[] = + "org/mozilla/gecko/media/SessionKeyInfo"; + +constexpr char SessionKeyInfo::New_t::name[]; +constexpr char SessionKeyInfo::New_t::signature[]; + +auto SessionKeyInfo::New(mozilla::jni::ByteArray::Param a0, int32_t a1) -> SessionKeyInfo::LocalRef +{ + return mozilla::jni::Constructor::Call(SessionKeyInfo::Context(), nullptr, a0, a1); +} + +constexpr char SessionKeyInfo::KeyId_t::name[]; +constexpr char SessionKeyInfo::KeyId_t::signature[]; + +auto SessionKeyInfo::KeyId() const -> mozilla::jni::ByteArray::LocalRef +{ + return mozilla::jni::Field::Get(SessionKeyInfo::mCtx, nullptr); +} + +auto SessionKeyInfo::KeyId(mozilla::jni::ByteArray::Param a0) const -> void +{ + return mozilla::jni::Field::Set(SessionKeyInfo::mCtx, nullptr, a0); +} + +constexpr char SessionKeyInfo::Status_t::name[]; +constexpr char SessionKeyInfo::Status_t::signature[]; + +auto SessionKeyInfo::Status() const -> int32_t +{ + return mozilla::jni::Field::Get(SessionKeyInfo::mCtx, nullptr); +} + +auto SessionKeyInfo::Status(int32_t a0) const -> void +{ + return mozilla::jni::Field::Set(SessionKeyInfo::mCtx, nullptr, a0); +} + const char Restrictions::name[] = "org/mozilla/gecko/restrictions/Restrictions"; diff --git a/widget/android/fennec/FennecJNIWrappers.h b/widget/android/fennec/FennecJNIWrappers.h index a57a4cbd98d6..8ff2ccf68c27 100644 --- a/widget/android/fennec/FennecJNIWrappers.h +++ b/widget/android/fennec/FennecJNIWrappers.h @@ -1060,6 +1060,81 @@ public: }; +class SessionKeyInfo : public mozilla::jni::ObjectBase +{ +public: + static const char name[]; + + explicit SessionKeyInfo(const Context& ctx) : ObjectBase(ctx) {} + + struct New_t { + typedef SessionKeyInfo Owner; + typedef SessionKeyInfo::LocalRef ReturnType; + typedef SessionKeyInfo::Param SetterType; + typedef mozilla::jni::Args< + mozilla::jni::ByteArray::Param, + int32_t> Args; + static constexpr char name[] = ""; + static constexpr char signature[] = + "([BI)V"; + static const bool isStatic = false; + static const mozilla::jni::ExceptionMode exceptionMode = + mozilla::jni::ExceptionMode::ABORT; + static const mozilla::jni::CallingThread callingThread = + mozilla::jni::CallingThread::ANY; + static const mozilla::jni::DispatchTarget dispatchTarget = + mozilla::jni::DispatchTarget::CURRENT; + }; + + static auto New(mozilla::jni::ByteArray::Param, int32_t) -> SessionKeyInfo::LocalRef; + + struct KeyId_t { + typedef SessionKeyInfo Owner; + typedef mozilla::jni::ByteArray::LocalRef ReturnType; + typedef mozilla::jni::ByteArray::Param SetterType; + typedef mozilla::jni::Args<> Args; + static constexpr char name[] = "keyId"; + static constexpr char signature[] = + "[B"; + static const bool isStatic = false; + static const mozilla::jni::ExceptionMode exceptionMode = + mozilla::jni::ExceptionMode::ABORT; + static const mozilla::jni::CallingThread callingThread = + mozilla::jni::CallingThread::ANY; + static const mozilla::jni::DispatchTarget dispatchTarget = + mozilla::jni::DispatchTarget::CURRENT; + }; + + auto KeyId() const -> mozilla::jni::ByteArray::LocalRef; + + auto KeyId(mozilla::jni::ByteArray::Param) const -> void; + + struct Status_t { + typedef SessionKeyInfo Owner; + typedef int32_t ReturnType; + typedef int32_t SetterType; + typedef mozilla::jni::Args<> Args; + static constexpr char name[] = "status"; + static constexpr char signature[] = + "I"; + static const bool isStatic = false; + static const mozilla::jni::ExceptionMode exceptionMode = + mozilla::jni::ExceptionMode::ABORT; + static const mozilla::jni::CallingThread callingThread = + mozilla::jni::CallingThread::ANY; + static const mozilla::jni::DispatchTarget dispatchTarget = + mozilla::jni::DispatchTarget::CURRENT; + }; + + auto Status() const -> int32_t; + + auto Status(int32_t) const -> void; + + static const mozilla::jni::CallingThread callingThread = + mozilla::jni::CallingThread::ANY; + +}; + class Restrictions : public mozilla::jni::ObjectBase { public: