winegstreamer: Add splitter output pin with video format.
[wine] / dlls / winegstreamer / main.c
1 /* Gstreamer Base Functions
2  *
3  * Copyright 2002 Lionel Ulmer
4  * Copyright 2010 Aric Stewart, CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include <stdarg.h>
23 #include <stdio.h>
24
25 #include <gst/app/gstappsink.h>
26 #include <gst/app/gstappsrc.h>
27 #include <gst/app/gstappbuffer.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winreg.h"
33 #include "winerror.h"
34 #include "advpub.h"
35 #include "wine/debug.h"
36
37 #include "wine/unicode.h"
38 #include "gst_private.h"
39 #include "initguid.h"
40 #include "gst_guids.h"
41
42 static HINSTANCE hInst = NULL;
43
44 WINE_DEFAULT_DEBUG_CHANNEL(gstreamer);
45
46 static const WCHAR wGstreamer_Splitter[] =
47 {'G','S','t','r','e','a','m','e','r',' ','s','p','l','i','t','t','e','r',' ','f','i','l','t','e','r',0};
48
49 static WCHAR wNull[] = {'\0'};
50
51 static const AMOVIESETUP_MEDIATYPE amfMTstream[] =
52 {   { &MEDIATYPE_Stream, &WINESUBTYPE_Gstreamer },
53     { &MEDIATYPE_Stream, &MEDIASUBTYPE_NULL },
54 };
55
56 static const AMOVIESETUP_MEDIATYPE amfMTaudio[] =
57 {   { &MEDIATYPE_Audio, &MEDIASUBTYPE_NULL } };
58
59 static const AMOVIESETUP_MEDIATYPE amfMTvideo[] =
60 {   { &MEDIATYPE_Video, &MEDIASUBTYPE_NULL } };
61
62 static const AMOVIESETUP_PIN amfSplitPin[] =
63 {   {   wNull,
64         FALSE, FALSE, FALSE, FALSE,
65         &GUID_NULL,
66         NULL,
67         2,
68         amfMTstream
69     },
70     {
71         wNull,
72         FALSE, TRUE, FALSE, FALSE,
73         &GUID_NULL,
74         NULL,
75         1,
76         amfMTaudio
77     },
78     {
79         wNull,
80         FALSE, TRUE, FALSE, FALSE,
81         &GUID_NULL,
82         NULL,
83         1,
84         amfMTvideo
85     }
86 };
87
88 static const AMOVIESETUP_FILTER amfSplitter =
89 {   &CLSID_Gstreamer_Splitter,
90     wGstreamer_Splitter,
91     MERIT_PREFERRED,
92     3,
93     amfSplitPin
94 };
95
96 FactoryTemplate const g_Templates[] = {
97     {
98         wGstreamer_Splitter,
99         &CLSID_Gstreamer_Splitter,
100         Gstreamer_Splitter_create,
101         NULL,
102         &amfSplitter,
103     },
104 };
105
106 const int g_cTemplates = sizeof(g_Templates) / sizeof (g_Templates[0]);
107
108 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
109 {
110     if (fdwReason == DLL_PROCESS_ATTACH)
111         hInst = hInstDLL;
112     return STRMBASE_DllMain(hInstDLL, fdwReason, lpv);
113 }
114
115 /* GStreamer common functions */
116
117 void dump_AM_MEDIA_TYPE(const AM_MEDIA_TYPE * pmt)
118 {
119     if (!pmt)
120         return;
121     TRACE("\t%s\n\t%s\n\t...\n\t%s\n", debugstr_guid(&pmt->majortype), debugstr_guid(&pmt->subtype), debugstr_guid(&pmt->formattype));
122 }
123
124 DWORD Gstreamer_init(void) {
125     static int inited;
126
127     if (!inited) {
128         char argv0[] = "wine";
129         char argv1[] = "--gst-disable-registry-fork";
130         char **argv = HeapAlloc(GetProcessHeap(), 0, sizeof(char *)*3);
131         int argc = 2;
132         GError *err = NULL;
133         argv[0] = argv0;
134         argv[1] = argv1;
135         argv[2] = NULL;
136         g_thread_impl_init();
137         inited = gst_init_check(&argc, &argv, &err);
138         HeapFree(GetProcessHeap(), 0, argv);
139         if (err) {
140             FIXME("Failed to initialize gstreamer: %s\n", err->message);
141             g_error_free(err);
142         }
143     }
144     return inited;
145 }
146
147 #define INF_SET_ID(id)            \
148     do                            \
149     {                             \
150         static CHAR name[] = #id; \
151                                   \
152         pse[i].pszName = name;    \
153         clsids[i++] = &id;        \
154     } while (0)
155
156 #define INF_SET_CLSID(clsid) INF_SET_ID(CLSID_ ## clsid)
157
158 static HRESULT register_server(BOOL do_register)
159 {
160     HRESULT hres;
161     HMODULE hAdvpack;
162     HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
163     STRTABLEA strtable;
164     STRENTRYA pse[3];
165     static CLSID const *clsids[3];
166     unsigned int i = 0;
167
168     static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
169
170     TRACE("(%x)\n", do_register);
171
172     INF_SET_CLSID(AsyncReader);
173     INF_SET_ID(MEDIATYPE_Stream);
174     INF_SET_ID(WINESUBTYPE_Gstreamer);
175
176     for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++) {
177         pse[i].pszValue = HeapAlloc(GetProcessHeap(),0,39);
178         sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
179                 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
180                 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
181                 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
182     }
183
184     strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
185     strtable.pse = pse;
186
187     hAdvpack = LoadLibraryW(wszAdvpack);
188     pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
189
190     hres = pRegInstall(hInst, do_register ? "RegisterDll" : "UnregisterDll", &strtable);
191
192     for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
193         HeapFree(GetProcessHeap(),0,pse[i].pszValue);
194
195     if(FAILED(hres)) {
196         ERR("RegInstall failed: %08x\n", hres);
197         return hres;
198     }
199
200     return hres;
201 }
202
203 #undef INF_SET_CLSID
204 #undef INF_SET_ID
205
206 /***********************************************************************
207  *      DllRegisterServer
208  */
209 HRESULT WINAPI DllRegisterServer(void)
210 {
211     HRESULT hr;
212
213     TRACE("\n");
214
215     hr = AMovieDllRegisterServer2(TRUE);
216     if (SUCCEEDED(hr))
217         hr = register_server(TRUE);
218     return hr;
219 }
220
221 /***********************************************************************
222  *      DllUnregisterServer
223  */
224 HRESULT WINAPI DllUnregisterServer(void)
225 {
226     HRESULT hr;
227
228     TRACE("\n");
229
230     hr = AMovieDllRegisterServer2(FALSE);
231     if (SUCCEEDED(hr))
232         hr = register_server(FALSE);
233     return hr;
234 }