Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_DRM_PROXY_H_ | |
| 6 #define MEDIA_BASE_ANDROID_MEDIA_DRM_PROXY_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "media/base/android/media_drm_bridge.h" | |
| 13 #include "media/base/browser_cdm.h" | |
| 14 | |
| 15 namespace media { | |
| 16 | |
| 17 // This class delegates MediaDrmBridge calls onto the Media thread | |
|
ddorwin
2015/09/16 20:42:21
This is a lot of duplicate code and extra function
Tima Vaisburd
2015/09/18 00:41:38
I tried a different approach, where only the callb
| |
| 18 class MEDIA_EXPORT MediaDrmProxy : public BrowserCdm { | |
|
ddorwin
2015/09/16 20:42:21
"Proxy" isn't very descriptive. (We've regretted u
| |
| 19 public: | |
| 20 ~MediaDrmProxy() override; | |
| 21 void DeleteOnCorrectThread() override; | |
| 22 | |
| 23 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL | |
| 24 // pointer otherwise. | |
| 25 // TODO(xhwang): Is it okay not to update session expiration info? | |
| 26 static scoped_ptr<MediaDrmProxy, BrowserCdmDeleter> Create( | |
| 27 const std::string& key_system, | |
| 28 MediaDrmBridge::SecurityLevel widevine_security_level, | |
| 29 const SessionMessageCB& session_message_cb, | |
| 30 const SessionClosedCB& session_closed_cb, | |
| 31 const LegacySessionErrorCB& legacy_session_error_cb, | |
| 32 const SessionKeysChangeCB& session_keys_change_cb, | |
| 33 const SessionExpirationUpdateCB& session_expiration_update_cb); | |
| 34 | |
| 35 // MediaKeys (via BrowserCdm) implementation. | |
| 36 | |
| 37 void SetServerCertificate( | |
| 38 const std::vector<uint8_t>& certificate, | |
| 39 scoped_ptr<media::SimpleCdmPromise> promise) override; | |
| 40 void CreateSessionAndGenerateRequest( | |
| 41 SessionType session_type, | |
| 42 media::EmeInitDataType init_data_type, | |
| 43 const std::vector<uint8_t>& init_data, | |
| 44 scoped_ptr<media::NewSessionCdmPromise> promise) override; | |
| 45 void LoadSession(SessionType session_type, | |
| 46 const std::string& session_id, | |
| 47 scoped_ptr<media::NewSessionCdmPromise> promise) override; | |
| 48 void UpdateSession(const std::string& session_id, | |
| 49 const std::vector<uint8_t>& response, | |
| 50 scoped_ptr<media::SimpleCdmPromise> promise) override; | |
| 51 void CloseSession(const std::string& session_id, | |
| 52 scoped_ptr<media::SimpleCdmPromise> promise) override; | |
| 53 void RemoveSession(const std::string& session_id, | |
| 54 scoped_ptr<media::SimpleCdmPromise> promise) override; | |
| 55 CdmContext* GetCdmContext() override; | |
| 56 | |
| 57 // PlayerTracker (via BrowserCdm) implementation. | |
| 58 | |
| 59 int RegisterPlayer(const base::Closure& new_key_cb, | |
| 60 const base::Closure& cdm_unset_cb) override; | |
| 61 void UnregisterPlayer(int registration_id) override; | |
| 62 | |
| 63 // Accessor for MediaDrmBridge | |
| 64 MediaDrmBridge* GetDrmBridge(); | |
| 65 | |
| 66 private: | |
| 67 MediaDrmProxy(const std::string& key_system, | |
| 68 MediaDrmBridge::SecurityLevel widevine_security_level, | |
| 69 const SessionMessageCB& session_message_cb, | |
| 70 const SessionClosedCB& session_closed_cb, | |
| 71 const LegacySessionErrorCB& legacy_session_error_cb, | |
| 72 const SessionKeysChangeCB& session_keys_change_cb, | |
| 73 const SessionExpirationUpdateCB& session_expiration_update_cb); | |
| 74 | |
| 75 // Helper method to create MediaDrmBridge on the Media thread. | |
| 76 void Initialize(); | |
| 77 | |
| 78 // Internal callbacks. | |
| 79 // We need to preserve the order of messages we send to the render process. | |
| 80 // Since we post the promise-related callbacks first from UI to Media thread | |
| 81 // and then back to UI thread, we need to do the same with session-related | |
| 82 // callbacks, too. | |
| 83 // We do this hopping with the promise-related callbacks to avoid a mutex in | |
| 84 // CdmPromiseAdapter, otherwise we could keep all callbacks on UI thread. | |
| 85 | |
| 86 void OnSessionMessage(const std::string& session_id, | |
| 87 MediaKeys::MessageType message_type, | |
| 88 const std::vector<uint8>& message, | |
| 89 const GURL& legacy_destination_url); | |
| 90 void OnSessionClosed(const std::string& session_id); | |
| 91 void OnLegacySessionError(const std::string& session_id, | |
| 92 MediaKeys::Exception exception_code, | |
| 93 uint32 system_code, | |
| 94 const std::string& error_message); | |
| 95 void OnSessionKeysChange(const std::string& session_id, | |
| 96 bool has_additional_usable_key, | |
| 97 CdmKeysInfo keys_info); | |
| 98 void OnSessionExpirationUpdate(const std::string& session_id, | |
| 99 const base::Time& new_expiry_time); | |
| 100 | |
| 101 // Data. | |
| 102 | |
| 103 // Object for posting tasks on UI thread. | |
| 104 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | |
| 105 | |
| 106 // MediaDrmBridge that will be accessed on the Media thread. | |
| 107 scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> media_drm_bridge_; | |
| 108 | |
| 109 // The key system. | |
| 110 const std::string key_system_; | |
| 111 | |
| 112 // Required security level. Only makes sense for Widevine system. | |
| 113 const MediaDrmBridge::SecurityLevel widevine_security_level_; | |
| 114 | |
| 115 // Callbacks received as parameters, to be called on UI thread | |
| 116 SessionMessageCB session_message_cb_; | |
| 117 SessionClosedCB session_closed_cb_; | |
| 118 LegacySessionErrorCB legacy_session_error_cb_; | |
| 119 SessionKeysChangeCB session_keys_change_cb_; | |
| 120 SessionExpirationUpdateCB session_expiration_update_cb_; | |
| 121 | |
| 122 // Internal callbacks passed to MediaDrmBridge, called on media thread. | |
| 123 SessionMessageCB internal_session_message_cb_; | |
| 124 SessionClosedCB internal_session_closed_cb_; | |
| 125 LegacySessionErrorCB internal_legacy_session_error_cb_; | |
| 126 SessionKeysChangeCB internal_session_keys_change_cb_; | |
| 127 SessionExpirationUpdateCB internal_session_expiration_update_cb_; | |
| 128 | |
| 129 base::WeakPtr<MediaDrmProxy> media_weak_this_; | |
| 130 | |
| 131 // NOTE: Weak pointers must be invalidated before all other member variables. | |
| 132 base::WeakPtrFactory<MediaDrmProxy> media_weak_factory_; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(MediaDrmProxy); | |
| 135 }; | |
| 136 | |
| 137 } // namespace media | |
| 138 | |
| 139 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_PROXY_H_ | |
| OLD | NEW |