Chromium Code Reviews| 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" |
| 9 #include "media/base/media_keys.h" | 12 #include "media/base/media_keys.h" |
| 10 | 13 |
| 11 class GURL; | 14 class GURL; |
| 12 | 15 |
| 13 namespace content { | 16 namespace content { |
| 14 | 17 |
| 15 class RendererMediaPlayerManager; | 18 class RendererMediaPlayerManager; |
| 16 | 19 |
| 17 // A MediaKeys proxy that wraps the EME part of RendererMediaPlayerManager. | 20 // A MediaKeys proxy that wraps the EME part of RendererMediaPlayerManager. |
| 18 // TODO(xhwang): Instead of accessing RendererMediaPlayerManager directly, let | 21 // TODO(xhwang): Instead of accessing RendererMediaPlayerManager directly, let |
| 19 // RendererMediaPlayerManager return a MediaKeys object that can be used by | 22 // RendererMediaPlayerManager return a MediaKeys object that can be used by |
| 20 // ProxyDecryptor directly. Then we can remove this class! | 23 // ProxyDecryptor directly. Then we can remove this class! |
| 21 class ProxyMediaKeys : public media::MediaKeys { | 24 class ProxyMediaKeys : public media::MediaKeys { |
| 22 public: | 25 public: |
| 23 static scoped_ptr<ProxyMediaKeys> Create( | 26 static scoped_ptr<ProxyMediaKeys> Create( |
| 24 const std::string& key_system, | 27 const std::string& key_system, |
| 25 const GURL& security_origin, | 28 const GURL& security_origin, |
| 26 RendererMediaPlayerManager* manager, | 29 RendererMediaPlayerManager* manager, |
| 27 const media::SessionCreatedCB& session_created_cb, | |
| 28 const media::SessionMessageCB& session_message_cb, | 30 const media::SessionMessageCB& session_message_cb, |
| 29 const media::SessionReadyCB& session_ready_cb, | 31 const media::SessionReadyCB& session_ready_cb, |
| 30 const media::SessionClosedCB& session_closed_cb, | 32 const media::SessionClosedCB& session_closed_cb, |
| 31 const media::SessionErrorCB& session_error_cb); | 33 const media::SessionErrorCB& session_error_cb); |
| 32 | 34 |
| 33 virtual ~ProxyMediaKeys(); | 35 virtual ~ProxyMediaKeys(); |
| 34 | 36 |
| 35 // MediaKeys implementation. | 37 // MediaKeys implementation. |
| 36 virtual bool CreateSession(uint32 session_id, | 38 virtual void CreateSession( |
| 37 const std::string& content_type, | 39 const std::string& init_data_type, |
| 38 const uint8* init_data, | 40 const uint8* init_data, |
| 39 int init_data_length) OVERRIDE; | 41 int init_data_length, |
| 40 virtual void LoadSession(uint32 session_id, | 42 SessionType session_type, |
| 41 const std::string& web_session_id) OVERRIDE; | 43 scoped_ptr<media::MediaKeysSessionPromise> promise) OVERRIDE; |
|
xhwang
2014/05/05 20:46:42
Now "cdm" is the standard term in chromium and Med
| |
| 42 virtual void UpdateSession(uint32 session_id, | 44 virtual void LoadSession( |
| 43 const uint8* response, | 45 const std::string& web_session_id, |
| 44 int response_length) OVERRIDE; | 46 scoped_ptr<media::MediaKeysSessionPromise> promise) OVERRIDE; |
| 45 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::MediaKeysSessionPromise> promise) OVERRIDE; | |
| 52 virtual void ReleaseSession( | |
| 53 const std::string& web_session_id, | |
| 54 scoped_ptr<media::MediaKeysSessionPromise> promise) OVERRIDE; | |
| 46 | 55 |
| 47 // Callbacks. | 56 // Callbacks. |
| 48 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); | 57 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); |
| 49 void OnSessionMessage(uint32 session_id, | 58 void OnSessionMessage(uint32 session_id, |
| 50 const std::vector<uint8>& message, | 59 const std::vector<uint8>& message, |
| 51 const std::string& destination_url); | 60 const std::string& destination_url); |
| 52 void OnSessionReady(uint32 session_id); | 61 void OnSessionReady(uint32 session_id); |
| 53 void OnSessionClosed(uint32 session_id); | 62 void OnSessionClosed(uint32 session_id); |
| 54 void OnSessionError(uint32 session_id, | 63 void OnSessionError(uint32 session_id, |
| 55 media::MediaKeys::KeyError error_code, | 64 media::MediaKeys::KeyError error_code, |
| 56 uint32 system_code); | 65 uint32 system_code); |
| 57 | 66 |
| 58 int GetCdmId() const; | 67 int GetCdmId() const; |
| 59 | 68 |
| 60 private: | 69 private: |
| 61 ProxyMediaKeys(RendererMediaPlayerManager* manager, | 70 ProxyMediaKeys(RendererMediaPlayerManager* manager, |
| 62 const media::SessionCreatedCB& session_created_cb, | |
| 63 const media::SessionMessageCB& session_message_cb, | 71 const media::SessionMessageCB& session_message_cb, |
| 64 const media::SessionReadyCB& session_ready_cb, | 72 const media::SessionReadyCB& session_ready_cb, |
| 65 const media::SessionClosedCB& session_closed_cb, | 73 const media::SessionClosedCB& session_closed_cb, |
| 66 const media::SessionErrorCB& session_error_cb); | 74 const media::SessionErrorCB& session_error_cb); |
| 67 | 75 |
| 68 void InitializeCdm(const std::string& key_system, | 76 void InitializeCdm(const std::string& key_system, |
| 69 const GURL& security_origin); | 77 const GURL& security_origin); |
| 70 | 78 |
| 79 // Helper functions to keep track of session_ids <-> web_session_ids. | |
|
xhwang
2014/05/05 20:46:42
Please add a comment that we are still keeping Ses
jrummell
2014/05/08 23:37:45
Done.
| |
| 80 uint32_t CreateSessionId(); | |
| 81 void AssignWebSessionId(uint32_t session_id, | |
| 82 const std::string& web_session_id); | |
| 83 uint32_t LookupSessionId(const std::string& web_session_id); | |
| 84 std::string LookupWebSessionId(uint32_t session_id); | |
| 85 void DropWebSessionId(std::string web_session_id); | |
| 86 | |
| 87 // Helper function to keep track of promises. Adding takes ownership of the | |
| 88 // promise, transferred back to caller on lookup. | |
| 89 void AddPromise(uint32_t session_id, | |
|
xhwang
2014/05/05 20:46:42
To be consistent to CdmSessionAdapter, how about R
jrummell
2014/05/08 23:37:45
Done.
| |
| 90 scoped_ptr<media::MediaKeysSessionPromise> promise); | |
| 91 scoped_ptr<media::MediaKeysSessionPromise> LookupPromise(uint32_t session_id); | |
|
xhwang
2014/05/05 20:46:42
"Lookup" usually is a const operation, but this is
jrummell
2014/05/08 23:37:45
Done.
| |
| 92 | |
| 71 // CDM ID should be unique per renderer process. | 93 // CDM ID should be unique per renderer process. |
| 72 // TODO(xhwang): Use uint32 to prevent undefined overflow behavior. | 94 // TODO(xhwang): Use uint32 to prevent undefined overflow behavior. |
| 73 static int next_cdm_id_; | 95 static int next_cdm_id_; |
| 74 | 96 |
| 75 RendererMediaPlayerManager* manager_; | 97 RendererMediaPlayerManager* manager_; |
| 76 int cdm_id_; | 98 int cdm_id_; |
| 77 media::SessionCreatedCB session_created_cb_; | |
| 78 media::SessionMessageCB session_message_cb_; | 99 media::SessionMessageCB session_message_cb_; |
| 79 media::SessionReadyCB session_ready_cb_; | 100 media::SessionReadyCB session_ready_cb_; |
| 80 media::SessionClosedCB session_closed_cb_; | 101 media::SessionClosedCB session_closed_cb_; |
| 81 media::SessionErrorCB session_error_cb_; | 102 media::SessionErrorCB session_error_cb_; |
| 82 | 103 |
| 104 uint32_t next_session_id_; | |
| 105 std::map<std::string, uint32_t> web_session_to_session_id_map_; | |
|
xhwang
2014/05/05 20:46:42
Since we use string as the key, use hash_map for b
jrummell
2014/05/08 23:37:45
Done.
| |
| 106 std::map<uint32_t, media::MediaKeysSessionPromise*> | |
| 107 session_id_to_promise_map_; | |
|
xhwang
2014/05/05 20:46:42
Please comment that this map owns the promises.
jrummell
2014/05/08 23:37:45
Done.
| |
| 108 | |
| 83 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys); | 109 DISALLOW_COPY_AND_ASSIGN(ProxyMediaKeys); |
| 84 }; | 110 }; |
| 85 | 111 |
| 86 } // namespace content | 112 } // namespace content |
| 87 | 113 |
| 88 #endif // CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_ | 114 #endif // CONTENT_RENDERER_MEDIA_ANDROID_PROXY_MEDIA_KEYS_H_ |
| OLD | NEW |