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/cdm_adapter.h" | 5 #include "media/cdm/ppapi/cdm_adapter.h" |
6 | 6 |
7 #include "media/base/limits.h" | 7 #include "media/base/limits.h" |
8 #include "media/cdm/ppapi/cdm_file_io_impl.h" | 8 #include "media/cdm/ppapi/cdm_file_io_impl.h" |
9 #include "media/cdm/ppapi/cdm_helpers.h" | 9 #include "media/cdm/ppapi/cdm_helpers.h" |
10 #include "media/cdm/ppapi/cdm_logging.h" | 10 #include "media/cdm/ppapi/cdm_logging.h" |
11 #include "media/cdm/ppapi/supported_cdm_versions.h" | 11 #include "media/cdm/ppapi/supported_cdm_versions.h" |
12 #include "ppapi/c/ppb_console.h" | 12 #include "ppapi/c/ppb_console.h" |
13 #include "ppapi/cpp/private/uma_private.h" | 13 #include "ppapi/cpp/private/uma_private.h" |
14 | 14 |
15 #if defined(CHECK_DOCUMENT_URL) | 15 #if defined(CHECK_DOCUMENT_URL) |
16 #include "ppapi/cpp/dev/url_util_dev.h" | 16 #include "ppapi/cpp/dev/url_util_dev.h" |
17 #include "ppapi/cpp/instance_handle.h" | 17 #include "ppapi/cpp/instance_handle.h" |
18 #endif // defined(CHECK_DOCUMENT_URL) | 18 #endif // defined(CHECK_DOCUMENT_URL) |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
| 22 // Constants for UMA reporting of file size (in KB) via HistogramCustomCounts(). |
| 23 // Note that the histogram is log-scaled (rather than linear). |
| 24 const uint32_t kSizeKBMin = 1; |
| 25 const uint32_t kSizeKBMax = 512 * 1024; // 512MB |
| 26 const uint32_t kSizeKBBuckets = 100; |
| 27 |
22 #if !defined(NDEBUG) | 28 #if !defined(NDEBUG) |
23 #define DLOG_TO_CONSOLE(message) LogToConsole(message); | 29 #define DLOG_TO_CONSOLE(message) LogToConsole(message); |
24 #else | 30 #else |
25 #define DLOG_TO_CONSOLE(message) (void)(message); | 31 #define DLOG_TO_CONSOLE(message) (void)(message); |
26 #endif | 32 #endif |
27 | 33 |
28 bool IsMainThread() { | 34 bool IsMainThread() { |
29 return pp::Module::Get()->core()->IsMainThread(); | 35 return pp::Module::Get()->core()->IsMainThread(); |
30 } | 36 } |
31 | 37 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 output_protection_mask_(0), | 266 output_protection_mask_(0), |
261 query_output_protection_in_progress_(false), | 267 query_output_protection_in_progress_(false), |
262 uma_for_output_protection_query_reported_(false), | 268 uma_for_output_protection_query_reported_(false), |
263 uma_for_output_protection_positive_result_reported_(false), | 269 uma_for_output_protection_positive_result_reported_(false), |
264 #endif | 270 #endif |
265 allocator_(this), | 271 allocator_(this), |
266 cdm_(NULL), | 272 cdm_(NULL), |
267 deferred_initialize_audio_decoder_(false), | 273 deferred_initialize_audio_decoder_(false), |
268 deferred_audio_decoder_config_id_(0), | 274 deferred_audio_decoder_config_id_(0), |
269 deferred_initialize_video_decoder_(false), | 275 deferred_initialize_video_decoder_(false), |
270 deferred_video_decoder_config_id_(0) { | 276 deferred_video_decoder_config_id_(0), |
| 277 last_read_file_size_kb_(0), |
| 278 file_size_uma_reported_(false) { |
271 callback_factory_.Initialize(this); | 279 callback_factory_.Initialize(this); |
272 } | 280 } |
273 | 281 |
274 CdmAdapter::~CdmAdapter() {} | 282 CdmAdapter::~CdmAdapter() {} |
275 | 283 |
276 bool CdmAdapter::CreateCdmInstance(const std::string& key_system) { | 284 bool CdmAdapter::CreateCdmInstance(const std::string& key_system) { |
277 PP_DCHECK(!cdm_); | 285 PP_DCHECK(!cdm_); |
278 cdm_ = make_linked_ptr(CdmWrapper::Create( | 286 cdm_ = make_linked_ptr(CdmWrapper::Create( |
279 key_system.data(), key_system.size(), GetCdmHost, this)); | 287 key_system.data(), key_system.size(), GetCdmHost, this)); |
280 bool success = cdm_ != NULL; | 288 bool success = cdm_ != NULL; |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 &CdmAdapter::SendPromiseResolvedWithUsableKeyIdsInternal, | 760 &CdmAdapter::SendPromiseResolvedWithUsableKeyIdsInternal, |
753 promise_id, | 761 promise_id, |
754 key_ids)); | 762 key_ids)); |
755 } | 763 } |
756 | 764 |
757 void CdmAdapter::OnRejectPromise(uint32_t promise_id, | 765 void CdmAdapter::OnRejectPromise(uint32_t promise_id, |
758 cdm::Error error, | 766 cdm::Error error, |
759 uint32_t system_code, | 767 uint32_t system_code, |
760 const char* error_message, | 768 const char* error_message, |
761 uint32_t error_message_length) { | 769 uint32_t error_message_length) { |
| 770 // UMA to investigate http://crbug.com/410630 |
| 771 // TODO(xhwang): Remove after bug is fixed. |
| 772 if (system_code == 0x27) { |
| 773 pp::UMAPrivate uma_interface(this); |
| 774 uma_interface.HistogramCustomCounts("Media.EME.CdmFileIO.FileSizeKBOnError", |
| 775 last_read_file_size_kb_, |
| 776 kSizeKBMin, |
| 777 kSizeKBMax, |
| 778 kSizeKBBuckets); |
| 779 } |
| 780 |
762 RejectPromise(promise_id, | 781 RejectPromise(promise_id, |
763 error, | 782 error, |
764 system_code, | 783 system_code, |
765 std::string(error_message, error_message_length)); | 784 std::string(error_message, error_message_length)); |
766 } | 785 } |
767 | 786 |
768 void CdmAdapter::RejectPromise(uint32_t promise_id, | 787 void CdmAdapter::RejectPromise(uint32_t promise_id, |
769 cdm::Error error, | 788 cdm::Error error, |
770 uint32_t system_code, | 789 uint32_t system_code, |
771 const std::string& error_message) { | 790 const std::string& error_message) { |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 static_cast<cdm::VideoFrame::VideoPlane>(i); | 1094 static_cast<cdm::VideoFrame::VideoPlane>(i); |
1076 if (ppb_buffer->Size() < video_frame->PlaneOffset(plane) + | 1095 if (ppb_buffer->Size() < video_frame->PlaneOffset(plane) + |
1077 plane_height * video_frame->Stride(plane)) { | 1096 plane_height * video_frame->Stride(plane)) { |
1078 return false; | 1097 return false; |
1079 } | 1098 } |
1080 } | 1099 } |
1081 | 1100 |
1082 return true; | 1101 return true; |
1083 } | 1102 } |
1084 | 1103 |
| 1104 void CdmAdapter::OnFileRead(int32_t file_size_bytes) { |
| 1105 PP_DCHECK(IsMainThread()); |
| 1106 PP_DCHECK(file_size_bytes >= 0); |
| 1107 |
| 1108 last_read_file_size_kb_ = file_size_bytes / 1024; |
| 1109 |
| 1110 if (file_size_uma_reported_) |
| 1111 return; |
| 1112 |
| 1113 pp::UMAPrivate uma_interface(this); |
| 1114 uma_interface.HistogramCustomCounts( |
| 1115 "Media.EME.CdmFileIO.FileSizeKBOnFirstRead", |
| 1116 last_read_file_size_kb_, |
| 1117 kSizeKBMin, |
| 1118 kSizeKBMax, |
| 1119 kSizeKBBuckets); |
| 1120 file_size_uma_reported_ = true; |
| 1121 } |
| 1122 |
1085 #if !defined(NDEBUG) | 1123 #if !defined(NDEBUG) |
1086 void CdmAdapter::LogToConsole(const pp::Var& value) { | 1124 void CdmAdapter::LogToConsole(const pp::Var& value) { |
1087 PP_DCHECK(IsMainThread()); | 1125 PP_DCHECK(IsMainThread()); |
1088 const PPB_Console* console = reinterpret_cast<const PPB_Console*>( | 1126 const PPB_Console* console = reinterpret_cast<const PPB_Console*>( |
1089 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); | 1127 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); |
1090 console->Log(pp_instance(), PP_LOGLEVEL_LOG, value.pp_var()); | 1128 console->Log(pp_instance(), PP_LOGLEVEL_LOG, value.pp_var()); |
1091 } | 1129 } |
1092 #endif // !defined(NDEBUG) | 1130 #endif // !defined(NDEBUG) |
1093 | 1131 |
1094 void CdmAdapter::SendPlatformChallenge( | 1132 void CdmAdapter::SendPlatformChallenge( |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 deferred_video_decoder_config_id_, | 1220 deferred_video_decoder_config_id_, |
1183 decoder_status == cdm::kSuccess)); | 1221 decoder_status == cdm::kSuccess)); |
1184 deferred_initialize_video_decoder_ = false; | 1222 deferred_initialize_video_decoder_ = false; |
1185 deferred_video_decoder_config_id_ = 0; | 1223 deferred_video_decoder_config_id_ = 0; |
1186 break; | 1224 break; |
1187 } | 1225 } |
1188 } | 1226 } |
1189 | 1227 |
1190 // The CDM owns the returned object and must call FileIO::Close() to release it. | 1228 // The CDM owns the returned object and must call FileIO::Close() to release it. |
1191 cdm::FileIO* CdmAdapter::CreateFileIO(cdm::FileIOClient* client) { | 1229 cdm::FileIO* CdmAdapter::CreateFileIO(cdm::FileIOClient* client) { |
1192 return new CdmFileIOImpl(client, pp_instance()); | 1230 return new CdmFileIOImpl( |
| 1231 client, |
| 1232 pp_instance(), |
| 1233 callback_factory_.NewCallback(&CdmAdapter::OnFileRead)); |
1193 } | 1234 } |
1194 | 1235 |
1195 #if defined(OS_CHROMEOS) | 1236 #if defined(OS_CHROMEOS) |
1196 void CdmAdapter::ReportOutputProtectionUMA(OutputProtectionStatus status) { | 1237 void CdmAdapter::ReportOutputProtectionUMA(OutputProtectionStatus status) { |
1197 pp::UMAPrivate uma_interface_(this); | 1238 pp::UMAPrivate uma_interface_(this); |
1198 uma_interface_.HistogramEnumeration( | 1239 uma_interface_.HistogramEnumeration( |
1199 "Media.EME.OutputProtection", status, OUTPUT_PROTECTION_MAX); | 1240 "Media.EME.OutputProtection", status, OUTPUT_PROTECTION_MAX); |
1200 } | 1241 } |
1201 | 1242 |
1202 void CdmAdapter::ReportOutputProtectionQuery() { | 1243 void CdmAdapter::ReportOutputProtectionQuery() { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 } // namespace media | 1399 } // namespace media |
1359 | 1400 |
1360 namespace pp { | 1401 namespace pp { |
1361 | 1402 |
1362 // Factory function for your specialization of the Module object. | 1403 // Factory function for your specialization of the Module object. |
1363 Module* CreateModule() { | 1404 Module* CreateModule() { |
1364 return new media::CdmAdapterModule(); | 1405 return new media::CdmAdapterModule(); |
1365 } | 1406 } |
1366 | 1407 |
1367 } // namespace pp | 1408 } // namespace pp |
OLD | NEW |