mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-09-02 04:03:56 +00:00
Some checks failed
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Has been cancelled
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Has been cancelled
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Has been cancelled
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Has been cancelled
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Has been cancelled
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Has been cancelled
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Has been cancelled
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Has been cancelled
build / module (push) Has been cancelled
build / host-linux (push) Has been cancelled
build / host-windows-cross (push) Has been cancelled
build / host-windows-native (push) Has been cancelled
build / idd (push) Has been cancelled
build / obs (clang) (push) Has been cancelled
build / obs (gcc) (push) Has been cancelled
build / docs (push) Has been cancelled
Add LGProtocol as a pinned submodule and consume its KVMFR protocol definitions throughout the client, host, IDD, OBS, and profiler. Keep Looking Glass framebuffer helpers local while removing duplicated protocol headers and migrating users to KVMFR-scoped types.
137 lines
3.9 KiB
C++
137 lines
3.9 KiB
C++
/**
|
|
* Looking Glass
|
|
* Copyright © 2017-2026 The Looking Glass Authors
|
|
* https://looking-glass.io
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
|
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "Atomic.h"
|
|
#include "CSRWLock.h"
|
|
#include "transport/IInputSource.h"
|
|
#include <LGProtocol/KVMFRInput.h>
|
|
#include <LGProtocol/LGMPConfig.h>
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
extern "C" {
|
|
#include "lgmp/host.h"
|
|
#include "lgmp/stream.h"
|
|
}
|
|
|
|
class CLGMPHost;
|
|
class IInputTarget;
|
|
|
|
class CLGMPInputTransport final : public IInputSource
|
|
{
|
|
private:
|
|
static constexpr ULONGLONG OWNER_LEASE_MS = 500;
|
|
static constexpr ULONGLONG LOG_INTERVAL_MS = 5000;
|
|
static constexpr unsigned DRAIN_LIMIT = 256;
|
|
|
|
struct StreamEndpoint
|
|
{
|
|
PLGMPHostStream stream;
|
|
LGMPStreamDescriptor descriptor;
|
|
uint32_t clientID;
|
|
uint32_t epoch;
|
|
bool draining;
|
|
};
|
|
|
|
struct Statistics
|
|
{
|
|
ULONGLONG lastLog;
|
|
uint64_t messages;
|
|
uint64_t reports;
|
|
uint64_t drainLimit;
|
|
uint64_t malformedSize;
|
|
uint64_t malformedMessage;
|
|
uint64_t sequenceErrors;
|
|
uint64_t nonOwner;
|
|
uint64_t deliveryFailures;
|
|
uint64_t claims;
|
|
uint64_t releases;
|
|
unsigned maxDrain;
|
|
};
|
|
|
|
CLGMPHost& m_host;
|
|
|
|
PLGMPHostQueue m_queue = nullptr;
|
|
PLGMPMemory m_statusMemory[LGMP_Q_INPUT_LEN] = {};
|
|
StreamEndpoint m_streamEndpoint[
|
|
KVMFR_INPUT_STREAM_ENDPOINT_COUNT] = {};
|
|
IInputTarget * m_target = nullptr;
|
|
|
|
CSRWLock m_lifecycleLock;
|
|
CSRWLock m_statusLock;
|
|
CSRWLock m_streamLock;
|
|
HANDLE m_stopEvent = nullptr;
|
|
HANDLE m_pollTimer = nullptr;
|
|
HANDLE m_thread = nullptr;
|
|
|
|
uint32_t m_ownerClientID = 0;
|
|
uint32_t m_ownerGeneration = 0;
|
|
uint32_t m_ownerSequence = 0;
|
|
ULONGLONG m_ownerDeadline = 0;
|
|
InputTargetState m_targetState;
|
|
uint32_t m_endpointGeneration = 0;
|
|
uint32_t m_streamGeneration = 0;
|
|
unsigned m_streamDrainCursor = 0;
|
|
uint32_t m_statusSerial = 0;
|
|
bool m_statusDirty = false;
|
|
std::atomic<bool> m_statusFailed = false;
|
|
Statistics m_statistics = {};
|
|
|
|
bool Initialize();
|
|
void DeInit();
|
|
bool ReconcileStreams(bool& changed);
|
|
void ResetStreams();
|
|
InputSourceId Owner() const;
|
|
void UpdateTargetState(const InputTargetState& state);
|
|
bool PublishStatus();
|
|
void FlushStatus();
|
|
void LogStatistics(ULONGLONG now);
|
|
bool DrainStreamMessages(bool& received);
|
|
bool ProcessMessage(uint32_t sourceClientID,
|
|
const KVMFRInputMessage& message);
|
|
bool ValidatePayload(const KVMFRInputMessage& message) const;
|
|
bool IsOwner(uint32_t sourceClientID, uint32_t generation) const;
|
|
bool Claim(uint32_t sourceClientID,
|
|
const KVMFRInputMessage& message);
|
|
void RenewLease();
|
|
void ReleaseOwner(bool reset);
|
|
void CheckOwner();
|
|
void Thread();
|
|
|
|
static DWORD CALLBACK ThreadProc(void * context);
|
|
|
|
friend class CLGMPTransport;
|
|
|
|
public:
|
|
explicit CLGMPInputTransport(CLGMPHost& host) :
|
|
m_host(host) {}
|
|
~CLGMPInputTransport() override;
|
|
|
|
CLGMPInputTransport(const CLGMPInputTransport&) = delete;
|
|
CLGMPInputTransport& operator=(const CLGMPInputTransport&) = delete;
|
|
|
|
bool Start(IInputTarget& target) override;
|
|
void Stop() override;
|
|
};
|