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