OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "content/renderer/media/cdm_session_adapter.h" | 5 #include "content/renderer/media/cdm_session_adapter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "content/renderer/media/crypto/content_decryption_module_factory.h" | 11 #include "content/renderer/media/crypto/content_decryption_module_factory.h" |
12 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" | 12 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" |
13 #include "media/base/cdm_promise.h" | 13 #include "media/base/cdm_promise.h" |
14 #include "media/base/media_keys.h" | 14 #include "media/base/media_keys.h" |
15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 CdmSessionAdapter::CdmSessionAdapter() : | 19 CdmSessionAdapter::CdmSessionAdapter() : |
20 #if defined(OS_ANDROID) | 20 #if defined(ENABLE_BROWSER_CDMS) |
21 cdm_id_(0), | 21 cdm_id_(0), |
22 #endif | 22 #endif |
23 weak_ptr_factory_(this) {} | 23 weak_ptr_factory_(this) {} |
24 | 24 |
25 CdmSessionAdapter::~CdmSessionAdapter() {} | 25 CdmSessionAdapter::~CdmSessionAdapter() {} |
26 | 26 |
27 bool CdmSessionAdapter::Initialize( | 27 bool CdmSessionAdapter::Initialize( |
28 #if defined(ENABLE_PEPPER_CDMS) | 28 #if defined(ENABLE_PEPPER_CDMS) |
29 const CreatePepperCdmCB& create_pepper_cdm_cb, | 29 const CreatePepperCdmCB& create_pepper_cdm_cb, |
30 #elif defined(OS_ANDROID) | 30 #elif defined(ENABLE_BROWSER_CDMS) |
31 RendererCdmManager* manager, | 31 RendererCdmManager* manager, |
32 #endif // defined(ENABLE_PEPPER_CDMS) | 32 #endif // defined(ENABLE_PEPPER_CDMS) |
33 const std::string& key_system, | 33 const std::string& key_system, |
34 const GURL& security_origin) { | 34 const GURL& security_origin) { |
35 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); | 35 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); |
36 media_keys_ = ContentDecryptionModuleFactory::Create( | 36 media_keys_ = ContentDecryptionModuleFactory::Create( |
37 key_system, | 37 key_system, |
38 security_origin, | 38 security_origin, |
39 #if defined(ENABLE_PEPPER_CDMS) | 39 #if defined(ENABLE_PEPPER_CDMS) |
40 create_pepper_cdm_cb, | 40 create_pepper_cdm_cb, |
41 #elif defined(OS_ANDROID) | 41 #elif defined(ENABLE_BROWSER_CDMS) |
42 manager, | 42 manager, |
43 &cdm_id_, | 43 &cdm_id_, |
44 #endif // defined(ENABLE_PEPPER_CDMS) | 44 #endif // defined(ENABLE_PEPPER_CDMS) |
45 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), | 45 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), |
46 base::Bind(&CdmSessionAdapter::OnSessionReady, weak_this), | 46 base::Bind(&CdmSessionAdapter::OnSessionReady, weak_this), |
47 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), | 47 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), |
48 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this)); | 48 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this)); |
49 | 49 |
50 // Success if |media_keys_| created. | 50 // Success if |media_keys_| created. |
51 return media_keys_; | 51 return media_keys_; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 void CdmSessionAdapter::ReleaseSession( | 93 void CdmSessionAdapter::ReleaseSession( |
94 const std::string& web_session_id, | 94 const std::string& web_session_id, |
95 scoped_ptr<media::SimpleCdmPromise> promise) { | 95 scoped_ptr<media::SimpleCdmPromise> promise) { |
96 media_keys_->ReleaseSession(web_session_id, promise.Pass()); | 96 media_keys_->ReleaseSession(web_session_id, promise.Pass()); |
97 } | 97 } |
98 | 98 |
99 media::Decryptor* CdmSessionAdapter::GetDecryptor() { | 99 media::Decryptor* CdmSessionAdapter::GetDecryptor() { |
100 return media_keys_->GetDecryptor(); | 100 return media_keys_->GetDecryptor(); |
101 } | 101 } |
102 | 102 |
103 #if defined(OS_ANDROID) | 103 #if defined(ENABLE_BROWSER_CDMS) |
104 int CdmSessionAdapter::GetCdmId() const { | 104 int CdmSessionAdapter::GetCdmId() const { |
105 return cdm_id_; | 105 return cdm_id_; |
106 } | 106 } |
107 #endif // defined(OS_ANDROID) | 107 #endif // defined(ENABLE_BROWSER_CDMS) |
108 | 108 |
109 void CdmSessionAdapter::OnSessionMessage(const std::string& web_session_id, | 109 void CdmSessionAdapter::OnSessionMessage(const std::string& web_session_id, |
110 const std::vector<uint8>& message, | 110 const std::vector<uint8>& message, |
111 const GURL& destination_url) { | 111 const GURL& destination_url) { |
112 WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); | 112 WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); |
113 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " | 113 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " |
114 << web_session_id; | 114 << web_session_id; |
115 if (session) | 115 if (session) |
116 session->OnSessionMessage(message, destination_url); | 116 session->OnSessionMessage(message, destination_url); |
117 } | 117 } |
(...skipping 29 matching lines...) Expand all Loading... |
147 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( | 147 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( |
148 const std::string& web_session_id) { | 148 const std::string& web_session_id) { |
149 // Since session objects may get garbage collected, it is possible that there | 149 // Since session objects may get garbage collected, it is possible that there |
150 // are events coming back from the CDM and the session has been unregistered. | 150 // are events coming back from the CDM and the session has been unregistered. |
151 // We can not tell if the CDM is firing events at sessions that never existed. | 151 // We can not tell if the CDM is firing events at sessions that never existed. |
152 SessionMap::iterator session = sessions_.find(web_session_id); | 152 SessionMap::iterator session = sessions_.find(web_session_id); |
153 return (session != sessions_.end()) ? session->second.get() : NULL; | 153 return (session != sessions_.end()) ? session->second.get() : NULL; |
154 } | 154 } |
155 | 155 |
156 } // namespace content | 156 } // namespace content |
OLD | NEW |