| 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 "content/renderer/media/android/webmediaplayer_android.h" | 5 #include "content/renderer/media/android/webmediaplayer_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| 11 #include "base/android/build_info.h" | 11 #include "base/android/build_info.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "cc/blink/web_layer_impl.h" | 21 #include "cc/blink/web_layer_impl.h" |
| 22 #include "cc/layers/video_layer.h" | 22 #include "cc/layers/video_layer.h" |
| 23 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
| 24 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 25 #include "content/public/common/renderer_preferences.h" | 25 #include "content/public/common/renderer_preferences.h" |
| 26 #include "content/public/renderer/render_frame.h" | 26 #include "content/public/renderer/render_frame.h" |
| 27 #include "content/renderer/media/android/renderer_demuxer_android.h" | 27 #include "content/renderer/media/android/renderer_demuxer_android.h" |
| 28 #include "content/renderer/media/android/renderer_media_player_manager.h" | 28 #include "content/renderer/media/android/renderer_media_player_manager.h" |
| 29 #include "content/renderer/media/cdm/render_cdm_factory.h" | |
| 30 #include "content/renderer/media/cdm/renderer_cdm_manager.h" | |
| 31 #include "content/renderer/render_frame_impl.h" | 29 #include "content/renderer/render_frame_impl.h" |
| 32 #include "content/renderer/render_thread_impl.h" | 30 #include "content/renderer/render_thread_impl.h" |
| 33 #include "content/renderer/render_view_impl.h" | 31 #include "content/renderer/render_view_impl.h" |
| 34 #include "gpu/GLES2/gl2extchromium.h" | 32 #include "gpu/GLES2/gl2extchromium.h" |
| 35 #include "gpu/command_buffer/client/gles2_interface.h" | 33 #include "gpu/command_buffer/client/gles2_interface.h" |
| 36 #include "gpu/command_buffer/common/constants.h" | 34 #include "gpu/command_buffer/common/constants.h" |
| 37 #include "gpu/command_buffer/common/mailbox_holder.h" | 35 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 38 #include "media/base/android/media_codec_util.h" | 36 #include "media/base/android/media_codec_util.h" |
| 39 #include "media/base/android/media_common_android.h" | 37 #include "media/base/android/media_common_android.h" |
| 40 #include "media/base/android/media_player_android.h" | 38 #include "media/base/android/media_player_android.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } // namespace | 171 } // namespace |
| 174 | 172 |
| 175 namespace content { | 173 namespace content { |
| 176 | 174 |
| 177 WebMediaPlayerAndroid::WebMediaPlayerAndroid( | 175 WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
| 178 blink::WebFrame* frame, | 176 blink::WebFrame* frame, |
| 179 blink::WebMediaPlayerClient* client, | 177 blink::WebMediaPlayerClient* client, |
| 180 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | 178 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
| 181 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 179 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
| 182 RendererMediaPlayerManager* player_manager, | 180 RendererMediaPlayerManager* player_manager, |
| 183 media::CdmFactory* cdm_factory, | |
| 184 scoped_refptr<StreamTextureFactory> factory, | 181 scoped_refptr<StreamTextureFactory> factory, |
| 185 int frame_id, | 182 int frame_id, |
| 186 bool enable_texture_copy, | 183 bool enable_texture_copy, |
| 187 const media::WebMediaPlayerParams& params) | 184 const media::WebMediaPlayerParams& params) |
| 188 : frame_(frame), | 185 : frame_(frame), |
| 189 client_(client), | 186 client_(client), |
| 190 encrypted_client_(encrypted_client), | 187 encrypted_client_(encrypted_client), |
| 191 delegate_(delegate), | 188 delegate_(delegate), |
| 192 delegate_id_(0), | 189 delegate_id_(0), |
| 193 defer_load_cb_(params.defer_load_cb()), | 190 defer_load_cb_(params.defer_load_cb()), |
| 194 buffered_(static_cast<size_t>(1)), | 191 buffered_(static_cast<size_t>(1)), |
| 195 media_task_runner_(params.media_task_runner()), | 192 media_task_runner_(params.media_task_runner()), |
| 196 ignore_metadata_duration_change_(false), | 193 ignore_metadata_duration_change_(false), |
| 197 pending_seek_(false), | 194 pending_seek_(false), |
| 198 seeking_(false), | 195 seeking_(false), |
| 199 did_loading_progress_(false), | 196 did_loading_progress_(false), |
| 200 player_manager_(player_manager), | 197 player_manager_(player_manager), |
| 201 cdm_factory_(cdm_factory), | |
| 202 media_permission_(params.media_permission()), | |
| 203 network_state_(WebMediaPlayer::NetworkStateEmpty), | 198 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 204 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 199 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 205 texture_id_(0), | 200 texture_id_(0), |
| 206 stream_id_(0), | 201 stream_id_(0), |
| 207 is_player_initialized_(false), | 202 is_player_initialized_(false), |
| 208 is_playing_(false), | 203 is_playing_(false), |
| 209 needs_establish_peer_(true), | 204 needs_establish_peer_(true), |
| 210 has_size_info_(false), | 205 has_size_info_(false), |
| 211 // Threaded compositing isn't enabled universally yet. | 206 // Threaded compositing isn't enabled universally yet. |
| 212 compositor_task_runner_(params.compositor_task_runner() | 207 compositor_task_runner_(params.compositor_task_runner() |
| 213 ? params.compositor_task_runner() | 208 ? params.compositor_task_runner() |
| 214 : base::ThreadTaskRunnerHandle::Get()), | 209 : base::ThreadTaskRunnerHandle::Get()), |
| 215 stream_texture_factory_(factory), | 210 stream_texture_factory_(factory), |
| 216 needs_external_surface_(false), | 211 needs_external_surface_(false), |
| 217 is_fullscreen_(false), | 212 is_fullscreen_(false), |
| 218 video_frame_provider_client_(nullptr), | 213 video_frame_provider_client_(nullptr), |
| 219 player_type_(MEDIA_PLAYER_TYPE_URL), | 214 player_type_(MEDIA_PLAYER_TYPE_URL), |
| 220 is_remote_(false), | 215 is_remote_(false), |
| 221 media_log_(params.media_log()), | 216 media_log_(params.media_log()), |
| 222 init_data_type_(media::EmeInitDataType::UNKNOWN), | |
| 223 cdm_context_(nullptr), | 217 cdm_context_(nullptr), |
| 224 allow_stored_credentials_(false), | 218 allow_stored_credentials_(false), |
| 225 is_local_resource_(false), | 219 is_local_resource_(false), |
| 226 interpolator_(&default_tick_clock_), | 220 interpolator_(&default_tick_clock_), |
| 227 frame_id_(frame_id), | 221 frame_id_(frame_id), |
| 228 enable_texture_copy_(enable_texture_copy), | 222 enable_texture_copy_(enable_texture_copy), |
| 229 suppress_deleting_texture_(false), | 223 suppress_deleting_texture_(false), |
| 230 playback_completed_(false), | 224 playback_completed_(false), |
| 231 volume_(1.0), | 225 volume_(1.0), |
| 232 volume_multiplier_(1.0), | 226 volume_multiplier_(1.0), |
| 233 weak_factory_(this) { | 227 weak_factory_(this) { |
| 234 DCHECK(player_manager_); | 228 DCHECK(player_manager_); |
| 235 DCHECK(cdm_factory_); | |
| 236 | 229 |
| 237 DCHECK(main_thread_checker_.CalledOnValidThread()); | 230 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 238 stream_texture_factory_->AddObserver(this); | 231 stream_texture_factory_->AddObserver(this); |
| 239 | 232 |
| 240 if (delegate_) | 233 if (delegate_) |
| 241 delegate_id_ = delegate_->AddObserver(this); | 234 delegate_id_ = delegate_->AddObserver(this); |
| 242 | 235 |
| 243 player_id_ = player_manager_->RegisterMediaPlayer(this); | 236 player_id_ = player_manager_->RegisterMediaPlayer(this); |
| 244 | 237 |
| 245 #if defined(VIDEO_HOLE) | 238 #if defined(VIDEO_HOLE) |
| (...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1432 // Store the changed geometry information when it is actually changed. | 1425 // Store the changed geometry information when it is actually changed. |
| 1433 last_computed_rect_ = rect; | 1426 last_computed_rect_ = rect; |
| 1434 return true; | 1427 return true; |
| 1435 } | 1428 } |
| 1436 | 1429 |
| 1437 const gfx::RectF WebMediaPlayerAndroid::GetBoundaryRectangle() { | 1430 const gfx::RectF WebMediaPlayerAndroid::GetBoundaryRectangle() { |
| 1438 return last_computed_rect_; | 1431 return last_computed_rect_; |
| 1439 } | 1432 } |
| 1440 #endif | 1433 #endif |
| 1441 | 1434 |
| 1442 // The following EME related code is copied from WebMediaPlayerImpl. | |
| 1443 // TODO(xhwang): Remove duplicate code between WebMediaPlayerAndroid and | |
| 1444 // WebMediaPlayerImpl. | |
| 1445 | |
| 1446 // Convert a WebString to ASCII, falling back on an empty string in the case | |
| 1447 // of a non-ASCII string. | |
| 1448 static std::string ToASCIIOrEmpty(const blink::WebString& string) { | |
| 1449 return base::IsStringASCII(string) | |
| 1450 ? base::UTF16ToASCII(base::StringPiece16(string)) | |
| 1451 : std::string(); | |
| 1452 } | |
| 1453 | |
| 1454 // Helper functions to report media EME related stats to UMA. They follow the | |
| 1455 // convention of more commonly used macros UMA_HISTOGRAM_ENUMERATION and | |
| 1456 // UMA_HISTOGRAM_COUNTS. The reason that we cannot use those macros directly is | |
| 1457 // that UMA_* macros require the names to be constant throughout the process' | |
| 1458 // lifetime. | |
| 1459 | |
| 1460 static void EmeUMAHistogramEnumeration(const std::string& key_system, | |
| 1461 const std::string& method, | |
| 1462 int sample, | |
| 1463 int boundary_value) { | |
| 1464 base::LinearHistogram::FactoryGet( | |
| 1465 kMediaEme + media::GetKeySystemNameForUMA(key_system) + "." + method, | |
| 1466 1, boundary_value, boundary_value + 1, | |
| 1467 base::Histogram::kUmaTargetedHistogramFlag)->Add(sample); | |
| 1468 } | |
| 1469 | |
| 1470 static void EmeUMAHistogramCounts(const std::string& key_system, | |
| 1471 const std::string& method, | |
| 1472 int sample) { | |
| 1473 // Use the same parameters as UMA_HISTOGRAM_COUNTS. | |
| 1474 base::Histogram::FactoryGet( | |
| 1475 kMediaEme + media::GetKeySystemNameForUMA(key_system) + "." + method, | |
| 1476 1, 1000000, 50, base::Histogram::kUmaTargetedHistogramFlag)->Add(sample); | |
| 1477 } | |
| 1478 | |
| 1479 // Helper enum for reporting generateKeyRequest/addKey histograms. | |
| 1480 enum MediaKeyException { | |
| 1481 kUnknownResultId, | |
| 1482 kSuccess, | |
| 1483 kKeySystemNotSupported, | |
| 1484 kInvalidPlayerState, | |
| 1485 kMaxMediaKeyException | |
| 1486 }; | |
| 1487 | |
| 1488 static MediaKeyException MediaKeyExceptionForUMA( | |
| 1489 WebMediaPlayer::MediaKeyException e) { | |
| 1490 switch (e) { | |
| 1491 case WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported: | |
| 1492 return kKeySystemNotSupported; | |
| 1493 case WebMediaPlayer::MediaKeyExceptionInvalidPlayerState: | |
| 1494 return kInvalidPlayerState; | |
| 1495 case WebMediaPlayer::MediaKeyExceptionNoError: | |
| 1496 return kSuccess; | |
| 1497 default: | |
| 1498 return kUnknownResultId; | |
| 1499 } | |
| 1500 } | |
| 1501 | |
| 1502 // Helper for converting |key_system| name and exception |e| to a pair of enum | |
| 1503 // values from above, for reporting to UMA. | |
| 1504 static void ReportMediaKeyExceptionToUMA(const std::string& method, | |
| 1505 const std::string& key_system, | |
| 1506 WebMediaPlayer::MediaKeyException e) { | |
| 1507 MediaKeyException result_id = MediaKeyExceptionForUMA(e); | |
| 1508 DCHECK_NE(result_id, kUnknownResultId) << e; | |
| 1509 EmeUMAHistogramEnumeration( | |
| 1510 key_system, method, result_id, kMaxMediaKeyException); | |
| 1511 } | |
| 1512 | |
| 1513 bool WebMediaPlayerAndroid::IsKeySystemSupported( | |
| 1514 const std::string& key_system) { | |
| 1515 // On Android, EME only works with MSE. | |
| 1516 return player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && | |
| 1517 media::PrefixedIsSupportedConcreteKeySystem(key_system); | |
| 1518 } | |
| 1519 | |
| 1520 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::generateKeyRequest( | |
| 1521 const WebString& key_system, | |
| 1522 const unsigned char* init_data, | |
| 1523 unsigned init_data_length) { | |
| 1524 DVLOG(1) << "generateKeyRequest: " << base::string16(key_system) << ": " | |
| 1525 << std::string(reinterpret_cast<const char*>(init_data), | |
| 1526 static_cast<size_t>(init_data_length)); | |
| 1527 | |
| 1528 std::string ascii_key_system = | |
| 1529 media::GetUnprefixedKeySystemName(ToASCIIOrEmpty(key_system)); | |
| 1530 | |
| 1531 WebMediaPlayer::MediaKeyException e = | |
| 1532 GenerateKeyRequestInternal(ascii_key_system, init_data, init_data_length); | |
| 1533 ReportMediaKeyExceptionToUMA("generateKeyRequest", ascii_key_system, e); | |
| 1534 return e; | |
| 1535 } | |
| 1536 | |
| 1537 // Guess the type of |init_data|. This is only used to handle some corner cases | |
| 1538 // so we keep it as simple as possible without breaking major use cases. | |
| 1539 static media::EmeInitDataType GuessInitDataType(const unsigned char* init_data, | |
| 1540 unsigned init_data_length) { | |
| 1541 // Most WebM files use KeyId of 16 bytes. CENC init data is always >16 bytes. | |
| 1542 if (init_data_length == 16) | |
| 1543 return media::EmeInitDataType::WEBM; | |
| 1544 | |
| 1545 return media::EmeInitDataType::CENC; | |
| 1546 } | |
| 1547 | |
| 1548 // TODO(xhwang): Report an error when there is encrypted stream but EME is | |
| 1549 // not enabled. Currently the player just doesn't start and waits for | |
| 1550 // ever. | |
| 1551 WebMediaPlayer::MediaKeyException | |
| 1552 WebMediaPlayerAndroid::GenerateKeyRequestInternal( | |
| 1553 const std::string& key_system, | |
| 1554 const unsigned char* init_data, | |
| 1555 unsigned init_data_length) { | |
| 1556 if (!IsKeySystemSupported(key_system)) | |
| 1557 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | |
| 1558 | |
| 1559 if (!proxy_decryptor_) { | |
| 1560 DCHECK(current_key_system_.empty()); | |
| 1561 proxy_decryptor_.reset(new media::ProxyDecryptor( | |
| 1562 media_permission_, | |
| 1563 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo(), | |
| 1564 base::Bind(&WebMediaPlayerAndroid::OnKeyAdded, | |
| 1565 weak_factory_.GetWeakPtr()), | |
| 1566 base::Bind(&WebMediaPlayerAndroid::OnKeyError, | |
| 1567 weak_factory_.GetWeakPtr()), | |
| 1568 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage, | |
| 1569 weak_factory_.GetWeakPtr()))); | |
| 1570 | |
| 1571 GURL security_origin( | |
| 1572 blink::WebStringToGURL(frame_->document().securityOrigin().toString())); | |
| 1573 proxy_decryptor_->CreateCdm( | |
| 1574 cdm_factory_, key_system, security_origin, | |
| 1575 base::Bind(&WebMediaPlayerAndroid::OnCdmContextReady, | |
| 1576 weak_factory_.GetWeakPtr())); | |
| 1577 current_key_system_ = key_system; | |
| 1578 } | |
| 1579 | |
| 1580 // We do not support run-time switching between key systems for now. | |
| 1581 DCHECK(!current_key_system_.empty()); | |
| 1582 if (key_system != current_key_system_) | |
| 1583 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | |
| 1584 | |
| 1585 media::EmeInitDataType init_data_type = init_data_type_; | |
| 1586 if (init_data_type == media::EmeInitDataType::UNKNOWN) | |
| 1587 init_data_type = GuessInitDataType(init_data, init_data_length); | |
| 1588 | |
| 1589 proxy_decryptor_->GenerateKeyRequest(init_data_type, init_data, | |
| 1590 init_data_length); | |
| 1591 | |
| 1592 return WebMediaPlayer::MediaKeyExceptionNoError; | |
| 1593 } | |
| 1594 | |
| 1595 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( | |
| 1596 const WebString& key_system, | |
| 1597 const unsigned char* key, | |
| 1598 unsigned key_length, | |
| 1599 const unsigned char* init_data, | |
| 1600 unsigned init_data_length, | |
| 1601 const WebString& session_id) { | |
| 1602 DVLOG(1) << "addKey: " << base::string16(key_system) << ": " | |
| 1603 << std::string(reinterpret_cast<const char*>(key), | |
| 1604 static_cast<size_t>(key_length)) << ", " | |
| 1605 << std::string(reinterpret_cast<const char*>(init_data), | |
| 1606 static_cast<size_t>(init_data_length)) << " [" | |
| 1607 << base::string16(session_id) << "]"; | |
| 1608 | |
| 1609 std::string ascii_key_system = | |
| 1610 media::GetUnprefixedKeySystemName(ToASCIIOrEmpty(key_system)); | |
| 1611 std::string ascii_session_id = ToASCIIOrEmpty(session_id); | |
| 1612 | |
| 1613 WebMediaPlayer::MediaKeyException e = AddKeyInternal(ascii_key_system, | |
| 1614 key, | |
| 1615 key_length, | |
| 1616 init_data, | |
| 1617 init_data_length, | |
| 1618 ascii_session_id); | |
| 1619 ReportMediaKeyExceptionToUMA("addKey", ascii_key_system, e); | |
| 1620 return e; | |
| 1621 } | |
| 1622 | |
| 1623 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::AddKeyInternal( | |
| 1624 const std::string& key_system, | |
| 1625 const unsigned char* key, | |
| 1626 unsigned key_length, | |
| 1627 const unsigned char* init_data, | |
| 1628 unsigned init_data_length, | |
| 1629 const std::string& session_id) { | |
| 1630 DCHECK(key); | |
| 1631 DCHECK_GT(key_length, 0u); | |
| 1632 | |
| 1633 if (!IsKeySystemSupported(key_system)) | |
| 1634 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | |
| 1635 | |
| 1636 if (current_key_system_.empty() || key_system != current_key_system_) | |
| 1637 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | |
| 1638 | |
| 1639 proxy_decryptor_->AddKey( | |
| 1640 key, key_length, init_data, init_data_length, session_id); | |
| 1641 return WebMediaPlayer::MediaKeyExceptionNoError; | |
| 1642 } | |
| 1643 | |
| 1644 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::cancelKeyRequest( | |
| 1645 const WebString& key_system, | |
| 1646 const WebString& session_id) { | |
| 1647 DVLOG(1) << "cancelKeyRequest: " << base::string16(key_system) << ": " | |
| 1648 << " [" << base::string16(session_id) << "]"; | |
| 1649 | |
| 1650 std::string ascii_key_system = | |
| 1651 media::GetUnprefixedKeySystemName(ToASCIIOrEmpty(key_system)); | |
| 1652 std::string ascii_session_id = ToASCIIOrEmpty(session_id); | |
| 1653 | |
| 1654 WebMediaPlayer::MediaKeyException e = | |
| 1655 CancelKeyRequestInternal(ascii_key_system, ascii_session_id); | |
| 1656 ReportMediaKeyExceptionToUMA("cancelKeyRequest", ascii_key_system, e); | |
| 1657 return e; | |
| 1658 } | |
| 1659 | |
| 1660 WebMediaPlayer::MediaKeyException | |
| 1661 WebMediaPlayerAndroid::CancelKeyRequestInternal(const std::string& key_system, | |
| 1662 const std::string& session_id) { | |
| 1663 if (!IsKeySystemSupported(key_system)) | |
| 1664 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | |
| 1665 | |
| 1666 if (current_key_system_.empty() || key_system != current_key_system_) | |
| 1667 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | |
| 1668 | |
| 1669 proxy_decryptor_->CancelKeyRequest(session_id); | |
| 1670 return WebMediaPlayer::MediaKeyExceptionNoError; | |
| 1671 } | |
| 1672 | |
| 1673 void WebMediaPlayerAndroid::setContentDecryptionModule( | 1435 void WebMediaPlayerAndroid::setContentDecryptionModule( |
| 1674 blink::WebContentDecryptionModule* cdm, | 1436 blink::WebContentDecryptionModule* cdm, |
| 1675 blink::WebContentDecryptionModuleResult result) { | 1437 blink::WebContentDecryptionModuleResult result) { |
| 1676 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1438 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1677 | 1439 |
| 1678 // Once the CDM is set it can't be cleared as there may be frames being | 1440 // Once the CDM is set it can't be cleared as there may be frames being |
| 1679 // decrypted on other threads. So fail this request. | 1441 // decrypted on other threads. So fail this request. |
| 1680 // http://crbug.com/462365#c7. | 1442 // http://crbug.com/462365#c7. |
| 1681 if (!cdm) { | 1443 if (!cdm) { |
| 1682 result.completeWithError( | 1444 result.completeWithError( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1705 result.complete(); | 1467 result.complete(); |
| 1706 return; | 1468 return; |
| 1707 } | 1469 } |
| 1708 | 1470 |
| 1709 result.completeWithError( | 1471 result.completeWithError( |
| 1710 blink::WebContentDecryptionModuleExceptionNotSupportedError, | 1472 blink::WebContentDecryptionModuleExceptionNotSupportedError, |
| 1711 0, | 1473 0, |
| 1712 "Unable to set MediaKeys object"); | 1474 "Unable to set MediaKeys object"); |
| 1713 } | 1475 } |
| 1714 | 1476 |
| 1715 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { | |
| 1716 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); | |
| 1717 | |
| 1718 encrypted_client_->keyAdded( | |
| 1719 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), | |
| 1720 WebString::fromUTF8(session_id)); | |
| 1721 } | |
| 1722 | |
| 1723 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, | |
| 1724 media::MediaKeys::KeyError error_code, | |
| 1725 uint32_t system_code) { | |
| 1726 EmeUMAHistogramEnumeration(current_key_system_, "KeyError", | |
| 1727 error_code, media::MediaKeys::kMaxKeyError); | |
| 1728 | |
| 1729 unsigned short short_system_code = 0; | |
| 1730 if (system_code > std::numeric_limits<unsigned short>::max()) { | |
| 1731 LOG(WARNING) << "system_code exceeds unsigned short limit."; | |
| 1732 short_system_code = std::numeric_limits<unsigned short>::max(); | |
| 1733 } else { | |
| 1734 short_system_code = static_cast<unsigned short>(system_code); | |
| 1735 } | |
| 1736 | |
| 1737 encrypted_client_->keyError( | |
| 1738 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), | |
| 1739 WebString::fromUTF8(session_id), | |
| 1740 static_cast<blink::WebMediaPlayerEncryptedMediaClient::MediaKeyErrorCode>( | |
| 1741 error_code), | |
| 1742 short_system_code); | |
| 1743 } | |
| 1744 | |
| 1745 void WebMediaPlayerAndroid::OnKeyMessage(const std::string& session_id, | |
| 1746 const std::vector<uint8_t>& message, | |
| 1747 const GURL& destination_url) { | |
| 1748 DCHECK(destination_url.is_empty() || destination_url.is_valid()); | |
| 1749 | |
| 1750 encrypted_client_->keyMessage( | |
| 1751 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), | |
| 1752 WebString::fromUTF8(session_id), message.empty() ? NULL : &message[0], | |
| 1753 message.size(), destination_url); | |
| 1754 } | |
| 1755 | |
| 1756 void WebMediaPlayerAndroid::OnMediaSourceOpened( | 1477 void WebMediaPlayerAndroid::OnMediaSourceOpened( |
| 1757 blink::WebMediaSource* web_media_source) { | 1478 blink::WebMediaSource* web_media_source) { |
| 1758 client_->mediaSourceOpened(web_media_source); | 1479 client_->mediaSourceOpened(web_media_source); |
| 1759 } | 1480 } |
| 1760 | 1481 |
| 1761 void WebMediaPlayerAndroid::OnEncryptedMediaInitData( | 1482 void WebMediaPlayerAndroid::OnEncryptedMediaInitData( |
| 1762 media::EmeInitDataType init_data_type, | 1483 media::EmeInitDataType init_data_type, |
| 1763 const std::vector<uint8_t>& init_data) { | 1484 const std::vector<uint8_t>& init_data) { |
| 1764 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1485 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1765 | 1486 |
| 1766 // Do not fire NeedKey event if encrypted media is not enabled. | 1487 // Do not fire the "encrypted" event if Encrypted Media is not enabled. |
| 1767 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && | 1488 // EME may not be enabled on Android Jelly Bean. |
| 1768 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { | 1489 if (!blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { |
| 1769 return; | 1490 return; |
| 1770 } | 1491 } |
| 1771 | 1492 |
| 1772 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); | 1493 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); |
| 1773 | 1494 |
| 1774 DCHECK(init_data_type != media::EmeInitDataType::UNKNOWN); | 1495 DCHECK(init_data_type != media::EmeInitDataType::UNKNOWN); |
| 1775 DLOG_IF(WARNING, init_data_type_ != media::EmeInitDataType::UNKNOWN && | |
| 1776 init_data_type != init_data_type_) | |
| 1777 << "Mixed init data type not supported. The new type is ignored."; | |
| 1778 if (init_data_type_ == media::EmeInitDataType::UNKNOWN) | |
| 1779 init_data_type_ = init_data_type; | |
| 1780 | 1496 |
| 1781 encrypted_client_->encrypted(ConvertToWebInitDataType(init_data_type), | 1497 encrypted_client_->encrypted(ConvertToWebInitDataType(init_data_type), |
| 1782 init_data.data(), init_data.size()); | 1498 init_data.data(), init_data.size()); |
| 1783 } | 1499 } |
| 1784 | 1500 |
| 1785 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { | 1501 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { |
| 1786 encrypted_client_->didBlockPlaybackWaitingForKey(); | 1502 encrypted_client_->didBlockPlaybackWaitingForKey(); |
| 1787 | 1503 |
| 1788 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called | 1504 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called |
| 1789 // when a key has been successfully added (e.g. OnSessionKeysChange() with | 1505 // when a key has been successfully added (e.g. OnSessionKeysChange() with |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1940 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; | 1656 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; |
| 1941 } else if (is_hls_url == is_hls) { | 1657 } else if (is_hls_url == is_hls) { |
| 1942 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; | 1658 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; |
| 1943 } | 1659 } |
| 1944 UMA_HISTOGRAM_ENUMERATION( | 1660 UMA_HISTOGRAM_ENUMERATION( |
| 1945 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", | 1661 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", |
| 1946 result, PREDICTION_RESULT_MAX); | 1662 result, PREDICTION_RESULT_MAX); |
| 1947 } | 1663 } |
| 1948 | 1664 |
| 1949 } // namespace content | 1665 } // namespace content |
| OLD | NEW |