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

Side by Side Diff: media/cdm/proxy_decryptor.h

Issue 1070853004: media: CdmFactory creates CDM (MediaKeys) asynchronously. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase only Created 5 years, 8 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_CDM_PROXY_DECRYPTOR_H_ 5 #ifndef MEDIA_CDM_PROXY_DECRYPTOR_H_
6 #define MEDIA_CDM_PROXY_DECRYPTOR_H_ 6 #define MEDIA_CDM_PROXY_DECRYPTOR_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "media/base/cdm_context.h"
15 #include "media/base/decryptor.h" 16 #include "media/base/decryptor.h"
16 #include "media/base/eme_constants.h" 17 #include "media/base/eme_constants.h"
17 #include "media/base/media_export.h" 18 #include "media/base/media_export.h"
18 #include "media/base/media_keys.h" 19 #include "media/base/media_keys.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 namespace media { 22 namespace media {
22 23
23 class CdmFactory; 24 class CdmFactory;
24 class MediaPermission; 25 class MediaPermission;
25 26
26 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API. 27 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API.
27 // A decryptor proxy that creates a real decryptor object on demand and 28 // A decryptor proxy that creates a real decryptor object on demand and
28 // forwards decryptor calls to it. 29 // forwards decryptor calls to it.
29 // 30 //
30 // TODO(xhwang): Currently we don't support run-time switching among decryptor 31 // TODO(xhwang): Currently we don't support run-time switching among decryptor
31 // objects. Fix this when needed. 32 // objects. Fix this when needed.
32 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! 33 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name!
33 class MEDIA_EXPORT ProxyDecryptor { 34 class MEDIA_EXPORT ProxyDecryptor {
34 public: 35 public:
36 typedef base::Callback<void(CdmContext*, const CdmAttachedCB&)>
37 SetCdmContextCB;
38
35 // These are similar to the callbacks in media_keys.h, but pass back the 39 // These are similar to the callbacks in media_keys.h, but pass back the
36 // session ID rather than the internal session ID. 40 // session ID rather than the internal session ID.
37 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; 41 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB;
38 typedef base::Callback<void(const std::string& session_id, 42 typedef base::Callback<void(const std::string& session_id,
39 MediaKeys::KeyError error_code, 43 MediaKeys::KeyError error_code,
40 uint32 system_code)> KeyErrorCB; 44 uint32 system_code)> KeyErrorCB;
41 typedef base::Callback<void(const std::string& session_id, 45 typedef base::Callback<void(const std::string& session_id,
42 const std::vector<uint8>& message, 46 const std::vector<uint8>& message,
43 const GURL& destination_url)> KeyMessageCB; 47 const GURL& destination_url)> KeyMessageCB;
44 48
45 ProxyDecryptor(MediaPermission* media_permission, 49 ProxyDecryptor(MediaPermission* media_permission,
46 const KeyAddedCB& key_added_cb, 50 const KeyAddedCB& key_added_cb,
47 const KeyErrorCB& key_error_cb, 51 const KeyErrorCB& key_error_cb,
48 const KeyMessageCB& key_message_cb); 52 const KeyMessageCB& key_message_cb);
49 virtual ~ProxyDecryptor(); 53 virtual ~ProxyDecryptor();
50 54
51 // Returns the CdmContext associated with this object. 55 // Creates the CDM and fires |cdm_created_cb|. This method should only be
52 CdmContext* GetCdmContext(); 56 // called once. If CDM creation failed, all following GenerateKeyRequest,
57 // AddKey and CancelKeyRequest calls will result in a KeyError.
58 void CreateCdm(CdmFactory* cdm_factory,
59 const std::string& key_system,
60 const GURL& security_origin,
61 const SetCdmContextCB& set_cdm_context_cb);
53 62
54 // Only call this once. 63 // May only be called after CreateCDM().
55 bool InitializeCDM(CdmFactory* cdm_factory, 64 void GenerateKeyRequest(EmeInitDataType init_data_type,
56 const std::string& key_system,
57 const GURL& security_origin);
58
59 // May only be called after InitializeCDM() succeeds.
60 bool GenerateKeyRequest(EmeInitDataType init_data_type,
61 const uint8* init_data, 65 const uint8* init_data,
62 int init_data_length); 66 int init_data_length);
63 void AddKey(const uint8* key, int key_length, 67 void AddKey(const uint8* key, int key_length,
64 const uint8* init_data, int init_data_length, 68 const uint8* init_data, int init_data_length,
65 const std::string& session_id); 69 const std::string& session_id);
66 void CancelKeyRequest(const std::string& session_id); 70 void CancelKeyRequest(const std::string& session_id);
67 71
68 private: 72 private:
69 // Helper function to create MediaKeys to handle the given |key_system|. 73 // Callback for CreateCdm().
70 scoped_ptr<MediaKeys> CreateMediaKeys( 74 void OnCdmCreated(const std::string& key_system,
71 CdmFactory* cdm_factory, 75 const GURL& security_origin,
72 const std::string& key_system, 76 const SetCdmContextCB& set_cdm_context_cb,
73 const GURL& security_origin); 77 scoped_ptr<MediaKeys> cdm);
78
79 void GenerateKeyRequestInternal(EmeInitDataType init_data_type,
80 const std::vector<uint8>& init_data);
74 81
75 // Callbacks for firing session events. 82 // Callbacks for firing session events.
76 void OnSessionMessage(const std::string& session_id, 83 void OnSessionMessage(const std::string& session_id,
77 MediaKeys::MessageType message_type, 84 MediaKeys::MessageType message_type,
78 const std::vector<uint8>& message, 85 const std::vector<uint8>& message,
79 const GURL& legacy_destination_url); 86 const GURL& legacy_destination_url);
80 void OnSessionKeysChange(const std::string& session_id, 87 void OnSessionKeysChange(const std::string& session_id,
81 bool has_additional_usable_key, 88 bool has_additional_usable_key,
82 CdmKeysInfo keys_info); 89 CdmKeysInfo keys_info);
83 void OnSessionExpirationUpdate(const std::string& session_id, 90 void OnSessionExpirationUpdate(const std::string& session_id,
(...skipping 15 matching lines...) Expand all
99 enum SessionCreationType { 106 enum SessionCreationType {
100 TemporarySession, 107 TemporarySession,
101 PersistentSession, 108 PersistentSession,
102 LoadSession 109 LoadSession
103 }; 110 };
104 111
105 // Called when a session is actually created or loaded. 112 // Called when a session is actually created or loaded.
106 void SetSessionId(SessionCreationType session_type, 113 void SetSessionId(SessionCreationType session_type,
107 const std::string& session_id); 114 const std::string& session_id);
108 115
116 struct PendingGenerateKeyRequestData {
117 PendingGenerateKeyRequestData(EmeInitDataType init_data_type,
118 const std::vector<uint8>& init_data);
119 ~PendingGenerateKeyRequestData();
120
121 EmeInitDataType init_data_type;
122 std::vector<uint8> init_data;
123 };
124
125 bool is_creating_cdm_;
126
109 // The real MediaKeys that manages key operations for the ProxyDecryptor. 127 // The real MediaKeys that manages key operations for the ProxyDecryptor.
110 scoped_ptr<MediaKeys> media_keys_; 128 scoped_ptr<MediaKeys> media_keys_;
111 129
112 MediaPermission* media_permission_; 130 MediaPermission* media_permission_;
113 131
114 // Callbacks for firing key events. 132 // Callbacks for firing key events.
115 KeyAddedCB key_added_cb_; 133 KeyAddedCB key_added_cb_;
116 KeyErrorCB key_error_cb_; 134 KeyErrorCB key_error_cb_;
117 KeyMessageCB key_message_cb_; 135 KeyMessageCB key_message_cb_;
118 136
119 std::string key_system_; 137 std::string key_system_;
120 GURL security_origin_; 138 GURL security_origin_;
121 139
122 // Keep track of both persistent and non-persistent sessions. 140 // Keep track of both persistent and non-persistent sessions.
123 base::hash_map<std::string, bool> active_sessions_; 141 base::hash_map<std::string, bool> active_sessions_;
124 142
125 bool is_clear_key_; 143 bool is_clear_key_;
126 144
145 std::vector<PendingGenerateKeyRequestData> pending_requests_;
146
127 // NOTE: Weak pointers must be invalidated before all other member variables. 147 // NOTE: Weak pointers must be invalidated before all other member variables.
128 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; 148 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_;
129 149
130 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); 150 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor);
131 }; 151 };
132 152
133 } // namespace media 153 } // namespace media
134 154
135 #endif // MEDIA_CDM_PROXY_DECRYPTOR_H_ 155 #endif // MEDIA_CDM_PROXY_DECRYPTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698