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 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "media/blink/texttrack_impl.h" | 31 #include "media/blink/texttrack_impl.h" |
32 #include "media/blink/webaudiosourceprovider_impl.h" | 32 #include "media/blink/webaudiosourceprovider_impl.h" |
33 #include "media/blink/webcontentdecryptionmodule_impl.h" | 33 #include "media/blink/webcontentdecryptionmodule_impl.h" |
34 #include "media/blink/webinbandtexttrack_impl.h" | 34 #include "media/blink/webinbandtexttrack_impl.h" |
35 #include "media/blink/webmediaplayer_delegate.h" | 35 #include "media/blink/webmediaplayer_delegate.h" |
36 #include "media/blink/webmediaplayer_util.h" | 36 #include "media/blink/webmediaplayer_util.h" |
37 #include "media/blink/webmediasource_impl.h" | 37 #include "media/blink/webmediasource_impl.h" |
38 #include "media/filters/chunk_demuxer.h" | 38 #include "media/filters/chunk_demuxer.h" |
39 #include "media/filters/ffmpeg_demuxer.h" | 39 #include "media/filters/ffmpeg_demuxer.h" |
40 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" | 40 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" |
| 41 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| 42 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient.
h" |
41 #include "third_party/WebKit/public/platform/WebMediaSource.h" | 43 #include "third_party/WebKit/public/platform/WebMediaSource.h" |
42 #include "third_party/WebKit/public/platform/WebRect.h" | 44 #include "third_party/WebKit/public/platform/WebRect.h" |
43 #include "third_party/WebKit/public/platform/WebSize.h" | 45 #include "third_party/WebKit/public/platform/WebSize.h" |
44 #include "third_party/WebKit/public/platform/WebString.h" | 46 #include "third_party/WebKit/public/platform/WebString.h" |
45 #include "third_party/WebKit/public/platform/WebURL.h" | 47 #include "third_party/WebKit/public/platform/WebURL.h" |
46 #include "third_party/WebKit/public/web/WebDocument.h" | 48 #include "third_party/WebKit/public/web/WebDocument.h" |
47 #include "third_party/WebKit/public/web/WebFrame.h" | 49 #include "third_party/WebKit/public/web/WebFrame.h" |
48 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 50 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
49 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 51 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
50 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 52 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ | 98 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ |
97 BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) | 99 BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) |
98 | 100 |
99 #define BIND_TO_RENDER_LOOP1(function, arg1) \ | 101 #define BIND_TO_RENDER_LOOP1(function, arg1) \ |
100 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ | 102 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ |
101 BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) | 103 BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) |
102 | 104 |
103 WebMediaPlayerImpl::WebMediaPlayerImpl( | 105 WebMediaPlayerImpl::WebMediaPlayerImpl( |
104 blink::WebLocalFrame* frame, | 106 blink::WebLocalFrame* frame, |
105 blink::WebMediaPlayerClient* client, | 107 blink::WebMediaPlayerClient* client, |
| 108 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
106 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 109 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
107 scoped_ptr<RendererFactory> renderer_factory, | 110 scoped_ptr<RendererFactory> renderer_factory, |
108 CdmFactory* cdm_factory, | 111 CdmFactory* cdm_factory, |
109 const WebMediaPlayerParams& params) | 112 const WebMediaPlayerParams& params) |
110 : frame_(frame), | 113 : frame_(frame), |
111 network_state_(WebMediaPlayer::NetworkStateEmpty), | 114 network_state_(WebMediaPlayer::NetworkStateEmpty), |
112 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 115 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
113 preload_(BufferedDataSource::AUTO), | 116 preload_(BufferedDataSource::AUTO), |
114 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 117 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
115 media_task_runner_(params.media_task_runner()), | 118 media_task_runner_(params.media_task_runner()), |
116 media_log_(params.media_log()), | 119 media_log_(params.media_log()), |
117 pipeline_(media_task_runner_, media_log_.get()), | 120 pipeline_(media_task_runner_, media_log_.get()), |
118 load_type_(LoadTypeURL), | 121 load_type_(LoadTypeURL), |
119 opaque_(false), | 122 opaque_(false), |
120 playback_rate_(0.0), | 123 playback_rate_(0.0), |
121 paused_(true), | 124 paused_(true), |
122 seeking_(false), | 125 seeking_(false), |
123 ended_(false), | 126 ended_(false), |
124 pending_seek_(false), | 127 pending_seek_(false), |
125 should_notify_time_changed_(false), | 128 should_notify_time_changed_(false), |
126 client_(client), | 129 client_(client), |
| 130 encrypted_client_(encrypted_client), |
127 delegate_(delegate), | 131 delegate_(delegate), |
128 defer_load_cb_(params.defer_load_cb()), | 132 defer_load_cb_(params.defer_load_cb()), |
129 context_3d_cb_(params.context_3d_cb()), | 133 context_3d_cb_(params.context_3d_cb()), |
130 supports_save_(true), | 134 supports_save_(true), |
131 chunk_demuxer_(NULL), | 135 chunk_demuxer_(NULL), |
132 // Threaded compositing isn't enabled universally yet. | 136 // Threaded compositing isn't enabled universally yet. |
133 compositor_task_runner_( | 137 compositor_task_runner_( |
134 params.compositor_task_runner() | 138 params.compositor_task_runner() |
135 ? params.compositor_task_runner() | 139 ? params.compositor_task_runner() |
136 : base::MessageLoop::current()->task_runner()), | 140 : base::MessageLoop::current()->task_runner()), |
137 compositor_(new VideoFrameCompositor( | 141 compositor_(new VideoFrameCompositor( |
138 compositor_task_runner_, | 142 compositor_task_runner_, |
139 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 143 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
140 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | 144 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
141 encrypted_media_support_(cdm_factory, | 145 encrypted_media_support_(cdm_factory, |
142 client, | 146 encrypted_client, |
143 params.media_permission(), | 147 params.media_permission(), |
144 base::Bind(&WebMediaPlayerImpl::SetCdm, | 148 base::Bind(&WebMediaPlayerImpl::SetCdm, |
145 AsWeakPtr(), | 149 AsWeakPtr(), |
146 base::Bind(&IgnoreCdmAttached))), | 150 base::Bind(&IgnoreCdmAttached))), |
147 renderer_factory_(renderer_factory.Pass()) { | 151 renderer_factory_(renderer_factory.Pass()) { |
148 media_log_->AddEvent( | 152 media_log_->AddEvent( |
149 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 153 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
150 | 154 |
151 if (params.initial_cdm()) { | 155 if (params.initial_cdm()) { |
152 SetCdm(base::Bind(&IgnoreCdmAttached), | 156 SetCdm(base::Bind(&IgnoreCdmAttached), |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && | 701 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && |
698 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { | 702 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { |
699 return; | 703 return; |
700 } | 704 } |
701 | 705 |
702 // TODO(xhwang): Update this UMA name. | 706 // TODO(xhwang): Update this UMA name. |
703 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); | 707 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); |
704 | 708 |
705 encrypted_media_support_.SetInitDataType(init_data_type); | 709 encrypted_media_support_.SetInitDataType(init_data_type); |
706 | 710 |
707 client_->encrypted(ConvertToWebInitDataType(init_data_type), | 711 encrypted_client_->encrypted( |
708 vector_as_array(&init_data), | 712 ConvertToWebInitDataType(init_data_type), vector_as_array(&init_data), |
709 base::saturated_cast<unsigned int>(init_data.size())); | 713 base::saturated_cast<unsigned int>(init_data.size())); |
710 } | 714 } |
711 | 715 |
712 void WebMediaPlayerImpl::OnWaitingForDecryptionKey() { | 716 void WebMediaPlayerImpl::OnWaitingForDecryptionKey() { |
713 client_->didBlockPlaybackWaitingForKey(); | 717 encrypted_client_->didBlockPlaybackWaitingForKey(); |
714 | 718 |
715 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called | 719 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called |
716 // when a key has been successfully added (e.g. OnSessionKeysChange() with | 720 // when a key has been successfully added (e.g. OnSessionKeysChange() with |
717 // |has_additional_usable_key| = true). http://crbug.com/461903 | 721 // |has_additional_usable_key| = true). http://crbug.com/461903 |
718 client_->didResumePlaybackBlockedForKey(); | 722 encrypted_client_->didResumePlaybackBlockedForKey(); |
719 } | 723 } |
720 | 724 |
721 void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, | 725 void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, |
722 CdmContext* cdm_context) { | 726 CdmContext* cdm_context) { |
723 // If CDM initialization succeeded, tell the pipeline about it. | 727 // If CDM initialization succeeded, tell the pipeline about it. |
724 if (cdm_context) | 728 if (cdm_context) |
725 pipeline_.SetCdm(cdm_context, cdm_attached_cb); | 729 pipeline_.SetCdm(cdm_context, cdm_attached_cb); |
726 } | 730 } |
727 | 731 |
728 void WebMediaPlayerImpl::OnCdmAttached( | 732 void WebMediaPlayerImpl::OnCdmAttached( |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 | 1035 |
1032 // pause() may be called after playback has ended and the HTMLMediaElement | 1036 // pause() may be called after playback has ended and the HTMLMediaElement |
1033 // requires that currentTime() == duration() after ending. We want to ensure | 1037 // requires that currentTime() == duration() after ending. We want to ensure |
1034 // |paused_time_| matches currentTime() in this case or a future seek() may | 1038 // |paused_time_| matches currentTime() in this case or a future seek() may |
1035 // incorrectly discard what it thinks is a seek to the existing time. | 1039 // incorrectly discard what it thinks is a seek to the existing time. |
1036 paused_time_ = | 1040 paused_time_ = |
1037 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); | 1041 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
1038 } | 1042 } |
1039 | 1043 |
1040 } // namespace media | 1044 } // namespace media |
OLD | NEW |