RDK Documentation (Open Sourced RDK Components)
AampDrmSession.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 2018 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 /**
21  * @file AampDrmSession.h
22  * @brief Header file for AampDrmSession
23  */
24 
25 
26 #ifndef AampDrmSession_h
27 #define AampDrmSession_h
28 #include <string>
29 #include <stdint.h>
30 #include <vector>
31 #include <gst/gst.h>
32 
33 #include "AampDRMutils.h"
34 #include "AampConfig.h"
35 
36 using namespace std;
37 
38 #define PLAYREADY_PROTECTION_SYSTEM_ID "9a04f079-9840-4286-ab92-e65be0885f95"
39 #define WIDEVINE_PROTECTION_SYSTEM_ID "edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
40 #define CLEARKEY_PROTECTION_SYSTEM_ID "1077efec-c0b2-4d02-ace3-3c1e52e2fb4b"
41 #define VERIMATRIX_PROTECTION_SYSTEM_ID "9a27dd82-fde2-4725-8cbc-4234aa06ec09"
42 
43 #define PLAYREADY_KEY_SYSTEM_STRING "com.microsoft.playready"
44 #define WIDEVINE_KEY_SYSTEM_STRING "com.widevine.alpha"
45 #define CLEAR_KEY_SYSTEM_STRING "org.w3.clearkey"
46 #define VERIMATRIX_KEY_SYSTEM_STRING "com.verimatrix.ott"
47 
48 #define HDCP_COMPLIANCE_CHECK_FAILURE 4327
49 #define HDCP_OUTPUT_PROTECTION_FAILURE 4427
50 /**
51  * @enum KeyState
52  * @brief DRM session states
53  */
54 typedef enum
55 {
56  KEY_INIT = 0, /**< Has been initialized */
57  KEY_PENDING = 1, /**< Has a key message pending to be processed */
58  KEY_READY = 2, /**< Has a usable key */
59  KEY_ERROR = 3, /**< Has an error */
60  KEY_CLOSED = 4, /**< Has been closed */
61  KEY_ERROR_EMPTY_SESSION_ID = 5 /**< Has Empty DRM session id */
62 
63 } KeyState;
64 
65 /**
66  * @class AampDrmSession
67  * @brief Base class for DRM sessions
68  */
70 {
71 protected:
72  std::string m_keySystem;
73  bool m_OutputProtectionEnabled;
74 #ifdef USE_SECMANAGER
75  int64_t mSessionId;
76 #endif
77 public:
78  AampLogManager *mLogObj;
79  /**
80  * @brief Create drm session with given init data
81  * @param f_pbInitData : pointer to initdata
82  * @param f_cbInitData : init data size
83  */
84  virtual void generateAampDRMSession(const uint8_t *f_pbInitData,uint32_t f_cbInitData, std::string &customData ) = 0;
85 
86  /**
87  * @brief Generate key request from DRM session
88  * Caller function should free the returned memory.
89  * @param destinationURL : gets updated with license server url
90  * @param timeout: max timeout untill which to wait for cdm key generation.
91  * @retval Pointer to DrmData containing license request.
92  */
93  virtual DrmData* aampGenerateKeyRequest(string& destinationURL, uint32_t timeout) = 0;
94 
95  /**
96  * @brief Updates the received key to DRM session
97  * @param key : License key from license server.
98  * @param timeout: max timeout untill which to wait for cdm key processing.
99  * @retval returns status of update request
100  */
101  virtual int aampDRMProcessKey(DrmData* key, uint32_t timeout) = 0;
102 
103  /**
104  * @fn decrypt
105  * @param keyIDBuffer : Key ID.
106  * @param ivBuffer : Initialization vector.
107  * @param buffer : Data to decrypt.
108  * @param subSampleCount : Number of subsamples.
109  * @param subSamplesBuffer : Subsamples buffer.
110  * @param caps : Caps of the media that is currently being decrypted
111  * @retval Returns status of decrypt request.
112  */
113  virtual int decrypt(GstBuffer* keyIDBuffer, GstBuffer* ivBuffer, GstBuffer* buffer, unsigned subSampleCount, GstBuffer* subSamplesBuffer, GstCaps* caps = NULL);
114 
115  /**
116  * @fn decrypt
117  * @param f_pbIV : Initialization vector.
118  * @param f_cbIV : Initialization vector length.
119  * @param payloadData : Data to decrypt.
120  * @param payloadDataSize : Size of data.
121  * @param ppOpaqueData : pointer to opaque buffer in case of SVP.
122  * @retval Returns status of decrypt request.
123  */
124  virtual int decrypt(const uint8_t *f_pbIV, uint32_t f_cbIV, const uint8_t *payloadData, uint32_t payloadDataSize, uint8_t **ppOpaqueData);
125 
126  /**
127  * @brief Get the current state of DRM Session.
128  * @retval KeyState
129  */
130  virtual KeyState getState() = 0;
131 
132  /**
133  * @brief Waits for the current state of DRM Session to match required.. Timeout is that from the helper.
134  * Only used by OCDM Adapter for now
135  * @param state the KeyState to achieve
136  * @param timeout how long to wait in mSecs
137  * @return true if obtained, false otherwise
138  */
139  virtual bool waitForState(KeyState state, const uint32_t timeout) { return true; }
140 
141  /**
142  * @brief Clear the current session context
143  * So that new init data can be bound.
144  */
145  virtual void clearDecryptContext() = 0;
146 
147  /**
148  * @fn AampDrmSession
149  * @param keySystem : DRM key system uuid
150  */
151  AampDrmSession(AampLogManager *logObj, const string &keySystem);
152  /**
153  * @brief Copy constructor disabled
154  *
155  */
156  AampDrmSession(const AampDrmSession&) = delete;
157  /**
158  * @brief assignment operator disabled
159  *
160  */
161  AampDrmSession& operator=(const AampDrmSession&) = delete;
162  /**
163  * @fn ~AampDrmSession
164  */
165  virtual ~AampDrmSession();
166 
167  /**
168  * @fn getKeySystem
169  * @retval DRM system uuid
170  */
171  string getKeySystem();
172 
173  /**
174  * @brief Set the OutputProtection for DRM Session
175  * @param bValue : Enable/Disable flag
176  * @retval void
177  */
178  void setOutputProtection(bool bValue) { m_OutputProtectionEnabled = bValue;}
179 #if defined(USE_OPENCDM_ADAPTER)
180  virtual void setKeyId(const std::vector<uint8_t>& keyId) {};
181 #endif
182 #ifdef USE_SECMANAGER
183  void setSessionId(int64_t sessionId);
184  int64_t getSessionId() const { return mSessionId; }
185 #endif
186 };
187 #endif
DrmData
To hold DRM key, license request etc.
Definition: AampDrmData.h:32
KEY_ERROR_EMPTY_SESSION_ID
@ KEY_ERROR_EMPTY_SESSION_ID
Definition: AampDrmSession.h:61
AampDrmSession::setOutputProtection
void setOutputProtection(bool bValue)
Set the OutputProtection for DRM Session.
Definition: AampDrmSession.h:178
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
KEY_PENDING
@ KEY_PENDING
Definition: AampDrmSession.h:57
AampDrmSession
Base class for DRM sessions.
Definition: AampDrmSession.h:69
AampDRMutils.h
Context-free common utility functions.
AampConfig.h
Configurations for AAMP.
KEY_INIT
@ KEY_INIT
Definition: AampDrmSession.h:56
KEY_READY
@ KEY_READY
Definition: AampDrmSession.h:58
KeyState
KeyState
DRM session states.
Definition: AampDrmSession.h:54
AampDrmSession::waitForState
virtual bool waitForState(KeyState state, const uint32_t timeout)
Waits for the current state of DRM Session to match required.. Timeout is that from the helper....
Definition: AampDrmSession.h:139
KEY_ERROR
@ KEY_ERROR
Definition: AampDrmSession.h:59
KEY_CLOSED
@ KEY_CLOSED
Definition: AampDrmSession.h:60