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