OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_ | 11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_ |
12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_ | 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 | 15 |
16 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | 16 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
17 #include "webrtc/modules/desktop_capture/desktop_region.h" | 17 #include "webrtc/modules/desktop_capture/desktop_region.h" |
18 #include "webrtc/modules/desktop_capture/shared_memory.h" | 18 #include "webrtc/modules/desktop_capture/shared_memory.h" |
19 #include "webrtc/typedefs.h" | 19 #include "webrtc/typedefs.h" |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 | 22 |
23 // DesktopFrame represents a video frame captured from the screen. | 23 // DesktopFrame represents a video frame captured from the screen. |
24 class DesktopFrame { | 24 class DesktopFrame { |
25 public: | 25 public: |
26 // DesktopFrame objects always hold RGBA data. | 26 // DesktopFrame objects always hold RGBA data. |
27 static const int kBytesPerPixel = 4; | 27 static const int kBytesPerPixel = 4; |
28 | 28 |
29 DesktopFrame(DesktopSize size, | |
Sergey Ulanov
2016/04/14 23:10:42
I don't think we want this constructor public. It
Hzj_jie
2016/04/15 19:42:17
Sure, I will write a new class in screen_capturer_
| |
30 int stride, | |
31 uint8_t* data, | |
32 SharedMemory* shared_memory); | |
33 | |
29 virtual ~DesktopFrame(); | 34 virtual ~DesktopFrame(); |
30 | 35 |
31 // Size of the frame. | 36 // Size of the frame. |
32 const DesktopSize& size() const { return size_; } | 37 const DesktopSize& size() const { return size_; } |
33 | 38 |
34 // Distance in the buffer between two neighboring rows in bytes. | 39 // Distance in the buffer between two neighboring rows in bytes. |
35 int stride() const { return stride_; } | 40 int stride() const { return stride_; } |
36 | 41 |
37 // Data buffer used for the frame. | 42 // Data buffer used for the frame. |
38 uint8_t* data() const { return data_; } | 43 uint8_t* data() const { return data_; } |
(...skipping 16 matching lines...) Expand all Loading... | |
55 int64_t capture_time_ms() const { return capture_time_ms_; } | 60 int64_t capture_time_ms() const { return capture_time_ms_; } |
56 void set_capture_time_ms(int64_t time_ms) { capture_time_ms_ = time_ms; } | 61 void set_capture_time_ms(int64_t time_ms) { capture_time_ms_ = time_ms; } |
57 | 62 |
58 // Optional shape for the frame. Frames may be shaped e.g. if | 63 // Optional shape for the frame. Frames may be shaped e.g. if |
59 // capturing the contents of a shaped window. | 64 // capturing the contents of a shaped window. |
60 const DesktopRegion* shape() const { return shape_.get(); } | 65 const DesktopRegion* shape() const { return shape_.get(); } |
61 void set_shape(DesktopRegion* shape) { shape_.reset(shape); } | 66 void set_shape(DesktopRegion* shape) { shape_.reset(shape); } |
62 | 67 |
63 // Copies pixels from a buffer or another frame. |dest_rect| rect must lay | 68 // Copies pixels from a buffer or another frame. |dest_rect| rect must lay |
64 // within bounds of this frame. | 69 // within bounds of this frame. |
65 void CopyPixelsFrom(uint8_t* src_buffer, int src_stride, | 70 void CopyPixelsFrom(uint8_t* src_buffer, |
71 int src_stride, | |
66 const DesktopRect& dest_rect); | 72 const DesktopRect& dest_rect); |
67 void CopyPixelsFrom(const DesktopFrame& src_frame, | 73 void CopyPixelsFrom(const DesktopFrame& src_frame, |
68 const DesktopVector& src_pos, | 74 const DesktopVector& src_pos, |
69 const DesktopRect& dest_rect); | 75 const DesktopRect& dest_rect); |
70 | 76 |
71 // A helper to return the data pointer of a frame at the specified position. | 77 // A helper to return the data pointer of a frame at the specified position. |
72 uint8_t* GetFrameDataAtPos(const DesktopVector& pos) const; | 78 uint8_t* GetFrameDataAtPos(const DesktopVector& pos) const; |
73 | 79 |
74 protected: | 80 protected: |
75 DesktopFrame(DesktopSize size, | |
76 int stride, | |
77 uint8_t* data, | |
78 SharedMemory* shared_memory); | |
79 | |
80 const DesktopSize size_; | |
81 const int stride_; | |
82 | |
83 // Ownership of the buffers is defined by the classes that inherit from this | 81 // Ownership of the buffers is defined by the classes that inherit from this |
84 // class. They must guarantee that the buffer is not deleted before the frame | 82 // class. They must guarantee that the buffer is not deleted before the frame |
85 // is deleted. | 83 // is deleted. |
86 uint8_t* const data_; | 84 uint8_t* const data_; |
87 SharedMemory* const shared_memory_; | 85 SharedMemory* const shared_memory_; |
88 | 86 |
87 private: | |
Sergey Ulanov
2016/04/14 23:10:42
If you are making these members private then I thi
Hzj_jie
2016/04/15 19:42:17
Unfortunately SharedMemoryDesktopFrame uses it in
| |
88 const DesktopSize size_; | |
89 const int stride_; | |
90 | |
89 DesktopRegion updated_region_; | 91 DesktopRegion updated_region_; |
90 DesktopVector dpi_; | 92 DesktopVector dpi_; |
91 int64_t capture_time_ms_; | 93 int64_t capture_time_ms_; |
92 std::unique_ptr<DesktopRegion> shape_; | 94 std::unique_ptr<DesktopRegion> shape_; |
93 | 95 |
94 private: | |
95 RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrame); | 96 RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrame); |
96 }; | 97 }; |
97 | 98 |
98 // A DesktopFrame that stores data in the heap. | 99 // A DesktopFrame that stores data in the heap. |
99 class BasicDesktopFrame : public DesktopFrame { | 100 class BasicDesktopFrame : public DesktopFrame { |
100 public: | 101 public: |
101 explicit BasicDesktopFrame(DesktopSize size); | 102 explicit BasicDesktopFrame(DesktopSize size); |
102 ~BasicDesktopFrame() override; | 103 ~BasicDesktopFrame() override; |
103 | 104 |
104 // Creates a BasicDesktopFrame that contains copy of |frame|. | 105 // Creates a BasicDesktopFrame that contains copy of |frame|. |
105 static DesktopFrame* CopyOf(const DesktopFrame& frame); | 106 static DesktopFrame* CopyOf(const DesktopFrame& frame); |
106 | 107 |
107 private: | 108 private: |
108 RTC_DISALLOW_COPY_AND_ASSIGN(BasicDesktopFrame); | 109 RTC_DISALLOW_COPY_AND_ASSIGN(BasicDesktopFrame); |
109 }; | 110 }; |
110 | 111 |
111 // A DesktopFrame that stores data in shared memory. | 112 // A DesktopFrame that stores data in shared memory. |
112 class SharedMemoryDesktopFrame : public DesktopFrame { | 113 class SharedMemoryDesktopFrame : public DesktopFrame { |
113 public: | 114 public: |
114 static std::unique_ptr<DesktopFrame> Create( | 115 static std::unique_ptr<DesktopFrame> Create( |
115 DesktopSize size, | 116 DesktopSize size, |
116 SharedMemoryFactory* shared_memory_factory); | 117 SharedMemoryFactory* shared_memory_factory); |
117 | 118 |
119 static std::unique_ptr<DesktopFrame> Create( | |
120 DesktopSize size, | |
121 int stride, | |
Sergey Ulanov
2016/04/14 23:10:42
Why do you need this constructor?
Hzj_jie
2016/04/15 19:42:17
In Windows, the pitch (stride in DesktopFrame) may
Sergey Ulanov
2016/04/19 23:51:07
I understand that, but this constructor allocates
Hzj_jie
2016/04/26 23:00:07
This constructor is used by remoting/protocol/fake
| |
122 SharedMemoryFactory* shared_memory_factory); | |
123 | |
118 // Takes ownership of |shared_memory|. | 124 // Takes ownership of |shared_memory|. |
119 // TODO(sergeyu): Remove this constructor and keep the second one. | 125 // TODO(zijiehe): Hide constructors, Create function is preferred. |
120 SharedMemoryDesktopFrame(DesktopSize size, | 126 SharedMemoryDesktopFrame(DesktopSize size, |
121 int stride, | 127 int stride, |
122 SharedMemory* shared_memory); | 128 SharedMemory* shared_memory); |
123 SharedMemoryDesktopFrame(DesktopSize size, | |
124 int stride, | |
125 std::unique_ptr<SharedMemory> shared_memory); | |
126 ~SharedMemoryDesktopFrame() override; | 129 ~SharedMemoryDesktopFrame() override; |
127 | 130 |
128 private: | 131 private: |
129 RTC_DISALLOW_COPY_AND_ASSIGN(SharedMemoryDesktopFrame); | 132 RTC_DISALLOW_COPY_AND_ASSIGN(SharedMemoryDesktopFrame); |
130 }; | 133 }; |
131 | 134 |
132 } // namespace webrtc | 135 } // namespace webrtc |
133 | 136 |
134 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_ | 137 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_ |
135 | 138 |
OLD | NEW |