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 1509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1520 // not enabled. Currently the player just doesn't start and waits for | 1520 // not enabled. Currently the player just doesn't start and waits for |
1521 // ever. | 1521 // ever. |
1522 WebMediaPlayer::MediaKeyException | 1522 WebMediaPlayer::MediaKeyException |
1523 WebMediaPlayerAndroid::GenerateKeyRequestInternal( | 1523 WebMediaPlayerAndroid::GenerateKeyRequestInternal( |
1524 const std::string& key_system, | 1524 const std::string& key_system, |
1525 const unsigned char* init_data, | 1525 const unsigned char* init_data, |
1526 unsigned init_data_length) { | 1526 unsigned init_data_length) { |
1527 if (!IsKeySystemSupported(key_system)) | 1527 if (!IsKeySystemSupported(key_system)) |
1528 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 1528 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
1529 | 1529 |
1530 // We do not support run-time switching between key systems for now. | 1530 if (!proxy_decryptor_) { |
1531 if (current_key_system_.empty()) { | 1531 DCHECK(current_key_system_.empty()); |
1532 if (!proxy_decryptor_) { | 1532 proxy_decryptor_.reset(new media::ProxyDecryptor( |
1533 proxy_decryptor_.reset(new media::ProxyDecryptor( | 1533 media_permission_, base::Bind(&WebMediaPlayerAndroid::OnKeyAdded, |
1534 media_permission_, | 1534 weak_factory_.GetWeakPtr()), |
1535 base::Bind(&WebMediaPlayerAndroid::OnKeyAdded, | 1535 base::Bind(&WebMediaPlayerAndroid::OnKeyError, |
1536 weak_factory_.GetWeakPtr()), | 1536 weak_factory_.GetWeakPtr()), |
1537 base::Bind(&WebMediaPlayerAndroid::OnKeyError, | 1537 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage, |
1538 weak_factory_.GetWeakPtr()), | 1538 weak_factory_.GetWeakPtr()))); |
1539 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage, | |
1540 weak_factory_.GetWeakPtr()))); | |
1541 } | |
1542 | 1539 |
1543 GURL security_origin(frame_->document().securityOrigin().toString()); | 1540 GURL security_origin(frame_->document().securityOrigin().toString()); |
1544 if (!proxy_decryptor_->InitializeCDM(cdm_factory_, key_system, | 1541 proxy_decryptor_->CreateCdm( |
1545 security_origin)) { | 1542 cdm_factory_, key_system, security_origin, |
1546 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 1543 base::Bind(&WebMediaPlayerAndroid::OnCdmContextReady, |
1547 } | 1544 weak_factory_.GetWeakPtr())); |
| 1545 current_key_system_ = key_system; |
| 1546 } |
1548 | 1547 |
1549 // Set the CDM onto the media player. | 1548 // We do not support run-time switching between key systems for now. |
1550 cdm_context_ = proxy_decryptor_->GetCdmContext(); | 1549 DCHECK(!current_key_system_.empty()); |
1551 | 1550 if (key_system != current_key_system_) |
1552 if (is_player_initialized_) | |
1553 SetCdmInternal(base::Bind(&media::IgnoreCdmAttached)); | |
1554 | |
1555 current_key_system_ = key_system; | |
1556 } else if (key_system != current_key_system_) { | |
1557 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 1551 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
1558 } | |
1559 | 1552 |
1560 media::EmeInitDataType init_data_type = init_data_type_; | 1553 media::EmeInitDataType init_data_type = init_data_type_; |
1561 if (init_data_type == media::EmeInitDataType::UNKNOWN) | 1554 if (init_data_type == media::EmeInitDataType::UNKNOWN) |
1562 init_data_type = GuessInitDataType(init_data, init_data_length); | 1555 init_data_type = GuessInitDataType(init_data, init_data_length); |
1563 | 1556 |
1564 // TODO(xhwang): We assume all streams are from the same container (thus have | 1557 proxy_decryptor_->GenerateKeyRequest(init_data_type, init_data, |
1565 // the same "type") for now. In the future, the "type" should be passed down | 1558 init_data_length); |
1566 // from the application. | |
1567 if (!proxy_decryptor_->GenerateKeyRequest( | |
1568 init_data_type, init_data, init_data_length)) { | |
1569 current_key_system_.clear(); | |
1570 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | |
1571 } | |
1572 | 1559 |
1573 return WebMediaPlayer::MediaKeyExceptionNoError; | 1560 return WebMediaPlayer::MediaKeyExceptionNoError; |
1574 } | 1561 } |
1575 | 1562 |
1576 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( | 1563 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( |
1577 const WebString& key_system, | 1564 const WebString& key_system, |
1578 const unsigned char* key, | 1565 const unsigned char* key, |
1579 unsigned key_length, | 1566 unsigned key_length, |
1580 const unsigned char* init_data, | 1567 const unsigned char* init_data, |
1581 unsigned init_data_length, | 1568 unsigned init_data_length, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1765 | 1752 |
1766 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { | 1753 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { |
1767 client_->didBlockPlaybackWaitingForKey(); | 1754 client_->didBlockPlaybackWaitingForKey(); |
1768 | 1755 |
1769 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called | 1756 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called |
1770 // when a key has been successfully added (e.g. OnSessionKeysChange() with | 1757 // when a key has been successfully added (e.g. OnSessionKeysChange() with |
1771 // |has_additional_usable_key| = true). http://crbug.com/461903 | 1758 // |has_additional_usable_key| = true). http://crbug.com/461903 |
1772 client_->didResumePlaybackBlockedForKey(); | 1759 client_->didResumePlaybackBlockedForKey(); |
1773 } | 1760 } |
1774 | 1761 |
| 1762 void WebMediaPlayerAndroid::OnCdmContextReady(media::CdmContext* cdm_context) { |
| 1763 DCHECK(!cdm_context_); |
| 1764 |
| 1765 if (!cdm_context) { |
| 1766 LOG(ERROR) << "CdmContext not available (e.g. CDM creation failed)."; |
| 1767 return; |
| 1768 } |
| 1769 |
| 1770 cdm_context_ = cdm_context; |
| 1771 |
| 1772 if (is_player_initialized_) |
| 1773 SetCdmInternal(base::Bind(&media::IgnoreCdmAttached)); |
| 1774 } |
| 1775 |
1775 void WebMediaPlayerAndroid::SetCdmInternal( | 1776 void WebMediaPlayerAndroid::SetCdmInternal( |
1776 const media::CdmAttachedCB& cdm_attached_cb) { | 1777 const media::CdmAttachedCB& cdm_attached_cb) { |
1777 DCHECK(cdm_context_ && is_player_initialized_); | 1778 DCHECK(cdm_context_ && is_player_initialized_); |
1778 DCHECK(cdm_context_->GetDecryptor() || | 1779 DCHECK(cdm_context_->GetDecryptor() || |
1779 cdm_context_->GetCdmId() != media::CdmContext::kInvalidCdmId) | 1780 cdm_context_->GetCdmId() != media::CdmContext::kInvalidCdmId) |
1780 << "CDM should support either a Decryptor or a CDM ID."; | 1781 << "CDM should support either a Decryptor or a CDM ID."; |
1781 | 1782 |
1782 media::Decryptor* decryptor = cdm_context_->GetDecryptor(); | 1783 media::Decryptor* decryptor = cdm_context_->GetDecryptor(); |
1783 | 1784 |
1784 // Note: | 1785 // Note: |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1848 | 1849 |
1849 bool WebMediaPlayerAndroid::IsHLSStream() const { | 1850 bool WebMediaPlayerAndroid::IsHLSStream() const { |
1850 std::string mime; | 1851 std::string mime; |
1851 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; | 1852 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; |
1852 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) | 1853 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) |
1853 return false; | 1854 return false; |
1854 return !mime.compare("application/x-mpegurl"); | 1855 return !mime.compare("application/x-mpegurl"); |
1855 } | 1856 } |
1856 | 1857 |
1857 } // namespace content | 1858 } // namespace content |
OLD | NEW |