| 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 "media/blink/webmediaplayer_impl.h" | 5 #include "media/blink/webmediaplayer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
| 26 #include "base/trace_event/trace_event.h" | 26 #include "base/trace_event/trace_event.h" |
| 27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 28 #include "cc/blink/web_layer_impl.h" | 28 #include "cc/blink/web_layer_impl.h" |
| 29 #include "cc/layers/video_layer.h" | 29 #include "cc/layers/video_layer.h" |
| 30 #include "media/audio/null_audio_sink.h" | 30 #include "media/audio/null_audio_sink.h" |
| 31 #include "media/base/bind_to_current_loop.h" | 31 #include "media/base/bind_to_current_loop.h" |
| 32 #include "media/base/cdm_context.h" | 32 #include "media/base/cdm_context.h" |
| 33 #include "media/base/limits.h" | 33 #include "media/base/limits.h" |
| 34 #include "media/base/media_content_type.h" | 34 #include "media/base/media_content_type.h" |
| 35 #include "media/base/media_keys.h" |
| 35 #include "media/base/media_log.h" | 36 #include "media/base/media_log.h" |
| 36 #include "media/base/media_switches.h" | 37 #include "media/base/media_switches.h" |
| 37 #include "media/base/text_renderer.h" | 38 #include "media/base/text_renderer.h" |
| 38 #include "media/base/timestamp_constants.h" | 39 #include "media/base/timestamp_constants.h" |
| 39 #include "media/base/video_frame.h" | 40 #include "media/base/video_frame.h" |
| 40 #include "media/blink/texttrack_impl.h" | 41 #include "media/blink/texttrack_impl.h" |
| 41 #include "media/blink/watch_time_reporter.h" | 42 #include "media/blink/watch_time_reporter.h" |
| 42 #include "media/blink/webaudiosourceprovider_impl.h" | 43 #include "media/blink/webaudiosourceprovider_impl.h" |
| 43 #include "media/blink/webcontentdecryptionmodule_impl.h" | 44 #include "media/blink/webcontentdecryptionmodule_impl.h" |
| 44 #include "media/blink/webinbandtexttrack_impl.h" | 45 #include "media/blink/webinbandtexttrack_impl.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), | 209 adjust_allocated_memory_cb_(params.adjust_allocated_memory_cb()), |
| 209 last_reported_memory_usage_(0), | 210 last_reported_memory_usage_(0), |
| 210 supports_save_(true), | 211 supports_save_(true), |
| 211 chunk_demuxer_(NULL), | 212 chunk_demuxer_(NULL), |
| 212 url_index_(url_index), | 213 url_index_(url_index), |
| 213 // Threaded compositing isn't enabled universally yet. | 214 // Threaded compositing isn't enabled universally yet. |
| 214 compositor_task_runner_(params.compositor_task_runner() | 215 compositor_task_runner_(params.compositor_task_runner() |
| 215 ? params.compositor_task_runner() | 216 ? params.compositor_task_runner() |
| 216 : base::ThreadTaskRunnerHandle::Get()), | 217 : base::ThreadTaskRunnerHandle::Get()), |
| 217 compositor_(new VideoFrameCompositor(compositor_task_runner_)), | 218 compositor_(new VideoFrameCompositor(compositor_task_runner_)), |
| 218 is_cdm_attached_(false), | |
| 219 #if defined(OS_ANDROID) // WMPI_CAST | 219 #if defined(OS_ANDROID) // WMPI_CAST |
| 220 cast_impl_(this, client_, params.context_3d_cb()), | 220 cast_impl_(this, client_, params.context_3d_cb()), |
| 221 #endif | 221 #endif |
| 222 volume_(1.0), | 222 volume_(1.0), |
| 223 volume_multiplier_(1.0), | 223 volume_multiplier_(1.0), |
| 224 renderer_factory_(std::move(renderer_factory)), | 224 renderer_factory_(std::move(renderer_factory)), |
| 225 surface_manager_(params.surface_manager()), | 225 surface_manager_(params.surface_manager()), |
| 226 overlay_surface_id_(SurfaceManager::kNoSurfaceID), | 226 overlay_surface_id_(SurfaceManager::kNoSurfaceID), |
| 227 suppress_destruction_errors_(false), | 227 suppress_destruction_errors_(false), |
| 228 can_suspend_state_(CanSuspendState::UNKNOWN), | 228 can_suspend_state_(CanSuspendState::UNKNOWN), |
| 229 is_encrypted_(false), | 229 is_encrypted_(false), |
| 230 underflow_count_(0) { | 230 underflow_count_(0) { |
| 231 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 231 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| 232 DCHECK(renderer_factory_); | 232 DCHECK(renderer_factory_); |
| 233 DCHECK(client_); | 233 DCHECK(client_); |
| 234 | 234 |
| 235 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 235 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 236 switches::kForceVideoOverlays); | 236 switches::kForceVideoOverlays); |
| 237 | 237 |
| 238 disable_fullscreen_video_overlays_ = | 238 disable_fullscreen_video_overlays_ = |
| 239 !base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo); | 239 !base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo); |
| 240 | 240 |
| 241 if (delegate_) | 241 if (delegate_) |
| 242 delegate_id_ = delegate_->AddObserver(this); | 242 delegate_id_ = delegate_->AddObserver(this); |
| 243 | 243 |
| 244 media_log_->AddEvent( | 244 media_log_->AddEvent( |
| 245 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 245 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
| 246 | 246 |
| 247 if (params.initial_cdm()) { | 247 if (params.initial_cdm()) |
| 248 SetCdm(base::Bind(&IgnoreCdmAttached), | 248 SetCdm(params.initial_cdm()); |
| 249 ToWebContentDecryptionModuleImpl(params.initial_cdm()) | |
| 250 ->GetCdmContext()); | |
| 251 } | |
| 252 | 249 |
| 253 // TODO(xhwang): When we use an external Renderer, many methods won't work, | 250 // TODO(xhwang): When we use an external Renderer, many methods won't work, |
| 254 // e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861 | 251 // e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861 |
| 255 | 252 |
| 256 // Use the null sink if no sink was provided. | 253 // Use the null sink if no sink was provided. |
| 257 audio_source_provider_ = new WebAudioSourceProviderImpl( | 254 audio_source_provider_ = new WebAudioSourceProviderImpl( |
| 258 params.audio_renderer_sink().get() | 255 params.audio_renderer_sink().get() |
| 259 ? params.audio_renderer_sink() | 256 ? params.audio_renderer_sink() |
| 260 : new NullAudioSink(media_task_runner_)); | 257 : new NullAudioSink(media_task_runner_)); |
| 261 } | 258 } |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 | 770 |
| 774 return did_loading_progress; | 771 return did_loading_progress; |
| 775 } | 772 } |
| 776 | 773 |
| 777 void WebMediaPlayerImpl::paint(blink::WebCanvas* canvas, | 774 void WebMediaPlayerImpl::paint(blink::WebCanvas* canvas, |
| 778 const blink::WebRect& rect, | 775 const blink::WebRect& rect, |
| 779 SkPaint& paint) { | 776 SkPaint& paint) { |
| 780 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 777 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 781 TRACE_EVENT0("media", "WebMediaPlayerImpl:paint"); | 778 TRACE_EVENT0("media", "WebMediaPlayerImpl:paint"); |
| 782 | 779 |
| 783 if (is_cdm_attached_) | 780 if (cdm_) |
| 784 return; | 781 return; |
| 785 | 782 |
| 786 scoped_refptr<VideoFrame> video_frame = GetCurrentFrameFromCompositor(); | 783 scoped_refptr<VideoFrame> video_frame = GetCurrentFrameFromCompositor(); |
| 787 | 784 |
| 788 gfx::Rect gfx_rect(rect); | 785 gfx::Rect gfx_rect(rect); |
| 789 Context3D context_3d; | 786 Context3D context_3d; |
| 790 if (video_frame.get() && video_frame->HasTextures()) { | 787 if (video_frame.get() && video_frame->HasTextures()) { |
| 791 if (!context_3d_cb_.is_null()) | 788 if (!context_3d_cb_.is_null()) |
| 792 context_3d = context_3d_cb_.Run(); | 789 context_3d = context_3d_cb_.Run(); |
| 793 if (!context_3d.gl) | 790 if (!context_3d.gl) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 // multiple simultaneous calls. | 885 // multiple simultaneous calls. |
| 889 DCHECK(!set_cdm_result_); | 886 DCHECK(!set_cdm_result_); |
| 890 set_cdm_result_.reset(new blink::WebContentDecryptionModuleResult(result)); | 887 set_cdm_result_.reset(new blink::WebContentDecryptionModuleResult(result)); |
| 891 | 888 |
| 892 // Recreate the watch time reporter if necessary. | 889 // Recreate the watch time reporter if necessary. |
| 893 const bool was_encrypted = is_encrypted_; | 890 const bool was_encrypted = is_encrypted_; |
| 894 is_encrypted_ = true; | 891 is_encrypted_ = true; |
| 895 if (!was_encrypted && watch_time_reporter_) | 892 if (!was_encrypted && watch_time_reporter_) |
| 896 CreateWatchTimeReporter(); | 893 CreateWatchTimeReporter(); |
| 897 | 894 |
| 898 SetCdm(BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnCdmAttached), | 895 SetCdm(cdm); |
| 899 ToWebContentDecryptionModuleImpl(cdm)->GetCdmContext()); | |
| 900 } | 896 } |
| 901 | 897 |
| 902 void WebMediaPlayerImpl::OnEncryptedMediaInitData( | 898 void WebMediaPlayerImpl::OnEncryptedMediaInitData( |
| 903 EmeInitDataType init_data_type, | 899 EmeInitDataType init_data_type, |
| 904 const std::vector<uint8_t>& init_data) { | 900 const std::vector<uint8_t>& init_data) { |
| 905 DCHECK(init_data_type != EmeInitDataType::UNKNOWN); | 901 DCHECK(init_data_type != EmeInitDataType::UNKNOWN); |
| 906 | 902 |
| 907 // TODO(xhwang): Update this UMA name. https://crbug.com/589251 | 903 // TODO(xhwang): Update this UMA name. https://crbug.com/589251 |
| 908 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); | 904 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); |
| 909 | 905 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 939 blink::WebString::fromUTF8(track->label()), | 935 blink::WebString::fromUTF8(track->label()), |
| 940 blink::WebString::fromUTF8(track->language()), | 936 blink::WebString::fromUTF8(track->language()), |
| 941 /*selected*/ true); | 937 /*selected*/ true); |
| 942 } else { | 938 } else { |
| 943 // Text tracks are not supported through this code path yet. | 939 // Text tracks are not supported through this code path yet. |
| 944 NOTREACHED(); | 940 NOTREACHED(); |
| 945 } | 941 } |
| 946 } | 942 } |
| 947 } | 943 } |
| 948 | 944 |
| 949 void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, | 945 void WebMediaPlayerImpl::SetCdm(blink::WebContentDecryptionModule* cdm) { |
| 950 CdmContext* cdm_context) { | 946 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 951 if (!cdm_context) { | 947 DCHECK(cdm); |
| 952 cdm_attached_cb.Run(false); | 948 scoped_refptr<MediaKeys> cdm_reference = |
| 949 ToWebContentDecryptionModuleImpl(cdm)->GetCdm(); |
| 950 if (!cdm_reference) { |
| 951 NOTREACHED(); |
| 952 OnCdmAttached(false); |
| 953 return; | 953 return; |
| 954 } | 954 } |
| 955 | 955 |
| 956 // If CDM initialization succeeded, tell the pipeline about it. | 956 CdmContext* cdm_context = cdm_reference->GetCdmContext(); |
| 957 pipeline_.SetCdm(cdm_context, cdm_attached_cb); | 957 if (!cdm_context) { |
| 958 OnCdmAttached(false); |
| 959 return; |
| 960 } |
| 961 |
| 962 // Keep the reference to the CDM, as it shouldn't be destroyed until |
| 963 // after the pipeline is done with the |cdm_context|. |
| 964 pending_cdm_ = std::move(cdm_reference); |
| 965 pipeline_.SetCdm(cdm_context, |
| 966 base::Bind(&WebMediaPlayerImpl::OnCdmAttached, AsWeakPtr())); |
| 958 } | 967 } |
| 959 | 968 |
| 960 void WebMediaPlayerImpl::OnCdmAttached(bool success) { | 969 void WebMediaPlayerImpl::OnCdmAttached(bool success) { |
| 970 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 971 DCHECK(pending_cdm_); |
| 972 |
| 973 // If the CDM is set from the constructor there is no promise |
| 974 // (|set_cdm_result_|) to fulfill. |
| 961 if (success) { | 975 if (success) { |
| 962 set_cdm_result_->complete(); | 976 // This will release the previously attached CDM (if any). |
| 963 set_cdm_result_.reset(); | 977 cdm_ = std::move(pending_cdm_); |
| 964 is_cdm_attached_ = true; | 978 if (set_cdm_result_) { |
| 979 set_cdm_result_->complete(); |
| 980 set_cdm_result_.reset(); |
| 981 } |
| 982 |
| 965 return; | 983 return; |
| 966 } | 984 } |
| 967 | 985 |
| 968 set_cdm_result_->completeWithError( | 986 pending_cdm_ = nullptr; |
| 969 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, | 987 if (set_cdm_result_) { |
| 970 "Unable to set MediaKeys object"); | 988 set_cdm_result_->completeWithError( |
| 971 set_cdm_result_.reset(); | 989 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, |
| 990 "Unable to set MediaKeys object"); |
| 991 set_cdm_result_.reset(); |
| 992 } |
| 972 } | 993 } |
| 973 | 994 |
| 974 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) { | 995 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) { |
| 975 seeking_ = false; | 996 seeking_ = false; |
| 976 seek_time_ = base::TimeDelta(); | 997 seek_time_ = base::TimeDelta(); |
| 977 if (paused_) { | 998 if (paused_) { |
| 978 #if defined(OS_ANDROID) // WMPI_CAST | 999 #if defined(OS_ANDROID) // WMPI_CAST |
| 979 if (isRemote()) { | 1000 if (isRemote()) { |
| 980 paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime()); | 1001 paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime()); |
| 981 } else { | 1002 } else { |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1815 pipeline_metadata_.natural_size, | 1836 pipeline_metadata_.natural_size, |
| 1816 base::Bind(&GetCurrentTimeInternal, this))); | 1837 base::Bind(&GetCurrentTimeInternal, this))); |
| 1817 watch_time_reporter_->OnVolumeChange(volume_); | 1838 watch_time_reporter_->OnVolumeChange(volume_); |
| 1818 if (delegate_ && delegate_->IsHidden()) | 1839 if (delegate_ && delegate_->IsHidden()) |
| 1819 watch_time_reporter_->OnHidden(); | 1840 watch_time_reporter_->OnHidden(); |
| 1820 else | 1841 else |
| 1821 watch_time_reporter_->OnShown(); | 1842 watch_time_reporter_->OnShown(); |
| 1822 } | 1843 } |
| 1823 | 1844 |
| 1824 } // namespace media | 1845 } // namespace media |
| OLD | NEW |