yolobs-studio/plugins/decklink/decklink-device-discovery.hpp

82 lines
1.9 KiB
C++
Raw Normal View History

2016-02-23 23:16:51 +00:00
#pragma once
2019-07-27 12:47:10 +00:00
#include <obs-module.h>
#include "platform.hpp"
2016-02-23 23:16:51 +00:00
#include <vector>
#include <mutex>
class DeckLinkDevice;
typedef void (*DeviceChangeCallback)(void *param, DeckLinkDevice *device,
2019-09-22 21:19:10 +00:00
bool added);
2016-02-23 23:16:51 +00:00
struct DeviceChangeInfo {
DeviceChangeCallback callback;
void *param;
};
class DeckLinkDeviceDiscovery : public IDeckLinkDeviceNotificationCallback {
protected:
ComPtr<IDeckLinkDiscovery> discovery;
2019-09-22 21:19:10 +00:00
long refCount = 1;
bool initialized = false;
2016-02-23 23:16:51 +00:00
std::recursive_mutex deviceMutex;
2019-09-22 21:19:10 +00:00
std::vector<DeckLinkDevice *> devices;
2016-02-23 23:16:51 +00: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-09-22 21:19:10 +00:00
if (curCB.callback == callback && curCB.param == param)
2016-02-23 23:16:51 +00: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-09-22 21:19:10 +00:00
curCB.param == param) {
2016-02-23 23:16:51 +00:00
callbacks.erase(callbacks.begin() + i);
return;
}
}
}
DeckLinkDevice *FindByHash(const char *hash);
2019-09-22 21:19:10 +00:00
inline void Lock() { deviceMutex.lock(); }
inline void Unlock() { deviceMutex.unlock(); }
inline const std::vector<DeckLinkDevice *> &GetDevices() const
2016-02-23 23:16:51 +00:00
{
return devices;
}
ULONG STDMETHODCALLTYPE AddRef(void);
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv);
ULONG STDMETHODCALLTYPE Release(void);
};