Skip to content

Commit d4726a8

Browse files
Kei TakahashiKei Takahashi
authored andcommitted
Add a new API on DRM Framework for streaming
In case of DRM streaming, decrypt session can start just after receiving the header, and it doesn't need to wait for the entire content. However, current API of DRM framework only accepts file handle or URI. With this new API, DRM session can start without waiting for the entire content. Changes are made by SEMC and Sony. Change-Id: I74375fe127df636067f1c300ea91654ba3d1aa3c
1 parent 67cf093 commit d4726a8

File tree

13 files changed

+172
-0
lines changed

13 files changed

+172
-0
lines changed

drm/common/DrmEngineBase.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ status_t DrmEngineBase::openDecryptSession(
129129
return onOpenDecryptSession(uniqueId, decryptHandle, uri);
130130
}
131131

132+
status_t DrmEngineBase::openDecryptSession(int uniqueId, DecryptHandle* decryptHandle,
133+
const DrmBuffer& buf, const String8& mimeType) {
134+
return onOpenDecryptSession(uniqueId, decryptHandle, buf, mimeType);
135+
}
136+
132137
status_t DrmEngineBase::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
133138
return onCloseDecryptSession(uniqueId, decryptHandle);
134139
}

drm/common/IDrmManagerService.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,33 @@ DecryptHandle* BpDrmManagerService::openDecryptSession(int uniqueId, const char*
640640
return handle;
641641
}
642642

643+
DecryptHandle* BpDrmManagerService::openDecryptSession(
644+
int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
645+
ALOGV("Entering BpDrmManagerService::openDecryptSession");
646+
Parcel data, reply;
647+
648+
data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
649+
data.writeInt32(uniqueId);
650+
if (buf.data != NULL && buf.length > 0) {
651+
data.writeInt32(buf.length);
652+
data.write(buf.data, buf.length);
653+
} else {
654+
data.writeInt32(0);
655+
}
656+
data.writeString8(mimeType);
657+
658+
remote()->transact(OPEN_DECRYPT_SESSION_FOR_STREAMING, data, &reply);
659+
660+
DecryptHandle* handle = NULL;
661+
if (0 != reply.dataAvail()) {
662+
handle = new DecryptHandle();
663+
readDecryptHandleFromParcelData(handle, reply);
664+
} else {
665+
ALOGV("no decryptHandle is generated in service side");
666+
}
667+
return handle;
668+
}
669+
643670
status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
644671
ALOGV("closeDecryptSession");
645672
Parcel data, reply;
@@ -1297,6 +1324,30 @@ status_t BnDrmManagerService::onTransact(
12971324
return DRM_NO_ERROR;
12981325
}
12991326

1327+
case OPEN_DECRYPT_SESSION_FOR_STREAMING:
1328+
{
1329+
ALOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FOR_STREAMING");
1330+
CHECK_INTERFACE(IDrmManagerService, data, reply);
1331+
1332+
const int uniqueId = data.readInt32();
1333+
const int bufferSize = data.readInt32();
1334+
DrmBuffer buf((bufferSize > 0) ? (char *)data.readInplace(bufferSize) : NULL,
1335+
bufferSize);
1336+
const String8 mimeType(data.readString8());
1337+
1338+
DecryptHandle* handle = openDecryptSession(uniqueId, buf, mimeType);
1339+
1340+
if (handle != NULL) {
1341+
writeDecryptHandleToParcelData(handle, reply);
1342+
clearDecryptHandle(handle);
1343+
delete handle;
1344+
handle = NULL;
1345+
} else {
1346+
ALOGV("NULL decryptHandle is returned");
1347+
}
1348+
return DRM_NO_ERROR;
1349+
}
1350+
13001351
case CLOSE_DECRYPT_SESSION:
13011352
{
13021353
ALOGV("BnDrmManagerService::onTransact :CLOSE_DECRYPT_SESSION");

drm/drmserver/DrmManager.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,36 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, const char* uri) {
481481
return handle;
482482
}
483483

484+
DecryptHandle* DrmManager::openDecryptSession(
485+
int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
486+
Mutex::Autolock _l(mDecryptLock);
487+
status_t result = DRM_ERROR_CANNOT_HANDLE;
488+
Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
489+
490+
DecryptHandle* handle = new DecryptHandle();
491+
if (NULL != handle) {
492+
handle->decryptId = mDecryptSessionId + 1;
493+
494+
for (size_t index = 0; index < plugInIdList.size(); index++) {
495+
String8 plugInId = plugInIdList.itemAt(index);
496+
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
497+
result = rDrmEngine.openDecryptSession(uniqueId, handle, buf, mimeType);
498+
499+
if (DRM_NO_ERROR == result) {
500+
++mDecryptSessionId;
501+
mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine);
502+
break;
503+
}
504+
}
505+
}
506+
if (DRM_NO_ERROR != result) {
507+
delete handle;
508+
handle = NULL;
509+
ALOGV("DrmManager::openDecryptSession: no capable plug-in found");
510+
}
511+
return handle;
512+
}
513+
484514
status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
485515
Mutex::Autolock _l(mDecryptLock);
486516
status_t result = DRM_ERROR_UNKNOWN;

drm/drmserver/DrmManagerService.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,16 @@ DecryptHandle* DrmManagerService::openDecryptSession(
227227
return NULL;
228228
}
229229

230+
DecryptHandle* DrmManagerService::openDecryptSession(
231+
int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
232+
ALOGV("Entering DrmManagerService::openDecryptSession for streaming");
233+
if (isProtectedCallAllowed()) {
234+
return mDrmManager->openDecryptSession(uniqueId, buf, mimeType);
235+
}
236+
237+
return NULL;
238+
}
239+
230240
status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
231241
ALOGV("Entering closeDecryptSession");
232242
return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);

drm/libdrmframework/DrmManagerClient.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ sp<DecryptHandle> DrmManagerClient::openDecryptSession(const char* uri) {
124124
return mDrmManagerClientImpl->openDecryptSession(mUniqueId, uri);
125125
}
126126

127+
sp<DecryptHandle> DrmManagerClient::openDecryptSession(
128+
const DrmBuffer& buf, const String8& mimeType) {
129+
return mDrmManagerClientImpl->openDecryptSession(mUniqueId, buf, mimeType);
130+
}
131+
127132
status_t DrmManagerClient::closeDecryptSession(sp<DecryptHandle> &decryptHandle) {
128133
return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle);
129134
}

drm/libdrmframework/DrmManagerClientImpl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ sp<DecryptHandle> DrmManagerClientImpl::openDecryptSession(
268268
return handle;
269269
}
270270

271+
sp<DecryptHandle> DrmManagerClientImpl::openDecryptSession(
272+
int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
273+
return getDrmManagerService()->openDecryptSession(uniqueId, buf, mimeType);
274+
}
275+
271276
status_t DrmManagerClientImpl::closeDecryptSession(
272277
int uniqueId, sp<DecryptHandle> &decryptHandle) {
273278
status_t status = DRM_ERROR_UNKNOWN;

drm/libdrmframework/include/DrmManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ class DrmManager : public IDrmEngine::OnInfoListener {
115115

116116
DecryptHandle* openDecryptSession(int uniqueId, const char* uri);
117117

118+
DecryptHandle* openDecryptSession(int uniqueId, const DrmBuffer& buf,
119+
const String8& mimeType);
120+
118121
status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
119122

120123
status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,

drm/libdrmframework/include/DrmManagerClientImpl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,18 @@ class DrmManagerClientImpl : public BnDrmServiceListener {
315315
*/
316316
sp<DecryptHandle> openDecryptSession(int uniqueId, const char* uri);
317317

318+
/**
319+
* Open the decrypt session to decrypt the given protected content
320+
*
321+
* @param[in] uniqueId Unique identifier for a session
322+
* @param[in] buf Data to initiate decrypt session
323+
* @param[in] mimeType Mime type of the protected content
324+
* @return
325+
* Handle for the decryption session
326+
*/
327+
sp<DecryptHandle> openDecryptSession(int uniqueId, const DrmBuffer& buf,
328+
const String8& mimeType);
329+
318330
/**
319331
* Close the decrypt session for the given handle
320332
*

drm/libdrmframework/include/DrmManagerService.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class DrmManagerService : public BnDrmManagerService {
102102

103103
DecryptHandle* openDecryptSession(int uniqueId, const char* uri);
104104

105+
DecryptHandle* openDecryptSession(int uniqueId, const DrmBuffer& buf,
106+
const String8& mimeType);
107+
105108
status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
106109

107110
status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,

drm/libdrmframework/include/IDrmManagerService.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class IDrmManagerService : public IInterface
7070
GET_ALL_SUPPORT_INFO,
7171
OPEN_DECRYPT_SESSION,
7272
OPEN_DECRYPT_SESSION_FROM_URI,
73+
OPEN_DECRYPT_SESSION_FOR_STREAMING,
7374
CLOSE_DECRYPT_SESSION,
7475
INITIALIZE_DECRYPT_UNIT,
7576
DECRYPT,
@@ -143,6 +144,9 @@ class IDrmManagerService : public IInterface
143144

144145
virtual DecryptHandle* openDecryptSession(int uniqueId, const char* uri) = 0;
145146

147+
virtual DecryptHandle* openDecryptSession(
148+
int uniqueId, const DrmBuffer& buf, const String8& mimeType) = 0;
149+
146150
virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0;
147151

148152
virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
@@ -226,6 +230,9 @@ class BpDrmManagerService: public BpInterface<IDrmManagerService>
226230

227231
virtual DecryptHandle* openDecryptSession(int uniqueId, const char* uri);
228232

233+
virtual DecryptHandle* openDecryptSession(
234+
int uniqueId, const DrmBuffer& buf, const String8& mimeType);
235+
229236
virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
230237

231238
virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,

0 commit comments

Comments
 (0)