OLD | NEW |
---|---|
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 CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_ |
6 #define CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_ | 6 #define CONTENT_RENDERER_MEDIA_ANDROID_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" | |
9 #include "media/base/media_keys.h" | 14 #include "media/base/media_keys.h" |
10 | 15 |
11 class GURL; | 16 class GURL; |
12 | 17 |
13 namespace content { | 18 namespace content { |
14 | 19 |
15 class RendererMediaPlayerManager; | 20 class RendererMediaPlayerManager; |
16 | 21 |
17 // A MediaKeys proxy that wraps the EME part of RendererMediaPlayerManager. | 22 // A MediaKeys proxy that wraps the EME part of RendererMediaPlayerManager. |
18 // TODO(xhwang): Instead of accessing RendererMediaPlayerManager directly, let | 23 // TODO(xhwang): Instead of accessing RendererMediaPlayerManager directly, let |
19 // RendererMediaPlayerManager return a MediaKeys object that can be used by | 24 // RendererMediaPlayerManager return a MediaKeys object that can be used by |
20 // ProxyDecryptor directly. Then we can remove this class! | 25 // ProxyDecryptor directly. Then we can remove this class! |
21 class ProxyMediaKeys : public media::MediaKeys { | 26 class ProxyMediaKeys : public media::MediaKeys { |
22 public: | 27 public: |
23 static scoped_ptr<ProxyMediaKeys> Create( | 28 static scoped_ptr<ProxyMediaKeys> Create( |
24 const std::string& key_system, | 29 const std::string& key_system, |
25 const GURL& security_origin, | 30 const GURL& security_origin, |
26 RendererMediaPlayerManager* manager, | 31 RendererMediaPlayerManager* manager, |
27 const media::SessionCreatedCB& session_created_cb, | |
28 const media::SessionMessageCB& session_message_cb, | 32 const media::SessionMessageCB& session_message_cb, |
29 const media::SessionReadyCB& session_ready_cb, | 33 const media::SessionReadyCB& session_ready_cb, |
30 const media::SessionClosedCB& session_closed_cb, | 34 const media::SessionClosedCB& session_closed_cb, |
31 const media::SessionErrorCB& session_error_cb); | 35 const media::SessionErrorCB& session_error_cb); |
32 | 36 |
33 virtual ~ProxyMediaKeys(); | 37 virtual ~ProxyMediaKeys(); |
34 | 38 |
35 // MediaKeys implementation. | 39 // MediaKeys implementation. |
36 virtual bool CreateSession(uint32 session_id, | 40 virtual void CreateSession( |
37 const std::string& content_type, | 41 const std::string& init_data_type, |
38 const uint8* init_data, | 42 const uint8* init_data, |
39 int init_data_length) OVERRIDE; | 43 int init_data_length, |
40 virtual void LoadSession(uint32 session_id, | 44 SessionType session_type, |
41 const std::string& web_session_id) OVERRIDE; | 45 scoped_ptr<media::NewSessionCdmPromise> promise) OVERRIDE; |
42 virtual void UpdateSession(uint32 session_id, | 46 virtual void LoadSession( |
43 const uint8* response, | 47 const std::string& web_session_id, |
44 int response_length) OVERRIDE; | 48 scoped_ptr<media::NewSessionCdmPromise> promise) OVERRIDE; |
45 virtual void ReleaseSession(uint32 session_id) OVERRIDE; | 49 virtual void UpdateSession( |
50 const std::string& web_session_id, | |
51 const uint8* response, | |
52 int response_length, | |
53 scoped_ptr<media::SimpleCdmPromise> promise) OVERRIDE; | |
54 virtual void ReleaseSession( | |
55 const std::string& web_session_id, | |
56 scoped_ptr<media::SimpleCdmPromise> promise) OVERRIDE; | |
46 | 57 |
47 // Callbacks. | 58 // Callbacks. |
48 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); | 59 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); |
49 void OnSessionMessage(uint32 session_id, | 60 void OnSessionMessage(uint32 session_id, |
50 const std::vector<uint8>& message, | 61 const std::vector<uint8>& message, |
51 const GURL& destination_url); | 62 const GURL& destination_url); |
52 void OnSessionReady(uint32 session_id); | 63 void OnSessionReady(uint32 session_id); |
53 void OnSessionClosed(uint32 session_id); | 64 void OnSessionClosed(uint32 session_id); |
54 void OnSessionError(uint32 session_id, | 65 void OnSessionError(uint32 session_id, |
55 media::MediaKeys::KeyError error_code, | 66 media::MediaKeys::KeyError error_code, |
56 uint32 system_code); | 67 uint32 system_code); |
57 | 68 |
58 int GetCdmId() const; | 69 int GetCdmId() const; |
59 | 70 |
60 private: | 71 private: |
72 // The Android-specific code that handles sessions uses integer session ids | |
73 // (basically a reference id), but media::MediaKeys bases everything on | |
74 // web_session_id (a string representing the actual session id as generated | |
75 // by the CDM). SessionIdMap is used to map between the web_session_id and | |
76 // the session_id used by the Android-specific code. | |
77 typedef base::hash_map<std::string, uint32_t> SessionIdMap; | |
78 | |
79 // The following types keep track of Promises. The index is the | |
80 // Android-specific session_id, so that returning results can be matched to | |
81 // the corresponding promise. | |
82 typedef base::ScopedPtrHashMap<uint32_t, media::CdmPromise> PromiseMap; | |
83 | |
61 ProxyMediaKeys(RendererMediaPlayerManager* manager, | 84 ProxyMediaKeys(RendererMediaPlayerManager* manager, |
62 const media::SessionCreatedCB& session_created_cb, | |
63 const media::SessionMessageCB& session_message_cb, | 85 const media::SessionMessageCB& session_message_cb, |
64 const media::SessionReadyCB& session_ready_cb, | 86 const media::SessionReadyCB& session_ready_cb, |
65 const media::SessionClosedCB& session_closed_cb, | 87 const media::SessionClosedCB& session_closed_cb, |
66 const media::SessionErrorCB& session_error_cb); | 88 const media::SessionErrorCB& session_error_cb); |
67 | 89 |
68 void InitializeCdm(const std::string& key_system, | 90 void InitializeCdm(const std::string& key_system, |
69 const GURL& security_origin); | 91 const GURL& security_origin); |
70 | 92 |
93 // These functions keep track of Android-specific session_ids <-> | |
94 // web_session_ids mappings. | |
95 // TODO(jrummell): Remove this once the Android-specific code changes to | |
96 // support string web session ids. | |
97 uint32_t CreateSessionId() const; | |
98 void AssignWebSessionId(const uint32_t session_id, | |
xhwang
2014/05/29 23:44:38
no need to use "const" for a integer that's passed
jrummell
2014/05/30 18:04:25
Done.
| |
99 const std::string& web_session_id); | |
100 uint32_t LookupSessionId(const std::string& web_session_id) const; | |
101 std::string LookupWebSessionId(const uint32_t session_id) const; | |
xhwang
2014/05/29 23:44:38
ditto
jrummell
2014/05/30 18:04:25
Done.
| |
102 void DropWebSessionId(const std::string& web_session_id); | |
103 | |
104 // Helper function to keep track of promises. Adding takes ownership of the | |
105 // promise, transferred back to caller on take. | |
106 void SavePromise(const uint32_t session_id, | |
xhwang
2014/05/29 23:44:38
ditto
jrummell
2014/05/30 18:04:25
Done.
| |
107 scoped_ptr<media::CdmPromise> promise); | |
108 scoped_ptr<media::CdmPromise> TakePromise(const uint32_t session_id); | |
109 | |
71 // CDM ID should be unique per renderer process. | 110 // CDM ID should be unique per renderer process. |
72 // TODO(xhwang): Use uint32 to prevent undefined overflow behavior. | 111 // TODO(xhwang): Use uint32 to prevent undefined overflow behavior. |
73 static int next_cdm_id_; | 112 static int next_cdm_id_; |
74 | 113 |
75 RendererMediaPlayerManager* manager_; | 114 RendererMediaPlayerManager* manager_; |
76 int cdm_id_; | 115 int cdm_id_; |
77 media::SessionCreatedCB session_created_cb_; | |
78 media::SessionMessageCB session_message_cb_; | 116 media::SessionMessageCB session_message_cb_; |
79 media::SessionReadyCB session_ready_cb_; | 117 media::SessionReadyCB session_ready_cb_; |
80 media::SessionClosedCB session_closed_cb_; | 118 media::SessionClosedCB session_closed_cb_; |
81 media::SessionErrorCB session_error_cb_; | 119 media::SessionErrorCB session_error_cb_; |
82 | 120 |
121 // Android-specific. See comment above CreateSessionId(). | |
122 uint32_t next_session_id_; | |
123 SessionIdMap web_session_to_session_id_map_; | |
124 | |
125 // Keep track of outstanding promises. This map owns the promise object. | |
126 PromiseMap session_id_to_promise_map_; | |
127 | |
83 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys); | 128 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys); |
84 }; | 129 }; |
85 | 130 |
86 } // namespace content | 131 } // namespace content |
87 | 132 |
88 #endif // CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_ | 133 #endif // CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_ |
OLD | NEW |