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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 blink::WebGraphicsContext3D* web_graphics_context_; | 141 blink::WebGraphicsContext3D* web_graphics_context_; |
142 }; | 142 }; |
143 | 143 |
144 } // namespace | 144 } // namespace |
145 | 145 |
146 namespace content { | 146 namespace content { |
147 | 147 |
148 WebMediaPlayerAndroid::WebMediaPlayerAndroid( | 148 WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
149 blink::WebFrame* frame, | 149 blink::WebFrame* frame, |
150 blink::WebMediaPlayerClient* client, | 150 blink::WebMediaPlayerClient* client, |
| 151 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
151 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 152 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
152 RendererMediaPlayerManager* player_manager, | 153 RendererMediaPlayerManager* player_manager, |
153 media::CdmFactory* cdm_factory, | 154 media::CdmFactory* cdm_factory, |
154 media::MediaPermission* media_permission, | 155 media::MediaPermission* media_permission, |
155 blink::WebContentDecryptionModule* initial_cdm, | 156 blink::WebContentDecryptionModule* initial_cdm, |
156 scoped_refptr<StreamTextureFactory> factory, | 157 scoped_refptr<StreamTextureFactory> factory, |
157 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 158 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
158 media::MediaLog* media_log) | 159 media::MediaLog* media_log) |
159 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), | 160 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), |
160 frame_(frame), | 161 frame_(frame), |
161 client_(client), | 162 client_(client), |
| 163 encrypted_client_(encrypted_client), |
162 delegate_(delegate), | 164 delegate_(delegate), |
163 buffered_(static_cast<size_t>(1)), | 165 buffered_(static_cast<size_t>(1)), |
164 media_task_runner_(task_runner), | 166 media_task_runner_(task_runner), |
165 ignore_metadata_duration_change_(false), | 167 ignore_metadata_duration_change_(false), |
166 pending_seek_(false), | 168 pending_seek_(false), |
167 seeking_(false), | 169 seeking_(false), |
168 did_loading_progress_(false), | 170 did_loading_progress_(false), |
169 player_manager_(player_manager), | 171 player_manager_(player_manager), |
170 cdm_factory_(cdm_factory), | 172 cdm_factory_(cdm_factory), |
171 media_permission_(media_permission), | 173 media_permission_(media_permission), |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 player_manager_->Start(player_id_); | 811 player_manager_->Start(player_id_); |
810 } | 812 } |
811 | 813 |
812 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) { | 814 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) { |
813 buffered_[0].end = duration() * percentage / 100; | 815 buffered_[0].end = duration() * percentage / 100; |
814 did_loading_progress_ = true; | 816 did_loading_progress_ = true; |
815 } | 817 } |
816 | 818 |
817 void WebMediaPlayerAndroid::OnSeekRequest(const base::TimeDelta& time_to_seek) { | 819 void WebMediaPlayerAndroid::OnSeekRequest(const base::TimeDelta& time_to_seek) { |
818 DCHECK(main_thread_checker_.CalledOnValidThread()); | 820 DCHECK(main_thread_checker_.CalledOnValidThread()); |
819 client_->requestSeek(time_to_seek.InSecondsF()); | 821 client_->mediaPlayerRequestSeek(time_to_seek.InSecondsF()); |
820 } | 822 } |
821 | 823 |
822 void WebMediaPlayerAndroid::OnSeekComplete( | 824 void WebMediaPlayerAndroid::OnSeekComplete( |
823 const base::TimeDelta& current_time) { | 825 const base::TimeDelta& current_time) { |
824 DCHECK(main_thread_checker_.CalledOnValidThread()); | 826 DCHECK(main_thread_checker_.CalledOnValidThread()); |
825 seeking_ = false; | 827 seeking_ = false; |
826 if (pending_seek_) { | 828 if (pending_seek_) { |
827 pending_seek_ = false; | 829 pending_seek_ = false; |
828 seek(pending_seek_time_.InSecondsF()); | 830 seek(pending_seek_time_.InSecondsF()); |
829 return; | 831 return; |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1683 | 1685 |
1684 result.completeWithError( | 1686 result.completeWithError( |
1685 blink::WebContentDecryptionModuleExceptionNotSupportedError, | 1687 blink::WebContentDecryptionModuleExceptionNotSupportedError, |
1686 0, | 1688 0, |
1687 "Unable to set MediaKeys object"); | 1689 "Unable to set MediaKeys object"); |
1688 } | 1690 } |
1689 | 1691 |
1690 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { | 1692 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { |
1691 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); | 1693 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); |
1692 | 1694 |
1693 client_->keyAdded( | 1695 encrypted_client_->keyAdded( |
1694 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), | 1696 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), |
1695 WebString::fromUTF8(session_id)); | 1697 WebString::fromUTF8(session_id)); |
1696 } | 1698 } |
1697 | 1699 |
1698 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, | 1700 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, |
1699 media::MediaKeys::KeyError error_code, | 1701 media::MediaKeys::KeyError error_code, |
1700 uint32 system_code) { | 1702 uint32 system_code) { |
1701 EmeUMAHistogramEnumeration(current_key_system_, "KeyError", | 1703 EmeUMAHistogramEnumeration(current_key_system_, "KeyError", |
1702 error_code, media::MediaKeys::kMaxKeyError); | 1704 error_code, media::MediaKeys::kMaxKeyError); |
1703 | 1705 |
1704 unsigned short short_system_code = 0; | 1706 unsigned short short_system_code = 0; |
1705 if (system_code > std::numeric_limits<unsigned short>::max()) { | 1707 if (system_code > std::numeric_limits<unsigned short>::max()) { |
1706 LOG(WARNING) << "system_code exceeds unsigned short limit."; | 1708 LOG(WARNING) << "system_code exceeds unsigned short limit."; |
1707 short_system_code = std::numeric_limits<unsigned short>::max(); | 1709 short_system_code = std::numeric_limits<unsigned short>::max(); |
1708 } else { | 1710 } else { |
1709 short_system_code = static_cast<unsigned short>(system_code); | 1711 short_system_code = static_cast<unsigned short>(system_code); |
1710 } | 1712 } |
1711 | 1713 |
1712 client_->keyError( | 1714 encrypted_client_->keyError( |
1713 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), | 1715 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), |
1714 WebString::fromUTF8(session_id), | 1716 WebString::fromUTF8(session_id), |
1715 static_cast<blink::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), | 1717 static_cast<blink::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), |
1716 short_system_code); | 1718 short_system_code); |
1717 } | 1719 } |
1718 | 1720 |
1719 void WebMediaPlayerAndroid::OnKeyMessage(const std::string& session_id, | 1721 void WebMediaPlayerAndroid::OnKeyMessage(const std::string& session_id, |
1720 const std::vector<uint8>& message, | 1722 const std::vector<uint8>& message, |
1721 const GURL& destination_url) { | 1723 const GURL& destination_url) { |
1722 DCHECK(destination_url.is_empty() || destination_url.is_valid()); | 1724 DCHECK(destination_url.is_empty() || destination_url.is_valid()); |
1723 | 1725 |
1724 client_->keyMessage( | 1726 encrypted_client_->keyMessage( |
1725 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), | 1727 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), |
1726 WebString::fromUTF8(session_id), | 1728 WebString::fromUTF8(session_id), message.empty() ? NULL : &message[0], |
1727 message.empty() ? NULL : &message[0], | 1729 message.size(), destination_url); |
1728 message.size(), | |
1729 destination_url); | |
1730 } | 1730 } |
1731 | 1731 |
1732 void WebMediaPlayerAndroid::OnMediaSourceOpened( | 1732 void WebMediaPlayerAndroid::OnMediaSourceOpened( |
1733 blink::WebMediaSource* web_media_source) { | 1733 blink::WebMediaSource* web_media_source) { |
1734 client_->mediaSourceOpened(web_media_source); | 1734 client_->mediaSourceOpened(web_media_source); |
1735 } | 1735 } |
1736 | 1736 |
1737 void WebMediaPlayerAndroid::OnEncryptedMediaInitData( | 1737 void WebMediaPlayerAndroid::OnEncryptedMediaInitData( |
1738 media::EmeInitDataType init_data_type, | 1738 media::EmeInitDataType init_data_type, |
1739 const std::vector<uint8>& init_data) { | 1739 const std::vector<uint8>& init_data) { |
1740 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1740 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1741 | 1741 |
1742 // Do not fire NeedKey event if encrypted media is not enabled. | 1742 // Do not fire NeedKey event if encrypted media is not enabled. |
1743 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && | 1743 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && |
1744 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { | 1744 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { |
1745 return; | 1745 return; |
1746 } | 1746 } |
1747 | 1747 |
1748 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); | 1748 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); |
1749 | 1749 |
1750 DCHECK(init_data_type != media::EmeInitDataType::UNKNOWN); | 1750 DCHECK(init_data_type != media::EmeInitDataType::UNKNOWN); |
1751 DLOG_IF(WARNING, init_data_type_ != media::EmeInitDataType::UNKNOWN && | 1751 DLOG_IF(WARNING, init_data_type_ != media::EmeInitDataType::UNKNOWN && |
1752 init_data_type != init_data_type_) | 1752 init_data_type != init_data_type_) |
1753 << "Mixed init data type not supported. The new type is ignored."; | 1753 << "Mixed init data type not supported. The new type is ignored."; |
1754 if (init_data_type_ == media::EmeInitDataType::UNKNOWN) | 1754 if (init_data_type_ == media::EmeInitDataType::UNKNOWN) |
1755 init_data_type_ = init_data_type; | 1755 init_data_type_ = init_data_type; |
1756 | 1756 |
1757 client_->encrypted(ConvertToWebInitDataType(init_data_type), | 1757 encrypted_client_->encrypted(ConvertToWebInitDataType(init_data_type), |
1758 vector_as_array(&init_data), init_data.size()); | 1758 vector_as_array(&init_data), init_data.size()); |
1759 } | 1759 } |
1760 | 1760 |
1761 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { | 1761 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { |
1762 client_->didBlockPlaybackWaitingForKey(); | 1762 encrypted_client_->didBlockPlaybackWaitingForKey(); |
1763 | 1763 |
1764 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called | 1764 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called |
1765 // when a key has been successfully added (e.g. OnSessionKeysChange() with | 1765 // when a key has been successfully added (e.g. OnSessionKeysChange() with |
1766 // |has_additional_usable_key| = true). http://crbug.com/461903 | 1766 // |has_additional_usable_key| = true). http://crbug.com/461903 |
1767 client_->didResumePlaybackBlockedForKey(); | 1767 encrypted_client_->didResumePlaybackBlockedForKey(); |
1768 } | 1768 } |
1769 | 1769 |
1770 void WebMediaPlayerAndroid::OnCdmContextReady(media::CdmContext* cdm_context) { | 1770 void WebMediaPlayerAndroid::OnCdmContextReady(media::CdmContext* cdm_context) { |
1771 DCHECK(!cdm_context_); | 1771 DCHECK(!cdm_context_); |
1772 | 1772 |
1773 if (!cdm_context) { | 1773 if (!cdm_context) { |
1774 LOG(ERROR) << "CdmContext not available (e.g. CDM creation failed)."; | 1774 LOG(ERROR) << "CdmContext not available (e.g. CDM creation failed)."; |
1775 return; | 1775 return; |
1776 } | 1776 } |
1777 | 1777 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1858 | 1858 |
1859 bool WebMediaPlayerAndroid::IsHLSStream() const { | 1859 bool WebMediaPlayerAndroid::IsHLSStream() const { |
1860 std::string mime; | 1860 std::string mime; |
1861 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; | 1861 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; |
1862 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) | 1862 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) |
1863 return false; | 1863 return false; |
1864 return !mime.compare("application/x-mpegurl"); | 1864 return !mime.compare("application/x-mpegurl"); |
1865 } | 1865 } |
1866 | 1866 |
1867 } // namespace content | 1867 } // namespace content |
OLD | NEW |