Mercurial > mplayer.hg
annotate loader/dshow/DS_Filter.c @ 9001:01a9cf43074c
An AltiVec-enhanced IMDCT for liba52 (liba52/imdct.c)
It's nearly bit-perfect, I have a couple of lsb
changed in a 128 frames sample. I can't hear the
differences :-)
patch by Romain Dolbeau <dolbeau@irisa.fr>
author | arpi |
---|---|
date | Sat, 18 Jan 2003 19:28:29 +0000 |
parents | 9533c26c0806 |
children | b0d1b415320c |
rev | line source |
---|---|
1545 | 1 #include "DS_Filter.h" |
3056 | 2 #include "driver.h" |
3 #include "com.h" | |
168 | 4 #include <stdio.h> |
5 #include <string.h> | |
7386 | 6 #include <stdlib.h> |
7 #include "win32.h" // printf macro | |
1545 | 8 |
168 | 9 typedef long STDCALL (*GETCLASS) (const GUID*, const GUID*, void**); |
10 | |
8292 | 11 //void trapbug(); |
244 | 12 |
3056 | 13 static void DS_Filter_Start(DS_Filter* This) |
168 | 14 { |
3056 | 15 HRESULT hr; |
16 | |
3467 | 17 if (This->m_pAll) |
3056 | 18 return; |
19 | |
20 //Debug printf("DS_Filter_Start(%p)\n", This); | |
8292 | 21 hr = This->m_pFilter->vt->Run(This->m_pFilter, (REFERENCE_TIME)0); |
3056 | 22 if (hr != 0) |
23 { | |
24 Debug printf("WARNING: m_Filter->Run() failed, error code %x\n", (int)hr); | |
25 } | |
26 hr = This->m_pImp->vt->GetAllocator(This->m_pImp, &This->m_pAll); | |
27 | |
28 if (hr || !This->m_pAll) | |
29 { | |
30 Debug printf("WARNING: error getting IMemAllocator interface %x\n", (int)hr); | |
31 This->m_pImp->vt->Release((IUnknown*)This->m_pImp); | |
32 return; | |
33 } | |
34 This->m_pImp->vt->NotifyAllocator(This->m_pImp, This->m_pAll, 0); | |
168 | 35 } |
36 | |
3056 | 37 static void DS_Filter_Stop(DS_Filter* This) |
713 | 38 { |
3467 | 39 if (This->m_pAll) |
3056 | 40 { |
41 //Debug printf("DS_Filter_Stop(%p)\n", This); | |
3467 | 42 This->m_pFilter->vt->Stop(This->m_pFilter); // causes weird crash ??? FIXME |
3056 | 43 This->m_pAll->vt->Release((IUnknown*)This->m_pAll); |
44 This->m_pAll = 0; | |
45 } | |
1545 | 46 } |
47 | |
3056 | 48 void DS_Filter_Destroy(DS_Filter* This) |
1545 | 49 { |
3056 | 50 This->Stop(This); |
51 | |
52 if (This->m_pOurInput) | |
53 This->m_pOurInput->vt->Release((IUnknown*)This->m_pOurInput); | |
54 if (This->m_pInputPin) | |
55 This->m_pInputPin->vt->Disconnect(This->m_pInputPin); | |
56 if (This->m_pOutputPin) | |
57 This->m_pOutputPin->vt->Disconnect(This->m_pOutputPin); | |
58 if (This->m_pFilter) | |
59 This->m_pFilter->vt->Release((IUnknown*)This->m_pFilter); | |
60 if (This->m_pOutputPin) | |
61 This->m_pOutputPin->vt->Release((IUnknown*)This->m_pOutputPin); | |
62 if (This->m_pInputPin) | |
63 This->m_pInputPin->vt->Release((IUnknown*)This->m_pInputPin); | |
64 if (This->m_pImp) | |
65 This->m_pImp->vt->Release((IUnknown*)This->m_pImp); | |
713 | 66 |
3056 | 67 if (This->m_pOurOutput) |
68 This->m_pOurOutput->vt->Release((IUnknown*)This->m_pOurOutput); | |
69 if (This->m_pParentFilter) | |
3130 | 70 This->m_pParentFilter->vt->Release((IUnknown*)This->m_pParentFilter); |
3056 | 71 if (This->m_pSrcFilter) |
72 This->m_pSrcFilter->vt->Release((IUnknown*)This->m_pSrcFilter); | |
713 | 73 |
74 // FIXME - we are still leaving few things allocated! | |
3056 | 75 if (This->m_iHandle) |
8292 | 76 FreeLibrary((unsigned)This->m_iHandle); |
3056 | 77 |
78 free(This); | |
79 | |
80 CodecRelease(); | |
713 | 81 } |
82 | |
3056 | 83 DS_Filter* DS_FilterCreate(const char* dllname, const GUID* id, |
84 AM_MEDIA_TYPE* in_fmt, | |
85 AM_MEDIA_TYPE* out_fmt) | |
168 | 86 { |
3467 | 87 int init = 0; |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7386
diff
changeset
|
88 // char eb[250]; |
3467 | 89 const char* em = NULL; |
8292 | 90 HRESULT result; |
3056 | 91 DS_Filter* This = (DS_Filter*) malloc(sizeof(DS_Filter)); |
92 if (!This) | |
93 return NULL; | |
94 | |
95 CodecAlloc(); | |
96 | |
97 This->m_pFilter = NULL; | |
98 This->m_pInputPin = NULL; | |
99 This->m_pOutputPin = NULL; | |
100 This->m_pSrcFilter = NULL; | |
101 This->m_pParentFilter = NULL; | |
102 This->m_pOurInput = NULL; | |
103 This->m_pOurOutput = NULL; | |
104 This->m_pAll = NULL; | |
105 This->m_pImp = NULL; | |
106 | |
107 This->Start = DS_Filter_Start; | |
108 This->Stop = DS_Filter_Stop; | |
109 | |
110 for (;;) | |
168 | 111 { |
3056 | 112 GETCLASS func; |
113 struct IClassFactory* factory = NULL; | |
114 struct IUnknown* object = NULL; | |
115 IEnumPins* enum_pins = 0; | |
116 IPin* array[256]; | |
117 ULONG fetched; | |
118 unsigned int i; | |
119 | |
120 This->m_iHandle = LoadLibraryA(dllname); | |
121 if (!This->m_iHandle) | |
713 | 122 { |
3467 | 123 em = "could not open DirectShow DLL"; |
3056 | 124 break; |
713 | 125 } |
8292 | 126 func = (GETCLASS)GetProcAddress((unsigned)This->m_iHandle, "DllGetClassObject"); |
713 | 127 if (!func) |
128 { | |
3467 | 129 em = "illegal or corrupt DirectShow DLL"; |
3056 | 130 break; |
713 | 131 } |
1545 | 132 result = func(id, &IID_IClassFactory, (void**)&factory); |
133 if (result || !factory) | |
3056 | 134 { |
3467 | 135 em = "no such class object"; |
3056 | 136 break; |
137 } | |
1545 | 138 result = factory->vt->CreateInstance(factory, 0, &IID_IUnknown, (void**)&object); |
168 | 139 factory->vt->Release((IUnknown*)factory); |
1545 | 140 if (result || !object) |
3056 | 141 { |
3467 | 142 em = "class factory failure"; |
3056 | 143 break; |
144 } | |
145 result = object->vt->QueryInterface(object, &IID_IBaseFilter, (void**)&This->m_pFilter); | |
168 | 146 object->vt->Release((IUnknown*)object); |
3056 | 147 if (result || !This->m_pFilter) |
148 { | |
7386 | 149 em = "object does not provide IBaseFilter interface"; |
3056 | 150 break; |
151 } | |
152 // enumerate pins | |
153 result = This->m_pFilter->vt->EnumPins(This->m_pFilter, &enum_pins); | |
154 if (result || !enum_pins) | |
155 { | |
3467 | 156 em = "could not enumerate pins"; |
3056 | 157 break; |
158 } | |
713 | 159 |
168 | 160 enum_pins->vt->Reset(enum_pins); |
1545 | 161 result = enum_pins->vt->Next(enum_pins, (ULONG)256, (IPin**)array, &fetched); |
8292 | 162 Debug printf("Pins enumeration returned %ld pins, error is %x\n", fetched, (int)result); |
713 | 163 |
3056 | 164 for (i = 0; i < fetched; i++) |
168 | 165 { |
713 | 166 int direction = -1; |
168 | 167 array[i]->vt->QueryDirection(array[i], (PIN_DIRECTION*)&direction); |
3056 | 168 if (!This->m_pInputPin && direction == 0) |
168 | 169 { |
3056 | 170 This->m_pInputPin = array[i]; |
171 This->m_pInputPin->vt->AddRef((IUnknown*)This->m_pInputPin); | |
168 | 172 } |
3056 | 173 if (!This->m_pOutputPin && direction == 1) |
168 | 174 { |
3056 | 175 This->m_pOutputPin = array[i]; |
176 This->m_pOutputPin->vt->AddRef((IUnknown*)This->m_pOutputPin); | |
168 | 177 } |
178 array[i]->vt->Release((IUnknown*)(array[i])); | |
179 } | |
3056 | 180 if (!This->m_pInputPin) |
181 { | |
3467 | 182 em = "could not find input pin"; |
3056 | 183 break; |
184 } | |
185 if (!This->m_pOutputPin) | |
186 { | |
3467 | 187 em = "could not find output pin"; |
3056 | 188 break; |
189 } | |
190 result = This->m_pInputPin->vt->QueryInterface((IUnknown*)This->m_pInputPin, | |
191 &IID_IMemInputPin, | |
192 (void**)&This->m_pImp); | |
713 | 193 if (result) |
3056 | 194 { |
3467 | 195 em = "could not get IMemInputPin interface"; |
3056 | 196 break; |
197 } | |
168 | 198 |
3056 | 199 This->m_pOurType = in_fmt; |
200 This->m_pDestType = out_fmt; | |
201 result = This->m_pInputPin->vt->QueryAccept(This->m_pInputPin, This->m_pOurType); | |
713 | 202 if (result) |
3056 | 203 { |
3467 | 204 em = "source format is not accepted"; |
3056 | 205 break; |
206 } | |
207 This->m_pParentFilter = CBaseFilter2Create(); | |
208 This->m_pSrcFilter = CBaseFilterCreate(This->m_pOurType, This->m_pParentFilter); | |
209 This->m_pOurInput = This->m_pSrcFilter->GetPin(This->m_pSrcFilter); | |
210 This->m_pOurInput->vt->AddRef((IUnknown*)This->m_pOurInput); | |
713 | 211 |
3056 | 212 result = This->m_pInputPin->vt->ReceiveConnection(This->m_pInputPin, |
213 This->m_pOurInput, | |
214 This->m_pOurType); | |
215 if (result) | |
216 { | |
3467 | 217 em = "could not connect to input pin"; |
3056 | 218 break; |
219 } | |
220 | |
221 This->m_pOurOutput = COutputPinCreate(This->m_pDestType); | |
222 | |
223 result = This->m_pOutputPin->vt->ReceiveConnection(This->m_pOutputPin, | |
224 (IPin*) This->m_pOurOutput, | |
225 This->m_pDestType); | |
713 | 226 if (result) |
1545 | 227 { |
3467 | 228 em = "could not connect to output pin"; |
3056 | 229 break; |
1545 | 230 } |
231 | |
3467 | 232 init++; |
3056 | 233 break; |
168 | 234 } |
3056 | 235 |
3467 | 236 if (!init) |
168 | 237 { |
3056 | 238 DS_Filter_Destroy(This); |
8292 | 239 printf("Warning: DS_Filter() %s. (DLL=%.200s, r=0x%x)\n", em, dllname, result); |
3056 | 240 This = 0; |
168 | 241 } |
3056 | 242 return This; |
168 | 243 } |