sergeyu@chromium.org | 15e32cc | 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 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 14 | #include "webrtc/base/scoped_ptr.h" |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 15 | #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 16 | #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 17 | #include "webrtc/modules/desktop_capture/shared_memory.h" |
| 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. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 54 | int64_t capture_time_ms() const { return capture_time_ms_; } |
| 55 | void set_capture_time_ms(int64_t time_ms) { capture_time_ms_ = time_ms; } |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 56 | |
sergeyu@chromium.org | 5e13ac9 | 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 | 5d85819 | 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 | |
jiayl@webrtc.org | 0e71070 | 2014-11-11 18:15:55 +0000 | [diff] [blame] | 70 | // A helper to return the data pointer of a frame at the specified position. |
| 71 | uint8_t* GetFrameDataAtPos(const DesktopVector& pos) const; |
| 72 | |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 73 | protected: |
| 74 | DesktopFrame(DesktopSize size, |
| 75 | int stride, |
| 76 | uint8_t* data, |
| 77 | SharedMemory* shared_memory); |
| 78 | |
| 79 | const DesktopSize size_; |
| 80 | const int stride_; |
| 81 | |
| 82 | // Ownership of the buffers is defined by the classes that inherit from this |
| 83 | // class. They must guarantee that the buffer is not deleted before the frame |
| 84 | // is deleted. |
| 85 | uint8_t* const data_; |
| 86 | SharedMemory* const shared_memory_; |
| 87 | |
| 88 | DesktopRegion updated_region_; |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 89 | DesktopVector dpi_; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 90 | int64_t capture_time_ms_; |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 91 | rtc::scoped_ptr<DesktopRegion> shape_; |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 92 | |
| 93 | private: |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame^] | 94 | RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrame); |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | // A DesktopFrame that stores data in the heap. |
| 98 | class BasicDesktopFrame : public DesktopFrame { |
| 99 | public: |
| 100 | explicit BasicDesktopFrame(DesktopSize size); |
Sergey Ulanov | 098c1de | 2015-09-01 11:36:40 -0700 | [diff] [blame] | 101 | ~BasicDesktopFrame() override; |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 102 | |
sergeyu@chromium.org | 2df89c0 | 2013-10-17 19:47:18 +0000 | [diff] [blame] | 103 | // Creates a BasicDesktopFrame that contains copy of |frame|. |
| 104 | static DesktopFrame* CopyOf(const DesktopFrame& frame); |
| 105 | |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 106 | private: |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame^] | 107 | RTC_DISALLOW_COPY_AND_ASSIGN(BasicDesktopFrame); |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | // A DesktopFrame that stores data in shared memory. |
| 111 | class SharedMemoryDesktopFrame : public DesktopFrame { |
| 112 | public: |
| 113 | // Takes ownership of |shared_memory|. |
| 114 | SharedMemoryDesktopFrame(DesktopSize size, |
| 115 | int stride, |
| 116 | SharedMemory* shared_memory); |
Sergey Ulanov | 098c1de | 2015-09-01 11:36:40 -0700 | [diff] [blame] | 117 | ~SharedMemoryDesktopFrame() override; |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 118 | |
| 119 | private: |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame^] | 120 | RTC_DISALLOW_COPY_AND_ASSIGN(SharedMemoryDesktopFrame); |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | } // namespace webrtc |
| 124 | |
| 125 | #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_ |
| 126 | |