| 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/browser/renderer_host/media/desktop_capture_device_ash.h" | 5 #include "content/browser/renderer_host/media/desktop_capture_device_ash.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.h" |
| 9 #include "cc/output/copy_output_request.h" | 9 #include "cc/output/copy_output_request.h" |
| 10 #include "cc/output/copy_output_result.h" | 10 #include "cc/output/copy_output_result.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 public: | 34 public: |
| 35 DesktopVideoCaptureMachine(const DesktopMediaID& source); | 35 DesktopVideoCaptureMachine(const DesktopMediaID& source); |
| 36 virtual ~DesktopVideoCaptureMachine(); | 36 virtual ~DesktopVideoCaptureMachine(); |
| 37 | 37 |
| 38 // VideoCaptureFrameSource overrides. | 38 // VideoCaptureFrameSource overrides. |
| 39 virtual bool Start( | 39 virtual bool Start( |
| 40 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy) OVERRIDE; | 40 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy) OVERRIDE; |
| 41 virtual void Stop() OVERRIDE; | 41 virtual void Stop() OVERRIDE; |
| 42 | 42 |
| 43 // Implements aura::WindowObserver. | 43 // Implements aura::WindowObserver. |
| 44 virtual void OnWindowBoundsChanged(aura::Window* window, |
| 45 const gfx::Rect& old_bounds, |
| 46 const gfx::Rect& new_bounds) OVERRIDE; |
| 44 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; | 47 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; |
| 45 | 48 |
| 46 // Implements ui::CompositorObserver. | 49 // Implements ui::CompositorObserver. |
| 47 virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE {} | 50 virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE {} |
| 48 virtual void OnCompositingStarted(ui::Compositor* compositor, | 51 virtual void OnCompositingStarted(ui::Compositor* compositor, |
| 49 base::TimeTicks start_time) OVERRIDE {} | 52 base::TimeTicks start_time) OVERRIDE {} |
| 50 virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE; | 53 virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE; |
| 51 virtual void OnCompositingAborted(ui::Compositor* compositor) OVERRIDE {} | 54 virtual void OnCompositingAborted(ui::Compositor* compositor) OVERRIDE {} |
| 52 virtual void OnCompositingLockStateChanged( | 55 virtual void OnCompositingLockStateChanged( |
| 53 ui::Compositor* compositor) OVERRIDE {} | 56 ui::Compositor* compositor) OVERRIDE {} |
| 54 virtual void OnUpdateVSyncParameters(ui::Compositor* compositor, | 57 virtual void OnUpdateVSyncParameters(ui::Compositor* compositor, |
| 55 base::TimeTicks timebase, | 58 base::TimeTicks timebase, |
| 56 base::TimeDelta interval) OVERRIDE {} | 59 base::TimeDelta interval) OVERRIDE {} |
| 57 | 60 |
| 58 private: | 61 private: |
| 59 // Captures a frame. | 62 // Captures a frame. |
| 60 // |dirty| is false for timer polls and true for compositor updates. | 63 // |dirty| is false for timer polls and true for compositor updates. |
| 61 void Capture(bool dirty); | 64 void Capture(bool dirty); |
| 62 | 65 |
| 66 // Update capture size. Must be called on the UI thread. |
| 67 void UpdateCaptureSize(); |
| 68 |
| 63 // Response callback for cc::Layer::RequestCopyOfOutput(). | 69 // Response callback for cc::Layer::RequestCopyOfOutput(). |
| 64 void DidCopyOutput( | 70 void DidCopyOutput( |
| 65 scoped_refptr<media::VideoFrame> video_frame, | 71 scoped_refptr<media::VideoFrame> video_frame, |
| 66 base::Time start_time, | 72 base::Time start_time, |
| 67 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | 73 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
| 68 scoped_ptr<cc::CopyOutputResult> result); | 74 scoped_ptr<cc::CopyOutputResult> result); |
| 69 | 75 |
| 70 // The window associated with the desktop. | 76 // The window associated with the desktop. |
| 71 aura::Window* desktop_window_; | 77 aura::Window* desktop_window_; |
| 72 | 78 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 return false; | 116 return false; |
| 111 | 117 |
| 112 // If the desktop layer is already destroyed then return failure. | 118 // If the desktop layer is already destroyed then return failure. |
| 113 desktop_layer_ = desktop_window_->layer(); | 119 desktop_layer_ = desktop_window_->layer(); |
| 114 if (!desktop_layer_) | 120 if (!desktop_layer_) |
| 115 return false; | 121 return false; |
| 116 | 122 |
| 117 DCHECK(oracle_proxy.get()); | 123 DCHECK(oracle_proxy.get()); |
| 118 oracle_proxy_ = oracle_proxy; | 124 oracle_proxy_ = oracle_proxy; |
| 119 | 125 |
| 126 // Update capture size. |
| 127 UpdateCaptureSize(); |
| 128 |
| 120 // Start observing window events. | 129 // Start observing window events. |
| 121 desktop_window_->AddObserver(this); | 130 desktop_window_->AddObserver(this); |
| 122 | 131 |
| 123 // Start observing compositor updates. | 132 // Start observing compositor updates. |
| 124 ui::Compositor* compositor = desktop_layer_->GetCompositor(); | 133 ui::Compositor* compositor = desktop_layer_->GetCompositor(); |
| 125 if (!compositor) | 134 if (!compositor) |
| 126 return false; | 135 return false; |
| 127 | 136 |
| 128 compositor->AddObserver(this); | 137 compositor->AddObserver(this); |
| 129 | 138 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 149 if (compositor) | 158 if (compositor) |
| 150 compositor->RemoveObserver(this); | 159 compositor->RemoveObserver(this); |
| 151 } | 160 } |
| 152 | 161 |
| 153 // Stop timer. | 162 // Stop timer. |
| 154 timer_.Stop(); | 163 timer_.Stop(); |
| 155 | 164 |
| 156 started_ = false; | 165 started_ = false; |
| 157 } | 166 } |
| 158 | 167 |
| 168 void DesktopVideoCaptureMachine::UpdateCaptureSize() { |
| 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 170 if (oracle_proxy_ && desktop_layer_) { |
| 171 oracle_proxy_->UpdateCaptureSize(ui::ConvertSizeToPixel( |
| 172 desktop_layer_, desktop_layer_->bounds().size())); |
| 173 } |
| 174 } |
| 175 |
| 159 void DesktopVideoCaptureMachine::Capture(bool dirty) { | 176 void DesktopVideoCaptureMachine::Capture(bool dirty) { |
| 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 161 | 178 |
| 162 // Do not capture if the desktop layer is already destroyed. | 179 // Do not capture if the desktop layer is already destroyed. |
| 163 if (!desktop_layer_) | 180 if (!desktop_layer_) |
| 164 return; | 181 return; |
| 165 | 182 |
| 166 scoped_refptr<media::VideoFrame> frame; | 183 scoped_refptr<media::VideoFrame> frame; |
| 167 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; | 184 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
| 168 | 185 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 region_in_frame, | 258 region_in_frame, |
| 242 true, | 259 true, |
| 243 true)); | 260 true)); |
| 244 } | 261 } |
| 245 yuv_readback_pipeline_->ReadbackYUV( | 262 yuv_readback_pipeline_->ReadbackYUV( |
| 246 texture_mailbox.name(), texture_mailbox.sync_point(), video_frame.get(), | 263 texture_mailbox.name(), texture_mailbox.sync_point(), video_frame.get(), |
| 247 base::Bind(&CopyOutputFinishedForVideo, start_time, capture_frame_cb, | 264 base::Bind(&CopyOutputFinishedForVideo, start_time, capture_frame_cb, |
| 248 base::Passed(&release_callback))); | 265 base::Passed(&release_callback))); |
| 249 } | 266 } |
| 250 | 267 |
| 268 void DesktopVideoCaptureMachine::OnWindowBoundsChanged( |
| 269 aura::Window* window, |
| 270 const gfx::Rect& old_bounds, |
| 271 const gfx::Rect& new_bounds) { |
| 272 DCHECK(desktop_window_ && window == desktop_window_); |
| 273 |
| 274 // Post task to update capture size on UI thread. |
| 275 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 276 &DesktopVideoCaptureMachine::UpdateCaptureSize, AsWeakPtr())); |
| 277 } |
| 278 |
| 251 void DesktopVideoCaptureMachine::OnWindowDestroyed(aura::Window* window) { | 279 void DesktopVideoCaptureMachine::OnWindowDestroyed(aura::Window* window) { |
| 252 DCHECK(desktop_window_ && window == desktop_window_); | 280 DCHECK(desktop_window_ && window == desktop_window_); |
| 253 desktop_window_ = NULL; | 281 desktop_window_ = NULL; |
| 254 desktop_layer_ = NULL; | 282 desktop_layer_ = NULL; |
| 255 | 283 |
| 256 // Post task to stop capture on UI thread. | 284 // Post task to stop capture on UI thread. |
| 257 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 285 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 258 &DesktopVideoCaptureMachine::Stop, AsWeakPtr())); | 286 &DesktopVideoCaptureMachine::Stop, AsWeakPtr())); |
| 259 } | 287 } |
| 260 | 288 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 290 scoped_ptr<Client> client) { | 318 scoped_ptr<Client> client) { |
| 291 DVLOG(1) << "Allocating " << params.requested_format.frame_size.ToString(); | 319 DVLOG(1) << "Allocating " << params.requested_format.frame_size.ToString(); |
| 292 impl_->AllocateAndStart(params, client.Pass()); | 320 impl_->AllocateAndStart(params, client.Pass()); |
| 293 } | 321 } |
| 294 | 322 |
| 295 void DesktopCaptureDeviceAsh::StopAndDeAllocate() { | 323 void DesktopCaptureDeviceAsh::StopAndDeAllocate() { |
| 296 impl_->StopAndDeAllocate(); | 324 impl_->StopAndDeAllocate(); |
| 297 } | 325 } |
| 298 | 326 |
| 299 } // namespace content | 327 } // namespace content |
| OLD | NEW |