| 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" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "cc/blink/web_layer_impl.h" | 19 #include "cc/blink/web_layer_impl.h" |
| 20 #include "cc/layers/video_layer.h" | 20 #include "cc/layers/video_layer.h" |
| 21 #include "content/public/common/content_client.h" | 21 #include "content/public/common/content_client.h" |
| 22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 23 #include "content/public/renderer/render_frame.h" | 23 #include "content/public/renderer/render_frame.h" |
| 24 #include "content/renderer/media/android/renderer_demuxer_android.h" | 24 #include "content/renderer/media/android/renderer_demuxer_android.h" |
| 25 #include "content/renderer/media/android/renderer_media_player_manager.h" | 25 #include "content/renderer/media/android/renderer_media_player_manager.h" |
| 26 #include "content/renderer/media/crypto/key_systems.h" | 26 #include "content/renderer/media/crypto/key_systems.h" |
| 27 #include "content/renderer/media/crypto/renderer_cdm_manager.h" | 27 #include "content/renderer/media/crypto/renderer_cdm_manager.h" |
| 28 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" | 28 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" |
| 29 #include "content/renderer/media/webmediaplayer_delegate.h" | |
| 30 #include "content/renderer/media/webmediaplayer_util.h" | |
| 31 #include "content/renderer/render_frame_impl.h" | 29 #include "content/renderer/render_frame_impl.h" |
| 32 #include "content/renderer/render_thread_impl.h" | 30 #include "content/renderer/render_thread_impl.h" |
| 33 #include "gpu/GLES2/gl2extchromium.h" | 31 #include "gpu/GLES2/gl2extchromium.h" |
| 34 #include "gpu/command_buffer/client/gles2_interface.h" | 32 #include "gpu/command_buffer/client/gles2_interface.h" |
| 35 #include "gpu/command_buffer/common/mailbox_holder.h" | 33 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 36 #include "media/base/android/media_player_android.h" | 34 #include "media/base/android/media_player_android.h" |
| 37 #include "media/base/bind_to_current_loop.h" | 35 #include "media/base/bind_to_current_loop.h" |
| 38 // TODO(xhwang): Remove when we remove prefixed EME implementation. | 36 // TODO(xhwang): Remove when we remove prefixed EME implementation. |
| 39 #include "media/base/media_keys.h" | 37 #include "media/base/media_keys.h" |
| 40 #include "media/base/media_log.h" | 38 #include "media/base/media_log.h" |
| 41 #include "media/base/media_switches.h" | 39 #include "media/base/media_switches.h" |
| 42 #include "media/base/video_frame.h" | 40 #include "media/base/video_frame.h" |
| 41 #include "media/blink/webmediaplayer_delegate.h" |
| 42 #include "media/blink/webmediaplayer_util.h" |
| 43 #include "net/base/mime_util.h" | 43 #include "net/base/mime_util.h" |
| 44 #include "third_party/WebKit/public/platform/Platform.h" | 44 #include "third_party/WebKit/public/platform/Platform.h" |
| 45 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | 45 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
| 46 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h" | 46 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h" |
| 47 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 47 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| 48 #include "third_party/WebKit/public/platform/WebString.h" | 48 #include "third_party/WebKit/public/platform/WebString.h" |
| 49 #include "third_party/WebKit/public/platform/WebURL.h" | 49 #include "third_party/WebKit/public/platform/WebURL.h" |
| 50 #include "third_party/WebKit/public/web/WebDocument.h" | 50 #include "third_party/WebKit/public/web/WebDocument.h" |
| 51 #include "third_party/WebKit/public/web/WebFrame.h" | 51 #include "third_party/WebKit/public/web/WebFrame.h" |
| 52 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 52 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 void DoNothing(bool) { | 104 void DoNothing(bool) { |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace | 107 } // namespace |
| 108 | 108 |
| 109 namespace content { | 109 namespace content { |
| 110 | 110 |
| 111 WebMediaPlayerAndroid::WebMediaPlayerAndroid( | 111 WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
| 112 blink::WebFrame* frame, | 112 blink::WebFrame* frame, |
| 113 blink::WebMediaPlayerClient* client, | 113 blink::WebMediaPlayerClient* client, |
| 114 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 114 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
| 115 RendererMediaPlayerManager* player_manager, | 115 RendererMediaPlayerManager* player_manager, |
| 116 RendererCdmManager* cdm_manager, | 116 RendererCdmManager* cdm_manager, |
| 117 scoped_refptr<StreamTextureFactory> factory, | 117 scoped_refptr<StreamTextureFactory> factory, |
| 118 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 118 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 119 media::MediaLog* media_log) | 119 media::MediaLog* media_log) |
| 120 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), | 120 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), |
| 121 frame_(frame), | 121 frame_(frame), |
| 122 client_(client), | 122 client_(client), |
| 123 delegate_(delegate), | 123 delegate_(delegate), |
| 124 buffered_(static_cast<size_t>(1)), | 124 buffered_(static_cast<size_t>(1)), |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 | 194 |
| 195 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_) | 195 if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_) |
| 196 delegate_->PlayerGone(this); | 196 delegate_->PlayerGone(this); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void WebMediaPlayerAndroid::load(LoadType load_type, | 199 void WebMediaPlayerAndroid::load(LoadType load_type, |
| 200 const blink::WebURL& url, | 200 const blink::WebURL& url, |
| 201 CORSMode cors_mode) { | 201 CORSMode cors_mode) { |
| 202 DCHECK(main_thread_checker_.CalledOnValidThread()); | 202 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 203 ReportMediaSchemeUma(GURL(url)); | 203 media::ReportMediaSchemeUma(GURL(url)); |
| 204 | 204 |
| 205 switch (load_type) { | 205 switch (load_type) { |
| 206 case LoadTypeURL: | 206 case LoadTypeURL: |
| 207 player_type_ = MEDIA_PLAYER_TYPE_URL; | 207 player_type_ = MEDIA_PLAYER_TYPE_URL; |
| 208 break; | 208 break; |
| 209 | 209 |
| 210 case LoadTypeMediaSource: | 210 case LoadTypeMediaSource: |
| 211 player_type_ = MEDIA_PLAYER_TYPE_MEDIA_SOURCE; | 211 player_type_ = MEDIA_PLAYER_TYPE_MEDIA_SOURCE; |
| 212 break; | 212 break; |
| 213 | 213 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 324 |
| 325 void WebMediaPlayerAndroid::pause() { | 325 void WebMediaPlayerAndroid::pause() { |
| 326 DCHECK(main_thread_checker_.CalledOnValidThread()); | 326 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 327 Pause(true); | 327 Pause(true); |
| 328 } | 328 } |
| 329 | 329 |
| 330 void WebMediaPlayerAndroid::seek(double seconds) { | 330 void WebMediaPlayerAndroid::seek(double seconds) { |
| 331 DCHECK(main_thread_checker_.CalledOnValidThread()); | 331 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 332 DVLOG(1) << __FUNCTION__ << "(" << seconds << ")"; | 332 DVLOG(1) << __FUNCTION__ << "(" << seconds << ")"; |
| 333 | 333 |
| 334 base::TimeDelta new_seek_time = ConvertSecondsToTimestamp(seconds); | 334 base::TimeDelta new_seek_time = media::ConvertSecondsToTimestamp(seconds); |
| 335 | 335 |
| 336 if (seeking_) { | 336 if (seeking_) { |
| 337 if (new_seek_time == seek_time_) { | 337 if (new_seek_time == seek_time_) { |
| 338 if (media_source_delegate_) { | 338 if (media_source_delegate_) { |
| 339 if (!pending_seek_) { | 339 if (!pending_seek_) { |
| 340 // If using media source demuxer, only suppress redundant seeks if | 340 // If using media source demuxer, only suppress redundant seeks if |
| 341 // there is no pending seek. This enforces that any pending seek that | 341 // there is no pending seek. This enforces that any pending seek that |
| 342 // results in a demuxer seek is preceded by matching | 342 // results in a demuxer seek is preceded by matching |
| 343 // CancelPendingSeek() and StartWaitingForSeek() calls. | 343 // CancelPendingSeek() and StartWaitingForSeek() calls. |
| 344 return; | 344 return; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 } | 665 } |
| 666 | 666 |
| 667 bool WebMediaPlayerAndroid::didPassCORSAccessCheck() const { | 667 bool WebMediaPlayerAndroid::didPassCORSAccessCheck() const { |
| 668 DCHECK(main_thread_checker_.CalledOnValidThread()); | 668 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 669 if (info_loader_) | 669 if (info_loader_) |
| 670 return info_loader_->DidPassCORSAccessCheck(); | 670 return info_loader_->DidPassCORSAccessCheck(); |
| 671 return false; | 671 return false; |
| 672 } | 672 } |
| 673 | 673 |
| 674 double WebMediaPlayerAndroid::mediaTimeForTimeValue(double timeValue) const { | 674 double WebMediaPlayerAndroid::mediaTimeForTimeValue(double timeValue) const { |
| 675 return ConvertSecondsToTimestamp(timeValue).InSecondsF(); | 675 return media::ConvertSecondsToTimestamp(timeValue).InSecondsF(); |
| 676 } | 676 } |
| 677 | 677 |
| 678 unsigned WebMediaPlayerAndroid::decodedFrameCount() const { | 678 unsigned WebMediaPlayerAndroid::decodedFrameCount() const { |
| 679 if (media_source_delegate_) | 679 if (media_source_delegate_) |
| 680 return media_source_delegate_->DecodedFrameCount(); | 680 return media_source_delegate_->DecodedFrameCount(); |
| 681 NOTIMPLEMENTED(); | 681 NOTIMPLEMENTED(); |
| 682 return 0; | 682 return 0; |
| 683 } | 683 } |
| 684 | 684 |
| 685 unsigned WebMediaPlayerAndroid::droppedFrameCount() const { | 685 unsigned WebMediaPlayerAndroid::droppedFrameCount() const { |
| (...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1764 | 1764 |
| 1765 bool WebMediaPlayerAndroid::IsHLSStream() const { | 1765 bool WebMediaPlayerAndroid::IsHLSStream() const { |
| 1766 std::string mime; | 1766 std::string mime; |
| 1767 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; | 1767 GURL url = redirected_url_.is_empty() ? url_ : redirected_url_; |
| 1768 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) | 1768 if (!net::GetMimeTypeFromFile(base::FilePath(url.path()), &mime)) |
| 1769 return false; | 1769 return false; |
| 1770 return !mime.compare("application/x-mpegurl"); | 1770 return !mime.compare("application/x-mpegurl"); |
| 1771 } | 1771 } |
| 1772 | 1772 |
| 1773 } // namespace content | 1773 } // namespace content |
| OLD | NEW |