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