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 "chromecast/media/cdm/browser_cdm_cast.h" | 5 #include "chromecast/media/cdm/browser_cdm_cast.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "media/base/cdm_key_information.h" | 10 #include "media/base/cdm_key_information.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 session_id, ::media::MediaKeys::Exception::NOT_SUPPORTED_ERROR, 0, | 61 session_id, ::media::MediaKeys::Exception::NOT_SUPPORTED_ERROR, 0, |
62 std::string()); | 62 std::string()); |
63 } | 63 } |
64 | 64 |
65 ::media::CdmContext* BrowserCdmCast::GetCdmContext() { | 65 ::media::CdmContext* BrowserCdmCast::GetCdmContext() { |
66 NOTREACHED(); | 66 NOTREACHED(); |
67 return nullptr; | 67 return nullptr; |
68 } | 68 } |
69 | 69 |
70 void BrowserCdmCast::OnSessionMessage(const std::string& session_id, | 70 void BrowserCdmCast::OnSessionMessage(const std::string& session_id, |
71 const std::vector<uint8>& message, | 71 const std::vector<uint8_t>& message, |
72 const GURL& destination_url) { | 72 const GURL& destination_url) { |
73 // Note: Message type is not supported in Chromecast. Do our best guess here. | 73 // Note: Message type is not supported in Chromecast. Do our best guess here. |
74 ::media::MediaKeys::MessageType message_type = | 74 ::media::MediaKeys::MessageType message_type = |
75 destination_url.is_empty() ? ::media::MediaKeys::LICENSE_REQUEST | 75 destination_url.is_empty() ? ::media::MediaKeys::LICENSE_REQUEST |
76 : ::media::MediaKeys::LICENSE_RENEWAL; | 76 : ::media::MediaKeys::LICENSE_RENEWAL; |
77 session_message_cb_.Run(session_id, | 77 session_message_cb_.Run(session_id, |
78 message_type, | 78 message_type, |
79 message, | 79 message, |
80 destination_url); | 80 destination_url); |
81 } | 81 } |
(...skipping 10 matching lines...) Expand all Loading... |
92 scoped_ptr< ::media::CdmKeyInformation> cdm_key_information( | 92 scoped_ptr< ::media::CdmKeyInformation> cdm_key_information( |
93 new ::media::CdmKeyInformation()); | 93 new ::media::CdmKeyInformation()); |
94 cdm_key_information->key_id.assign(key.first.begin(), key.first.end()); | 94 cdm_key_information->key_id.assign(key.first.begin(), key.first.end()); |
95 cdm_keys_info.push_back(cdm_key_information.release()); | 95 cdm_keys_info.push_back(cdm_key_information.release()); |
96 } | 96 } |
97 session_keys_change_cb_.Run(session_id, true, cdm_keys_info.Pass()); | 97 session_keys_change_cb_.Run(session_id, true, cdm_keys_info.Pass()); |
98 | 98 |
99 player_tracker_impl_->NotifyNewKey(); | 99 player_tracker_impl_->NotifyNewKey(); |
100 } | 100 } |
101 | 101 |
102 void BrowserCdmCast::SetServerCertificateHelper( | |
103 const std::vector<uint8>& certificate_data, | |
104 scoped_ptr<::media::SimpleCdmPromise> promise) { | |
105 SetServerCertificate(certificate_data.data(), | |
106 certificate_data.size(), | |
107 promise.Pass()); | |
108 } | |
109 | |
110 void BrowserCdmCast::CreateSessionAndGenerateRequestHelper( | |
111 ::media::MediaKeys::SessionType session_type, | |
112 ::media::EmeInitDataType init_data_type, | |
113 const std::vector<uint8>& init_data, | |
114 scoped_ptr<::media::NewSessionCdmPromise> promise) { | |
115 CreateSessionAndGenerateRequest( | |
116 session_type, init_data_type, init_data.data(), init_data.size(), | |
117 promise.Pass()); | |
118 } | |
119 | |
120 void BrowserCdmCast::UpdateSessionHelper( | |
121 const std::string& session_id, | |
122 const std::vector<uint8>& response, | |
123 scoped_ptr<::media::SimpleCdmPromise> promise) { | |
124 UpdateSession(session_id, response.data(), response.size(), promise.Pass()); | |
125 } | |
126 | |
127 // A macro runs current member function on |cdm_loop_| thread. | 102 // A macro runs current member function on |cdm_loop_| thread. |
128 #define FORWARD_ON_CDM_THREAD(param_fn, ...) \ | 103 #define FORWARD_ON_CDM_THREAD(param_fn, ...) \ |
129 cdm_loop_->PostTask( \ | 104 cdm_loop_->PostTask( \ |
130 FROM_HERE, \ | 105 FROM_HERE, \ |
131 base::Bind(&BrowserCdmCast::param_fn, \ | 106 base::Bind(&BrowserCdmCast::param_fn, \ |
132 base::Unretained(browser_cdm_cast_.get()), ##__VA_ARGS__)) | 107 base::Unretained(browser_cdm_cast_.get()), ##__VA_ARGS__)) |
133 | 108 |
134 | 109 |
135 BrowserCdmCastUi::BrowserCdmCastUi( | 110 BrowserCdmCastUi::BrowserCdmCastUi( |
136 scoped_ptr<BrowserCdmCast> browser_cdm_cast, | 111 scoped_ptr<BrowserCdmCast> browser_cdm_cast, |
(...skipping 16 matching lines...) Expand all Loading... |
153 void BrowserCdmCastUi::UnregisterPlayer(int registration_id) { | 128 void BrowserCdmCastUi::UnregisterPlayer(int registration_id) { |
154 NOTREACHED() << "UnregisterPlayer should be called on BrowserCdmCast"; | 129 NOTREACHED() << "UnregisterPlayer should be called on BrowserCdmCast"; |
155 } | 130 } |
156 | 131 |
157 BrowserCdmCast* BrowserCdmCastUi::browser_cdm_cast() const { | 132 BrowserCdmCast* BrowserCdmCastUi::browser_cdm_cast() const { |
158 DCHECK(thread_checker_.CalledOnValidThread()); | 133 DCHECK(thread_checker_.CalledOnValidThread()); |
159 return browser_cdm_cast_.get(); | 134 return browser_cdm_cast_.get(); |
160 } | 135 } |
161 | 136 |
162 void BrowserCdmCastUi::SetServerCertificate( | 137 void BrowserCdmCastUi::SetServerCertificate( |
163 const uint8* certificate_data, | 138 const std::vector<uint8_t>& certificate, |
164 int certificate_data_length, | |
165 scoped_ptr<::media::SimpleCdmPromise> promise) { | 139 scoped_ptr<::media::SimpleCdmPromise> promise) { |
166 DCHECK(thread_checker_.CalledOnValidThread()); | 140 DCHECK(thread_checker_.CalledOnValidThread()); |
167 FORWARD_ON_CDM_THREAD( | 141 FORWARD_ON_CDM_THREAD( |
168 SetServerCertificateHelper, | 142 SetServerCertificate, |
169 std::vector<uint8>(certificate_data, | 143 certificate, |
170 certificate_data + certificate_data_length), | |
171 base::Passed(&promise)); | 144 base::Passed(&promise)); |
172 } | 145 } |
173 | 146 |
174 void BrowserCdmCastUi::CreateSessionAndGenerateRequest( | 147 void BrowserCdmCastUi::CreateSessionAndGenerateRequest( |
175 ::media::MediaKeys::SessionType session_type, | 148 ::media::MediaKeys::SessionType session_type, |
176 ::media::EmeInitDataType init_data_type, | 149 ::media::EmeInitDataType init_data_type, |
177 const uint8* init_data, | 150 const std::vector<uint8_t>& init_data, |
178 int init_data_length, | |
179 scoped_ptr<::media::NewSessionCdmPromise> promise) { | 151 scoped_ptr<::media::NewSessionCdmPromise> promise) { |
180 DCHECK(thread_checker_.CalledOnValidThread()); | 152 DCHECK(thread_checker_.CalledOnValidThread()); |
181 FORWARD_ON_CDM_THREAD( | 153 FORWARD_ON_CDM_THREAD( |
182 CreateSessionAndGenerateRequestHelper, | 154 CreateSessionAndGenerateRequest, |
183 session_type, | 155 session_type, |
184 init_data_type, | 156 init_data_type, |
185 std::vector<uint8>(init_data, init_data + init_data_length), | 157 init_data, |
186 base::Passed(&promise)); | 158 base::Passed(&promise)); |
187 } | 159 } |
188 | 160 |
189 void BrowserCdmCastUi::LoadSession( | 161 void BrowserCdmCastUi::LoadSession( |
190 ::media::MediaKeys::SessionType session_type, | 162 ::media::MediaKeys::SessionType session_type, |
191 const std::string& session_id, | 163 const std::string& session_id, |
192 scoped_ptr<::media::NewSessionCdmPromise> promise) { | 164 scoped_ptr<::media::NewSessionCdmPromise> promise) { |
193 DCHECK(thread_checker_.CalledOnValidThread()); | 165 DCHECK(thread_checker_.CalledOnValidThread()); |
194 FORWARD_ON_CDM_THREAD( | 166 FORWARD_ON_CDM_THREAD( |
195 LoadSession, session_type, session_id, base::Passed(&promise)); | 167 LoadSession, session_type, session_id, base::Passed(&promise)); |
196 } | 168 } |
197 | 169 |
198 void BrowserCdmCastUi::UpdateSession( | 170 void BrowserCdmCastUi::UpdateSession( |
199 const std::string& session_id, | 171 const std::string& session_id, |
200 const uint8* response, | 172 const std::vector<uint8_t>& response, |
201 int response_length, | |
202 scoped_ptr<::media::SimpleCdmPromise> promise) { | 173 scoped_ptr<::media::SimpleCdmPromise> promise) { |
203 DCHECK(thread_checker_.CalledOnValidThread()); | 174 DCHECK(thread_checker_.CalledOnValidThread()); |
204 FORWARD_ON_CDM_THREAD( | 175 FORWARD_ON_CDM_THREAD( |
205 UpdateSessionHelper, | 176 UpdateSession, |
206 session_id, | 177 session_id, |
207 std::vector<uint8>(response, response + response_length), | 178 response, |
208 base::Passed(&promise)); | 179 base::Passed(&promise)); |
209 } | 180 } |
210 | 181 |
211 void BrowserCdmCastUi::CloseSession( | 182 void BrowserCdmCastUi::CloseSession( |
212 const std::string& session_id, | 183 const std::string& session_id, |
213 scoped_ptr<::media::SimpleCdmPromise> promise) { | 184 scoped_ptr<::media::SimpleCdmPromise> promise) { |
214 DCHECK(thread_checker_.CalledOnValidThread()); | 185 DCHECK(thread_checker_.CalledOnValidThread()); |
215 FORWARD_ON_CDM_THREAD(CloseSession, session_id, base::Passed(&promise)); | 186 FORWARD_ON_CDM_THREAD(CloseSession, session_id, base::Passed(&promise)); |
216 } | 187 } |
217 | 188 |
218 void BrowserCdmCastUi::RemoveSession( | 189 void BrowserCdmCastUi::RemoveSession( |
219 const std::string& session_id, | 190 const std::string& session_id, |
220 scoped_ptr<::media::SimpleCdmPromise> promise) { | 191 scoped_ptr<::media::SimpleCdmPromise> promise) { |
221 DCHECK(thread_checker_.CalledOnValidThread()); | 192 DCHECK(thread_checker_.CalledOnValidThread()); |
222 FORWARD_ON_CDM_THREAD(RemoveSession, session_id, base::Passed(&promise)); | 193 FORWARD_ON_CDM_THREAD(RemoveSession, session_id, base::Passed(&promise)); |
223 } | 194 } |
224 | 195 |
225 ::media::CdmContext* BrowserCdmCastUi::GetCdmContext() { | 196 ::media::CdmContext* BrowserCdmCastUi::GetCdmContext() { |
226 NOTREACHED(); | 197 NOTREACHED(); |
227 return nullptr; | 198 return nullptr; |
228 } | 199 } |
229 | 200 |
230 } // namespace media | 201 } // namespace media |
231 } // namespace chromecast | 202 } // namespace chromecast |
OLD | NEW |