blob: 49b964630ce069ac1d1bfc277def563241a979b9 [file] [log] [blame]
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +00001/*
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.org00b8f6b2015-02-26 14:34:55 +000014#include "webrtc/base/scoped_ptr.h"
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +000015#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
20namespace webrtc {
21
22// DesktopFrame represents a video frame captured from the screen.
23class 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.org16825b12015-01-12 21:51:21 +000054 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.org15e32cc2013-04-29 20:10:57 +000056
sergeyu@chromium.org5e13ac92013-12-07 01:03:28 +000057 // 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.org5d858192013-11-19 02:15:47 +000062 // 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.org0e710702014-11-11 18:15:55 +000070 // 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.org15e32cc2013-04-29 20:10:57 +000073 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.org15e32cc2013-04-29 20:10:57 +000089 DesktopVector dpi_;
pkasting@chromium.org16825b12015-01-12 21:51:21 +000090 int64_t capture_time_ms_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000091 rtc::scoped_ptr<DesktopRegion> shape_;
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +000092
93 private:
henrikg3c089d72015-09-16 05:37:44 -070094 RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrame);
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +000095};
96
97// A DesktopFrame that stores data in the heap.
98class BasicDesktopFrame : public DesktopFrame {
99 public:
100 explicit BasicDesktopFrame(DesktopSize size);
Sergey Ulanov098c1de2015-09-01 11:36:40 -0700101 ~BasicDesktopFrame() override;
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +0000102
sergeyu@chromium.org2df89c02013-10-17 19:47:18 +0000103 // Creates a BasicDesktopFrame that contains copy of |frame|.
104 static DesktopFrame* CopyOf(const DesktopFrame& frame);
105
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +0000106 private:
henrikg3c089d72015-09-16 05:37:44 -0700107 RTC_DISALLOW_COPY_AND_ASSIGN(BasicDesktopFrame);
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +0000108};
109
110// A DesktopFrame that stores data in shared memory.
111class SharedMemoryDesktopFrame : public DesktopFrame {
112 public:
113 // Takes ownership of |shared_memory|.
114 SharedMemoryDesktopFrame(DesktopSize size,
115 int stride,
116 SharedMemory* shared_memory);
Sergey Ulanov098c1de2015-09-01 11:36:40 -0700117 ~SharedMemoryDesktopFrame() override;
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +0000118
119 private:
henrikg3c089d72015-09-16 05:37:44 -0700120 RTC_DISALLOW_COPY_AND_ASSIGN(SharedMemoryDesktopFrame);
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +0000121};
122
123} // namespace webrtc
124
125#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_
126