sergeyu@chromium.org | 85a1dab | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_ |
| 12 | #define WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_ |
| 13 | |
| 14 | #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 15 | #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 16 | #include "webrtc/modules/desktop_capture/shared_memory.h" |
sergeyu@chromium.org | 935c8c7 | 2013-12-07 01:03:28 +0000 | [diff] [blame] | 17 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
sergeyu@chromium.org | 85a1dab | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 18 | #include "webrtc/typedefs.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | // DesktopFrame represents a video frame captured from the screen. |
| 23 | class DesktopFrame { |
| 24 | public: |
| 25 | // DesktopFrame objects always hold RGBA data. |
| 26 | static const int kBytesPerPixel = 4; |
| 27 | |
| 28 | virtual ~DesktopFrame(); |
| 29 | |
| 30 | // Size of the frame. |
| 31 | const DesktopSize& size() const { return size_; } |
| 32 | |
| 33 | // Distance in the buffer between two neighboring rows in bytes. |
| 34 | int stride() const { return stride_; } |
| 35 | |
| 36 | // Data buffer used for the frame. |
| 37 | uint8_t* data() const { return data_; } |
| 38 | |
| 39 | // SharedMemory used for the buffer or NULL if memory is allocated on the |
| 40 | // heap. The result is guaranteed to be deleted only after the frame is |
| 41 | // deleted (classes that inherit from DesktopFrame must ensure it). |
| 42 | SharedMemory* shared_memory() const { return shared_memory_; } |
| 43 | |
| 44 | // Indicates region of the screen that has changed since the previous frame. |
| 45 | const DesktopRegion& updated_region() const { return updated_region_; } |
| 46 | DesktopRegion* mutable_updated_region() { return &updated_region_; } |
| 47 | |
| 48 | // DPI of the screen being captured. May be set to zero, e.g. if DPI is |
| 49 | // unknown. |
| 50 | const DesktopVector& dpi() const { return dpi_; } |
| 51 | void set_dpi(const DesktopVector& dpi) { dpi_ = dpi; } |
| 52 | |
| 53 | // Time taken to capture the frame in milliseconds. |
| 54 | int32_t capture_time_ms() const { return capture_time_ms_; } |
| 55 | void set_capture_time_ms(int32_t time_ms) { capture_time_ms_ = time_ms; } |
| 56 | |
sergeyu@chromium.org | 935c8c7 | 2013-12-07 01:03:28 +0000 | [diff] [blame] | 57 | // Optional shape for the frame. Frames may be shaped e.g. if |
| 58 | // capturing the contents of a shaped window. |
| 59 | const DesktopRegion* shape() const { return shape_.get(); } |
| 60 | void set_shape(DesktopRegion* shape) { shape_.reset(shape); } |
| 61 | |
sergeyu@chromium.org | 8b0791c | 2013-11-19 02:15:47 +0000 | [diff] [blame] | 62 | // Copies pixels from a buffer or another frame. |dest_rect| rect must lay |
| 63 | // within bounds of this frame. |
| 64 | void CopyPixelsFrom(uint8_t* src_buffer, int src_stride, |
| 65 | const DesktopRect& dest_rect); |
| 66 | void CopyPixelsFrom(const DesktopFrame& src_frame, |
| 67 | const DesktopVector& src_pos, |
| 68 | const DesktopRect& dest_rect); |
| 69 | |
sergeyu@chromium.org | 85a1dab | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 70 | protected: |
| 71 | DesktopFrame(DesktopSize size, |
| 72 | int stride, |
| 73 | uint8_t* data, |
| 74 | SharedMemory* shared_memory); |
| 75 | |
| 76 | const DesktopSize size_; |
| 77 | const int stride_; |
| 78 | |
| 79 | // Ownership of the buffers is defined by the classes that inherit from this |
| 80 | // class. They must guarantee that the buffer is not deleted before the frame |
| 81 | // is deleted. |
| 82 | uint8_t* const data_; |
| 83 | SharedMemory* const shared_memory_; |
| 84 | |
| 85 | DesktopRegion updated_region_; |
sergeyu@chromium.org | 85a1dab | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 86 | DesktopVector dpi_; |
| 87 | int32_t capture_time_ms_; |
sergeyu@chromium.org | 935c8c7 | 2013-12-07 01:03:28 +0000 | [diff] [blame] | 88 | scoped_ptr<DesktopRegion> shape_; |
sergeyu@chromium.org | 85a1dab | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 89 | |
| 90 | private: |
| 91 | DISALLOW_COPY_AND_ASSIGN(DesktopFrame); |
| 92 | }; |
| 93 | |
| 94 | // A DesktopFrame that stores data in the heap. |
| 95 | class BasicDesktopFrame : public DesktopFrame { |
| 96 | public: |
| 97 | explicit BasicDesktopFrame(DesktopSize size); |
| 98 | virtual ~BasicDesktopFrame(); |
| 99 | |
sergeyu@chromium.org | 2873c4c | 2013-10-17 19:47:18 +0000 | [diff] [blame] | 100 | // Creates a BasicDesktopFrame that contains copy of |frame|. |
| 101 | static DesktopFrame* CopyOf(const DesktopFrame& frame); |
| 102 | |
sergeyu@chromium.org | 85a1dab | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 103 | private: |
| 104 | DISALLOW_COPY_AND_ASSIGN(BasicDesktopFrame); |
| 105 | }; |
| 106 | |
| 107 | // A DesktopFrame that stores data in shared memory. |
| 108 | class SharedMemoryDesktopFrame : public DesktopFrame { |
| 109 | public: |
| 110 | // Takes ownership of |shared_memory|. |
| 111 | SharedMemoryDesktopFrame(DesktopSize size, |
| 112 | int stride, |
| 113 | SharedMemory* shared_memory); |
| 114 | virtual ~SharedMemoryDesktopFrame(); |
| 115 | |
| 116 | private: |
| 117 | DISALLOW_COPY_AND_ASSIGN(SharedMemoryDesktopFrame); |
| 118 | }; |
| 119 | |
| 120 | } // namespace webrtc |
| 121 | |
| 122 | #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_ |
| 123 | |