fragmentcollector_mpd.cpp
/**
 * @brief Create DRM Session
 *
 * @param[in] arg DrmSessionParams object pointer
 */
@brief Create DRM Session
@param[in] arg DrmSessionParams object pointer
@brief Create DRM Session @param [ in ] arg DrmSessionParams object pointer
void *CreateDRMSession(void *arg)
{
	if(aamp_pthread_setname(pthread_self(), "aampDRM"))
	{
		logprintf("%s:%d: aamp_pthread_setname failed\n", __FUNCTION__, __LINE__);
	}
	struct DrmSessionParams* sessionParams = (struct DrmSessionParams*)arg;
	AampDRMSessionManager* sessionManger = new AampDRMSessionManager();
	sessionParams->aamp->profiler.ProfileBegin(PROFILE_BUCKET_LA_TOTAL);
	AAMPEvent e;
	e.type = AAMP_EVENT_DRM_METADATA;
	e.data.dash_drmmetadata.failure = AAMP_TUNE_FAILURE_UNKNOWN;
	e.data.dash_drmmetadata.responseCode = 0;
	unsigned char * data = sessionParams->initData;
	int dataLength = sessionParams->initDataLen;
	unsigned char *contentMetadata = sessionParams->contentMetadata;
	AampDrmSession *drmSession = NULL;
	const char * systemId = WIDEVINE_SYSTEM_ID;
	if (sessionParams->isWidevine)
	{
		logprintf("Found Widevine encryption from manifest\n");
	}
	else
	{
		logprintf("Found Playready encryption from manifest\n");
		systemId = PLAYREADY_SYSTEM_ID;
	}
	sessionParams->aamp->mStreamSink->QueueProtectionEvent(systemId, data, dataLength);
	drmSession = sessionManger->createDrmSession(systemId, data, dataLength, sessionParams->stream_type,
					contentMetadata, sessionParams->aamp, &e);
	if(NULL == drmSession)
	{
		AAMPTuneFailure failure = e.data.dash_drmmetadata.failure;
		bool isRetryEnabled =      (failure != AAMP_TUNE_AUTHORISATION_FAILURE)
		                        && (failure != AAMP_TUNE_LICENCE_REQUEST_FAILED)
								&& (failure != AAMP_TUNE_LICENCE_TIMEOUT)
		                        && (failure != AAMP_TUNE_DEVICE_NOT_PROVISIONED);
		sessionParams->aamp->SendDrmErrorEvent(e.data.dash_drmmetadata.failure, e.data.dash_drmmetadata.responseCode, isRetryEnabled);
		sessionParams->aamp->profiler.SetDrmErrorCode((int)e.data.dash_drmmetadata.failure);
		sessionParams->aamp->profiler.ProfileError(PROFILE_BUCKET_LA_TOTAL, (int)e.data.dash_drmmetadata.failure);
	}
	else
	{
		if(e.data.dash_drmmetadata.accessStatus_value != 3)
		{
			AAMPLOG_INFO("Sending DRMMetaData\n");
			sessionParams->aamp->SendDRMMetaData(e);
		}
		sessionParams->aamp->profiler.ProfileEnd(PROFILE_BUCKET_LA_TOTAL);
	}
	delete sessionManger;
	free(data);
	if(contentMetadata != NULL)
		free(contentMetadata);
	free(sessionParams);
	return NULL;
}
void * CreateDRMSession ( void * arg ) { if ( aamp_pthread_setname ( pthread_self ( ) , " " ) ) { logprintf ( " \n " , __FUNCTION__ , __LINE__ ) ; } struct DrmSessionParams * sessionParams = ( struct DrmSessionParams * ) arg ; AampDRMSessionManager * sessionManger = new AampDRMSessionManager ( ) ; sessionParams -> aamp -> profiler . ProfileBegin ( PROFILE_BUCKET_LA_TOTAL ) ; AAMPEvent e ; e . type = AAMP_EVENT_DRM_METADATA ; e . data . dash_drmmetadata . failure = AAMP_TUNE_FAILURE_UNKNOWN ; e . data . dash_drmmetadata . responseCode = 0 ; unsigned char * data = sessionParams -> initData ; int dataLength = sessionParams -> initDataLen ; unsigned char * contentMetadata = sessionParams -> contentMetadata ; AampDrmSession * drmSession = NULL ; const char * systemId = WIDEVINE_SYSTEM_ID ; if ( sessionParams -> isWidevine ) { logprintf ( " \n " ) ; } else { logprintf ( " \n " ) ; systemId = PLAYREADY_SYSTEM_ID ; } sessionParams -> aamp -> mStreamSink -> QueueProtectionEvent ( systemId , data , dataLength ) ; drmSession = sessionManger -> createDrmSession ( systemId , data , dataLength , sessionParams -> stream_type , contentMetadata , sessionParams -> aamp , & e ) ; if ( NULL == drmSession ) { AAMPTuneFailure failure = e . data . dash_drmmetadata . failure ; bool isRetryEnabled = ( failure != AAMP_TUNE_AUTHORISATION_FAILURE ) && ( failure != AAMP_TUNE_LICENCE_REQUEST_FAILED ) && ( failure != AAMP_TUNE_LICENCE_TIMEOUT ) && ( failure != AAMP_TUNE_DEVICE_NOT_PROVISIONED ) ; sessionParams -> aamp -> SendDrmErrorEvent ( e . data . dash_drmmetadata . failure , e . data . dash_drmmetadata . responseCode , isRetryEnabled ) ; sessionParams -> aamp -> profiler . SetDrmErrorCode ( ( int ) e . data . dash_drmmetadata . failure ) ; sessionParams -> aamp -> profiler . ProfileError ( PROFILE_BUCKET_LA_TOTAL , ( int ) e . data . dash_drmmetadata . failure ) ; } else { if ( e . data . dash_drmmetadata . accessStatus_value != 3 ) { AAMPLOG_INFO ( " \n " ) ; sessionParams -> aamp -> SendDRMMetaData ( e ) ; } sessionParams -> aamp -> profiler . ProfileEnd ( PROFILE_BUCKET_LA_TOTAL ) ; } delete sessionManger ; free ( data ) ; if ( contentMetadata != NULL ) free ( contentMetadata ) ; free ( sessionParams ) ; return NULL ; }
@brief Create DRM Session
 @param[in] arg DrmSessionParams object pointer
@brief Create DRM Session @param [ in ] arg DrmSessionParams object pointer
//Hao Li: review changes for Widevine, contentMetadata is freed inside the following calls