RDK Documentation (Open Sourced RDK Components)
opencdmsessionadapter.h
Go to the documentation of this file.
1 #ifndef OpenCDMSessionAdapter_h
2 #define OpenCDMSessionAdapter_h
3 
4 /**
5  * @file opencdmsessionadapter.h
6  * @brief Handles operation with OCDM session to handle DRM License data
7  */
8 
9 #include "AampDrmSession.h"
10 #include "aampoutputprotection.h"
11 #include "AampDrmHelper.h"
12 
13 #include <open_cdm.h>
14 #include <open_cdm_adapter.h>
15 #include "AampDrmCallbacks.h"
16 
17 using namespace std;
18 
19 /**
20  * @class Event
21  * @brief class to DRM Event handle
22  */
23 
24 class Event {
25 private:
26  bool signalled; //TODO: added to handle the events fired before calling wait, need to recheck
27  pthread_mutex_t lock;
28  pthread_cond_t condition;
29  pthread_condattr_t condAttr;
30 public:
31  Event() : signalled(false), lock(PTHREAD_MUTEX_INITIALIZER), condition(PTHREAD_COND_INITIALIZER), condAttr() {
32  pthread_mutex_init(&lock, NULL);
33  pthread_condattr_init(&condAttr);
34  pthread_condattr_setclock(&condAttr, CLOCK_MONOTONIC );
35  pthread_cond_init(&condition, &condAttr);
36  }
37  virtual ~Event() {
38  pthread_cond_destroy(&condition);
39  pthread_mutex_destroy(&lock);
40  pthread_condattr_destroy(&condAttr);
41  }
42 
43  inline bool wait(const uint32_t waitTime)
44  {
45  int ret = 0;
46  pthread_mutex_lock(&lock);
47  if (!signalled) {
48  if (waitTime == 0) {
49  ret = pthread_cond_wait(&condition, &lock);
50  } else {
51  struct timespec time;
52  clock_gettime(CLOCK_MONOTONIC, &time);
53 
54  time.tv_nsec += ((waitTime % 1000) * 1000 * 1000);
55  time.tv_sec += (waitTime / 1000) + (time.tv_nsec / 1000000000);
56  time.tv_nsec = time.tv_nsec % 1000000000;
57 
58  ret = pthread_cond_timedwait(&condition, &lock, &time);
59 
60  }
61  }
62 
63  signalled = false;
64  pthread_mutex_unlock(&lock);
65 
66  return ((ret == 0)? true: false);
67  }
68 
69  inline void signal()
70  {
71  pthread_mutex_lock(&lock);
72  signalled = true;
73  pthread_cond_broadcast(&condition);
74  pthread_mutex_unlock(&lock);
75  }
76 };
77 
78 /**
79  * @class AAMPOCDMSessionAdapter
80  * @brief Open CDM DRM session
81  */
83 {
84 protected:
85  pthread_mutex_t decryptMutex;
86 
87  KeyState m_eKeyState;
88 
89  OpenCDMSession* m_pOpenCDMSession;
90 #ifdef USE_THUNDER_OCDM_API_0_2
91  struct OpenCDMSystem* m_pOpenCDMSystem;
92 #else
93  struct OpenCDMAccessor* m_pOpenCDMSystem;
94 #endif
95  OpenCDMSessionCallbacks m_OCDMSessionCallbacks;
96  AampOutputProtection* m_pOutputProtection;
97 
98  std::string m_challenge;
99  uint16_t m_challengeSize;
100 
101  std::string m_destUrl;
102  KeyStatus m_keyStatus;
103  bool m_keyStateIndeterminate;
104  std::vector<uint8_t> m_keyStored;
105 
106  Event m_challengeReady;
107  Event m_keyStatusReady;
108  Event m_keyStatusWait;
109  string m_sessionID;
110 
111  std::vector<uint8_t> m_keyId;
112 
113  std::shared_ptr<AampDrmHelper> m_drmHelper;
114  AampDrmCallbacks *m_drmCallbacks;
115 
116  bool verifyOutputProtection();
117 public:
118  void processOCDMChallenge(const char destUrl[], const uint8_t challenge[], const uint16_t challengeSize);
119  void keysUpdatedOCDM();
120  void keyUpdateOCDM(const uint8_t key[], const uint8_t keySize);
121  long long timeBeforeCallback;
122 
123 private:
124  void initAampDRMSystem();
125 
126 public:
127  AAMPOCDMSessionAdapter(AampLogManager *logObj, std::shared_ptr<AampDrmHelper> drmHelper, AampDrmCallbacks *callbacks = nullptr);
130  AAMPOCDMSessionAdapter& operator=(const AAMPOCDMSessionAdapter&) = delete;
131  void generateAampDRMSession(const uint8_t *f_pbInitData,
132  uint32_t f_cbInitData, std::string &customData);
133  DrmData * aampGenerateKeyRequest(string& destinationURL, uint32_t timeout);
134  int aampDRMProcessKey(DrmData* key, uint32_t timeout);
135  KeyState getState();
136  void clearDecryptContext();
137  void setKeyId(const std::vector<uint8_t>& keyId);
138  bool waitForState(KeyState state, const uint32_t timeout) override;
139 };
140 
141 #endif
AampDrmCallbacks
DRM callback interface.
Definition: AampDrmCallbacks.h:34
AampDrmHelper.h
Implented DRM helper functionalities.
aampoutputprotection.h
Output protection management for Aamp.
DrmData
To hold DRM key, license request etc.
Definition: AampDrmData.h:32
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
Event
class to DRM Event handle
Definition: opencdmsessionadapter.h:24
AampOutputProtection
Class to enforce HDCP authentication.
Definition: aampoutputprotection.h:119
AampDrmCallbacks.h
Call back handler for Aamp.
AAMPOCDMSessionAdapter
Open CDM DRM session.
Definition: opencdmsessionadapter.h:82
AampDrmSession
Base class for DRM sessions.
Definition: AampDrmSession.h:69
KeyState
KeyState
DRM session states.
Definition: AampDrmSession.h:54
AampDrmSession.h
Header file for AampDrmSession.