webservices: Implement WsGetPrefixFromNamespace.
[wine.git] / dlls / winegstreamer / main.c
blob7b9cd31959690dabb96ce60d62d36172973a4c8f
1 /* GStreamer Base Functions
3 * Copyright 2002 Lionel Ulmer
4 * Copyright 2010 Aric Stewart, CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
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 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include <stdarg.h>
23 #include <stdio.h>
25 #include <gst/gst.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "winerror.h"
32 #include "advpub.h"
33 #include "wine/debug.h"
35 #include "wine/unicode.h"
36 #include "gst_private.h"
37 #include "initguid.h"
38 #include "gst_guids.h"
40 static HINSTANCE hInst = NULL;
42 WINE_DEFAULT_DEBUG_CHANNEL(gstreamer);
44 static const WCHAR wGstreamer_Splitter[] =
45 {'G','S','t','r','e','a','m','e','r',' ','s','p','l','i','t','t','e','r',' ','f','i','l','t','e','r',0};
46 static const WCHAR wGstreamer_YUV[] =
47 {'G','S','t','r','e','a','m','e','r',' ','Y','U','V',' ','f','i','l','t','e','r',0};
48 static const WCHAR wGstreamer_Mp3[] =
49 {'G','S','t','r','e','a','m','e','r',' ','M','p','3',' ','f','i','l','t','e','r',0};
50 static const WCHAR wGstreamer_AudioConvert[] =
51 {'G','S','t','r','e','a','m','e','r',' ','A','u','d','i','o','C','o','n','v','e','r','t',' ','f','i','l','t','e','r',0};
53 static WCHAR wNull[] = {'\0'};
55 static const AMOVIESETUP_MEDIATYPE amfMTstream[] =
56 { { &MEDIATYPE_Stream, &WINESUBTYPE_Gstreamer },
57 { &MEDIATYPE_Stream, &MEDIASUBTYPE_NULL },
60 static const AMOVIESETUP_MEDIATYPE amfMTaudio[] =
61 { { &MEDIATYPE_Audio, &MEDIASUBTYPE_NULL } };
63 static const AMOVIESETUP_MEDIATYPE amfMTvideo[] =
64 { { &MEDIATYPE_Video, &MEDIASUBTYPE_NULL } };
66 static const AMOVIESETUP_PIN amfSplitPin[] =
67 { { wNull,
68 FALSE, FALSE, FALSE, FALSE,
69 &GUID_NULL,
70 NULL,
72 amfMTstream
75 wNull,
76 FALSE, TRUE, FALSE, FALSE,
77 &GUID_NULL,
78 NULL,
80 amfMTaudio
83 wNull,
84 FALSE, TRUE, FALSE, FALSE,
85 &GUID_NULL,
86 NULL,
88 amfMTvideo
92 static const AMOVIESETUP_FILTER amfSplitter =
93 { &CLSID_Gstreamer_Splitter,
94 wGstreamer_Splitter,
95 MERIT_PREFERRED,
97 amfSplitPin
100 static const AMOVIESETUP_PIN amfYUVPin[] =
101 { { wNull,
102 FALSE, FALSE, FALSE, FALSE,
103 &GUID_NULL,
104 NULL,
106 amfMTvideo
109 wNull,
110 FALSE, TRUE, FALSE, FALSE,
111 &GUID_NULL,
112 NULL,
114 amfMTvideo
118 static const AMOVIESETUP_FILTER amfYUV =
119 { &CLSID_Gstreamer_YUV,
120 wGstreamer_YUV,
121 MERIT_UNLIKELY,
123 amfYUVPin
126 AMOVIESETUP_PIN amfMp3Pin[] =
127 { { wNull,
128 FALSE, FALSE, FALSE, FALSE,
129 &GUID_NULL,
130 NULL,
132 amfMTaudio
135 wNull,
136 FALSE, TRUE, FALSE, FALSE,
137 &GUID_NULL,
138 NULL,
140 amfMTaudio
144 AMOVIESETUP_FILTER const amfMp3 =
145 { &CLSID_Gstreamer_Mp3,
146 wGstreamer_Mp3,
147 MERIT_NORMAL,
149 amfMp3Pin
152 AMOVIESETUP_PIN amfAudioConvertPin[] =
153 { { wNull,
154 FALSE, FALSE, FALSE, FALSE,
155 &GUID_NULL,
156 NULL,
158 amfMTaudio
161 wNull,
162 FALSE, TRUE, FALSE, FALSE,
163 &GUID_NULL,
164 NULL,
166 amfMTaudio
170 AMOVIESETUP_FILTER const amfAudioConvert =
171 { &CLSID_Gstreamer_AudioConvert,
172 wGstreamer_AudioConvert,
173 MERIT_UNLIKELY,
175 amfAudioConvertPin
178 FactoryTemplate const g_Templates[] = {
180 wGstreamer_Splitter,
181 &CLSID_Gstreamer_Splitter,
182 Gstreamer_Splitter_create,
183 NULL,
184 &amfSplitter,
187 wGstreamer_YUV,
188 &CLSID_Gstreamer_YUV,
189 Gstreamer_YUV_create,
190 NULL,
191 &amfYUV,
194 wGstreamer_Mp3,
195 &CLSID_Gstreamer_Mp3,
196 Gstreamer_Mp3_create,
197 NULL,
198 &amfMp3,
201 wGstreamer_AudioConvert,
202 &CLSID_Gstreamer_AudioConvert,
203 Gstreamer_AudioConvert_create,
204 NULL,
205 &amfAudioConvert,
209 const int g_cTemplates = sizeof(g_Templates) / sizeof (g_Templates[0]);
211 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
213 if (fdwReason == DLL_PROCESS_ATTACH)
214 hInst = hInstDLL;
215 return STRMBASE_DllMain(hInstDLL, fdwReason, lpv);
218 /***********************************************************************
219 * DllCanUnloadNow
221 HRESULT WINAPI DllCanUnloadNow(void)
223 return STRMBASE_DllCanUnloadNow();
226 /***********************************************************************
227 * DllGetClassObject
229 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
231 return STRMBASE_DllGetClassObject( rclsid, riid, ppv );
234 /* GStreamer common functions */
236 void dump_AM_MEDIA_TYPE(const AM_MEDIA_TYPE * pmt)
238 if (!pmt)
239 return;
240 TRACE("\t%s\n\t%s\n\t...\n\t%s\n", debugstr_guid(&pmt->majortype), debugstr_guid(&pmt->subtype), debugstr_guid(&pmt->formattype));
243 DWORD Gstreamer_init(void)
245 static int inited;
247 if (!inited) {
248 char argv0[] = "wine";
249 char argv1[] = "--gst-disable-registry-fork";
250 char **argv = HeapAlloc(GetProcessHeap(), 0, sizeof(char *)*3);
251 int argc = 2;
252 GError *err = NULL;
254 TRACE("initializing\n");
256 argv[0] = argv0;
257 argv[1] = argv1;
258 argv[2] = NULL;
259 inited = gst_init_check(&argc, &argv, &err);
260 HeapFree(GetProcessHeap(), 0, argv);
261 if (err) {
262 FIXME("Failed to initialize gstreamer: %s\n", err->message);
263 g_error_free(err);
265 if (inited) {
266 HINSTANCE newhandle;
267 /* Unloading glib is a bad idea.. it installs atexit handlers,
268 * so never unload the dll after loading */
269 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
270 (LPCWSTR)hInst, &newhandle);
271 if (!newhandle)
272 ERR("Could not pin module %p\n", hInst);
274 start_dispatch_thread();
277 return inited;
280 #define INF_SET_ID(id) \
281 do \
283 static CHAR name[] = #id; \
285 pse[i].pszName = name; \
286 clsids[i++] = &id; \
287 } while (0)
289 #define INF_SET_CLSID(clsid) INF_SET_ID(CLSID_ ## clsid)
291 static HRESULT register_server(BOOL do_register)
293 HRESULT hres;
294 HMODULE hAdvpack;
295 HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
296 STRTABLEA strtable;
297 STRENTRYA pse[3];
298 static CLSID const *clsids[3];
299 unsigned int i = 0;
301 static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
303 TRACE("(%x)\n", do_register);
305 INF_SET_CLSID(AsyncReader);
306 INF_SET_ID(MEDIATYPE_Stream);
307 INF_SET_ID(WINESUBTYPE_Gstreamer);
309 for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++) {
310 pse[i].pszValue = HeapAlloc(GetProcessHeap(),0,39);
311 sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
312 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
313 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
314 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
317 strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
318 strtable.pse = pse;
320 hAdvpack = LoadLibraryW(wszAdvpack);
321 pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
323 hres = pRegInstall(hInst, do_register ? "RegisterDll" : "UnregisterDll", &strtable);
325 for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
326 HeapFree(GetProcessHeap(),0,pse[i].pszValue);
328 if(FAILED(hres)) {
329 ERR("RegInstall failed: %08x\n", hres);
330 return hres;
333 return hres;
336 #undef INF_SET_CLSID
337 #undef INF_SET_ID
339 /***********************************************************************
340 * DllRegisterServer
342 HRESULT WINAPI DllRegisterServer(void)
344 HRESULT hr;
346 TRACE("\n");
348 hr = AMovieDllRegisterServer2(TRUE);
349 if (SUCCEEDED(hr))
350 hr = register_server(TRUE);
351 return hr;
354 /***********************************************************************
355 * DllUnregisterServer
357 HRESULT WINAPI DllUnregisterServer(void)
359 HRESULT hr;
361 TRACE("\n");
363 hr = AMovieDllRegisterServer2(FALSE);
364 if (SUCCEEDED(hr))
365 hr = register_server(FALSE);
366 return hr;