RDK Documentation (Open Sourced RDK Components)
AampVerimatrixHelper.cpp
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2020 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 #include <memory>
21 #include <iostream>
22 
23 #include "AampVerimatrixHelper.h"
24 #include "AampDRMutils.h"
25 #include "AampConfig.h"
26 #include "AampConstants.h"
27 
28 #define KEYURL_TAG_START "<KeyUrl><![CDATA["
29 #define KEYURL_TAG_END "]]></KeyUrl>"
30 
31 static AampVerimatrixHelperFactory verimatrix_helper_factory;
32 
33 const std::string AampVerimatrixHelper::VERIMATRIX_OCDM_ID = "com.verimatrix.ott";
34 
35 bool AampVerimatrixHelper::parsePssh(const uint8_t* initData, uint32_t initDataLen)
36 {
37  this->mInitData.assign(initData, initData+initDataLen);
38 
39  if(mDrmInfo.mediaFormat == eMEDIAFORMAT_HLS)
40  {
41  logprintf("mediaFormat is not DASH");
42  return true;
43  }
44 
45  if(initDataLen < VERIMATRIX_PSSH_DATA_POSITION)
46  {
47  logprintf("initDataLen less than %d", VERIMATRIX_PSSH_DATA_POSITION);
48  return false;
49  }
50 
51  initData += VERIMATRIX_PSSH_DATA_POSITION;
52  initDataLen -= VERIMATRIX_PSSH_DATA_POSITION;
53  char *init = new char[initDataLen + 1];
54  memcpy(init, initData, initDataLen);
55  init[initDataLen] = 0;
56 
57  std::string pssh(init);
58  delete []init;
59 
60  logprintf("pssh %s", pssh.c_str());
61 
62  size_t sp = pssh.find(KEYURL_TAG_START);
63  size_t ep = pssh.find(KEYURL_TAG_END);
64  if((sp == std::string::npos) || (ep == std::string::npos))
65  {
66  logprintf("not found KeyUrl TAG");
67  return false;
68  }
69 
70  sp += strlen(KEYURL_TAG_START);
71 
72  std::string keyfile = pssh.substr(sp, ep - sp);
73  logprintf("keyfile %s", keyfile.c_str());
74 
75  mKeyID.assign((uint8_t *)keyfile.c_str(), (uint8_t *)keyfile.c_str() + keyfile.length());
76 
77  return true;
78 }
79 
80 
81 void AampVerimatrixHelper::setDrmMetaData(const std::string& metaData)
82 {
83  mContentMetadata = metaData;
84 }
85 
86 const std::string& AampVerimatrixHelper::ocdmSystemId() const
87 {
88  return VERIMATRIX_OCDM_ID;
89 }
90 
91 void AampVerimatrixHelper::createInitData(std::vector<uint8_t>& initData) const
92 {
93  const char *init;
94 
95  if(mDrmInfo.mediaFormat == eMEDIAFORMAT_HLS)
96  init = "{\"contentType\" : \"HLS\"}";
97  else if(mDrmInfo.mediaFormat == eMEDIAFORMAT_DASH)
98  init = "{\"contentType\" : \"DASH\"}";
99  else
100  logprintf("unknown mediaFormat %d", mDrmInfo.mediaFormat);
101 
102  initData.assign((uint8_t *)init, (uint8_t *)init + strlen(init));
103 }
104 
105 void AampVerimatrixHelper::getKey(std::vector<uint8_t>& keyID) const
106 {
107  keyID.clear();
108  if(mDrmInfo.mediaFormat == eMEDIAFORMAT_HLS)
109  keyID.insert(keyID.begin(), mDrmInfo.keyURI.begin(), mDrmInfo.keyURI.end());
110  else if(mDrmInfo.mediaFormat == eMEDIAFORMAT_DASH)
111  keyID.insert(keyID.begin(), mKeyID.begin(), mKeyID.end());
112  else
113  logprintf("unknown mediaFormat %d", mDrmInfo.mediaFormat);
114 }
115 
117 {
118  licenseRequest.method = AampLicenseRequest::DRM_RETRIEVE;
119  licenseRequest.url = "";
120  licenseRequest.payload = "";
121 }
122 
123 void AampVerimatrixHelper::transformLicenseResponse(std::shared_ptr<DrmData> licenseResponse) const
124 {
125  if(mDrmInfo.mediaFormat == eMEDIAFORMAT_HLS)
126  licenseResponse->setData((unsigned char*)mDrmInfo.keyURI.c_str(), mDrmInfo.keyURI.length());
127  else if(mDrmInfo.mediaFormat == eMEDIAFORMAT_DASH)
128  licenseResponse->setData((unsigned char*)mKeyID.data(), mKeyID.size());
129  else
130  logprintf("unknown mediaFormat %d", mDrmInfo.mediaFormat);
131 }
132 
133 bool AampVerimatrixHelperFactory::isDRM(const struct DrmInfo& drmInfo) const
134 {
135  return (((VERIMATRIX_UUID == drmInfo.systemUUID) || (AampVerimatrixHelper::VERIMATRIX_OCDM_ID == drmInfo.keyFormat))
136  && ((drmInfo.mediaFormat == eMEDIAFORMAT_DASH) || (drmInfo.mediaFormat == eMEDIAFORMAT_HLS))
137  );
138 }
139 
140 std::shared_ptr<AampDrmHelper> AampVerimatrixHelperFactory::createHelper(const struct DrmInfo& drmInfo, AampLogManager *logObj) const
141 {
142  if (isDRM(drmInfo))
143  {
144  return std::make_shared<AampVerimatrixHelper>(drmInfo, logObj);
145  }
146  return NULL;
147 }
148 
149 void AampVerimatrixHelperFactory::appendSystemId(std::vector<std::string>& systemIds) const
150 {
151  systemIds.push_back(VERIMATRIX_UUID);
152 }
AampVerimatrixHelperFactory
Definition: AampVerimatrixHelper.h:73
AampVerimatrixHelper::parsePssh
bool parsePssh(const uint8_t *initData, uint32_t initDataLen)
Parse the optional PSSH data.
Definition: AampVerimatrixHelper.cpp:35
AampVerimatrixHelperFactory::isDRM
bool isDRM(const struct DrmInfo &drmInfo) const
Determines if a helper class provides the identified DRM.
Definition: AampVerimatrixHelper.cpp:133
DrmInfo::keyURI
std::string keyURI
Definition: AampDrmInfo.h:87
AampVerimatrixHelperFactory::appendSystemId
void appendSystemId(std::vector< std::string > &systemIds) const
Adds the system IDs supported by the DRM to a vector Used by the GStreamer plugins to advertise the D...
Definition: AampVerimatrixHelper.cpp:149
logprintf
void logprintf(const char *format,...)
Print logs to console / log fil.
Definition: aamplogging.cpp:432
AampVerimatrixHelper::transformLicenseResponse
void transformLicenseResponse(std::shared_ptr< DrmData > licenseResponse) const
Transform the license response from the server into the necessary format for OCDM.
Definition: AampVerimatrixHelper.cpp:123
eMEDIAFORMAT_DASH
@ eMEDIAFORMAT_DASH
Definition: AampDrmMediaFormat.h:35
AampVerimatrixHelperFactory::createHelper
std::shared_ptr< AampDrmHelper > createHelper(const struct DrmInfo &drmInfo, AampLogManager *logObj=NULL) const
Build a helper class to support the identified DRM.
Definition: AampVerimatrixHelper.cpp:140
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
AampVerimatrixHelper::ocdmSystemId
virtual const std::string & ocdmSystemId() const
Returns the OCDM system ID of the helper.
Definition: AampVerimatrixHelper.cpp:86
AampLicenseRequest::DRM_RETRIEVE
@ DRM_RETRIEVE
Definition: AampDrmHelper.h:63
AampVerimatrixHelper::createInitData
void createInitData(std::vector< uint8_t > &initData) const
Definition: AampVerimatrixHelper.cpp:91
AampLicenseRequest
Holds the data to get the License.
Definition: AampDrmHelper.h:57
DrmInfo::systemUUID
std::string systemUUID
Definition: AampDrmInfo.h:89
DrmInfo
DRM information required to decrypt.
Definition: AampDrmInfo.h:47
DrmInfo::keyFormat
std::string keyFormat
Definition: AampDrmInfo.h:88
AampVerimatrixHelper::generateLicenseRequest
void generateLicenseRequest(const AampChallengeInfo &challengeInfo, AampLicenseRequest &licenseRequest) const
Generate the request details for the DRM license.
Definition: AampVerimatrixHelper.cpp:116
AampDRMutils.h
Context-free common utility functions.
AampConfig.h
Configurations for AAMP.
AampVerimatrixHelper::setDrmMetaData
void setDrmMetaData(const std::string &metaData)
Sets the content specific DRM metadata.
Definition: AampVerimatrixHelper.cpp:81
eMEDIAFORMAT_HLS
@ eMEDIAFORMAT_HLS
Definition: AampDrmMediaFormat.h:34
AampConstants.h
Constants in AAMP.
AampChallengeInfo
Aamp challenge info to get the License.
Definition: AampDrmHelper.h:44
DrmInfo::mediaFormat
MediaFormat mediaFormat
Definition: AampDrmInfo.h:80
AampVerimatrixHelper::getKey
void getKey(std::vector< uint8_t > &keyID) const
Get the key ID.
Definition: AampVerimatrixHelper.cpp:105