Mercurial > mplayer.hg
annotate loader/dshow/DS_Filter.c @ 22347:c8a46062a210
Move glob-win.c out of MinGW section, configure handles it.
author | diego |
---|---|
date | Tue, 27 Feb 2007 17:12:23 +0000 |
parents | 254733f57707 |
children | 49f01f8fbd60 |
rev | line source |
---|---|
15166
f5537cc95b02
Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents:
9967
diff
changeset
|
1 /* |
18783 | 2 * Modified for use with MPlayer, detailed changelog at |
3 * http://svn.mplayerhq.hu/mplayer/trunk/ | |
15166
f5537cc95b02
Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents:
9967
diff
changeset
|
4 * $Id$ |
f5537cc95b02
Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents:
9967
diff
changeset
|
5 */ |
f5537cc95b02
Mark modified imported files as such to comply with GPL ¡ø2a.
diego
parents:
9967
diff
changeset
|
6 |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
7 #include "config.h" |
1545 | 8 #include "DS_Filter.h" |
3056 | 9 #include "driver.h" |
10 #include "com.h" | |
168 | 11 #include <stdio.h> |
12 #include <string.h> | |
7386 | 13 #include <stdlib.h> |
14 #include "win32.h" // printf macro | |
1545 | 15 |
168 | 16 typedef long STDCALL (*GETCLASS) (const GUID*, const GUID*, void**); |
17 | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
18 #ifndef WIN32_LOADER |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
19 const GUID IID_IUnknown = |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
20 { |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
21 0x00000000, 0x0000, 0x0000, |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
22 {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
23 }; |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
24 const GUID IID_IClassFactory = |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
25 { |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
26 0x00000001, 0x0000, 0x0000, |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
27 {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
28 }; |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
29 |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
30 HRESULT STDCALL CoInitialize(LPVOID pvReserved); |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
31 void STDCALL CoUninitialize(void); |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
32 #endif |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
33 |
8292 | 34 //void trapbug(); |
244 | 35 |
3056 | 36 static void DS_Filter_Start(DS_Filter* This) |
168 | 37 { |
3056 | 38 HRESULT hr; |
39 | |
40 //Debug printf("DS_Filter_Start(%p)\n", This); | |
8292 | 41 hr = This->m_pFilter->vt->Run(This->m_pFilter, (REFERENCE_TIME)0); |
3056 | 42 if (hr != 0) |
43 { | |
44 Debug printf("WARNING: m_Filter->Run() failed, error code %x\n", (int)hr); | |
45 } | |
168 | 46 } |
47 | |
3056 | 48 static void DS_Filter_Stop(DS_Filter* This) |
713 | 49 { |
3467 | 50 if (This->m_pAll) |
3056 | 51 { |
52 //Debug printf("DS_Filter_Stop(%p)\n", This); | |
3467 | 53 This->m_pFilter->vt->Stop(This->m_pFilter); // causes weird crash ??? FIXME |
3056 | 54 This->m_pAll->vt->Release((IUnknown*)This->m_pAll); |
55 This->m_pAll = 0; | |
56 } | |
1545 | 57 } |
58 | |
3056 | 59 void DS_Filter_Destroy(DS_Filter* This) |
1545 | 60 { |
3056 | 61 This->Stop(This); |
62 | |
63 if (This->m_pOurInput) | |
64 This->m_pOurInput->vt->Release((IUnknown*)This->m_pOurInput); | |
65 if (This->m_pInputPin) | |
66 This->m_pInputPin->vt->Disconnect(This->m_pInputPin); | |
67 if (This->m_pOutputPin) | |
68 This->m_pOutputPin->vt->Disconnect(This->m_pOutputPin); | |
69 if (This->m_pFilter) | |
70 This->m_pFilter->vt->Release((IUnknown*)This->m_pFilter); | |
71 if (This->m_pOutputPin) | |
72 This->m_pOutputPin->vt->Release((IUnknown*)This->m_pOutputPin); | |
73 if (This->m_pInputPin) | |
74 This->m_pInputPin->vt->Release((IUnknown*)This->m_pInputPin); | |
75 if (This->m_pImp) | |
76 This->m_pImp->vt->Release((IUnknown*)This->m_pImp); | |
713 | 77 |
3056 | 78 if (This->m_pOurOutput) |
79 This->m_pOurOutput->vt->Release((IUnknown*)This->m_pOurOutput); | |
80 if (This->m_pParentFilter) | |
3130 | 81 This->m_pParentFilter->vt->Release((IUnknown*)This->m_pParentFilter); |
3056 | 82 if (This->m_pSrcFilter) |
83 This->m_pSrcFilter->vt->Release((IUnknown*)This->m_pSrcFilter); | |
713 | 84 |
85 // FIXME - we are still leaving few things allocated! | |
3056 | 86 if (This->m_iHandle) |
8292 | 87 FreeLibrary((unsigned)This->m_iHandle); |
3056 | 88 |
89 free(This); | |
90 | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
91 #ifdef WIN32_LOADER |
3056 | 92 CodecRelease(); |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
93 #else |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
94 CoUninitialize(); |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
95 #endif |
713 | 96 } |
97 | |
3056 | 98 DS_Filter* DS_FilterCreate(const char* dllname, const GUID* id, |
99 AM_MEDIA_TYPE* in_fmt, | |
100 AM_MEDIA_TYPE* out_fmt) | |
168 | 101 { |
3467 | 102 int init = 0; |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7386
diff
changeset
|
103 // char eb[250]; |
3467 | 104 const char* em = NULL; |
22304
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
105 MemAllocator* tempAll; |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
106 ALLOCATOR_PROPERTIES props,props1; |
8292 | 107 HRESULT result; |
3056 | 108 DS_Filter* This = (DS_Filter*) malloc(sizeof(DS_Filter)); |
109 if (!This) | |
110 return NULL; | |
111 | |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
112 #ifdef WIN32_LOADER |
3056 | 113 CodecAlloc(); |
9967
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
114 #else |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
115 CoInitialize(0L); |
b0d1b415320c
cygwin support patch by Sascha Sommer and some fixes by me
alex
parents:
8292
diff
changeset
|
116 #endif |
3056 | 117 |
22304
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
118 /* |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
119 tempAll is not used anywhere. |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
120 MemAllocatorCreate() is called to ensure that RegisterComObject for IMemoryAllocator |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
121 will be called before possible call |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
122 to CoCreateInstance(...,&IID_IMemoryAllocator,...) from binary codec. |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
123 */ |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
124 tempAll=MemAllocatorCreate(); |
3056 | 125 This->m_pFilter = NULL; |
126 This->m_pInputPin = NULL; | |
127 This->m_pOutputPin = NULL; | |
128 This->m_pSrcFilter = NULL; | |
129 This->m_pParentFilter = NULL; | |
130 This->m_pOurInput = NULL; | |
131 This->m_pOurOutput = NULL; | |
132 This->m_pAll = NULL; | |
133 This->m_pImp = NULL; | |
134 | |
135 This->Start = DS_Filter_Start; | |
136 This->Stop = DS_Filter_Stop; | |
137 | |
138 for (;;) | |
168 | 139 { |
3056 | 140 GETCLASS func; |
141 struct IClassFactory* factory = NULL; | |
142 struct IUnknown* object = NULL; | |
143 IEnumPins* enum_pins = 0; | |
144 IPin* array[256]; | |
145 ULONG fetched; | |
146 unsigned int i; | |
147 | |
148 This->m_iHandle = LoadLibraryA(dllname); | |
149 if (!This->m_iHandle) | |
713 | 150 { |
3467 | 151 em = "could not open DirectShow DLL"; |
3056 | 152 break; |
713 | 153 } |
8292 | 154 func = (GETCLASS)GetProcAddress((unsigned)This->m_iHandle, "DllGetClassObject"); |
713 | 155 if (!func) |
156 { | |
3467 | 157 em = "illegal or corrupt DirectShow DLL"; |
3056 | 158 break; |
713 | 159 } |
1545 | 160 result = func(id, &IID_IClassFactory, (void**)&factory); |
161 if (result || !factory) | |
3056 | 162 { |
3467 | 163 em = "no such class object"; |
3056 | 164 break; |
165 } | |
1545 | 166 result = factory->vt->CreateInstance(factory, 0, &IID_IUnknown, (void**)&object); |
168 | 167 factory->vt->Release((IUnknown*)factory); |
1545 | 168 if (result || !object) |
3056 | 169 { |
3467 | 170 em = "class factory failure"; |
3056 | 171 break; |
172 } | |
173 result = object->vt->QueryInterface(object, &IID_IBaseFilter, (void**)&This->m_pFilter); | |
168 | 174 object->vt->Release((IUnknown*)object); |
3056 | 175 if (result || !This->m_pFilter) |
176 { | |
7386 | 177 em = "object does not provide IBaseFilter interface"; |
3056 | 178 break; |
179 } | |
180 // enumerate pins | |
181 result = This->m_pFilter->vt->EnumPins(This->m_pFilter, &enum_pins); | |
182 if (result || !enum_pins) | |
183 { | |
3467 | 184 em = "could not enumerate pins"; |
3056 | 185 break; |
186 } | |
713 | 187 |
168 | 188 enum_pins->vt->Reset(enum_pins); |
1545 | 189 result = enum_pins->vt->Next(enum_pins, (ULONG)256, (IPin**)array, &fetched); |
8292 | 190 Debug printf("Pins enumeration returned %ld pins, error is %x\n", fetched, (int)result); |
713 | 191 |
3056 | 192 for (i = 0; i < fetched; i++) |
168 | 193 { |
713 | 194 int direction = -1; |
168 | 195 array[i]->vt->QueryDirection(array[i], (PIN_DIRECTION*)&direction); |
3056 | 196 if (!This->m_pInputPin && direction == 0) |
168 | 197 { |
3056 | 198 This->m_pInputPin = array[i]; |
199 This->m_pInputPin->vt->AddRef((IUnknown*)This->m_pInputPin); | |
168 | 200 } |
3056 | 201 if (!This->m_pOutputPin && direction == 1) |
168 | 202 { |
3056 | 203 This->m_pOutputPin = array[i]; |
204 This->m_pOutputPin->vt->AddRef((IUnknown*)This->m_pOutputPin); | |
168 | 205 } |
206 array[i]->vt->Release((IUnknown*)(array[i])); | |
207 } | |
3056 | 208 if (!This->m_pInputPin) |
209 { | |
3467 | 210 em = "could not find input pin"; |
3056 | 211 break; |
212 } | |
213 if (!This->m_pOutputPin) | |
214 { | |
3467 | 215 em = "could not find output pin"; |
3056 | 216 break; |
217 } | |
218 result = This->m_pInputPin->vt->QueryInterface((IUnknown*)This->m_pInputPin, | |
219 &IID_IMemInputPin, | |
220 (void**)&This->m_pImp); | |
713 | 221 if (result) |
3056 | 222 { |
3467 | 223 em = "could not get IMemInputPin interface"; |
3056 | 224 break; |
225 } | |
168 | 226 |
3056 | 227 This->m_pOurType = in_fmt; |
228 This->m_pDestType = out_fmt; | |
229 result = This->m_pInputPin->vt->QueryAccept(This->m_pInputPin, This->m_pOurType); | |
713 | 230 if (result) |
3056 | 231 { |
3467 | 232 em = "source format is not accepted"; |
3056 | 233 break; |
234 } | |
235 This->m_pParentFilter = CBaseFilter2Create(); | |
236 This->m_pSrcFilter = CBaseFilterCreate(This->m_pOurType, This->m_pParentFilter); | |
237 This->m_pOurInput = This->m_pSrcFilter->GetPin(This->m_pSrcFilter); | |
238 This->m_pOurInput->vt->AddRef((IUnknown*)This->m_pOurInput); | |
713 | 239 |
3056 | 240 result = This->m_pInputPin->vt->ReceiveConnection(This->m_pInputPin, |
241 This->m_pOurInput, | |
242 This->m_pOurType); | |
243 if (result) | |
244 { | |
3467 | 245 em = "could not connect to input pin"; |
3056 | 246 break; |
247 } | |
22304
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
248 result = This->m_pImp->vt->GetAllocator(This->m_pImp, &This->m_pAll); |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
249 if (result || !This->m_pAll) |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
250 { |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
251 em="error getting IMemAllocator interface"; |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
252 break; |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
253 } |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
254 |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
255 //Seting allocator property according to our media type |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
256 props.cBuffers=1; |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
257 props.cbBuffer=This->m_pOurType->lSampleSize; |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
258 props.cbAlign=1; |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
259 props.cbPrefix=0; |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
260 This->m_pAll->vt->SetProperties(This->m_pAll, &props, &props1); |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
261 |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
262 //Notify remote pin about choosed allocator |
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
263 This->m_pImp->vt->NotifyAllocator(This->m_pImp, This->m_pAll, 0); |
3056 | 264 |
265 This->m_pOurOutput = COutputPinCreate(This->m_pDestType); | |
266 | |
267 result = This->m_pOutputPin->vt->ReceiveConnection(This->m_pOutputPin, | |
268 (IPin*) This->m_pOurOutput, | |
269 This->m_pDestType); | |
713 | 270 if (result) |
1545 | 271 { |
3467 | 272 em = "could not connect to output pin"; |
3056 | 273 break; |
1545 | 274 } |
275 | |
3467 | 276 init++; |
3056 | 277 break; |
168 | 278 } |
22304
254733f57707
Fixed loading of VoxWare and wma9sp binary audio codecs using dshow engine.
voroshil
parents:
18783
diff
changeset
|
279 tempAll->vt->Release(tempAll); |
3056 | 280 |
3467 | 281 if (!init) |
168 | 282 { |
3056 | 283 DS_Filter_Destroy(This); |
8292 | 284 printf("Warning: DS_Filter() %s. (DLL=%.200s, r=0x%x)\n", em, dllname, result); |
3056 | 285 This = 0; |
168 | 286 } |
3056 | 287 return This; |
168 | 288 } |