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 | 2bb3afa | 2016-03-16 15:58:08 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
zijiehe | 88ac827 | 2017-03-22 11:38:46 -0700 | [diff] [blame] | 16 | #include "webrtc/modules/desktop_capture/desktop_capture_types.h" |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 17 | #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 18 | #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 19 | #include "webrtc/modules/desktop_capture/shared_memory.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 20 | #include "webrtc/rtc_base/constructormagic.h" |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 21 | #include "webrtc/typedefs.h" |
| 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | // DesktopFrame represents a video frame captured from the screen. |
| 26 | class DesktopFrame { |
| 27 | public: |
| 28 | // DesktopFrame objects always hold RGBA data. |
| 29 | static const int kBytesPerPixel = 4; |
| 30 | |
| 31 | virtual ~DesktopFrame(); |
| 32 | |
| 33 | // Size of the frame. |
| 34 | const DesktopSize& size() const { return size_; } |
| 35 | |
| 36 | // Distance in the buffer between two neighboring rows in bytes. |
| 37 | int stride() const { return stride_; } |
| 38 | |
| 39 | // Data buffer used for the frame. |
| 40 | uint8_t* data() const { return data_; } |
| 41 | |
| 42 | // SharedMemory used for the buffer or NULL if memory is allocated on the |
| 43 | // heap. The result is guaranteed to be deleted only after the frame is |
| 44 | // deleted (classes that inherit from DesktopFrame must ensure it). |
| 45 | SharedMemory* shared_memory() const { return shared_memory_; } |
| 46 | |
| 47 | // Indicates region of the screen that has changed since the previous frame. |
| 48 | const DesktopRegion& updated_region() const { return updated_region_; } |
| 49 | DesktopRegion* mutable_updated_region() { return &updated_region_; } |
| 50 | |
| 51 | // DPI of the screen being captured. May be set to zero, e.g. if DPI is |
| 52 | // unknown. |
| 53 | const DesktopVector& dpi() const { return dpi_; } |
| 54 | void set_dpi(const DesktopVector& dpi) { dpi_ = dpi; } |
| 55 | |
| 56 | // Time taken to capture the frame in milliseconds. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 57 | int64_t capture_time_ms() const { return capture_time_ms_; } |
| 58 | 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] | 59 | |
sergeyu@chromium.org | 5d85819 | 2013-11-19 02:15:47 +0000 | [diff] [blame] | 60 | // Copies pixels from a buffer or another frame. |dest_rect| rect must lay |
| 61 | // within bounds of this frame. |
qiangchen | 6f79d84 | 2016-09-21 16:44:55 -0700 | [diff] [blame] | 62 | void CopyPixelsFrom(const uint8_t* src_buffer, |
zijiehe | 2970c2a | 2016-05-20 22:08:00 -0700 | [diff] [blame] | 63 | int src_stride, |
sergeyu@chromium.org | 5d85819 | 2013-11-19 02:15:47 +0000 | [diff] [blame] | 64 | const DesktopRect& dest_rect); |
| 65 | void CopyPixelsFrom(const DesktopFrame& src_frame, |
| 66 | const DesktopVector& src_pos, |
| 67 | const DesktopRect& dest_rect); |
| 68 | |
jiayl@webrtc.org | 0e71070 | 2014-11-11 18:15:55 +0000 | [diff] [blame] | 69 | // A helper to return the data pointer of a frame at the specified position. |
| 70 | uint8_t* GetFrameDataAtPos(const DesktopVector& pos) const; |
| 71 | |
zijiehe | 88ac827 | 2017-03-22 11:38:46 -0700 | [diff] [blame] | 72 | // The DesktopCapturer implementation which generates current DesktopFrame. |
| 73 | // Not all DesktopCapturer implementations set this field; it's set to |
| 74 | // kUnknown by default. |
| 75 | uint32_t capturer_id() const { return capturer_id_; } |
| 76 | void set_capturer_id(uint32_t capturer_id) { |
| 77 | capturer_id_ = capturer_id; |
| 78 | } |
| 79 | |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 80 | protected: |
| 81 | DesktopFrame(DesktopSize size, |
| 82 | int stride, |
| 83 | uint8_t* data, |
| 84 | SharedMemory* shared_memory); |
| 85 | |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 86 | // Ownership of the buffers is defined by the classes that inherit from this |
| 87 | // class. They must guarantee that the buffer is not deleted before the frame |
| 88 | // is deleted. |
| 89 | uint8_t* const data_; |
| 90 | SharedMemory* const shared_memory_; |
| 91 | |
zijiehe | 2970c2a | 2016-05-20 22:08:00 -0700 | [diff] [blame] | 92 | private: |
| 93 | const DesktopSize size_; |
| 94 | const int stride_; |
| 95 | |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 96 | DesktopRegion updated_region_; |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 97 | DesktopVector dpi_; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 98 | int64_t capture_time_ms_; |
zijiehe | 88ac827 | 2017-03-22 11:38:46 -0700 | [diff] [blame] | 99 | uint32_t capturer_id_; |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 100 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 101 | RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrame); |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | // A DesktopFrame that stores data in the heap. |
| 105 | class BasicDesktopFrame : public DesktopFrame { |
| 106 | public: |
| 107 | explicit BasicDesktopFrame(DesktopSize size); |
Sergey Ulanov | 098c1de | 2015-09-01 11:36:40 -0700 | [diff] [blame] | 108 | ~BasicDesktopFrame() override; |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 109 | |
sergeyu@chromium.org | 2df89c0 | 2013-10-17 19:47:18 +0000 | [diff] [blame] | 110 | // Creates a BasicDesktopFrame that contains copy of |frame|. |
| 111 | static DesktopFrame* CopyOf(const DesktopFrame& frame); |
| 112 | |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 113 | private: |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 114 | RTC_DISALLOW_COPY_AND_ASSIGN(BasicDesktopFrame); |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | // A DesktopFrame that stores data in shared memory. |
| 118 | class SharedMemoryDesktopFrame : public DesktopFrame { |
| 119 | public: |
kwiberg | 2bb3afa | 2016-03-16 15:58:08 -0700 | [diff] [blame] | 120 | static std::unique_ptr<DesktopFrame> Create( |
sergeyu | cc9669c | 2016-02-09 15:13:26 -0800 | [diff] [blame] | 121 | DesktopSize size, |
| 122 | SharedMemoryFactory* shared_memory_factory); |
| 123 | |
zijiehe | 2970c2a | 2016-05-20 22:08:00 -0700 | [diff] [blame] | 124 | static std::unique_ptr<DesktopFrame> Create( |
| 125 | DesktopSize size, |
| 126 | std::unique_ptr<SharedMemory> shared_memory); |
| 127 | |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 128 | // Takes ownership of |shared_memory|. |
zijiehe | 2970c2a | 2016-05-20 22:08:00 -0700 | [diff] [blame] | 129 | // TODO(zijiehe): Hide constructors after fake_desktop_capturer.cc has been |
| 130 | // migrated, Create() is preferred. |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 131 | SharedMemoryDesktopFrame(DesktopSize size, |
| 132 | int stride, |
| 133 | SharedMemory* shared_memory); |
Sergey Ulanov | 098c1de | 2015-09-01 11:36:40 -0700 | [diff] [blame] | 134 | ~SharedMemoryDesktopFrame() override; |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 135 | |
| 136 | private: |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 137 | RTC_DISALLOW_COPY_AND_ASSIGN(SharedMemoryDesktopFrame); |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | } // namespace webrtc |
| 141 | |
| 142 | #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_ |
| 143 | |