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 "content/renderer/media/crypto/content_decryption_module_factory.h" | 10 #include "content/renderer/media/crypto/content_decryption_module_factory.h" |
11 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" | 11 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" |
12 #include "media/base/media_keys.h" | 12 #include "media/base/media_keys.h" |
13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 const uint32 kStartingSessionId = 1; | 17 const uint32 kStartingSessionId = 1; |
18 uint32 CdmSessionAdapter::next_session_id_ = kStartingSessionId; | 18 uint32 CdmSessionAdapter::next_session_id_ = kStartingSessionId; |
19 COMPILE_ASSERT(kStartingSessionId > media::MediaKeys::kInvalidSessionId, | 19 COMPILE_ASSERT(kStartingSessionId > media::MediaKeys::kInvalidSessionId, |
20 invalid_starting_value); | 20 invalid_starting_value); |
21 | 21 |
22 CdmSessionAdapter::CdmSessionAdapter() : weak_ptr_factory_(this) {} | 22 CdmSessionAdapter::CdmSessionAdapter() : |
| 23 #if defined(OS_ANDROID) |
| 24 cdm_id_(0), |
| 25 #endif |
| 26 weak_ptr_factory_(this) {} |
23 | 27 |
24 CdmSessionAdapter::~CdmSessionAdapter() {} | 28 CdmSessionAdapter::~CdmSessionAdapter() {} |
25 | 29 |
26 bool CdmSessionAdapter::Initialize( | 30 bool CdmSessionAdapter::Initialize( |
27 #if defined(ENABLE_PEPPER_CDMS) | 31 #if defined(ENABLE_PEPPER_CDMS) |
28 const CreatePepperCdmCB& create_pepper_cdm_cb, | 32 const CreatePepperCdmCB& create_pepper_cdm_cb, |
29 #endif | 33 #endif // defined(ENABLE_PEPPER_CDMS) |
30 const std::string& key_system) { | 34 const std::string& key_system) { |
31 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); | 35 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); |
32 media_keys_ = | 36 media_keys_ = |
33 ContentDecryptionModuleFactory::Create( | 37 ContentDecryptionModuleFactory::Create( |
34 key_system, | 38 key_system, |
35 #if defined(ENABLE_PEPPER_CDMS) | 39 #if defined(ENABLE_PEPPER_CDMS) |
36 create_pepper_cdm_cb, | 40 create_pepper_cdm_cb, |
37 #elif defined(OS_ANDROID) | 41 #elif defined(OS_ANDROID) |
38 // TODO(xhwang): Support Android. | 42 // TODO(xhwang): Support Android. |
39 NULL, | 43 NULL, |
40 0, | |
41 // TODO(ddorwin): Get the URL for the frame containing the MediaKeys. | 44 // TODO(ddorwin): Get the URL for the frame containing the MediaKeys. |
42 GURL(), | 45 GURL(), |
| 46 &cdm_id_, |
43 #endif // defined(ENABLE_PEPPER_CDMS) | 47 #endif // defined(ENABLE_PEPPER_CDMS) |
44 base::Bind(&CdmSessionAdapter::OnSessionCreated, weak_this), | 48 base::Bind(&CdmSessionAdapter::OnSessionCreated, weak_this), |
45 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), | 49 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), |
46 base::Bind(&CdmSessionAdapter::OnSessionReady, weak_this), | 50 base::Bind(&CdmSessionAdapter::OnSessionReady, weak_this), |
47 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), | 51 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), |
48 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this)); | 52 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this)); |
49 | 53 |
50 // Success if |media_keys_| created. | 54 // Success if |media_keys_| created. |
51 return media_keys_; | 55 return media_keys_; |
52 } | 56 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 89 |
86 void CdmSessionAdapter::ReleaseSession(uint32 session_id) { | 90 void CdmSessionAdapter::ReleaseSession(uint32 session_id) { |
87 DCHECK(sessions_.find(session_id) != sessions_.end()); | 91 DCHECK(sessions_.find(session_id) != sessions_.end()); |
88 media_keys_->ReleaseSession(session_id); | 92 media_keys_->ReleaseSession(session_id); |
89 } | 93 } |
90 | 94 |
91 media::Decryptor* CdmSessionAdapter::GetDecryptor() { | 95 media::Decryptor* CdmSessionAdapter::GetDecryptor() { |
92 return media_keys_->GetDecryptor(); | 96 return media_keys_->GetDecryptor(); |
93 } | 97 } |
94 | 98 |
| 99 #if defined(OS_ANDROID) |
| 100 int CdmSessionAdapter::GetCdmId() const { |
| 101 return cdm_id_; |
| 102 } |
| 103 #endif // defined(OS_ANDROID) |
| 104 |
95 void CdmSessionAdapter::OnSessionCreated(uint32 session_id, | 105 void CdmSessionAdapter::OnSessionCreated(uint32 session_id, |
96 const std::string& web_session_id) { | 106 const std::string& web_session_id) { |
97 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); | 107 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); |
98 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " | 108 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " |
99 << session_id; | 109 << session_id; |
100 if (session) | 110 if (session) |
101 session->OnSessionCreated(web_session_id); | 111 session->OnSessionCreated(web_session_id); |
102 } | 112 } |
103 | 113 |
104 void CdmSessionAdapter::OnSessionMessage(uint32 session_id, | 114 void CdmSessionAdapter::OnSessionMessage(uint32 session_id, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( | 150 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( |
141 uint32 session_id) { | 151 uint32 session_id) { |
142 // Since session objects may get garbage collected, it is possible that there | 152 // Since session objects may get garbage collected, it is possible that there |
143 // are events coming back from the CDM and the session has been unregistered. | 153 // are events coming back from the CDM and the session has been unregistered. |
144 // We can not tell if the CDM is firing events at sessions that never existed. | 154 // We can not tell if the CDM is firing events at sessions that never existed. |
145 SessionMap::iterator session = sessions_.find(session_id); | 155 SessionMap::iterator session = sessions_.find(session_id); |
146 return (session != sessions_.end()) ? session->second : NULL; | 156 return (session != sessions_.end()) ? session->second : NULL; |
147 } | 157 } |
148 | 158 |
149 } // namespace content | 159 } // namespace content |
OLD | NEW |