OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_HOST_VIDEO_FRAME_CAPTURER_H_ |
| 6 #define REMOTING_HOST_VIDEO_FRAME_CAPTURER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" |
| 10 #include "media/base/video_frame.h" |
| 11 #include "third_party/skia/include/core/SkRegion.h" |
| 12 |
| 13 namespace remoting { |
| 14 |
| 15 namespace protocol { |
| 16 class CursorShapeInfo; |
| 17 } |
| 18 |
| 19 class CaptureData; |
| 20 |
| 21 // A class to perform the task of capturing the image of a window. |
| 22 // The capture action is asynchronous to allow maximum throughput. |
| 23 // |
| 24 // The full capture process is as follows: |
| 25 // |
| 26 // (1) Start |
| 27 // This is when pre-capture steps are executed, such as flagging the |
| 28 // display to prevent it from sleeping during a session. |
| 29 // |
| 30 // (2) InvalidateRects |
| 31 // This is an optional step where regions of the screen are marked as |
| 32 // invalid. Some platforms (Windows, for now) won't use this and will |
| 33 // instead calculate the diff-regions later (in step (2). Other |
| 34 // platforms (Mac) will use this to mark all the changed regions of the |
| 35 // screen. Some limited rect-merging (e.g., to eliminate exact |
| 36 // duplicates) may be done here. |
| 37 // |
| 38 // (3) CaptureInvalidRects |
| 39 // This is where the bits for the invalid rects are packaged up and sent |
| 40 // to the encoder. |
| 41 // A screen capture is performed if needed. For example, Windows requires |
| 42 // a capture to calculate the diff from the previous screen, whereas the |
| 43 // Mac version does not. |
| 44 // |
| 45 // (4) Stop |
| 46 // This is when post-capture steps are executed, such as releasing the |
| 47 // assertion that prevents the display from sleeping. |
| 48 // |
| 49 // Implementation has to ensure the following guarantees: |
| 50 // 1. Double buffering |
| 51 // Since data can be read while another capture action is happening. |
| 52 class VideoFrameCapturer { |
| 53 public: |
| 54 // CaptureCompletedCallback is called when the capturer has completed. |
| 55 typedef base::Callback<void(scoped_refptr<CaptureData>)> |
| 56 CaptureCompletedCallback; |
| 57 |
| 58 // CursorShapeChangedCallback is called when the cursor shape has changed. |
| 59 typedef base::Callback<void(scoped_ptr<protocol::CursorShapeInfo>)> |
| 60 CursorShapeChangedCallback; |
| 61 |
| 62 virtual ~VideoFrameCapturer() {} |
| 63 |
| 64 // Create platform-specific capturer. |
| 65 static VideoFrameCapturer* Create(); |
| 66 |
| 67 #if defined(OS_LINUX) |
| 68 // Set whether the VideoFrameCapturer should try to use X DAMAGE support if it |
| 69 // is available. This needs to be called before the VideoFrameCapturer is |
| 70 // created. |
| 71 // This is used by the Virtual Me2Me host, since the XDamage extension is |
| 72 // known to work reliably in this case. |
| 73 |
| 74 // TODO(lambroslambrou): This currently sets a global flag, referenced during |
| 75 // VideoFrameCapturer::Create(). This is a temporary solution, until the |
| 76 // DesktopEnvironment class is refactored to allow applications to control |
| 77 // the creation of various stubs (including the VideoFrameCapturer) - see |
| 78 // http://crbug.com/104544 |
| 79 static void EnableXDamage(bool enable); |
| 80 #endif // defined(OS_LINUX) |
| 81 |
| 82 // Called at the beginning of a capturing session. |
| 83 virtual void Start( |
| 84 const CursorShapeChangedCallback& callback) = 0; |
| 85 |
| 86 // Called at the end of a capturing session. |
| 87 virtual void Stop() = 0; |
| 88 |
| 89 // Called when the screen configuration is changed. |
| 90 virtual void ScreenConfigurationChanged() = 0; |
| 91 |
| 92 // Return the pixel format of the screen. |
| 93 virtual media::VideoFrame::Format pixel_format() const = 0; |
| 94 |
| 95 // Clear out the invalid region. |
| 96 virtual void ClearInvalidRegion() = 0; |
| 97 |
| 98 // Invalidate the specified region. |
| 99 virtual void InvalidateRegion(const SkRegion& invalid_region) = 0; |
| 100 |
| 101 // Invalidate the entire screen, of a given size. |
| 102 virtual void InvalidateScreen(const SkISize& size) = 0; |
| 103 |
| 104 // Invalidate the entire screen, using the size of the most recently |
| 105 // captured screen. |
| 106 virtual void InvalidateFullScreen() = 0; |
| 107 |
| 108 // Capture the screen data associated with each of the accumulated |
| 109 // dirty region. |
| 110 // When the capture is complete, |callback| is called even if the dirty region |
| 111 // is empty. |
| 112 // |
| 113 // It is OK to call this method while another thread is reading |
| 114 // data of the previous capture. |
| 115 // There can be at most one concurrent read going on when this |
| 116 // method is called. |
| 117 virtual void CaptureInvalidRegion( |
| 118 const CaptureCompletedCallback& callback) = 0; |
| 119 |
| 120 // Get the size of the most recently captured screen. |
| 121 virtual const SkISize& size_most_recent() const = 0; |
| 122 }; |
| 123 |
| 124 } // namespace remoting |
| 125 |
| 126 #endif // REMOTING_HOST_VIDEO_FRAME_CAPTURER_H_ |
OLD | NEW |