blob: 631f119b5ffb6f24334c026b60ee7768b402266d [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
11#ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_SHARED_MEMORY_H_
12#define WEBRTC_MODULES_DESKTOP_CAPTURE_SHARED_MEMORY_H_
13
14#include <stddef.h>
15
16#if defined(WEBRTC_WIN)
17#include <windows.h>
18#endif
19
henrike@webrtc.org88fbb2d2014-05-21 21:18:46 +000020#include "webrtc/base/constructormagic.h"
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +000021#include "webrtc/typedefs.h"
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +000022
23namespace webrtc {
24
25// SharedMemory is a base class for shared memory. It stores all required
26// parameters of the buffer, but doesn't have any logic to allocate or destroy
27// the actual buffer. DesktopCapturer consumers that need to use shared memory
28// for video frames must extend this class with creation and destruction logic
29// specific for the target platform and then implement
30// DesktopCapturer::Delegate::CreateSharedMemory() as appropriate.
31class SharedMemory {
32 public:
33#if defined(WEBRTC_WIN)
34 typedef HANDLE Handle;
35 static const Handle kInvalidHandle;
36#else
37 typedef int Handle;
38 static const Handle kInvalidHandle;
39#endif
40
41 void* data() const { return data_; }
42 size_t size() const { return size_; }
43
44 // Platform-specific handle of the buffer.
45 Handle handle() const { return handle_; }
46
47 // Integer identifier that can be used used by consumers of DesktopCapturer
48 // interface to identify shared memory buffers it created.
49 int id() const { return id_; }
50
51 virtual ~SharedMemory() {}
52
53 protected:
54 SharedMemory(void* data, size_t size, Handle handle, int id);
55
56 void* const data_;
57 const size_t size_;
58 const Handle handle_;
59 const int id_;
60
61 private:
henrikg3c089d72015-09-16 05:37:44 -070062 RTC_DISALLOW_COPY_AND_ASSIGN(SharedMemory);
sergeyu@chromium.org15e32cc2013-04-29 20:10:57 +000063};
64
65} // namespace webrtc
66
67#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SHARED_MEMORY_H_
68