2013-04-29 20:10:57 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_DESKTOP_CAPTURE_SHARED_MEMORY_H_
|
|
|
|
|
#define MODULES_DESKTOP_CAPTURE_SHARED_MEMORY_H_
|
2013-04-29 20:10:57 +00:00
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
|
|
#if defined(WEBRTC_WIN)
|
2021-08-29 10:04:02 -07:00
|
|
|
// Forward declare HANDLE in a windows.h compatible way so that we can avoid
|
|
|
|
|
// including windows.h.
|
|
|
|
|
typedef void* HANDLE;
|
2013-04-29 20:10:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
2016-04-27 01:19:58 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2019-09-23 14:54:28 +02:00
|
|
|
#include "rtc_base/system/rtc_export.h"
|
2013-04-29 20:10:57 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// SharedMemory is a base class for shared memory. It stores all required
|
|
|
|
|
// parameters of the buffer, but doesn't have any logic to allocate or destroy
|
|
|
|
|
// the actual buffer. DesktopCapturer consumers that need to use shared memory
|
|
|
|
|
// for video frames must extend this class with creation and destruction logic
|
2016-02-09 15:13:26 -08:00
|
|
|
// specific for the target platform and then call
|
|
|
|
|
// DesktopCapturer::SetSharedMemoryFactory().
|
2019-09-23 14:54:28 +02:00
|
|
|
class RTC_EXPORT SharedMemory {
|
2013-04-29 20:10:57 +00:00
|
|
|
public:
|
|
|
|
|
#if defined(WEBRTC_WIN)
|
|
|
|
|
typedef HANDLE Handle;
|
|
|
|
|
static const Handle kInvalidHandle;
|
|
|
|
|
#else
|
|
|
|
|
typedef int Handle;
|
|
|
|
|
static const Handle kInvalidHandle;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void* data() const { return data_; }
|
|
|
|
|
size_t size() const { return size_; }
|
|
|
|
|
|
|
|
|
|
// Platform-specific handle of the buffer.
|
|
|
|
|
Handle handle() const { return handle_; }
|
|
|
|
|
|
|
|
|
|
// Integer identifier that can be used used by consumers of DesktopCapturer
|
|
|
|
|
// interface to identify shared memory buffers it created.
|
|
|
|
|
int id() const { return id_; }
|
|
|
|
|
|
|
|
|
|
virtual ~SharedMemory() {}
|
|
|
|
|
|
2022-01-21 09:49:39 +09:00
|
|
|
SharedMemory(const SharedMemory&) = delete;
|
|
|
|
|
SharedMemory& operator=(const SharedMemory&) = delete;
|
|
|
|
|
|
2013-04-29 20:10:57 +00:00
|
|
|
protected:
|
|
|
|
|
SharedMemory(void* data, size_t size, Handle handle, int id);
|
|
|
|
|
|
|
|
|
|
void* const data_;
|
|
|
|
|
const size_t size_;
|
|
|
|
|
const Handle handle_;
|
|
|
|
|
const int id_;
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-09 15:13:26 -08:00
|
|
|
// Interface used to create SharedMemory instances.
|
|
|
|
|
class SharedMemoryFactory {
|
|
|
|
|
public:
|
|
|
|
|
SharedMemoryFactory() {}
|
|
|
|
|
virtual ~SharedMemoryFactory() {}
|
|
|
|
|
|
2022-01-21 09:49:39 +09:00
|
|
|
SharedMemoryFactory(const SharedMemoryFactory&) = delete;
|
|
|
|
|
SharedMemoryFactory& operator=(const SharedMemoryFactory&) = delete;
|
2016-02-09 15:13:26 -08:00
|
|
|
|
2022-01-21 09:49:39 +09:00
|
|
|
virtual std::unique_ptr<SharedMemory> CreateSharedMemory(size_t size) = 0;
|
2016-02-09 15:13:26 -08:00
|
|
|
};
|
|
|
|
|
|
2013-04-29 20:10:57 +00:00
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_DESKTOP_CAPTURE_SHARED_MEMORY_H_
|