-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathopencdmsessionadapter.h
More file actions
150 lines (129 loc) · 4.05 KB
/
Copy pathopencdmsessionadapter.h
File metadata and controls
150 lines (129 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* If not stated otherwise in this file or this component's license file the
* following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OpenCDMSessionAdapter_h
#define OpenCDMSessionAdapter_h
/**
* @file opencdmsessionadapter.h
* @brief Handles operation with OCDM session to handle DRM License data
*/
#include "PlayerExternalsInterface.h"
#include "DrmSession.h"
#include "DrmHelper.h"
#include "open_cdm.h"
#include "open_cdm_adapter.h"
#include <condition_variable>
#include "DrmCallbacks.h"
using namespace std;
/**
* @class Event
* @brief class to DRM Event handle
*/
class Event {
private:
bool signalled; //TODO: added to handle the events fired before calling wait, need to recheck
std::mutex lock;
std::condition_variable condition;
public:
Event() : signalled(false), lock(), condition() {
}
virtual ~Event() {
}
inline bool wait(const uint32_t waitTime)
{
bool ret = true;
std::unique_lock<std::mutex> _lock(lock);
if (!signalled) {
if (waitTime == 0) {
condition.wait(_lock);
} else {
if( std::cv_status::timeout == condition.wait_for(_lock,std::chrono::milliseconds(waitTime)) )
{
ret = false;
}
}
}
signalled = false;
return ret;
}
inline void signal()
{
std::unique_lock<std::mutex> _lock(lock);
signalled = true;
condition.notify_all();
}
};
/**
* @class OCDMSessionAdapter
* @brief Open CDM DRM session
*/
class OCDMSessionAdapter : public DrmSession
{
protected:
std::mutex decryptMutex;
KeyState m_eKeyState;
OpenCDMSession* m_pOpenCDMSession;
#ifdef USE_THUNDER_OCDM_API_0_2
struct OpenCDMSystem* m_pOpenCDMSystem;
#else
struct OpenCDMAccessor* m_pOpenCDMSystem;
#endif
OpenCDMSessionCallbacks m_OCDMSessionCallbacks;
std::shared_ptr<PlayerExternalsInterface> m_pOutputProtection;
std::string m_challenge;
uint16_t m_challengeSize;
std::string m_destUrl;
KeyStatus m_keyStatus;
KeyStatus m_sessionKeyStatus; // tracks any non-Usable key status received in a callback burst
bool m_keyStateIndeterminate;
std::vector<uint8_t> m_keyStored;
std::vector<std::vector<uint8_t>> m_usableKeys; // Store usable key IDs from ocdm_update_callback
mutable std::mutex m_usableKeysMutex; // Protects m_usableKeys from concurrent access
Event m_challengeReady;
Event m_keyStatusReady;
Event m_keyStatusWait;
string m_sessionID;
std::vector<uint8_t> m_keyId;
DrmHelperPtr m_drmHelper;
DrmCallbacks *m_drmCallbacks;
bool verifyOutputProtection();
public:
void processOCDMChallenge(const char destUrl[], const uint8_t challenge[], const uint16_t challengeSize);
void keysUpdatedOCDM();
void keyUpdateOCDM(const uint8_t key[], const uint8_t keySize);
const std::vector<std::vector<uint8_t>>& getUsableKeys() const override;
long long timeBeforeCallback;
private:
void initDRMSystem();
public:
OCDMSessionAdapter(DrmHelperPtr drmHelper, DrmCallbacks *callbacks = nullptr);
~OCDMSessionAdapter();
OCDMSessionAdapter(const OCDMSessionAdapter&) = delete;
OCDMSessionAdapter& operator=(const OCDMSessionAdapter&) = delete;
void generateDRMSession(const uint8_t *f_pbInitData,
uint32_t f_cbInitData, std::string &customData) override;
DrmData * generateKeyRequest(string& destinationURL, uint32_t timeout) override;
int processDRMKey(DrmData* key, uint32_t timeout) override;
KeyState getState() override;
void clearDecryptContext() override;
#if defined(USE_OPENCDM_ADAPTER)
void setKeyId(const std::vector<uint8_t>& keyId) override;
#endif
bool waitForState(KeyState state, const uint32_t timeout) override;
};
#endif