| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/media/webmediaplayer_impl.h" | 5 #include "webkit/media/webmediaplayer_impl.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 32 #include "v8/include/v8.h" | 32 #include "v8/include/v8.h" |
| 33 #include "webkit/media/buffered_data_source.h" | 33 #include "webkit/media/buffered_data_source.h" |
| 34 #include "webkit/media/media_stream_client.h" | 34 #include "webkit/media/media_stream_client.h" |
| 35 #include "webkit/media/simple_data_source.h" | 35 #include "webkit/media/simple_data_source.h" |
| 36 #include "webkit/media/video_renderer_impl.h" | 36 #include "webkit/media/video_renderer_impl.h" |
| 37 #include "webkit/media/web_video_renderer.h" | |
| 38 #include "webkit/media/webmediaplayer_delegate.h" | 37 #include "webkit/media/webmediaplayer_delegate.h" |
| 39 #include "webkit/media/webmediaplayer_proxy.h" | 38 #include "webkit/media/webmediaplayer_proxy.h" |
| 40 #include "webkit/media/webvideoframe_impl.h" | 39 #include "webkit/media/webvideoframe_impl.h" |
| 41 | 40 |
| 42 using WebKit::WebCanvas; | 41 using WebKit::WebCanvas; |
| 43 using WebKit::WebRect; | 42 using WebKit::WebRect; |
| 44 using WebKit::WebSize; | 43 using WebKit::WebSize; |
| 45 using media::PipelineStatus; | 44 using media::PipelineStatus; |
| 46 | 45 |
| 47 namespace { | 46 namespace { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 incremented_externally_allocated_memory_(false) { | 123 incremented_externally_allocated_memory_(false) { |
| 125 // Saves the current message loop. | 124 // Saves the current message loop. |
| 126 DCHECK(!main_loop_); | 125 DCHECK(!main_loop_); |
| 127 main_loop_ = MessageLoop::current(); | 126 main_loop_ = MessageLoop::current(); |
| 128 media_log_->AddEvent( | 127 media_log_->AddEvent( |
| 129 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 128 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
| 130 } | 129 } |
| 131 | 130 |
| 132 bool WebMediaPlayerImpl::Initialize( | 131 bool WebMediaPlayerImpl::Initialize( |
| 133 WebKit::WebFrame* frame, | 132 WebKit::WebFrame* frame, |
| 134 bool use_simple_data_source, | 133 bool use_simple_data_source) { |
| 135 scoped_refptr<WebVideoRenderer> web_video_renderer) { | |
| 136 DCHECK_EQ(main_loop_, MessageLoop::current()); | 134 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 137 MessageLoop* pipeline_message_loop = | 135 MessageLoop* pipeline_message_loop = |
| 138 message_loop_factory_->GetMessageLoop("PipelineThread"); | 136 message_loop_factory_->GetMessageLoop("PipelineThread"); |
| 139 if (!pipeline_message_loop) { | 137 if (!pipeline_message_loop) { |
| 140 NOTREACHED() << "Could not start PipelineThread"; | 138 NOTREACHED() << "Could not start PipelineThread"; |
| 141 return false; | 139 return false; |
| 142 } | 140 } |
| 143 | 141 |
| 144 // Let V8 know we started new thread if we did not did it yet. | 142 // Let V8 know we started new thread if we did not did it yet. |
| 145 // Made separate task to avoid deletion of player currently being created. | 143 // Made separate task to avoid deletion of player currently being created. |
| 146 // Also, delaying GC until after player starts gets rid of starting lag -- | 144 // Also, delaying GC until after player starts gets rid of starting lag -- |
| 147 // collection happens in parallel with playing. | 145 // collection happens in parallel with playing. |
| 148 // TODO(enal): remove when we get rid of per-audio-stream thread. | 146 // TODO(enal): remove when we get rid of per-audio-stream thread. |
| 149 if (!incremented_externally_allocated_memory_) { | 147 if (!incremented_externally_allocated_memory_) { |
| 150 MessageLoop::current()->PostTask( | 148 MessageLoop::current()->PostTask( |
| 151 FROM_HERE, | 149 FROM_HERE, |
| 152 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, | 150 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, |
| 153 AsWeakPtr())); | 151 AsWeakPtr())); |
| 154 } | 152 } |
| 155 | 153 |
| 156 is_accelerated_compositing_active_ = | 154 is_accelerated_compositing_active_ = |
| 157 frame->view()->isAcceleratedCompositingActive(); | 155 frame->view()->isAcceleratedCompositingActive(); |
| 158 | 156 |
| 159 pipeline_ = new media::PipelineImpl(pipeline_message_loop, media_log_); | 157 pipeline_ = new media::PipelineImpl(pipeline_message_loop, media_log_); |
| 160 | 158 |
| 161 // Also we want to be notified of |main_loop_| destruction. | 159 // Also we want to be notified of |main_loop_| destruction. |
| 162 main_loop_->AddDestructionObserver(this); | 160 main_loop_->AddDestructionObserver(this); |
| 163 | 161 |
| 164 // Creates the proxy. | 162 // Create proxy and default video renderer. |
| 165 proxy_ = new WebMediaPlayerProxy(main_loop_, this); | 163 proxy_ = new WebMediaPlayerProxy(main_loop_, this); |
| 166 web_video_renderer->SetWebMediaPlayerProxy(proxy_); | 164 scoped_refptr<VideoRendererImpl> video_renderer = |
| 167 proxy_->SetVideoRenderer(web_video_renderer); | 165 new VideoRendererImpl(proxy_); |
| 166 filter_collection_->AddVideoRenderer(video_renderer); |
| 167 proxy_->SetVideoRenderer(video_renderer); |
| 168 | 168 |
| 169 // Set our pipeline callbacks. | 169 // Set our pipeline callbacks. |
| 170 pipeline_->Init( | 170 pipeline_->Init( |
| 171 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, | 171 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, |
| 172 proxy_.get()), | 172 proxy_.get()), |
| 173 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, | 173 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, |
| 174 proxy_.get()), | 174 proxy_.get()), |
| 175 base::Bind(&WebMediaPlayerProxy::NetworkEventCallback, | 175 base::Bind(&WebMediaPlayerProxy::NetworkEventCallback, |
| 176 proxy_.get())); | 176 proxy_.get())); |
| 177 | 177 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 } | 554 } |
| 555 | 555 |
| 556 unsigned long long WebMediaPlayerImpl::totalBytes() const { | 556 unsigned long long WebMediaPlayerImpl::totalBytes() const { |
| 557 DCHECK_EQ(main_loop_, MessageLoop::current()); | 557 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 558 | 558 |
| 559 return pipeline_->GetTotalBytes(); | 559 return pipeline_->GetTotalBytes(); |
| 560 } | 560 } |
| 561 | 561 |
| 562 void WebMediaPlayerImpl::setSize(const WebSize& size) { | 562 void WebMediaPlayerImpl::setSize(const WebSize& size) { |
| 563 DCHECK_EQ(main_loop_, MessageLoop::current()); | 563 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 564 DCHECK(proxy_); | |
| 565 | 564 |
| 566 proxy_->SetSize(gfx::Rect(0, 0, size.width, size.height)); | 565 // Don't need to do anything as we use the dimensions passed in via paint(). |
| 567 } | 566 } |
| 568 | 567 |
| 569 void WebMediaPlayerImpl::paint(WebCanvas* canvas, | 568 void WebMediaPlayerImpl::paint(WebCanvas* canvas, |
| 570 const WebRect& rect) { | 569 const WebRect& rect) { |
| 571 DCHECK_EQ(main_loop_, MessageLoop::current()); | 570 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 572 DCHECK(proxy_); | 571 DCHECK(proxy_); |
| 573 | 572 |
| 574 #if WEBKIT_USING_SKIA | 573 #if WEBKIT_USING_SKIA |
| 575 proxy_->Paint(canvas, rect); | 574 proxy_->Paint(canvas, rect); |
| 576 #elif WEBKIT_USING_CG | 575 #elif WEBKIT_USING_CG |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 return client_; | 907 return client_; |
| 909 } | 908 } |
| 910 | 909 |
| 911 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 910 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
| 912 DCHECK_EQ(main_loop_, MessageLoop::current()); | 911 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 913 incremented_externally_allocated_memory_ = true; | 912 incremented_externally_allocated_memory_ = true; |
| 914 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 913 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
| 915 } | 914 } |
| 916 | 915 |
| 917 } // namespace webkit_media | 916 } // namespace webkit_media |
| OLD | NEW |