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 "gst_private.h"
23 #include "wine/debug.h"
24 #include "wine/unicode.h"
27 #include "gst_guids.h"
29 static HINSTANCE winegstreamer_instance
;
32 WINE_DEFAULT_DEBUG_CHANNEL(gstreamer
);
34 static const WCHAR wGstreamer_Splitter
[] =
35 {'G','S','t','r','e','a','m','e','r',' ','s','p','l','i','t','t','e','r',' ','f','i','l','t','e','r',0};
36 static const WCHAR wave_parserW
[] =
37 {'W','a','v','e',' ','P','a','r','s','e','r',0};
38 static const WCHAR avi_splitterW
[] =
39 {'A','V','I',' ','S','p','l','i','t','t','e','r',0};
40 static const WCHAR mpeg_splitterW
[] =
41 {'M','P','E','G','-','I',' ','S','t','r','e','a','m',' ','S','p','l','i','t','t','e','r',0};
43 BOOL WINAPI
DllMain(HINSTANCE instance
, DWORD reason
, void *reserved
)
45 if (reason
== DLL_PROCESS_ATTACH
)
47 winegstreamer_instance
= instance
;
48 DisableThreadLibraryCalls(instance
);
53 HRESULT WINAPI
DllCanUnloadNow(void)
57 return object_locks
? S_FALSE
: S_OK
;
62 IClassFactory IClassFactory_iface
;
63 HRESULT (*create_instance
)(IUnknown
*outer
, IUnknown
**out
);
66 static inline struct class_factory
*impl_from_IClassFactory(IClassFactory
*iface
)
68 return CONTAINING_RECORD(iface
, struct class_factory
, IClassFactory_iface
);
71 static HRESULT WINAPI
class_factory_QueryInterface(IClassFactory
*iface
, REFIID iid
, void **out
)
73 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
75 if (IsEqualGUID(iid
, &IID_IUnknown
) || IsEqualGUID(iid
, &IID_IClassFactory
))
78 IClassFactory_AddRef(iface
);
83 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
87 static ULONG WINAPI
class_factory_AddRef(IClassFactory
*iface
)
92 static ULONG WINAPI
class_factory_Release(IClassFactory
*iface
)
97 static HRESULT WINAPI
class_factory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID iid
, void **out
)
99 struct class_factory
*factory
= impl_from_IClassFactory(iface
);
103 TRACE("iface %p, outer %p, iid %s, out %p.\n", iface
, outer
, debugstr_guid(iid
), out
);
105 if (outer
&& !IsEqualGUID(iid
, &IID_IUnknown
))
106 return E_NOINTERFACE
;
109 if (SUCCEEDED(hr
= factory
->create_instance(outer
, &unk
)))
111 hr
= IUnknown_QueryInterface(unk
, iid
, out
);
112 IUnknown_Release(unk
);
117 static HRESULT WINAPI
class_factory_LockServer(IClassFactory
*iface
, BOOL lock
)
119 TRACE("iface %p, lock %d.\n", iface
, lock
);
122 InterlockedIncrement(&object_locks
);
124 InterlockedDecrement(&object_locks
);
128 static const IClassFactoryVtbl class_factory_vtbl
=
130 class_factory_QueryInterface
,
131 class_factory_AddRef
,
132 class_factory_Release
,
133 class_factory_CreateInstance
,
134 class_factory_LockServer
,
137 static struct class_factory avi_splitter_cf
= {{&class_factory_vtbl
}, avi_splitter_create
};
138 static struct class_factory gstdemux_cf
= {{&class_factory_vtbl
}, gstdemux_create
};
139 static struct class_factory mpeg_splitter_cf
= {{&class_factory_vtbl
}, mpeg_splitter_create
};
140 static struct class_factory wave_parser_cf
= {{&class_factory_vtbl
}, wave_parser_create
};
142 HRESULT WINAPI
DllGetClassObject(REFCLSID clsid
, REFIID iid
, void **out
)
144 struct class_factory
*factory
;
147 TRACE("clsid %s, iid %s, out %p.\n", debugstr_guid(clsid
), debugstr_guid(iid
), out
);
149 if (!init_gstreamer())
150 return CLASS_E_CLASSNOTAVAILABLE
;
152 if (SUCCEEDED(hr
= mfplat_get_class_object(clsid
, iid
, out
)))
155 if (IsEqualGUID(clsid
, &CLSID_AviSplitter
))
156 factory
= &avi_splitter_cf
;
157 else if (IsEqualGUID(clsid
, &CLSID_Gstreamer_Splitter
))
158 factory
= &gstdemux_cf
;
159 else if (IsEqualGUID(clsid
, &CLSID_MPEG1Splitter
))
160 factory
= &mpeg_splitter_cf
;
161 else if (IsEqualGUID(clsid
, &CLSID_WAVEParser
))
162 factory
= &wave_parser_cf
;
165 FIXME("%s not implemented, returning CLASS_E_CLASSNOTAVAILABLE.\n", debugstr_guid(clsid
));
166 return CLASS_E_CLASSNOTAVAILABLE
;
169 return IClassFactory_QueryInterface(&factory
->IClassFactory_iface
, iid
, out
);
172 static BOOL CALLBACK
init_gstreamer_proc(INIT_ONCE
*once
, void *param
, void **ctx
)
174 BOOL
*status
= param
;
175 char argv0
[] = "wine";
176 char argv1
[] = "--gst-disable-registry-fork";
182 TRACE("Initializing...\n");
187 *status
= gst_init_check(&argc
, &argv
, &err
);
192 TRACE("Initialized, version %s. Built with %d.%d.%d.\n", gst_version_string(),
193 GST_VERSION_MAJOR
, GST_VERSION_MINOR
, GST_VERSION_MICRO
);
195 /* Unloading glib is a bad idea.. it installs atexit handlers,
196 * so never unload the dll after loading */
197 GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
| GET_MODULE_HANDLE_EX_FLAG_PIN
,
198 (LPCWSTR
)winegstreamer_instance
, &handle
);
200 ERR("Failed to pin module %p.\n", winegstreamer_instance
);
202 start_dispatch_thread();
206 ERR("Failed to initialize gstreamer: %s\n", debugstr_a(err
->message
));
213 BOOL
init_gstreamer(void)
215 static INIT_ONCE once
= INIT_ONCE_STATIC_INIT
;
218 InitOnceExecuteOnce(&once
, init_gstreamer_proc
, &status
, NULL
);
223 static const REGPINTYPES reg_audio_mt
= {&MEDIATYPE_Audio
, &GUID_NULL
};
224 static const REGPINTYPES reg_stream_mt
= {&MEDIATYPE_Stream
, &GUID_NULL
};
225 static const REGPINTYPES reg_video_mt
= {&MEDIATYPE_Video
, &GUID_NULL
};
227 static const REGPINTYPES reg_avi_splitter_sink_mt
= {&MEDIATYPE_Stream
, &MEDIASUBTYPE_Avi
};
229 static const REGFILTERPINS2 reg_avi_splitter_pins
[2] =
233 .lpMediaType
= ®_avi_splitter_sink_mt
,
236 .dwFlags
= REG_PINFLAG_B_OUTPUT
,
238 .lpMediaType
= ®_video_mt
,
242 static const REGFILTER2 reg_avi_splitter
=
245 .dwMerit
= MERIT_NORMAL
,
247 .u
.s2
.rgPins2
= reg_avi_splitter_pins
,
250 static const REGPINTYPES reg_mpeg_splitter_sink_mts
[4] =
252 {&MEDIATYPE_Stream
, &MEDIASUBTYPE_MPEG1Audio
},
253 {&MEDIATYPE_Stream
, &MEDIASUBTYPE_MPEG1Video
},
254 {&MEDIATYPE_Stream
, &MEDIASUBTYPE_MPEG1System
},
255 {&MEDIATYPE_Stream
, &MEDIASUBTYPE_MPEG1VideoCD
},
258 static const REGPINTYPES reg_mpeg_splitter_audio_mts
[2] =
260 {&MEDIATYPE_Audio
, &MEDIASUBTYPE_MPEG1Packet
},
261 {&MEDIATYPE_Audio
, &MEDIASUBTYPE_MPEG1AudioPayload
},
264 static const REGPINTYPES reg_mpeg_splitter_video_mts
[2] =
266 {&MEDIATYPE_Video
, &MEDIASUBTYPE_MPEG1Packet
},
267 {&MEDIATYPE_Video
, &MEDIASUBTYPE_MPEG1Payload
},
270 static const REGFILTERPINS2 reg_mpeg_splitter_pins
[3] =
274 .lpMediaType
= reg_mpeg_splitter_sink_mts
,
277 .dwFlags
= REG_PINFLAG_B_ZERO
| REG_PINFLAG_B_OUTPUT
,
279 .lpMediaType
= reg_mpeg_splitter_audio_mts
,
282 .dwFlags
= REG_PINFLAG_B_ZERO
| REG_PINFLAG_B_OUTPUT
,
284 .lpMediaType
= reg_mpeg_splitter_video_mts
,
288 static const REGFILTER2 reg_mpeg_splitter
=
291 .dwMerit
= MERIT_NORMAL
,
293 .u
.s2
.rgPins2
= reg_mpeg_splitter_pins
,
296 static const REGPINTYPES reg_wave_parser_sink_mts
[3] =
298 {&MEDIATYPE_Stream
, &MEDIASUBTYPE_WAVE
},
299 {&MEDIATYPE_Stream
, &MEDIASUBTYPE_AU
},
300 {&MEDIATYPE_Stream
, &MEDIASUBTYPE_AIFF
},
303 static const REGFILTERPINS2 reg_wave_parser_pins
[2] =
307 .lpMediaType
= reg_wave_parser_sink_mts
,
310 .dwFlags
= REG_PINFLAG_B_OUTPUT
,
312 .lpMediaType
= ®_audio_mt
,
316 static const REGFILTER2 reg_wave_parser
=
319 .dwMerit
= MERIT_UNLIKELY
,
321 .u
.s2
.rgPins2
= reg_wave_parser_pins
,
324 static const REGFILTERPINS2 reg_gstdemux_pins
[3] =
328 .lpMediaType
= ®_stream_mt
,
331 .dwFlags
= REG_PINFLAG_B_OUTPUT
,
333 .lpMediaType
= ®_audio_mt
,
336 .dwFlags
= REG_PINFLAG_B_OUTPUT
,
338 .lpMediaType
= ®_video_mt
,
342 static const REGFILTER2 reg_gstdemux
=
345 .dwMerit
= MERIT_PREFERRED
,
347 .u
.s2
.rgPins2
= reg_gstdemux_pins
,
350 HRESULT WINAPI
DllRegisterServer(void)
352 IFilterMapper2
*mapper
;
357 if (FAILED(hr
= __wine_register_resources(winegstreamer_instance
)))
360 if (FAILED(hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC_SERVER
,
361 &IID_IFilterMapper2
, (void **)&mapper
)))
364 IFilterMapper2_RegisterFilter(mapper
, &CLSID_AviSplitter
, avi_splitterW
, NULL
, NULL
, NULL
, ®_avi_splitter
);
365 IFilterMapper2_RegisterFilter(mapper
, &CLSID_Gstreamer_Splitter
,
366 wGstreamer_Splitter
, NULL
, NULL
, NULL
, ®_gstdemux
);
367 IFilterMapper2_RegisterFilter(mapper
, &CLSID_MPEG1Splitter
, mpeg_splitterW
, NULL
, NULL
, NULL
, ®_mpeg_splitter
);
368 IFilterMapper2_RegisterFilter(mapper
, &CLSID_WAVEParser
, wave_parserW
, NULL
, NULL
, NULL
, ®_wave_parser
);
370 IFilterMapper2_Release(mapper
);
374 HRESULT WINAPI
DllUnregisterServer(void)
376 IFilterMapper2
*mapper
;
381 if (FAILED(hr
= __wine_unregister_resources(winegstreamer_instance
)))
384 if (FAILED(hr
= CoCreateInstance(&CLSID_FilterMapper2
, NULL
, CLSCTX_INPROC_SERVER
,
385 &IID_IFilterMapper2
, (void **)&mapper
)))
388 IFilterMapper2_UnregisterFilter(mapper
, NULL
, NULL
, &CLSID_AviSplitter
);
389 IFilterMapper2_UnregisterFilter(mapper
, NULL
, NULL
, &CLSID_Gstreamer_Splitter
);
390 IFilterMapper2_UnregisterFilter(mapper
, NULL
, NULL
, &CLSID_MPEG1Splitter
);
391 IFilterMapper2_UnregisterFilter(mapper
, NULL
, NULL
, &CLSID_WAVEParser
);
393 IFilterMapper2_Release(mapper
);