52 static int GetFieldValue(
string &attrName,
string keyName,
string &valuePtr);
53 static int getKeyId(
string attrName,
string &keyId);
54 static int getPsshData(
string attrName,
string &psshData);
55 static shared_ptr<AampDrmHelper> getDrmHelper(
string attrName ,
bool bPropagateUriParams);
56 static uint8_t getPsshDataVersion(
string attrName);
65 static int GetFieldValue(
string &attrName,
string keyName,
string &valuePtr){
67 int valueStartPos = 0;
68 int valueEndPos = attrName.length();
69 int keylen = keyName.length();
70 int status = DRM_API_FAILED;
71 int found = 0, foundpos = 0;
75 while ( (foundpos = attrName.find(keyName,found)) != std::string::npos)
80 valueStartPos = foundpos + keylen;
81 if (attrName.at(valueStartPos) ==
'=')
83 string valueTempPtr = attrName.substr(valueStartPos+1);
86 valueTempPtr.c_str());
90 if (valueTempPtr.at(0) ==
'"')
92 valueTempPtr = valueTempPtr.substr(1);
93 valueEndPos = valueTempPtr.find(
'"');
95 else if ( (valueEndPos = valueTempPtr.find(
',')) == std::string::npos)
98 valueEndPos = valueTempPtr.length();
101 valuePtr = valueTempPtr.substr(valueStartPos, valueEndPos);
102 AAMPLOG_INFO(
"Value found : %s for Key : %s",
103 valuePtr.c_str(), keyName.c_str());
110 keyName.c_str(), attrName.c_str());
111 found = valueStartPos+1;
117 AAMPLOG_ERR(
"Could not able to find %s in %s",
118 keyName.c_str(), attrName.c_str());
143 static int getKeyId(
string attrName,
string &keyId){
145 int status = GetFieldValue(attrName,
"KEYID", keyId );
147 AAMPLOG_INFO(
"Could not able to get Key Id from manifest"
153 keyId = keyId.substr(2);
164 static int getPsshData(
string attrName,
string &psshData){
166 int status = GetFieldValue(attrName,
"URI", psshData );
168 AAMPLOG_ERR(
"Could not able to get psshData from manifest"
173 psshData = psshData.substr(psshData.find(
',')+1);
184 static uint8_t getPsshDataVersion(
string attrName){
186 uint8_t psshDataVer = 0;
187 string psshDataVerStr =
"";
189 if(
DRM_API_SUCCESS != GetFieldValue(attrName,
"KEYFORMATVERSIONS", psshDataVerStr )){
190 AAMPLOG_WARN(
"Could not able to receive pssh data version from manifest"
191 "returning default value as 0"
194 psshDataVer = (uint8_t)std::atoi(psshDataVerStr.c_str());
206 static std::shared_ptr<AampDrmHelper> getDrmHelper(
string attrName ,
bool bPropagateUriParams){
208 string systemId =
"";
210 if(
DRM_API_SUCCESS != GetFieldValue(attrName,
"KEYFORMAT", systemId )){
211 AAMPLOG_ERR(
"Could not able to receive key id from manifest"
217 if (systemId.find(
"urn:uuid:") != std::string::npos){
218 systemId = systemId.substr(strlen(
"urn:uuid:"));
247 shared_ptr<AampDrmHelper> drmHelper;
248 unsigned char* data = NULL;
249 unsigned char* contentMetadata = NULL;
250 size_t dataLength = 0;
251 int status = DRM_API_FAILED;
252 string psshDataStr =
"";
253 char* psshData = NULL;
254 unsigned char * keyId = NULL;
260 if (
nullptr == drmHelper){
261 AAMPLOG_ERR(
"Failed to get DRM type/helper from manifest!");
265 status = getPsshData(attrName, psshDataStr);
267 AAMPLOG_ERR(
"Failed to get PSSH Data from manifest!");
270 psshData = (
char*) malloc(psshDataStr.length() + 1);
271 memset(psshData, 0x00 , psshDataStr.length() + 1);
272 strncpy(psshData, psshDataStr.c_str(), psshDataStr.length());
274 if(drmHelper->friendlyName().compare(
"Verimatrix") == 0)
276 logprintf(
"%s:%d Verimatrix DRM.", __FUNCTION__, __LINE__);
277 data = (
unsigned char *)psshData;
278 dataLength = psshDataStr.length();
290 AAMPLOG_ERR(
"Could not able to retrive DRM data from PSSH");
297 printf(
"*****************************************************************\n");
298 for (
int i = 0; i < dataLength; i++)
300 printf(
"%c", data[i]);
302 printf(
"\n*****************************************************************\n");
303 for (
int i = 0; i < dataLength; i++)
305 printf(
"%02x ", data[i]);
307 printf(
"\n*****************************************************************\n");
310 if (!drmHelper->parsePssh(data, dataLength))
312 AAMPLOG_ERR(
"Failed to get key Id from manifest");
325 sessionParams->initData = data;
326 sessionParams->initDataLen = dataLength;
327 sessionParams->stream_type = mediaType;
328 sessionParams->aamp = aamp;
329 sessionParams->drmHelper = drmHelper;
336 drmSessioData->
processedKeyId = (
unsigned char *) malloc(keyIdLen + 1);
350 return drmSessioData;
356 AAMPLOG_INFO(
"AAMP_HLS_DRM not enabled"