summaryrefslogtreecommitdiffstats
path: root/drm/mediadrm
diff options
context:
space:
mode:
authorJeff Tinker <jtinker@google.com>2015-05-29 16:35:28 -0700
committerJeff Tinker <jtinker@google.com>2015-06-03 11:35:50 -0700
commit9472e5f3ab44f04c92e44ad0f3e94c0ee508ec11 (patch)
tree310e52bec409cfbdfcc355f67c03e792c51df347 /drm/mediadrm
parent2d6b6601743c3c6960c6511a2cb774ef902759f4 (diff)
downloadframeworks_av-9472e5f3ab44f04c92e44ad0f3e94c0ee508ec11.zip
frameworks_av-9472e5f3ab44f04c92e44ad0f3e94c0ee508ec11.tar.gz
frameworks_av-9472e5f3ab44f04c92e44ad0f3e94c0ee508ec11.tar.bz2
Implement MediaCrypto.setMediaDrmSession in clearkey plugin
To support adding cts tests for new APIs in M, the clearkey DRM plugin needs to be updated. Change-Id: If672ecec8f570d1dd5130e8e4419d37bd931a9e2 related-to-bug: 21527003
Diffstat (limited to 'drm/mediadrm')
-rw-r--r--drm/mediadrm/plugins/clearkey/CryptoFactory.cpp16
-rw-r--r--drm/mediadrm/plugins/clearkey/CryptoPlugin.cpp16
-rw-r--r--drm/mediadrm/plugins/clearkey/CryptoPlugin.h11
-rw-r--r--drm/mediadrm/plugins/clearkey/DrmPlugin.cpp12
-rw-r--r--drm/mediadrm/plugins/clearkey/SessionLibrary.cpp7
-rw-r--r--drm/mediadrm/plugins/clearkey/SessionLibrary.h4
6 files changed, 48 insertions, 18 deletions
diff --git a/drm/mediadrm/plugins/clearkey/CryptoFactory.cpp b/drm/mediadrm/plugins/clearkey/CryptoFactory.cpp
index ee3189b..eeb64c3 100644
--- a/drm/mediadrm/plugins/clearkey/CryptoFactory.cpp
+++ b/drm/mediadrm/plugins/clearkey/CryptoFactory.cpp
@@ -43,10 +43,18 @@ android::status_t CryptoFactory::createPlugin(
return android::BAD_VALUE;
}
- android::sp<Session> session = SessionLibrary::get()->findSession(
- data, size);
- *plugin = new CryptoPlugin(session);
- return android::OK;
+ android::Vector<uint8_t> sessionId;
+ sessionId.appendArray(reinterpret_cast<const uint8_t*>(data), size);
+
+ CryptoPlugin *clearKeyPlugin = new CryptoPlugin(sessionId);
+ android::status_t result = clearKeyPlugin->getInitStatus();
+ if (result == android::OK) {
+ *plugin = clearKeyPlugin;
+ } else {
+ delete clearKeyPlugin;
+ *plugin = NULL;
+ }
+ return result;
}
} // namespace clearkeydrm
diff --git a/drm/mediadrm/plugins/clearkey/CryptoPlugin.cpp b/drm/mediadrm/plugins/clearkey/CryptoPlugin.cpp
index adad136..53cbf80 100644
--- a/drm/mediadrm/plugins/clearkey/CryptoPlugin.cpp
+++ b/drm/mediadrm/plugins/clearkey/CryptoPlugin.cpp
@@ -19,9 +19,9 @@
#include <utils/Log.h>
#include <media/stagefright/MediaErrors.h>
-#include <utils/Errors.h>
#include "CryptoPlugin.h"
+#include "SessionLibrary.h"
namespace clearkeydrm {
@@ -80,4 +80,18 @@ ssize_t CryptoPlugin::decrypt(bool secure, const KeyId keyId, const Iv iv,
}
}
+android::status_t CryptoPlugin::setMediaDrmSession(
+ const android::Vector<uint8_t>& sessionId) {
+ if (!sessionId.size()) {
+ mSession.clear();
+ } else {
+ mSession = SessionLibrary::get()->findSession(sessionId);
+ if (!mSession.get()) {
+ return android::ERROR_DRM_SESSION_NOT_OPENED;
+ }
+ }
+ return android::OK;
+}
+
+
} // namespace clearkeydrm
diff --git a/drm/mediadrm/plugins/clearkey/CryptoPlugin.h b/drm/mediadrm/plugins/clearkey/CryptoPlugin.h
index 002d9e0..fd38f28 100644
--- a/drm/mediadrm/plugins/clearkey/CryptoPlugin.h
+++ b/drm/mediadrm/plugins/clearkey/CryptoPlugin.h
@@ -31,7 +31,10 @@ namespace clearkeydrm {
class CryptoPlugin : public android::CryptoPlugin {
public:
- CryptoPlugin(const android::sp<Session>& session) : mSession(session) {}
+ CryptoPlugin(const android::Vector<uint8_t>& sessionId) {
+ mInitStatus = setMediaDrmSession(sessionId);
+ }
+
virtual ~CryptoPlugin() {}
virtual bool requiresSecureDecoderComponent(const char* mime) const {
@@ -45,10 +48,16 @@ public:
const SubSample* subSamples, size_t numSubSamples,
void* dstPtr, android::AString* errorDetailMsg);
+ virtual android::status_t setMediaDrmSession(
+ const android::Vector<uint8_t>& sessionId);
+
+ android::status_t getInitStatus() const {return mInitStatus;}
+
private:
DISALLOW_EVIL_CONSTRUCTORS(CryptoPlugin);
android::sp<Session> mSession;
+ android::status_t mInitStatus;
};
} // namespace clearkeydrm
diff --git a/drm/mediadrm/plugins/clearkey/DrmPlugin.cpp b/drm/mediadrm/plugins/clearkey/DrmPlugin.cpp
index 6b8c772..e5ee403 100644
--- a/drm/mediadrm/plugins/clearkey/DrmPlugin.cpp
+++ b/drm/mediadrm/plugins/clearkey/DrmPlugin.cpp
@@ -37,7 +37,9 @@ status_t DrmPlugin::openSession(Vector<uint8_t>& sessionId) {
status_t DrmPlugin::closeSession(const Vector<uint8_t>& sessionId) {
sp<Session> session = mSessionLibrary->findSession(sessionId);
- mSessionLibrary->destroySession(session);
+ if (session.get()) {
+ mSessionLibrary->destroySession(session);
+ }
return android::OK;
}
@@ -55,8 +57,11 @@ status_t DrmPlugin::getKeyRequest(
return android::ERROR_DRM_CANNOT_HANDLE;
}
*keyRequestType = DrmPlugin::kKeyRequestType_Initial;
- sp<Session> session = mSessionLibrary->findSession(scope);
defaultUrl.clear();
+ sp<Session> session = mSessionLibrary->findSession(scope);
+ if (!session.get()) {
+ return android::ERROR_DRM_SESSION_NOT_OPENED;
+ }
return session->getKeyRequest(initData, initDataType, &request);
}
@@ -65,6 +70,9 @@ status_t DrmPlugin::provideKeyResponse(
const Vector<uint8_t>& response,
Vector<uint8_t>& keySetId) {
sp<Session> session = mSessionLibrary->findSession(scope);
+ if (!session.get()) {
+ return android::ERROR_DRM_SESSION_NOT_OPENED;
+ }
status_t res = session->provideKeyResponse(response);
if (res == android::OK) {
keySetId.clear();
diff --git a/drm/mediadrm/plugins/clearkey/SessionLibrary.cpp b/drm/mediadrm/plugins/clearkey/SessionLibrary.cpp
index d047c53..46d7f77 100644
--- a/drm/mediadrm/plugins/clearkey/SessionLibrary.cpp
+++ b/drm/mediadrm/plugins/clearkey/SessionLibrary.cpp
@@ -63,13 +63,6 @@ const sp<Session>& SessionLibrary::findSession(
return mSessions.valueFor(sessionId);
}
-const sp<Session>& SessionLibrary::findSession(
- const void* data, size_t size) {
- Vector<uint8_t> sessionId;
- sessionId.appendArray(reinterpret_cast<const uint8_t*>(data), size);
- return findSession(sessionId);
-}
-
void SessionLibrary::destroySession(const sp<Session>& session) {
Mutex::Autolock lock(mSessionsLock);\
mSessions.removeItem(session->sessionId());
diff --git a/drm/mediadrm/plugins/clearkey/SessionLibrary.h b/drm/mediadrm/plugins/clearkey/SessionLibrary.h
index 56c8828..199ad64 100644
--- a/drm/mediadrm/plugins/clearkey/SessionLibrary.h
+++ b/drm/mediadrm/plugins/clearkey/SessionLibrary.h
@@ -36,8 +36,6 @@ public:
const android::sp<Session>& findSession(
const android::Vector<uint8_t>& sessionId);
- const android::sp<Session>& findSession(const void* data, size_t size);
-
void destroySession(const android::sp<Session>& session);
private:
@@ -50,7 +48,7 @@ private:
android::Mutex mSessionsLock;
uint32_t mNextSessionId;
- android::KeyedVector<android::Vector<uint8_t>, android::sp<Session> >
+ android::DefaultKeyedVector<android::Vector<uint8_t>, android::sp<Session> >
mSessions;
};