Index: media/base/android/media_drm_proxy.h |
diff --git a/media/base/android/media_drm_proxy.h b/media/base/android/media_drm_proxy.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..35db3a8cea6df7864b5857d724766b34dda562cd |
--- /dev/null |
+++ b/media/base/android/media_drm_proxy.h |
@@ -0,0 +1,139 @@ |
+// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_BASE_ANDROID_MEDIA_DRM_PROXY_H_ |
+#define MEDIA_BASE_ANDROID_MEDIA_DRM_PROXY_H_ |
+ |
+#include <string> |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "media/base/android/media_drm_bridge.h" |
+#include "media/base/browser_cdm.h" |
+ |
+namespace media { |
+ |
+// 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
|
+class MEDIA_EXPORT MediaDrmProxy : public BrowserCdm { |
ddorwin
2015/09/16 20:42:21
"Proxy" isn't very descriptive. (We've regretted u
|
+ public: |
+ ~MediaDrmProxy() override; |
+ void DeleteOnCorrectThread() override; |
+ |
+ // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL |
+ // pointer otherwise. |
+ // TODO(xhwang): Is it okay not to update session expiration info? |
+ static scoped_ptr<MediaDrmProxy, BrowserCdmDeleter> Create( |
+ const std::string& key_system, |
+ MediaDrmBridge::SecurityLevel widevine_security_level, |
+ const SessionMessageCB& session_message_cb, |
+ const SessionClosedCB& session_closed_cb, |
+ const LegacySessionErrorCB& legacy_session_error_cb, |
+ const SessionKeysChangeCB& session_keys_change_cb, |
+ const SessionExpirationUpdateCB& session_expiration_update_cb); |
+ |
+ // MediaKeys (via BrowserCdm) implementation. |
+ |
+ void SetServerCertificate( |
+ const std::vector<uint8_t>& certificate, |
+ scoped_ptr<media::SimpleCdmPromise> promise) override; |
+ void CreateSessionAndGenerateRequest( |
+ SessionType session_type, |
+ media::EmeInitDataType init_data_type, |
+ const std::vector<uint8_t>& init_data, |
+ scoped_ptr<media::NewSessionCdmPromise> promise) override; |
+ void LoadSession(SessionType session_type, |
+ const std::string& session_id, |
+ scoped_ptr<media::NewSessionCdmPromise> promise) override; |
+ void UpdateSession(const std::string& session_id, |
+ const std::vector<uint8_t>& response, |
+ scoped_ptr<media::SimpleCdmPromise> promise) override; |
+ void CloseSession(const std::string& session_id, |
+ scoped_ptr<media::SimpleCdmPromise> promise) override; |
+ void RemoveSession(const std::string& session_id, |
+ scoped_ptr<media::SimpleCdmPromise> promise) override; |
+ CdmContext* GetCdmContext() override; |
+ |
+ // PlayerTracker (via BrowserCdm) implementation. |
+ |
+ int RegisterPlayer(const base::Closure& new_key_cb, |
+ const base::Closure& cdm_unset_cb) override; |
+ void UnregisterPlayer(int registration_id) override; |
+ |
+ // Accessor for MediaDrmBridge |
+ MediaDrmBridge* GetDrmBridge(); |
+ |
+ private: |
+ MediaDrmProxy(const std::string& key_system, |
+ MediaDrmBridge::SecurityLevel widevine_security_level, |
+ const SessionMessageCB& session_message_cb, |
+ const SessionClosedCB& session_closed_cb, |
+ const LegacySessionErrorCB& legacy_session_error_cb, |
+ const SessionKeysChangeCB& session_keys_change_cb, |
+ const SessionExpirationUpdateCB& session_expiration_update_cb); |
+ |
+ // Helper method to create MediaDrmBridge on the Media thread. |
+ void Initialize(); |
+ |
+ // Internal callbacks. |
+ // We need to preserve the order of messages we send to the render process. |
+ // Since we post the promise-related callbacks first from UI to Media thread |
+ // and then back to UI thread, we need to do the same with session-related |
+ // callbacks, too. |
+ // We do this hopping with the promise-related callbacks to avoid a mutex in |
+ // CdmPromiseAdapter, otherwise we could keep all callbacks on UI thread. |
+ |
+ void OnSessionMessage(const std::string& session_id, |
+ MediaKeys::MessageType message_type, |
+ const std::vector<uint8>& message, |
+ const GURL& legacy_destination_url); |
+ void OnSessionClosed(const std::string& session_id); |
+ void OnLegacySessionError(const std::string& session_id, |
+ MediaKeys::Exception exception_code, |
+ uint32 system_code, |
+ const std::string& error_message); |
+ void OnSessionKeysChange(const std::string& session_id, |
+ bool has_additional_usable_key, |
+ CdmKeysInfo keys_info); |
+ void OnSessionExpirationUpdate(const std::string& session_id, |
+ const base::Time& new_expiry_time); |
+ |
+ // Data. |
+ |
+ // Object for posting tasks on UI thread. |
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
+ |
+ // MediaDrmBridge that will be accessed on the Media thread. |
+ scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> media_drm_bridge_; |
+ |
+ // The key system. |
+ const std::string key_system_; |
+ |
+ // Required security level. Only makes sense for Widevine system. |
+ const MediaDrmBridge::SecurityLevel widevine_security_level_; |
+ |
+ // Callbacks received as parameters, to be called on UI thread |
+ SessionMessageCB session_message_cb_; |
+ SessionClosedCB session_closed_cb_; |
+ LegacySessionErrorCB legacy_session_error_cb_; |
+ SessionKeysChangeCB session_keys_change_cb_; |
+ SessionExpirationUpdateCB session_expiration_update_cb_; |
+ |
+ // Internal callbacks passed to MediaDrmBridge, called on media thread. |
+ SessionMessageCB internal_session_message_cb_; |
+ SessionClosedCB internal_session_closed_cb_; |
+ LegacySessionErrorCB internal_legacy_session_error_cb_; |
+ SessionKeysChangeCB internal_session_keys_change_cb_; |
+ SessionExpirationUpdateCB internal_session_expiration_update_cb_; |
+ |
+ base::WeakPtr<MediaDrmProxy> media_weak_this_; |
+ |
+ // NOTE: Weak pointers must be invalidated before all other member variables. |
+ base::WeakPtrFactory<MediaDrmProxy> media_weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MediaDrmProxy); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BASE_ANDROID_MEDIA_DRM_PROXY_H_ |