| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "gpu/command_buffer/client/gles2_interface.h" | 34 #include "gpu/command_buffer/client/gles2_interface.h" |
| 35 #include "gpu/command_buffer/common/mailbox_holder.h" | 35 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 36 #include "media/base/android/media_player_android.h" | 36 #include "media/base/android/media_player_android.h" |
| 37 #include "media/base/bind_to_current_loop.h" | 37 #include "media/base/bind_to_current_loop.h" |
| 38 // TODO(xhwang): Remove when we remove prefixed EME implementation. | 38 // TODO(xhwang): Remove when we remove prefixed EME implementation. |
| 39 #include "media/base/media_keys.h" | 39 #include "media/base/media_keys.h" |
| 40 #include "media/base/media_switches.h" | 40 #include "media/base/media_switches.h" |
| 41 #include "media/base/video_frame.h" | 41 #include "media/base/video_frame.h" |
| 42 #include "net/base/mime_util.h" | 42 #include "net/base/mime_util.h" |
| 43 #include "third_party/WebKit/public/platform/Platform.h" | 43 #include "third_party/WebKit/public/platform/Platform.h" |
| 44 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
| 44 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h" | 45 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h" |
| 45 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 46 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| 46 #include "third_party/WebKit/public/platform/WebString.h" | 47 #include "third_party/WebKit/public/platform/WebString.h" |
| 47 #include "third_party/WebKit/public/platform/WebURL.h" | 48 #include "third_party/WebKit/public/platform/WebURL.h" |
| 48 #include "third_party/WebKit/public/web/WebDocument.h" | 49 #include "third_party/WebKit/public/web/WebDocument.h" |
| 49 #include "third_party/WebKit/public/web/WebFrame.h" | 50 #include "third_party/WebKit/public/web/WebFrame.h" |
| 50 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 51 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 51 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 52 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 52 #include "third_party/WebKit/public/web/WebView.h" | 53 #include "third_party/WebKit/public/web/WebView.h" |
| 53 #include "third_party/skia/include/core/SkCanvas.h" | 54 #include "third_party/skia/include/core/SkCanvas.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 return web_graphics_context_->insertSyncPoint(); | 92 return web_graphics_context_->insertSyncPoint(); |
| 92 } | 93 } |
| 93 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE { | 94 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE { |
| 94 web_graphics_context_->waitSyncPoint(sync_point); | 95 web_graphics_context_->waitSyncPoint(sync_point); |
| 95 } | 96 } |
| 96 | 97 |
| 97 private: | 98 private: |
| 98 blink::WebGraphicsContext3D* web_graphics_context_; | 99 blink::WebGraphicsContext3D* web_graphics_context_; |
| 99 }; | 100 }; |
| 100 | 101 |
| 102 // Used for calls to decryptor_ready_cb_ where the result can be ignored. |
| 103 void DoNothing(bool) { |
| 104 } |
| 105 |
| 101 } // namespace | 106 } // namespace |
| 102 | 107 |
| 103 namespace content { | 108 namespace content { |
| 104 | 109 |
| 105 WebMediaPlayerAndroid::WebMediaPlayerAndroid( | 110 WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
| 106 blink::WebFrame* frame, | 111 blink::WebFrame* frame, |
| 107 blink::WebMediaPlayerClient* client, | 112 blink::WebMediaPlayerClient* client, |
| 108 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 113 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
| 109 RendererMediaPlayerManager* player_manager, | 114 RendererMediaPlayerManager* player_manager, |
| 110 RendererCdmManager* cdm_manager, | 115 RendererCdmManager* cdm_manager, |
| (...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage, | 1385 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage, |
| 1381 weak_factory_.GetWeakPtr()))); | 1386 weak_factory_.GetWeakPtr()))); |
| 1382 } | 1387 } |
| 1383 | 1388 |
| 1384 GURL security_origin(frame_->document().securityOrigin().toString()); | 1389 GURL security_origin(frame_->document().securityOrigin().toString()); |
| 1385 if (!proxy_decryptor_->InitializeCDM(key_system, security_origin)) | 1390 if (!proxy_decryptor_->InitializeCDM(key_system, security_origin)) |
| 1386 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 1391 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 1387 | 1392 |
| 1388 if (!decryptor_ready_cb_.is_null()) { | 1393 if (!decryptor_ready_cb_.is_null()) { |
| 1389 base::ResetAndReturn(&decryptor_ready_cb_) | 1394 base::ResetAndReturn(&decryptor_ready_cb_) |
| 1390 .Run(proxy_decryptor_->GetDecryptor()); | 1395 .Run(proxy_decryptor_->GetDecryptor(), base::Bind(DoNothing)); |
| 1391 } | 1396 } |
| 1392 | 1397 |
| 1393 // Only browser CDMs have CDM ID. Render side CDMs (e.g. ClearKey CDM) do | 1398 // Only browser CDMs have CDM ID. Render side CDMs (e.g. ClearKey CDM) do |
| 1394 // not have a CDM ID and there is no need to call player_manager_->SetCdm(). | 1399 // not have a CDM ID and there is no need to call player_manager_->SetCdm(). |
| 1395 if (proxy_decryptor_->GetCdmId() != RendererCdmManager::kInvalidCdmId) | 1400 if (proxy_decryptor_->GetCdmId() != RendererCdmManager::kInvalidCdmId) |
| 1396 player_manager_->SetCdm(player_id_, proxy_decryptor_->GetCdmId()); | 1401 player_manager_->SetCdm(player_id_, proxy_decryptor_->GetCdmId()); |
| 1397 | 1402 |
| 1398 current_key_system_ = key_system; | 1403 current_key_system_ = key_system; |
| 1399 } else if (key_system != current_key_system_) { | 1404 } else if (key_system != current_key_system_) { |
| 1400 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 1405 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1504 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1500 | 1505 |
| 1501 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 | 1506 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 |
| 1502 if (!cdm) | 1507 if (!cdm) |
| 1503 return; | 1508 return; |
| 1504 | 1509 |
| 1505 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); | 1510 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
| 1506 if (!web_cdm_) | 1511 if (!web_cdm_) |
| 1507 return; | 1512 return; |
| 1508 | 1513 |
| 1509 if (!decryptor_ready_cb_.is_null()) | 1514 if (!decryptor_ready_cb_.is_null()) { |
| 1510 base::ResetAndReturn(&decryptor_ready_cb_).Run(web_cdm_->GetDecryptor()); | 1515 base::ResetAndReturn(&decryptor_ready_cb_) |
| 1516 .Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing)); |
| 1517 } |
| 1511 | 1518 |
| 1512 if (web_cdm_->GetCdmId() != RendererCdmManager::kInvalidCdmId) | 1519 if (web_cdm_->GetCdmId() != RendererCdmManager::kInvalidCdmId) |
| 1513 player_manager_->SetCdm(player_id_, web_cdm_->GetCdmId()); | 1520 player_manager_->SetCdm(player_id_, web_cdm_->GetCdmId()); |
| 1514 } | 1521 } |
| 1515 | 1522 |
| 1523 void WebMediaPlayerAndroid::setContentDecryptionModule( |
| 1524 blink::WebContentDecryptionModule* cdm, |
| 1525 blink::WebContentDecryptionModuleResult result) { |
| 1526 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1527 |
| 1528 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 |
| 1529 if (!cdm) { |
| 1530 result.completeWithError( |
| 1531 blink::WebContentDecryptionModuleExceptionNotSupportedError, |
| 1532 0, |
| 1533 "Null MediaKeys object is not supported."); |
| 1534 return; |
| 1535 } |
| 1536 |
| 1537 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
| 1538 DCHECK(web_cdm_); |
| 1539 |
| 1540 if (!decryptor_ready_cb_.is_null()) { |
| 1541 base::ResetAndReturn(&decryptor_ready_cb_).Run( |
| 1542 web_cdm_->GetDecryptor(), |
| 1543 media::BindToCurrentLoop( |
| 1544 base::Bind(&WebMediaPlayerAndroid::ContentDecryptionModuleAttached, |
| 1545 weak_factory_.GetWeakPtr(), |
| 1546 result))); |
| 1547 } else { |
| 1548 // No pipeline/decoder connected, so resolve the promise. When something |
| 1549 // is connected, setting the CDM will happen in SetDecryptorReadyCB(). |
| 1550 ContentDecryptionModuleAttached(result, true); |
| 1551 } |
| 1552 |
| 1553 if (web_cdm_->GetCdmId() != RendererCdmManager::kInvalidCdmId) |
| 1554 player_manager_->SetCdm(player_id_, web_cdm_->GetCdmId()); |
| 1555 } |
| 1556 |
| 1557 void WebMediaPlayerAndroid::setContentDecryptionModuleSync( |
| 1558 blink::WebContentDecryptionModule* cdm) { |
| 1559 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1560 |
| 1561 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 |
| 1562 if (!cdm) |
| 1563 return; |
| 1564 |
| 1565 DCHECK(decryptor_ready_cb_.is_null()); |
| 1566 |
| 1567 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
| 1568 if (web_cdm_->GetCdmId() != RendererCdmManager::kInvalidCdmId) |
| 1569 player_manager_->SetCdm(player_id_, web_cdm_->GetCdmId()); |
| 1570 } |
| 1571 |
| 1572 void WebMediaPlayerAndroid::ContentDecryptionModuleAttached( |
| 1573 blink::WebContentDecryptionModuleResult result, |
| 1574 bool success) { |
| 1575 if (success) { |
| 1576 result.complete(); |
| 1577 return; |
| 1578 } |
| 1579 |
| 1580 result.completeWithError( |
| 1581 blink::WebContentDecryptionModuleExceptionNotSupportedError, |
| 1582 0, |
| 1583 "Unable to set MediaKeys object"); |
| 1584 } |
| 1585 |
| 1516 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { | 1586 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { |
| 1517 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); | 1587 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); |
| 1518 | 1588 |
| 1519 client_->keyAdded( | 1589 client_->keyAdded( |
| 1520 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), | 1590 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), |
| 1521 WebString::fromUTF8(session_id)); | 1591 WebString::fromUTF8(session_id)); |
| 1522 } | 1592 } |
| 1523 | 1593 |
| 1524 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, | 1594 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, |
| 1525 media::MediaKeys::KeyError error_code, | 1595 media::MediaKeys::KeyError error_code, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 client_->keyNeeded( | 1650 client_->keyNeeded( |
| 1581 WebString::fromUTF8(type), init_data_ptr, init_data.size()); | 1651 WebString::fromUTF8(type), init_data_ptr, init_data.size()); |
| 1582 } | 1652 } |
| 1583 | 1653 |
| 1584 void WebMediaPlayerAndroid::SetDecryptorReadyCB( | 1654 void WebMediaPlayerAndroid::SetDecryptorReadyCB( |
| 1585 const media::DecryptorReadyCB& decryptor_ready_cb) { | 1655 const media::DecryptorReadyCB& decryptor_ready_cb) { |
| 1586 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1656 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1587 | 1657 |
| 1588 // Cancels the previous decryptor request. | 1658 // Cancels the previous decryptor request. |
| 1589 if (decryptor_ready_cb.is_null()) { | 1659 if (decryptor_ready_cb.is_null()) { |
| 1590 if (!decryptor_ready_cb_.is_null()) | 1660 if (!decryptor_ready_cb_.is_null()) { |
| 1591 base::ResetAndReturn(&decryptor_ready_cb_).Run(NULL); | 1661 base::ResetAndReturn(&decryptor_ready_cb_) |
| 1662 .Run(NULL, base::Bind(DoNothing)); |
| 1663 } |
| 1592 return; | 1664 return; |
| 1593 } | 1665 } |
| 1594 | 1666 |
| 1595 // TODO(xhwang): Support multiple decryptor notification request (e.g. from | 1667 // TODO(xhwang): Support multiple decryptor notification request (e.g. from |
| 1596 // video and audio). The current implementation is okay for the current | 1668 // video and audio). The current implementation is okay for the current |
| 1597 // media pipeline since we initialize audio and video decoders in sequence. | 1669 // media pipeline since we initialize audio and video decoders in sequence. |
| 1598 // But WebMediaPlayerImpl should not depend on media pipeline's implementation | 1670 // But WebMediaPlayerImpl should not depend on media pipeline's implementation |
| 1599 // detail. | 1671 // detail. |
| 1600 DCHECK(decryptor_ready_cb_.is_null()); | 1672 DCHECK(decryptor_ready_cb_.is_null()); |
| 1601 | 1673 |
| 1602 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. | 1674 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. |
| 1603 DCHECK(!proxy_decryptor_ || !web_cdm_); | 1675 DCHECK(!proxy_decryptor_ || !web_cdm_); |
| 1604 | 1676 |
| 1605 if (proxy_decryptor_) { | 1677 if (proxy_decryptor_) { |
| 1606 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); | 1678 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor(), |
| 1679 base::Bind(DoNothing)); |
| 1607 return; | 1680 return; |
| 1608 } | 1681 } |
| 1609 | 1682 |
| 1610 if (web_cdm_) { | 1683 if (web_cdm_) { |
| 1611 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); | 1684 decryptor_ready_cb.Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing)); |
| 1612 return; | 1685 return; |
| 1613 } | 1686 } |
| 1614 | 1687 |
| 1615 decryptor_ready_cb_ = decryptor_ready_cb; | 1688 decryptor_ready_cb_ = decryptor_ready_cb; |
| 1616 } | 1689 } |
| 1617 | 1690 |
| 1618 void WebMediaPlayerAndroid::enterFullscreen() { | 1691 void WebMediaPlayerAndroid::enterFullscreen() { |
| 1619 if (player_manager_->CanEnterFullscreen(frame_)) { | 1692 if (player_manager_->CanEnterFullscreen(frame_)) { |
| 1620 player_manager_->EnterFullscreen(player_id_, frame_); | 1693 player_manager_->EnterFullscreen(player_id_, frame_); |
| 1621 SetNeedsEstablishPeer(false); | 1694 SetNeedsEstablishPeer(false); |
| 1622 } | 1695 } |
| 1623 } | 1696 } |
| 1624 | 1697 |
| 1625 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1698 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
| 1626 return player_manager_->CanEnterFullscreen(frame_); | 1699 return player_manager_->CanEnterFullscreen(frame_); |
| 1627 } | 1700 } |
| 1628 | 1701 |
| 1629 } // namespace content | 1702 } // namespace content |
| OLD | NEW |