Line data Source code
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 <memory>
15 :
16 : #include "webrtc/base/constructormagic.h"
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"
20 : #include "webrtc/typedefs.h"
21 :
22 : namespace webrtc {
23 :
24 : // DesktopFrame represents a video frame captured from the screen.
25 : class DesktopFrame {
26 : public:
27 : // DesktopFrame objects always hold RGBA data.
28 : static const int kBytesPerPixel = 4;
29 :
30 : virtual ~DesktopFrame();
31 :
32 : // Size of the frame.
33 0 : const DesktopSize& size() const { return size_; }
34 :
35 : // Distance in the buffer between two neighboring rows in bytes.
36 0 : int stride() const { return stride_; }
37 :
38 : // Data buffer used for the frame.
39 0 : uint8_t* data() const { return data_; }
40 :
41 : // SharedMemory used for the buffer or NULL if memory is allocated on the
42 : // heap. The result is guaranteed to be deleted only after the frame is
43 : // deleted (classes that inherit from DesktopFrame must ensure it).
44 0 : SharedMemory* shared_memory() const { return shared_memory_; }
45 :
46 : // Indicates region of the screen that has changed since the previous frame.
47 0 : const DesktopRegion& updated_region() const { return updated_region_; }
48 0 : DesktopRegion* mutable_updated_region() { return &updated_region_; }
49 :
50 : // DPI of the screen being captured. May be set to zero, e.g. if DPI is
51 : // unknown.
52 0 : const DesktopVector& dpi() const { return dpi_; }
53 0 : void set_dpi(const DesktopVector& dpi) { dpi_ = dpi; }
54 :
55 : // Time taken to capture the frame in milliseconds.
56 0 : int64_t capture_time_ms() const { return capture_time_ms_; }
57 0 : void set_capture_time_ms(int64_t time_ms) { capture_time_ms_ = time_ms; }
58 :
59 : // Copies pixels from a buffer or another frame. |dest_rect| rect must lay
60 : // within bounds of this frame.
61 : void CopyPixelsFrom(const uint8_t* src_buffer,
62 : int src_stride,
63 : const DesktopRect& dest_rect);
64 : void CopyPixelsFrom(const DesktopFrame& src_frame,
65 : const DesktopVector& src_pos,
66 : const DesktopRect& dest_rect);
67 :
68 : // A helper to return the data pointer of a frame at the specified position.
69 : uint8_t* GetFrameDataAtPos(const DesktopVector& pos) const;
70 :
71 : protected:
72 : DesktopFrame(DesktopSize size,
73 : int stride,
74 : uint8_t* data,
75 : SharedMemory* shared_memory);
76 :
77 : // Ownership of the buffers is defined by the classes that inherit from this
78 : // class. They must guarantee that the buffer is not deleted before the frame
79 : // is deleted.
80 : uint8_t* const data_;
81 : SharedMemory* const shared_memory_;
82 :
83 : private:
84 : const DesktopSize size_;
85 : const int stride_;
86 :
87 : DesktopRegion updated_region_;
88 : DesktopVector dpi_;
89 : int64_t capture_time_ms_;
90 :
91 : RTC_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 : ~BasicDesktopFrame() override;
99 :
100 : // Creates a BasicDesktopFrame that contains copy of |frame|.
101 : static DesktopFrame* CopyOf(const DesktopFrame& frame);
102 :
103 : private:
104 : RTC_DISALLOW_COPY_AND_ASSIGN(BasicDesktopFrame);
105 : };
106 :
107 : // A DesktopFrame that stores data in shared memory.
108 : class SharedMemoryDesktopFrame : public DesktopFrame {
109 : public:
110 : static std::unique_ptr<DesktopFrame> Create(
111 : DesktopSize size,
112 : SharedMemoryFactory* shared_memory_factory);
113 :
114 : static std::unique_ptr<DesktopFrame> Create(
115 : DesktopSize size,
116 : std::unique_ptr<SharedMemory> shared_memory);
117 :
118 : // Takes ownership of |shared_memory|.
119 : // TODO(zijiehe): Hide constructors after fake_desktop_capturer.cc has been
120 : // migrated, Create() is preferred.
121 : SharedMemoryDesktopFrame(DesktopSize size,
122 : int stride,
123 : SharedMemory* shared_memory);
124 : ~SharedMemoryDesktopFrame() override;
125 :
126 : private:
127 : RTC_DISALLOW_COPY_AND_ASSIGN(SharedMemoryDesktopFrame);
128 : };
129 :
130 : } // namespace webrtc
131 :
132 : #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_
133 :
|