2017-10-31 16:53:06 +00:00
|
|
|
/*
|
2017-12-03 15:31:16 +00:00
|
|
|
Looking Glass - KVM FrameRelay (KVMFR) Client
|
2019-02-22 11:16:14 +00:00
|
|
|
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
|
2017-12-11 17:30:47 +00:00
|
|
|
https://looking-glass.hostfission.com
|
2017-10-31 16:53:06 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2017-10-31 12:21:05 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#define W32_LEAN_AND_MEAN
|
2017-12-14 19:11:41 +00:00
|
|
|
#include <windows.h>
|
2017-11-16 09:53:22 +00:00
|
|
|
#include <vector>
|
2017-10-31 12:21:05 +00:00
|
|
|
|
2017-12-14 19:11:41 +00:00
|
|
|
#include "common/debug.h"
|
2017-10-31 12:21:05 +00:00
|
|
|
#include "ICapture.h"
|
2017-12-14 19:19:18 +00:00
|
|
|
#if CONFIG_CAPTURE_NVFBC
|
2017-12-14 19:11:41 +00:00
|
|
|
#include "Capture/NvFBC.h"
|
2017-12-14 19:19:18 +00:00
|
|
|
#endif
|
2017-12-14 19:11:41 +00:00
|
|
|
#include "Capture/DXGI.h"
|
2017-10-31 12:21:05 +00:00
|
|
|
|
2017-10-31 14:46:47 +00:00
|
|
|
class CaptureFactory
|
2017-10-31 12:21:05 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-11-16 09:53:22 +00:00
|
|
|
typedef std::vector<ICapture *> DeviceList;
|
|
|
|
|
|
|
|
static DeviceList & GetDevices()
|
2017-10-31 12:21:05 +00:00
|
|
|
{
|
2017-11-16 09:53:22 +00:00
|
|
|
static DeviceList devices;
|
|
|
|
if (!devices.empty())
|
|
|
|
return devices;
|
|
|
|
|
2017-12-14 19:19:18 +00:00
|
|
|
#if CONFIG_CAPTURE_NVFBC
|
2017-11-16 09:53:22 +00:00
|
|
|
devices.push_back(new Capture::NvFBC());
|
2017-12-14 19:19:18 +00:00
|
|
|
#endif
|
2017-11-16 09:53:22 +00:00
|
|
|
devices.push_back(new Capture::DXGI ());
|
|
|
|
|
|
|
|
return devices;
|
|
|
|
}
|
2017-11-02 06:55:25 +00:00
|
|
|
|
2017-11-16 09:53:22 +00:00
|
|
|
static ICapture * GetDevice(const char * name, CaptureOptions * options)
|
|
|
|
{
|
|
|
|
DeviceList devices = GetDevices();
|
|
|
|
for (DeviceList::const_iterator it = devices.begin(); it != devices.end(); ++it)
|
2017-11-02 06:55:25 +00:00
|
|
|
{
|
2017-11-16 09:53:22 +00:00
|
|
|
ICapture * device = *it;
|
|
|
|
if (_strcmpi(name, device->GetName()) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (device->Initialize(options))
|
|
|
|
{
|
|
|
|
DEBUG_INFO("Using %s", device->GetName());
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->DeInitialize();
|
|
|
|
DEBUG_ERROR("Failed to initialize %s", device->GetName());
|
|
|
|
return NULL;
|
2017-11-02 06:55:25 +00:00
|
|
|
}
|
2017-11-16 09:53:22 +00:00
|
|
|
|
|
|
|
DEBUG_ERROR("No such device: %s", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ICapture * DetectDevice(CaptureOptions * options)
|
|
|
|
{
|
|
|
|
DeviceList devices = GetDevices();
|
2017-12-05 09:39:54 +00:00
|
|
|
for (DeviceList::const_iterator it = devices.cbegin(); it != devices.cend(); ++it)
|
2017-11-02 06:55:25 +00:00
|
|
|
{
|
2017-11-16 09:53:22 +00:00
|
|
|
ICapture * device = *it;
|
|
|
|
|
|
|
|
DEBUG_INFO("Trying %s", device->GetName());
|
|
|
|
if (device->Initialize(options))
|
|
|
|
{
|
|
|
|
DEBUG_INFO("Using %s", device->GetName());
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
device->DeInitialize();
|
2017-11-02 06:55:25 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 09:53:22 +00:00
|
|
|
DEBUG_ERROR("Failed to initialize a capture device");
|
2017-11-02 06:55:25 +00:00
|
|
|
return NULL;
|
2017-10-31 12:21:05 +00:00
|
|
|
}
|
|
|
|
};
|