| 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/webmediaplayer_ms.h" | 5 #include "content/renderer/media/webmediaplayer_ms.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "gpu/blink/webgraphicscontext3d_impl.h" | 25 #include "gpu/blink/webgraphicscontext3d_impl.h" |
| 26 #include "media/base/media_log.h" | 26 #include "media/base/media_log.h" |
| 27 #include "media/base/video_frame.h" | 27 #include "media/base/video_frame.h" |
| 28 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 28 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| 29 #include "third_party/WebKit/public/platform/WebRect.h" | 29 #include "third_party/WebKit/public/platform/WebRect.h" |
| 30 #include "third_party/WebKit/public/platform/WebSize.h" | 30 #include "third_party/WebKit/public/platform/WebSize.h" |
| 31 #include "third_party/WebKit/public/platform/WebURL.h" | 31 #include "third_party/WebKit/public/platform/WebURL.h" |
| 32 | 32 |
| 33 namespace content { | 33 namespace content { |
| 34 | 34 |
| 35 namespace { | |
| 36 | |
| 37 static const float DEFAULT_AUDIO_VOLUME = 1.0f; | |
| 38 | |
| 39 } // anonymous namespace | |
| 40 | |
| 41 WebMediaPlayerMS::WebMediaPlayerMS( | 35 WebMediaPlayerMS::WebMediaPlayerMS( |
| 42 blink::WebFrame* frame, | 36 blink::WebFrame* frame, |
| 43 blink::WebMediaPlayerClient* client, | 37 blink::WebMediaPlayerClient* client, |
| 44 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 38 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
| 45 media::MediaLog* media_log, | 39 media::MediaLog* media_log, |
| 46 scoped_ptr<MediaStreamRendererFactory> factory, | 40 scoped_ptr<MediaStreamRendererFactory> factory, |
| 47 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | 41 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, |
| 48 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, | 42 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, |
| 49 const scoped_refptr<base::TaskRunner>& worker_task_runner, | 43 const scoped_refptr<base::TaskRunner>& worker_task_runner, |
| 50 media::GpuVideoAcceleratorFactories* gpu_factories, | 44 media::GpuVideoAcceleratorFactories* gpu_factories, |
| 51 const blink::WebString& sink_id, | 45 const blink::WebString& sink_id, |
| 52 const blink::WebSecurityOrigin& security_origin) | 46 const blink::WebSecurityOrigin& security_origin) |
| 53 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), | 47 : frame_(frame), |
| 54 frame_(frame), | |
| 55 network_state_(WebMediaPlayer::NetworkStateEmpty), | 48 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 56 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 49 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 57 buffered_(static_cast<size_t>(0)), | 50 buffered_(static_cast<size_t>(0)), |
| 58 client_(client), | 51 client_(client), |
| 59 delegate_(delegate), | 52 delegate_(delegate), |
| 53 delegate_id_(0), |
| 60 paused_(true), | 54 paused_(true), |
| 61 render_frame_suspended_(false), | 55 render_frame_suspended_(false), |
| 62 received_first_frame_(false), | 56 received_first_frame_(false), |
| 63 media_log_(media_log), | 57 media_log_(media_log), |
| 64 renderer_factory_(std::move(factory)), | 58 renderer_factory_(std::move(factory)), |
| 65 media_task_runner_(media_task_runner), | 59 media_task_runner_(media_task_runner), |
| 66 worker_task_runner_(worker_task_runner), | 60 worker_task_runner_(worker_task_runner), |
| 67 gpu_factories_(gpu_factories), | 61 gpu_factories_(gpu_factories), |
| 68 compositor_task_runner_(compositor_task_runner), | 62 compositor_task_runner_(compositor_task_runner), |
| 69 initial_audio_output_device_id_(sink_id.utf8()), | 63 initial_audio_output_device_id_(sink_id.utf8()), |
| 70 initial_security_origin_(security_origin.isNull() | 64 initial_security_origin_(security_origin.isNull() |
| 71 ? url::Origin() | 65 ? url::Origin() |
| 72 : url::Origin(security_origin)) { | 66 : url::Origin(security_origin)), |
| 67 volume_(1.0), |
| 68 volume_multiplier_(1.0) { |
| 73 DVLOG(1) << __FUNCTION__; | 69 DVLOG(1) << __FUNCTION__; |
| 74 DCHECK(client); | 70 DCHECK(client); |
| 71 if (delegate_) |
| 72 delegate_id_ = delegate_->AddObserver(this); |
| 73 |
| 75 media_log_->AddEvent( | 74 media_log_->AddEvent( |
| 76 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 75 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
| 77 } | 76 } |
| 78 | 77 |
| 79 WebMediaPlayerMS::~WebMediaPlayerMS() { | 78 WebMediaPlayerMS::~WebMediaPlayerMS() { |
| 80 DVLOG(1) << __FUNCTION__; | 79 DVLOG(1) << __FUNCTION__; |
| 81 DCHECK(thread_checker_.CalledOnValidThread()); | 80 DCHECK(thread_checker_.CalledOnValidThread()); |
| 82 | 81 |
| 83 if (compositor_ && !compositor_task_runner_->BelongsToCurrentThread()) | 82 if (compositor_ && !compositor_task_runner_->BelongsToCurrentThread()) |
| 84 compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_.release()); | 83 compositor_task_runner_->DeleteSoon(FROM_HERE, compositor_.release()); |
| 85 | 84 |
| 86 get_client()->setWebLayer(nullptr); | 85 get_client()->setWebLayer(nullptr); |
| 87 | 86 |
| 88 if (video_frame_provider_) | 87 if (video_frame_provider_) |
| 89 video_frame_provider_->Stop(); | 88 video_frame_provider_->Stop(); |
| 90 | 89 |
| 91 if (audio_renderer_) | 90 if (audio_renderer_) |
| 92 audio_renderer_->Stop(); | 91 audio_renderer_->Stop(); |
| 93 | 92 |
| 94 media_log_->AddEvent( | 93 media_log_->AddEvent( |
| 95 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); | 94 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); |
| 96 | 95 |
| 97 if (delegate_.get()) | 96 if (delegate_) { |
| 98 delegate_->PlayerGone(this); | 97 delegate_->PlayerGone(delegate_id_); |
| 98 delegate_->RemoveObserver(delegate_id_); |
| 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 101 void WebMediaPlayerMS::load(LoadType load_type, | 102 void WebMediaPlayerMS::load(LoadType load_type, |
| 102 const blink::WebURL& url, | 103 const blink::WebURL& url, |
| 103 CORSMode /*cors_mode*/) { | 104 CORSMode /*cors_mode*/) { |
| 104 DVLOG(1) << __FUNCTION__; | 105 DVLOG(1) << __FUNCTION__; |
| 105 DCHECK(thread_checker_.CalledOnValidThread()); | 106 DCHECK(thread_checker_.CalledOnValidThread()); |
| 106 | 107 |
| 107 // TODO(acolwell): Change this to DCHECK_EQ(load_type, LoadTypeMediaStream) | 108 // TODO(acolwell): Change this to DCHECK_EQ(load_type, LoadTypeMediaStream) |
| 108 // once Blink-side changes land. | 109 // once Blink-side changes land. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 130 url, frame->GetRoutingID(), initial_audio_output_device_id_, | 131 url, frame->GetRoutingID(), initial_audio_output_device_id_, |
| 131 initial_security_origin_); | 132 initial_security_origin_); |
| 132 } | 133 } |
| 133 | 134 |
| 134 if (!video_frame_provider_ && !audio_renderer_) { | 135 if (!video_frame_provider_ && !audio_renderer_) { |
| 135 SetNetworkState(WebMediaPlayer::NetworkStateNetworkError); | 136 SetNetworkState(WebMediaPlayer::NetworkStateNetworkError); |
| 136 return; | 137 return; |
| 137 } | 138 } |
| 138 | 139 |
| 139 if (audio_renderer_) { | 140 if (audio_renderer_) { |
| 140 audio_renderer_->SetVolume(DEFAULT_AUDIO_VOLUME); | 141 audio_renderer_->SetVolume(volume_); |
| 141 audio_renderer_->Start(); | 142 audio_renderer_->Start(); |
| 142 } | 143 } |
| 143 if (video_frame_provider_) | 144 if (video_frame_provider_) |
| 144 video_frame_provider_->Start(); | 145 video_frame_provider_->Start(); |
| 145 if (audio_renderer_ && !video_frame_provider_) { | 146 if (audio_renderer_ && !video_frame_provider_) { |
| 146 // This is audio-only mode. | 147 // This is audio-only mode. |
| 147 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 148 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 148 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 149 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| 149 } | 150 } |
| 150 } | 151 } |
| 151 | 152 |
| 152 void WebMediaPlayerMS::play() { | 153 void WebMediaPlayerMS::play() { |
| 153 DVLOG(1) << __FUNCTION__; | 154 DVLOG(1) << __FUNCTION__; |
| 154 DCHECK(thread_checker_.CalledOnValidThread()); | 155 DCHECK(thread_checker_.CalledOnValidThread()); |
| 155 if (paused_) { | 156 if (paused_) { |
| 156 if (video_frame_provider_.get()) | 157 if (video_frame_provider_.get()) |
| 157 video_frame_provider_->Play(); | 158 video_frame_provider_->Play(); |
| 158 | 159 |
| 159 compositor_->StartRendering(); | 160 compositor_->StartRendering(); |
| 160 | 161 |
| 161 if (audio_renderer_.get()) | 162 if (audio_renderer_.get()) |
| 162 audio_renderer_->Play(); | 163 audio_renderer_->Play(); |
| 163 | 164 |
| 164 if (delegate_.get()) | 165 if (delegate_) { |
| 165 delegate_->DidPlay(this); | 166 delegate_->DidPlay(delegate_id_, hasVideo(), hasAudio(), false, |
| 167 media::kInfiniteDuration()); |
| 168 } |
| 166 } | 169 } |
| 167 | 170 |
| 168 paused_ = false; | 171 paused_ = false; |
| 169 | 172 |
| 170 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY)); | 173 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY)); |
| 171 } | 174 } |
| 172 | 175 |
| 173 void WebMediaPlayerMS::pause() { | 176 void WebMediaPlayerMS::pause() { |
| 174 DVLOG(1) << __FUNCTION__; | 177 DVLOG(1) << __FUNCTION__; |
| 175 DCHECK(thread_checker_.CalledOnValidThread()); | 178 DCHECK(thread_checker_.CalledOnValidThread()); |
| 176 | 179 |
| 177 if (video_frame_provider_.get()) | 180 if (video_frame_provider_.get()) |
| 178 video_frame_provider_->Pause(); | 181 video_frame_provider_->Pause(); |
| 179 | 182 |
| 180 compositor_->StopRendering(); | 183 compositor_->StopRendering(); |
| 181 compositor_->ReplaceCurrentFrameWithACopy(); | 184 compositor_->ReplaceCurrentFrameWithACopy(); |
| 182 | 185 |
| 183 if (!paused_) { | 186 if (!paused_) { |
| 184 if (audio_renderer_.get()) | 187 if (audio_renderer_.get()) |
| 185 audio_renderer_->Pause(); | 188 audio_renderer_->Pause(); |
| 186 | 189 |
| 187 if (delegate_.get()) | 190 if (delegate_) |
| 188 delegate_->DidPause(this); | 191 delegate_->DidPause(delegate_id_, false); |
| 189 } | 192 } |
| 190 | 193 |
| 191 paused_ = true; | 194 paused_ = true; |
| 192 | 195 |
| 193 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PAUSE)); | 196 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PAUSE)); |
| 194 } | 197 } |
| 195 | 198 |
| 196 bool WebMediaPlayerMS::supportsSave() const { | 199 bool WebMediaPlayerMS::supportsSave() const { |
| 197 DCHECK(thread_checker_.CalledOnValidThread()); | 200 DCHECK(thread_checker_.CalledOnValidThread()); |
| 198 return false; | 201 return false; |
| 199 } | 202 } |
| 200 | 203 |
| 201 void WebMediaPlayerMS::seek(double seconds) { | 204 void WebMediaPlayerMS::seek(double seconds) { |
| 202 DCHECK(thread_checker_.CalledOnValidThread()); | 205 DCHECK(thread_checker_.CalledOnValidThread()); |
| 203 } | 206 } |
| 204 | 207 |
| 205 void WebMediaPlayerMS::setRate(double rate) { | 208 void WebMediaPlayerMS::setRate(double rate) { |
| 206 DCHECK(thread_checker_.CalledOnValidThread()); | 209 DCHECK(thread_checker_.CalledOnValidThread()); |
| 207 } | 210 } |
| 208 | 211 |
| 209 void WebMediaPlayerMS::setVolume(double volume) { | 212 void WebMediaPlayerMS::setVolume(double volume) { |
| 210 DVLOG(1) << __FUNCTION__ << "(volume=" << volume << ")"; | 213 DVLOG(1) << __FUNCTION__ << "(volume=" << volume << ")"; |
| 211 DCHECK(thread_checker_.CalledOnValidThread()); | 214 DCHECK(thread_checker_.CalledOnValidThread()); |
| 215 volume_ = volume; |
| 212 if (audio_renderer_.get()) | 216 if (audio_renderer_.get()) |
| 213 audio_renderer_->SetVolume(volume); | 217 audio_renderer_->SetVolume(volume_ * volume_multiplier_); |
| 214 } | 218 } |
| 215 | 219 |
| 216 void WebMediaPlayerMS::setSinkId( | 220 void WebMediaPlayerMS::setSinkId( |
| 217 const blink::WebString& sink_id, | 221 const blink::WebString& sink_id, |
| 218 const blink::WebSecurityOrigin& security_origin, | 222 const blink::WebSecurityOrigin& security_origin, |
| 219 blink::WebSetSinkIdCallbacks* web_callback) { | 223 blink::WebSetSinkIdCallbacks* web_callback) { |
| 220 DVLOG(1) << __FUNCTION__; | 224 DVLOG(1) << __FUNCTION__; |
| 221 DCHECK(thread_checker_.CalledOnValidThread()); | 225 DCHECK(thread_checker_.CalledOnValidThread()); |
| 222 const media::SwitchOutputDeviceCB callback = | 226 const media::SwitchOutputDeviceCB callback = |
| 223 media::ConvertToSwitchOutputDeviceCB(web_callback); | 227 media::ConvertToSwitchOutputDeviceCB(web_callback); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 NOTIMPLEMENTED(); | 357 NOTIMPLEMENTED(); |
| 354 return 0; | 358 return 0; |
| 355 } | 359 } |
| 356 | 360 |
| 357 unsigned WebMediaPlayerMS::videoDecodedByteCount() const { | 361 unsigned WebMediaPlayerMS::videoDecodedByteCount() const { |
| 358 DCHECK(thread_checker_.CalledOnValidThread()); | 362 DCHECK(thread_checker_.CalledOnValidThread()); |
| 359 NOTIMPLEMENTED(); | 363 NOTIMPLEMENTED(); |
| 360 return 0; | 364 return 0; |
| 361 } | 365 } |
| 362 | 366 |
| 363 void WebMediaPlayerMS::WasHidden() { | 367 void WebMediaPlayerMS::OnHidden() { |
| 364 #if defined(OS_ANDROID) | 368 #if defined(OS_ANDROID) |
| 365 DCHECK(thread_checker_.CalledOnValidThread()); | 369 DCHECK(thread_checker_.CalledOnValidThread()); |
| 366 DCHECK(!render_frame_suspended_); | 370 DCHECK(!render_frame_suspended_); |
| 367 | 371 |
| 368 // Method called when the RenderFrame is sent to background and suspended | 372 // Method called when the RenderFrame is sent to background and suspended |
| 369 // (android). Substitute the displayed VideoFrame with a copy to avoid | 373 // (android). Substitute the displayed VideoFrame with a copy to avoid |
| 370 // holding on to it unnecessarily. | 374 // holding on to it unnecessarily. |
| 371 render_frame_suspended_=true; | 375 render_frame_suspended_ = true; |
| 372 if (!paused_) | 376 if (!paused_) |
| 373 compositor_->ReplaceCurrentFrameWithACopy(); | 377 compositor_->ReplaceCurrentFrameWithACopy(); |
| 374 #endif // defined(OS_ANDROID) | 378 #endif // defined(OS_ANDROID) |
| 375 } | 379 } |
| 376 | 380 |
| 377 void WebMediaPlayerMS::WasShown() { | 381 void WebMediaPlayerMS::OnShown() { |
| 378 #if defined(OS_ANDROID) | 382 #if defined(OS_ANDROID) |
| 379 DCHECK(thread_checker_.CalledOnValidThread()); | 383 DCHECK(thread_checker_.CalledOnValidThread()); |
| 380 | 384 |
| 381 render_frame_suspended_ = false; | 385 render_frame_suspended_ = false; |
| 382 #endif // defined(OS_ANDROID) | 386 #endif // defined(OS_ANDROID) |
| 383 } | 387 } |
| 384 | 388 |
| 389 void WebMediaPlayerMS::OnPlay() { |
| 390 play(); |
| 391 client_->playbackStateChanged(); |
| 392 } |
| 393 |
| 394 void WebMediaPlayerMS::OnPause() { |
| 395 pause(); |
| 396 client_->playbackStateChanged(); |
| 397 } |
| 398 |
| 399 void WebMediaPlayerMS::OnVolumeMultiplierUpdate(double multiplier) { |
| 400 volume_multiplier_ = multiplier; |
| 401 setVolume(volume_); |
| 402 } |
| 403 |
| 385 bool WebMediaPlayerMS::copyVideoTextureToPlatformTexture( | 404 bool WebMediaPlayerMS::copyVideoTextureToPlatformTexture( |
| 386 blink::WebGraphicsContext3D* web_graphics_context, | 405 blink::WebGraphicsContext3D* web_graphics_context, |
| 387 unsigned int texture, | 406 unsigned int texture, |
| 388 unsigned int internal_format, | 407 unsigned int internal_format, |
| 389 unsigned int type, | 408 unsigned int type, |
| 390 bool premultiply_alpha, | 409 bool premultiply_alpha, |
| 391 bool flip_y) { | 410 bool flip_y) { |
| 392 TRACE_EVENT0("media", "WebMediaPlayerMS:copyVideoTextureToPlatformTexture"); | 411 TRACE_EVENT0("media", "WebMediaPlayerMS:copyVideoTextureToPlatformTexture"); |
| 393 DCHECK(thread_checker_.CalledOnValidThread()); | 412 DCHECK(thread_checker_.CalledOnValidThread()); |
| 394 | 413 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 media::SkCanvasVideoRenderer* WebMediaPlayerMS::GetSkCanvasVideoRenderer() { | 501 media::SkCanvasVideoRenderer* WebMediaPlayerMS::GetSkCanvasVideoRenderer() { |
| 483 return &video_renderer_; | 502 return &video_renderer_; |
| 484 } | 503 } |
| 485 | 504 |
| 486 void WebMediaPlayerMS::ResetCanvasCache() { | 505 void WebMediaPlayerMS::ResetCanvasCache() { |
| 487 DCHECK(thread_checker_.CalledOnValidThread()); | 506 DCHECK(thread_checker_.CalledOnValidThread()); |
| 488 video_renderer_.ResetCache(); | 507 video_renderer_.ResetCache(); |
| 489 } | 508 } |
| 490 | 509 |
| 491 } // namespace content | 510 } // namespace content |
| OLD | NEW |