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 #if defined(OS_ANDROID) | |
16 #include "content/renderer/media/android/renderer_media_player_manager.h" | |
ddorwin
2014/03/25 23:04:00
This is a very odd include in this file. Would it
xhwang
2014/03/26 06:02:04
GetCdmId() should only be called after Initialize(
| |
17 #endif | |
18 | |
15 namespace content { | 19 namespace content { |
16 | 20 |
17 const uint32 kStartingSessionId = 1; | 21 const uint32 kStartingSessionId = 1; |
18 uint32 CdmSessionAdapter::next_session_id_ = kStartingSessionId; | 22 uint32 CdmSessionAdapter::next_session_id_ = kStartingSessionId; |
19 COMPILE_ASSERT(kStartingSessionId > media::MediaKeys::kInvalidSessionId, | 23 COMPILE_ASSERT(kStartingSessionId > media::MediaKeys::kInvalidSessionId, |
20 invalid_starting_value); | 24 invalid_starting_value); |
21 | 25 |
22 CdmSessionAdapter::CdmSessionAdapter() : weak_ptr_factory_(this) {} | 26 CdmSessionAdapter::CdmSessionAdapter() : |
27 #if defined(OS_ANDROID) | |
28 cdm_id_(RendererMediaPlayerManager::kInvalidCdmId), | |
29 #endif | |
30 weak_ptr_factory_(this) {} | |
23 | 31 |
24 CdmSessionAdapter::~CdmSessionAdapter() {} | 32 CdmSessionAdapter::~CdmSessionAdapter() {} |
25 | 33 |
26 bool CdmSessionAdapter::Initialize( | 34 bool CdmSessionAdapter::Initialize( |
27 #if defined(ENABLE_PEPPER_CDMS) | 35 #if defined(ENABLE_PEPPER_CDMS) |
28 const CreatePepperCdmCB& create_pepper_cdm_cb, | 36 const CreatePepperCdmCB& create_pepper_cdm_cb, |
29 #endif | 37 #endif // defined(ENABLE_PEPPER_CDMS) |
30 const std::string& key_system) { | 38 const std::string& key_system) { |
39 | |
ddorwin
2014/03/25 23:04:00
remove
xhwang
2014/03/26 06:02:04
Done.
| |
31 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); | 40 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); |
32 media_keys_ = | 41 media_keys_ = |
33 ContentDecryptionModuleFactory::Create( | 42 ContentDecryptionModuleFactory::Create( |
34 key_system, | 43 key_system, |
35 #if defined(ENABLE_PEPPER_CDMS) | 44 #if defined(ENABLE_PEPPER_CDMS) |
36 create_pepper_cdm_cb, | 45 create_pepper_cdm_cb, |
37 #elif defined(OS_ANDROID) | 46 #elif defined(OS_ANDROID) |
38 // TODO(xhwang): Support Android. | 47 // TODO(xhwang): Support Android. |
39 NULL, | 48 NULL, |
40 0, | |
41 // TODO(ddorwin): Get the URL for the frame containing the MediaKeys. | 49 // TODO(ddorwin): Get the URL for the frame containing the MediaKeys. |
42 GURL(), | 50 GURL(), |
51 &cdm_id_, | |
43 #endif // defined(ENABLE_PEPPER_CDMS) | 52 #endif // defined(ENABLE_PEPPER_CDMS) |
44 base::Bind(&CdmSessionAdapter::OnSessionCreated, weak_this), | 53 base::Bind(&CdmSessionAdapter::OnSessionCreated, weak_this), |
45 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), | 54 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), |
46 base::Bind(&CdmSessionAdapter::OnSessionReady, weak_this), | 55 base::Bind(&CdmSessionAdapter::OnSessionReady, weak_this), |
47 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), | 56 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), |
48 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this)); | 57 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this)); |
49 | 58 |
50 // Success if |media_keys_| created. | 59 // Success if |media_keys_| created. |
51 return media_keys_; | 60 return media_keys_; |
52 } | 61 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 | 94 |
86 void CdmSessionAdapter::ReleaseSession(uint32 session_id) { | 95 void CdmSessionAdapter::ReleaseSession(uint32 session_id) { |
87 DCHECK(sessions_.find(session_id) != sessions_.end()); | 96 DCHECK(sessions_.find(session_id) != sessions_.end()); |
88 media_keys_->ReleaseSession(session_id); | 97 media_keys_->ReleaseSession(session_id); |
89 } | 98 } |
90 | 99 |
91 media::Decryptor* CdmSessionAdapter::GetDecryptor() { | 100 media::Decryptor* CdmSessionAdapter::GetDecryptor() { |
92 return media_keys_->GetDecryptor(); | 101 return media_keys_->GetDecryptor(); |
93 } | 102 } |
94 | 103 |
104 #if defined(OS_ANDROID) | |
105 int CdmSessionAdapter::GetCdmId() const { | |
106 return cdm_id_; | |
107 } | |
108 #endif // defined(OS_ANDROID) | |
109 | |
95 void CdmSessionAdapter::OnSessionCreated(uint32 session_id, | 110 void CdmSessionAdapter::OnSessionCreated(uint32 session_id, |
96 const std::string& web_session_id) { | 111 const std::string& web_session_id) { |
97 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); | 112 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); |
98 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " | 113 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " |
99 << session_id; | 114 << session_id; |
100 if (session) | 115 if (session) |
101 session->OnSessionCreated(web_session_id); | 116 session->OnSessionCreated(web_session_id); |
102 } | 117 } |
103 | 118 |
104 void CdmSessionAdapter::OnSessionMessage(uint32 session_id, | 119 void CdmSessionAdapter::OnSessionMessage(uint32 session_id, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( | 155 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( |
141 uint32 session_id) { | 156 uint32 session_id) { |
142 // Since session objects may get garbage collected, it is possible that there | 157 // 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. | 158 // 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. | 159 // We can not tell if the CDM is firing events at sessions that never existed. |
145 SessionMap::iterator session = sessions_.find(session_id); | 160 SessionMap::iterator session = sessions_.find(session_id); |
146 return (session != sessions_.end()) ? session->second : NULL; | 161 return (session != sessions_.end()) ? session->second : NULL; |
147 } | 162 } |
148 | 163 |
149 } // namespace content | 164 } // namespace content |
OLD | NEW |