forked from AvionBlock/OpusSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopus_shim.c
More file actions
135 lines (108 loc) · 3.94 KB
/
opus_shim.c
File metadata and controls
135 lines (108 loc) · 3.94 KB
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
/*
* opus_shim.c - Non-variadic wrappers for Opus CTL functions.
*
* On ARM64 Apple Silicon (macOS/iOS), the C ABI passes variadic arguments
* on the stack while fixed arguments go in registers. The opus _ctl functions
* (opus_encoder_ctl, opus_decoder_ctl, etc.) are variadic, so calling them
* via P/Invoke (which treats all parameters as fixed) causes arguments to be
* passed in registers instead of on the stack, resulting in OPUS_BAD_ARG.
*
* These thin non-variadic wrappers correctly forward calls to the variadic
* opus CTL functions. Since the wrapper itself is compiled natively, the
* compiler handles the variadic calling convention correctly.
*
* Built into the opus shared/static library for all platforms to avoid
* conditional compilation in C#.
*/
#include <opus.h>
#include <opus_multistream.h>
#ifdef _WIN32
# define SHIM_EXPORT __declspec(dllexport)
#else
# define SHIM_EXPORT
#endif
/* === Encoder CTL === */
SHIM_EXPORT SHIM_EXPORT int opussharp_encoder_ctl(OpusEncoder *st, int request)
{
return opus_encoder_ctl(st, request);
}
SHIM_EXPORT int opussharp_encoder_ctl_i(OpusEncoder *st, int request, int value)
{
return opus_encoder_ctl(st, request, value);
}
SHIM_EXPORT int opussharp_encoder_ctl_p(OpusEncoder *st, int request, void *value)
{
return opus_encoder_ctl(st, request, value);
}
SHIM_EXPORT int opussharp_encoder_ctl_pi(OpusEncoder *st, int request, void *data, int data2)
{
return opus_encoder_ctl(st, request, data, data2);
}
SHIM_EXPORT int opussharp_encoder_ctl_ip(OpusEncoder *st, int request, int data, void *data2)
{
return opus_encoder_ctl(st, request, data, data2);
}
SHIM_EXPORT int opussharp_encoder_ctl_pp(OpusEncoder *st, int request, void *data, void *data2)
{
return opus_encoder_ctl(st, request, data, data2);
}
/* === Decoder CTL === */
SHIM_EXPORT int opussharp_decoder_ctl(OpusDecoder *st, int request)
{
return opus_decoder_ctl(st, request);
}
SHIM_EXPORT int opussharp_decoder_ctl_i(OpusDecoder *st, int request, int value)
{
return opus_decoder_ctl(st, request, value);
}
SHIM_EXPORT int opussharp_decoder_ctl_p(OpusDecoder *st, int request, void *value)
{
return opus_decoder_ctl(st, request, value);
}
/* === DRED Decoder CTL === */
SHIM_EXPORT int opussharp_dred_decoder_ctl(OpusDREDDecoder *dred_dec, int request)
{
return opus_dred_decoder_ctl(dred_dec, request);
}
SHIM_EXPORT int opussharp_dred_decoder_ctl_p(OpusDREDDecoder *dred_dec, int request, void *value)
{
return opus_dred_decoder_ctl(dred_dec, request, value);
}
/* === Multistream Encoder CTL === */
SHIM_EXPORT int opussharp_ms_encoder_ctl(OpusMSEncoder *st, int request)
{
return opus_multistream_encoder_ctl(st, request);
}
SHIM_EXPORT int opussharp_ms_encoder_ctl_i(OpusMSEncoder *st, int request, int value)
{
return opus_multistream_encoder_ctl(st, request, value);
}
SHIM_EXPORT int opussharp_ms_encoder_ctl_p(OpusMSEncoder *st, int request, void *value)
{
return opus_multistream_encoder_ctl(st, request, value);
}
SHIM_EXPORT int opussharp_ms_encoder_ctl_pi(OpusMSEncoder *st, int request, void *data, int data2)
{
return opus_multistream_encoder_ctl(st, request, data, data2);
}
SHIM_EXPORT int opussharp_ms_encoder_ctl_ip(OpusMSEncoder *st, int request, int data, void *data2)
{
return opus_multistream_encoder_ctl(st, request, data, data2);
}
SHIM_EXPORT int opussharp_ms_encoder_ctl_pp(OpusMSEncoder *st, int request, void *data, void *data2)
{
return opus_multistream_encoder_ctl(st, request, data, data2);
}
/* === Multistream Decoder CTL === */
SHIM_EXPORT int opussharp_ms_decoder_ctl(OpusMSDecoder *st, int request)
{
return opus_multistream_decoder_ctl(st, request);
}
SHIM_EXPORT int opussharp_ms_decoder_ctl_i(OpusMSDecoder *st, int request, int value)
{
return opus_multistream_decoder_ctl(st, request, value);
}
SHIM_EXPORT int opussharp_ms_decoder_ctl_p(OpusMSDecoder *st, int request, void *value)
{
return opus_multistream_decoder_ctl(st, request, value);
}