Parent Directory | Revision Log
Revision 2080 - (view) (download)
1 : | Irhall | 2014 | /***************************************************************************** |
2 : | * | ||
3 : | * Xvid MiniConvert | ||
4 : | * - Utility and helper functions - | ||
5 : | * | ||
6 : | Isibaar | 2080 | * Copyright(C) 2011-2014 Xvid Solutions GmbH |
7 : | Irhall | 2014 | * |
8 : | * This program is free software ; you can redistribute it and/or modify | ||
9 : | * it under the terms of the GNU General Public License as published by | ||
10 : | * the Free Software Foundation ; either version 2 of the License, or | ||
11 : | * (at your option) any later version. | ||
12 : | * | ||
13 : | * This program is distributed in the hope that it will be useful, | ||
14 : | * but WITHOUT ANY WARRANTY ; without even the implied warranty of | ||
15 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 : | * GNU General Public License for more details. | ||
17 : | * | ||
18 : | * You should have received a copy of the GNU General Public License | ||
19 : | * along with this program ; if not, write to the Free Software | ||
20 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 : | * | ||
22 : | * $Id$ | ||
23 : | * | ||
24 : | ****************************************************************************/ | ||
25 : | /* | ||
26 : | * Author(s): Ireneusz Hallmann | ||
27 : | * | ||
28 : | ****************************************************************************/ | ||
29 : | |||
30 : | #include "stdafx.h" | ||
31 : | #include "utils.h" | ||
32 : | |||
33 : | HRESULT | ||
34 : | GetFilterPin(IBaseFilter *pFilter, // Pointer to the filter. | ||
35 : | PIN_DIRECTION PinDir, // Direction of the pin to find. | ||
36 : | int WantConnected, // 0 - unconnected, 1 - connected, -1 - N/A | ||
37 : | IPin **ppPin, | ||
38 : | const GUID &MainType, | ||
39 : | const GUID &SubType) // Receives a pointer to the pin. | ||
40 : | { | ||
41 : | *ppPin = 0; | ||
42 : | IEnumPins *pEnum = 0; | ||
43 : | IPin *pPin = 0; | ||
44 : | if (!pFilter) return E_POINTER; | ||
45 : | |||
46 : | HRESULT hr = pFilter->EnumPins(&pEnum); | ||
47 : | |||
48 : | if (FAILED(hr)) { | ||
49 : | return hr; | ||
50 : | } | ||
51 : | |||
52 : | CMediaType TestMediaType; | ||
53 : | TestMediaType.majortype = MainType; | ||
54 : | TestMediaType.subtype = SubType; | ||
55 : | |||
56 : | while (pEnum->Next(1, &pPin, NULL) == S_OK) | ||
57 : | { | ||
58 : | PIN_DIRECTION ThisPinDir; | ||
59 : | pPin->QueryDirection(&ThisPinDir); | ||
60 : | |||
61 : | if (ThisPinDir == PinDir) { | ||
62 : | IPin *pTmp = 0; | ||
63 : | hr = pPin->ConnectedTo(&pTmp); | ||
64 : | if (SUCCEEDED(hr)) // Already connected | ||
65 : | { | ||
66 : | pTmp->Release(); | ||
67 : | } | ||
68 : | |||
69 : | if ((FAILED (hr) && WantConnected ==0) || | ||
70 : | (SUCCEEDED(hr) && WantConnected ==1)) { | ||
71 : | |||
72 : | if (MainType == GUID_NULL) { | ||
73 : | pEnum->Release(); | ||
74 : | *ppPin = pPin; | ||
75 : | return S_OK; | ||
76 : | } | ||
77 : | |||
78 : | if (WantConnected ==1) { | ||
79 : | AM_MEDIA_TYPE mType; | ||
80 : | hr = pPin->ConnectionMediaType(&mType); | ||
81 : | |||
82 : | if (SUCCEEDED(hr)) { | ||
83 : | if (mType.majortype == MainType && | ||
84 : | (SubType == GUID_NULL || SubType == mType.subtype)) { | ||
85 : | |||
86 : | FreeMediaType(mType); | ||
87 : | pEnum->Release(); | ||
88 : | *ppPin = pPin; | ||
89 : | return S_OK; | ||
90 : | } | ||
91 : | |||
92 : | FreeMediaType(mType); | ||
93 : | } | ||
94 : | } | ||
95 : | else { | ||
96 : | IEnumMediaTypes *pmEnum; | ||
97 : | AM_MEDIA_TYPE *mType =0; | ||
98 : | hr = pPin->EnumMediaTypes(&pmEnum); | ||
99 : | |||
100 : | if (hr == S_OK) { | ||
101 : | hr = pmEnum->Reset(); | ||
102 : | |||
103 : | while (hr == S_OK) { | ||
104 : | ULONG lM; | ||
105 : | hr = pmEnum->Next(1, &mType, &lM); | ||
106 : | |||
107 : | if (hr == S_OK && lM ==1) { | ||
108 : | if (mType->majortype == MainType && | ||
109 : | (SubType == GUID_NULL || SubType == mType->subtype)) { | ||
110 : | |||
111 : | DeleteMediaType(mType); | ||
112 : | pmEnum->Release(); | ||
113 : | pEnum->Release(); | ||
114 : | *ppPin = pPin; | ||
115 : | |||
116 : | return S_OK; | ||
117 : | } | ||
118 : | DeleteMediaType(mType); | ||
119 : | } | ||
120 : | else if (MainType != GUID_NULL && SubType != GUID_NULL) { | ||
121 : | HRESULT hrPom; | ||
122 : | if ((hrPom = pPin->QueryAccept(&TestMediaType)) == S_OK) { | ||
123 : | pmEnum->Release(); | ||
124 : | pEnum->Release(); | ||
125 : | *ppPin = pPin; | ||
126 : | |||
127 : | return S_OK; | ||
128 : | } | ||
129 : | } | ||
130 : | } | ||
131 : | pmEnum->Release(); | ||
132 : | } | ||
133 : | } | ||
134 : | } | ||
135 : | } | ||
136 : | pPin->Release(); | ||
137 : | } | ||
138 : | pEnum->Release(); | ||
139 : | |||
140 : | // Did not find a matching pin. | ||
141 : | return E_FAIL; | ||
142 : | } | ||
143 : | |||
144 : | HRESULT | ||
145 : | GetUnconnectedPin(IBaseFilter *pFilter, PIN_DIRECTION PinDir, | ||
146 : | IPin **ppPin, const GUID &MainType, const GUID &SubType) | ||
147 : | { | ||
148 : | return GetFilterPin(pFilter, PinDir, 0, ppPin, MainType, SubType); | ||
149 : | } | ||
150 : | |||
151 : | HRESULT | ||
152 : | ConnectFilters(IGraphBuilder *pGraph, IPin *pOut, IBaseFilter *pDest, | ||
153 : | const GUID &MainType, const GUID &SubType, BOOL bConnectDirect) | ||
154 : | { | ||
155 : | if ((pGraph == NULL) || (pOut == NULL) || (pDest == NULL)) | ||
156 : | return E_POINTER; | ||
157 : | |||
158 : | #ifdef _DEBUG | ||
159 : | PIN_DIRECTION PinDir; | ||
160 : | pOut->QueryDirection(&PinDir); | ||
161 : | _ASSERTE(PinDir == PINDIR_OUTPUT); | ||
162 : | #endif | ||
163 : | |||
164 : | // Find an input pin on the downstream filter. | ||
165 : | IPin *pIn = 0; | ||
166 : | HRESULT hr = GetUnconnectedPin(pDest, PINDIR_INPUT, &pIn); | ||
167 : | if (FAILED(hr)) { | ||
168 : | return hr; | ||
169 : | } | ||
170 : | |||
171 : | // Try to connect them. | ||
172 : | if (bConnectDirect) | ||
173 : | hr = pGraph->ConnectDirect (pOut, pIn, NULL); | ||
174 : | else | ||
175 : | hr = pGraph->Connect(pOut, pIn); | ||
176 : | |||
177 : | pIn->Release(); | ||
178 : | |||
179 : | return hr; | ||
180 : | } | ||
181 : | |||
182 : | HRESULT | ||
183 : | ConnectFilters(IGraphBuilder *pGraph, IBaseFilter *pSrc, | ||
184 : | IPin *pIn, const GUID &MainType, | ||
185 : | const GUID &SubType, BOOL bConnectDirect) | ||
186 : | { | ||
187 : | if ((pGraph == NULL) || (pIn == NULL) || (pSrc == NULL)) | ||
188 : | return E_POINTER; | ||
189 : | |||
190 : | #ifdef _DEBUG | ||
191 : | PIN_DIRECTION PinDir; | ||
192 : | pIn->QueryDirection(&PinDir); | ||
193 : | _ASSERTE(PinDir == PINDIR_INPUT); | ||
194 : | #endif | ||
195 : | |||
196 : | // Find an input pin on the downstream filter. | ||
197 : | IPin *pOut = 0; | ||
198 : | HRESULT hr = GetUnconnectedPin(pSrc, PINDIR_OUTPUT, &pOut, MainType, SubType); | ||
199 : | if (FAILED(hr)) { | ||
200 : | return hr; | ||
201 : | } | ||
202 : | |||
203 : | // Try to connect them. | ||
204 : | if (bConnectDirect) | ||
205 : | hr = pGraph->ConnectDirect(pOut, pIn, NULL); | ||
206 : | else | ||
207 : | hr = pGraph->Connect(pOut, pIn); | ||
208 : | |||
209 : | pOut->Release(); | ||
210 : | |||
211 : | return hr; | ||
212 : | } | ||
213 : | |||
214 : | HRESULT | ||
215 : | ConnectFilters(IGraphBuilder *pGraph, IBaseFilter *pSrc, | ||
216 : | IBaseFilter *pDest, const GUID &MainType, | ||
217 : | const GUID &SubType, BOOL bConnectDirect) | ||
218 : | { | ||
219 : | if ((pGraph == NULL) || (pSrc == NULL) || (pDest == NULL)) | ||
220 : | return E_POINTER; | ||
221 : | |||
222 : | // Find an output pin on the first filter. | ||
223 : | IPin *pOut = 0; | ||
224 : | HRESULT hr = GetUnconnectedPin(pSrc, PINDIR_OUTPUT, &pOut, MainType, SubType); | ||
225 : | if (FAILED(hr)) { | ||
226 : | return hr; | ||
227 : | } | ||
228 : | |||
229 : | hr = ConnectFilters(pGraph, pOut, pDest, MainType, SubType, bConnectDirect); | ||
230 : | |||
231 : | pOut->Release(); | ||
232 : | |||
233 : | return hr; | ||
234 : | } | ||
235 : | |||
236 : | HRESULT | ||
237 : | AddDirectXFilterByMoniker(const CLSID &MonikerClsID, char *FriendlyName, | ||
238 : | IBaseFilter **pFilter, int StringType) | ||
239 : | { | ||
240 : | // Create the System Device Enumerator. | ||
241 : | HRESULT hr, ret = E_FAIL; | ||
242 : | |||
243 : | int NameLen = (int) strlen(FriendlyName); | ||
244 : | wchar_t *wFcc = new wchar_t [NameLen + 1]; | ||
245 : | mbstowcs(wFcc, FriendlyName, NameLen); | ||
246 : | ICreateDevEnum *pSysDevEnum = NULL; | ||
247 : | |||
248 : | hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, | ||
249 : | IID_ICreateDevEnum, (void **)&pSysDevEnum); | ||
250 : | if (FAILED(hr)) { | ||
251 : | return hr; | ||
252 : | } | ||
253 : | |||
254 : | // Obtain a class enumerator for the video compressor category. | ||
255 : | IEnumMoniker *pEnumCat = NULL; | ||
256 : | hr = pSysDevEnum->CreateClassEnumerator(MonikerClsID, &pEnumCat, 0); | ||
257 : | |||
258 : | if (hr == S_OK) | ||
259 : | { | ||
260 : | // Enumerate the monikers. | ||
261 : | IMoniker *pMoniker = NULL; | ||
262 : | ULONG cFetched; | ||
263 : | |||
264 : | while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK && FAILED(ret)) | ||
265 : | { | ||
266 : | IPropertyBag *pPropBag; | ||
267 : | hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag); | ||
268 : | |||
269 : | if (SUCCEEDED(hr)) | ||
270 : | { | ||
271 : | // To retrieve the filter's friendly name, do the following: | ||
272 : | VARIANT varName; | ||
273 : | VariantInit(&varName); | ||
274 : | |||
275 : | if (StringType == 0) | ||
276 : | hr = pPropBag->Read(L"FriendlyName", &varName, 0); | ||
277 : | else { | ||
278 : | hr = pPropBag->Read(L"FccHandler", &varName, 0); | ||
279 : | } | ||
280 : | |||
281 : | if (SUCCEEDED(hr)) { | ||
282 : | size_t k; | ||
283 : | |||
284 : | if (SysStringLen(varName.bstrVal) == (k=strlen(FriendlyName))) { | ||
285 : | size_t l, j=1; | ||
286 : | |||
287 : | for (l=0; l<k; l++) { | ||
288 : | if (varName.bstrVal[l] != wFcc[l]) | ||
289 : | j=0; | ||
290 : | } | ||
291 : | |||
292 : | if(j==1) { | ||
293 : | // Display the name in your UI somehow. | ||
294 : | ret = hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, | ||
295 : | (void**)pFilter); | ||
296 : | } | ||
297 : | } | ||
298 : | } | ||
299 : | VariantClear(&varName); | ||
300 : | pPropBag->Release(); | ||
301 : | } | ||
302 : | pMoniker->Release(); | ||
303 : | } | ||
304 : | pEnumCat->Release(); | ||
305 : | } | ||
306 : | pSysDevEnum->Release(); | ||
307 : | |||
308 : | delete [] wFcc; | ||
309 : | |||
310 : | return ret; | ||
311 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |