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/key_systems.h" | 11 #include "content/renderer/media/crypto/key_systems.h" |
12 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" | 12 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" |
13 #include "media/base/cdm_factory.h" | 13 #include "media/base/cdm_factory.h" |
14 #include "media/base/cdm_promise.h" | 14 #include "media/base/cdm_promise.h" |
15 #include "media/base/media_keys.h" | 15 #include "media/base/media_keys.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 #if defined(ENABLE_BROWSER_CDMS) | |
19 #include "content/renderer/media/crypto/renderer_cdm_manager.h" | |
20 #endif // defined(ENABLE_BROWSER_CDMS) | |
21 | |
22 namespace content { | 18 namespace content { |
23 | 19 |
24 const char kMediaEME[] = "Media.EME."; | 20 const char kMediaEME[] = "Media.EME."; |
25 const char kDot[] = "."; | 21 const char kDot[] = "."; |
26 | 22 |
27 CdmSessionAdapter::CdmSessionAdapter() : | 23 CdmSessionAdapter::CdmSessionAdapter() : weak_ptr_factory_(this) { |
28 #if defined(ENABLE_BROWSER_CDMS) | 24 } |
29 // TODO(xhwang): Move kInvalidCdmId to src/media. | |
30 cdm_id_(RendererCdmManager::kInvalidCdmId), | |
31 #endif | |
32 weak_ptr_factory_(this) {} | |
33 | 25 |
34 CdmSessionAdapter::~CdmSessionAdapter() {} | 26 CdmSessionAdapter::~CdmSessionAdapter() {} |
35 | 27 |
36 bool CdmSessionAdapter::Initialize(media::CdmFactory* cdm_factory, | 28 bool CdmSessionAdapter::Initialize(media::CdmFactory* cdm_factory, |
37 const std::string& key_system, | 29 const std::string& key_system, |
38 const GURL& security_origin) { | 30 const GURL& security_origin) { |
39 // TODO(xhwang): This is why we need to include "key_systems.h". Move | 31 // TODO(xhwang): This is why we need to include "key_systems.h". Move |
40 // KeySystemNameForUMA out of src/content so we can move CdmSessionAdapter to | 32 // KeySystemNameForUMA out of src/content so we can move CdmSessionAdapter to |
41 // src/media. | 33 // src/media. |
42 key_system_uma_prefix_ = kMediaEME + KeySystemNameForUMA(key_system) + kDot; | 34 key_system_uma_prefix_ = kMediaEME + KeySystemNameForUMA(key_system) + kDot; |
43 | 35 |
44 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); | 36 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); |
45 media_keys_ = cdm_factory->Create( | 37 media_keys_ = cdm_factory->Create( |
46 key_system, | 38 key_system, |
47 security_origin, | 39 security_origin, |
48 #if defined(ENABLE_BROWSER_CDMS) | |
49 &cdm_id_, | |
50 #endif // defined(ENABLE_PEPPER_CDMS) | |
51 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), | 40 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), |
52 base::Bind(&CdmSessionAdapter::OnSessionReady, weak_this), | 41 base::Bind(&CdmSessionAdapter::OnSessionReady, weak_this), |
53 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), | 42 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), |
54 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this), | 43 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this), |
55 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), | 44 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), |
56 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this)); | 45 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this)); |
57 | 46 |
58 // Success if |media_keys_| created. | 47 // Success if |media_keys_| created. |
59 return media_keys_; | 48 return media_keys_; |
60 } | 49 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 media::Decryptor* CdmSessionAdapter::GetDecryptor() { | 125 media::Decryptor* CdmSessionAdapter::GetDecryptor() { |
137 return media_keys_->GetDecryptor(); | 126 return media_keys_->GetDecryptor(); |
138 } | 127 } |
139 | 128 |
140 const std::string& CdmSessionAdapter::GetKeySystemUMAPrefix() const { | 129 const std::string& CdmSessionAdapter::GetKeySystemUMAPrefix() const { |
141 return key_system_uma_prefix_; | 130 return key_system_uma_prefix_; |
142 } | 131 } |
143 | 132 |
144 #if defined(ENABLE_BROWSER_CDMS) | 133 #if defined(ENABLE_BROWSER_CDMS) |
145 int CdmSessionAdapter::GetCdmId() const { | 134 int CdmSessionAdapter::GetCdmId() const { |
146 return cdm_id_; | 135 DCHECK(media_keys_); |
jrummell
2014/10/17 17:53:25
I thought the convention was not to check if the c
xhwang
2014/10/17 20:32:06
Done.
| |
136 return media_keys_->GetCdmId(); | |
147 } | 137 } |
148 #endif // defined(ENABLE_BROWSER_CDMS) | 138 #endif // defined(ENABLE_BROWSER_CDMS) |
149 | 139 |
150 void CdmSessionAdapter::OnSessionMessage(const std::string& web_session_id, | 140 void CdmSessionAdapter::OnSessionMessage(const std::string& web_session_id, |
151 const std::vector<uint8>& message, | 141 const std::vector<uint8>& message, |
152 const GURL& destination_url) { | 142 const GURL& destination_url) { |
153 WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); | 143 WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id); |
154 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " | 144 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " |
155 << web_session_id; | 145 << web_session_id; |
156 if (session) | 146 if (session) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( | 197 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( |
208 const std::string& web_session_id) { | 198 const std::string& web_session_id) { |
209 // Since session objects may get garbage collected, it is possible that there | 199 // Since session objects may get garbage collected, it is possible that there |
210 // are events coming back from the CDM and the session has been unregistered. | 200 // are events coming back from the CDM and the session has been unregistered. |
211 // We can not tell if the CDM is firing events at sessions that never existed. | 201 // We can not tell if the CDM is firing events at sessions that never existed. |
212 SessionMap::iterator session = sessions_.find(web_session_id); | 202 SessionMap::iterator session = sessions_.find(web_session_id); |
213 return (session != sessions_.end()) ? session->second.get() : NULL; | 203 return (session != sessions_.end()) ? session->second.get() : NULL; |
214 } | 204 } |
215 | 205 |
216 } // namespace content | 206 } // namespace content |
OLD | NEW |