| 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_CAPTURER_VIDEO_FRAME_CAPTURER_H_ | |
| 6 #define REMOTING_CAPTURER_VIDEO_FRAME_CAPTURER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/shared_memory.h" | |
| 11 #include "third_party/skia/include/core/SkRegion.h" | |
| 12 | |
| 13 namespace remoting { | |
| 14 | |
| 15 class CaptureData; | |
| 16 struct MouseCursorShape; | |
| 17 class SharedBufferFactory; | |
| 18 | |
| 19 // Class used to capture video frames asynchronously. | |
| 20 // | |
| 21 // The full capture sequence is as follows: | |
| 22 // | |
| 23 // (1) Start | |
| 24 // This is when pre-capture steps are executed, such as flagging the | |
| 25 // display to prevent it from sleeping during a session. | |
| 26 // | |
| 27 // (2) InvalidateRegion | |
| 28 // This is an optional step where regions of the screen are marked as | |
| 29 // invalid. Some platforms (Windows, for now) won't use this and will | |
| 30 // instead calculate the diff-regions later (in step (2). Other | |
| 31 // platforms (Mac) will use this to mark all the changed regions of the | |
| 32 // screen. Some limited rect-merging (e.g., to eliminate exact | |
| 33 // duplicates) may be done here. | |
| 34 // | |
| 35 // (3) CaptureFrame | |
| 36 // This is where the bits for the invalid rects are packaged up and sent | |
| 37 // to the encoder. | |
| 38 // A screen capture is performed if needed. For example, Windows requires | |
| 39 // a capture to calculate the diff from the previous screen, whereas the | |
| 40 // Mac version does not. | |
| 41 // | |
| 42 // (4) Stop | |
| 43 // This is when post-capture steps are executed, such as releasing the | |
| 44 // assertion that prevents the display from sleeping. | |
| 45 // | |
| 46 // Implementation has to ensure the following guarantees: | |
| 47 // 1. Double buffering | |
| 48 // Since data can be read while another capture action is happening. | |
| 49 class VideoFrameCapturer { | |
| 50 public: | |
| 51 // Provides callbacks used by the capturer to pass captured video frames and | |
| 52 // mouse cursor shapes to the processing pipeline. | |
| 53 class Delegate { | |
| 54 public: | |
| 55 virtual ~Delegate() {} | |
| 56 | |
| 57 // Called when a video frame has been captured. |capture_data| describes | |
| 58 // a captured frame. | |
| 59 virtual void OnCaptureCompleted( | |
| 60 scoped_refptr<CaptureData> capture_data) = 0; | |
| 61 | |
| 62 // Called when the cursor shape has changed. | |
| 63 // TODO(sergeyu): Move cursor shape capturing to a separate class. | |
| 64 virtual void OnCursorShapeChanged( | |
| 65 scoped_ptr<MouseCursorShape> cursor_shape) = 0; | |
| 66 }; | |
| 67 | |
| 68 virtual ~VideoFrameCapturer() {} | |
| 69 | |
| 70 // Create platform-specific capturer. | |
| 71 static scoped_ptr<VideoFrameCapturer> Create(); | |
| 72 | |
| 73 // Create platform-specific capturer that uses shared memory buffers. | |
| 74 static scoped_ptr<VideoFrameCapturer> CreateWithFactory( | |
| 75 SharedBufferFactory* shared_buffer_factory); | |
| 76 | |
| 77 #if defined(OS_LINUX) | |
| 78 // Set whether the VideoFrameCapturer should try to use X DAMAGE support if it | |
| 79 // is available. This needs to be called before the VideoFrameCapturer is | |
| 80 // created. | |
| 81 // This is used by the Virtual Me2Me host, since the XDamage extension is | |
| 82 // known to work reliably in this case. | |
| 83 | |
| 84 // TODO(lambroslambrou): This currently sets a global flag, referenced during | |
| 85 // VideoFrameCapturer::Create(). This is a temporary solution, until the | |
| 86 // DesktopEnvironment class is refactored to allow applications to control | |
| 87 // the creation of various stubs (including the VideoFrameCapturer) - see | |
| 88 // http://crbug.com/104544 | |
| 89 static void EnableXDamage(bool enable); | |
| 90 #endif // defined(OS_LINUX) | |
| 91 | |
| 92 // Called at the beginning of a capturing session. |delegate| must remain | |
| 93 // valid until Stop() is called. | |
| 94 virtual void Start(Delegate* delegate) = 0; | |
| 95 | |
| 96 // Called at the end of a capturing session. | |
| 97 virtual void Stop() = 0; | |
| 98 | |
| 99 // Invalidates the specified region. | |
| 100 virtual void InvalidateRegion(const SkRegion& invalid_region) = 0; | |
| 101 | |
| 102 // Captures the screen data associated with each of the accumulated | |
| 103 // dirty region. When the capture is complete, the delegate is notified even | |
| 104 // if the dirty region is empty. | |
| 105 // | |
| 106 // It is OK to call this method while another thread is reading | |
| 107 // data of the previous capture. There can be at most one concurrent read | |
| 108 // going on when this method is called. | |
| 109 virtual void CaptureFrame() = 0; | |
| 110 }; | |
| 111 | |
| 112 } // namespace remoting | |
| 113 | |
| 114 #endif // REMOTING_CAPTURER_VIDEO_FRAME_CAPTURER_H_ | |
| OLD | NEW |