Mercurial > mplayer.hg
comparison loader/dshow/DS_Filter.c @ 1545:da26060c81ef
big avifile sync - from now we have common code
author | arpi |
---|---|
date | Thu, 16 Aug 2001 00:50:02 +0000 |
parents | 9525bff8bea8 |
children | ce45cce7f7a5 |
comparison
equal
deleted
inserted
replaced
1544:558c1b03b8d0 | 1545:da26060c81ef |
---|---|
1 #include "DS_Filter.h" | |
2 //#include "../loader/loader.h" | |
3 #include <libwin32.h> | |
4 #include <string> | |
1 #include <stdio.h> | 5 #include <stdio.h> |
2 #include <string.h> | 6 #include <string.h> |
3 #include "DS_Filter.h" | 7 |
4 #include <except.h> | |
5 //#include "../loader/loader.h" | |
6 #include <string> | |
7 #include <iostream> | |
8 #define __MODULE__ "DirectShow generic filter" | 8 #define __MODULE__ "DirectShow generic filter" |
9 | 9 |
10 using namespace std; | 10 using namespace std; |
11 | 11 |
12 extern "C" int STDCALL expLoadLibraryA(const char*); | |
13 | |
12 typedef long STDCALL (*GETCLASS) (const GUID*, const GUID*, void**); | 14 typedef long STDCALL (*GETCLASS) (const GUID*, const GUID*, void**); |
13 extern "C" char* def_path; | 15 |
14 | 16 //extern "C" int STDCALL LoadLibraryA(const char*); |
15 extern "C" int STDCALL expLoadLibraryA(const char*); | 17 //extern "C" STDCALL void* GetProcAddress(int, const char*); // STDCALL has to be first NetBSD |
16 extern "C" STDCALL void* GetProcAddress(int, const char*); | 18 //extern "C" int STDCALL FreeLibrary(int); |
17 extern "C" int STDCALL FreeLibrary(int); | |
18 | |
19 extern "C" void Setup_LDT_Keeper(); | |
20 extern "C" void setup_FS_Segment(); | |
21 | 19 |
22 DS_Filter::DS_Filter() | 20 DS_Filter::DS_Filter() |
23 :m_iHandle(0), m_pFilter(0), m_pInputPin(0), | 21 { |
24 m_pOutputPin(0), m_pSrcFilter(0), m_pParentFilter(0), | 22 m_iHandle = 0; |
25 m_pOurInput(0), m_pOurOutput(0), m_pAll(0), m_pImp(0), | 23 m_pFilter = 0; |
26 m_iState(0) | 24 m_pInputPin = 0; |
27 { | 25 m_pOutputPin = 0; |
28 } | 26 m_pSrcFilter = 0; |
29 | 27 m_pParentFilter = 0; |
30 void DS_Filter::clean() | 28 m_pOurInput = 0; |
31 { | 29 m_pOurOutput = 0; |
30 m_pAll = 0; | |
31 m_pImp = 0; | |
32 m_iState = 0; | |
33 } | |
34 | |
35 DS_Filter::~DS_Filter() | |
36 { | |
37 //cout << "Destruction of DS_FILTER" << endl; | |
38 Stop(); | |
39 destroy(); | |
40 //cout << "Destruction of DS_FILTER done" << endl; | |
41 } | |
42 | |
43 void DS_Filter::destroy() | |
44 { | |
45 if (m_iState == 0) | |
46 return; | |
32 m_iState = 0; | 47 m_iState = 0; |
33 | 48 |
34 if (m_pOurInput) | 49 if (m_pOurInput) |
35 m_pOurInput->vt->Release((IUnknown*)m_pOurInput); | 50 m_pOurInput->vt->Release((IUnknown*)m_pOurInput); |
36 if (m_pInputPin) | 51 if (m_pInputPin) |
51 delete m_pSrcFilter; | 66 delete m_pSrcFilter; |
52 | 67 |
53 // FIXME - we are still leaving few things allocated! | 68 // FIXME - we are still leaving few things allocated! |
54 if (m_iHandle) | 69 if (m_iHandle) |
55 FreeLibrary(m_iHandle); | 70 FreeLibrary(m_iHandle); |
56 | 71 } |
57 } | 72 |
58 | 73 void DS_Filter::Create(const char* dllname, const GUID* id, |
59 DS_Filter::~DS_Filter() | 74 AM_MEDIA_TYPE* in_fmt, |
60 { | 75 AM_MEDIA_TYPE* out_fmt) |
61 //cout << "Destruction of DS_FILTER" << endl; | 76 { |
62 Stop(); | |
63 if (m_iState == 1) | |
64 clean(); | |
65 //cout << "Destruction of DS_FILTER done" << endl; | |
66 } | |
67 | |
68 void DS_Filter::Create(char* dllname, const GUID* id, AM_MEDIA_TYPE* in_fmt, AM_MEDIA_TYPE* out_fmt) | |
69 { | |
70 | |
71 Setup_LDT_Keeper(); | |
72 | |
73 try | 77 try |
74 { | 78 { |
75 // string _fullname=def_path; | 79 m_iHandle = expLoadLibraryA(dllname); |
76 // _fullname+="/"; | |
77 // _fullname+=dllname; | |
78 m_iHandle= expLoadLibraryA(dllname); | |
79 if (!m_iHandle) | 80 if (!m_iHandle) |
80 { | 81 { |
81 char e[1024]; | 82 char e[256]; |
82 snprintf(e, 1024, "Could not open DirectShow DLL: %s", dllname); | 83 printf("Could not open DirectShow DLL: %.200s", dllname); |
83 throw FATAL(e); | 84 throw FATAL(e); |
84 } | 85 } |
85 GETCLASS func=(GETCLASS)GetProcAddress(m_iHandle, "DllGetClassObject"); | 86 GETCLASS func = (GETCLASS)GetProcAddress(m_iHandle, "DllGetClassObject"); |
86 if (!func) | 87 if (!func) |
87 { | 88 { |
88 char e[1024]; | 89 char e[256]; |
89 snprintf(e, 1024, "Illegal or corrupt DirectShow DLL: %s", dllname); | 90 printf("Illegal or corrupt DirectShow DLL: %.200s", dllname); |
90 throw FATAL(e); | 91 throw FATAL(e); |
91 } | 92 } |
92 | 93 |
93 HRESULT result; | 94 HRESULT result; |
94 IClassFactory* factory=0; | 95 IClassFactory* factory = 0; |
95 result=func(id, &IID_IClassFactory, (void**)&factory); | 96 result = func(id, &IID_IClassFactory, (void**)&factory); |
96 if(result || (!factory)) throw FATAL("No such class object");; | 97 if (result || !factory) |
97 | 98 throw FATAL("No such class object");; |
98 setup_FS_Segment(); | 99 |
99 | 100 IUnknown* object = 0; |
100 IUnknown* object=0; | 101 result = factory->vt->CreateInstance(factory, 0, &IID_IUnknown, (void**)&object); |
101 result=factory->vt->CreateInstance(factory, 0, &IID_IUnknown, (void**)&object); | |
102 factory->vt->Release((IUnknown*)factory); | 102 factory->vt->Release((IUnknown*)factory); |
103 if(result || (!object)) throw FATAL("Class factory failure"); | 103 if (result || !object) |
104 | 104 throw FATAL("Class factory failure"); |
105 result=object->vt->QueryInterface(object, &IID_IBaseFilter, (void**)&m_pFilter); | 105 |
106 result = object->vt->QueryInterface(object, &IID_IBaseFilter, (void**)&m_pFilter); | |
106 object->vt->Release((IUnknown*)object); | 107 object->vt->Release((IUnknown*)object); |
107 if(result || (!m_pFilter)) throw FATAL("Object does not have IBaseFilter interface"); | 108 if (result || !m_pFilter) |
108 | 109 throw FATAL("Object does not have IBaseFilter interface"); |
109 IEnumPins* enum_pins=0; | 110 |
110 // enumerate pins | 111 IEnumPins* enum_pins = 0; |
111 result=m_pFilter->vt->EnumPins(m_pFilter, &enum_pins); | 112 // enumerate pins |
112 if(result || (!enum_pins)) throw FATAL("Could not enumerate pins"); | 113 result = m_pFilter->vt->EnumPins(m_pFilter, &enum_pins); |
114 if (result || !enum_pins) | |
115 throw FATAL("Could not enumerate pins"); | |
116 | |
113 IPin* array[256]; | 117 IPin* array[256]; |
114 ULONG fetched; | 118 ULONG fetched; |
115 enum_pins->vt->Reset(enum_pins); | 119 enum_pins->vt->Reset(enum_pins); |
116 result=enum_pins->vt->Next(enum_pins, (ULONG)256, (IPin**)array, &fetched); | 120 result = enum_pins->vt->Next(enum_pins, (ULONG)256, (IPin**)array, &fetched); |
117 Debug printf("Pins enumeration returned %ld pins, error is %x\n", fetched, (int)result); | 121 Debug printf("Pins enumeration returned %ld pins, error is %x\n", fetched, (int)result); |
118 | 122 |
119 for (unsigned i = 0; i < fetched; i++) | 123 for (unsigned i = 0; i < fetched; i++) |
120 { | 124 { |
121 int direction = -1; | 125 int direction = -1; |
138 throw FATAL("Output pin not found"); | 142 throw FATAL("Output pin not found"); |
139 | 143 |
140 result = m_pInputPin->vt->QueryInterface((IUnknown*)m_pInputPin, | 144 result = m_pInputPin->vt->QueryInterface((IUnknown*)m_pInputPin, |
141 &IID_IMemInputPin, | 145 &IID_IMemInputPin, |
142 (void**)&m_pImp); | 146 (void**)&m_pImp); |
143 if(result) | 147 if (result) |
144 throw FATAL("Error getting IMemInputPin interface"); | 148 throw FATAL("Error getting IMemInputPin interface"); |
145 m_pOurType=in_fmt; | 149 m_pOurType = in_fmt; |
146 m_pDestType=out_fmt; | 150 m_pDestType = out_fmt; |
147 result=m_pInputPin->vt->QueryAccept(m_pInputPin, m_pOurType); | 151 result = m_pInputPin->vt->QueryAccept(m_pInputPin, m_pOurType); |
148 if (result) | 152 if (result) |
149 throw FATAL("Source format is not accepted"); | 153 throw FATAL("Source format is not accepted"); |
150 | 154 |
151 m_pParentFilter=new CBaseFilter2; | 155 m_pParentFilter = new CBaseFilter2; |
152 m_pSrcFilter=new CBaseFilter(*m_pOurType, m_pParentFilter); | 156 m_pSrcFilter = new CBaseFilter(*m_pOurType, m_pParentFilter); |
153 m_pOurInput=m_pSrcFilter->GetPin(); | 157 m_pOurInput = m_pSrcFilter->GetPin(); |
154 m_pOurInput->vt->AddRef((IUnknown*)m_pOurInput); | 158 m_pOurInput->vt->AddRef((IUnknown*)m_pOurInput); |
155 | 159 |
156 result=m_pInputPin->vt->ReceiveConnection(m_pInputPin, m_pOurInput, | 160 result = m_pInputPin->vt->ReceiveConnection(m_pInputPin, |
157 m_pOurType); | 161 m_pOurInput, |
162 m_pOurType); | |
158 if (result) | 163 if (result) |
159 throw FATAL("Error connecting to input pin"); | 164 throw FATAL("Error connecting to input pin"); |
160 | 165 |
161 m_pOurOutput = new COutputPin(*m_pDestType); | 166 m_pOurOutput = new COutputPin(*m_pDestType); |
162 | 167 |
168 //extern void trapbug(); | |
169 //trapbug(); | |
163 result = m_pOutputPin->vt->ReceiveConnection(m_pOutputPin, | 170 result = m_pOutputPin->vt->ReceiveConnection(m_pOutputPin, |
164 m_pOurOutput, | 171 m_pOurOutput, |
165 m_pDestType); | 172 m_pDestType); |
166 if (result) | 173 if (result) |
174 { | |
175 //printf("Tracking ACELP %d 0%x\n", result); | |
167 throw FATAL("Error connecting to output pin"); | 176 throw FATAL("Error connecting to output pin"); |
168 cout << "Using DirectShow codec: " << dllname << endl; | 177 } |
178 | |
179 printf("Using DirectShow codec: %s\n", dllname); | |
169 m_iState = 1; | 180 m_iState = 1; |
170 } | 181 } |
171 catch(FatalError e) | 182 catch (FatalError e) |
172 { | 183 { |
173 e.PrintAll(); | 184 //e.PrintAll(); |
174 clean(); | 185 destroy(); |
175 throw; | 186 throw; |
176 } | 187 } |
177 } | 188 } |
178 | 189 |
179 void DS_Filter::Start() | 190 void DS_Filter::Start() |
180 { | 191 { |
181 if (m_iState != 1) | 192 if (m_iState != 1) |
182 return; | 193 return; |
183 | 194 |
184 m_pFilter->vt->Pause(m_pFilter); | |
185 | |
186 HRESULT hr=m_pFilter->vt->Run(m_pFilter, 0); | 195 HRESULT hr=m_pFilter->vt->Run(m_pFilter, 0); |
187 if (hr != 0) | 196 if (hr != 0) |
188 { | 197 { |
189 Debug cerr<<"WARNING: m_Filter->Run() failed, error code "<<hex<<hr<<dec<<endl; | 198 Debug printf("WARNING: m_Filter->Run() failed, error code %x\n", (int)hr); |
190 } | 199 } |
191 hr=m_pImp->vt->GetAllocator(m_pImp, &m_pAll); | 200 hr = m_pImp->vt->GetAllocator(m_pImp, &m_pAll); |
192 if (hr) | 201 if (hr) |
193 { | 202 { |
194 Debug cerr<<"Error getting IMemAllocator interface "<<hex<<hr<<dec<<endl; | 203 Debug printf("Error getting IMemAllocator interface %x\n", (int)hr); |
195 m_pImp->vt->Release((IUnknown*)m_pImp); | 204 m_pImp->vt->Release((IUnknown*)m_pImp); |
196 return; | 205 return; |
197 } | 206 } |
198 m_pImp->vt->NotifyAllocator(m_pImp, m_pAll, 0); | 207 m_pImp->vt->NotifyAllocator(m_pImp, m_pAll, 0); |
199 | |
200 m_iState = 2; | 208 m_iState = 2; |
201 } | 209 } |
202 | 210 |
203 void DS_Filter::Stop() | 211 void DS_Filter::Stop() |
204 { | 212 { |
205 if (m_iState == 2) | 213 if (m_iState == 2) |
206 { | 214 { |
207 m_pAll->vt->Release((IUnknown*)m_pAll); | 215 m_pAll->vt->Release((IUnknown*)m_pAll); |
208 m_pAll=0; | 216 m_pFilter->vt->Stop(m_pFilter); // causes weird crash ??? FIXME |
209 m_pFilter->vt->Stop(m_pFilter); | 217 m_pAll = 0; |
210 m_iState=1; | 218 m_iState = 1; |
211 } | 219 } |
212 } | 220 } |