Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 | |
| 18 class MEDIA_EXPORT MediaDrmProxy : public BrowserCdm { | |
| 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 /* | |
| 79 // Internal callbacks | |
|
Tima Vaisburd
2015/09/14 20:42:33
It is possible to relay the callbacks inside the M
| |
| 80 void OnSessionMessage(const std::string& session_id, | |
| 81 MediaKeys::MessageType message_type, | |
| 82 const std::vector<uint8>& message, | |
| 83 const GURL& legacy_destination_url); | |
| 84 void OnSessionClosed(const std::string& session_id); | |
| 85 void OnLegacySessionError(const std::string& session_id, | |
| 86 MediaKeys::Exception exception_code, | |
| 87 uint32 system_code, | |
| 88 const std::string& error_message); | |
| 89 void OnSessionKeysChange(const std::string& session_id, | |
| 90 bool has_additional_usable_key, | |
| 91 CdmKeysInfo keys_info); | |
| 92 void OnSessionExpirationUpdate(const std::string& session_id, | |
| 93 const base::Time& new_expiry_time); | |
| 94 */ | |
| 95 | |
| 96 // Data. | |
| 97 | |
| 98 // Object for posting tasks on UI thread. | |
| 99 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | |
| 100 | |
| 101 // MediaDrmBridge that will be accessed on the Media thread. | |
| 102 scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> media_drm_bridge_; | |
| 103 | |
| 104 // The key system. | |
| 105 std::string key_system_; | |
| 106 | |
| 107 // Required security level. Only makes sense for Widevine system. | |
| 108 MediaDrmBridge::SecurityLevel widevine_security_level_; | |
| 109 | |
| 110 // Callbacks received as parameters, to be called on UI thread | |
| 111 SessionMessageCB session_message_cb_; | |
| 112 SessionClosedCB session_closed_cb_; | |
| 113 LegacySessionErrorCB legacy_session_error_cb_; | |
| 114 SessionKeysChangeCB session_keys_change_cb_; | |
| 115 SessionExpirationUpdateCB session_expiration_update_cb_; | |
| 116 | |
| 117 /* | |
| 118 // Internal callbacks passed to MediaDrmBridge, called on media thread. | |
| 119 SessionMessageCB internal_session_message_cb_; | |
| 120 SessionClosedCB internal_session_closed_cb_; | |
| 121 LegacySessionErrorCB internal_legacy_session_error_cb_; | |
| 122 SessionKeysChangeCB internal_session_keys_change_cb_; | |
| 123 SessionExpirationUpdateCB internal_session_expiration_update_cb_; | |
| 124 */ | |
| 125 | |
| 126 base::WeakPtr<MediaDrmProxy> media_weak_this_; | |
| 127 | |
| 128 // NOTE: Weak pointers must be invalidated before all other member variables. | |
| 129 base::WeakPtrFactory<MediaDrmProxy> media_weak_factory_; | |
| 130 | |
| 131 DISALLOW_COPY_AND_ASSIGN(MediaDrmProxy); | |
| 132 }; | |
| 133 | |
| 134 } // namespace media | |
| 135 | |
| 136 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_PROXY_H_ | |
| OLD | NEW |