[WVDRM] Support new Java API crypto HAL
Implements WV crypto plugin core lib build Change-Id: I4f3fb06a4a9cf7c9c663d3dcee9cfd2c2900ebc2 related-to-bug: 5986621
This commit is contained in:
committed by
Jeff Tinker
parent
aaa8479c34
commit
6473768dcb
13
proprietary/cryptoPlugin/Android.mk
Normal file
13
proprietary/cryptoPlugin/Android.mk
Normal file
@@ -0,0 +1,13 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
WVCryptoPlugin.cpp
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(TOP)/vendor/widevine/proprietary/wvm/include \
|
||||
|
||||
LOCAL_MODULE:= libwvdecryptcommon
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
146
proprietary/cryptoPlugin/WVCryptoPlugin.cpp
Normal file
146
proprietary/cryptoPlugin/WVCryptoPlugin.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//#define LOG_NDEBUG 0
|
||||
#define LOG_TAG "wv_crypto_plugin"
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include "WVCryptoPlugin.h"
|
||||
|
||||
#include <media/stagefright/foundation/ADebug.h>
|
||||
#include <media/stagefright/foundation/hexdump.h>
|
||||
|
||||
#include <OEMCrypto_L1.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
// static
|
||||
const uint8_t WVCryptoFactory::kUUIDWidevine[16] = {
|
||||
0xED,0xEF,0x8B,0xA9,0x79,0xD6,0x4A,0xCE,
|
||||
0xA3,0xC8,0x27,0xDC,0xD5,0x1D,0x21,0xED
|
||||
};
|
||||
|
||||
WVCryptoPlugin::WVCryptoPlugin(const void *data, size_t size)
|
||||
: mInitCheck(NO_INIT) {
|
||||
|
||||
// not using data at this time, require
|
||||
// size to be zero.
|
||||
if (size > 0) {
|
||||
mInitCheck = -EINVAL;
|
||||
} else {
|
||||
OEMCryptoResult res = OEMCrypto_Initialize();
|
||||
if (res != OEMCrypto_SUCCESS) {
|
||||
ALOGE("OEMCrypto_Initialize failed: %d", res);
|
||||
mInitCheck = -EINVAL;
|
||||
} else {
|
||||
mInitCheck = OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WVCryptoPlugin::~WVCryptoPlugin() {
|
||||
if (mInitCheck == OK) {
|
||||
OEMCryptoResult res = OEMCrypto_Terminate();
|
||||
if (res != OEMCrypto_SUCCESS) {
|
||||
ALOGW("OEMCrypto_Terminate failed: %d", res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
status_t WVCryptoPlugin::initCheck() const {
|
||||
return mInitCheck;
|
||||
}
|
||||
|
||||
bool WVCryptoPlugin::requiresSecureDecoderComponent(const char *mime) const {
|
||||
return !strncasecmp(mime, "video/", 6);
|
||||
}
|
||||
|
||||
status_t WVCryptoPlugin::decrypt(
|
||||
bool secure,
|
||||
const uint8_t key[16],
|
||||
const uint8_t iv[16],
|
||||
Mode mode,
|
||||
const void *srcPtr,
|
||||
const SubSample *subSamples, size_t numSubSamples,
|
||||
void *dstPtr,
|
||||
AString *errorDetailMsg) {
|
||||
Mutex::Autolock autoLock(mLock);
|
||||
|
||||
//ALOGD("mode=%d, secure=%d, numSubSamples=%d", mode, secure, numSubSamples);
|
||||
CHECK(mode == kMode_Unencrypted || mode == kMode_AES_WV);
|
||||
|
||||
size_t offset = 0;
|
||||
for (size_t i = 0; i < numSubSamples; ++i) {
|
||||
const SubSample &ss = subSamples[i];
|
||||
|
||||
size_t srcSize;
|
||||
|
||||
if (mode == kMode_Unencrypted) {
|
||||
srcSize = ss.mNumBytesOfClearData;
|
||||
CHECK_EQ(ss.mNumBytesOfEncryptedData, 0u);
|
||||
} else {
|
||||
CHECK_EQ(ss.mNumBytesOfClearData, 0u);
|
||||
srcSize = ss.mNumBytesOfEncryptedData;
|
||||
}
|
||||
|
||||
//ALOGD("size[%d]=%d", i, srcSize);
|
||||
|
||||
OEMCrypto_UINT32 dstLength = srcSize;
|
||||
|
||||
OEMCryptoResult res;
|
||||
|
||||
OEMCrypto_UINT8 _iv[16];
|
||||
const OEMCrypto_UINT8 *iv = NULL;
|
||||
|
||||
if (mode != kMode_Unencrypted) {
|
||||
memset(_iv, 0, sizeof(_iv));
|
||||
iv = _iv;
|
||||
}
|
||||
|
||||
if (secure) {
|
||||
//ALOGD("calling DecryptVideo, size=%d", srcSize);
|
||||
res = OEMCrypto_DecryptVideo(
|
||||
iv,
|
||||
(const OEMCrypto_UINT8 *)srcPtr + offset,
|
||||
srcSize,
|
||||
(OEMCrypto_UINT32)dstPtr,
|
||||
offset,
|
||||
&dstLength);
|
||||
} else {
|
||||
//ALOGD("calling DecryptAudio: size=%d", srcSize);
|
||||
res = OEMCrypto_DecryptAudio(
|
||||
iv,
|
||||
(const OEMCrypto_UINT8 *)srcPtr + offset,
|
||||
srcSize,
|
||||
(OEMCrypto_UINT8 *)dstPtr + offset,
|
||||
&dstLength);
|
||||
}
|
||||
|
||||
if (res != OEMCrypto_SUCCESS) {
|
||||
ALOGE("decrypt result: %d", res);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
offset += dstLength;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
89
proprietary/cryptoPlugin/WVCryptoPlugin.h
Normal file
89
proprietary/cryptoPlugin/WVCryptoPlugin.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WV_CRYPTO_PLUGIN_H_
|
||||
|
||||
#define WV_CRYPTO_PLUGIN_H_
|
||||
|
||||
#include <media/hardware/CryptoAPI.h>
|
||||
#include <utils/threads.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
struct WVCryptoPlugin : public CryptoPlugin {
|
||||
WVCryptoPlugin(const void *data, size_t size);
|
||||
virtual ~WVCryptoPlugin();
|
||||
|
||||
status_t initCheck() const;
|
||||
|
||||
virtual bool requiresSecureDecoderComponent(const char *mime) const;
|
||||
|
||||
virtual status_t decrypt(
|
||||
bool secure,
|
||||
const uint8_t key[16],
|
||||
const uint8_t iv[16],
|
||||
Mode mode,
|
||||
const void *srcPtr,
|
||||
const SubSample *subSamples, size_t numSubSamples,
|
||||
void *dstPtr,
|
||||
AString *errorDetailMsg);
|
||||
|
||||
private:
|
||||
Mutex mLock;
|
||||
|
||||
status_t mInitCheck;
|
||||
|
||||
WVCryptoPlugin(const WVCryptoPlugin &);
|
||||
WVCryptoPlugin &operator=(const WVCryptoPlugin &);
|
||||
};
|
||||
|
||||
struct WVCryptoFactory : public CryptoFactory {
|
||||
static const uint8_t kUUIDWidevine[16];
|
||||
|
||||
virtual bool isCryptoSchemeSupported(
|
||||
const uint8_t uuid[16]) const {
|
||||
return !memcmp(uuid, kUUIDWidevine, 16);
|
||||
}
|
||||
|
||||
virtual status_t createPlugin(
|
||||
const uint8_t uuid[16], const void *data, size_t size,
|
||||
CryptoPlugin **out) {
|
||||
*out = NULL;
|
||||
|
||||
if (memcmp(uuid, kUUIDWidevine, 16)) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
WVCryptoPlugin *plugin = new WVCryptoPlugin(data, size);
|
||||
|
||||
status_t err;
|
||||
if ((err = plugin->initCheck()) != OK) {
|
||||
delete plugin;
|
||||
plugin = NULL;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
*out = plugin;
|
||||
|
||||
return OK;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // WV_CRYPTO_PLUGIN_H_
|
||||
|
||||
14
proprietary/cryptoPlugin/decrypt-core.mk
Normal file
14
proprietary/cryptoPlugin/decrypt-core.mk
Normal file
@@ -0,0 +1,14 @@
|
||||
#
|
||||
# To be included by platform-specific vendor Android.mk to build
|
||||
# Widevine wvm static library. Sets up includes and defines the core libraries
|
||||
# required.
|
||||
#
|
||||
include $(TOP)/vendor/widevine/proprietary/wvm/common.mk
|
||||
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES := \
|
||||
libwvdecryptcommon
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libstagefright_foundation \
|
||||
libutils \
|
||||
|
||||
Reference in New Issue
Block a user