Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: media/base/media_keys.h

Issue 2568463003: media: Rename MediaKeys to ContentDecryptionModule (Closed)
Patch Set: comments addressed Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/ipc/media_param_traits_macros.h ('k') | media/base/media_keys.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 MEDIA_BASE_MEDIA_KEYS_H_
6 #define MEDIA_BASE_MEDIA_KEYS_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <string>
12 #include <vector>
13
14 #include "base/callback.h"
15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_vector.h"
18 #include "media/base/eme_constants.h"
19 #include "media/base/media_export.h"
20 #include "url/gurl.h"
21
22 namespace base {
23 class Time;
24 }
25
26 namespace media {
27
28 class CdmContext;
29 struct CdmKeyInformation;
30 struct MediaKeysTraits;
31
32 template <typename... T>
33 class CdmPromiseTemplate;
34
35 typedef CdmPromiseTemplate<std::string> NewSessionCdmPromise;
36 typedef CdmPromiseTemplate<> SimpleCdmPromise;
37 typedef ScopedVector<CdmKeyInformation> CdmKeysInfo;
38
39 // An interface that represents the Content Decryption Module (CDM) in the
40 // Encrypted Media Extensions (EME) spec in Chromium.
41 // See http://w3c.github.io/encrypted-media/#cdm
42 //
43 // * Ownership
44 //
45 // This class is ref-counted. However, a ref-count should only be held by:
46 // - The owner of the CDM. This is usually some class in the EME stack, e.g.
47 // CdmSessionAdapter in the render process, or MojoCdmService in a non-render
48 // process.
49 // - The media player that uses the CDM, to prevent the CDM from being
50 // destructed while still being used by the media player.
51 //
52 // When binding class methods into callbacks, prefer WeakPtr to using |this|
53 // directly to avoid having a ref-count held by the callback.
54 //
55 // * Thread Safety
56 //
57 // Most CDM operations happen on one thread. However, it is not uncommon that
58 // the media player lives on a different thread and may call into the CDM from
59 // that thread. For example, if the CDM supports a Decryptor interface, the
60 // Decryptor methods could be called on a different thread. The CDM
61 // implementation should make sure it's thread safe for these situations.
62 //
63 // TODO(xhwang): Rename MediaKeys to ContentDecryptionModule. See
64 // http://crbug.com/309237
65
66 class MEDIA_EXPORT MediaKeys
67 : public base::RefCountedThreadSafe<MediaKeys, MediaKeysTraits> {
68 public:
69 // Type of license required when creating/loading a session.
70 // Must be consistent with the values specified in the spec:
71 // https://w3c.github.io/encrypted-media/#idl-def-MediaKeySessionType
72 enum SessionType {
73 TEMPORARY_SESSION,
74 PERSISTENT_LICENSE_SESSION,
75 PERSISTENT_RELEASE_MESSAGE_SESSION,
76 SESSION_TYPE_MAX = PERSISTENT_RELEASE_MESSAGE_SESSION
77 };
78
79 // Type of message being sent to the application.
80 // Must be consistent with the values specified in the spec:
81 // https://w3c.github.io/encrypted-media/#idl-def-MediaKeyMessageType
82 enum MessageType {
83 LICENSE_REQUEST,
84 LICENSE_RENEWAL,
85 LICENSE_RELEASE,
86 MESSAGE_TYPE_MAX = LICENSE_RELEASE
87 };
88
89 // Provides a server certificate to be used to encrypt messages to the
90 // license server.
91 virtual void SetServerCertificate(
92 const std::vector<uint8_t>& certificate,
93 std::unique_ptr<SimpleCdmPromise> promise) = 0;
94
95 // Creates a session with |session_type|. Then generates a request with the
96 // |init_data_type| and |init_data|.
97 // Note:
98 // 1. The session ID will be provided when the |promise| is resolved.
99 // 2. The generated request should be returned through a SessionMessageCB,
100 // which must be AFTER the |promise| is resolved. Otherwise, the session ID
101 // in the callback will not be recognized.
102 // 3. UpdateSession(), CloseSession() and RemoveSession() should only be
103 // called after the |promise| is resolved.
104 virtual void CreateSessionAndGenerateRequest(
105 SessionType session_type,
106 EmeInitDataType init_data_type,
107 const std::vector<uint8_t>& init_data,
108 std::unique_ptr<NewSessionCdmPromise> promise) = 0;
109
110 // Loads a session with the |session_id| provided. Resolves the |promise| with
111 // |session_id| if the session is successfully loaded. Resolves the |promise|
112 // with an empty session ID if the session cannot be found. Rejects the
113 // |promise| if session loading is not supported, or other unexpected failure
114 // happened.
115 // Note: UpdateSession(), CloseSession() and RemoveSession() should only be
116 // called after the |promise| is resolved.
117 virtual void LoadSession(SessionType session_type,
118 const std::string& session_id,
119 std::unique_ptr<NewSessionCdmPromise> promise) = 0;
120
121 // Updates a session specified by |session_id| with |response|.
122 virtual void UpdateSession(const std::string& session_id,
123 const std::vector<uint8_t>& response,
124 std::unique_ptr<SimpleCdmPromise> promise) = 0;
125
126 // Closes the session specified by |session_id|. The CDM should resolve or
127 // reject the |promise| when the call has been processed. This may be before
128 // the session is closed. Once the session is closed, a SessionClosedCB must
129 // also be called.
130 virtual void CloseSession(const std::string& session_id,
131 std::unique_ptr<SimpleCdmPromise> promise) = 0;
132
133 // Removes stored session data associated with the session specified by
134 // |session_id|.
135 virtual void RemoveSession(const std::string& session_id,
136 std::unique_ptr<SimpleCdmPromise> promise) = 0;
137
138 // Returns the CdmContext associated with |this|. The returned CdmContext is
139 // owned by |this| and the caller needs to make sure it is not used after
140 // |this| is destructed.
141 // Returns null if CdmContext is not supported. Instead the media player may
142 // use the CDM via some platform specific method.
143 // By default this method returns null.
144 // TODO(xhwang): Convert all SetCdm() implementations to use CdmContext so
145 // that this function should never return nullptr.
146 virtual CdmContext* GetCdmContext();
147
148 // Deletes |this| on the correct thread. By default |this| is deleted
149 // immediately. Override this method if |this| needs to be deleted on a
150 // specific thread.
151 virtual void DeleteOnCorrectThread() const;
152
153 protected:
154 friend class base::RefCountedThreadSafe<MediaKeys, MediaKeysTraits>;
155
156 MediaKeys();
157 virtual ~MediaKeys();
158
159 private:
160 DISALLOW_COPY_AND_ASSIGN(MediaKeys);
161 };
162
163 struct MEDIA_EXPORT MediaKeysTraits {
164 // Destroys |media_keys| on the correct thread.
165 static void Destruct(const MediaKeys* media_keys);
166 };
167
168 // CDM session event callbacks.
169
170 // Called when the CDM needs to queue a message event to the session object.
171 // See http://w3c.github.io/encrypted-media/#dom-evt-message
172 typedef base::Callback<void(const std::string& session_id,
173 MediaKeys::MessageType message_type,
174 const std::vector<uint8_t>& message)>
175 SessionMessageCB;
176
177 // Called when the session specified by |session_id| is closed. Note that the
178 // CDM may close a session at any point, such as in response to a CloseSession()
179 // call, when the session is no longer needed, or when system resources are
180 // lost. See http://w3c.github.io/encrypted-media/#session-close
181 typedef base::Callback<void(const std::string& session_id)> SessionClosedCB;
182
183 // Called when there has been a change in the keys in the session or their
184 // status. See http://w3c.github.io/encrypted-media/#dom-evt-keystatuseschange
185 typedef base::Callback<void(const std::string& session_id,
186 bool has_additional_usable_key,
187 CdmKeysInfo keys_info)> SessionKeysChangeCB;
188
189 // Called when the CDM changes the expiration time of a session.
190 // See http://w3c.github.io/encrypted-media/#update-expiration
191 typedef base::Callback<void(const std::string& session_id,
192 base::Time new_expiry_time)>
193 SessionExpirationUpdateCB;
194
195 } // namespace media
196
197 #endif // MEDIA_BASE_MEDIA_KEYS_H_
OLDNEW
« no previous file with comments | « media/base/ipc/media_param_traits_macros.h ('k') | media/base/media_keys.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698