RDK Documentation (Open Sourced RDK Components)
AampWidevineDrmHelper.h
Go to the documentation of this file.
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 #ifndef _AAMP_WIDEVINE_DRM_HELPER_H
20 #define _AAMP_WIDEVINE_DRM_HELPER_H
21 
22 /**
23  * @file AampWidevineDrmHelper.h
24  * @brief Handles the operation for Wide vine DRM operation
25  */
26 
27 #include <memory>
28 
29 #include "AampDrmHelper.h"
30 
31 #define KEYID_MARKER 0x12
32 #define CONTENTID_MARKER 0x22
33 #define DATA_LENGTH_FIELD_SIZE 2
34 
35 /**
36  * @class AampWidevineDrmHelper
37  * @brief Handles the operation for Wide vine DRM operation
38  */
39 
41 {
42 public:
43  friend class AampWidevineDrmHelperFactory;
44 
45  virtual const std::string& ocdmSystemId() const;
46 
47  void createInitData(std::vector<uint8_t>& initData) const;
48 
49  bool parsePssh(const uint8_t* initData, uint32_t initDataLen);
50 
51  bool isClearDecrypt() const { return false; }
52 
53  bool isExternalLicense() const { return false; };
54 
55  void getKey(std::vector<uint8_t>& keyID) const;
56 
57  void getKeys(std::map<int, std::vector<uint8_t>>& keyIDs) const;
58 
59  const std::string& getDrmMetaData() const {return mContentMetadata;}
60 
61  void setDrmMetaData(const std::string& metaData);
62 
63  void setDefaultKeyID(const std::string& cencData);
64 
65  virtual int getDrmCodecType() const { return CODEC_TYPE; }
66 
67  void generateLicenseRequest(const AampChallengeInfo& challengeInfo, AampLicenseRequest& licenseRequest) const;
68 
69  virtual const std::string& friendlyName() const override { return FRIENDLY_NAME; };
70 
71  AampWidevineDrmHelper(const struct DrmInfo& drmInfo, AampLogManager *logObj) : AampDrmHelper(drmInfo, logObj), FRIENDLY_NAME("Widevine"),
72  CODEC_TYPE(1), WIDEVINE_KEY_ID_SIZE_INDICATOR(0x12), WIDEVINE_DASH_KEY_ID_OFFSET(32u),
73  WIDEVINE_CONTENT_METADATA_OFFSET(28u), mInitData(), mKeyID(), mKeyIDs(), mContentMetadata()
74  ,WIDEVINE_PSSH_DATA_VERSION_POSITION(8u), WIDEVINE_PSSH_KEYID_SIZE_OFFSET(32u),
75  WIDEVINE_PSSH_KEYID_SIZE_OFFSET_WITH_AUTHOR(34u), WIDEVINE_PSSH_VER1_KEY_ID_SIZE(16u)
76  ,mDefaultKeySlot(-1)
77  {}
78 
80 
81 private:
82  static const std::string WIDEVINE_OCDM_ID;
83  const std::string FRIENDLY_NAME;
84  const int CODEC_TYPE;
85  const uint8_t WIDEVINE_KEY_ID_SIZE_INDICATOR;
86  const size_t WIDEVINE_DASH_KEY_ID_OFFSET; // Offset in the PSSH to find the key ID for DASH
87  const uint8_t WIDEVINE_CONTENT_METADATA_OFFSET; // Offset of content metadata in Widevine PSSH data
88  const uint8_t WIDEVINE_PSSH_DATA_VERSION_POSITION; // Offset of pssh data version in Widevine PSSH data
89  const uint8_t WIDEVINE_PSSH_KEYID_SIZE_OFFSET; // Offset of content metadata in Widevine PSSH data without auther id
90  const uint8_t WIDEVINE_PSSH_KEYID_SIZE_OFFSET_WITH_AUTHOR; // Offset of content metadata in Widevine PSSH data with auther id
91  const uint8_t WIDEVINE_PSSH_VER1_KEY_ID_SIZE; // Const key id length for pSSH data version 1
92 
93  std::vector<uint8_t> mInitData;
94  std::vector<uint8_t> mKeyID;
95  std::map<int,std::vector<uint8_t>> mKeyIDs;
96  std::string mContentMetadata;
97  int mDefaultKeySlot;
98 };
99 
100 /**
101  * @class AampWidevineDrmHelperFactory
102  * @brief Helps to handle widevine DRM
103  */
105 {
106  std::shared_ptr<AampDrmHelper> createHelper(const struct DrmInfo& drmInfo, AampLogManager *logObj=NULL) const;
107 
108  void appendSystemId(std::vector<std::string>& systemIds) const;
109 
110  bool isDRM(const struct DrmInfo& drmInfo) const;
111 };
112 
113 
114 #endif //_AAMP_WIDEVINE_DRM_HELPER_H
AampDrmHelper.h
Implented DRM helper functionalities.
AampWidevineDrmHelper::isExternalLicense
bool isExternalLicense() const
Determines if the DRM itself fetches the license or if AAMP should use its own internal HTTP client t...
Definition: AampWidevineDrmHelper.h:53
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
AampWidevineDrmHelper::setDefaultKeyID
void setDefaultKeyID(const std::string &cencData)
Sets the defualt keyID.
Definition: AampWidevineDrmHelper.cpp:178
AampWidevineDrmHelper::friendlyName
virtual const std::string & friendlyName() const override
Gets the friendly display name of the DRM.
Definition: AampWidevineDrmHelper.h:69
AampWidevineDrmHelperFactory::createHelper
std::shared_ptr< AampDrmHelper > createHelper(const struct DrmInfo &drmInfo, AampLogManager *logObj=NULL) const
Build a helper class to support the identified DRM.
Definition: AampWidevineDrmHelper.cpp:248
AampLicenseRequest
Holds the data to get the License.
Definition: AampDrmHelper.h:57
AampWidevineDrmHelperFactory
Helps to handle widevine DRM.
Definition: AampWidevineDrmHelper.h:104
AampWidevineDrmHelper
Handles the operation for Wide vine DRM operation.
Definition: AampWidevineDrmHelper.h:40
DrmInfo
DRM information required to decrypt.
Definition: AampDrmInfo.h:47
AampWidevineDrmHelper::getKey
void getKey(std::vector< uint8_t > &keyID) const
Get the key ID.
Definition: AampWidevineDrmHelper.cpp:205
AampWidevineDrmHelper::ocdmSystemId
virtual const std::string & ocdmSystemId() const
Returns the OCDM system ID of the helper.
Definition: AampWidevineDrmHelper.cpp:195
AampWidevineDrmHelper::createInitData
void createInitData(std::vector< uint8_t > &initData) const
Definition: AampWidevineDrmHelper.cpp:200
AampWidevineDrmHelperFactory::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: AampWidevineDrmHelper.cpp:257
AampWidevineDrmHelper::getKeys
void getKeys(std::map< int, std::vector< uint8_t >> &keyIDs) const
Get the key IDs.
Definition: AampWidevineDrmHelper.cpp:222
AampWidevineDrmHelper::getDrmMetaData
const std::string & getDrmMetaData() const
Returns the content specific DRM metadata.
Definition: AampWidevineDrmHelper.h:59
AampDrmHelperFactory
Helper class to Maintain DRM data.
Definition: AampDrmHelper.h:250
AampWidevineDrmHelper::parsePssh
bool parsePssh(const uint8_t *initData, uint32_t initDataLen)
Parse the optional PSSH data.
Definition: AampWidevineDrmHelper.cpp:37
AampWidevineDrmHelper::isClearDecrypt
bool isClearDecrypt() const
Determine if the DRM system needs to be in the clear or encrypted.
Definition: AampWidevineDrmHelper.h:51
AampWidevineDrmHelper::generateLicenseRequest
void generateLicenseRequest(const AampChallengeInfo &challengeInfo, AampLicenseRequest &licenseRequest) const
Generate the request details for the DRM license.
Definition: AampWidevineDrmHelper.cpp:227
AampDrmHelper
AampDRM helper to handle DRM operations.
Definition: AampDrmHelper.h:79
AampChallengeInfo
Aamp challenge info to get the License.
Definition: AampDrmHelper.h:44
AampWidevineDrmHelperFactory::isDRM
bool isDRM(const struct DrmInfo &drmInfo) const
Determines if a helper class provides the identified DRM.
Definition: AampWidevineDrmHelper.cpp:241
AampWidevineDrmHelper::setDrmMetaData
void setDrmMetaData(const std::string &metaData)
Sets the content specific DRM metadata.
Definition: AampWidevineDrmHelper.cpp:173
AampWidevineDrmHelper::getDrmCodecType
virtual int getDrmCodecType() const
Returns the DRM codec type for the helper, used in trace.
Definition: AampWidevineDrmHelper.h:65