clean code, change remote request code.

Signed-off-by: jiangchunli <jiangchunli1@huawei.com>
This commit is contained in:
jiangchunli
2024-07-10 09:16:00 +00:00
parent a04a243448
commit 3d3da678d2
8 changed files with 35 additions and 32 deletions
@@ -412,7 +412,7 @@ bool DrmServiceNdkFuzzer::DrmserviceGetMediaDecryptModuleTest(uint8_t *rawData,
MessageOption option;
MessageParcel data;
data.WriteInterfaceToken(MEDIA_KEY_SESSION_TOKEN);
mediaKeySessionService->OnRemoteRequest(CREATE_MEDIA_DECRYPT_MODULE, data, reply, option);
mediaKeySessionService->OnRemoteRequest(GET_MEDIA_DECRYPT_MODULE, data, reply, option);
return true;
}
@@ -38,7 +38,7 @@ int32_t MediaKeySessionServiceProxy::GetMediaDecryptModule(sptr<IMediaDecryptMod
return IPC_PROXY_ERR;
}
int32_t ret = MediaKeySessionServiceProxy::Remote()->SendRequest(CREATE_MEDIA_DECRYPT_MODULE, data, reply, option);
int32_t ret = MediaKeySessionServiceProxy::Remote()->SendRequest(GET_MEDIA_DECRYPT_MODULE, data, reply, option);
if (ret != ERR_NONE) {
DRM_ERR_LOG("MediaKeySessionServiceProxy::GetMediaDecryptModule failed, ret: %{public}d", ret);
return ret;
@@ -46,7 +46,7 @@ enum MediaKeySystemServiceRequestCode {
};
enum MediaKeySessionServiceRequestCode {
CREATE_MEDIA_DECRYPT_MODULE = 0,
GET_MEDIA_DECRYPT_MODULE = 0,
KEY_SESSION_RELEASE,
MEDIA_KEY_SESSION_GENERATE_LICENSE_REQUEST,
MEDIA_KEY_SESSION_PROCESS_LICENSE_RESPONSE,
@@ -60,7 +60,7 @@ private:
std::mutex moduleLock_;
sptr<OHOS::HDI::Drm::V1_0::IMediaDecryptModule> hdiMediaDecryptModule_;
std::mutex statisticsMutex_;
DecryptStatistics decryptStatustics_;
DecryptStatistics decryptStatistics_;
uint64_t instanceId_;
};
} // DrmStandard
@@ -69,7 +69,7 @@ static int32_t ProcessSetListenerObject(MediaKeySessionServiceStub *stub, Messag
MessageParcel &reply, MessageOption &option);
static struct ProcessRemoteRequestFuncArray g_mediaKeySessionServiceStubRequestProcessFunc[] = {
{CREATE_MEDIA_DECRYPT_MODULE, ProcessGetMediaDecryptModule},
{GET_MEDIA_DECRYPT_MODULE, ProcessGetMediaDecryptModule},
{KEY_SESSION_RELEASE, ProcessRleaseKeySession},
{MEDIA_KEY_SESSION_GENERATE_LICENSE_REQUEST, ProcessMediaKeyRequest},
{MEDIA_KEY_SESSION_PROCESS_LICENSE_RESPONSE, ProcessMediaKeyResponse},
@@ -421,7 +421,7 @@ int32_t MediaKeySessionServiceStub::OnRemoteRequest(uint32_t code, MessageParcel
DRM_CHECK_AND_RETURN_RET_LOG(data.ReadInterfaceToken() == GetDescriptor(), errCode,
"MediaKeySessionServiceStub: ReadInterfaceToken failed.");
DRM_CHECK_AND_RETURN_RET_LOG((code >= CREATE_MEDIA_DECRYPT_MODULE) && (code <= MEDIA_KEY_SESSION_GETSECURITYLEVEL),
DRM_CHECK_AND_RETURN_RET_LOG((code >= GET_MEDIA_DECRYPT_MODULE) && (code <= MEDIA_KEY_SESSION_GETSECURITYLEVEL),
IPCObjectStub::OnRemoteRequest(code, data, reply, option),
"code not match, need check MediaKeySessionServiceStub");
return g_mediaKeySessionServiceStubRequestProcessFunc[code].processFunc(this, data, reply, option);
@@ -146,20 +146,20 @@ void MediaDecryptModuleService::ReportDecryptionStatisticEvent()
std::shared_ptr<Media::Meta> meta = std::make_shared<Media::Meta>();
meta->SetData(Media::Tag::DRM_APP_NAME, GetClientBundleName(IPCSkeleton::GetCallingUid()));
meta->SetData(Media::Tag::DRM_INSTANCE_ID, std::to_string(instanceId_));
meta->SetData(Media::Tag::DRM_ERROR_CODE, decryptStatustics_.errCode);
meta->SetData(Media::Tag::DRM_ERROR_MESG, decryptStatustics_.errMessage);
meta->SetData(Media::Tag::DRM_DECRYPT_TIMES, decryptStatustics_.decryptTimes);
if (decryptStatustics_.decryptTimes != 0) {
meta->SetData(Media::Tag::DRM_ERROR_CODE, decryptStatistics_.errCode);
meta->SetData(Media::Tag::DRM_ERROR_MESG, decryptStatistics_.errMessage);
meta->SetData(Media::Tag::DRM_DECRYPT_TIMES, decryptStatistics_.decryptTimes);
if (decryptStatistics_.decryptTimes != 0) {
meta->SetData(Media::Tag::DRM_DECRYPT_AVG_SIZE,
static_cast<uint32_t>(decryptStatustics_.decryptSumSize / decryptStatustics_.decryptTimes));
static_cast<uint32_t>(decryptStatistics_.decryptSumSize / decryptStatistics_.decryptTimes));
meta->SetData(Media::Tag::DRM_DECRYPT_AVG_DURATION,
static_cast<uint32_t>(decryptStatustics_.decryptSumDuration / decryptStatustics_.decryptTimes));
static_cast<uint32_t>(decryptStatistics_.decryptSumDuration / decryptStatistics_.decryptTimes));
} else {
meta->SetData(Media::Tag::DRM_DECRYPT_AVG_SIZE, 0);
meta->SetData(Media::Tag::DRM_DECRYPT_AVG_DURATION, 0);
}
meta->SetData(Media::Tag::DRM_DECRYPT_MAX_SIZE, decryptStatustics_.decryptMaxSize);
meta->SetData(Media::Tag::DRM_DECRYPT_MAX_DURATION, decryptStatustics_.decryptMaxDuration);
meta->SetData(Media::Tag::DRM_DECRYPT_MAX_SIZE, decryptStatistics_.decryptMaxSize);
meta->SetData(Media::Tag::DRM_DECRYPT_MAX_DURATION, decryptStatistics_.decryptMaxDuration);
DrmEvent::GetInstance().AppendMediaInfo(meta, instanceId_);
DrmEvent::GetInstance().ReportMediaInfo(instanceId_);
}
@@ -168,20 +168,25 @@ void MediaDecryptModuleService::UpdateDecryptionStatistics(int32_t decryptionRes
uint32_t bufLen, uint32_t curDuration)
{
std::lock_guard<std::mutex> statisticsLock(statisticsMutex_);
decryptStatustics_.topThree.push(curDuration);
if (decryptStatustics_.topThree.size() > TOP_THREE_SIZE) {
decryptStatustics_.topThree.pop();
decryptStatistics_.topThree.push(curDuration);
if (decryptStatistics_.topThree.size() > TOP_THREE_SIZE) {
decryptStatistics_.topThree.pop();
}
if (decryptStatustics_.decryptMaxSize < bufLen) {
decryptStatustics_.decryptMaxSize = bufLen;
if (decryptStatistics_.decryptMaxSize < bufLen) {
decryptStatistics_.decryptMaxSize = bufLen;
}
if (decryptionResult != DRM_OK) {
decryptStatustics_.errorDecryptTimes++;
decryptStatistics_.errorDecryptTimes++;
}
decryptStatustics_.decryptTimes++;
decryptStatustics_.decryptSumSize += bufLen;
decryptStatustics_.decryptSumDuration += curDuration;
if (decryptStatistics_.decryptTimes == UINT32_MAX) {
decryptStatistics_.decryptTimes = 0;
decryptStatistics_.decryptSumSize = 0;
decryptStatistics_.decryptSumDuration = 0;
}
decryptStatistics_.decryptTimes++;
decryptStatistics_.decryptSumSize += bufLen;
decryptStatistics_.decryptSumDuration += curDuration;
}
const std::string MediaDecryptModuleService::GetTopThreeDecryptionDurations()
@@ -189,14 +194,14 @@ const std::string MediaDecryptModuleService::GetTopThreeDecryptionDurations()
DRM_INFO_LOG("MediaDecryptModuleService::GetTopThreeDecryptionDurations");
std::vector<uint32_t> topThreeDurations(TOP_THREE_SIZE, 0);
std::lock_guard<std::mutex> statisticsLock(statisticsMutex_);
uint32_t currentTopThreeSize = decryptStatustics_.topThree.size();
uint32_t currentTopThreeSize = decryptStatistics_.topThree.size();
for (uint32_t i = 0; i < currentTopThreeSize; i++) {
uint32_t tmp = decryptStatustics_.topThree.top();
decryptStatustics_.topThree.pop();
uint32_t tmp = decryptStatistics_.topThree.top();
decryptStatistics_.topThree.pop();
topThreeDurations[i] = tmp;
}
for (uint32_t i = 0; i < currentTopThreeSize; i++) {
decryptStatustics_.topThree.push(topThreeDurations[i]);
decryptStatistics_.topThree.push(topThreeDurations[i]);
}
return std::to_string(topThreeDurations[TOP_ONE]) + " " +
std::to_string(topThreeDurations[TOP_SEC]) + " " +
@@ -206,8 +211,8 @@ const std::string MediaDecryptModuleService::GetTopThreeDecryptionDurations()
std::string MediaDecryptModuleService::GetDumpInfo()
{
DRM_INFO_LOG("MediaDecryptModuleService::GetDumpInfo");
std::string dumpInfo = "Total Decryption Times: " + std::to_string(decryptStatustics_.decryptTimes) + "\n"
"Error Decryption Times: " + std::to_string(decryptStatustics_.errorDecryptTimes) + "\n"
std::string dumpInfo = "Total Decryption Times: " + std::to_string(decryptStatistics_.decryptTimes) + "\n"
"Error Decryption Times: " + std::to_string(decryptStatistics_.errorDecryptTimes) + "\n"
"Top3 Decryption Duration: " + GetTopThreeDecryptionDurations();
return dumpInfo;
}
@@ -316,6 +316,7 @@ int32_t MediaKeySystemFactoryService::WriteDumpInfo(int32_t fd, std::string &dum
dumpString += "#### MediaKeySystem " + std::to_string(systemNum) + " ####\n";
dumpString += "PID: " + std::to_string(pidIter.first) + "\n";
for (auto &system : pidIter.second) {
dumpString += "-------------------------------\n";
IMediaKeySystemService::CertificateStatus certStatus = IMediaKeySystemService::CERT_STATUS_UNAVAILABLE;
system->GetCertificateStatus(&certStatus);
dumpString += "Plugin Name: " + system->GetPluginName() + "\n";
-3
View File
@@ -32,10 +32,7 @@ namespace DrmStandard {
uint32_t __attribute__((visibility("default"))) CalculateTimeDiff(std::chrono::system_clock::time_point timeBefore,
std::chrono::system_clock::time_point timeAfter);
const int minimumDigit = 2;
const std::string currentSessionNum = "currentSessionNum";
const std::string version = "version";
const std::string errorDecryptNumber = "errorDecryptNumber";
const std::string decryptTimes = "decryptTimes";
const std::string vendor = "vendor";
} // namespace DrmStandard
} // namespace OHOS