| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef MEDIA_VIDEO_CAPTURE_SCREEN_SCREEN_CAPTURER_H_ | 5 #ifndef MEDIA_VIDEO_CAPTURE_SCREEN_SCREEN_CAPTURER_H_ |
| 6 #define MEDIA_VIDEO_CAPTURE_SCREEN_SCREEN_CAPTURER_H_ | 6 #define MEDIA_VIDEO_CAPTURE_SCREEN_SCREEN_CAPTURER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/shared_memory.h" | |
| 12 #include "media/base/media_export.h" | 11 #include "media/base/media_export.h" |
| 13 #include "media/video/capture/screen/shared_buffer.h" | 12 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
| 14 | 13 |
| 15 namespace media { | 14 namespace media { |
| 16 | 15 |
| 17 class ScreenCaptureData; | |
| 18 struct MouseCursorShape; | 16 struct MouseCursorShape; |
| 19 class SharedBuffer; | |
| 20 | 17 |
| 21 // Class used to capture video frames asynchronously. | 18 // Class used to capture video frames asynchronously. |
| 22 // | 19 // |
| 23 // The full capture sequence is as follows: | 20 // The full capture sequence is as follows: |
| 24 // | 21 // |
| 25 // (1) Start | 22 // (1) Start |
| 26 // This is when pre-capture steps are executed, such as flagging the | 23 // This is when pre-capture steps are executed, such as flagging the |
| 27 // display to prevent it from sleeping during a session. | 24 // display to prevent it from sleeping during a session. |
| 28 // | 25 // |
| 29 // (2) CaptureFrame | 26 // (2) CaptureFrame |
| 30 // This is where the bits for the invalid rects are packaged up and sent | 27 // This is where the bits for the invalid rects are packaged up and sent |
| 31 // to the encoder. | 28 // to the encoder. |
| 32 // A screen capture is performed if needed. For example, Windows requires | 29 // A screen capture is performed if needed. For example, Windows requires |
| 33 // a capture to calculate the diff from the previous screen, whereas the | 30 // a capture to calculate the diff from the previous screen, whereas the |
| 34 // Mac version does not. | 31 // Mac version does not. |
| 35 // | 32 // |
| 36 // Implementation has to ensure the following guarantees: | 33 // Implementation has to ensure the following guarantees: |
| 37 // 1. Double buffering | 34 // 1. Double buffering |
| 38 // Since data can be read while another capture action is happening. | 35 // Since data can be read while another capture action is happening. |
| 39 class MEDIA_EXPORT ScreenCapturer { | 36 class MEDIA_EXPORT ScreenCapturer |
| 37 : public NON_EXPORTED_BASE(webrtc::DesktopCapturer) { |
| 40 public: | 38 public: |
| 41 // Provides callbacks used by the capturer to pass captured video frames and | 39 // Provides callbacks used by the capturer to pass captured video frames and |
| 42 // mouse cursor shapes to the processing pipeline. | 40 // mouse cursor shapes to the processing pipeline. |
| 43 class MEDIA_EXPORT Delegate { | 41 // |
| 42 // TODO(sergeyu): Move cursor shape capturing to a separate class because it's |
| 43 // unrelated. |
| 44 class MEDIA_EXPORT MouseShapeObserver { |
| 44 public: | 45 public: |
| 45 // Creates a shared memory buffer of the given size. Returns NULL if shared | |
| 46 // buffers are not supported. | |
| 47 virtual scoped_refptr<SharedBuffer> CreateSharedBuffer(uint32 size); | |
| 48 | |
| 49 // Notifies the delegate that the buffer is no longer used and can be | |
| 50 // released. | |
| 51 virtual void ReleaseSharedBuffer(scoped_refptr<SharedBuffer> buffer); | |
| 52 | |
| 53 // Called when a video frame has been captured. |capture_data| describes | |
| 54 // a captured frame. | |
| 55 virtual void OnCaptureCompleted( | |
| 56 scoped_refptr<ScreenCaptureData> capture_data) = 0; | |
| 57 | |
| 58 // Called when the cursor shape has changed. | 46 // Called when the cursor shape has changed. |
| 59 // TODO(sergeyu): Move cursor shape capturing to a separate class. | |
| 60 virtual void OnCursorShapeChanged( | 47 virtual void OnCursorShapeChanged( |
| 61 scoped_ptr<MouseCursorShape> cursor_shape) = 0; | 48 scoped_ptr<MouseCursorShape> cursor_shape) = 0; |
| 62 | 49 |
| 63 protected: | 50 protected: |
| 64 virtual ~Delegate() {} | 51 virtual ~MouseShapeObserver() {} |
| 65 }; | 52 }; |
| 66 | 53 |
| 67 virtual ~ScreenCapturer() {} | 54 virtual ~ScreenCapturer() {} |
| 68 | 55 |
| 69 // Creates platform-specific capturer. | 56 // Creates platform-specific capturer. |
| 70 static scoped_ptr<ScreenCapturer> Create(); | 57 static scoped_ptr<ScreenCapturer> Create(); |
| 71 | 58 |
| 72 #if defined(OS_LINUX) | 59 #if defined(OS_LINUX) |
| 73 // Creates platform-specific capturer and instructs it whether it should use | 60 // Creates platform-specific capturer and instructs it whether it should use |
| 74 // X DAMAGE support. | 61 // X DAMAGE support. |
| 75 static scoped_ptr<ScreenCapturer> CreateWithXDamage(bool use_x_damage); | 62 static scoped_ptr<ScreenCapturer> CreateWithXDamage(bool use_x_damage); |
| 76 #elif defined(OS_WIN) | 63 #elif defined(OS_WIN) |
| 77 // Creates Windows-specific capturer and instructs it whether or not to | 64 // Creates Windows-specific capturer and instructs it whether or not to |
| 78 // disable desktop compositing. | 65 // disable desktop compositing. |
| 79 static scoped_ptr<ScreenCapturer> CreateWithDisableAero(bool disable_aero); | 66 static scoped_ptr<ScreenCapturer> CreateWithDisableAero(bool disable_aero); |
| 80 #endif | 67 #endif // defined(OS_WIN) |
| 81 | 68 |
| 82 // Called at the beginning of a capturing session. |delegate| must remain | 69 // Called at the beginning of a capturing session. |mouse_shape_observer| must |
| 83 // valid until Stop() is called. | 70 // remain valid until the capturer is destroyed. |
| 84 virtual void Start(Delegate* delegate) = 0; | 71 virtual void SetMouseShapeObserver( |
| 85 | 72 MouseShapeObserver* mouse_shape_observer) = 0; |
| 86 // Captures the screen data associated with each of the accumulated | |
| 87 // dirty region. When the capture is complete, the delegate is notified even | |
| 88 // if the dirty region is empty. | |
| 89 // | |
| 90 // It is OK to call this method while another thread is reading | |
| 91 // data of the previous capture. There can be at most one concurrent read | |
| 92 // going on when this method is called. | |
| 93 virtual void CaptureFrame() = 0; | |
| 94 }; | 73 }; |
| 95 | 74 |
| 96 } // namespace media | 75 } // namespace media |
| 97 | 76 |
| 98 #endif // MEDIA_VIDEO_CAPTURE_SCREEN_SCREEN_CAPTURER_H_ | 77 #endif // MEDIA_VIDEO_CAPTURE_SCREEN_SCREEN_CAPTURER_H_ |
| OLD | NEW |