-
Notifications
You must be signed in to change notification settings - Fork 0
/
DShowUtils.cpp
202 lines (166 loc) · 5.13 KB
/
DShowUtils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "DShowUtils.h"
#include "dshow.h"
#include "strmif.h"
#include "objidl.h"
#include "shlwapi.h"
#pragma comment(lib, "strmiids")
//inspiration for this from FFMpeg and the DirectShow SDK (Microsoft)
static void locShowDShowFilterProperties(IBaseFilter* pDeviceFilter)
{
ISpecifyPropertyPages* pPropertyPages = NULL;
IUnknown* pDeviceFilterIUnknown = NULL;
HRESULT hr;
FILTER_INFO filterInfo = { 0 }; /* a warning on this line is false positive GCC bug 53119 AFAICT */
CAUUID ca_guid = { 0 };
hr = pDeviceFilter->QueryInterface(IID_ISpecifyPropertyPages, (void**)&pPropertyPages);
if (hr != S_OK) //error "requested filter does not have a property page to show"
goto end;
hr = pDeviceFilter->QueryFilterInfo(&filterInfo);
if (hr != S_OK)
goto fail;
hr = pDeviceFilter->QueryInterface(IID_IUnknown, (void**)&pDeviceFilterIUnknown);
if (hr != S_OK)
goto fail;
hr = pPropertyPages->GetPages(&ca_guid);
if (hr != S_OK)
goto fail;
hr = OleCreatePropertyFrame(NULL, 0, 0, filterInfo.achName, 1, &pDeviceFilterIUnknown, ca_guid.cElems, ca_guid.pElems, 0, 0, NULL);
if (hr != S_OK)
goto fail;
goto end;
fail:
//error "Failure showing property pages for filter"
end:
if (pPropertyPages)
pPropertyPages->Release();
if (pDeviceFilterIUnknown)
pDeviceFilterIUnknown->Release();
if (filterInfo.pGraph)
filterInfo.pGraph->Release();
if (ca_guid.pElems)
CoTaskMemFree(ca_guid.pElems);
}
static HRESULT locEnumerateDevices(REFGUID category, IEnumMoniker** ppEnum)
{
// Create the System Device Enumerator.
ICreateDevEnum* pDevEnum;
HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDevEnum));
if (SUCCEEDED(hr))
{
// Create an enumerator for the category.
hr = pDevEnum->CreateClassEnumerator(category, ppEnum, 0);
if (hr == S_FALSE)
{
hr = VFW_E_NOT_FOUND; // The category is empty. Treat as an error.
}
pDevEnum->Release();
}
return hr;
}
static void locDisplayDeviceInformation(IEnumMoniker* pEnum, wxString sFriendlyName)
{
IMoniker* pMoniker = NULL;
bool foundIt = false;
while (!foundIt && pEnum->Next(1, &pMoniker, NULL) == S_OK)
{
IPropertyBag* pPropBag;
HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
if (FAILED(hr))
{
pMoniker->Release();
continue;
}
VARIANT var;
VariantInit(&var);
// Get description or friendly name.
hr = pPropBag->Read(L"Description", &var, 0);
if (FAILED(hr))
{
hr = pPropBag->Read(L"FriendlyName", &var, 0);
}
if (SUCCEEDED(hr))
{
VariantClear(&var);
}
hr = pPropBag->Write(L"FriendlyName", &var);
foundIt = sFriendlyName.CompareTo(var.bstrVal) == 0;
if (foundIt)
{
IBaseFilter* pFilter;
hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, (void**)&pFilter);
if (SUCCEEDED(hr))
{
locShowDShowFilterProperties(pFilter);
pFilter->Release();
}
}
pPropBag->Release();
pMoniker->Release();
}
}
static void locGetFriendlyDeviceNames(IEnumMoniker* pEnum, wxArrayString &outArrResult)
{
IMoniker* pMoniker = NULL;
while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
{
IPropertyBag* pPropBag;
HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
if (FAILED(hr))
{
pMoniker->Release();
continue;
}
VARIANT var;
VariantInit(&var);
// Get description or friendly name.
hr = pPropBag->Read(L"Description", &var, 0);
if (FAILED(hr))
{
hr = pPropBag->Read(L"FriendlyName", &var, 0);
}
if (SUCCEEDED(hr))
{
VariantClear(&var);
}
hr = pPropBag->Write(L"FriendlyName", &var);
outArrResult.Add(var.bstrVal);
pPropBag->Release();
pMoniker->Release();
}
}
void GetDevicesFriendlyName(wxArrayString& outArrResult)
{
outArrResult.Clear();
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (SUCCEEDED(hr))
{
IEnumMoniker* pEnum = NULL;
hr = locEnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum);
if (SUCCEEDED(hr))
{
locGetFriendlyDeviceNames(pEnum, outArrResult);
pEnum->Release();
}
CoUninitialize();
}
}
void ShowDevicePropertyDialog(wxString sFriendlyName)
{
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (SUCCEEDED(hr))
{
IEnumMoniker* pEnum;
hr = locEnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum);
if (SUCCEEDED(hr))
{
locDisplayDeviceInformation(pEnum, sFriendlyName);
pEnum->Release();
}
CoUninitialize();
}
}