drm/ave/drm.cpp
/**
 * @brief Set DRM meta-data. Creates AveDrm instance if meta-data is not already configured.
 *
 * @param[in] aamp          AAMP instance associated with the operation.
 * @param[in] metaDataNode  DRM meta data node containing meta-data to be set.
 */
@brief Set DRM meta-data. Creates AveDrm instance if meta-data is not already configured.
@param[in] aamp          AAMP instance associated with the operation.
@param[in] metaDataNode  DRM meta data node containing meta-data to be set.
@brief Set DRM meta - data . Creates AveDrm instance if meta - data is not already configured . @param [ in ] aamp AAMP instance associated with the operation . @param [ in ] metaDataNode DRM meta data node containing meta - data to be set .
void AveDrmManager::SetMetadata(PrivateInstanceAAMP *aamp, DrmMetadataNode *metaDataNode,int trackType)
{
	AveDrmManager* aveDrmManager = NULL;
	bool drmMetaDataSet = false;
	AVE_DRM_MANGER_DEBUG ("%s:%d: Enter sAveDrmManager.size = %d\n", __FUNCTION__, __LINE__, (int)sAveDrmManager.size());
	pthread_mutex_lock(&aveDrmManagerMutex);
	for (int i = 0; i < sAveDrmManager.size(); i++)
	{
		if (sAveDrmManager[i]->mDrmContexSet)
		{
			if (0 == memcmp(metaDataNode->sha1Hash, sAveDrmManager[i]->mSha1Hash, DRM_SHA1_HASH_LEN))
			{
				drmMetaDataSet = true;
				if(sAveDrmManager[i]->mTrackType & (1<<trackType))
				{
					AVE_DRM_MANGER_DEBUG("[%s][%d] Meta hash[%s] already set for tracktype[%x]UserCount[%d]\n",__FUNCTION__, __LINE__,metaDataNode->sha1Hash,sAveDrmManager[i]->mTrackType,sAveDrmManager[i]->mUserCount);
				}
				else
                             	{
					sAveDrmManager[i]->mTrackType |= (1<<trackType);
					sAveDrmManager[i]->mUserCount++;
				}
				AVE_DRM_MANGER_DEBUG("%s:%d: Found matching sha1Hash[%s]. Index[%d] UserCount[%d][%x]\n", __FUNCTION__, __LINE__,metaDataNode->sha1Hash, i,sAveDrmManager[i]->mUserCount,sAveDrmManager[i]->mTrackType);
				break;
			}
			else
			{
#ifdef ENABLE_AVE_DRM_MANGER_DEBUG
				printf("%s:%d sHlsDrmContext[%d].mSha1Hash -  ", __FUNCTION__, __LINE__, i);
				PrintSha1Hash(sAveDrmManager[i]->mSha1Hash);
				printf("metaDataNode->sha1Hash - ");
				PrintSha1Hash(metaDataNode->sha1Hash);
#endif
			}
		}
		else if (!aveDrmManager)
		{
			aveDrmManager = sAveDrmManager[i];
		}
	}
	if (!drmMetaDataSet)
	{
		if (!aveDrmManager)
		{
			aveDrmManager = new AveDrmManager();
			sAveDrmManager.push_back(aveDrmManager);
			logprintf("%s:%d: Created new AveDrmManager[%s] .Track[%d].Total Sz=%d\n", __FUNCTION__, __LINE__,metaDataNode->sha1Hash,trackType,sAveDrmManager.size());
		}
		if (aveDrmManager)
		{
			aveDrmManager->mDrm->SetMetaData(aamp, &metaDataNode->metaData);
			aveDrmManager->mDrmContexSet = true;
			aveDrmManager->mUserCount++;
			aveDrmManager->mTrackType |= (1<<trackType);
			memcpy(aveDrmManager->mSha1Hash, metaDataNode->sha1Hash, DRM_SHA1_HASH_LEN);
		}
	}
	pthread_mutex_unlock(&aveDrmManagerMutex);
	AVE_DRM_MANGER_DEBUG ("%s:%d: Exit sAveDrmManager.size = %d\n", __FUNCTION__, __LINE__, sAveDrmManager.size());
}
void AveDrmManager :: SetMetadata ( PrivateInstanceAAMP * aamp , DrmMetadataNode * metaDataNode , int trackType ) { AveDrmManager * aveDrmManager = NULL ; bool drmMetaDataSet = false ; AVE_DRM_MANGER_DEBUG ( " \n " , __FUNCTION__ , __LINE__ , ( int ) sAveDrmManager . size ( ) ) ; pthread_mutex_lock ( & aveDrmManagerMutex ) ; for ( int i = 0 ; i < sAveDrmManager . size ( ) ; i ++ ) { if ( sAveDrmManager [ i ] -> mDrmContexSet ) { if ( 0 == memcmp ( metaDataNode -> sha1Hash , sAveDrmManager [ i ] -> mSha1Hash , DRM_SHA1_HASH_LEN ) ) { drmMetaDataSet = true ; if ( sAveDrmManager [ i ] -> mTrackType & ( 1 << trackType ) ) { AVE_DRM_MANGER_DEBUG ( " \n " , __FUNCTION__ , __LINE__ , metaDataNode -> sha1Hash , sAveDrmManager [ i ] -> mTrackType , sAveDrmManager [ i ] -> mUserCount ) ; } else { sAveDrmManager [ i ] -> mTrackType |= ( 1 << trackType ) ; sAveDrmManager [ i ] -> mUserCount ++ ; } AVE_DRM_MANGER_DEBUG ( " \n " , __FUNCTION__ , __LINE__ , metaDataNode -> sha1Hash , i , sAveDrmManager [ i ] -> mUserCount , sAveDrmManager [ i ] -> mTrackType ) ; break ; } else { #ifdef ENABLE_AVE_DRM_MANGER_DEBUG printf ( " " , __FUNCTION__ , __LINE__ , i ) ; PrintSha1Hash ( sAveDrmManager [ i ] -> mSha1Hash ) ; printf ( " " ) ; PrintSha1Hash ( metaDataNode -> sha1Hash ) ; #endif } } else if ( ! aveDrmManager ) { aveDrmManager = sAveDrmManager [ i ] ; } } if ( ! drmMetaDataSet ) { if ( ! aveDrmManager ) { aveDrmManager = new AveDrmManager ( ) ; sAveDrmManager . push_back ( aveDrmManager ) ; logprintf ( " \n " , __FUNCTION__ , __LINE__ , metaDataNode -> sha1Hash , trackType , sAveDrmManager . size ( ) ) ; } if ( aveDrmManager ) { aveDrmManager -> mDrm -> SetMetaData ( aamp , & metaDataNode -> metaData ) ; aveDrmManager -> mDrmContexSet = true ; aveDrmManager -> mUserCount ++ ; aveDrmManager -> mTrackType |= ( 1 << trackType ) ; memcpy ( aveDrmManager -> mSha1Hash , metaDataNode -> sha1Hash , DRM_SHA1_HASH_LEN ) ; } } pthread_mutex_unlock ( & aveDrmManagerMutex ) ; AVE_DRM_MANGER_DEBUG ( " \n " , __FUNCTION__ , __LINE__ , sAveDrmManager . size ( ) ) ; }
@brief Set DRM meta-data.
@brief Set DRM meta - data .