!310 DRM内存泄漏问题处理

Merge pull request !310 from baoxy92/master
This commit is contained in:
openharmony_ci
2024-10-25 07:13:54 +00:00
committed by Gitee
11 changed files with 2 additions and 98 deletions
@@ -39,24 +39,6 @@ MediaKeySessionImpl::MediaKeySessionImpl(sptr<IMediaKeySessionService> &keySessi
DRM_ERR_LOG("failed to add deathRecipient");
return;
}
CreateListenerObject();
}
int32_t MediaKeySessionImpl::CreateListenerObject()
{
DRM_INFO_LOG("CreateListenerObject");
std::lock_guard<std::recursive_mutex> lock(mutex_);
listenerStub_ = new(std::nothrow) DrmListenerStub();
DRM_CHECK_AND_RETURN_RET_LOG(listenerStub_ != nullptr, DRM_MEMORY_ERROR,
"failed to new DrmListenerStub object");
DRM_CHECK_AND_RETURN_RET_LOG(keySessionServiceProxy_ != nullptr, DRM_MEMORY_ERROR,
"Drm service does not exist.");
sptr<IRemoteObject> object = listenerStub_->AsObject();
DRM_CHECK_AND_RETURN_RET_LOG(object != nullptr, DRM_MEMORY_ERROR, "listener object is nullptr.");
return keySessionServiceProxy_->SetListenerObject(object);
}
MediaKeySessionImpl::~MediaKeySessionImpl()
@@ -78,7 +60,6 @@ void MediaKeySessionImpl::MediaKeySessionServerDied(pid_t pid)
(void)keySessionServiceProxy_->AsObject()->RemoveDeathRecipient(deathRecipient_);
keySessionServiceProxy_ = nullptr;
}
listenerStub_ = nullptr;
deathRecipient_ = nullptr;
}
@@ -39,8 +39,6 @@ MediaKeySystemImpl::MediaKeySystemImpl(sptr<IMediaKeySystemService> &mediaKeysys
DRM_ERR_LOG("failed to add deathRecipient");
return;
}
CreateListenerObject();
}
MediaKeySystemImpl::~MediaKeySystemImpl()
@@ -58,23 +56,6 @@ void MediaKeySystemImpl::MediaKeySystemServerDied(pid_t pid)
serviceProxy_ = nullptr;
deathRecipient_ = nullptr;
}
listenerStub_ = nullptr;
}
int32_t MediaKeySystemImpl::CreateListenerObject()
{
DRM_INFO_LOG("CreateListenerObject");
std::lock_guard<std::recursive_mutex> lock(mutex_);
listenerStub_ = new(std::nothrow) DrmListenerStub();
DRM_CHECK_AND_RETURN_RET_LOG(listenerStub_ != nullptr, DRM_MEMORY_ERROR,
"failed to new DrmListenerStub object");
DRM_CHECK_AND_RETURN_RET_LOG(serviceProxy_ != nullptr, DRM_MEMORY_ERROR,
"Drm service does not exist.");
sptr<IRemoteObject> object = listenerStub_->AsObject();
DRM_CHECK_AND_RETURN_RET_LOG(object != nullptr, DRM_MEMORY_ERROR, "listener object is nullptr.");
return serviceProxy_->SetListenerObject(object);
}
int32_t MediaKeySystemImpl::Release()
@@ -72,14 +72,12 @@ public:
int32_t RequireSecureDecoderModule(std::string &mimeType, bool *status);
private:
int32_t CreateListenerObject();
void MediaKeySessionServerDied(pid_t pid);
sptr<MediaKeySessionImplCallback> keySessionApplicationCallback_;
sptr<IMediaKeySessionServiceCallback> keySessionServiceCallback_;
sptr<OHOS::DrmStandard::IMediaKeySessionService> keySessionServiceProxy_;
std::recursive_mutex mutex_;
sptr<DrmDeathRecipient> deathRecipient_ = nullptr;
sptr<DrmListenerStub> listenerStub_ = nullptr;
};
class MediaKeySessionServiceCallback : public MediaKeySessionServiceCallbackStub {
@@ -68,13 +68,11 @@ public:
private:
void MediaKeySystemServerDied(pid_t pid);
int32_t CreateListenerObject();
std::recursive_mutex mutex_;
sptr<IMediaKeySystemService> serviceProxy_;
sptr<MediaKeySystemImplCallback> mediaKeySystemApplicationCallback_;
sptr<IMediaKeySystemServiceCallback> serviceCallback_;
sptr<DrmDeathRecipient> deathRecipient_ = nullptr;
sptr<DrmListenerStub> listenerStub_ = nullptr;
};
class MediaKeySystemCallback : public MediaKeySystemServiceCallbackStub {
@@ -28,7 +28,6 @@ public:
explicit MediaDecryptModuleServiceProxy(const sptr<IRemoteObject> &impl);
virtual ~MediaDecryptModuleServiceProxy() = default;
int32_t Release() override;
int32_t SetListenerObject(const sptr<IRemoteObject> &object) override;
int32_t DecryptMediaData(bool secureDecodrtState, IMediaDecryptModuleService::CryptInfo &cryptInfo,
IMediaDecryptModuleService::DrmBuffer &srcBuffer, IMediaDecryptModuleService::DrmBuffer &dstBuffer) override;
@@ -44,23 +44,6 @@ int32_t MediaDecryptModuleServiceProxy::Release()
return ret;
}
int32_t MediaDecryptModuleServiceProxy::SetListenerObject(const sptr<IRemoteObject> &object)
{
DRM_INFO_LOG("SetListenerObject enter.");
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(GetDescriptor());
(void)data.WriteRemoteObject(object);
int ret = Remote()->SendRequest(DECRYPT_MODULE_SET_LISTENER_OBJ, data, reply, option);
if (ret != DRM_OK) {
DRM_ERR_LOG("Set listener obj failed, errcode: %{public}d", ret);
return IPC_PROXY_ERR;
}
return reply.ReadInt32();
}
int32_t MediaDecryptModuleServiceProxy::ProcessDrmBuffer(MessageParcel &data,
IMediaDecryptModuleService::DrmBuffer &srcBuffer, IMediaDecryptModuleService::DrmBuffer &dstBuffer)
{
@@ -64,7 +64,6 @@ public:
virtual ~IMediaDecryptModuleService() = default;
virtual int32_t Release() = 0;
virtual int32_t SetListenerObject(const sptr<IRemoteObject> &object) = 0;
virtual int32_t DecryptMediaData(bool secureDecodrtState, IMediaDecryptModuleService::CryptInfo &cryptInfo,
DrmBuffer &srcBuffer, DrmBuffer &dstBuffer) = 0;
DECLARE_INTERFACE_DESCRIPTOR(u"IMediaDecryptModuleService");
@@ -63,8 +63,7 @@ enum MediaKeySessionServiceRequestCode {
enum MediaDecryptModuleServiceRequestCode {
DECRYPT_MODULE_DECRYPT_DATA = 0,
DECRYPT_MODULE_SET_LISTENER_OBJ = 1,
DECRYPT_MODULE_RELEASE = 2,
DECRYPT_MODULE_RELEASE = 1,
};
enum MediaKeySessionServiceCallbackRequestCode {
@@ -35,8 +35,6 @@ public:
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option) override;
int32_t SetListenerObject(const sptr<IRemoteObject> &object) override;
private:
void MediaDecryptModuleClientDied(pid_t pid);
std::recursive_mutex decryptModuleStubMutex_;
@@ -462,6 +462,7 @@ void DrmHostManager::ReleaseSevices(sptr<IMediaKeySystemFactory> drmHostServiePr
remote->RemoveDeathRecipient(drmHostDeathRecipientMap[drmHostServieProxy]);
drmHostDeathRecipientMap[drmHostServieProxy] = nullptr;
}
drmHostDeathRecipientMap.erase(drmHostServieProxy);
std::string name = hdiMediaKeySystemFactoryAndPluginNameMap[drmHostServieProxy];
/* No need to release non lazy loading */
if (lazyLoadPluginInfoMap.count(name) <= 0) {
@@ -44,33 +44,6 @@ void MediaDecryptModuleServiceStub::MediaDecryptModuleClientDied(pid_t pid)
}
}
int32_t MediaDecryptModuleServiceStub::SetListenerObject(const sptr<IRemoteObject> &object)
{
pid_t pid = IPCSkeleton::GetCallingPid();
std::lock_guard<std::recursive_mutex> lock(decryptModuleStubMutex_);
if (clientListener_ != nullptr && clientListener_->AsObject() != nullptr && deathRecipient_ != nullptr) {
DRM_DEBUG_LOG("This MediaDecryptModuleServiceStub has already set listener!");
(void)clientListener_->AsObject()->RemoveDeathRecipient(deathRecipient_);
deathRecipient_ = nullptr;
clientListener_ = nullptr;
}
DRM_CHECK_AND_RETURN_RET_LOG(object != nullptr, DRM_MEMORY_ERROR, "set listener object is nullptr");
sptr<IDrmListener> clientListener_ = iface_cast<IDrmListener>(object);
DRM_CHECK_AND_RETURN_RET_LOG(
clientListener_ != nullptr, DRM_MEMORY_ERROR, "failed to convert IDrmListener");
deathRecipient_ = new (std::nothrow) DrmDeathRecipient(pid);
DRM_CHECK_AND_RETURN_RET_LOG(deathRecipient_ != nullptr, DRM_MEMORY_ERROR, "failed to new DrmDeathRecipient");
deathRecipient_->SetNotifyCb([this] (pid_t pid) {
this->MediaDecryptModuleClientDied(pid);
});
if (clientListener_->AsObject() != nullptr) {
(void)clientListener_->AsObject()->AddDeathRecipient(deathRecipient_);
}
DRM_DEBUG_LOG("MediaDecryptModule client pid:%{public}d", pid);
return DRM_OK;
}
int32_t MediaDecryptModuleServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
@@ -139,12 +112,6 @@ int32_t MediaDecryptModuleServiceStub::OnRemoteRequest(uint32_t code, MessagePar
}
return ret;
}
case DECRYPT_MODULE_SET_LISTENER_OBJ: {
DRM_INFO_LOG("DECRYPT_MODULE_SET_LISTENER_OBJ enter.");
sptr<IRemoteObject> object = data.ReadRemoteObject();
int32_t ret = SetListenerObject(object);
return ret;
}
case DECRYPT_MODULE_RELEASE: {
DRM_INFO_LOG("MediaDecryptModuleServiceStub DECRYPT_MODULE_RELEASE enter.");
int32_t ret = Release();