| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "media/base/video_frame.h" | 43 #include "media/base/video_frame.h" |
| 44 #include "media/blink/webcontentdecryptionmodule_impl.h" | 44 #include "media/blink/webcontentdecryptionmodule_impl.h" |
| 45 #include "media/blink/webmediaplayer_delegate.h" | 45 #include "media/blink/webmediaplayer_delegate.h" |
| 46 #include "media/blink/webmediaplayer_util.h" | 46 #include "media/blink/webmediaplayer_util.h" |
| 47 #include "net/base/mime_util.h" | 47 #include "net/base/mime_util.h" |
| 48 #include "third_party/WebKit/public/platform/Platform.h" | 48 #include "third_party/WebKit/public/platform/Platform.h" |
| 49 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | 49 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
| 50 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" | 50 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" |
| 51 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h" | 51 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h" |
| 52 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 52 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| 53 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient.
h" |
| 53 #include "third_party/WebKit/public/platform/WebString.h" | 54 #include "third_party/WebKit/public/platform/WebString.h" |
| 54 #include "third_party/WebKit/public/platform/WebURL.h" | 55 #include "third_party/WebKit/public/platform/WebURL.h" |
| 55 #include "third_party/WebKit/public/web/WebDocument.h" | 56 #include "third_party/WebKit/public/web/WebDocument.h" |
| 56 #include "third_party/WebKit/public/web/WebFrame.h" | 57 #include "third_party/WebKit/public/web/WebFrame.h" |
| 57 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 58 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 58 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 59 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 59 #include "third_party/WebKit/public/web/WebView.h" | 60 #include "third_party/WebKit/public/web/WebView.h" |
| 60 #include "third_party/skia/include/core/SkCanvas.h" | 61 #include "third_party/skia/include/core/SkCanvas.h" |
| 61 #include "third_party/skia/include/core/SkPaint.h" | 62 #include "third_party/skia/include/core/SkPaint.h" |
| 62 #include "third_party/skia/include/core/SkTypeface.h" | 63 #include "third_party/skia/include/core/SkTypeface.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 blink::WebGraphicsContext3D* web_graphics_context_; | 144 blink::WebGraphicsContext3D* web_graphics_context_; |
| 144 }; | 145 }; |
| 145 | 146 |
| 146 } // namespace | 147 } // namespace |
| 147 | 148 |
| 148 namespace content { | 149 namespace content { |
| 149 | 150 |
| 150 WebMediaPlayerAndroid::WebMediaPlayerAndroid( | 151 WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
| 151 blink::WebFrame* frame, | 152 blink::WebFrame* frame, |
| 152 blink::WebMediaPlayerClient* client, | 153 blink::WebMediaPlayerClient* client, |
| 154 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
| 153 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 155 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
| 154 RendererMediaPlayerManager* player_manager, | 156 RendererMediaPlayerManager* player_manager, |
| 155 media::CdmFactory* cdm_factory, | 157 media::CdmFactory* cdm_factory, |
| 156 media::MediaPermission* media_permission, | 158 media::MediaPermission* media_permission, |
| 157 blink::WebContentDecryptionModule* initial_cdm, | 159 blink::WebContentDecryptionModule* initial_cdm, |
| 158 scoped_refptr<StreamTextureFactory> factory, | 160 scoped_refptr<StreamTextureFactory> factory, |
| 159 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 161 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 160 media::MediaLog* media_log) | 162 media::MediaLog* media_log) |
| 161 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), | 163 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), |
| 162 frame_(frame), | 164 frame_(frame), |
| 163 client_(client), | 165 client_(client), |
| 166 encrypted_client_(encrypted_client), |
| 164 delegate_(delegate), | 167 delegate_(delegate), |
| 165 buffered_(static_cast<size_t>(1)), | 168 buffered_(static_cast<size_t>(1)), |
| 166 media_task_runner_(task_runner), | 169 media_task_runner_(task_runner), |
| 167 ignore_metadata_duration_change_(false), | 170 ignore_metadata_duration_change_(false), |
| 168 pending_seek_(false), | 171 pending_seek_(false), |
| 169 seeking_(false), | 172 seeking_(false), |
| 170 did_loading_progress_(false), | 173 did_loading_progress_(false), |
| 171 player_manager_(player_manager), | 174 player_manager_(player_manager), |
| 172 cdm_factory_(cdm_factory), | 175 cdm_factory_(cdm_factory), |
| 173 media_permission_(media_permission), | 176 media_permission_(media_permission), |
| (...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 | 1693 |
| 1691 result.completeWithError( | 1694 result.completeWithError( |
| 1692 blink::WebContentDecryptionModuleExceptionNotSupportedError, | 1695 blink::WebContentDecryptionModuleExceptionNotSupportedError, |
| 1693 0, | 1696 0, |
| 1694 "Unable to set MediaKeys object"); | 1697 "Unable to set MediaKeys object"); |
| 1695 } | 1698 } |
| 1696 | 1699 |
| 1697 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { | 1700 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { |
| 1698 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); | 1701 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); |
| 1699 | 1702 |
| 1700 client_->keyAdded( | 1703 encrypted_client_->keyAdded( |
| 1701 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), | 1704 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), |
| 1702 WebString::fromUTF8(session_id)); | 1705 WebString::fromUTF8(session_id)); |
| 1703 } | 1706 } |
| 1704 | 1707 |
| 1705 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, | 1708 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, |
| 1706 media::MediaKeys::KeyError error_code, | 1709 media::MediaKeys::KeyError error_code, |
| 1707 uint32 system_code) { | 1710 uint32 system_code) { |
| 1708 EmeUMAHistogramEnumeration(current_key_system_, "KeyError", | 1711 EmeUMAHistogramEnumeration(current_key_system_, "KeyError", |
| 1709 error_code, media::MediaKeys::kMaxKeyError); | 1712 error_code, media::MediaKeys::kMaxKeyError); |
| 1710 | 1713 |
| 1711 unsigned short short_system_code = 0; | 1714 unsigned short short_system_code = 0; |
| 1712 if (system_code > std::numeric_limits<unsigned short>::max()) { | 1715 if (system_code > std::numeric_limits<unsigned short>::max()) { |
| 1713 LOG(WARNING) << "system_code exceeds unsigned short limit."; | 1716 LOG(WARNING) << "system_code exceeds unsigned short limit."; |
| 1714 short_system_code = std::numeric_limits<unsigned short>::max(); | 1717 short_system_code = std::numeric_limits<unsigned short>::max(); |
| 1715 } else { | 1718 } else { |
| 1716 short_system_code = static_cast<unsigned short>(system_code); | 1719 short_system_code = static_cast<unsigned short>(system_code); |
| 1717 } | 1720 } |
| 1718 | 1721 |
| 1719 client_->keyError( | 1722 encrypted_client_->keyError( |
| 1720 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), | 1723 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), |
| 1721 WebString::fromUTF8(session_id), | 1724 WebString::fromUTF8(session_id), |
| 1722 static_cast<blink::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), | 1725 static_cast<blink::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), |
| 1723 short_system_code); | 1726 short_system_code); |
| 1724 } | 1727 } |
| 1725 | 1728 |
| 1726 void WebMediaPlayerAndroid::OnKeyMessage(const std::string& session_id, | 1729 void WebMediaPlayerAndroid::OnKeyMessage(const std::string& session_id, |
| 1727 const std::vector<uint8>& message, | 1730 const std::vector<uint8>& message, |
| 1728 const GURL& destination_url) { | 1731 const GURL& destination_url) { |
| 1729 DCHECK(destination_url.is_empty() || destination_url.is_valid()); | 1732 DCHECK(destination_url.is_empty() || destination_url.is_valid()); |
| 1730 | 1733 |
| 1731 client_->keyMessage( | 1734 encrypted_client_->keyMessage( |
| 1732 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), | 1735 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), |
| 1733 WebString::fromUTF8(session_id), | 1736 WebString::fromUTF8(session_id), message.empty() ? NULL : &message[0], |
| 1734 message.empty() ? NULL : &message[0], | 1737 message.size(), destination_url); |
| 1735 message.size(), | |
| 1736 destination_url); | |
| 1737 } | 1738 } |
| 1738 | 1739 |
| 1739 void WebMediaPlayerAndroid::OnMediaSourceOpened( | 1740 void WebMediaPlayerAndroid::OnMediaSourceOpened( |
| 1740 blink::WebMediaSource* web_media_source) { | 1741 blink::WebMediaSource* web_media_source) { |
| 1741 client_->mediaSourceOpened(web_media_source); | 1742 client_->mediaSourceOpened(web_media_source); |
| 1742 } | 1743 } |
| 1743 | 1744 |
| 1744 void WebMediaPlayerAndroid::OnEncryptedMediaInitData( | 1745 void WebMediaPlayerAndroid::OnEncryptedMediaInitData( |
| 1745 media::EmeInitDataType init_data_type, | 1746 media::EmeInitDataType init_data_type, |
| 1746 const std::vector<uint8>& init_data) { | 1747 const std::vector<uint8>& init_data) { |
| 1747 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1748 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1748 | 1749 |
| 1749 // Do not fire NeedKey event if encrypted media is not enabled. | 1750 // Do not fire NeedKey event if encrypted media is not enabled. |
| 1750 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && | 1751 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && |
| 1751 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { | 1752 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { |
| 1752 return; | 1753 return; |
| 1753 } | 1754 } |
| 1754 | 1755 |
| 1755 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); | 1756 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); |
| 1756 | 1757 |
| 1757 DCHECK(init_data_type != media::EmeInitDataType::UNKNOWN); | 1758 DCHECK(init_data_type != media::EmeInitDataType::UNKNOWN); |
| 1758 DLOG_IF(WARNING, init_data_type_ != media::EmeInitDataType::UNKNOWN && | 1759 DLOG_IF(WARNING, init_data_type_ != media::EmeInitDataType::UNKNOWN && |
| 1759 init_data_type != init_data_type_) | 1760 init_data_type != init_data_type_) |
| 1760 << "Mixed init data type not supported. The new type is ignored."; | 1761 << "Mixed init data type not supported. The new type is ignored."; |
| 1761 if (init_data_type_ == media::EmeInitDataType::UNKNOWN) | 1762 if (init_data_type_ == media::EmeInitDataType::UNKNOWN) |
| 1762 init_data_type_ = init_data_type; | 1763 init_data_type_ = init_data_type; |
| 1763 | 1764 |
| 1764 client_->encrypted(ConvertToWebInitDataType(init_data_type), | 1765 encrypted_client_->encrypted(ConvertToWebInitDataType(init_data_type), |
| 1765 vector_as_array(&init_data), init_data.size()); | 1766 vector_as_array(&init_data), init_data.size()); |
| 1766 } | 1767 } |
| 1767 | 1768 |
| 1768 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { | 1769 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { |
| 1769 client_->didBlockPlaybackWaitingForKey(); | 1770 encrypted_client_->didBlockPlaybackWaitingForKey(); |
| 1770 | 1771 |
| 1771 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called | 1772 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called |
| 1772 // when a key has been successfully added (e.g. OnSessionKeysChange() with | 1773 // when a key has been successfully added (e.g. OnSessionKeysChange() with |
| 1773 // |has_additional_usable_key| = true). http://crbug.com/461903 | 1774 // |has_additional_usable_key| = true). http://crbug.com/461903 |
| 1774 client_->didResumePlaybackBlockedForKey(); | 1775 encrypted_client_->didResumePlaybackBlockedForKey(); |
| 1775 } | 1776 } |
| 1776 | 1777 |
| 1777 void WebMediaPlayerAndroid::OnCdmContextReady(media::CdmContext* cdm_context) { | 1778 void WebMediaPlayerAndroid::OnCdmContextReady(media::CdmContext* cdm_context) { |
| 1778 DCHECK(!cdm_context_); | 1779 DCHECK(!cdm_context_); |
| 1779 | 1780 |
| 1780 if (!cdm_context) { | 1781 if (!cdm_context) { |
| 1781 LOG(ERROR) << "CdmContext not available (e.g. CDM creation failed)."; | 1782 LOG(ERROR) << "CdmContext not available (e.g. CDM creation failed)."; |
| 1782 return; | 1783 return; |
| 1783 } | 1784 } |
| 1784 | 1785 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1865 | 1866 |
| 1866 bool WebMediaPlayerAndroid::IsHLSStream() const { | 1867 bool WebMediaPlayerAndroid::IsHLSStream() const { |
| 1867 std::string mime; | 1868 std::string mime; |
| 1868 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; | 1869 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; |
| 1869 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) | 1870 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) |
| 1870 return false; | 1871 return false; |
| 1871 return !mime.compare("application/x-mpegurl"); | 1872 return !mime.compare("application/x-mpegurl"); |
| 1872 } | 1873 } |
| 1873 | 1874 |
| 1874 } // namespace content | 1875 } // namespace content |
| OLD | NEW |