1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <dlfcn.h>
#include "wrappedlibs.h"
#include "debug.h"
#include "wrapper.h"
#include "bridge.h"
#include "librarian/library_private.h"
#include "x64emu.h"
#include "emu/x64emu_private.h"
#include "callback.h"
#include "librarian.h"
#include "box64context.h"
#include "emu/x64emu_private.h"
#include "myalign.h"
#include "gtkclass.h"
#include "fileutils.h"
const char* gstreamerName = "libgstreamer-1.0.so.0";
#define LIBNAME gstreamer
typedef void* (*pFppA_t)(void*, void*, va_list);
typedef void* (*pFv_t)();
typedef size_t (*LFv_t)();
typedef void* (*pFp_t)(void*);
typedef void (*vFpp_t)(void*, void*);
typedef int (*iFpp_t)(void*, void*);
#define ADDED_FUNCTIONS() \
GO(gst_object_get_type, LFv_t) \
GO(gst_allocator_get_type, LFv_t) \
GO(gst_task_pool_get_type, LFv_t) \
GO(gst_structure_new_valist, pFppA_t) \
GO(gst_structure_new_empty, pFp_t) \
GO(gst_caps_new_empty, pFv_t) \
GO(gst_caps_replace, iFpp_t) \
GO(gst_caps_append_structure, vFpp_t) \
GO(gst_bin_add, iFpp_t) \
GO(gst_element_link, iFpp_t) \
#include "generated/wrappedgstreamertypes.h"
#include "wrappercallback.h"
#define SUPER() \
GO(0) \
GO(1) \
GO(2) \
GO(3) \
// GDestroyFunc ...
#define GO(A) \
static uintptr_t my_destroyfunc_fct_##A = 0; \
static int my_destroyfunc_##A(void* a, void* b) \
{ \
return RunFunctionFmt(my_destroyfunc_fct_##A, "pp", a, b); \
}
SUPER()
#undef GO
static void* findDestroyFct(void* fct)
{
if(!fct) return fct;
void* p;
if((p = GetNativeFnc((uintptr_t)fct))) return p;
if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct);
#define GO(A) if(my_destroyfunc_fct_##A == (uintptr_t)fct) return my_destroyfunc_##A;
SUPER()
#undef GO
#define GO(A) if(my_destroyfunc_fct_##A == 0) {my_destroyfunc_fct_##A = (uintptr_t)fct; return my_destroyfunc_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for gstreamer GDestroyNotify callback\n");
return NULL;
}
//GstPadActivateModeFunction
#define GO(A) \
static uintptr_t my_GstPadActivateModeFunction_fct_##A = 0; \
static int my_GstPadActivateModeFunction_##A(void* a, void* b, int c, int d) \
{ \
return (int)RunFunctionFmt(my_GstPadActivateModeFunction_fct_##A, "ppii", a, b, c, d); \
}
SUPER()
#undef GO
static void* findGstPadActivateModeFunctionFct(void* fct)
{
if(!fct) return fct;
void* p;
if((p = GetNativeFnc((uintptr_t)fct))) return p;
#define GO(A) if(my_GstPadActivateModeFunction_fct_##A == (uintptr_t)fct) return my_GstPadActivateModeFunction_##A;
SUPER()
#undef GO
#define GO(A) if(my_GstPadActivateModeFunction_fct_##A == 0) {my_GstPadActivateModeFunction_fct_##A = (uintptr_t)fct; return my_GstPadActivateModeFunction_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for gstreamer GstPadActivateModeFunction callback\n");
return NULL;
}
//GstPadQueryFunction
#define GO(A) \
static uintptr_t my_GstPadQueryFunction_fct_##A = 0; \
static int my_GstPadQueryFunction_##A(void* a, void* b, void* c) \
{ \
return (int)RunFunctionFmt(my_GstPadQueryFunction_fct_##A, "ppp", a, b, c); \
}
SUPER()
#undef GO
static void* findGstPadQueryFunctionFct(void* fct)
{
if(!fct) return fct;
void* p;
if((p = GetNativeFnc((uintptr_t)fct))) return p;
#define GO(A) if(my_GstPadQueryFunction_fct_##A == (uintptr_t)fct) return my_GstPadQueryFunction_##A;
SUPER()
#undef GO
#define GO(A) if(my_GstPadQueryFunction_fct_##A == 0) {my_GstPadQueryFunction_fct_##A = (uintptr_t)fct; return my_GstPadQueryFunction_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for gstreamer GstPadQueryFunction callback\n");
return NULL;
}
//GstPadGetRangeFunction
#define GO(A) \
static uintptr_t my_GstPadGetRangeFunction_fct_##A = 0; \
static int my_GstPadGetRangeFunction_##A(void* a, void* b, uint64_t c, uint32_t d, void* e) \
{ \
return (int)RunFunctionFmt(my_GstPadGetRangeFunction_fct_##A, "ppUup", a, b, c, d, e); \
}
SUPER()
#undef GO
static void* findGstPadGetRangeFunctionFct(void* fct)
{
if(!fct) return fct;
void* p;
if((p = GetNativeFnc((uintptr_t)fct))) return p;
#define GO(A) if(my_GstPadGetRangeFunction_fct_##A == (uintptr_t)fct) return my_GstPadGetRangeFunction_##A;
SUPER()
#undef GO
#define GO(A) if(my_GstPadGetRangeFunction_fct_##A == 0) {my_GstPadGetRangeFunction_fct_##A = (uintptr_t)fct; return my_GstPadGetRangeFunction_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for gstreamer GstPadGetRangeFunction callback\n");
return NULL;
}
//GstPadChainFunction
#define GO(A) \
static uintptr_t my_GstPadChainFunction_fct_##A = 0; \
static int my_GstPadChainFunction_##A(void* a, void* b, void* c) \
{ \
return (int)RunFunctionFmt(my_GstPadChainFunction_fct_##A, "ppp", a, b, c); \
}
SUPER()
#undef GO
static void* findGstPadChainFunctionFct(void* fct)
{
if(!fct) return fct;
void* p;
if((p = GetNativeFnc((uintptr_t)fct))) return p;
#define GO(A) if(my_GstPadChainFunction_fct_##A == (uintptr_t)fct) return my_GstPadChainFunction_##A;
SUPER()
#undef GO
#define GO(A) if(my_GstPadChainFunction_fct_##A == 0) {my_GstPadChainFunction_fct_##A = (uintptr_t)fct; return my_GstPadChainFunction_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for gstreamer GstPadChainFunction callback\n");
return NULL;
}
//GstPadEventFunction
#define GO(A) \
static uintptr_t my_GstPadEventFunction_fct_##A = 0; \
static int my_GstPadEventFunction_##A(void* a, void* b, void* c) \
{ \
return (int)RunFunctionFmt(my_GstPadEventFunction_fct_##A, "ppp", a, b, c); \
}
SUPER()
#undef GO
static void* findGstPadEventFunctionFct(void* fct)
{
if(!fct) return fct;
#define GO(A) if(my_GstPadEventFunction_fct_##A == (uintptr_t)fct) return my_GstPadEventFunction_##A;
SUPER()
#undef GO
#define GO(A) if(my_GstPadEventFunction_fct_##A == 0) {my_GstPadEventFunction_fct_##A = (uintptr_t)fct; return my_GstPadEventFunction_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for gstreamer GstPadEventFunction callback\n");
return NULL;
}
//GstBusSyncHandler
#define GO(A) \
static uintptr_t my_GstBusSyncHandler_fct_##A = 0; \
static int my_GstBusSyncHandler_##A(void* a, void* b, void* c) \
{ \
return (int)RunFunctionFmt(my_GstBusSyncHandler_fct_##A, "ppp", a, b, c); \
}
SUPER()
#undef GO
static void* findGstBusSyncHandlerFct(void* fct)
{
if(!fct) return fct;
#define GO(A) if(my_GstBusSyncHandler_fct_##A == (uintptr_t)fct) return my_GstBusSyncHandler_##A;
SUPER()
#undef GO
#define GO(A) if(my_GstBusSyncHandler_fct_##A == 0) {my_GstBusSyncHandler_fct_##A = (uintptr_t)fct; return my_GstBusSyncHandler_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for gstreamer GstBusSyncHandler callback\n");
return NULL;
}
//GstBusFunc
#define GO(A) \
static uintptr_t my_GstBusFunc_fct_##A = 0; \
static int my_GstBusFunc_##A(void* a, void* b, void* c) \
{ \
return (int)RunFunctionFmt(my_GstBusFunc_fct_##A, "ppp", a, b, c); \
}
SUPER()
#undef GO
static void* findGstBusFuncFct(void* fct)
{
if(!fct) return fct;
#define GO(A) if(my_GstBusFunc_fct_##A == (uintptr_t)fct) return my_GstBusFunc_##A;
SUPER()
#undef GO
#define GO(A) if(my_GstBusFunc_fct_##A == 0) {my_GstBusFunc_fct_##A = (uintptr_t)fct; return my_GstBusFunc_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for gstreamer GstBusFunc callback\n");
return NULL;
}
//GstPluginFeatureFilter
#define GO(A) \
static uintptr_t my_GstPluginFeatureFilter_fct_##A = 0; \
static int my_GstPluginFeatureFilter_##A(void* a, void* b) \
{ \
return (int)RunFunctionFmt(my_GstPluginFeatureFilter_fct_##A, "pp", a, b); \
}
SUPER()
#undef GO
static void* findGstPluginFeatureFilterFct(void* fct)
{
if(!fct) return fct;
#define GO(A) if(my_GstPluginFeatureFilter_fct_##A == (uintptr_t)fct) return my_GstPluginFeatureFilter_##A;
SUPER()
#undef GO
#define GO(A) if(my_GstPluginFeatureFilter_fct_##A == 0) {my_GstPluginFeatureFilter_fct_##A = (uintptr_t)fct; return my_GstPluginFeatureFilter_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for gstreamer GstPluginFeatureFilter callback\n");
return NULL;
}
//GstCapsFilterMapFunc
#define GO(A) \
static uintptr_t my_GstCapsFilterMapFunc_fct_##A = 0; \
static int my_GstCapsFilterMapFunc_##A(void* a, void* b, void* c) \
{ \
return (int)RunFunctionFmt(my_GstCapsFilterMapFunc_fct_##A, "ppp", a, b, c); \
}
SUPER()
#undef GO
static void* findGstCapsFilterMapFuncFct(void* fct)
{
if(!fct) return fct;
#define GO(A) if(my_GstCapsFilterMapFunc_fct_##A == (uintptr_t)fct) return my_GstCapsFilterMapFunc_##A;
SUPER()
#undef GO
#define GO(A) if(my_GstCapsFilterMapFunc_fct_##A == 0) {my_GstCapsFilterMapFunc_fct_##A = (uintptr_t)fct; return my_GstCapsFilterMapFunc_##A; }
SUPER()
#undef GO
printf_log(LOG_NONE, "Warning, no more slot for gstreamer GstCapsFilterMapFunc callback\n");
return NULL;
}
#undef SUPER
EXPORT void my_gst_caps_set_simple(x64emu_t* emu, void* caps, void* field, void* b) {
CREATE_VALIST_FROM_VAARG(b, emu->scratch, 2);
my->gst_caps_set_simple_valist(caps, field, VARARGS);
}
EXPORT void my_gst_caps_set_simple_valist(x64emu_t* emu, void* caps, void* field, x64_va_list_t V) {
#ifdef CONVERT_VALIST
CONVERT_VALIST(V);
#else
CREATE_VALIST_FROM_VALIST(V, emu->scratch);
#endif
my->gst_caps_set_simple_valist(caps, field, VARARGS);
}
EXPORT void my_gst_structure_remove_fields(x64emu_t* emu, void* structure, void* field, void* b) {
CREATE_VALIST_FROM_VAARG(b, emu->scratch, 2);
my->gst_structure_remove_fields_valist(structure, field, VARARGS);
}
EXPORT void my_gst_structure_remove_fields_valist(x64emu_t* emu, void* structure, void* field, x64_va_list_t V) {
#ifdef CONVERT_VALIST
CONVERT_VALIST(V);
#else
CREATE_VALIST_FROM_VALIST(V, emu->scratch);
#endif
my->gst_structure_remove_fields_valist(structure, field, VARARGS);
}
EXPORT void my_gst_debug_log(x64emu_t* emu, void* cat, int level, void* file, void* func, int line, void* obj, void* fmt, void* b) {
myStackAlign(emu, (const char*)fmt, b, emu->scratch, R_EAX, 7);
PREPARE_VALIST;
my->gst_debug_log_valist(cat, level, file, func, line, obj, fmt, VARARGS);
}
EXPORT void my_gst_debug_log_valist(x64emu_t* emu, void* cat, int level, void* file, void* func, int line, void* obj, void* fmt, x64_va_list_t V) {
#ifdef CONVERT_VALIST
CONVERT_VALIST(V);
#else
myStackAlignValist(emu, (const char*)fmt, emu->scratch, V);
PREPARE_VALIST;
#endif
my->gst_debug_log_valist(cat, level, file, func, line, obj, fmt, VARARGS);
}
EXPORT int my_gst_structure_get(x64emu_t* emu, void* structure, void* field, void* b) {
CREATE_VALIST_FROM_VAARG(b, emu->scratch, 2);
return my->gst_structure_get_valist(structure, field, VARARGS);
}
EXPORT int my_gst_structure_get_valist(x64emu_t* emu, void* structure, void* field, x64_va_list_t V) {
#ifdef CONVERT_VALIST
CONVERT_VALIST(V);
#else
CREATE_VALIST_FROM_VALIST(V, emu->scratch);
#endif
return my->gst_structure_get_valist(structure, field, VARARGS);
}
EXPORT void my_gst_pad_set_activatemode_function_full(x64emu_t* emu, void* pad, void* f, void* data, void* d)
{
my->gst_pad_set_activatemode_function_full(pad, findGstPadActivateModeFunctionFct(f), data, findDestroyFct(d));
}
EXPORT void my_gst_pad_set_query_function_full(x64emu_t* emu, void* pad, void* f, void* data, void* d)
{
my->gst_pad_set_query_function_full(pad, findGstPadQueryFunctionFct(f), data, findDestroyFct(d));
}
EXPORT void my_gst_pad_set_getrange_function_full(x64emu_t* emu, void* pad, void* f, void* data, void* d)
{
my->gst_pad_set_getrange_function_full(pad, findGstPadGetRangeFunctionFct(f), data, findDestroyFct(d));
}
EXPORT void my_gst_pad_set_chain_function_full(x64emu_t* emu, void* pad, void* f, void* data, void* d)
{
my->gst_pad_set_chain_function_full(pad, findGstPadChainFunctionFct(f), data, findDestroyFct(d));
}
EXPORT void my_gst_pad_set_event_function_full(x64emu_t* emu, void* pad, void* f, void* data, void* d)
{
my->gst_pad_set_event_function_full(pad, findGstPadEventFunctionFct(f), data, findDestroyFct(d));
}
EXPORT void my_gst_bus_set_sync_handler(x64emu_t* emu, void* bus, void* f, void* data, void* d)
{
my->gst_bus_set_sync_handler(bus, findGstBusSyncHandlerFct(f), data, findDestroyFct(d));
}
EXPORT void* my_gst_buffer_new_wrapped_full(x64emu_t* emu, uint32_t f, void* data, size_t maxsize, size_t offset, size_t size, void* user, void* d)
{
return my->gst_buffer_new_wrapped_full(f, data, maxsize, offset, size, user, findDestroyFct(d));
}
EXPORT void* my_gst_structure_new(x64emu_t* emu, void* name, void* first, uint64_t* b)
{
if(!first)
return my->gst_structure_new_empty(name);
CREATE_VALIST_FROM_VAARG(b, emu->scratch, 2);
return my->gst_structure_new_valist(name, first, VARARGS);
}
EXPORT void my_gst_mini_object_set_qdata(x64emu_t* emu, void* object, void* quark, void* data, void* d)
{
my->gst_mini_object_set_qdata(object, quark, data, findDestroyFct(d));
}
EXPORT void* my_gst_caps_new_simple(x64emu_t* emu, void* type, void* name, void* b)
{
// need to unroll the function here, there is no direct VA equivalent
CREATE_VALIST_FROM_VAARG(b, emu->scratch, 2);
void* caps = my->gst_caps_new_empty();
void* structure = my->gst_structure_new_valist(type, name, VARARGS);
if (structure)
my->gst_caps_append_structure(caps, structure);
else
my->gst_caps_replace(&caps, NULL);
return caps;
}
EXPORT void* my_gst_registry_feature_filter(x64emu_t* emu, void* reg, void* filter, int first, void* data)
{
return my->gst_registry_feature_filter(reg, findGstPluginFeatureFilterFct(filter), first, data);
}
EXPORT int my_gst_caps_foreach(x64emu_t* emu, void* caps, void* f, void* data)
{
return my->gst_caps_foreach(caps, findGstCapsFilterMapFuncFct(f), data);
}
EXPORT uint32_t my_gst_bus_add_watch(x64emu_t* emu, void* bus, void* f, void* data)
{
return my->gst_bus_add_watch(bus, findGstBusFuncFct(f), data);
}
EXPORT uint32_t my_gst_bus_add_watch_full(x64emu_t* emu, void* bus, int priority, void* f, void* data, void* d)
{
return my->gst_bus_add_watch_full(bus, priority, findGstBusFuncFct(f), data, findDestroyFct(d));
}
EXPORT int my_gst_bin_add_many(x64emu_t* emu, void* bin, void* first, void** b)
{
int ret = my->gst_bin_add(bin, first);
while(ret && *b) {
ret = my->gst_bin_add(bin, *b);
++b;
}
return ret;
}
EXPORT int my_gst_element_link_many(x64emu_t* emu, void* e1, void* e2, void** b)
{
int ret = my->gst_element_link(e1, e2);
void* a = e2;
while(ret && *b) {
ret = my->gst_element_link(a, *b);
a = *b;
++b;
}
return ret;
}
/*
EXPORT void* my_gst_plugin_load_file(x64emu_t* emu, const char* filename, void** error)
{
printf_log(LOG_INFO, "using gst_plugin_load_file, file %s (is x86_64=%d)\n", filename, FileIsX64ELF(filename));
return my->gst_plugin_load_file((void*)filename, error);
}
EXPORT int my_gst_init_check(x64emu_t* emu, int* argc, char*** argv, void** error)
{
printf_log(LOG_INFO, "will call gst_init_check(%o, %p, %p)\n", argc, argv, error);
if(argc && argv) {
printf_log(LOG_INFO, " argc=%d, argv=[", *argc);
for(int i=0; i<*argc; ++i)
printf_log(LOG_INFO, "%s\"%s\"", i?", ":"", (*argv)[i]);
printf_log(LOG_INFO, "]");
}
if(getenv("GST_PLUGIN_LOADING_WHITELIST"))
printf_log(LOG_INFO, "\nGST_PLUGIN_LOADING_WHITELIST=%s", getenv("GST_PLUGIN_LOADING_WHITELIST"));
printf_log(LOG_INFO, "\n");
int ret = my->gst_init_check(argc, argv, error);
printf_log(LOG_INFO, "gst_init_check(...) return = %d\n", ret);
return ret;
}
*/
#define PRE_INIT \
if(box64_nogtk) \
return -1;
#define CUSTOM_INIT \
getMy(lib); \
SetGstObjectID(my->gst_object_get_type()); \
SetGstAllocatorID(my->gst_allocator_get_type()); \
SetGstTaskPoolID(my->gst_task_pool_get_type()); \
setNeededLibs(lib, 1, "libgtk-3.so.0");
#define CUSTOM_FINI \
freeMy();
#include "wrappedlib_init.h"
|