Pepper_31_C++_interfaces
content_decryptor_samsung.h
Go to the documentation of this file.
1 // Copyright 2013 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 PPAPI_CPP_CONTENT_DECRYPTOR_SAMSUNG_H_
6 #define PPAPI_CPP_CONTENT_DECRYPTOR_SAMSUNG_H_
7 
8 #include "ppapi/c/pp_stdint.h"
9 #include "ppapi/c/pp_bool.h"
10 #include "ppapi/cpp/dev/buffer_dev.h"
11 #include "ppapi/cpp/resource.h"
12 #include "ppapi/cpp/var.h"
13 #include "ppapi/cpp/var_array_buffer.h"
14 #include "ppapi/c/samsung/pp_content_decryptor_samsung.h"
15 
16 
17 /// @file
18 /// This file defines API for implementing Content Decryptor functionality
19 /// by NaCl application. Interface is based on
20 /// <code>PP[PB]_ContentDecryptor_Private</code> API
21 
22 namespace pp {
23 
24 class InstanceHandle;
25 
26 /// Content Decryptor API allowing NaCl application to receive encrypted
27 /// chunks formining elementary stream and deliver decrypted (but encoded)
28 /// chunks of elementary stream to be decoded by the browser.
30  public:
31 
32  /// A constructor that creates an ContentDecryptor_Samsung bound to instance
33  /// After creation decryptor must be registered using method
34  /// <code>RegisterDecryptor</code> in order to be used.
35  explicit ContentDecryptor_Samsung(Instance* instance);
36 
37  /// Destructor
38  virtual ~ContentDecryptor_Samsung();
39 
40  // PPP_ContentDecryptor_Samsung functions exposed as virtual functions
41  // for you to override.
42 
43  /// Generates a key request. key_system specifies the key or licensing system
44  /// to use. type contains the MIME type of init_data. init_data is a data
45  /// buffer containing data for use in generating the request.
46  ///
47  /// Note: <code>GenerateKeyRequest()</code> must create the session ID used in
48  /// other methods on this interface. The session ID must be provided to the
49  /// browser by the CDM via <code>KeyMessage()</code> on the
50  /// <code>PPB_ContentDecryptor_Samsung</code> interface.
51  ///
52  /// @param[in] key_system The name of the key system.
53  ///
54  /// @param[in] type MIME type for init_data.
55  ///
56  /// @param[in] init_data Container specific initialization data.
57  virtual void GenerateKeyRequest(const std::string& key_system,
58  const std::string& type,
59  VarArrayBuffer init_data) = 0;
60 
61  /// Provides a key or license to the decryptor for decrypting media data.
62  ///
63  /// When the CDM needs more information to complete addition of the key it
64  /// will call <code>KeyMessage()</code> on the
65  /// <code>PPB_ContentDecryptor_Samsung</code> interface, which the browser
66  /// passes to the application. When the key is ready to use, the CDM
67  /// must call call <code>KeyAdded()</code> on the
68  /// <code>PPB_ContentDecryptor_Samsung</code> interface, and the browser
69  /// must notify the web application.
70  ///
71  /// @param[in] session_id The session ID.
72  ///
73  /// @param[in] key Decryption key, license, or other message for
74  /// the given session ID.
75  ///
76  /// @param[in] init_data Container specific initialization data.
77  virtual void AddKey(const std::string& session_id,
78  VarArrayBuffer key,
79  VarArrayBuffer init_data) = 0;
80 
81  /// Cancels a pending key request for the specified session ID.
82  ///
83  /// @param[in] session_id The session ID.
84  virtual void CancelKeyRequest(const std::string& session_id) = 0;
85 
86  /// Decrypts the block and returns the unencrypted block via
87  /// <code>DeliverBlock()</code> on the
88  /// <code>PPB_ContentDecryptor_Samsung</code> interface. The returned block
89  /// contains encoded data.
90  ///
91  /// @param[in] resource An encrypted data block.
92  ///
93  /// @param[in] encrypted_block_info A <code>PP_EncryptedBlockInfo</code> that
94  /// contains all auxiliary information needed for decryption of the
95  /// <code>encrypted_block</code>.
96  virtual void Decrypt(Buffer_Dev encrypted_buffer,
97  const PP_EncryptedBlockInfo& encrypted_block_info) = 0;
98 
99  // PPB_ContentDecryptor_Samsung methods for passing data from the decryptor
100  // to the browser.
101 
102  /// The decryptor requires a key that has not been provided.
103  ///
104  /// Sent when the decryptor encounters encrypted content, but it does not have
105  /// the key required to decrypt the data. The plugin will call this method in
106  /// response to a call to the <code>Decrypt()</code> method on the
107  /// <code>PPP_ContentDecryptor_Samsung<code> interface.
108  ///
109  /// The browser must notify the application that a key is needed, and, in
110  /// response, the web application must direct the browser to call
111  /// <code>AddKey()</code> on the <code>PPP_ContentDecryptor_Samsung</code>
112  /// interface.
113  ///
114  /// @param[in] key_system The name of the key system.
115  ///
116  /// @param[in] session_id The session ID.
117  ///
118  /// @param[in] init_data Container specific initialization data.
119  void NeedKey(const std::string& key_system,
120  const std::string& session_id,
121  VarArrayBuffer init_data);
122 
123  /// A key has been added as the result of a call to the <code>AddKey()</code>
124  /// method on the <code>PPP_ContentDecryptor_Samsung</code> interface.
125  ///
126  /// Note: The above describes the most simple case. Depending on the key
127  /// system, a series of <code>KeyMessage()</code> calls from the CDM will be
128  /// sent to the browser, and then on to the web application. The web
129  /// application must then provide more data to the CDM by directing the browser
130  /// to pass the data to the CDM via calls to <code>AddKey()</code> on the
131  /// <code>PPP_ContentDecryptor_Samsung</code> interface.
132  /// The CDM must call <code>KeyAdded()</code> when the sequence is completed,
133  /// and, in response, the browser must notify the web application.
134  ///
135  /// @param[in] key_system The name of the key system.
136  ///
137  /// @param[in] session_id The session ID.
138  void KeyAdded(const std::string& key_system,
139  const std::string& session_id);
140 
141  /// A message or request has been generated for key_system in the CDM, and
142  /// must be sent to the web application.
143  ///
144  /// For example, when the browser invokes <code>GenerateKeyRequest()</code>
145  /// on the <code>PPP_ContentDecryptor_Samsung</code> interface, the plugin
146  /// must send a key message containing the key request.
147  ///
148  /// Note that <code>KeyMessage()</code> can be used for purposes other than
149  /// responses to <code>GenerateKeyRequest()</code> calls. See also the text
150  /// in the comment for <code>KeyAdded()</code>, which describes a sequence of
151  /// <code>AddKey()</code> and <code>KeyMessage()</code> calls required to
152  /// prepare for decryption.
153  ///
154  /// @param[in] key_system Tthe name of the key system.
155  ///
156  /// @param[in] session_id The session ID.
157  ///
158  /// @param[in] message Buffer containing the message.
159  ///
160  /// @param[in] default_url Default URL for the message.
161  void KeyMessage(const std::string& key_system,
162  const std::string& session_id,
163  VarArrayBuffer message,
164  const std::string& default_url);
165 
166  /// An error occurred in a <code>PPP_ContentDecryptor_Samsung</code> method,
167  /// or within the plugin implementing the interface.
168  ///
169  /// @param[in] key_system The name of the key system.
170  ///
171  /// @param[in] session_id The session ID.
172  ///
173  /// @param[in] media_error A MediaKeyError.
174  ///
175  /// @param[in] system_error A system error code.
176  void KeyError(const std::string& key_system,
177  const std::string& session_id,
178  int32_t media_error,
179  int32_t system_code);
180 
181  /// Called after the <code>Decrypt()</code> method completes to
182  /// deliver decrypted_block to the browser for decoding and rendering.
183  ///
184  /// The plugin must not hold a reference to the encrypted buffer resource
185  /// provided to <code>Decrypt()</code> when it calls this method. The browser
186  /// will reuse the buffer in a subsequent <code>Decrypt()</code> call.
187  ///
188  /// @param[in] decrypted_block Decrypted data block.
189  ///
190  /// @param[in] decrypted_block_info A <code>PP_DecryptedBlockInfo</code> that
191  /// contains the result code and tracking info associated with the
192  /// <code>decrypted_block</code>.
193  void DeliverBlock(Buffer_Dev decrypted_block,
194  const PP_DecryptedBlockInfo& decrypted_block_info);
195 
196  /// The decryptor must register itself in the Browser, so that it can be used
197  /// by the Browser as Content Decryptor Module.
198  ///
199  /// @param[in] key_system Name of this content decryptor uder
200  /// which the Browser will recognize it.
201  ///
202  /// @param[in] type Type of media that are supported
203  /// by this content decryptor (* - means all MIME types)
204  ///
205  /// @return A <code>PP_Bool</code> containing containing <code>PP_TRUE</code>
206  /// if the registration succeed, otherwise <code>PP_FALSE</code>.
207  PP_Bool RegisterDecryptor(const std::string& key_system,
208  const std::string& type);
209 
210  private:
211  InstanceHandle associated_instance_;
212 };
213 
214 } // namespace pp
215 
216 #endif // PPAPI_CPP_CONTENT_DECRYPTOR_SAMSUNG_H_
217 
PP_Bool RegisterDecryptor(const std::string &key_system, const std::string &type)
virtual void GenerateKeyRequest(const std::string &key_system, const std::string &type, VarArrayBuffer init_data)=0
virtual void CancelKeyRequest(const std::string &session_id)=0
void DeliverBlock(Buffer_Dev decrypted_block, const PP_DecryptedBlockInfo &decrypted_block_info)
void KeyAdded(const std::string &key_system, const std::string &session_id)
virtual void AddKey(const std::string &session_id, VarArrayBuffer key, VarArrayBuffer init_data)=0
virtual ~ContentDecryptor_Samsung()
Destructor.
virtual void Decrypt(Buffer_Dev encrypted_buffer, const PP_EncryptedBlockInfo &encrypted_block_info)=0
void KeyError(const std::string &key_system, const std::string &session_id, int32_t media_error, int32_t system_code)
void KeyMessage(const std::string &key_system, const std::string &session_id, VarArrayBuffer message, const std::string &default_url)
ContentDecryptor_Samsung(Instance *instance)
void NeedKey(const std::string &key_system, const std::string &session_id, VarArrayBuffer init_data)