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/ppapi_cdm_adapter.h" | 5 #include "media/cdm/ppapi/ppapi_cdm_adapter.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 return PP_CDMKEYSTATUS_INVALID; | 313 return PP_CDMKEYSTATUS_INVALID; |
314 } | 314 } |
315 | 315 |
316 } // namespace | 316 } // namespace |
317 | 317 |
318 namespace media { | 318 namespace media { |
319 | 319 |
320 PpapiCdmAdapter::PpapiCdmAdapter(PP_Instance instance, pp::Module* module) | 320 PpapiCdmAdapter::PpapiCdmAdapter(PP_Instance instance, pp::Module* module) |
321 : pp::Instance(instance), | 321 : pp::Instance(instance), |
322 pp::ContentDecryptor_Private(this), | 322 pp::ContentDecryptor_Private(this), |
323 #if defined(OS_CHROMEOS) | |
324 output_protection_(this), | 323 output_protection_(this), |
325 platform_verification_(this), | |
326 output_link_mask_(0), | 324 output_link_mask_(0), |
327 output_protection_mask_(0), | 325 output_protection_mask_(0), |
328 query_output_protection_in_progress_(false), | 326 query_output_protection_in_progress_(false), |
329 uma_for_output_protection_query_reported_(false), | 327 uma_for_output_protection_query_reported_(false), |
330 uma_for_output_protection_positive_result_reported_(false), | 328 uma_for_output_protection_positive_result_reported_(false), |
| 329 #if defined(OS_CHROMEOS) |
| 330 platform_verification_(this), |
331 #endif | 331 #endif |
332 allocator_(this), | 332 allocator_(this), |
333 cdm_(NULL), | 333 cdm_(NULL), |
334 allow_distinctive_identifier_(false), | 334 allow_distinctive_identifier_(false), |
335 allow_persistent_state_(false), | 335 allow_persistent_state_(false), |
336 deferred_initialize_audio_decoder_(false), | 336 deferred_initialize_audio_decoder_(false), |
337 deferred_audio_decoder_config_id_(0), | 337 deferred_audio_decoder_config_id_(0), |
338 deferred_initialize_video_decoder_(false), | 338 deferred_initialize_video_decoder_(false), |
339 deferred_video_decoder_config_id_(0), | 339 deferred_video_decoder_config_id_(0), |
340 last_read_file_size_kb_(0), | 340 last_read_file_size_kb_(0), |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 // Fall through on error and issue an empty OnPlatformChallengeResponse(). | 1062 // Fall through on error and issue an empty OnPlatformChallengeResponse(). |
1063 PP_DCHECK(result != PP_OK); | 1063 PP_DCHECK(result != PP_OK); |
1064 } | 1064 } |
1065 #endif | 1065 #endif |
1066 | 1066 |
1067 cdm::PlatformChallengeResponse platform_challenge_response = {}; | 1067 cdm::PlatformChallengeResponse platform_challenge_response = {}; |
1068 cdm_->OnPlatformChallengeResponse(platform_challenge_response); | 1068 cdm_->OnPlatformChallengeResponse(platform_challenge_response); |
1069 } | 1069 } |
1070 | 1070 |
1071 void PpapiCdmAdapter::EnableOutputProtection(uint32_t desired_protection_mask) { | 1071 void PpapiCdmAdapter::EnableOutputProtection(uint32_t desired_protection_mask) { |
1072 #if defined(OS_CHROMEOS) | |
1073 int32_t result = output_protection_.EnableProtection( | 1072 int32_t result = output_protection_.EnableProtection( |
1074 desired_protection_mask, | 1073 desired_protection_mask, |
1075 callback_factory_.NewCallback(&PpapiCdmAdapter::EnableProtectionDone)); | 1074 callback_factory_.NewCallback(&PpapiCdmAdapter::EnableProtectionDone)); |
1076 | 1075 |
1077 // Errors are ignored since clients must call QueryOutputProtectionStatus() to | 1076 // Errors are ignored since clients must call QueryOutputProtectionStatus() to |
1078 // inspect the protection status on a regular basis. | 1077 // inspect the protection status on a regular basis. |
1079 | 1078 |
1080 if (result != PP_OK && result != PP_OK_COMPLETIONPENDING) | 1079 if (result != PP_OK && result != PP_OK_COMPLETIONPENDING) |
1081 CDM_DLOG() << __FUNCTION__ << " failed!"; | 1080 CDM_DLOG() << __FUNCTION__ << " failed!"; |
1082 #endif | |
1083 } | 1081 } |
1084 | 1082 |
1085 void PpapiCdmAdapter::QueryOutputProtectionStatus() { | 1083 void PpapiCdmAdapter::QueryOutputProtectionStatus() { |
1086 #if defined(OS_CHROMEOS) | |
1087 PP_DCHECK(!query_output_protection_in_progress_); | 1084 PP_DCHECK(!query_output_protection_in_progress_); |
1088 | 1085 |
1089 output_link_mask_ = output_protection_mask_ = 0; | 1086 output_link_mask_ = output_protection_mask_ = 0; |
1090 const int32_t result = output_protection_.QueryStatus( | 1087 const int32_t result = output_protection_.QueryStatus( |
1091 &output_link_mask_, &output_protection_mask_, | 1088 &output_link_mask_, &output_protection_mask_, |
1092 callback_factory_.NewCallback( | 1089 callback_factory_.NewCallback( |
1093 &PpapiCdmAdapter::QueryOutputProtectionStatusDone)); | 1090 &PpapiCdmAdapter::QueryOutputProtectionStatusDone)); |
1094 if (result == PP_OK_COMPLETIONPENDING) { | 1091 if (result == PP_OK_COMPLETIONPENDING) { |
1095 query_output_protection_in_progress_ = true; | 1092 query_output_protection_in_progress_ = true; |
1096 ReportOutputProtectionQuery(); | 1093 ReportOutputProtectionQuery(); |
1097 return; | 1094 return; |
1098 } | 1095 } |
1099 | 1096 |
1100 // Fall through on error and issue an empty OnQueryOutputProtectionStatus(). | 1097 // Fall through on error and issue an empty OnQueryOutputProtectionStatus(). |
1101 PP_DCHECK(result != PP_OK); | 1098 PP_DCHECK(result != PP_OK); |
1102 CDM_DLOG() << __FUNCTION__ << " failed, result = " << result; | 1099 CDM_DLOG() << __FUNCTION__ << " failed, result = " << result; |
1103 #endif | |
1104 cdm_->OnQueryOutputProtectionStatus(cdm::kQueryFailed, 0, 0); | |
1105 } | 1100 } |
1106 | 1101 |
1107 void PpapiCdmAdapter::OnDeferredInitializationDone(cdm::StreamType stream_type, | 1102 void PpapiCdmAdapter::OnDeferredInitializationDone(cdm::StreamType stream_type, |
1108 cdm::Status decoder_status) { | 1103 cdm::Status decoder_status) { |
1109 switch (stream_type) { | 1104 switch (stream_type) { |
1110 case cdm::kStreamTypeAudio: | 1105 case cdm::kStreamTypeAudio: |
1111 PP_DCHECK(deferred_initialize_audio_decoder_); | 1106 PP_DCHECK(deferred_initialize_audio_decoder_); |
1112 CallOnMain(callback_factory_.NewCallback( | 1107 CallOnMain(callback_factory_.NewCallback( |
1113 &PpapiCdmAdapter::DecoderInitializeDone, PP_DECRYPTORSTREAMTYPE_AUDIO, | 1108 &PpapiCdmAdapter::DecoderInitializeDone, PP_DECRYPTORSTREAMTYPE_AUDIO, |
1114 deferred_audio_decoder_config_id_, decoder_status == cdm::kSuccess)); | 1109 deferred_audio_decoder_config_id_, decoder_status == cdm::kSuccess)); |
(...skipping 17 matching lines...) Expand all Loading... |
1132 CDM_DLOG() | 1127 CDM_DLOG() |
1133 << "Cannot create FileIO because persistent state is not allowed."; | 1128 << "Cannot create FileIO because persistent state is not allowed."; |
1134 return nullptr; | 1129 return nullptr; |
1135 } | 1130 } |
1136 | 1131 |
1137 return new CdmFileIOImpl( | 1132 return new CdmFileIOImpl( |
1138 client, pp_instance(), | 1133 client, pp_instance(), |
1139 callback_factory_.NewCallback(&PpapiCdmAdapter::OnFirstFileRead)); | 1134 callback_factory_.NewCallback(&PpapiCdmAdapter::OnFirstFileRead)); |
1140 } | 1135 } |
1141 | 1136 |
1142 #if defined(OS_CHROMEOS) | |
1143 void PpapiCdmAdapter::ReportOutputProtectionUMA(OutputProtectionStatus status) { | 1137 void PpapiCdmAdapter::ReportOutputProtectionUMA(OutputProtectionStatus status) { |
1144 pp::UMAPrivate uma_interface(this); | 1138 pp::UMAPrivate uma_interface(this); |
1145 uma_interface.HistogramEnumeration("Media.EME.OutputProtection", status, | 1139 uma_interface.HistogramEnumeration("Media.EME.OutputProtection", status, |
1146 OUTPUT_PROTECTION_MAX); | 1140 OUTPUT_PROTECTION_MAX); |
1147 } | 1141 } |
1148 | 1142 |
1149 void PpapiCdmAdapter::ReportOutputProtectionQuery() { | 1143 void PpapiCdmAdapter::ReportOutputProtectionQuery() { |
1150 if (uma_for_output_protection_query_reported_) | 1144 if (uma_for_output_protection_query_reported_) |
1151 return; | 1145 return; |
1152 | 1146 |
(...skipping 25 matching lines...) Expand all Loading... |
1178 ReportOutputProtectionUMA(OUTPUT_PROTECTION_ALL_EXTERNAL_LINKS_PROTECTED); | 1172 ReportOutputProtectionUMA(OUTPUT_PROTECTION_ALL_EXTERNAL_LINKS_PROTECTED); |
1179 uma_for_output_protection_positive_result_reported_ = true; | 1173 uma_for_output_protection_positive_result_reported_ = true; |
1180 return; | 1174 return; |
1181 } | 1175 } |
1182 | 1176 |
1183 // Do not report a negative result because it could be a false negative. | 1177 // Do not report a negative result because it could be a false negative. |
1184 // Instead, we will calculate number of negatives using the total number of | 1178 // Instead, we will calculate number of negatives using the total number of |
1185 // queries and success results. | 1179 // queries and success results. |
1186 } | 1180 } |
1187 | 1181 |
| 1182 #if defined(OS_CHROMEOS) |
1188 void PpapiCdmAdapter::SendPlatformChallengeDone( | 1183 void PpapiCdmAdapter::SendPlatformChallengeDone( |
1189 int32_t result, | 1184 int32_t result, |
1190 const linked_ptr<PepperPlatformChallengeResponse>& response) { | 1185 const linked_ptr<PepperPlatformChallengeResponse>& response) { |
1191 if (result != PP_OK) { | 1186 if (result != PP_OK) { |
1192 CDM_DLOG() << __FUNCTION__ << ": Platform challenge failed!"; | 1187 CDM_DLOG() << __FUNCTION__ << ": Platform challenge failed!"; |
1193 cdm::PlatformChallengeResponse platform_challenge_response = {}; | 1188 cdm::PlatformChallengeResponse platform_challenge_response = {}; |
1194 cdm_->OnPlatformChallengeResponse(platform_challenge_response); | 1189 cdm_->OnPlatformChallengeResponse(platform_challenge_response); |
1195 return; | 1190 return; |
1196 } | 1191 } |
1197 | 1192 |
1198 pp::VarArrayBuffer signed_data_var(response->signed_data); | 1193 pp::VarArrayBuffer signed_data_var(response->signed_data); |
1199 pp::VarArrayBuffer signed_data_signature_var(response->signed_data_signature); | 1194 pp::VarArrayBuffer signed_data_signature_var(response->signed_data_signature); |
1200 std::string platform_key_certificate_string = | 1195 std::string platform_key_certificate_string = |
1201 response->platform_key_certificate.AsString(); | 1196 response->platform_key_certificate.AsString(); |
1202 | 1197 |
1203 cdm::PlatformChallengeResponse platform_challenge_response = { | 1198 cdm::PlatformChallengeResponse platform_challenge_response = { |
1204 static_cast<uint8_t*>(signed_data_var.Map()), | 1199 static_cast<uint8_t*>(signed_data_var.Map()), |
1205 signed_data_var.ByteLength(), | 1200 signed_data_var.ByteLength(), |
1206 static_cast<uint8_t*>(signed_data_signature_var.Map()), | 1201 static_cast<uint8_t*>(signed_data_signature_var.Map()), |
1207 signed_data_signature_var.ByteLength(), | 1202 signed_data_signature_var.ByteLength(), |
1208 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.data()), | 1203 reinterpret_cast<const uint8_t*>(platform_key_certificate_string.data()), |
1209 static_cast<uint32_t>(platform_key_certificate_string.length())}; | 1204 static_cast<uint32_t>(platform_key_certificate_string.length())}; |
1210 cdm_->OnPlatformChallengeResponse(platform_challenge_response); | 1205 cdm_->OnPlatformChallengeResponse(platform_challenge_response); |
1211 | 1206 |
1212 signed_data_var.Unmap(); | 1207 signed_data_var.Unmap(); |
1213 signed_data_signature_var.Unmap(); | 1208 signed_data_signature_var.Unmap(); |
1214 } | 1209 } |
| 1210 #endif |
1215 | 1211 |
1216 void PpapiCdmAdapter::EnableProtectionDone(int32_t result) { | 1212 void PpapiCdmAdapter::EnableProtectionDone(int32_t result) { |
1217 // Does nothing since clients must call QueryOutputProtectionStatus() to | 1213 // Does nothing since clients must call QueryOutputProtectionStatus() to |
1218 // inspect the protection status on a regular basis. | 1214 // inspect the protection status on a regular basis. |
1219 CDM_DLOG() << __FUNCTION__ << " : " << result; | 1215 CDM_DLOG() << __FUNCTION__ << " : " << result; |
1220 } | 1216 } |
1221 | 1217 |
1222 void PpapiCdmAdapter::QueryOutputProtectionStatusDone(int32_t result) { | 1218 void PpapiCdmAdapter::QueryOutputProtectionStatusDone(int32_t result) { |
1223 PP_DCHECK(query_output_protection_in_progress_); | 1219 PP_DCHECK(query_output_protection_in_progress_); |
1224 query_output_protection_in_progress_ = false; | 1220 query_output_protection_in_progress_ = false; |
1225 | 1221 |
1226 // Return a query status of failed on error. | 1222 // Return a query status of failed on error. |
1227 cdm::QueryResult query_result; | 1223 cdm::QueryResult query_result; |
1228 if (result != PP_OK) { | 1224 if (result != PP_OK) { |
1229 CDM_DLOG() << __FUNCTION__ << " failed, result = " << result; | 1225 CDM_DLOG() << __FUNCTION__ << " failed, result = " << result; |
1230 output_link_mask_ = output_protection_mask_ = 0; | 1226 output_link_mask_ = output_protection_mask_ = 0; |
1231 query_result = cdm::kQueryFailed; | 1227 query_result = cdm::kQueryFailed; |
1232 } else { | 1228 } else { |
1233 query_result = cdm::kQuerySucceeded; | 1229 query_result = cdm::kQuerySucceeded; |
1234 ReportOutputProtectionQueryResult(); | 1230 ReportOutputProtectionQueryResult(); |
1235 } | 1231 } |
1236 | 1232 |
1237 cdm_->OnQueryOutputProtectionStatus(query_result, output_link_mask_, | 1233 cdm_->OnQueryOutputProtectionStatus(query_result, output_link_mask_, |
1238 output_protection_mask_); | 1234 output_protection_mask_); |
1239 } | 1235 } |
1240 #endif | |
1241 | 1236 |
1242 PpapiCdmAdapter::SessionError::SessionError( | 1237 PpapiCdmAdapter::SessionError::SessionError( |
1243 cdm::Error error, | 1238 cdm::Error error, |
1244 uint32_t system_code, | 1239 uint32_t system_code, |
1245 const std::string& error_description) | 1240 const std::string& error_description) |
1246 : error(error), | 1241 : error(error), |
1247 system_code(system_code), | 1242 system_code(system_code), |
1248 error_description(error_description) {} | 1243 error_description(error_description) {} |
1249 | 1244 |
1250 PpapiCdmAdapter::SessionMessage::SessionMessage( | 1245 PpapiCdmAdapter::SessionMessage::SessionMessage( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 } // namespace media | 1312 } // namespace media |
1318 | 1313 |
1319 namespace pp { | 1314 namespace pp { |
1320 | 1315 |
1321 // Factory function for your specialization of the Module object. | 1316 // Factory function for your specialization of the Module object. |
1322 Module* CreateModule() { | 1317 Module* CreateModule() { |
1323 return new media::PpapiCdmAdapterModule(); | 1318 return new media::PpapiCdmAdapterModule(); |
1324 } | 1319 } |
1325 | 1320 |
1326 } // namespace pp | 1321 } // namespace pp |
OLD | NEW |