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" |
| 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 RendererMediaPlayerManager; | 21 class RendererMediaPlayerManager; |
16 | 22 |
17 // A MediaKeys proxy that wraps the EME part of RendererMediaPlayerManager. | 23 // A MediaKeys proxy that wraps the EME part of RendererMediaPlayerManager. |
18 // TODO(xhwang): Instead of accessing RendererMediaPlayerManager directly, let | 24 // TODO(xhwang): Instead of accessing RendererMediaPlayerManager directly, let |
19 // RendererMediaPlayerManager return a MediaKeys object that can be used by | 25 // RendererMediaPlayerManager return a MediaKeys object that can be used by |
20 // ProxyDecryptor directly. Then we can remove this class! | 26 // ProxyDecryptor directly. Then we can remove this class! |
21 class ProxyMediaKeys : public media::MediaKeys { | 27 class ProxyMediaKeys : public media::MediaKeys { |
22 public: | 28 public: |
23 static scoped_ptr<ProxyMediaKeys> Create( | 29 static scoped_ptr<ProxyMediaKeys> Create( |
24 const std::string& key_system, | 30 const std::string& key_system, |
25 const GURL& security_origin, | 31 const GURL& security_origin, |
26 RendererMediaPlayerManager* manager, | 32 RendererMediaPlayerManager* manager, |
27 const media::SessionCreatedCB& session_created_cb, | |
28 const media::SessionMessageCB& session_message_cb, | 33 const media::SessionMessageCB& session_message_cb, |
29 const media::SessionReadyCB& session_ready_cb, | 34 const media::SessionReadyCB& session_ready_cb, |
30 const media::SessionClosedCB& session_closed_cb, | 35 const media::SessionClosedCB& session_closed_cb, |
31 const media::SessionErrorCB& session_error_cb); | 36 const media::SessionErrorCB& session_error_cb); |
32 | 37 |
33 virtual ~ProxyMediaKeys(); | 38 virtual ~ProxyMediaKeys(); |
34 | 39 |
35 // MediaKeys implementation. | 40 // MediaKeys implementation. |
36 virtual bool CreateSession(uint32 session_id, | 41 virtual void CreateSession( |
37 const std::string& content_type, | 42 const std::string& init_data_type, |
38 const uint8* init_data, | 43 const uint8* init_data, |
39 int init_data_length) OVERRIDE; | 44 int init_data_length, |
40 virtual void LoadSession(uint32 session_id, | 45 SessionType session_type, |
41 const std::string& web_session_id) OVERRIDE; | 46 scoped_ptr<media::NewSessionCdmPromise> promise) OVERRIDE; |
42 virtual void UpdateSession(uint32 session_id, | 47 virtual void LoadSession( |
43 const uint8* response, | 48 const std::string& web_session_id, |
44 int response_length) OVERRIDE; | 49 scoped_ptr<media::NewSessionCdmPromise> promise) OVERRIDE; |
45 virtual void ReleaseSession(uint32 session_id) OVERRIDE; | 50 virtual void UpdateSession( |
| 51 const std::string& web_session_id, |
| 52 const uint8* response, |
| 53 int response_length, |
| 54 scoped_ptr<media::SimpleCdmPromise> promise) OVERRIDE; |
| 55 virtual void ReleaseSession( |
| 56 const std::string& web_session_id, |
| 57 scoped_ptr<media::SimpleCdmPromise> promise) OVERRIDE; |
46 | 58 |
47 // Callbacks. | 59 // Callbacks. |
48 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); | 60 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); |
49 void OnSessionMessage(uint32 session_id, | 61 void OnSessionMessage(uint32 session_id, |
50 const std::vector<uint8>& message, | 62 const std::vector<uint8>& message, |
51 const GURL& destination_url); | 63 const GURL& destination_url); |
52 void OnSessionReady(uint32 session_id); | 64 void OnSessionReady(uint32 session_id); |
53 void OnSessionClosed(uint32 session_id); | 65 void OnSessionClosed(uint32 session_id); |
54 void OnSessionError(uint32 session_id, | 66 void OnSessionError(uint32 session_id, |
55 media::MediaKeys::KeyError error_code, | 67 media::MediaKeys::KeyError error_code, |
56 uint32 system_code); | 68 uint32 system_code); |
57 | 69 |
58 int GetCdmId() const; | 70 int GetCdmId() const; |
59 | 71 |
60 private: | 72 private: |
| 73 // The Android-specific code that handles sessions uses integer session ids |
| 74 // (basically a reference id), but media::MediaKeys bases everything on |
| 75 // web_session_id (a string representing the actual session id as generated |
| 76 // by the CDM). SessionIdMap is used to map between the web_session_id and |
| 77 // the session_id used by the Android-specific code. |
| 78 typedef base::hash_map<std::string, uint32_t> SessionIdMap; |
| 79 |
| 80 // The following types keep track of Promises. The index is the |
| 81 // Android-specific session_id, so that returning results can be matched to |
| 82 // the corresponding promise. |
| 83 typedef base::ScopedPtrHashMap<uint32_t, media::CdmPromise> PromiseMap; |
| 84 |
61 ProxyMediaKeys(RendererMediaPlayerManager* manager, | 85 ProxyMediaKeys(RendererMediaPlayerManager* manager, |
62 const media::SessionCreatedCB& session_created_cb, | |
63 const media::SessionMessageCB& session_message_cb, | 86 const media::SessionMessageCB& session_message_cb, |
64 const media::SessionReadyCB& session_ready_cb, | 87 const media::SessionReadyCB& session_ready_cb, |
65 const media::SessionClosedCB& session_closed_cb, | 88 const media::SessionClosedCB& session_closed_cb, |
66 const media::SessionErrorCB& session_error_cb); | 89 const media::SessionErrorCB& session_error_cb); |
67 | 90 |
68 void InitializeCdm(const std::string& key_system, | 91 void InitializeCdm(const std::string& key_system, |
69 const GURL& security_origin); | 92 const GURL& security_origin); |
70 | 93 |
| 94 // These functions keep track of Android-specific session_ids <-> |
| 95 // web_session_ids mappings. |
| 96 // TODO(jrummell): Remove this once the Android-specific code changes to |
| 97 // support string web session ids. |
| 98 uint32_t CreateSessionId(); |
| 99 void AssignWebSessionId(uint32_t session_id, |
| 100 const std::string& web_session_id); |
| 101 uint32_t LookupSessionId(const std::string& web_session_id) const; |
| 102 std::string LookupWebSessionId(uint32_t session_id) const; |
| 103 void DropWebSessionId(const std::string& web_session_id); |
| 104 |
| 105 // Helper function to keep track of promises. Adding takes ownership of the |
| 106 // promise, transferred back to caller on take. |
| 107 void SavePromise(uint32_t session_id, scoped_ptr<media::CdmPromise> promise); |
| 108 scoped_ptr<media::CdmPromise> TakePromise(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 |