Debian Codegraph @

src/decrypters/widevineandroid/WVCencSingleSampleDecrypter.h

raw
1 /*
2 * Copyright (C) 2023 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #pragma once
10 #include "../IDecrypter.h"
11 #include "common/AdaptiveCencSampleDecrypter.h"
12
13 #include <map>
14 #include <string_view>
15
16 #include <bento4/Ap4.h>
17
18 class CWVCdmAdapterA;
19 class CWVDecrypterA;
20
21 class ATTR_DLL_LOCAL CWVCencSingleSampleDecrypterA : public Adaptive_CencSingleSampleDecrypter
22 {
23 public:
24 // methods
25 CWVCencSingleSampleDecrypterA(CWVCdmAdapterA& drm,
26 std::vector<uint8_t>& pssh,
27 std::string_view optionalKeyParameter,
28 const std::vector<uint8_t>& defaultKeyId,
29 CWVDecrypterA* host);
30 virtual ~CWVCencSingleSampleDecrypterA();
31
32 bool StartSession(bool skipSessionMessage) { return KeyUpdateRequest(true, skipSessionMessage); };
33 const std::vector<char>& GetSessionIdRaw() { return m_sessionId; };
34 virtual const char* GetSessionId() override;
35 std::vector<char> GetChallengeData();
36 virtual bool HasLicenseKey(const std::vector<uint8_t>& keyId);
37
38 virtual AP4_Result SetFragmentInfo(AP4_UI32 poolId,
39 const std::vector<uint8_t>& keyId,
40 const AP4_UI08 nalLengthSize,
41 AP4_DataBuffer& annexbSpsPps,
42 AP4_UI32 flags,
43 CryptoInfo cryptoInfo) override;
44 virtual AP4_UI32 AddPool() override;
45 virtual void RemovePool(AP4_UI32 poolId) override;
46
47 virtual AP4_Result DecryptSampleData(
48 AP4_UI32 poolId,
49 AP4_DataBuffer& dataIn,
50 AP4_DataBuffer& dataOut,
51
52 // always 16 bytes
53 const AP4_UI08* iv,
54
55 // pass 0 for full decryption
56 unsigned int subsampleCount,
57
58 // array of <subsample_count> integers. NULL if subsample_count is 0
59 const AP4_UI16* bytesOfCleartextData,
60
61 // array of <subsample_count> integers. NULL if subsample_count is 0
62 const AP4_UI32* bytesOfEncryptedData) override;
63
64 void GetCapabilities(const std::vector<uint8_t>& keyId,
65 uint32_t media,
66 DRM::DecrypterCapabilites& caps);
67
68 void RequestNewKeys() { m_isKeyUpdateRequested = true; };
69
70 private:
71 bool ProvisionRequest();
72 bool GetKeyRequest(std::vector<char>& keyRequestData);
73 bool KeyUpdateRequest(bool waitForKeys, bool skipSessionMessage);
74 bool SendSessionMessage(const std::vector<char>& keyRequestData);
75
76 CWVCdmAdapterA& m_mediaDrm;
77 std::vector<uint8_t> m_pssh;
78 std::vector<uint8_t> m_initialPssh;
79 std::map<std::string, std::string> m_optParams;
80 CWVDecrypterA* m_host;
81
82 std::vector<char> m_sessionId;
83 std::vector<char> m_keySetId;
84 std::vector<char> m_keyRequestData;
85
86 char m_sessionIdChar[128];
87 bool m_isProvisioningRequested;
88 bool m_isKeyUpdateRequested;
89
90 std::vector<uint8_t> m_defaultKeyId;
91
92 struct FINFO
93 {
94 std::vector<uint8_t> m_key;
95 AP4_UI08 m_nalLengthSize;
96 AP4_UI16 m_decrypterFlags;
97 AP4_DataBuffer m_annexbSpsPps;
98 };
99 std::vector<FINFO> m_fragmentPool;
100 int m_hdcpLimit;
101 int m_resolutionLimit;
102 };