-
Notifications
You must be signed in to change notification settings - Fork 8
/
MediaSession.h
193 lines (161 loc) · 5.88 KB
/
MediaSession.h
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
* Copyright 2016-2017 TATA ELXSI
* Copyright 2016-2017 Metrological
*
* 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.
*/
#pragma once
#define MODULE_NAME OCDM_Playready
#include <drmbuild_oem.h>
#include <drmmanager.h>
#include <drmmathsafe.h>
#include <drmtypes.h>
#ifndef SIZEOF
#define SIZEOF sizeof
#include <drmcrt.h>
#undef min
#undef max
#include <drmbytemanip.h>
#else
#include <drmcommon.h>
#endif
#include <drmerr.h>
#include <drmerror.h>
#include <drmversionconstants.h>
#undef __in
#undef __out
#undef __reserved
#include <string.h>
#include <memory>
#include <interfaces/IDRM.h>
#include <core/core.h>
namespace CDMi {
struct PlayLevels {
uint16_t compressedDigitalVideoLevel_; //!< Compressed digital video output protection level.
uint16_t uncompressedDigitalVideoLevel_; //!< Uncompressed digital video output protection level.
uint16_t analogVideoLevel_; //!< Analog video output protection level.
uint16_t compressedDigitalAudioLevel_; //!< Compressed digital audio output protection level.
uint16_t uncompressedDigitalAudioLevel_; //!< Uncompressed digital audio output protection level.
};
class LicenseResponse {
public:
LicenseResponse() : dlr(new DRM_LICENSE_RESPONSE) {}
~LicenseResponse() { delete dlr; }
DRM_LICENSE_RESPONSE * get() { return dlr; }
void clear() { memset(dlr, 0, sizeof(DRM_LICENSE_RESPONSE)); }
private:
DRM_LICENSE_RESPONSE * const dlr;
};
class MediaKeySession : public IMediaKeySession, public IMediaKeySessionExt {
private:
enum KeyState {
// Has been initialized.
KEY_INIT = 0,
// Has a key message pending to be processed.
KEY_PENDING = 1,
// Has a usable key.
KEY_READY = 2,
// Has an error.
KEY_ERROR = 3,
// Has been closed.
KEY_CLOSED = 4
};
enum MessageType {
LicenseRequest = 0,
LicenseRenewal = 1,
LicenseRelease = 2,
IndividualizationRequest = 3
};
public:
//static const std::vector<std::string> m_mimeTypes;
MediaKeySession(const uint8_t *f_pbInitData, uint32_t f_cbInitData, const uint8_t *f_pbCDMData, uint32_t f_cbCDMData, DRM_APP_CONTEXT * poAppContext, bool initWithLast15, bool initiateChallengeGeneration = false);
~MediaKeySession();
bool playreadyGenerateKeyRequest();
bool ready() const { return m_eKeyState == KEY_READY; }
// MediaKeySession overrides
virtual void Run(
const IMediaKeySessionCallback *f_piMediaKeySessionCallback);
virtual CDMi_RESULT Load();
virtual void Update(
const uint8_t *f_pbKeyMessageResponse,
uint32_t f_cbKeyMessageResponse);
virtual CDMi_RESULT Remove();
virtual CDMi_RESULT Close(void);
virtual const char *GetSessionId(void) const;
virtual const char *GetKeySystem(void) const;
virtual CDMi_RESULT Decrypt(
const uint8_t *f_pbSessionKey,
uint32_t f_cbSessionKey,
const EncryptionScheme encryptionScheme,
const EncryptionPattern& pattern,
const uint8_t *f_pbIV,
uint32_t f_cbIV,
uint8_t *f_pbData,
uint32_t f_cbData,
uint32_t *f_pcbOpaqueClearContent,
uint8_t **f_ppbOpaqueClearContent,
const uint8_t keyIdLength,
const uint8_t* keyId,
bool initWithLast15) override;
virtual CDMi_RESULT ReleaseClearContent(
const uint8_t *f_pbSessionKey,
uint32_t f_cbSessionKey,
const uint32_t f_cbClearContentOpaque,
uint8_t *f_pbClearContentOpaque );
uint32_t GetSessionIdExt(void) const override;
virtual CDMi_RESULT SetDrmHeader(const uint8_t drmHeader[], uint32_t drmHeaderLength) override;
virtual CDMi_RESULT GetChallengeDataExt(uint8_t * challenge, uint32_t & challengeSize, uint32_t isLDL) override;
virtual CDMi_RESULT CancelChallengeDataExt() override;
virtual CDMi_RESULT StoreLicenseData(const uint8_t licenseData[], uint32_t licenseDataSize, unsigned char * secureStopId) override;
virtual CDMi_RESULT CleanDecryptContext() override;
virtual CDMi_RESULT SelectKeyId(const uint8_t keyLength, const uint8_t keyId[]) override;
private:
static DRM_RESULT DRM_CALL _PolicyCallback(const DRM_VOID *, DRM_POLICY_CALLBACK_TYPE f_dwCallbackType,
const DRM_KID *,
const DRM_LID *,
const DRM_VOID *);
DRM_BYTE *m_pbOpaqueBuffer;
DRM_DWORD m_cbOpaqueBuffer;
DRM_BYTE *m_pbRevocationBuffer;
KeyState m_eKeyState;
DRM_CHAR m_rgchSessionID[CCH_BASE64_EQUIV(SIZEOF(DRM_ID)) + 1];
DRM_BYTE *m_pbChallenge;
DRM_DWORD m_cbChallenge;
DRM_CHAR *m_pchSilentURL;
std::string m_customData;
IMediaKeySessionCallback *m_piCallback;
void CleanLicenseStore(DRM_APP_CONTEXT *pDrmAppCtx);
inline void PrintBase64(const int32_t length, const uint8_t* data, const char id[])
{
std::string base64, hex;
Thunder::Core::ToString(data, length, true, base64);
Thunder::Core::ToHexString(data, length, hex);
fprintf(stderr, "%s: %s\t[%s]", id, base64.c_str(), hex.c_str());
}
private:
std::vector<uint8_t> mDrmHeader;
std::vector<uint8_t> mNounce;
uint32_t mSessionId;
std::unique_ptr<LicenseResponse> mLicenseResponse;
std::vector<uint8_t> mSecureStopId;
PlayLevels levels_;
bool mInitWithLast15;
bool mInitiateChallengeGeneration;
DRM_ID mBatchId;
protected:
DRM_BOOL m_fCommit;
DRM_APP_CONTEXT *m_poAppContext;
DRM_DECRYPT_CONTEXT *m_oDecryptContext;
bool m_decryptInited;
};
} // namespace CDMi