From b5ce361d19e69fe156f7188c9ee0f4734b259874 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Thu, 24 Feb 2011 16:40:57 -0800 Subject: Fix for bug 3477330 This patch fixs a crash bug caused by using a NULL DecryptHandle pointer. Fix by using sp instead. Change-Id: Icbd59858385e8256125a615a3c82656b25319d44 --- drm/common/IDrmManagerService.cpp | 5 - drm/libdrmframework/DrmManagerClient.cpp | 25 +++-- drm/libdrmframework/DrmManagerClientImpl.cpp | 111 +++++++++++++-------- drm/libdrmframework/include/DrmManagerClientImpl.h | 18 ++-- include/drm/DrmManagerClient.h | 21 ++-- include/drm/drm_framework_common.h | 10 +- include/media/stagefright/DataSource.h | 4 +- include/media/stagefright/FileSource.h | 6 +- media/libstagefright/AwesomePlayer.cpp | 5 +- media/libstagefright/DRMExtractor.cpp | 10 +- media/libstagefright/FileSource.cpp | 6 +- media/libstagefright/NuCachedSource2.cpp | 4 +- media/libstagefright/NuHTTPDataSource.cpp | 6 +- .../chromium_http/ChromiumHTTPDataSource.cpp | 6 +- media/libstagefright/include/AwesomePlayer.h | 2 +- .../include/ChromiumHTTPDataSource.h | 6 +- media/libstagefright/include/DRMExtractor.h | 2 +- media/libstagefright/include/NuCachedSource2.h | 4 +- media/libstagefright/include/NuHTTPDataSource.h | 6 +- 19 files changed, 146 insertions(+), 111 deletions(-) diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index 696e305..e2bfb16 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -621,11 +621,6 @@ status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* d remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply); - if (NULL != decryptHandle->decryptInfo) { - LOGV("deleting decryptInfo"); - delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL; - } - delete decryptHandle; decryptHandle = NULL; return reply.readInt32(); } diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp index 7b51822..3143d45 100644 --- a/drm/libdrmframework/DrmManagerClient.cpp +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -77,13 +77,14 @@ int DrmManagerClient::checkRightsStatus(const String8& path, int action) { return mDrmManagerClientImpl->checkRightsStatus(mUniqueId, path, action); } -status_t DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int action, bool reserve) { +status_t DrmManagerClient::consumeRights( + sp &decryptHandle, int action, bool reserve) { Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve); } status_t DrmManagerClient::setPlaybackStatus( - DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { + sp &decryptHandle, int playbackStatus, int64_t position) { return mDrmManagerClientImpl ->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position); } @@ -117,40 +118,42 @@ status_t DrmManagerClient::getAllSupportInfo(int* length, DrmSupportInfo** drmSu return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray); } -DecryptHandle* DrmManagerClient::openDecryptSession(int fd, off64_t offset, off64_t length) { +sp DrmManagerClient::openDecryptSession(int fd, off64_t offset, off64_t length) { return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length); } -DecryptHandle* DrmManagerClient::openDecryptSession(const char* uri) { +sp DrmManagerClient::openDecryptSession(const char* uri) { return mDrmManagerClientImpl->openDecryptSession(mUniqueId, uri); } -status_t DrmManagerClient::closeDecryptSession(DecryptHandle* decryptHandle) { +status_t DrmManagerClient::closeDecryptSession(sp &decryptHandle) { return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle); } status_t DrmManagerClient::initializeDecryptUnit( - DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { + sp &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->initializeDecryptUnit( mUniqueId, decryptHandle, decryptUnitId, headerInfo); } status_t DrmManagerClient::decrypt( - DecryptHandle* decryptHandle, int decryptUnitId, - const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { + sp &decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->decrypt( mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); } -status_t DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId) { +status_t DrmManagerClient::finalizeDecryptUnit( + sp &decryptHandle, int decryptUnitId) { Mutex::Autolock _l(mDecryptLock); - return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, decryptHandle, decryptUnitId); + return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, + decryptHandle, decryptUnitId); } ssize_t DrmManagerClient::pread( - DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { + sp &decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset); } diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index d20de92..e6ae220 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -78,14 +78,16 @@ void DrmManagerClientImpl::removeClient(int uniqueId) { } status_t DrmManagerClientImpl::setOnInfoListener( - int uniqueId, const sp& infoListener) { + int uniqueId, + const sp& infoListener) { Mutex::Autolock _l(mLock); mOnInfoListener = infoListener; return getDrmManagerService()->setDrmServiceListener(uniqueId, (NULL != infoListener.get()) ? this : NULL); } -status_t DrmManagerClientImpl::installDrmEngine(int uniqueId, const String8& drmEngineFile) { +status_t DrmManagerClientImpl::installDrmEngine( + int uniqueId, const String8& drmEngineFile) { status_t status = DRM_ERROR_UNKNOWN; if (EMPTY_STRING != drmEngineFile) { status = getDrmManagerService()->installDrmEngine(uniqueId, drmEngineFile); @@ -97,7 +99,8 @@ DrmConstraints* DrmManagerClientImpl::getConstraints( int uniqueId, const String8* path, const int action) { DrmConstraints *drmConstraints = NULL; if ((NULL != path) && (EMPTY_STRING != *path)) { - drmConstraints = getDrmManagerService()->getConstraints(uniqueId, path, action); + drmConstraints = + getDrmManagerService()->getConstraints(uniqueId, path, action); } return drmConstraints; } @@ -110,7 +113,8 @@ DrmMetadata* DrmManagerClientImpl::getMetadata(int uniqueId, const String8* path return drmMetadata; } -bool DrmManagerClientImpl::canHandle(int uniqueId, const String8& path, const String8& mimeType) { +bool DrmManagerClientImpl::canHandle( + int uniqueId, const String8& path, const String8& mimeType) { bool retCode = false; if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) { retCode = getDrmManagerService()->canHandle(uniqueId, path, mimeType); @@ -118,7 +122,8 @@ bool DrmManagerClientImpl::canHandle(int uniqueId, const String8& path, const St return retCode; } -DrmInfoStatus* DrmManagerClientImpl::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { +DrmInfoStatus* DrmManagerClientImpl::processDrmInfo( + int uniqueId, const DrmInfo* drmInfo) { DrmInfoStatus *drmInfoStatus = NULL; if (NULL != drmInfo) { drmInfoStatus = getDrmManagerService()->processDrmInfo(uniqueId, drmInfo); @@ -126,7 +131,8 @@ DrmInfoStatus* DrmManagerClientImpl::processDrmInfo(int uniqueId, const DrmInfo* return drmInfoStatus; } -DrmInfo* DrmManagerClientImpl::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { +DrmInfo* DrmManagerClientImpl::acquireDrmInfo( + int uniqueId, const DrmInfoRequest* drmInfoRequest) { DrmInfo* drmInfo = NULL; if (NULL != drmInfoRequest) { drmInfo = getDrmManagerService()->acquireDrmInfo(uniqueId, drmInfoRequest); @@ -138,12 +144,14 @@ status_t DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRigh const String8& rightsPath, const String8& contentPath) { status_t status = DRM_ERROR_UNKNOWN; if (EMPTY_STRING != contentPath) { - status = getDrmManagerService()->saveRights(uniqueId, drmRights, rightsPath, contentPath); + status = getDrmManagerService()->saveRights( + uniqueId, drmRights, rightsPath, contentPath); } return status; } -String8 DrmManagerClientImpl::getOriginalMimeType(int uniqueId, const String8& path) { +String8 DrmManagerClientImpl::getOriginalMimeType( + int uniqueId, const String8& path) { String8 mimeType = EMPTY_STRING; if (EMPTY_STRING != path) { mimeType = getDrmManagerService()->getOriginalMimeType(uniqueId, path); @@ -155,7 +163,8 @@ int DrmManagerClientImpl::getDrmObjectType( int uniqueId, const String8& path, const String8& mimeType) { int drmOjectType = DrmObjectType::UNKNOWN; if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) { - drmOjectType = getDrmManagerService()->getDrmObjectType(uniqueId, path, mimeType); + drmOjectType = + getDrmManagerService()->getDrmObjectType(uniqueId, path, mimeType); } return drmOjectType; } @@ -164,35 +173,41 @@ int DrmManagerClientImpl::checkRightsStatus( int uniqueId, const String8& path, int action) { int rightsStatus = RightsStatus::RIGHTS_INVALID; if (EMPTY_STRING != path) { - rightsStatus = getDrmManagerService()->checkRightsStatus(uniqueId, path, action); + rightsStatus = + getDrmManagerService()->checkRightsStatus(uniqueId, path, action); } return rightsStatus; } status_t DrmManagerClientImpl::consumeRights( - int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { + int uniqueId, sp &decryptHandle, + int action, bool reserve) { status_t status = DRM_ERROR_UNKNOWN; - if (NULL != decryptHandle) { - status = getDrmManagerService()->consumeRights(uniqueId, decryptHandle, action, reserve); + if (NULL != decryptHandle.get()) { + status = getDrmManagerService()->consumeRights( + uniqueId, decryptHandle.get(), action, reserve); } return status; } status_t DrmManagerClientImpl::setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { + int uniqueId, sp &decryptHandle, + int playbackStatus, int64_t position) { status_t status = DRM_ERROR_UNKNOWN; - if (NULL != decryptHandle) { + if (NULL != decryptHandle.get()) { status = getDrmManagerService()->setPlaybackStatus( - uniqueId, decryptHandle, playbackStatus, position); + uniqueId, decryptHandle.get(), playbackStatus, position); } return status; } bool DrmManagerClientImpl::validateAction( - int uniqueId, const String8& path, int action, const ActionDescription& description) { + int uniqueId, const String8& path, + int action, const ActionDescription& description) { bool retCode = false; if (EMPTY_STRING != path) { - retCode = getDrmManagerService()->validateAction(uniqueId, path, action, description); + retCode = getDrmManagerService()->validateAction( + uniqueId, path, action, description); } return retCode; } @@ -209,7 +224,8 @@ status_t DrmManagerClientImpl::removeAllRights(int uniqueId) { return getDrmManagerService()->removeAllRights(uniqueId); } -int DrmManagerClientImpl::openConvertSession(int uniqueId, const String8& mimeType) { +int DrmManagerClientImpl::openConvertSession( + int uniqueId, const String8& mimeType) { int retCode = INVALID_VALUE; if (EMPTY_STRING != mimeType) { retCode = getDrmManagerService()->openConvertSession(uniqueId, mimeType); @@ -221,12 +237,14 @@ DrmConvertedStatus* DrmManagerClientImpl::convertData( int uniqueId, int convertId, const DrmBuffer* inputData) { DrmConvertedStatus* drmConvertedStatus = NULL; if (NULL != inputData) { - drmConvertedStatus = getDrmManagerService()->convertData(uniqueId, convertId, inputData); + drmConvertedStatus = + getDrmManagerService()->convertData(uniqueId, convertId, inputData); } return drmConvertedStatus; } -DrmConvertedStatus* DrmManagerClientImpl::closeConvertSession(int uniqueId, int convertId) { +DrmConvertedStatus* DrmManagerClientImpl::closeConvertSession( + int uniqueId, int convertId) { return getDrmManagerService()->closeConvertSession(uniqueId, convertId); } @@ -234,17 +252,19 @@ status_t DrmManagerClientImpl::getAllSupportInfo( int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { status_t status = DRM_ERROR_UNKNOWN; if ((NULL != drmSupportInfoArray) && (NULL != length)) { - status = getDrmManagerService()->getAllSupportInfo(uniqueId, length, drmSupportInfoArray); + status = getDrmManagerService()->getAllSupportInfo( + uniqueId, length, drmSupportInfoArray); } return status; } -DecryptHandle* DrmManagerClientImpl::openDecryptSession( +sp DrmManagerClientImpl::openDecryptSession( int uniqueId, int fd, off64_t offset, off64_t length) { return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length); } -DecryptHandle* DrmManagerClientImpl::openDecryptSession(int uniqueId, const char* uri) { +sp DrmManagerClientImpl::openDecryptSession( + int uniqueId, const char* uri) { DecryptHandle* handle = NULL; if (NULL != uri) { handle = getDrmManagerService()->openDecryptSession(uniqueId, uri); @@ -252,50 +272,57 @@ DecryptHandle* DrmManagerClientImpl::openDecryptSession(int uniqueId, const char return handle; } -status_t DrmManagerClientImpl::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { +status_t DrmManagerClientImpl::closeDecryptSession( + int uniqueId, sp &decryptHandle) { status_t status = DRM_ERROR_UNKNOWN; - if (NULL != decryptHandle) { - status = getDrmManagerService()->closeDecryptSession( uniqueId, decryptHandle); + if (NULL != decryptHandle.get()) { + status = getDrmManagerService()->closeDecryptSession( + uniqueId, decryptHandle.get()); } return status; } -status_t DrmManagerClientImpl::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* headerInfo) { +status_t DrmManagerClientImpl::initializeDecryptUnit( + int uniqueId, sp &decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo) { status_t status = DRM_ERROR_UNKNOWN; - if ((NULL != decryptHandle) && (NULL != headerInfo)) { + if ((NULL != decryptHandle.get()) && (NULL != headerInfo)) { status = getDrmManagerService()->initializeDecryptUnit( - uniqueId, decryptHandle, decryptUnitId, headerInfo); + uniqueId, decryptHandle.get(), decryptUnitId, headerInfo); } return status; } -status_t DrmManagerClientImpl::decrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { +status_t DrmManagerClientImpl::decrypt( + int uniqueId, sp &decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, + DrmBuffer** decBuffer, DrmBuffer* IV) { status_t status = DRM_ERROR_UNKNOWN; - if ((NULL != decryptHandle) && (NULL != encBuffer) + if ((NULL != decryptHandle.get()) && (NULL != encBuffer) && (NULL != decBuffer) && (NULL != *decBuffer)) { status = getDrmManagerService()->decrypt( - uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); + uniqueId, decryptHandle.get(), decryptUnitId, + encBuffer, decBuffer, IV); } return status; } status_t DrmManagerClientImpl::finalizeDecryptUnit( - int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { + int uniqueId, sp &decryptHandle, int decryptUnitId) { status_t status = DRM_ERROR_UNKNOWN; - if (NULL != decryptHandle) { - status - = getDrmManagerService()->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); + if (NULL != decryptHandle.get()) { + status = getDrmManagerService()->finalizeDecryptUnit( + uniqueId, decryptHandle.get(), decryptUnitId); } return status; } -ssize_t DrmManagerClientImpl::pread(int uniqueId, DecryptHandle* decryptHandle, +ssize_t DrmManagerClientImpl::pread(int uniqueId, sp &decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { ssize_t retCode = INVALID_VALUE; - if ((NULL != decryptHandle) && (NULL != buffer) && (0 < numBytes)) { - retCode = getDrmManagerService()->pread(uniqueId, decryptHandle, buffer, numBytes, offset); + if ((NULL != decryptHandle.get()) && (NULL != buffer) && (0 < numBytes)) { + retCode = getDrmManagerService()->pread( + uniqueId, decryptHandle.get(), buffer, numBytes, offset); } return retCode; } diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h index 0a7fcd1..0cba8d4 100644 --- a/drm/libdrmframework/include/DrmManagerClientImpl.h +++ b/drm/libdrmframework/include/DrmManagerClientImpl.h @@ -189,7 +189,7 @@ public: * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + status_t consumeRights(int uniqueId, sp &decryptHandle, int action, bool reserve); /** * Informs the DRM engine about the playback actions performed on the DRM files. @@ -203,7 +203,7 @@ public: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ status_t setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position); + int uniqueId, sp &decryptHandle, int playbackStatus, int64_t position); /** * Validates whether an action on the DRM content is allowed or not. @@ -303,7 +303,7 @@ public: * @return * Handle for the decryption session */ - DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); + sp openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); /** * Open the decrypt session to decrypt the given protected content @@ -313,7 +313,7 @@ public: * @return * Handle for the decryption session */ - DecryptHandle* openDecryptSession(int uniqueId, const char* uri); + sp openDecryptSession(int uniqueId, const char* uri); /** * Close the decrypt session for the given handle @@ -323,7 +323,7 @@ public: * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + status_t closeDecryptSession(int uniqueId, sp &decryptHandle); /** * Initialize decryption for the given unit of the protected content @@ -335,7 +335,7 @@ public: * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + status_t initializeDecryptUnit(int uniqueId, sp &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); /** @@ -355,7 +355,7 @@ public: * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, * DRM_ERROR_DECRYPT for failure. */ - status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + status_t decrypt(int uniqueId, sp &decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV); /** @@ -367,7 +367,7 @@ public: * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + status_t finalizeDecryptUnit(int uniqueId, sp &decryptHandle, int decryptUnitId); /** * Reads the specified number of bytes from an open DRM file. @@ -380,7 +380,7 @@ public: * * @return Number of bytes read. Returns -1 for Failure. */ - ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, + ssize_t pread(int uniqueId, sp &decryptHandle, void* buffer, ssize_t numBytes, off64_t offset); /** diff --git a/include/drm/DrmManagerClient.h b/include/drm/DrmManagerClient.h index 085ebf1..044ff0e 100644 --- a/include/drm/DrmManagerClient.h +++ b/include/drm/DrmManagerClient.h @@ -69,7 +69,7 @@ public: * @return * Handle for the decryption session */ - DecryptHandle* openDecryptSession(int fd, off64_t offset, off64_t length); + sp openDecryptSession(int fd, off64_t offset, off64_t length); /** * Open the decrypt session to decrypt the given protected content @@ -78,7 +78,7 @@ public: * @return * Handle for the decryption session */ - DecryptHandle* openDecryptSession(const char* uri); + sp openDecryptSession(const char* uri); /** * Close the decrypt session for the given handle @@ -87,7 +87,7 @@ public: * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t closeDecryptSession(DecryptHandle* decryptHandle); + status_t closeDecryptSession(sp &decryptHandle); /** * Consumes the rights for a content. @@ -101,7 +101,7 @@ public: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure. * In case license has been expired, DRM_ERROR_LICENSE_EXPIRED will be returned. */ - status_t consumeRights(DecryptHandle* decryptHandle, int action, bool reserve); + status_t consumeRights(sp &decryptHandle, int action, bool reserve); /** * Informs the DRM engine about the playback actions performed on the DRM files. @@ -113,7 +113,8 @@ public: * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t setPlaybackStatus(DecryptHandle* decryptHandle, int playbackStatus, int64_t position); + status_t setPlaybackStatus( + sp &decryptHandle, int playbackStatus, int64_t position); /** * Initialize decryption for the given unit of the protected content @@ -125,7 +126,7 @@ public: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ status_t initializeDecryptUnit( - DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); + sp &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); /** * Decrypt the protected content buffers for the given unit @@ -144,7 +145,7 @@ public: * DRM_ERROR_DECRYPT for failure. */ status_t decrypt( - DecryptHandle* decryptHandle, int decryptUnitId, + sp &decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV = NULL); /** @@ -155,7 +156,8 @@ public: * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId); + status_t finalizeDecryptUnit( + sp &decryptHandle, int decryptUnitId); /** * Reads the specified number of bytes from an open DRM file. @@ -167,7 +169,8 @@ public: * * @return Number of bytes read. Returns -1 for Failure. */ - ssize_t pread(DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset); + ssize_t pread(sp &decryptHandle, + void* buffer, ssize_t numBytes, off64_t offset); /** * Validates whether an action on the DRM content is allowed or not. diff --git a/include/drm/drm_framework_common.h b/include/drm/drm_framework_common.h index 1758cdd..3ad0330 100644 --- a/include/drm/drm_framework_common.h +++ b/include/drm/drm_framework_common.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -240,7 +241,7 @@ public: /** * Defines decryption handle */ -class DecryptHandle { +class DecryptHandle : public RefBase { public: /** * Decryption session Handle @@ -285,10 +286,15 @@ public: decryptId(INVALID_VALUE), mimeType(""), decryptApiType(INVALID_VALUE), - status(INVALID_VALUE) { + status(INVALID_VALUE), + decryptInfo(NULL) { } + ~DecryptHandle() { + delete decryptInfo; decryptInfo = NULL; + } + bool operator<(const DecryptHandle& handle) const { return (decryptId < handle.decryptId); } diff --git a/include/media/stagefright/DataSource.h b/include/media/stagefright/DataSource.h index f95e56a..d30e908 100644 --- a/include/media/stagefright/DataSource.h +++ b/include/media/stagefright/DataSource.h @@ -75,10 +75,10 @@ public: static void RegisterDefaultSniffers(); // for DRM - virtual DecryptHandle* DrmInitialization() { + virtual sp DrmInitialization() { return NULL; } - virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client) {}; + virtual void getDrmInfo(sp &handle, DrmManagerClient **client) {}; virtual String8 getUri() { return String8(); diff --git a/include/media/stagefright/FileSource.h b/include/media/stagefright/FileSource.h index 51a4343..6cf86dc 100644 --- a/include/media/stagefright/FileSource.h +++ b/include/media/stagefright/FileSource.h @@ -38,9 +38,9 @@ public: virtual status_t getSize(off64_t *size); - virtual DecryptHandle* DrmInitialization(); + virtual sp DrmInitialization(); - virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client); + virtual void getDrmInfo(sp &handle, DrmManagerClient **client); protected: virtual ~FileSource(); @@ -52,7 +52,7 @@ private: Mutex mLock; /*for DRM*/ - DecryptHandle *mDecryptHandle; + sp mDecryptHandle; DrmManagerClient *mDrmManagerClient; int64_t mDrmBufOffset; int64_t mDrmBufSize; diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index fbf200f..07e7bd5 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -303,7 +303,7 @@ status_t AwesomePlayer::setDataSource_l( return UNKNOWN_ERROR; } - dataSource->getDrmInfo(&mDecryptHandle, &mDrmManagerClient); + dataSource->getDrmInfo(mDecryptHandle, &mDrmManagerClient); if (mDecryptHandle != NULL) { CHECK(mDrmManagerClient); if (RightsStatus::RIGHTS_VALID != mDecryptHandle->status) { @@ -1689,7 +1689,8 @@ status_t AwesomePlayer::finishSetDataSource_l() { return UNKNOWN_ERROR; } - dataSource->getDrmInfo(&mDecryptHandle, &mDrmManagerClient); + dataSource->getDrmInfo(mDecryptHandle, &mDrmManagerClient); + if (mDecryptHandle != NULL) { CHECK(mDrmManagerClient); if (RightsStatus::RIGHTS_VALID == mDecryptHandle->status) { diff --git a/media/libstagefright/DRMExtractor.cpp b/media/libstagefright/DRMExtractor.cpp index 2809df5..c4ed516 100644 --- a/media/libstagefright/DRMExtractor.cpp +++ b/media/libstagefright/DRMExtractor.cpp @@ -41,7 +41,7 @@ namespace android { class DRMSource : public MediaSource { public: DRMSource(const sp &mediaSource, - DecryptHandle *decryptHandle, + const sp &decryptHandle, DrmManagerClient *managerClient, int32_t trackId, DrmBuffer *ipmpBox); @@ -56,7 +56,7 @@ protected: private: sp mOriginalMediaSource; - DecryptHandle* mDecryptHandle; + sp mDecryptHandle; DrmManagerClient* mDrmManagerClient; size_t mTrackId; mutable Mutex mDRMLock; @@ -70,7 +70,7 @@ private: //////////////////////////////////////////////////////////////////////////////// DRMSource::DRMSource(const sp &mediaSource, - DecryptHandle *decryptHandle, + const sp &decryptHandle, DrmManagerClient *managerClient, int32_t trackId, DrmBuffer *ipmpBox) : mOriginalMediaSource(mediaSource), @@ -245,7 +245,7 @@ DRMExtractor::DRMExtractor(const sp &source, const char* mime) mOriginalExtractor->setDrmFlag(true); mOriginalExtractor->getMetaData()->setInt32(kKeyIsDRM, 1); - source->getDrmInfo(&mDecryptHandle, &mDrmManagerClient); + source->getDrmInfo(mDecryptHandle, &mDrmManagerClient); } DRMExtractor::~DRMExtractor() { @@ -281,7 +281,7 @@ sp DRMExtractor::getMetaData() { bool SniffDRM( const sp &source, String8 *mimeType, float *confidence, sp *) { - DecryptHandle *decryptHandle = source->DrmInitialization(); + sp decryptHandle = source->DrmInitialization(); if (decryptHandle != NULL) { if (decryptHandle->decryptApiType == DecryptApiType::CONTAINER_BASED) { diff --git a/media/libstagefright/FileSource.cpp b/media/libstagefright/FileSource.cpp index 02a78c9..f2f3500 100644 --- a/media/libstagefright/FileSource.cpp +++ b/media/libstagefright/FileSource.cpp @@ -125,7 +125,7 @@ status_t FileSource::getSize(off64_t *size) { return OK; } -DecryptHandle* FileSource::DrmInitialization() { +sp FileSource::DrmInitialization() { if (mDrmManagerClient == NULL) { mDrmManagerClient = new DrmManagerClient(); } @@ -147,8 +147,8 @@ DecryptHandle* FileSource::DrmInitialization() { return mDecryptHandle; } -void FileSource::getDrmInfo(DecryptHandle **handle, DrmManagerClient **client) { - *handle = mDecryptHandle; +void FileSource::getDrmInfo(sp &handle, DrmManagerClient **client) { + handle = mDecryptHandle; *client = mDrmManagerClient; } diff --git a/media/libstagefright/NuCachedSource2.cpp b/media/libstagefright/NuCachedSource2.cpp index c7b99b9..7c65612 100644 --- a/media/libstagefright/NuCachedSource2.cpp +++ b/media/libstagefright/NuCachedSource2.cpp @@ -477,11 +477,11 @@ void NuCachedSource2::resumeFetchingIfNecessary() { restartPrefetcherIfNecessary_l(true /* ignore low water threshold */); } -DecryptHandle* NuCachedSource2::DrmInitialization() { +sp NuCachedSource2::DrmInitialization() { return mSource->DrmInitialization(); } -void NuCachedSource2::getDrmInfo(DecryptHandle **handle, DrmManagerClient **client) { +void NuCachedSource2::getDrmInfo(sp &handle, DrmManagerClient **client) { mSource->getDrmInfo(handle, client); } diff --git a/media/libstagefright/NuHTTPDataSource.cpp b/media/libstagefright/NuHTTPDataSource.cpp index b24343f..73daf12 100644 --- a/media/libstagefright/NuHTTPDataSource.cpp +++ b/media/libstagefright/NuHTTPDataSource.cpp @@ -530,7 +530,7 @@ void NuHTTPDataSource::addBandwidthMeasurement_l( } } -DecryptHandle* NuHTTPDataSource::DrmInitialization() { +sp NuHTTPDataSource::DrmInitialization() { if (mDrmManagerClient == NULL) { mDrmManagerClient = new DrmManagerClient(); } @@ -554,8 +554,8 @@ DecryptHandle* NuHTTPDataSource::DrmInitialization() { return mDecryptHandle; } -void NuHTTPDataSource::getDrmInfo(DecryptHandle **handle, DrmManagerClient **client) { - *handle = mDecryptHandle; +void NuHTTPDataSource::getDrmInfo(sp &handle, DrmManagerClient **client) { + handle = mDecryptHandle; *client = mDrmManagerClient; } diff --git a/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp b/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp index e3a9829..949a5e4 100644 --- a/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp +++ b/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp @@ -273,7 +273,7 @@ bool ChromiumHTTPDataSource::estimateBandwidth(int32_t *bandwidth_bps) { return true; } -DecryptHandle *ChromiumHTTPDataSource::DrmInitialization() { +sp ChromiumHTTPDataSource::DrmInitialization() { Mutex::Autolock autoLock(mLock); if (mDrmManagerClient == NULL) { @@ -301,10 +301,10 @@ DecryptHandle *ChromiumHTTPDataSource::DrmInitialization() { } void ChromiumHTTPDataSource::getDrmInfo( - DecryptHandle **handle, DrmManagerClient **client) { + sp &handle, DrmManagerClient **client) { Mutex::Autolock autoLock(mLock); - *handle = mDecryptHandle; + handle = mDecryptHandle; *client = mDrmManagerClient; } diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h index fe6bf3f..b26f202 100644 --- a/media/libstagefright/include/AwesomePlayer.h +++ b/media/libstagefright/include/AwesomePlayer.h @@ -217,7 +217,7 @@ private: sp mConnectingRTSPController; DrmManagerClient *mDrmManagerClient; - DecryptHandle *mDecryptHandle; + sp mDecryptHandle; status_t setDataSource_l( const char *uri, diff --git a/media/libstagefright/include/ChromiumHTTPDataSource.h b/media/libstagefright/include/ChromiumHTTPDataSource.h index ee8fcda..af49059 100644 --- a/media/libstagefright/include/ChromiumHTTPDataSource.h +++ b/media/libstagefright/include/ChromiumHTTPDataSource.h @@ -45,9 +45,9 @@ struct ChromiumHTTPDataSource : public HTTPBase { virtual bool estimateBandwidth(int32_t *bandwidth_bps); - virtual DecryptHandle *DrmInitialization(); + virtual sp DrmInitialization(); - virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client); + virtual void getDrmInfo(sp &handle, DrmManagerClient **client); virtual String8 getUri(); @@ -95,7 +95,7 @@ private: int64_t mTotalTransferTimeUs; size_t mTotalTransferBytes; - DecryptHandle *mDecryptHandle; + sp mDecryptHandle; DrmManagerClient *mDrmManagerClient; void disconnect_l(); diff --git a/media/libstagefright/include/DRMExtractor.h b/media/libstagefright/include/DRMExtractor.h index 9881cc1..b4e4afb 100644 --- a/media/libstagefright/include/DRMExtractor.h +++ b/media/libstagefright/include/DRMExtractor.h @@ -45,7 +45,7 @@ private: sp mDataSource; sp mOriginalExtractor; - DecryptHandle* mDecryptHandle; + sp mDecryptHandle; DrmManagerClient* mDrmManagerClient; DRMExtractor(const DRMExtractor &); diff --git a/media/libstagefright/include/NuCachedSource2.h b/media/libstagefright/include/NuCachedSource2.h index 022804c..02d5817 100644 --- a/media/libstagefright/include/NuCachedSource2.h +++ b/media/libstagefright/include/NuCachedSource2.h @@ -37,8 +37,8 @@ struct NuCachedSource2 : public DataSource { virtual status_t getSize(off64_t *size); virtual uint32_t flags(); - virtual DecryptHandle* DrmInitialization(); - virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client); + virtual sp DrmInitialization(); + virtual void getDrmInfo(sp &handle, DrmManagerClient **client); virtual String8 getUri(); //////////////////////////////////////////////////////////////////////////// diff --git a/media/libstagefright/include/NuHTTPDataSource.h b/media/libstagefright/include/NuHTTPDataSource.h index ff51ba9..7dd5d59 100644 --- a/media/libstagefright/include/NuHTTPDataSource.h +++ b/media/libstagefright/include/NuHTTPDataSource.h @@ -47,8 +47,8 @@ struct NuHTTPDataSource : public HTTPBase { // false otherwise. virtual bool estimateBandwidth(int32_t *bandwidth_bps); - virtual DecryptHandle* DrmInitialization(); - virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client); + virtual sp DrmInitialization(); + virtual void getDrmInfo(sp &handle, DrmManagerClient **client); virtual String8 getUri(); protected: @@ -94,7 +94,7 @@ private: int64_t mTotalTransferTimeUs; size_t mTotalTransferBytes; - DecryptHandle *mDecryptHandle; + sp mDecryptHandle; DrmManagerClient *mDrmManagerClient; status_t connect( -- cgit v1.1