blob: ba846da4c812796f0685d4a7592f523247908ab7 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_DESKTOP_CAPTURE_SHARED_MEMORY_H_
12#define MODULES_DESKTOP_CAPTURE_SHARED_MEMORY_H_
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +000013
14#include <stddef.h>
15
16#if defined(WEBRTC_WIN)
17#include <windows.h>
18#endif
19
kwiberg84be5112016-04-27 01:19:58 -070020#include <memory>
21
Steve Anton10542f22019-01-11 09:11:00 -080022#include "rtc_base/constructor_magic.h"
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +000023
24namespace webrtc {
25
26// SharedMemory is a base class for shared memory. It stores all required
27// parameters of the buffer, but doesn't have any logic to allocate or destroy
28// the actual buffer. DesktopCapturer consumers that need to use shared memory
29// for video frames must extend this class with creation and destruction logic
sergeyucc9669c2016-02-09 15:13:26 -080030// specific for the target platform and then call
31// DesktopCapturer::SetSharedMemoryFactory().
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +000032class SharedMemory {
33 public:
34#if defined(WEBRTC_WIN)
35 typedef HANDLE Handle;
36 static const Handle kInvalidHandle;
37#else
38 typedef int Handle;
39 static const Handle kInvalidHandle;
40#endif
41
42 void* data() const { return data_; }
43 size_t size() const { return size_; }
44
45 // Platform-specific handle of the buffer.
46 Handle handle() const { return handle_; }
47
48 // Integer identifier that can be used used by consumers of DesktopCapturer
49 // interface to identify shared memory buffers it created.
50 int id() const { return id_; }
51
52 virtual ~SharedMemory() {}
53
54 protected:
55 SharedMemory(void* data, size_t size, Handle handle, int id);
56
57 void* const data_;
58 const size_t size_;
59 const Handle handle_;
60 const int id_;
61
62 private:
henrikg3c089d72015-09-16 05:37:44 -070063 RTC_DISALLOW_COPY_AND_ASSIGN(SharedMemory);
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +000064};
65
sergeyucc9669c2016-02-09 15:13:26 -080066// Interface used to create SharedMemory instances.
67class SharedMemoryFactory {
68 public:
69 SharedMemoryFactory() {}
70 virtual ~SharedMemoryFactory() {}
71
kwiberg84be5112016-04-27 01:19:58 -070072 virtual std::unique_ptr<SharedMemory> CreateSharedMemory(size_t size) = 0;
sergeyucc9669c2016-02-09 15:13:26 -080073
74 private:
75 RTC_DISALLOW_COPY_AND_ASSIGN(SharedMemoryFactory);
76};
77
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +000078} // namespace webrtc
79
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020080#endif // MODULES_DESKTOP_CAPTURE_SHARED_MEMORY_H_