blob: 374f54a2a025dccaddf4c78574a2ff4e870c4f15 [file] [log] [blame]
Xiaohan Wang5f25cb62017-12-04 14:33:11 -08001// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CDM_CONTENT_DECRYPTION_MODULE_PROXY_H_
6#define CDM_CONTENT_DECRYPTION_MODULE_PROXY_H_
7
8#include "content_decryption_module_export.h"
9
10#if defined(_MSC_VER)
11typedef unsigned char uint8_t;
12typedef unsigned int uint32_t;
13typedef unsigned __int64 uint64_t;
14#else
15#include <stdint.h>
16#endif
17
18namespace cdm {
19
20class CDM_CLASS_API CdmProxyClient;
21
22// A proxy class for the CDM.
23// In general, the interpretation of the CdmProxy and CdmProxyClient method
24// parameters are protocol dependent. For enum parameters, values outside the
25// enum range may not work.
26class CDM_CLASS_API CdmProxy {
27 public:
Xiaohan Wang1a218422018-02-09 14:29:11 -080028 enum Function : uint32_t {
Xiaohan Wang5f25cb62017-12-04 14:33:11 -080029 // For Intel Negotiate Crypto SessionKey Exchange (CSME) path to call
30 // ID3D11VideoContext::NegotiateCryptoSessionKeyExchange.
Xiaohan Wang1a218422018-02-09 14:29:11 -080031 kIntelNegotiateCryptoSessionKeyExchange = 1,
Xiaohan Wang5f25cb62017-12-04 14:33:11 -080032 // There will be more values in the future e.g. for D3D11 RSA method.
33 };
34
Xiaohan Wang38948022018-09-13 10:44:17 -070035 enum KeyType : uint32_t {
36 kDecryptOnly = 0,
37 kDecryptAndDecode = 1,
38 };
39
Xiaohan Wanga4cb09b2017-12-21 14:51:26 -080040 // Initializes the proxy. The results will be returned in
Xiaohan Wang5f25cb62017-12-04 14:33:11 -080041 // CdmProxyClient::OnInitialized().
Xiaohan Wanga4cb09b2017-12-21 14:51:26 -080042 virtual void Initialize() = 0;
Xiaohan Wang5f25cb62017-12-04 14:33:11 -080043
44 // Processes and updates the state of the proxy.
45 // |output_data_size| is required by some protocol to set up the output data.
46 // The operation may fail if the |output_data_size| is wrong. The results will
47 // be returned in CdmProxyClient::OnProcessed().
48 virtual void Process(Function function,
49 uint32_t crypto_session_id,
50 const uint8_t* input_data,
51 uint32_t input_data_size,
52 uint32_t output_data_size) = 0;
53
54 // Creates a crypto session for handling media.
55 // If extra data has to be passed to further setup the media crypto session,
56 // pass the data as |input_data|. The results will be returned in
57 // CdmProxyClient::OnMediaCryptoSessionCreated().
58 virtual void CreateMediaCryptoSession(const uint8_t* input_data,
59 uint32_t input_data_size) = 0;
60
61 // Sets a key for the session identified by |crypto_session_id|.
62 virtual void SetKey(uint32_t crypto_session_id,
63 const uint8_t* key_id,
64 uint32_t key_id_size,
Xiaohan Wang38948022018-09-13 10:44:17 -070065 KeyType key_type,
Xiaohan Wang5f25cb62017-12-04 14:33:11 -080066 const uint8_t* key_blob,
67 uint32_t key_blob_size) = 0;
68
69 // Removes a key for the session identified by |crypto_session_id|.
70 virtual void RemoveKey(uint32_t crypto_session_id,
71 const uint8_t* key_id,
72 uint32_t key_id_size) = 0;
73
Xiaohan Wang5f25cb62017-12-04 14:33:11 -080074 protected:
75 CdmProxy() {}
76 virtual ~CdmProxy() {}
77};
78
79// Responses to CdmProxy calls. All responses will be called asynchronously.
80class CDM_CLASS_API CdmProxyClient {
81 public:
Xiaohan Wang1a218422018-02-09 14:29:11 -080082 enum Status : uint32_t {
Xiaohan Wang5f25cb62017-12-04 14:33:11 -080083 kOk,
84 kFail,
85 };
86
Xiaohan Wang1a218422018-02-09 14:29:11 -080087 enum Protocol : uint32_t {
88 kNone = 0, // No protocol supported. Can be used in failure cases.
Xiaohan Wangbd20cfc2018-06-21 00:42:18 -070089 kIntel, // Method using Intel CSME.
Xiaohan Wang5f25cb62017-12-04 14:33:11 -080090 // There will be more values in the future e.g. kD3D11RsaHardware,
91 // kD3D11RsaSoftware to use the D3D11 RSA method.
92 };
93
94 // Callback for Initialize(). If the proxy created a crypto session, then the
95 // ID for the crypto session is |crypto_session_id|.
96 virtual void OnInitialized(Status status,
97 Protocol protocol,
98 uint32_t crypto_session_id) = 0;
99
100 // Callback for Process(). |output_data| is the output of processing.
101 virtual void OnProcessed(Status status,
102 const uint8_t* output_data,
103 uint32_t output_data_size) = 0;
104
105 // Callback for CreateMediaCryptoSession(). On success:
106 // - |crypto_session_id| is the ID for the created crypto session.
107 // - |output_data| is extra value, if any.
108 // Otherwise, |crypto_session_id| and |output_data| should be ignored.
109 virtual void OnMediaCryptoSessionCreated(Status status,
110 uint32_t crypto_session_id,
111 uint64_t output_data) = 0;
112
Xiaohan Wangbf6d8e02018-09-21 17:07:59 -0700113 // Callback for SetKey().
114 virtual void OnKeySet(Status status) = 0;
115
116 // Callback for RemoveKey().
117 virtual void OnKeyRemoved(Status status) = 0;
118
Xiaohan Wang5f25cb62017-12-04 14:33:11 -0800119 // Called when there is a hardware reset and all the hardware context is lost.
120 virtual void NotifyHardwareReset() = 0;
121
122 protected:
123 CdmProxyClient() {}
124 virtual ~CdmProxyClient() {}
125};
126
127} // namespace cdm
128
129#endif // CDM_CONTENT_DECRYPTION_MODULE_PROXY_H_