winegstreamer: Use init-once API to initialize library.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2019-03-26 08:57:33 +03:00 committed by Alexandre Julliard
parent c46bdc9473
commit f5908390a7
4 changed files with 45 additions and 37 deletions

View File

@ -43,7 +43,7 @@ IUnknown * CALLBACK Gstreamer_YUV2RGB_create(IUnknown *pUnkOuter, HRESULT *phr);
IUnknown * CALLBACK Gstreamer_YUV2ARGB_create(IUnknown *pUnkOuter, HRESULT *phr);
IUnknown * CALLBACK Gstreamer_Splitter_create(IUnknown *pUnkOuter, HRESULT *phr);
DWORD Gstreamer_init(void);
BOOL init_gstreamer(void) DECLSPEC_HIDDEN;
GstFlowReturn got_data(GstPad *pad, GstObject *parent, GstBuffer *buf) DECLSPEC_HIDDEN;
GstFlowReturn request_buffer(GstPad *pad, guint64 ofs, guint size, GstCaps *caps, GstBuffer **buf) DECLSPEC_HIDDEN;

View File

@ -1230,7 +1230,7 @@ IUnknown * CALLBACK Gstreamer_Splitter_create(IUnknown *pUnkOuter, HRESULT *phr)
TRACE("%p %p\n", pUnkOuter, phr);
if (!Gstreamer_init())
if (!init_gstreamer())
{
*phr = E_FAIL;
return NULL;

View File

@ -626,7 +626,7 @@ IUnknown * CALLBACK Gstreamer_Mp3_create(IUnknown *punkouter, HRESULT *phr)
TRACE("%p %p\n", punkouter, phr);
if (!Gstreamer_init())
if (!init_gstreamer())
{
*phr = E_FAIL;
return NULL;
@ -769,7 +769,7 @@ IUnknown * CALLBACK Gstreamer_YUV2RGB_create(IUnknown *punkouter, HRESULT *phr)
TRACE("%p %p\n", punkouter, phr);
if (!Gstreamer_init())
if (!init_gstreamer())
{
*phr = E_FAIL;
return NULL;
@ -871,7 +871,7 @@ IUnknown * CALLBACK Gstreamer_YUV2ARGB_create(IUnknown *punkouter, HRESULT *phr)
TRACE("%p %p\n", punkouter, phr);
if (!Gstreamer_init())
if (!init_gstreamer())
{
*phr = E_FAIL;
return NULL;
@ -1004,7 +1004,7 @@ IUnknown * CALLBACK Gstreamer_AudioConvert_create(IUnknown *punkouter, HRESULT *
TRACE("%p %p\n", punkouter, phr);
if (!Gstreamer_init())
if (!init_gstreamer())
{
*phr = E_FAIL;
return NULL;

View File

@ -257,41 +257,49 @@ void dump_AM_MEDIA_TYPE(const AM_MEDIA_TYPE * pmt)
TRACE("\t%s\n\t%s\n\t...\n\t%s\n", debugstr_guid(&pmt->majortype), debugstr_guid(&pmt->subtype), debugstr_guid(&pmt->formattype));
}
DWORD Gstreamer_init(void)
static BOOL CALLBACK init_gstreamer_proc(INIT_ONCE *once, void *param, void **ctx)
{
static int inited;
BOOL *status = param;
char argv0[] = "wine";
char argv1[] = "--gst-disable-registry-fork";
char **argv = HeapAlloc(GetProcessHeap(), 0, sizeof(char *)*3);
int argc = 2;
GError *err = NULL;
if (!inited) {
char argv0[] = "wine";
char argv1[] = "--gst-disable-registry-fork";
char **argv = HeapAlloc(GetProcessHeap(), 0, sizeof(char *)*3);
int argc = 2;
GError *err = NULL;
TRACE("initializing\n");
TRACE("initializing\n");
argv[0] = argv0;
argv[1] = argv1;
argv[2] = NULL;
inited = gst_init_check(&argc, &argv, &err);
HeapFree(GetProcessHeap(), 0, argv);
if (err) {
ERR("Failed to initialize gstreamer: %s\n", err->message);
g_error_free(err);
}
if (inited) {
HINSTANCE newhandle;
/* Unloading glib is a bad idea.. it installs atexit handlers,
* so never unload the dll after loading */
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
(LPCWSTR)hInst, &newhandle);
if (!newhandle)
ERR("Could not pin module %p\n", hInst);
start_dispatch_thread();
}
argv[0] = argv0;
argv[1] = argv1;
argv[2] = NULL;
*status = gst_init_check(&argc, &argv, &err);
HeapFree(GetProcessHeap(), 0, argv);
if (err) {
ERR("Failed to initialize gstreamer: %s\n", err->message);
g_error_free(err);
}
return inited;
if (*status) {
HINSTANCE newhandle;
/* Unloading glib is a bad idea.. it installs atexit handlers,
* so never unload the dll after loading */
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
(LPCWSTR)hInst, &newhandle);
if (!newhandle)
ERR("Could not pin module %p\n", hInst);
start_dispatch_thread();
}
return TRUE;
}
BOOL init_gstreamer(void)
{
static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
static BOOL status;
InitOnceExecuteOnce(&once, init_gstreamer_proc, &status, NULL);
return status;
}
#define INF_SET_ID(id) \