OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/blink/encrypted_media_player_support.h" | 5 #include "media/blink/encrypted_media_player_support.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/numerics/safe_conversions.h" | 12 #include "base/numerics/safe_conversions.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "media/base/bind_to_current_loop.h" | 16 #include "media/base/bind_to_current_loop.h" |
17 #include "media/base/key_systems.h" | 17 #include "media/base/key_systems.h" |
18 #include "media/blink/webcontentdecryptionmodule_impl.h" | 18 #include "media/blink/webcontentdecryptionmodule_impl.h" |
19 #include "third_party/WebKit/public/platform/WebContentDecryptionModule.h" | 19 #include "third_party/WebKit/public/platform/WebContentDecryptionModule.h" |
20 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 20 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
21 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient. h" | |
21 #include "third_party/WebKit/public/web/WebDocument.h" | 22 #include "third_party/WebKit/public/web/WebDocument.h" |
22 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 23 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
23 | 24 |
24 using blink::WebMediaPlayer; | 25 using blink::WebMediaPlayer; |
25 using blink::WebMediaPlayerClient; | 26 using blink::WebMediaPlayerClient; |
27 using blink::WebMediaPlayerEncryptedMediaClient; | |
26 using blink::WebString; | 28 using blink::WebString; |
27 | 29 |
28 namespace media { | 30 namespace media { |
29 | 31 |
30 #define BIND_TO_RENDER_LOOP(function) \ | 32 #define BIND_TO_RENDER_LOOP(function) \ |
31 (BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) | 33 (BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) |
32 | 34 |
33 #define BIND_TO_RENDER_LOOP1(function, arg1) \ | 35 #define BIND_TO_RENDER_LOOP1(function, arg1) \ |
34 (BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) | 36 (BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) |
35 | 37 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 unsigned init_data_length) { | 109 unsigned init_data_length) { |
108 // Most WebM files use KeyId of 16 bytes. CENC init data is always >16 bytes. | 110 // Most WebM files use KeyId of 16 bytes. CENC init data is always >16 bytes. |
109 if (init_data_length == 16) | 111 if (init_data_length == 16) |
110 return EmeInitDataType::WEBM; | 112 return EmeInitDataType::WEBM; |
111 | 113 |
112 return EmeInitDataType::CENC; | 114 return EmeInitDataType::CENC; |
113 } | 115 } |
114 | 116 |
115 EncryptedMediaPlayerSupport::EncryptedMediaPlayerSupport( | 117 EncryptedMediaPlayerSupport::EncryptedMediaPlayerSupport( |
116 CdmFactory* cdm_factory, | 118 CdmFactory* cdm_factory, |
117 blink::WebMediaPlayerClient* client, | 119 WebMediaPlayerClient* client, |
ddorwin
2015/05/26 21:43:07
I don't understand why we're passing this in.
If
Srirama
2015/05/27 14:48:50
To move encrypted related functions from WebMediaP
| |
120 WebMediaPlayerEncryptedMediaClient* encrypted_client, | |
118 MediaPermission* media_permission, | 121 MediaPermission* media_permission, |
119 const CdmContextReadyCB& cdm_context_ready_cb) | 122 const CdmContextReadyCB& cdm_context_ready_cb) |
120 : cdm_factory_(cdm_factory), | 123 : cdm_factory_(cdm_factory), |
121 client_(client), | 124 client_(client), |
125 encrypted_client_(encrypted_client), | |
122 media_permission_(media_permission), | 126 media_permission_(media_permission), |
123 init_data_type_(EmeInitDataType::UNKNOWN), | 127 init_data_type_(EmeInitDataType::UNKNOWN), |
124 cdm_context_ready_cb_(cdm_context_ready_cb) { | 128 cdm_context_ready_cb_(cdm_context_ready_cb) { |
125 } | 129 } |
126 | 130 |
127 EncryptedMediaPlayerSupport::~EncryptedMediaPlayerSupport() { | 131 EncryptedMediaPlayerSupport::~EncryptedMediaPlayerSupport() { |
128 } | 132 } |
129 | 133 |
130 WebMediaPlayer::MediaKeyException | 134 WebMediaPlayer::MediaKeyException |
131 EncryptedMediaPlayerSupport::GenerateKeyRequest( | 135 EncryptedMediaPlayerSupport::GenerateKeyRequest( |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 if (init_data_type_ == EmeInitDataType::UNKNOWN) | 279 if (init_data_type_ == EmeInitDataType::UNKNOWN) |
276 init_data_type_ = init_data_type; | 280 init_data_type_ = init_data_type; |
277 } | 281 } |
278 | 282 |
279 void EncryptedMediaPlayerSupport::OnPipelineDecryptError() { | 283 void EncryptedMediaPlayerSupport::OnPipelineDecryptError() { |
280 EmeUMAHistogramCounts(current_key_system_, "DecryptError", 1); | 284 EmeUMAHistogramCounts(current_key_system_, "DecryptError", 1); |
281 } | 285 } |
282 | 286 |
283 void EncryptedMediaPlayerSupport::OnKeyAdded(const std::string& session_id) { | 287 void EncryptedMediaPlayerSupport::OnKeyAdded(const std::string& session_id) { |
284 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); | 288 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); |
285 client_->keyAdded( | 289 client_->keyAdded( |
ddorwin
2015/05/26 21:43:07
This would result in two events if the encrypted_c
Srirama
2015/05/27 14:48:50
The client_ event will be dummy as i have kept emp
| |
286 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), | 290 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), |
287 WebString::fromUTF8(session_id)); | 291 WebString::fromUTF8(session_id)); |
292 if (encrypted_client_) | |
293 encrypted_client_->keyAdded( | |
294 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), | |
295 WebString::fromUTF8(session_id)); | |
288 } | 296 } |
289 | 297 |
290 void EncryptedMediaPlayerSupport::OnKeyError(const std::string& session_id, | 298 void EncryptedMediaPlayerSupport::OnKeyError(const std::string& session_id, |
291 MediaKeys::KeyError error_code, | 299 MediaKeys::KeyError error_code, |
292 uint32 system_code) { | 300 uint32 system_code) { |
293 EmeUMAHistogramEnumeration(current_key_system_, "KeyError", | 301 EmeUMAHistogramEnumeration(current_key_system_, "KeyError", |
294 error_code, MediaKeys::kMaxKeyError); | 302 error_code, MediaKeys::kMaxKeyError); |
295 | 303 |
296 uint16 short_system_code = 0; | 304 uint16 short_system_code = 0; |
297 if (system_code > std::numeric_limits<uint16>::max()) { | 305 if (system_code > std::numeric_limits<uint16>::max()) { |
298 LOG(WARNING) << "system_code exceeds unsigned short limit."; | 306 LOG(WARNING) << "system_code exceeds unsigned short limit."; |
299 short_system_code = std::numeric_limits<uint16>::max(); | 307 short_system_code = std::numeric_limits<uint16>::max(); |
300 } else { | 308 } else { |
301 short_system_code = static_cast<uint16>(system_code); | 309 short_system_code = static_cast<uint16>(system_code); |
302 } | 310 } |
303 | 311 |
304 client_->keyError( | 312 client_->keyError( |
305 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), | 313 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), |
306 WebString::fromUTF8(session_id), | 314 WebString::fromUTF8(session_id), |
307 static_cast<WebMediaPlayerClient::MediaKeyErrorCode>(error_code), | 315 static_cast<WebMediaPlayerClient::MediaKeyErrorCode>(error_code), |
308 short_system_code); | 316 short_system_code); |
317 if (encrypted_client_) | |
318 encrypted_client_->keyError( | |
319 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), | |
320 WebString::fromUTF8(session_id), | |
321 static_cast<WebMediaPlayerEncryptedMediaClient::MediaKeyErrorCode>( | |
322 error_code), | |
323 short_system_code); | |
309 } | 324 } |
310 | 325 |
311 void EncryptedMediaPlayerSupport::OnKeyMessage( | 326 void EncryptedMediaPlayerSupport::OnKeyMessage( |
312 const std::string& session_id, | 327 const std::string& session_id, |
313 const std::vector<uint8>& message, | 328 const std::vector<uint8>& message, |
314 const GURL& destination_url) { | 329 const GURL& destination_url) { |
315 DCHECK(destination_url.is_empty() || destination_url.is_valid()); | 330 DCHECK(destination_url.is_empty() || destination_url.is_valid()); |
316 | 331 |
317 client_->keyMessage( | 332 client_->keyMessage( |
318 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), | 333 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), |
319 WebString::fromUTF8(session_id), | 334 WebString::fromUTF8(session_id), |
320 message.empty() ? NULL : &message[0], | 335 message.empty() ? NULL : &message[0], |
321 base::saturated_cast<unsigned int>(message.size()), | 336 base::saturated_cast<unsigned int>(message.size()), |
322 destination_url); | 337 destination_url); |
338 if (encrypted_client_) | |
339 encrypted_client_->keyMessage( | |
340 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), | |
341 WebString::fromUTF8(session_id), message.empty() ? NULL : &message[0], | |
342 base::saturated_cast<unsigned int>(message.size()), destination_url); | |
323 } | 343 } |
324 | 344 |
325 } // namespace media | 345 } // namespace media |
OLD | NEW |