sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef MODULES_DESKTOP_CAPTURE_SHARED_MEMORY_H_ |
| 12 | #define MODULES_DESKTOP_CAPTURE_SHARED_MEMORY_H_ |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 | [diff] [blame] | 13 | |
| 14 | #include <stddef.h> |
| 15 | |
| 16 | #if defined(WEBRTC_WIN) |
Bruce Dawson | 126d0b9 | 2021-08-29 17:04:02 | [diff] [blame] | 17 | // Forward declare HANDLE in a windows.h compatible way so that we can avoid |
| 18 | // including windows.h. |
| 19 | typedef void* HANDLE; |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 | [diff] [blame] | 20 | #endif |
| 21 | |
kwiberg | 84be511 | 2016-04-27 08:19:58 | [diff] [blame] | 22 | #include <memory> |
| 23 | |
Mirko Bonadei | 35214fc | 2019-09-23 12:54:28 | [diff] [blame] | 24 | #include "rtc_base/system/rtc_export.h" |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | |
| 28 | // SharedMemory is a base class for shared memory. It stores all required |
| 29 | // parameters of the buffer, but doesn't have any logic to allocate or destroy |
| 30 | // the actual buffer. DesktopCapturer consumers that need to use shared memory |
| 31 | // for video frames must extend this class with creation and destruction logic |
sergeyu | cc9669c | 2016-02-09 23:13:26 | [diff] [blame] | 32 | // specific for the target platform and then call |
| 33 | // DesktopCapturer::SetSharedMemoryFactory(). |
Mirko Bonadei | 35214fc | 2019-09-23 12:54:28 | [diff] [blame] | 34 | class RTC_EXPORT SharedMemory { |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 | [diff] [blame] | 35 | public: |
| 36 | #if defined(WEBRTC_WIN) |
| 37 | typedef HANDLE Handle; |
| 38 | static const Handle kInvalidHandle; |
| 39 | #else |
| 40 | typedef int Handle; |
| 41 | static const Handle kInvalidHandle; |
| 42 | #endif |
| 43 | |
| 44 | void* data() const { return data_; } |
| 45 | size_t size() const { return size_; } |
| 46 | |
| 47 | // Platform-specific handle of the buffer. |
| 48 | Handle handle() const { return handle_; } |
| 49 | |
| 50 | // Integer identifier that can be used used by consumers of DesktopCapturer |
| 51 | // interface to identify shared memory buffers it created. |
| 52 | int id() const { return id_; } |
| 53 | |
| 54 | virtual ~SharedMemory() {} |
| 55 | |
Byoungchan Lee | 604fd2f | 2022-01-21 00:49:39 | [diff] [blame] | 56 | SharedMemory(const SharedMemory&) = delete; |
| 57 | SharedMemory& operator=(const SharedMemory&) = delete; |
| 58 | |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 | [diff] [blame] | 59 | protected: |
| 60 | SharedMemory(void* data, size_t size, Handle handle, int id); |
| 61 | |
| 62 | void* const data_; |
| 63 | const size_t size_; |
| 64 | const Handle handle_; |
| 65 | const int id_; |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 | [diff] [blame] | 66 | }; |
| 67 | |
sergeyu | cc9669c | 2016-02-09 23:13:26 | [diff] [blame] | 68 | // Interface used to create SharedMemory instances. |
| 69 | class SharedMemoryFactory { |
| 70 | public: |
| 71 | SharedMemoryFactory() {} |
| 72 | virtual ~SharedMemoryFactory() {} |
| 73 | |
Byoungchan Lee | 604fd2f | 2022-01-21 00:49:39 | [diff] [blame] | 74 | SharedMemoryFactory(const SharedMemoryFactory&) = delete; |
| 75 | SharedMemoryFactory& operator=(const SharedMemoryFactory&) = delete; |
sergeyu | cc9669c | 2016-02-09 23:13:26 | [diff] [blame] | 76 | |
Byoungchan Lee | 604fd2f | 2022-01-21 00:49:39 | [diff] [blame] | 77 | virtual std::unique_ptr<SharedMemory> CreateSharedMemory(size_t size) = 0; |
sergeyu | cc9669c | 2016-02-09 23:13:26 | [diff] [blame] | 78 | }; |
| 79 | |
sergeyu@chromium.org | 15e32cc | 2013-04-29 20:10:57 | [diff] [blame] | 80 | } // namespace webrtc |
| 81 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 82 | #endif // MODULES_DESKTOP_CAPTURE_SHARED_MEMORY_H_ |