Skip to content

Commit e81f49c

Browse files
committed
use symlinks for capture devices
1 parent e511155 commit e81f49c

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

ShaderGlass/CaptureManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ bool CaptureManager::StartSession()
191191
if(!FindDeviceFormat(m_options.deviceFormatNo, di, fi))
192192
return false;
193193

194-
m_deviceCapture.Start(m_d3dDevice, di->no, fi->no);
194+
m_deviceCapture.Start(m_d3dDevice, di->symlink, fi->no);
195195

196196
// retrieve input image size
197197
auto inputTexture = m_deviceCapture.m_outputTexture;

ShaderGlass/DeviceCapture.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ static HRESULT hr;
1818

1919
constexpr unsigned STREAM_NO = 0;
2020

21-
const std::map<unsigned long, int> FormatPriorities {
22-
{842094158, 3}, // NV12
23-
{1196444237, 0}, // MJPG
24-
{844715353, 2}, // YUY2
25-
{875967048, 0}, // H264
26-
{20, 1}}
27-
; // RGB
21+
const std::map<unsigned long, int> FormatPriorities {{842094158, 3}, // NV12
22+
{1196444237, 0}, // MJPG
23+
{844715353, 2}, // YUY2
24+
{875967048, 0}, // H264
25+
{20, 1}}; // RGB
2826

2927
DeviceCapture::DeviceCapture() { }
3028

@@ -65,8 +63,11 @@ std::vector<CaptureDevice> DeviceCapture::GetCaptureDevices()
6563
winrt::com_ptr<IMFStreamDescriptor> streamDescriptor;
6664
winrt::com_ptr<IMFMediaTypeHandler> mediaTypeHandler;
6765
winrt::com_ptr<IMFMediaType> mediaType;
66+
LPWSTR symlink;
67+
UINT32 slen;
6868

6969
THROW(devices[deviceNo]->ActivateObject(__uuidof(IMFMediaSource), reinterpret_cast<void**>(mediaSource.put())));
70+
THROW(devices[deviceNo]->GetAllocatedString(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &symlink, &slen));
7071
THROW(mediaSource->CreatePresentationDescriptor(presentationDescriptor.put()));
7172
THROW(presentationDescriptor->GetStreamDescriptorByIndex(STREAM_NO, &selected, streamDescriptor.put()));
7273
if(!selected)
@@ -76,7 +77,7 @@ std::vector<CaptureDevice> DeviceCapture::GetCaptureDevices()
7677
UINT32 deviceNameLen = MAX_DEVICE_NAME;
7778
devices[deviceNo]->GetString(MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, deviceName, MAX_DEVICE_NAME, &deviceNameLen);
7879

79-
CaptureDevice cdi {.no = deviceNo, .name = std::wstring(deviceName)};
80+
CaptureDevice cdi {.no = deviceNo, .name = std::wstring(deviceName), .symlink = symlink };
8081

8182
DWORD mediaTypeCount;
8283
THROW(streamDescriptor->GetMediaTypeHandler(mediaTypeHandler.put()));
@@ -220,11 +221,11 @@ bool DeviceCapture::Poll()
220221
return false;
221222
}
222223

223-
void DeviceCapture::Start(winrt::com_ptr<ID3D11Device> d3dDevice, int deviceNo, int formatNo)
224+
void DeviceCapture::Start(winrt::com_ptr<ID3D11Device> d3dDevice, LPWSTR symlink, int formatNo)
224225
{
225226
Init();
226227

227-
CreateMediaSource(deviceNo, STREAM_NO, formatNo);
228+
CreateMediaSource(symlink, STREAM_NO, formatNo);
228229
CreateSourceReader();
229230
SetMediaType();
230231
CreateSampleAllocator(d3dDevice);
@@ -255,7 +256,7 @@ void DeviceCapture::CreateSourceReader()
255256
THROW(MFCreateSourceReaderFromMediaSource(m_mediaSource.get(), attributes.get(), m_sourceReader.put()));
256257
}
257258

258-
void DeviceCapture::CreateMediaSource(unsigned deviceNo, unsigned streamNo, unsigned mediaNo)
259+
void DeviceCapture::CreateMediaSource(LPWSTR symlink, unsigned streamNo, unsigned mediaNo)
259260
{
260261
winrt::com_ptr<IMFAttributes> attributes;
261262
winrt::com_ptr<IMFPresentationDescriptor> presentationDescriptor;
@@ -268,13 +269,11 @@ void DeviceCapture::CreateMediaSource(unsigned deviceNo, unsigned streamNo, unsi
268269

269270
THROW(MFCreateAttributes(attributes.put(), 1));
270271
THROW(attributes->SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID));
271-
THROW(MFEnumDeviceSources(attributes.get(), &devices, &numDevices));
272-
if(numDevices == 0 || numDevices <= deviceNo)
273-
throw std::runtime_error("Device not found");
272+
THROW(attributes->SetString(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, symlink));
274273

275274
try
276275
{
277-
THROW(devices[deviceNo]->ActivateObject(__uuidof(IMFMediaSource), reinterpret_cast<void**>(m_mediaSource.put())));
276+
THROW(MFCreateDeviceSource(attributes.get(), m_mediaSource.put()));
278277
THROW(m_mediaSource->CreatePresentationDescriptor(presentationDescriptor.put()));
279278
THROW(presentationDescriptor->GetStreamDescriptorByIndex(streamNo, &selected, streamDescriptor.put()));
280279
if(!selected)

ShaderGlass/DeviceCapture.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DeviceCapture
1616
DeviceCapture();
1717

1818
std::vector<CaptureDevice> GetCaptureDevices();
19-
void Start(winrt::com_ptr<ID3D11Device> d3dDevice, int deviceNo, int formatNo);
19+
void Start(winrt::com_ptr<ID3D11Device> d3dDevice, LPWSTR symlink, int formatNo);
2020
void Stop();
2121
bool WaitForNextFrame();
2222
bool Poll();
@@ -26,7 +26,7 @@ class DeviceCapture
2626

2727
private:
2828
void Init();
29-
void CreateMediaSource(unsigned deviceNo, unsigned streamNo, unsigned mediaNo);
29+
void CreateMediaSource(LPWSTR symlink, unsigned streamNo, unsigned mediaNo);
3030
void CreateSourceReader();
3131
void SetMediaType();
3232
void CreateSampleAllocator(winrt::com_ptr<ID3D11Device>);

ShaderGlass/Options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct CaptureDevice
100100
{
101101
unsigned no;
102102
std::wstring name;
103+
LPWSTR symlink;
103104

104105
std::vector<CaptureFormat> formats;
105106
};

0 commit comments

Comments
 (0)