| 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 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/stl_util.h" | |
| 14 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 15 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 16 #include "media/base/cdm_callback_promise.h" | 15 #include "media/base/cdm_callback_promise.h" |
| 17 #include "media/base/cdm_key_information.h" | 16 #include "media/base/cdm_key_information.h" |
| 18 #include "media/base/decoder_buffer.h" | 17 #include "media/base/decoder_buffer.h" |
| 19 #include "media/base/decrypt_config.h" | 18 #include "media/base/decrypt_config.h" |
| 20 #include "media/base/key_systems.h" | 19 #include "media/base/key_systems.h" |
| 21 #include "media/cdm/json_web_key.h" | 20 #include "media/cdm/json_web_key.h" |
| 22 #include "media/cdm/ppapi/cdm_file_io_test.h" | 21 #include "media/cdm/ppapi/cdm_file_io_test.h" |
| 23 #include "media/cdm/ppapi/external_clear_key/cdm_video_decoder.h" | 22 #include "media/cdm/ppapi/external_clear_key/cdm_video_decoder.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 196 } |
| 198 | 197 |
| 199 // Shallow copy all the key information from |keys_info| into |keys_vector|. | 198 // Shallow copy all the key information from |keys_info| into |keys_vector|. |
| 200 // |keys_vector| is only valid for the lifetime of |keys_info| because it | 199 // |keys_vector| is only valid for the lifetime of |keys_info| because it |
| 201 // contains pointers into the latter. | 200 // contains pointers into the latter. |
| 202 void ConvertCdmKeysInfo(const std::vector<media::CdmKeyInformation*>& keys_info, | 201 void ConvertCdmKeysInfo(const std::vector<media::CdmKeyInformation*>& keys_info, |
| 203 std::vector<cdm::KeyInformation>* keys_vector) { | 202 std::vector<cdm::KeyInformation>* keys_vector) { |
| 204 keys_vector->reserve(keys_info.size()); | 203 keys_vector->reserve(keys_info.size()); |
| 205 for (const auto& key_info : keys_info) { | 204 for (const auto& key_info : keys_info) { |
| 206 cdm::KeyInformation key; | 205 cdm::KeyInformation key; |
| 207 key.key_id = vector_as_array(&key_info->key_id); | 206 key.key_id = key_info->key_id.data(); |
| 208 key.key_id_size = key_info->key_id.size(); | 207 key.key_id_size = key_info->key_id.size(); |
| 209 key.status = ConvertKeyStatus(key_info->status); | 208 key.status = ConvertKeyStatus(key_info->status); |
| 210 key.system_code = key_info->system_code; | 209 key.system_code = key_info->system_code; |
| 211 keys_vector->push_back(key); | 210 keys_vector->push_back(key); |
| 212 } | 211 } |
| 213 } | 212 } |
| 214 | 213 |
| 215 void INITIALIZE_CDM_MODULE() { | 214 void INITIALIZE_CDM_MODULE() { |
| 216 DVLOG(1) << __FUNCTION__; | 215 DVLOG(1) << __FUNCTION__; |
| 217 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) | 216 #if defined(CLEAR_KEY_CDM_USE_FFMPEG_DECODER) |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 } | 739 } |
| 741 | 740 |
| 742 // Loadable session has already been created, so pass this event on, | 741 // Loadable session has already been created, so pass this event on, |
| 743 // using the session_id callers expect to see. | 742 // using the session_id callers expect to see. |
| 744 new_session_id = std::string(kLoadableSessionId); | 743 new_session_id = std::string(kLoadableSessionId); |
| 745 } | 744 } |
| 746 | 745 |
| 747 std::vector<cdm::KeyInformation> keys_vector; | 746 std::vector<cdm::KeyInformation> keys_vector; |
| 748 ConvertCdmKeysInfo(keys_info.get(), &keys_vector); | 747 ConvertCdmKeysInfo(keys_info.get(), &keys_vector); |
| 749 host_->OnSessionKeysChange(new_session_id.data(), new_session_id.length(), | 748 host_->OnSessionKeysChange(new_session_id.data(), new_session_id.length(), |
| 750 has_additional_usable_key, | 749 has_additional_usable_key, keys_vector.data(), |
| 751 vector_as_array(&keys_vector), keys_vector.size()); | 750 keys_vector.size()); |
| 752 } | 751 } |
| 753 | 752 |
| 754 void ClearKeyCdm::OnSessionClosed(const std::string& session_id) { | 753 void ClearKeyCdm::OnSessionClosed(const std::string& session_id) { |
| 755 std::string new_session_id = session_id; | 754 std::string new_session_id = session_id; |
| 756 if (new_session_id == session_id_for_emulated_loadsession_) | 755 if (new_session_id == session_id_for_emulated_loadsession_) |
| 757 new_session_id = std::string(kLoadableSessionId); | 756 new_session_id = std::string(kLoadableSessionId); |
| 758 host_->OnSessionClosed(new_session_id.data(), new_session_id.length()); | 757 host_->OnSessionClosed(new_session_id.data(), new_session_id.length()); |
| 759 } | 758 } |
| 760 | 759 |
| 761 void ClearKeyCdm::OnSessionCreated(uint32 promise_id, | 760 void ClearKeyCdm::OnSessionCreated(uint32 promise_id, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 // TODO(jrummell): Once the order of events is fixed in the spec, either | 804 // TODO(jrummell): Once the order of events is fixed in the spec, either |
| 806 // require the keyschange event to have happened, or remove this code. | 805 // require the keyschange event to have happened, or remove this code. |
| 807 // http://crbug.com/448225 | 806 // http://crbug.com/448225 |
| 808 if (has_received_keys_change_event_for_emulated_loadsession_) { | 807 if (has_received_keys_change_event_for_emulated_loadsession_) { |
| 809 std::vector<cdm::KeyInformation> keys_vector; | 808 std::vector<cdm::KeyInformation> keys_vector; |
| 810 CdmKeysInfo keys_info; | 809 CdmKeysInfo keys_info; |
| 811 keys_info.swap(keys_info_for_emulated_loadsession_); | 810 keys_info.swap(keys_info_for_emulated_loadsession_); |
| 812 has_received_keys_change_event_for_emulated_loadsession_ = false; | 811 has_received_keys_change_event_for_emulated_loadsession_ = false; |
| 813 DCHECK(!keys_vector.empty()); | 812 DCHECK(!keys_vector.empty()); |
| 814 ConvertCdmKeysInfo(keys_info.get(), &keys_vector); | 813 ConvertCdmKeysInfo(keys_info.get(), &keys_vector); |
| 815 host_->OnSessionKeysChange( | 814 host_->OnSessionKeysChange(kLoadableSessionId, strlen(kLoadableSessionId), |
| 816 kLoadableSessionId, strlen(kLoadableSessionId), !keys_vector.empty(), | 815 !keys_vector.empty(), keys_vector.data(), |
| 817 vector_as_array(&keys_vector), keys_vector.size()); | 816 keys_vector.size()); |
| 818 } | 817 } |
| 819 } | 818 } |
| 820 | 819 |
| 821 void ClearKeyCdm::OnPromiseResolved(uint32 promise_id) { | 820 void ClearKeyCdm::OnPromiseResolved(uint32 promise_id) { |
| 822 host_->OnResolvePromise(promise_id); | 821 host_->OnResolvePromise(promise_id); |
| 823 } | 822 } |
| 824 | 823 |
| 825 void ClearKeyCdm::OnPromiseFailed(uint32 promise_id, | 824 void ClearKeyCdm::OnPromiseFailed(uint32 promise_id, |
| 826 MediaKeys::Exception exception_code, | 825 MediaKeys::Exception exception_code, |
| 827 uint32 system_code, | 826 uint32 system_code, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 void ClearKeyCdm::OnFileIOTestComplete(bool success) { | 901 void ClearKeyCdm::OnFileIOTestComplete(bool success) { |
| 903 DVLOG(1) << __FUNCTION__ << ": " << success; | 902 DVLOG(1) << __FUNCTION__ << ": " << success; |
| 904 std::string message = GetFileIOTestResultMessage(success); | 903 std::string message = GetFileIOTestResultMessage(success); |
| 905 host_->OnSessionMessage(last_session_id_.data(), last_session_id_.length(), | 904 host_->OnSessionMessage(last_session_id_.data(), last_session_id_.length(), |
| 906 cdm::kLicenseRequest, message.data(), | 905 cdm::kLicenseRequest, message.data(), |
| 907 message.length(), NULL, 0); | 906 message.length(), NULL, 0); |
| 908 file_io_test_runner_.reset(); | 907 file_io_test_runner_.reset(); |
| 909 } | 908 } |
| 910 | 909 |
| 911 } // namespace media | 910 } // namespace media |
| OLD | NEW |