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

Side by Side Diff: content/renderer/media/crypto/proxy_media_keys.h

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: One more trybot issue Created 6 years, 6 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_CRYPTO_PROXY_MEDIA_KEYS_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_
6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_ 6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_
7 7
8 #include <map>
9 #include <string>
10
8 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "media/base/cdm_promise.h"
9 #include "media/base/media_keys.h" 15 #include "media/base/media_keys.h"
10 16
11 class GURL; 17 class GURL;
12 18
13 namespace content { 19 namespace content {
14 20
15 class RendererCdmManager; 21 class RendererCdmManager;
16 22
17 // A MediaKeys proxy that wraps the EME part of RendererCdmManager. 23 // A MediaKeys proxy that wraps the EME part of RendererCdmManager.
18 class ProxyMediaKeys : public media::MediaKeys { 24 class ProxyMediaKeys : public media::MediaKeys {
19 public: 25 public:
20 static scoped_ptr<ProxyMediaKeys> Create( 26 static scoped_ptr<ProxyMediaKeys> Create(
21 const std::string& key_system, 27 const std::string& key_system,
22 const GURL& security_origin, 28 const GURL& security_origin,
23 RendererCdmManager* manager, 29 RendererCdmManager* manager,
24 const media::SessionCreatedCB& session_created_cb,
25 const media::SessionMessageCB& session_message_cb, 30 const media::SessionMessageCB& session_message_cb,
26 const media::SessionReadyCB& session_ready_cb, 31 const media::SessionReadyCB& session_ready_cb,
27 const media::SessionClosedCB& session_closed_cb, 32 const media::SessionClosedCB& session_closed_cb,
28 const media::SessionErrorCB& session_error_cb); 33 const media::SessionErrorCB& session_error_cb);
29 34
30 virtual ~ProxyMediaKeys(); 35 virtual ~ProxyMediaKeys();
31 36
32 // MediaKeys implementation. 37 // MediaKeys implementation.
33 virtual bool CreateSession(uint32 session_id, 38 virtual void CreateSession(
34 const std::string& content_type, 39 const std::string& init_data_type,
35 const uint8* init_data, 40 const uint8* init_data,
36 int init_data_length) OVERRIDE; 41 int init_data_length,
37 virtual void LoadSession(uint32 session_id, 42 SessionType session_type,
38 const std::string& web_session_id) OVERRIDE; 43 scoped_ptr<media::NewSessionCdmPromise> promise) OVERRIDE;
39 virtual void UpdateSession(uint32 session_id, 44 virtual void LoadSession(
40 const uint8* response, 45 const std::string& web_session_id,
41 int response_length) OVERRIDE; 46 scoped_ptr<media::NewSessionCdmPromise> promise) OVERRIDE;
42 virtual void ReleaseSession(uint32 session_id) OVERRIDE; 47 virtual void UpdateSession(
48 const std::string& web_session_id,
49 const uint8* response,
50 int response_length,
51 scoped_ptr<media::SimpleCdmPromise> promise) OVERRIDE;
52 virtual void ReleaseSession(
53 const std::string& web_session_id,
54 scoped_ptr<media::SimpleCdmPromise> promise) OVERRIDE;
43 55
44 // Callbacks. 56 // Callbacks.
45 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); 57 void OnSessionCreated(uint32 session_id, const std::string& web_session_id);
46 void OnSessionMessage(uint32 session_id, 58 void OnSessionMessage(uint32 session_id,
47 const std::vector<uint8>& message, 59 const std::vector<uint8>& message,
48 const GURL& destination_url); 60 const GURL& destination_url);
49 void OnSessionReady(uint32 session_id); 61 void OnSessionReady(uint32 session_id);
50 void OnSessionClosed(uint32 session_id); 62 void OnSessionClosed(uint32 session_id);
51 void OnSessionError(uint32 session_id, 63 void OnSessionError(uint32 session_id,
52 media::MediaKeys::KeyError error_code, 64 media::MediaKeys::KeyError error_code,
53 uint32 system_code); 65 uint32 system_code);
54 66
55 int GetCdmId() const; 67 int GetCdmId() const;
56 68
57 private: 69 private:
70 // The Android-specific code that handles sessions uses integer session ids
71 // (basically a reference id), but media::MediaKeys bases everything on
72 // web_session_id (a string representing the actual session id as generated
73 // by the CDM). SessionIdMap is used to map between the web_session_id and
74 // the session_id used by the Android-specific code.
75 typedef base::hash_map<std::string, uint32_t> SessionIdMap;
76
77 // The following types keep track of Promises. The index is the
78 // Android-specific session_id, so that returning results can be matched to
79 // the corresponding promise.
80 typedef base::ScopedPtrHashMap<uint32_t, media::CdmPromise> PromiseMap;
81
58 ProxyMediaKeys(RendererCdmManager* manager, 82 ProxyMediaKeys(RendererCdmManager* manager,
59 const media::SessionCreatedCB& session_created_cb,
60 const media::SessionMessageCB& session_message_cb, 83 const media::SessionMessageCB& session_message_cb,
61 const media::SessionReadyCB& session_ready_cb, 84 const media::SessionReadyCB& session_ready_cb,
62 const media::SessionClosedCB& session_closed_cb, 85 const media::SessionClosedCB& session_closed_cb,
63 const media::SessionErrorCB& session_error_cb); 86 const media::SessionErrorCB& session_error_cb);
64 87
65 void InitializeCdm(const std::string& key_system, 88 void InitializeCdm(const std::string& key_system,
66 const GURL& security_origin); 89 const GURL& security_origin);
67 90
91 // These functions keep track of Android-specific session_ids <->
92 // web_session_ids mappings.
93 // TODO(jrummell): Remove this once the Android-specific code changes to
94 // support string web session ids.
95 uint32_t CreateSessionId();
96 void AssignWebSessionId(uint32_t session_id,
97 const std::string& web_session_id);
98 uint32_t LookupSessionId(const std::string& web_session_id) const;
99 std::string LookupWebSessionId(uint32_t session_id) const;
100 void DropWebSessionId(const std::string& web_session_id);
101
102 // Helper function to keep track of promises. Adding takes ownership of the
103 // promise, transferred back to caller on take.
104 void SavePromise(uint32_t session_id, scoped_ptr<media::CdmPromise> promise);
105 scoped_ptr<media::CdmPromise> TakePromise(uint32_t session_id);
106
68 RendererCdmManager* manager_; 107 RendererCdmManager* manager_;
69 int cdm_id_; 108 int cdm_id_;
70 109
71 media::SessionCreatedCB session_created_cb_;
72 media::SessionMessageCB session_message_cb_; 110 media::SessionMessageCB session_message_cb_;
73 media::SessionReadyCB session_ready_cb_; 111 media::SessionReadyCB session_ready_cb_;
74 media::SessionClosedCB session_closed_cb_; 112 media::SessionClosedCB session_closed_cb_;
75 media::SessionErrorCB session_error_cb_; 113 media::SessionErrorCB session_error_cb_;
76 114
115 // Android-specific. See comment above CreateSessionId().
116 uint32_t next_session_id_;
117 SessionIdMap web_session_to_session_id_map_;
118
119 // Keep track of outstanding promises. This map owns the promise object.
120 PromiseMap session_id_to_promise_map_;
121
77 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys); 122 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys);
78 }; 123 };
79 124
80 } // namespace content 125 } // namespace content
81 126
82 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_ 127 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_MEDIA_KEYS_H_
OLDNEW
« no previous file with comments | « content/renderer/media/crypto/proxy_decryptor.cc ('k') | content/renderer/media/crypto/proxy_media_keys.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698