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 | |
| 14 | #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 15 | #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 16 | #include "webrtc/modules/desktop_capture/shared_memory.h" |
| 17 | #include "webrtc/typedefs.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | // DesktopFrame represents a video frame captured from the screen. |
| 22 | class DesktopFrame { |
| 23 | public: |
| 24 | // DesktopFrame objects always hold RGBA data. |
| 25 | static const int kBytesPerPixel = 4; |
| 26 | |
| 27 | virtual ~DesktopFrame(); |
| 28 | |
| 29 | // Size of the frame. |
| 30 | const DesktopSize& size() const { return size_; } |
| 31 | |
| 32 | // Distance in the buffer between two neighboring rows in bytes. |
| 33 | int stride() const { return stride_; } |
| 34 | |
| 35 | // Data buffer used for the frame. |
| 36 | uint8_t* data() const { return data_; } |
| 37 | |
| 38 | // SharedMemory used for the buffer or NULL if memory is allocated on the |
| 39 | // heap. The result is guaranteed to be deleted only after the frame is |
| 40 | // deleted (classes that inherit from DesktopFrame must ensure it). |
| 41 | SharedMemory* shared_memory() const { return shared_memory_; } |
| 42 | |
| 43 | // Indicates region of the screen that has changed since the previous frame. |
| 44 | const DesktopRegion& updated_region() const { return updated_region_; } |
| 45 | DesktopRegion* mutable_updated_region() { return &updated_region_; } |
| 46 | |
| 47 | // DPI of the screen being captured. May be set to zero, e.g. if DPI is |
| 48 | // unknown. |
| 49 | const DesktopVector& dpi() const { return dpi_; } |
| 50 | void set_dpi(const DesktopVector& dpi) { dpi_ = dpi; } |
| 51 | |
| 52 | // Time taken to capture the frame in milliseconds. |
| 53 | int32_t capture_time_ms() const { return capture_time_ms_; } |
| 54 | void set_capture_time_ms(int32_t time_ms) { capture_time_ms_ = time_ms; } |
| 55 | |
| 56 | protected: |
| 57 | DesktopFrame(DesktopSize size, |
| 58 | int stride, |
| 59 | uint8_t* data, |
| 60 | SharedMemory* shared_memory); |
| 61 | |
| 62 | const DesktopSize size_; |
| 63 | const int stride_; |
| 64 | |
| 65 | // Ownership of the buffers is defined by the classes that inherit from this |
| 66 | // class. They must guarantee that the buffer is not deleted before the frame |
| 67 | // is deleted. |
| 68 | uint8_t* const data_; |
| 69 | SharedMemory* const shared_memory_; |
| 70 | |
| 71 | DesktopRegion updated_region_; |
| 72 | |
| 73 | DesktopVector dpi_; |
| 74 | int32_t capture_time_ms_; |
| 75 | |
| 76 | private: |
| 77 | DISALLOW_COPY_AND_ASSIGN(DesktopFrame); |
| 78 | }; |
| 79 | |
| 80 | // A DesktopFrame that stores data in the heap. |
| 81 | class BasicDesktopFrame : public DesktopFrame { |
| 82 | public: |
| 83 | explicit BasicDesktopFrame(DesktopSize size); |
| 84 | virtual ~BasicDesktopFrame(); |
| 85 | |
| 86 | private: |
| 87 | DISALLOW_COPY_AND_ASSIGN(BasicDesktopFrame); |
| 88 | }; |
| 89 | |
| 90 | // A DesktopFrame that stores data in shared memory. |
| 91 | class SharedMemoryDesktopFrame : public DesktopFrame { |
| 92 | public: |
| 93 | // Takes ownership of |shared_memory|. |
| 94 | SharedMemoryDesktopFrame(DesktopSize size, |
| 95 | int stride, |
| 96 | SharedMemory* shared_memory); |
| 97 | virtual ~SharedMemoryDesktopFrame(); |
| 98 | |
| 99 | private: |
| 100 | DISALLOW_COPY_AND_ASSIGN(SharedMemoryDesktopFrame); |
| 101 | }; |
| 102 | |
| 103 | } // namespace webrtc |
| 104 | |
| 105 | #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_H_ |
| 106 | |