summaryrefslogtreecommitdiffstats
path: root/drm/libmediadrm/ICrypto.cpp
diff options
context:
space:
mode:
authorChong Zhang <chz@google.com>2017-03-28 14:18:27 -0700
committerChong Zhang <chz@google.com>2017-03-29 10:40:49 -0700
commit6dcab2bafd847be84c2c2230bbd04af9c45c491e (patch)
tree51f39e6d2f1ac74fd546c8a2797c06745a757694 /drm/libmediadrm/ICrypto.cpp
parentd07c92742fc5801cab8e99801f591365986acbe9 (diff)
downloadframeworks_av-6dcab2bafd847be84c2c2230bbd04af9c45c491e.tar.gz
frameworks_av-6dcab2bafd847be84c2c2230bbd04af9c45c491e.tar.bz2
frameworks_av-6dcab2bafd847be84c2c2230bbd04af9c45c491e.zip
DRM: more fixes for heap base mapping -- DO NOT MERGE
Heap base for the same heap could be mapped to different values after they go across binder to CryptoHal. So we can't use heapbase to index the heaps. Since each ACodec instance allocates all its shared memory buffers from the same memory dealer, we let CryptoHal assign a sequence number to the ACodec when it calls setHeap. In subsequent calls to CryptoHal::decrypt, reference the heap by the seq num, and ignore the heap base address. Bug: 36479980 Bug: 36209723 Bug: 36660223 Test: the above bugs don't repro Change-Id: I2f519a689a5891447385d1bf9d6e668bb3b4dbe2 (cherry-picked from bf628da1e231e2e4d6bf61f9884e120bae3f9156)
Diffstat (limited to 'drm/libmediadrm/ICrypto.cpp')
-rw-r--r--drm/libmediadrm/ICrypto.cpp42
1 files changed, 27 insertions, 15 deletions
diff --git a/drm/libmediadrm/ICrypto.cpp b/drm/libmediadrm/ICrypto.cpp
index 7b702059be..8506d95c0f 100644
--- a/drm/libmediadrm/ICrypto.cpp
+++ b/drm/libmediadrm/ICrypto.cpp
@@ -98,7 +98,7 @@ struct BpCrypto : public BpInterface<ICrypto> {
virtual ssize_t decrypt(const uint8_t key[16], const uint8_t iv[16],
CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern,
- const sp<IMemory> &source, size_t offset,
+ const SourceBuffer &source, size_t offset,
const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
const DestinationBuffer &destination, AString *errorDetailMsg) {
Parcel data, reply;
@@ -127,7 +127,8 @@ struct BpCrypto : public BpInterface<ICrypto> {
}
data.writeInt32(totalSize);
- data.writeStrongBinder(IInterface::asBinder(source));
+ data.writeStrongBinder(IInterface::asBinder(source.mSharedMemory));
+ data.writeInt32(source.mHeapSeqNum);
data.writeInt32(offset);
data.writeInt32(numSubSamples);
@@ -179,18 +180,25 @@ struct BpCrypto : public BpInterface<ICrypto> {
return reply.readInt32();
}
- virtual void setHeap(const sp<IMemoryHeap> &heap) {
+ virtual int32_t setHeap(const sp<IMemoryHeap> &heap) {
Parcel data, reply;
data.writeInterfaceToken(ICrypto::getInterfaceDescriptor());
data.writeStrongBinder(IInterface::asBinder(heap));
- remote()->transact(SET_HEAP, data, &reply);
- return;
+ status_t err = remote()->transact(SET_HEAP, data, &reply);
+ if (err != NO_ERROR) {
+ return -1;
+ }
+ int32_t seqNum;
+ if (reply.readInt32(&seqNum) != NO_ERROR) {
+ return -1;
+ }
+ return seqNum;
}
- virtual void unsetHeap(const sp<IMemoryHeap>& heap) {
+ virtual void unsetHeap(int32_t seqNum) {
Parcel data, reply;
data.writeInterfaceToken(ICrypto::getInterfaceDescriptor());
- data.writeStrongBinder(IInterface::asBinder(heap));
+ data.writeInt32(seqNum);
remote()->transact(UNSET_HEAP, data, &reply);
return;
}
@@ -314,12 +322,17 @@ status_t BnCrypto::onTransact(
data.read(iv, sizeof(iv));
size_t totalSize = data.readInt32();
- sp<IMemory> source =
+
+ SourceBuffer source;
+
+ source.mSharedMemory =
interface_cast<IMemory>(data.readStrongBinder());
- if (source == NULL) {
+ if (source.mSharedMemory == NULL) {
reply->writeInt32(BAD_VALUE);
return OK;
}
+ source.mHeapSeqNum = data.readInt32();
+
int32_t offset = data.readInt32();
int32_t numSubSamples = data.readInt32();
@@ -372,9 +385,9 @@ status_t BnCrypto::onTransact(
if (overflow || sumSubsampleSizes != totalSize) {
result = -EINVAL;
- } else if (totalSize > source->size()) {
+ } else if (totalSize > source.mSharedMemory->size()) {
result = -EINVAL;
- } else if ((size_t)offset > source->size() - totalSize) {
+ } else if ((size_t)offset > source.mSharedMemory->size() - totalSize) {
result = -EINVAL;
} else {
result = decrypt(key, iv, mode, pattern, source, offset,
@@ -428,16 +441,15 @@ status_t BnCrypto::onTransact(
CHECK_INTERFACE(ICrypto, data, reply);
sp<IMemoryHeap> heap =
interface_cast<IMemoryHeap>(data.readStrongBinder());
- setHeap(heap);
+ reply->writeInt32(setHeap(heap));
return OK;
}
case UNSET_HEAP:
{
CHECK_INTERFACE(ICrypto, data, reply);
- sp<IMemoryHeap> heap =
- interface_cast<IMemoryHeap>(data.readStrongBinder());
- unsetHeap(heap);
+ int32_t seqNum = data.readInt32();
+ unsetHeap(seqNum);
return OK;
}