2015-02-18 15:15:38 -08:00
|
|
|
#pragma once
|
|
|
|
|
2018-09-25 15:51:32 -07:00
|
|
|
#include <obs-module.h>
|
|
|
|
#include "platform.hpp"
|
|
|
|
|
2015-02-18 15:15:38 -08:00
|
|
|
#include <vector>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
class DeckLinkDevice;
|
|
|
|
|
|
|
|
typedef void (*DeviceChangeCallback)(void *param, DeckLinkDevice *device,
|
2019-06-22 22:13:45 -07:00
|
|
|
bool added);
|
2015-02-18 15:15:38 -08:00
|
|
|
|
|
|
|
struct DeviceChangeInfo {
|
|
|
|
DeviceChangeCallback callback;
|
|
|
|
void *param;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DeckLinkDeviceDiscovery : public IDeckLinkDeviceNotificationCallback {
|
|
|
|
protected:
|
|
|
|
ComPtr<IDeckLinkDiscovery> discovery;
|
2019-06-22 22:13:45 -07:00
|
|
|
long refCount = 1;
|
|
|
|
bool initialized = false;
|
2015-02-18 15:15:38 -08:00
|
|
|
|
|
|
|
std::recursive_mutex deviceMutex;
|
2019-06-22 22:13:45 -07:00
|
|
|
std::vector<DeckLinkDevice *> devices;
|
2015-02-18 15:15:38 -08:00
|
|
|
std::vector<DeviceChangeInfo> callbacks;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DeckLinkDeviceDiscovery();
|
|
|
|
virtual ~DeckLinkDeviceDiscovery(void);
|
|
|
|
|
|
|
|
bool Init();
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE DeckLinkDeviceArrived(IDeckLink *device);
|
|
|
|
HRESULT STDMETHODCALLTYPE DeckLinkDeviceRemoved(IDeckLink *device);
|
|
|
|
|
|
|
|
inline void AddCallback(DeviceChangeCallback callback, void *param)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(deviceMutex);
|
|
|
|
DeviceChangeInfo info;
|
|
|
|
|
|
|
|
info.callback = callback;
|
|
|
|
info.param = param;
|
|
|
|
|
|
|
|
for (DeviceChangeInfo &curCB : callbacks) {
|
2019-06-22 22:13:45 -07:00
|
|
|
if (curCB.callback == callback && curCB.param == param)
|
2015-02-18 15:15:38 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
callbacks.push_back(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void RemoveCallback(DeviceChangeCallback callback, void *param)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(deviceMutex);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < callbacks.size(); i++) {
|
|
|
|
DeviceChangeInfo &curCB = callbacks[i];
|
|
|
|
|
|
|
|
if (curCB.callback == callback &&
|
2019-06-22 22:13:45 -07:00
|
|
|
curCB.param == param) {
|
2015-02-18 15:15:38 -08:00
|
|
|
callbacks.erase(callbacks.begin() + i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DeckLinkDevice *FindByHash(const char *hash);
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
inline void Lock() { deviceMutex.lock(); }
|
|
|
|
inline void Unlock() { deviceMutex.unlock(); }
|
|
|
|
inline const std::vector<DeckLinkDevice *> &GetDevices() const
|
2015-02-18 15:15:38 -08:00
|
|
|
{
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE AddRef(void);
|
|
|
|
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv);
|
|
|
|
ULONG STDMETHODCALLTYPE Release(void);
|
|
|
|
};
|