| 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> |
| 8 |
| 7 #include <limits> | 9 #include <limits> |
| 8 | 10 |
| 9 #include "base/android/build_info.h" | 11 #include "base/android/build_info.h" |
| 10 #include "base/bind.h" | 12 #include "base/bind.h" |
| 11 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 14 #include "base/logging.h" | 16 #include "base/logging.h" |
| 15 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 16 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 61 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 60 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 62 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 61 #include "third_party/WebKit/public/web/WebView.h" | 63 #include "third_party/WebKit/public/web/WebView.h" |
| 62 #include "third_party/skia/include/core/SkCanvas.h" | 64 #include "third_party/skia/include/core/SkCanvas.h" |
| 63 #include "third_party/skia/include/core/SkPaint.h" | 65 #include "third_party/skia/include/core/SkPaint.h" |
| 64 #include "third_party/skia/include/core/SkTypeface.h" | 66 #include "third_party/skia/include/core/SkTypeface.h" |
| 65 #include "third_party/skia/include/gpu/GrContext.h" | 67 #include "third_party/skia/include/gpu/GrContext.h" |
| 66 #include "third_party/skia/include/gpu/SkGrPixelRef.h" | 68 #include "third_party/skia/include/gpu/SkGrPixelRef.h" |
| 67 #include "ui/gfx/image/image.h" | 69 #include "ui/gfx/image/image.h" |
| 68 | 70 |
| 69 static const uint32 kGLTextureExternalOES = 0x8D65; | 71 static const uint32_t kGLTextureExternalOES = 0x8D65; |
| 70 static const int kSDKVersionToSupportSecurityOriginCheck = 20; | 72 static const int kSDKVersionToSupportSecurityOriginCheck = 20; |
| 71 | 73 |
| 72 using blink::WebMediaPlayer; | 74 using blink::WebMediaPlayer; |
| 73 using blink::WebSize; | 75 using blink::WebSize; |
| 74 using blink::WebString; | 76 using blink::WebString; |
| 75 using blink::WebURL; | 77 using blink::WebURL; |
| 76 using gpu::gles2::GLES2Interface; | 78 using gpu::gles2::GLES2Interface; |
| 77 using media::LogHelper; | 79 using media::LogHelper; |
| 78 using media::MediaLog; | 80 using media::MediaLog; |
| 79 using media::MediaPlayerAndroid; | 81 using media::MediaPlayerAndroid; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 90 PREDICTION_RESULT_ALL_INCORRECT, | 92 PREDICTION_RESULT_ALL_INCORRECT, |
| 91 PREDICTION_RESULT_PATH_BASED_WAS_BETTER, | 93 PREDICTION_RESULT_PATH_BASED_WAS_BETTER, |
| 92 PREDICTION_RESULT_URL_BASED_WAS_BETTER, | 94 PREDICTION_RESULT_URL_BASED_WAS_BETTER, |
| 93 // Must always be larger than the largest logged value. | 95 // Must always be larger than the largest logged value. |
| 94 PREDICTION_RESULT_MAX | 96 PREDICTION_RESULT_MAX |
| 95 }; | 97 }; |
| 96 | 98 |
| 97 // File-static function is to allow it to run even after WMPA is deleted. | 99 // File-static function is to allow it to run even after WMPA is deleted. |
| 98 void OnReleaseTexture( | 100 void OnReleaseTexture( |
| 99 const scoped_refptr<content::StreamTextureFactory>& factories, | 101 const scoped_refptr<content::StreamTextureFactory>& factories, |
| 100 uint32 texture_id, | 102 uint32_t texture_id, |
| 101 const gpu::SyncToken& sync_token) { | 103 const gpu::SyncToken& sync_token) { |
| 102 GLES2Interface* gl = factories->ContextGL(); | 104 GLES2Interface* gl = factories->ContextGL(); |
| 103 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); | 105 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
| 104 gl->DeleteTextures(1, &texture_id); | 106 gl->DeleteTextures(1, &texture_id); |
| 105 // Flush to ensure that the stream texture gets deleted in a timely fashion. | 107 // Flush to ensure that the stream texture gets deleted in a timely fashion. |
| 106 gl->ShallowFlushCHROMIUM(); | 108 gl->ShallowFlushCHROMIUM(); |
| 107 } | 109 } |
| 108 | 110 |
| 109 bool IsSkBitmapProperlySizedTexture(const SkBitmap* bitmap, | 111 bool IsSkBitmapProperlySizedTexture(const SkBitmap* bitmap, |
| 110 const gfx::Size& size) { | 112 const gfx::Size& size) { |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); | 699 const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(0); |
| 698 DCHECK((!is_remote_ && | 700 DCHECK((!is_remote_ && |
| 699 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) || | 701 mailbox_holder.texture_target == GL_TEXTURE_EXTERNAL_OES) || |
| 700 (is_remote_ && mailbox_holder.texture_target == GL_TEXTURE_2D)); | 702 (is_remote_ && mailbox_holder.texture_target == GL_TEXTURE_2D)); |
| 701 | 703 |
| 702 web_graphics_context->waitSyncTokenCHROMIUM( | 704 web_graphics_context->waitSyncTokenCHROMIUM( |
| 703 mailbox_holder.sync_token.GetConstData()); | 705 mailbox_holder.sync_token.GetConstData()); |
| 704 | 706 |
| 705 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise | 707 // Ensure the target of texture is set before copyTextureCHROMIUM, otherwise |
| 706 // an invalid texture target may be used for copy texture. | 708 // an invalid texture target may be used for copy texture. |
| 707 uint32 src_texture = | 709 uint32_t src_texture = web_graphics_context->createAndConsumeTextureCHROMIUM( |
| 708 web_graphics_context->createAndConsumeTextureCHROMIUM( | 710 mailbox_holder.texture_target, mailbox_holder.mailbox.name); |
| 709 mailbox_holder.texture_target, mailbox_holder.mailbox.name); | |
| 710 | 711 |
| 711 // Application itself needs to take care of setting the right flip_y | 712 // Application itself needs to take care of setting the right flip_y |
| 712 // value down to get the expected result. | 713 // value down to get the expected result. |
| 713 // flip_y==true means to reverse the video orientation while | 714 // flip_y==true means to reverse the video orientation while |
| 714 // flip_y==false means to keep the intrinsic orientation. | 715 // flip_y==false means to keep the intrinsic orientation. |
| 715 web_graphics_context->copyTextureCHROMIUM( | 716 web_graphics_context->copyTextureCHROMIUM( |
| 716 GL_TEXTURE_2D, src_texture, texture, internal_format, type, | 717 GL_TEXTURE_2D, src_texture, texture, internal_format, type, |
| 717 flip_y, premultiply_alpha, false); | 718 flip_y, premultiply_alpha, false); |
| 718 | 719 |
| 719 web_graphics_context->deleteTexture(src_texture); | 720 web_graphics_context->deleteTexture(src_texture); |
| (...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1758 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { | 1759 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { |
| 1759 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); | 1760 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); |
| 1760 | 1761 |
| 1761 encrypted_client_->keyAdded( | 1762 encrypted_client_->keyAdded( |
| 1762 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), | 1763 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), |
| 1763 WebString::fromUTF8(session_id)); | 1764 WebString::fromUTF8(session_id)); |
| 1764 } | 1765 } |
| 1765 | 1766 |
| 1766 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, | 1767 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, |
| 1767 media::MediaKeys::KeyError error_code, | 1768 media::MediaKeys::KeyError error_code, |
| 1768 uint32 system_code) { | 1769 uint32_t system_code) { |
| 1769 EmeUMAHistogramEnumeration(current_key_system_, "KeyError", | 1770 EmeUMAHistogramEnumeration(current_key_system_, "KeyError", |
| 1770 error_code, media::MediaKeys::kMaxKeyError); | 1771 error_code, media::MediaKeys::kMaxKeyError); |
| 1771 | 1772 |
| 1772 unsigned short short_system_code = 0; | 1773 unsigned short short_system_code = 0; |
| 1773 if (system_code > std::numeric_limits<unsigned short>::max()) { | 1774 if (system_code > std::numeric_limits<unsigned short>::max()) { |
| 1774 LOG(WARNING) << "system_code exceeds unsigned short limit."; | 1775 LOG(WARNING) << "system_code exceeds unsigned short limit."; |
| 1775 short_system_code = std::numeric_limits<unsigned short>::max(); | 1776 short_system_code = std::numeric_limits<unsigned short>::max(); |
| 1776 } else { | 1777 } else { |
| 1777 short_system_code = static_cast<unsigned short>(system_code); | 1778 short_system_code = static_cast<unsigned short>(system_code); |
| 1778 } | 1779 } |
| 1779 | 1780 |
| 1780 encrypted_client_->keyError( | 1781 encrypted_client_->keyError( |
| 1781 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), | 1782 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), |
| 1782 WebString::fromUTF8(session_id), | 1783 WebString::fromUTF8(session_id), |
| 1783 static_cast<blink::WebMediaPlayerEncryptedMediaClient::MediaKeyErrorCode>( | 1784 static_cast<blink::WebMediaPlayerEncryptedMediaClient::MediaKeyErrorCode>( |
| 1784 error_code), | 1785 error_code), |
| 1785 short_system_code); | 1786 short_system_code); |
| 1786 } | 1787 } |
| 1787 | 1788 |
| 1788 void WebMediaPlayerAndroid::OnKeyMessage(const std::string& session_id, | 1789 void WebMediaPlayerAndroid::OnKeyMessage(const std::string& session_id, |
| 1789 const std::vector<uint8>& message, | 1790 const std::vector<uint8_t>& message, |
| 1790 const GURL& destination_url) { | 1791 const GURL& destination_url) { |
| 1791 DCHECK(destination_url.is_empty() || destination_url.is_valid()); | 1792 DCHECK(destination_url.is_empty() || destination_url.is_valid()); |
| 1792 | 1793 |
| 1793 encrypted_client_->keyMessage( | 1794 encrypted_client_->keyMessage( |
| 1794 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), | 1795 WebString::fromUTF8(media::GetPrefixedKeySystemName(current_key_system_)), |
| 1795 WebString::fromUTF8(session_id), message.empty() ? NULL : &message[0], | 1796 WebString::fromUTF8(session_id), message.empty() ? NULL : &message[0], |
| 1796 message.size(), destination_url); | 1797 message.size(), destination_url); |
| 1797 } | 1798 } |
| 1798 | 1799 |
| 1799 void WebMediaPlayerAndroid::OnMediaSourceOpened( | 1800 void WebMediaPlayerAndroid::OnMediaSourceOpened( |
| 1800 blink::WebMediaSource* web_media_source) { | 1801 blink::WebMediaSource* web_media_source) { |
| 1801 client_->mediaSourceOpened(web_media_source); | 1802 client_->mediaSourceOpened(web_media_source); |
| 1802 } | 1803 } |
| 1803 | 1804 |
| 1804 void WebMediaPlayerAndroid::OnEncryptedMediaInitData( | 1805 void WebMediaPlayerAndroid::OnEncryptedMediaInitData( |
| 1805 media::EmeInitDataType init_data_type, | 1806 media::EmeInitDataType init_data_type, |
| 1806 const std::vector<uint8>& init_data) { | 1807 const std::vector<uint8_t>& init_data) { |
| 1807 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1808 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1808 | 1809 |
| 1809 // Do not fire NeedKey event if encrypted media is not enabled. | 1810 // Do not fire NeedKey event if encrypted media is not enabled. |
| 1810 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && | 1811 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && |
| 1811 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { | 1812 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { |
| 1812 return; | 1813 return; |
| 1813 } | 1814 } |
| 1814 | 1815 |
| 1815 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); | 1816 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); |
| 1816 | 1817 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; | 1974 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; |
| 1974 } else if (is_hls_url == is_hls) { | 1975 } else if (is_hls_url == is_hls) { |
| 1975 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; | 1976 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; |
| 1976 } | 1977 } |
| 1977 UMA_HISTOGRAM_ENUMERATION( | 1978 UMA_HISTOGRAM_ENUMERATION( |
| 1978 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", | 1979 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", |
| 1979 result, PREDICTION_RESULT_MAX); | 1980 result, PREDICTION_RESULT_MAX); |
| 1980 } | 1981 } |
| 1981 | 1982 |
| 1982 } // namespace content | 1983 } // namespace content |
| OLD | NEW |