gdiplus/tests: Fix copy/paste error in format tests.
[wine.git] / dlls / winegstreamer / main.c
blob2bb69f403face59e7ebed6e6724772465eb311c9
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_YUV2RGB[] =
47 {'G','S','t','r','e','a','m','e','r',' ','Y','U','V',' ','t','o',' ','R','G','B',' ','f','i','l','t','e','r',0};
48 static const WCHAR wGstreamer_YUV2ARGB[] =
49 {'G','S','t','r','e','a','m','e','r',' ','Y','U','V',' ','t','o',' ','A','R','G','B',' ','f','i','l','t','e','r',0};
50 static const WCHAR wGstreamer_Mp3[] =
51 {'G','S','t','r','e','a','m','e','r',' ','M','p','3',' ','f','i','l','t','e','r',0};
52 static const WCHAR wGstreamer_AudioConvert[] =
53 {'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};
55 static WCHAR wNull[] = {'\0'};
57 static const AMOVIESETUP_MEDIATYPE amfMTstream[] =
58 { { &MEDIATYPE_Stream, &WINESUBTYPE_Gstreamer },
59 { &MEDIATYPE_Stream, &MEDIASUBTYPE_NULL },
62 static const AMOVIESETUP_MEDIATYPE amfMTaudio[] =
63 { { &MEDIATYPE_Audio, &MEDIASUBTYPE_NULL } };
65 static const AMOVIESETUP_MEDIATYPE amfMTvideo[] =
66 { { &MEDIATYPE_Video, &MEDIASUBTYPE_NULL } };
68 static const AMOVIESETUP_PIN amfSplitPin[] =
69 { { wNull,
70 FALSE, FALSE, FALSE, FALSE,
71 &GUID_NULL,
72 NULL,
74 amfMTstream
77 wNull,
78 FALSE, TRUE, FALSE, FALSE,
79 &GUID_NULL,
80 NULL,
82 amfMTaudio
85 wNull,
86 FALSE, TRUE, FALSE, FALSE,
87 &GUID_NULL,
88 NULL,
90 amfMTvideo
94 static const AMOVIESETUP_FILTER amfSplitter =
95 { &CLSID_Gstreamer_Splitter,
96 wGstreamer_Splitter,
97 MERIT_PREFERRED,
99 amfSplitPin
102 static const AMOVIESETUP_PIN amfYUVPin[] =
103 { { wNull,
104 FALSE, FALSE, FALSE, FALSE,
105 &GUID_NULL,
106 NULL,
108 amfMTvideo
111 wNull,
112 FALSE, TRUE, FALSE, FALSE,
113 &GUID_NULL,
114 NULL,
116 amfMTvideo
120 static const AMOVIESETUP_FILTER amfYUV2RGB =
121 { &CLSID_Gstreamer_YUV2RGB,
122 wGstreamer_YUV2RGB,
123 MERIT_UNLIKELY,
125 amfYUVPin
128 static const AMOVIESETUP_FILTER amfYUV2ARGB =
129 { &CLSID_Gstreamer_YUV2ARGB,
130 wGstreamer_YUV2ARGB,
131 MERIT_UNLIKELY,
133 amfYUVPin
136 AMOVIESETUP_PIN amfMp3Pin[] =
137 { { wNull,
138 FALSE, FALSE, FALSE, FALSE,
139 &GUID_NULL,
140 NULL,
142 amfMTaudio
145 wNull,
146 FALSE, TRUE, FALSE, FALSE,
147 &GUID_NULL,
148 NULL,
150 amfMTaudio
154 AMOVIESETUP_FILTER const amfMp3 =
155 { &CLSID_Gstreamer_Mp3,
156 wGstreamer_Mp3,
157 MERIT_NORMAL,
159 amfMp3Pin
162 AMOVIESETUP_PIN amfAudioConvertPin[] =
163 { { wNull,
164 FALSE, FALSE, FALSE, FALSE,
165 &GUID_NULL,
166 NULL,
168 amfMTaudio
171 wNull,
172 FALSE, TRUE, FALSE, FALSE,
173 &GUID_NULL,
174 NULL,
176 amfMTaudio
180 AMOVIESETUP_FILTER const amfAudioConvert =
181 { &CLSID_Gstreamer_AudioConvert,
182 wGstreamer_AudioConvert,
183 MERIT_UNLIKELY,
185 amfAudioConvertPin
188 FactoryTemplate const g_Templates[] = {
190 wGstreamer_Splitter,
191 &CLSID_Gstreamer_Splitter,
192 Gstreamer_Splitter_create,
193 NULL,
194 &amfSplitter,
197 wGstreamer_YUV2RGB,
198 &CLSID_Gstreamer_YUV2RGB,
199 Gstreamer_YUV2RGB_create,
200 NULL,
201 &amfYUV2RGB,
204 wGstreamer_YUV2ARGB,
205 &CLSID_Gstreamer_YUV2ARGB,
206 Gstreamer_YUV2ARGB_create,
207 NULL,
208 &amfYUV2ARGB,
211 wGstreamer_Mp3,
212 &CLSID_Gstreamer_Mp3,
213 Gstreamer_Mp3_create,
214 NULL,
215 &amfMp3,
218 wGstreamer_AudioConvert,
219 &CLSID_Gstreamer_AudioConvert,
220 Gstreamer_AudioConvert_create,
221 NULL,
222 &amfAudioConvert,
226 const int g_cTemplates = sizeof(g_Templates) / sizeof (g_Templates[0]);
228 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
230 if (fdwReason == DLL_PROCESS_ATTACH)
231 hInst = hInstDLL;
232 return STRMBASE_DllMain(hInstDLL, fdwReason, lpv);
235 /***********************************************************************
236 * DllCanUnloadNow
238 HRESULT WINAPI DllCanUnloadNow(void)
240 return STRMBASE_DllCanUnloadNow();
243 /***********************************************************************
244 * DllGetClassObject
246 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
248 return STRMBASE_DllGetClassObject( rclsid, riid, ppv );
251 /* GStreamer common functions */
253 void dump_AM_MEDIA_TYPE(const AM_MEDIA_TYPE * pmt)
255 if (!pmt)
256 return;
257 TRACE("\t%s\n\t%s\n\t...\n\t%s\n", debugstr_guid(&pmt->majortype), debugstr_guid(&pmt->subtype), debugstr_guid(&pmt->formattype));
260 DWORD Gstreamer_init(void)
262 static int inited;
264 if (!inited) {
265 char argv0[] = "wine";
266 char argv1[] = "--gst-disable-registry-fork";
267 char **argv = HeapAlloc(GetProcessHeap(), 0, sizeof(char *)*3);
268 int argc = 2;
269 GError *err = NULL;
271 TRACE("initializing\n");
273 argv[0] = argv0;
274 argv[1] = argv1;
275 argv[2] = NULL;
276 inited = gst_init_check(&argc, &argv, &err);
277 HeapFree(GetProcessHeap(), 0, argv);
278 if (err) {
279 FIXME("Failed to initialize gstreamer: %s\n", err->message);
280 g_error_free(err);
282 if (inited) {
283 HINSTANCE newhandle;
284 /* Unloading glib is a bad idea.. it installs atexit handlers,
285 * so never unload the dll after loading */
286 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
287 (LPCWSTR)hInst, &newhandle);
288 if (!newhandle)
289 ERR("Could not pin module %p\n", hInst);
291 start_dispatch_thread();
294 return inited;
297 #define INF_SET_ID(id) \
298 do \
300 static CHAR name[] = #id; \
302 pse[i].pszName = name; \
303 clsids[i++] = &id; \
304 } while (0)
306 #define INF_SET_CLSID(clsid) INF_SET_ID(CLSID_ ## clsid)
308 static HRESULT register_server(BOOL do_register)
310 HRESULT hres;
311 HMODULE hAdvpack;
312 HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
313 STRTABLEA strtable;
314 STRENTRYA pse[3];
315 static CLSID const *clsids[3];
316 unsigned int i = 0;
318 static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
320 TRACE("(%x)\n", do_register);
322 INF_SET_CLSID(AsyncReader);
323 INF_SET_ID(MEDIATYPE_Stream);
324 INF_SET_ID(WINESUBTYPE_Gstreamer);
326 for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++) {
327 pse[i].pszValue = HeapAlloc(GetProcessHeap(),0,39);
328 sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
329 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
330 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
331 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
334 strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
335 strtable.pse = pse;
337 hAdvpack = LoadLibraryW(wszAdvpack);
338 pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
340 hres = pRegInstall(hInst, do_register ? "RegisterDll" : "UnregisterDll", &strtable);
342 for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
343 HeapFree(GetProcessHeap(),0,pse[i].pszValue);
345 if(FAILED(hres)) {
346 ERR("RegInstall failed: %08x\n", hres);
347 return hres;
350 return hres;
353 #undef INF_SET_CLSID
354 #undef INF_SET_ID
356 /***********************************************************************
357 * DllRegisterServer
359 HRESULT WINAPI DllRegisterServer(void)
361 HRESULT hr;
363 TRACE("\n");
365 hr = AMovieDllRegisterServer2(TRUE);
366 if (SUCCEEDED(hr))
367 hr = register_server(TRUE);
368 return hr;
371 /***********************************************************************
372 * DllUnregisterServer
374 HRESULT WINAPI DllUnregisterServer(void)
376 HRESULT hr;
378 TRACE("\n");
380 hr = AMovieDllRegisterServer2(FALSE);
381 if (SUCCEEDED(hr))
382 hr = register_server(FALSE);
383 return hr;