OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" | 5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <sstream> | 9 #include <sstream> |
10 #include <string> | 10 #include <string> |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 213 } |
214 | 214 |
215 const char* GetCdmVersion() { | 215 const char* GetCdmVersion() { |
216 return kClearKeyCdmVersion; | 216 return kClearKeyCdmVersion; |
217 } | 217 } |
218 | 218 |
219 namespace media { | 219 namespace media { |
220 | 220 |
221 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, const std::string& key_system) | 221 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, const std::string& key_system) |
222 : decryptor_( | 222 : decryptor_( |
223 base::Bind(&ClearKeyCdm::OnSessionMessage, base::Unretained(this)), | 223 base::Bind(&ClearKeyCdm::OnSessionMessage, base::Unretained(this)), |
224 base::Bind(&ClearKeyCdm::OnSessionClosed, base::Unretained(this))), | 224 base::Bind(&ClearKeyCdm::OnSessionClosed, base::Unretained(this)), |
| 225 base::Bind(&ClearKeyCdm::OnSessionKeysChange, |
| 226 base::Unretained(this))), |
225 host_(host), | 227 host_(host), |
226 key_system_(key_system), | 228 key_system_(key_system), |
227 timer_delay_ms_(kInitialTimerDelayMs), | 229 timer_delay_ms_(kInitialTimerDelayMs), |
228 heartbeat_timer_set_(false) { | 230 heartbeat_timer_set_(false) { |
229 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) | 231 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) |
230 channel_count_ = 0; | 232 channel_count_ = 0; |
231 bits_per_channel_ = 0; | 233 bits_per_channel_ = 0; |
232 samples_per_second_ = 0; | 234 samples_per_second_ = 0; |
233 output_timestamp_base_in_microseconds_ = kNoTimestamp; | 235 output_timestamp_base_in_microseconds_ = kNoTimestamp; |
234 total_samples_generated_ = 0; | 236 total_samples_generated_ = 0; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 } | 322 } |
321 } | 323 } |
322 | 324 |
323 void ClearKeyCdm::CloseSession(uint32 promise_id, | 325 void ClearKeyCdm::CloseSession(uint32 promise_id, |
324 const char* web_session_id, | 326 const char* web_session_id, |
325 uint32_t web_session_id_length) { | 327 uint32_t web_session_id_length) { |
326 DVLOG(1) << __FUNCTION__; | 328 DVLOG(1) << __FUNCTION__; |
327 std::string web_session_str(web_session_id, web_session_id_length); | 329 std::string web_session_str(web_session_id, web_session_id_length); |
328 | 330 |
329 scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise( | 331 scoped_ptr<media::SimpleCdmPromise> promise(new media::SimpleCdmPromise( |
330 base::Bind(&ClearKeyCdm::OnSessionReleased, | 332 base::Bind( |
331 base::Unretained(this), | 333 &ClearKeyCdm::OnPromiseResolved, base::Unretained(this), promise_id), |
332 promise_id, | |
333 web_session_str), | |
334 base::Bind( | 334 base::Bind( |
335 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); | 335 &ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); |
336 decryptor_.ReleaseSession(web_session_str, promise.Pass()); | 336 decryptor_.CloseSession(web_session_str, promise.Pass()); |
337 } | 337 } |
338 | 338 |
339 void ClearKeyCdm::RemoveSession(uint32 promise_id, | 339 void ClearKeyCdm::RemoveSession(uint32 promise_id, |
340 const char* web_session_id, | 340 const char* web_session_id, |
341 uint32_t web_session_id_length) { | 341 uint32_t web_session_id_length) { |
342 DVLOG(1) << __FUNCTION__; | 342 DVLOG(1) << __FUNCTION__; |
343 // RemoveSession only allowed for persistent sessions. | 343 // RemoveSession only allowed for persistent sessions. |
344 bool is_persistent_session = | 344 bool is_persistent_session = |
345 std::string(kLoadableWebSessionId) == | 345 std::string(kLoadableWebSessionId) == |
346 std::string(web_session_id, web_session_id_length); | 346 std::string(web_session_id, web_session_id_length); |
347 if (is_persistent_session) { | 347 if (is_persistent_session) { |
348 host_->OnResolvePromise(promise_id); | 348 std::string web_session_str(web_session_id, web_session_id_length); |
| 349 |
| 350 scoped_ptr<media::SimpleCdmPromise> promise( |
| 351 new media::SimpleCdmPromise(base::Bind(&ClearKeyCdm::OnPromiseResolved, |
| 352 base::Unretained(this), |
| 353 promise_id), |
| 354 base::Bind(&ClearKeyCdm::OnPromiseFailed, |
| 355 base::Unretained(this), |
| 356 promise_id))); |
| 357 decryptor_.RemoveSession(web_session_str, promise.Pass()); |
349 } else { | 358 } else { |
| 359 // TODO(jrummell): This should be a DCHECK once blink does the proper |
| 360 // checks. |
350 std::string message("Not supported for non-persistent sessions."); | 361 std::string message("Not supported for non-persistent sessions."); |
351 host_->OnRejectPromise(promise_id, | 362 host_->OnRejectPromise(promise_id, |
352 cdm::kInvalidAccessError, | 363 cdm::kInvalidAccessError, |
353 0, | 364 0, |
354 message.data(), | 365 message.data(), |
355 message.length()); | 366 message.length()); |
356 } | 367 } |
357 } | 368 } |
358 | 369 |
359 void ClearKeyCdm::SetServerCertificate(uint32 promise_id, | 370 void ClearKeyCdm::SetServerCertificate(uint32 promise_id, |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 // involved (OnSessionCreated() called to resolve the CreateSession() | 687 // involved (OnSessionCreated() called to resolve the CreateSession() |
677 // promise). | 688 // promise). |
678 host_->OnSessionMessage(web_session_id.data(), | 689 host_->OnSessionMessage(web_session_id.data(), |
679 web_session_id.length(), | 690 web_session_id.length(), |
680 reinterpret_cast<const char*>(message.data()), | 691 reinterpret_cast<const char*>(message.data()), |
681 message.size(), | 692 message.size(), |
682 destination_url.spec().data(), | 693 destination_url.spec().data(), |
683 destination_url.spec().size()); | 694 destination_url.spec().size()); |
684 } | 695 } |
685 | 696 |
| 697 void ClearKeyCdm::OnSessionKeysChange(const std::string& web_session_id, |
| 698 bool has_additional_usable_key) { |
| 699 host_->OnSessionUsableKeysChange(web_session_id.data(), |
| 700 web_session_id.length(), |
| 701 has_additional_usable_key); |
| 702 } |
| 703 |
686 void ClearKeyCdm::OnSessionClosed(const std::string& web_session_id) { | 704 void ClearKeyCdm::OnSessionClosed(const std::string& web_session_id) { |
687 host_->OnSessionClosed(web_session_id.data(), web_session_id.length()); | 705 host_->OnSessionClosed(web_session_id.data(), web_session_id.length()); |
688 } | 706 } |
689 | 707 |
690 void ClearKeyCdm::OnSessionCreated(uint32 promise_id, | 708 void ClearKeyCdm::OnSessionCreated(uint32 promise_id, |
691 const std::string& web_session_id) { | 709 const std::string& web_session_id) { |
692 // Save the latest session ID for heartbeat and file IO test messages. | 710 // Save the latest session ID for heartbeat and file IO test messages. |
693 last_session_id_ = web_session_id; | 711 last_session_id_ = web_session_id; |
694 | 712 |
695 host_->OnResolveNewSessionPromise( | 713 host_->OnResolveNewSessionPromise( |
(...skipping 30 matching lines...) Expand all Loading... |
726 session_id_for_emulated_loadsession_ = std::string(); | 744 session_id_for_emulated_loadsession_ = std::string(); |
727 // |promise_id| is the LoadSession() promise, so resolve appropriately. | 745 // |promise_id| is the LoadSession() promise, so resolve appropriately. |
728 host_->OnResolveNewSessionPromise( | 746 host_->OnResolveNewSessionPromise( |
729 promise_id, kLoadableWebSessionId, strlen(kLoadableWebSessionId)); | 747 promise_id, kLoadableWebSessionId, strlen(kLoadableWebSessionId)); |
730 return; | 748 return; |
731 } | 749 } |
732 | 750 |
733 host_->OnResolvePromise(promise_id); | 751 host_->OnResolvePromise(promise_id); |
734 } | 752 } |
735 | 753 |
736 void ClearKeyCdm::OnSessionReleased(uint32 promise_id, | |
737 const std::string& web_session_id) { | |
738 host_->OnResolvePromise(promise_id); | |
739 } | |
740 | |
741 void ClearKeyCdm::OnUsableKeyIdsObtained(uint32 promise_id, | 754 void ClearKeyCdm::OnUsableKeyIdsObtained(uint32 promise_id, |
742 const KeyIdsVector& key_ids) { | 755 const KeyIdsVector& key_ids) { |
743 scoped_ptr<cdm::BinaryData[]> result(new cdm::BinaryData[key_ids.size()]); | 756 scoped_ptr<cdm::BinaryData[]> result(new cdm::BinaryData[key_ids.size()]); |
744 for (uint32 i = 0; i < key_ids.size(); ++i) { | 757 for (uint32 i = 0; i < key_ids.size(); ++i) { |
745 result[i].data = key_ids[i].data(); | 758 result[i].data = key_ids[i].data(); |
746 result[i].length = key_ids[i].size(); | 759 result[i].length = key_ids[i].size(); |
747 } | 760 } |
748 host_->OnResolveKeyIdsPromise(promise_id, result.get(), key_ids.size()); | 761 host_->OnResolveKeyIdsPromise(promise_id, result.get(), key_ids.size()); |
749 } | 762 } |
750 | 763 |
| 764 void ClearKeyCdm::OnPromiseResolved(uint32 promise_id) { |
| 765 host_->OnResolvePromise(promise_id); |
| 766 } |
| 767 |
751 void ClearKeyCdm::OnPromiseFailed(uint32 promise_id, | 768 void ClearKeyCdm::OnPromiseFailed(uint32 promise_id, |
752 MediaKeys::Exception exception_code, | 769 MediaKeys::Exception exception_code, |
753 uint32 system_code, | 770 uint32 system_code, |
754 const std::string& error_message) { | 771 const std::string& error_message) { |
755 host_->OnRejectPromise(promise_id, | 772 host_->OnRejectPromise(promise_id, |
756 ConvertException(exception_code), | 773 ConvertException(exception_code), |
757 system_code, | 774 system_code, |
758 error_message.data(), | 775 error_message.data(), |
759 error_message.length()); | 776 error_message.length()); |
760 } | 777 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 host_->OnSessionMessage(last_session_id_.data(), | 848 host_->OnSessionMessage(last_session_id_.data(), |
832 last_session_id_.length(), | 849 last_session_id_.length(), |
833 message.data(), | 850 message.data(), |
834 message.length(), | 851 message.length(), |
835 NULL, | 852 NULL, |
836 0); | 853 0); |
837 file_io_test_runner_.reset(); | 854 file_io_test_runner_.reset(); |
838 } | 855 } |
839 | 856 |
840 } // namespace media | 857 } // namespace media |
OLD | NEW |