1 /* GStreamer
2 * Copyright (C) 2007 Sebastien Moutte <sebastien@moutte.net>
3 *
4 * gstdshow.cpp:
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #include <dmodshow.h>
23 #include <dmoreg.h>
24
25 #include "gstdshowutil.h"
26 #include "gstdshowfakesrc.h"
27
28 _COM_SMARTPTR_TYPEDEF(IDMOWrapperFilter, __uuidof(IDMOWrapperFilter));
29
30 IPin *
gst_dshow_get_pin_from_filter(IBaseFilter * filter,PIN_DIRECTION pindir)31 gst_dshow_get_pin_from_filter (IBaseFilter *filter, PIN_DIRECTION pindir)
32 {
33 IEnumPinsPtr enumpins;
34 IPinPtr pin;
35 HRESULT hres;
36
37 hres = filter->EnumPins (&enumpins);
38 if (FAILED(hres)) {
39 return NULL;
40 }
41
42 while (enumpins->Next (1, &pin, NULL) == S_OK)
43 {
44 PIN_DIRECTION pindirtmp;
45 hres = pin->QueryDirection (&pindirtmp);
46 if (hres == S_OK && pindir == pindirtmp) {
47 return pin;
48 }
49 pin.Release();
50 }
51
52 return NULL;
53 }
54
55 IBaseFilter *
gst_dshow_find_filter(CLSID input_majortype,CLSID input_subtype,CLSID output_majortype,CLSID output_subtype,PreferredFilter * preferred_filters)56 gst_dshow_find_filter(CLSID input_majortype, CLSID input_subtype,
57 CLSID output_majortype, CLSID output_subtype,
58 PreferredFilter *preferred_filters)
59 {
60 HRESULT hres;
61 GUID inTypes[2];
62 GUID outTypes[2];
63 IFilterMapper2Ptr mapper;
64 IEnumMonikerPtr enum_moniker;
65 IMonikerPtr moniker;
66 ULONG fetched;
67 IBaseFilter *filter;
68
69 /* First, see if any of our preferred filters is available.
70 * If not, we fall back to the highest-ranked installed filter */
71 if (preferred_filters) {
72 while (preferred_filters->filter_guid)
73 {
74 /* If the filter is a DMO, we need to do this a bit differently */
75 if (preferred_filters->dmo_category)
76 {
77 IDMOWrapperFilterPtr wrapper;
78
79 hres = CoCreateInstance (CLSID_DMOWrapperFilter, NULL,
80 CLSCTX_INPROC,
81 IID_IBaseFilter, (void **)&filter);
82 if (SUCCEEDED(hres)) {
83 hres = filter->QueryInterface (&wrapper);
84 if (SUCCEEDED(hres)) {
85 hres = wrapper->Init (*preferred_filters->filter_guid,
86 *preferred_filters->dmo_category);
87 if (SUCCEEDED(hres))
88 return filter;
89 }
90 filter->Release();
91 }
92 }
93 else
94 {
95 hres = CoCreateInstance (*preferred_filters->filter_guid,
96 NULL, CLSCTX_INPROC,
97 IID_IBaseFilter, (void **)&filter);
98 if (SUCCEEDED(hres))
99 return filter;
100 }
101
102 /* Continue to the next filter */
103 preferred_filters++;
104 }
105 }
106
107 hres = CoCreateInstance(CLSID_FilterMapper2, NULL, CLSCTX_INPROC,
108 IID_IFilterMapper2, (void **) &mapper);
109 if (FAILED(hres))
110 return NULL;
111
112 inTypes[0] = input_majortype;
113 inTypes[1] = input_subtype;
114 outTypes[0] = output_majortype;
115 outTypes[1] = output_subtype;
116
117 hres = mapper->EnumMatchingFilters (&enum_moniker, 0,
118 FALSE, MERIT_DO_NOT_USE+1,
119 TRUE, 1, inTypes, NULL, NULL, FALSE,
120 TRUE, 1, outTypes, NULL, NULL);
121 if (FAILED(hres))
122 return NULL;
123
124 enum_moniker->Reset ();
125
126 while(enum_moniker->Next (1, &moniker, &fetched) == S_OK)
127 {
128 hres = moniker->BindToObject(NULL, NULL,
129 IID_IBaseFilter, (void**)&filter);
130 if(SUCCEEDED(hres)) {
131 return filter;
132 }
133 moniker.Release ();
134 }
135
136 return NULL;
137 }
138
139