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