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

Side by Side Diff: content/renderer/media/cdm_session_adapter.h

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_
6 #define CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ 6 #define CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "media/base/media_keys.h" 13 #include "media/base/media_keys.h"
14 #include "media/base/media_keys_session_promise.h"
14 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h " 15 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h "
15 16
16 #if defined(ENABLE_PEPPER_CDMS) 17 #if defined(ENABLE_PEPPER_CDMS)
17 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" 18 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h"
18 #endif 19 #endif
19 20
20 class GURL; 21 class GURL;
21 22
22 namespace content { 23 namespace content {
23 24
24 class WebContentDecryptionModuleSessionImpl; 25 class WebContentDecryptionModuleSessionImpl;
25 26
26 // Owns the CDM instance and makes calls from session objects to the CDM. 27 // Owns the CDM instance and makes calls from session objects to the CDM.
27 // Forwards the session ID-based callbacks of the MediaKeys interface to the 28 // Forwards the session ID-based callbacks of the MediaKeys interface to the
xhwang 2014/05/05 20:46:42 s/session/web session/ This seems a pretty big ch
jrummell 2014/05/08 23:37:45 Done.
28 // appropriate session object. Callers should hold references to this class 29 // appropriate session object. Callers should hold references to this class
29 // as long as they need the CDM instance. 30 // as long as they need the CDM instance.
30 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { 31 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> {
31 public: 32 public:
32 CdmSessionAdapter(); 33 CdmSessionAdapter();
33 34
34 // Returns true on success. 35 // Returns true on success.
35 bool Initialize( 36 bool Initialize(
36 #if defined(ENABLE_PEPPER_CDMS) 37 #if defined(ENABLE_PEPPER_CDMS)
37 const CreatePepperCdmCB& create_pepper_cdm_cb, 38 const CreatePepperCdmCB& create_pepper_cdm_cb,
38 #endif 39 #endif
39 const std::string& key_system, 40 const std::string& key_system,
40 const GURL& security_origin); 41 const GURL& security_origin);
41 42
42 // Creates a new session and adds it to the internal map. The caller owns the 43 // Creates a new session and adds it to the internal map. The caller owns the
43 // created session. RemoveSession() must be called when destroying it. 44 // created session.
ddorwin 2014/05/05 18:35:42 Why was the following removed? Is it no longer tru
jrummell 2014/05/08 23:37:45 Added back (with explanation).
44 WebContentDecryptionModuleSessionImpl* CreateSession( 45 WebContentDecryptionModuleSessionImpl* CreateSession(
45 blink::WebContentDecryptionModuleSession::Client* client); 46 blink::WebContentDecryptionModuleSession::Client* client);
46 47
48 // Adds a session to the internal map. Called once the session is successfully
49 // initialized.
50 void RegisterSession(
51 const std::string& web_session_id,
52 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session);
53
47 // Removes a session from the internal map. 54 // Removes a session from the internal map.
48 void RemoveSession(uint32 session_id); 55 void RemoveSession(const std::string& web_session_id);
49 56
50 // Initializes the session specified by |session_id| with the |content_type| 57 // Initializes a session with the |init_data_type|, |init_data| and
51 // and |init_data| provided. 58 // |session_type| provided. Takes ownership of |promise|.
52 void InitializeNewSession(uint32 session_id, 59 void InitializeNewSession(const std::string& init_data_type,
53 const std::string& content_type,
54 const uint8* init_data, 60 const uint8* init_data,
55 int init_data_length); 61 int init_data_length,
62 media::MediaKeys::SessionType session_type,
63 scoped_ptr<media::MediaKeysSessionPromise> promise);
56 64
57 // Updates the session specified by |session_id| with |response|. 65 // Updates the session specified by |web_session_id| with |response|.
58 void UpdateSession(uint32 session_id, 66 // Takes ownership of |promise|.
67 void UpdateSession(const std::string& web_session_id,
59 const uint8* response, 68 const uint8* response,
60 int response_length); 69 int response_length,
70 scoped_ptr<media::MediaKeysSessionPromise> promise);
61 71
62 // Releases the session specified by |session_id|. 72 // Releases the session specified by |web_session_id|.
63 void ReleaseSession(uint32 session_id); 73 // Takes ownership of |promise|.
74 void ReleaseSession(const std::string& web_session_id,
75 scoped_ptr<media::MediaKeysSessionPromise> promise);
64 76
65 // Returns the Decryptor associated with this CDM. May be NULL if no 77 // Returns the Decryptor associated with this CDM. May be NULL if no
66 // Decryptor is associated with the MediaKeys object. 78 // Decryptor is associated with the MediaKeys object.
67 // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor 79 // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor
68 // after WebContentDecryptionModule is freed. http://crbug.com/330324 80 // after WebContentDecryptionModule is freed. http://crbug.com/330324
69 media::Decryptor* GetDecryptor(); 81 media::Decryptor* GetDecryptor();
70 82
71 #if defined(OS_ANDROID) 83 #if defined(OS_ANDROID)
72 // Returns the CDM ID associated with the |media_keys_|. May be kInvalidCdmId 84 // Returns the CDM ID associated with the |media_keys_|. May be kInvalidCdmId
73 // if no CDM ID is associated. 85 // if no CDM ID is associated.
74 int GetCdmId() const; 86 int GetCdmId() const;
75 #endif 87 #endif
76 88
77 private: 89 private:
78 friend class base::RefCounted<CdmSessionAdapter>; 90 friend class base::RefCounted<CdmSessionAdapter>;
79 typedef std::map<uint32, WebContentDecryptionModuleSessionImpl*> SessionMap; 91 typedef std::map<std::string,
xhwang 2014/05/05 20:46:42 Since the key is now a string, we should use hash_
jrummell 2014/05/08 23:37:45 Done.
92 base::WeakPtr<WebContentDecryptionModuleSessionImpl> >
93 SessionMap;
80 94
81 ~CdmSessionAdapter(); 95 ~CdmSessionAdapter();
82 96
83 // Callbacks for firing session events. 97 // Callbacks for firing session events.
84 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); 98 void OnSessionMessage(const std::string& web_session_id,
85 void OnSessionMessage(uint32 session_id,
86 const std::vector<uint8>& message, 99 const std::vector<uint8>& message,
87 const std::string& destination_url); 100 const std::string& destination_url);
88 void OnSessionReady(uint32 session_id); 101 void OnSessionReady(const std::string& web_session_id);
89 void OnSessionClosed(uint32 session_id); 102 void OnSessionClosed(const std::string& web_session_id);
90 void OnSessionError(uint32 session_id, 103 void OnSessionError(const std::string& web_session_id,
91 media::MediaKeys::KeyError error_code, 104 const std::string& error_name,
92 uint32 system_code); 105 uint32 system_code,
106 const std::string& error_message);
93 107
94 // Helper function of the callbacks. 108 // Helper function of the callbacks.
95 WebContentDecryptionModuleSessionImpl* GetSession(uint32 session_id); 109 WebContentDecryptionModuleSessionImpl* GetSession(
96 110 const std::string& web_session_id);
97 // Session ID should be unique per renderer process for debugging purposes.
98 static uint32 next_session_id_;
99 111
100 scoped_ptr<media::MediaKeys> media_keys_; 112 scoped_ptr<media::MediaKeys> media_keys_;
101 113
102 SessionMap sessions_; 114 SessionMap sessions_;
103 115
104 #if defined(OS_ANDROID) 116 #if defined(OS_ANDROID)
105 int cdm_id_; 117 int cdm_id_;
106 #endif 118 #endif
107 119
108 // NOTE: Weak pointers must be invalidated before all other member variables. 120 // NOTE: Weak pointers must be invalidated before all other member variables.
109 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; 121 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_;
110 122
111 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); 123 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter);
112 }; 124 };
113 125
114 } // namespace content 126 } // namespace content
115 127
116 #endif // CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ 128 #endif // CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698