60 mRegisteredEvents(), mWatermarkPluginObj(WATERMARK_PLUGIN_CALLSIGN), mWatMutex(), mSpeedStateMutex()
63 std::lock_guard<std::mutex> lock(
mSecMutex);
66 std::lock_guard<std::mutex> lock(
mWatMutex);
71 if(
false == mSchedulerStarted)
74 mSchedulerStarted =
true;
85 std::lock_guard<std::mutex> lock(
mSecMutex);
88 if(
true == mSchedulerStarted)
91 mSchedulerStarted =
false;
101 const char* accessAttributes[][2],
const char* contentMetdata,
size_t contMetaLen,
102 const char* licenseRequest,
size_t licReqLen,
const char* keySystemId,
103 const char* mediaUsage,
const char* accessToken,
size_t accTokenLen,
105 char** licenseResponse,
size_t* licenseResponseLength, int32_t* statusCode, int32_t* reasonCode, int32_t* businessStatus)
111 bool rpcResult =
false;
112 unsigned int retryCount = 0;
116 *statusCode = SECMANGER_DRM_FAILURE;
122 void * shmPt_accToken = NULL;
123 key_t shmKey_accToken = 0;
124 void * shmPt_contMeta = NULL;
125 key_t shmKey_contMeta = 0;
126 void * shmPt_licReq = NULL;
127 key_t shmKey_licReq = 0;
129 const char* apiName =
"openPlaybackSession";
132 JsonObject sessionConfig;
133 JsonObject aspectDimensions;
138 sessionConfig[
"distributedTraceType"] =
"money";
139 sessionConfig[
"distributedTraceId"] = moneyTraceMetdata[0][1];
140 sessionConfig[
"sessionState"] =
"active";
143 aspectDimensions[
"width"] = 1920;
144 aspectDimensions[
"height"] = 1080;
146 param[
"clientId"] =
"aamp";
147 param[
"sessionConfiguration"] = sessionConfig;
148 param[
"contentAspectDimensions"] = aspectDimensions;
150 param[
"keySystem"] = keySystemId;
151 param[
"mediaUsage"] = mediaUsage;
154 if (*sessionId != -1)
156 apiName =
"updatePlaybackSession";
157 param[
"sessionId"] = *sessionId;
160 #ifdef DEBUG_SECMAMANER
162 param.ToString(params);
163 AAMPLOG_WARN(
"SecManager openPlaybackSession param: %s", params.c_str());
167 std::lock_guard<std::mutex> lock(
mSecMutex);
168 if(accTokenLen > 0 && contMetaLen > 0 && licReqLen > 0)
170 shmPt_accToken = aamp_CreateSharedMem(accTokenLen, shmKey_accToken);
171 shmPt_contMeta = aamp_CreateSharedMem(contMetaLen, shmKey_contMeta);
172 shmPt_licReq = aamp_CreateSharedMem(licReqLen, shmKey_licReq);
176 if(NULL != shmPt_accToken && NULL != accessToken &&
177 NULL != shmPt_contMeta && NULL != contentMetdata &&
178 NULL != shmPt_licReq && NULL != licenseRequest)
181 memcpy(shmPt_accToken, accessToken, accTokenLen);
182 memcpy(shmPt_contMeta, contentMetdata, contMetaLen);
183 memcpy(shmPt_licReq, licenseRequest, licReqLen);
185 AAMPLOG_INFO(
"Access token, Content metadata and license request are copied to the shared memory successfully, passing details with SecManager");
188 param[
"accessTokenBufferKey"] = shmKey_accToken;
189 param[
"accessTokenLength"] = accTokenLen;
191 param[
"contentMetadataBufferKey"] = shmKey_contMeta;
192 param[
"contentMetadataLength"] = contMetaLen;
194 param[
"licenseRequestBufferKey"] = shmKey_licReq;
195 param[
"licenseRequestLength"] = licReqLen;
200 if(sleepTime<=0) sleepTime = 100;
207 #ifdef DEBUG_SECMAMANER
209 response.ToString(output);
210 AAMPLOG_WARN(
"SecManager openPlaybackSession o/p: %s",output.c_str());
212 if (response[
"success"].Boolean())
214 std::string license = response[
"license"].String();
215 AAMPLOG_TRACE(
"SecManager obtained license with length: %d and data: %s",license.size(), license.c_str());
216 if (!license.empty())
219 unsigned char * licenseDecoded = NULL;
220 size_t licenseDecodedLen = 0;
221 licenseDecoded =
base64_Decode(license.c_str(), &licenseDecodedLen);
222 AAMPLOG_TRACE(
"SecManager license decoded len: %d and data: %p", licenseDecodedLen, licenseDecoded);
224 if (licenseDecoded != NULL && licenseDecodedLen != 0)
226 AAMPLOG_INFO(
"SecManager license post base64 decode length: %d", *licenseResponseLength);
227 *licenseResponse = (
char*) malloc(licenseDecodedLen);
228 if (*licenseResponse)
230 memcpy(*licenseResponse, licenseDecoded, licenseDecodedLen);
231 *licenseResponseLength = licenseDecodedLen;
235 AAMPLOG_ERR(
"SecManager failed to allocate memory for license!");
237 free(licenseDecoded);
242 AAMPLOG_ERR(
"SecManager license base64 decode failed!");
247 if (*sessionId == -1)
249 *sessionId = response[
"sessionId"].Number();
254 if(response.HasLabel(
"secManagerResultContext"))
256 JsonObject resultContext = response[
"secManagerResultContext"].Object();
258 if(resultContext.HasLabel(
"class"))
259 *statusCode = resultContext[
"class"].Number();
260 if(resultContext.HasLabel(
"reason"))
261 *reasonCode = resultContext[
"reason"].Number();
262 if(resultContext.HasLabel(
"businessStatus"))
263 *businessStatus = resultContext[
"businessStatus"].Number();
276 (*reasonCode == SECMANGER_SERVICE_TIMEOUT ||
277 *reasonCode == SECMANGER_SERVICE_CON_FAILURE ||
278 *reasonCode == SECMANGER_SERVICE_BUSY ) && retryCount < MAX_LICENSE_REQUEST_ATTEMPTS)
281 AAMPLOG_WARN(
"SecManager license request failed, response for %s : statusCode: %d, reasonCode: %d, so retrying with delay %d, retry count : %u", apiName, *statusCode, *reasonCode, sleepTime, retryCount );
286 AAMPLOG_ERR(
"SecManager license request failed, response for %s : statusCode: %d, reasonCode: %d", apiName, *statusCode, *reasonCode);
292 AAMPLOG_INFO(
"SecManager license request success, response for %s : statusCode: %d, reasonCode: %d", apiName, *statusCode, *reasonCode);
296 while(retryCount < MAX_LICENSE_REQUEST_ATTEMPTS);
299 aamp_CleanUpSharedMem( shmPt_accToken, shmKey_accToken, accTokenLen);
300 aamp_CleanUpSharedMem( shmPt_contMeta, shmKey_contMeta, contMetaLen);
301 aamp_CleanUpSharedMem( shmPt_licReq, shmKey_licReq, licReqLen);
305 AAMPLOG_ERR(
"SecManager Failed to copy access token to the shared memory, open playback session is aborted statusCode: %d, reasonCode: %d", *statusCode, *reasonCode);
316 bool rpcResult =
false;
319 param[
"clientId"] =
"aamp";
320 param[
"sessionId"] = sessionId;
321 AAMPLOG_INFO(
"%s:%d SecManager call setPlaybackSessionState for ID: %" PRId64
" and state: %d", __FUNCTION__, __LINE__, sessionId, active);
324 param[
"sessionState"] =
"active";
328 param[
"sessionState"] =
"inactive";
332 std::lock_guard<std::mutex> lock(
mSecMutex);
338 if (!result[
"success"].Boolean())
340 std::string responseStr;
341 result.ToString(responseStr);
342 AAMPLOG_ERR(
"%s:%d SecManager setPlaybackSessionState failed for ID: %" PRId64
", active:%d and result: %s", __FUNCTION__, __LINE__, sessionId, active, responseStr.c_str());
347 AAMPLOG_ERR(
"%s:%d SecManager setPlaybackSessionState failed for ID: %" PRId64
" and active: %d", __FUNCTION__, __LINE__, sessionId, active);
356 bool rpcResult =
false;
359 param[
"clientId"] =
"aamp";
360 param[
"sessionId"] = sessionId;
361 AAMPLOG_INFO(
"%s:%d SecManager call closePlaybackSession for ID: %" PRId64
"", __FUNCTION__, __LINE__, sessionId);
364 std::lock_guard<std::mutex> lock(
mSecMutex);
370 if (!result[
"success"].Boolean())
372 std::string responseStr;
373 result.ToString(responseStr);
374 AAMPLOG_ERR(
"%s:%d SecManager closePlaybackSession failed for ID: %" PRId64
" and result: %s", __FUNCTION__, __LINE__, sessionId, responseStr.c_str());
379 AAMPLOG_ERR(
"%s:%d SecManager closePlaybackSession failed for ID: %" PRId64
"", __FUNCTION__, __LINE__, sessionId);
390 bool rpcResult =
false;
394 param[
"sessionId"] = sessionId;
395 param[
"videoWidth"] = video_width;
396 param[
"videoHeight"] = video_height;
398 AAMPLOG_INFO(
"%s:%d SecManager call setVideoWindowSize for ID: %" PRId64
"", __FUNCTION__, __LINE__, sessionId);
400 std::lock_guard<std::mutex> lock(
mSecMutex);
406 if (!result[
"success"].Boolean())
408 std::string responseStr;
409 result.ToString(responseStr);
410 AAMPLOG_ERR(
"%s:%d SecManager setVideoWindowSize failed for ID: %" PRId64
" and result: %s", __FUNCTION__, __LINE__, sessionId, responseStr.c_str());
417 AAMPLOG_ERR(
"%s:%d SecManager setVideoWindowSize failed for ID: %" PRId64
"", __FUNCTION__, __LINE__, sessionId);
427 bool rpcResult =
false;
434 mssleep(SECMANGER_SPEED_SET_DELAY);
437 param[
"sessionId"] = sessionId;
438 param[
"playbackSpeed"] = playback_speed;
439 param[
"playbackPosition"] = playback_position;
441 AAMPLOG_INFO(
"%s:%d SecManager call setPlaybackSpeedState for ID: %" PRId64
"", __FUNCTION__, __LINE__, sessionId);
444 std::lock_guard<std::mutex> lock(
mSecMutex);
450 if (!result[
"success"].Boolean())
452 std::string responseStr;
453 result.ToString(responseStr);
454 AAMPLOG_ERR(
"%s:%d SecManager setPlaybackSpeedState failed for ID: %" PRId64
" and result: %s", __FUNCTION__, __LINE__, sessionId, responseStr.c_str());
460 AAMPLOG_ERR(
"%s:%d SecManager setPlaybackSpeedState failed for ID: %" PRId64
"", __FUNCTION__, __LINE__, sessionId);
470 const char* clutPaletteFormat, int64_t watermarkWidth, int64_t watermarkHeight,
float aspectRatio)
472 bool rpcResult =
false;
476 param[
"sessionId"] = sessionId;
477 param[
"graphicId"] = graphicId;
478 param[
"watermarkClutBufferKey"] = watermarkClutBufferKey;
479 param[
"watermarkImageBufferKey"] = watermarkImageBufferKey;
480 param[
"clutPaletteSize"] = clutPaletteSize;
481 param[
"clutPaletteFormat"] = clutPaletteFormat;
482 param[
"watermarkWidth"] = watermarkWidth;
483 param[
"watermarkHeight"] = watermarkHeight;
484 param[
"aspectRatio"] = std::to_string(aspectRatio).c_str();
486 AAMPLOG_INFO(
"%s:%d SecManager call loadClutWatermark for ID: %" PRId64
"", __FUNCTION__, __LINE__, sessionId);
489 std::lock_guard<std::mutex> lock(
mSecMutex);
495 if (!result[
"success"].Boolean())
497 std::string responseStr;
498 result.ToString(responseStr);
499 AAMPLOG_ERR(
"%s:%d SecManager loadClutWatermark failed for ID: %" PRId64
" and result: %s", __FUNCTION__, __LINE__, sessionId, responseStr.c_str());
505 AAMPLOG_ERR(
"%s:%d SecManager loadClutWatermark failed for ID: %" PRId64
"", __FUNCTION__, __LINE__, sessionId);
520 mRegisteredEvents.push_back(eventName);
556 for (
auto const& evtName : mRegisteredEvents) {
559 mRegisteredEvents.clear();
568 parameters.ToString(param);
569 AAMPLOG_WARN(
"AampSecManager::%s:%d i/p params: %s", __FUNCTION__, __LINE__, param.c_str());
581 #ifdef DEBUG_SECMAMANER
583 parameters.ToString(param);
585 AAMPLOG_WARN(
"AampSecManager::%s:%d i/p params: %s", __FUNCTION__, __LINE__, param.c_str());
587 if(mSchedulerStarted)
589 int graphicId = parameters[
"graphicId"].Number();
590 int zIndex = parameters[
"zIndex"].Number();
591 AAMPLOG_WARN(
"AampSecManager::%s:%d graphicId : %d index : %d ", __FUNCTION__, __LINE__, graphicId, zIndex);
598 int smKey = parameters[
"graphicImageBufferKey"].Number();
599 int smSize = parameters[
"graphicImageSize"].Number();
600 AAMPLOG_WARN(
"AampSecManager::%s:%d graphicId : %d smKey: %d smSize: %d", __FUNCTION__, __LINE__, graphicId, smKey, smSize);
607 if (parameters[
"adjustVisibilityRequired"].Boolean())
609 int sessionId = parameters[
"sessionId"].Number();
610 AAMPLOG_WARN(
"AampSecManager::%s:%d adjustVisibilityRequired is true, invoking GetWaterMarkPalette. graphicId : %d", __FUNCTION__, __LINE__, graphicId);
619 AAMPLOG_WARN(
"AampSecManager::%s:%d adjustVisibilityRequired is false, graphicId : %d", __FUNCTION__, __LINE__, graphicId);
638 if(mSchedulerStarted)
640 int graphicId = parameters[
"graphicId"].Number();
641 int clutKey = parameters[
"watermarkClutBufferKey"].Number();
642 int imageKey = parameters[
"watermarkImageBufferKey"].Number();
657 #ifdef DEBUG_SECMAMANER
659 parameters.ToString(param);
660 AAMPLOG_WARN(
"AampSecManager::%s:%d i/p params: %s", __FUNCTION__, __LINE__, param.c_str());
662 if(mSchedulerStarted)
664 int graphicId = parameters[
"graphicId"].Number();
665 AAMPLOG_WARN(
"AampSecManager::%s:%d graphicId : %d ", __FUNCTION__, __LINE__, graphicId);
689 if(parameters[
"hideWatermark"].Boolean())
693 AAMPLOG_INFO(
"Received onDisplayWatermark, show: %d ", show);
694 if(mSchedulerStarted)
714 bool rpcResult =
false;
716 AAMPLOG_ERR(
"AampSecManager %s:%d ", __FUNCTION__, __LINE__);
717 param[
"show"] = show;
719 std::lock_guard<std::mutex> lock(
mWatMutex);
724 if (!result[
"success"].Boolean())
726 std::string responseStr;
727 result.ToString(responseStr);
728 AAMPLOG_ERR(
"AampSecManager::%s failed and result: %s", __FUNCTION__, responseStr.c_str());
733 AAMPLOG_ERR(
"AampSecManager::%s thunder invocation failed!", __FUNCTION__);
746 bool rpcResult =
false;
748 AAMPLOG_ERR(
"AampSecManager %s:%d ", __FUNCTION__, __LINE__);
749 param[
"id"] = graphicId;
750 param[
"zorder"] = zIndex;
752 std::lock_guard<std::mutex> lock(
mWatMutex);
757 if (!result[
"success"].Boolean())
759 std::string responseStr;
760 result.ToString(responseStr);
761 AAMPLOG_ERR(
"AampSecManager::%s failed and result: %s", __FUNCTION__, responseStr.c_str());
766 AAMPLOG_ERR(
"AampSecManager::%s thunder invocation failed!", __FUNCTION__);
778 bool rpcResult =
false;
780 AAMPLOG_ERR(
"AampSecManager %s:%d ", __FUNCTION__, __LINE__);
781 param[
"id"] = graphicId;
783 std::lock_guard<std::mutex> lock(
mWatMutex);
788 if (!result[
"success"].Boolean())
790 std::string responseStr;
791 result.ToString(responseStr);
792 AAMPLOG_ERR(
"AampSecManager::%s failed and result: %s", __FUNCTION__, responseStr.c_str());
797 AAMPLOG_ERR(
"AampSecManager::%s thunder invocation failed!", __FUNCTION__);
810 bool rpcResult =
false;
812 AAMPLOG_ERR(
"AampSecManager %s:%d ", __FUNCTION__, __LINE__);
813 param[
"id"] = graphicId;
814 param[
"key"] = smKey;
815 param[
"size"] = smSize;
817 std::lock_guard<std::mutex> lock(
mWatMutex);
822 if (!result[
"success"].Boolean())
824 std::string responseStr;
825 result.ToString(responseStr);
826 AAMPLOG_ERR(
"AampSecManager::%s failed and result: %s", __FUNCTION__, responseStr.c_str());
831 AAMPLOG_ERR(
"AampSecManager::%s thunder invocation failed!", __FUNCTION__);
845 bool rpcResult =
false;
847 AAMPLOG_ERR(
"AampSecManager %s:%d ", __FUNCTION__, __LINE__);
848 param[
"show"] = show;
850 std::lock_guard<std::mutex> lock(
mWatMutex);
855 if (!result[
"success"].Boolean())
857 std::string responseStr;
858 result.ToString(responseStr);
859 AAMPLOG_ERR(
"AampSecManager::%s failed and result: %s", __FUNCTION__, responseStr.c_str());
864 AAMPLOG_ERR(
"AampSecManager::%s thunder invocation failed!", __FUNCTION__);
875 bool rpcResult =
false;
876 param[
"id"] = graphicId;
877 AAMPLOG_WARN(
"AampSecManager %s:%d Graphic id: %d ", __FUNCTION__, __LINE__, graphicId);
879 std::lock_guard<std::mutex> lock(
mWatMutex);
885 if (!result[
"success"].Boolean())
887 std::string responseStr;
888 result.ToString(responseStr);
889 AAMPLOG_ERR(
"AampSecManager::%s failed and result: %s", __FUNCTION__, responseStr.c_str());
894 AAMPLOG_WARN(
"AampSecManager::%s getWatermarkPalette invoke success for graphicId %d, calling loadClutWatermark", __FUNCTION__, graphicId);
895 int clutKey = result[
"clutKey"].Number();
896 int clutSize = result[
"clutSize"].Number();
897 int imageKey = result[
"imageKey"].Number();
898 int imageWidth = result[
"imageWidth"].Number();
899 int imageHeight = result[
"imageHeight"].Number();
900 float aspectRatio = (imageHeight != 0) ? (
float)imageWidth/(float)imageHeight : 0.0;
902 clutSize,
"RGBA8888", imageWidth, imageHeight,
909 AAMPLOG_ERR(
"AampSecManager::%s thunder invocation failed!", __FUNCTION__);
921 bool rpcResult =
false;
922 param[
"id"] = graphicId;
923 param[
"clutKey"] = clutKey;
924 param[
"imageKey"] = imageKey;
926 std::lock_guard<std::mutex> lock(
mWatMutex);
931 if (!result[
"success"].Boolean())
933 std::string responseStr;
934 result.ToString(responseStr);
935 AAMPLOG_ERR(
"AampSecManager modifyPalettedWatermark failed with result: %s, graphic id: %d", responseStr.c_str(), graphicId);
939 AAMPLOG_TRACE(
"AampSecManager modifyPalettedWatermark invoke success, graphic id: %d", graphicId);
944 AAMPLOG_ERR(
"AampSecManager Thunder invocation for modifyPalettedWatermark failed!, graphic id: %d", graphicId);