/
MumblePlugin.h
1823 lines (1615 loc) · 81.4 KB
/
MumblePlugin.h
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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2023 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////// CONTROL OVER WHAT SECTIONS TO INCLUDE ////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Whether or not to include default implementations
#ifdef MUMBLE_PLUGIN_NO_DEFAULT_FUNCTION_DEFINITIONS
# undef EXTERNAL_MUMBLE_PLUGIN_DEFAULT_IMPLEMENTATIONS_
# define EXTERNAL_MUMBLE_PLUGIN_DEFAULT_IMPLEMENTATIONS_
#endif
// Whether or not to create the MumbleAPI typedef
#undef MUMBLE_PLUGIN_CREATE_MUMBLE_API_TYPEDEF
#ifndef MUMBLE_PLUGIN_NO_API_TYPEDEF
# define MUMBLE_PLUGIN_CREATE_MUMBLE_API_TYPEDEF
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// MACRO DEFINITIONS //////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef EXTERNAL_MUMBLE_PLUGIN_MACROS_
# define EXTERNAL_MUMBLE_PLUGIN_MACROS_
/*
* Plugin version information
*/
# define MUMBLE_PLUGIN_INTERFACE_MAJOR_MACRO 1
# define MUMBLE_PLUGIN_INTERFACE_MINOR_MACRO 2
# define MUMBLE_PLUGIN_INTERFACE_PATCH_MACRO 0
// Allow the selected API version be overwritten by external definitions
# ifndef MUMBLE_PLUGIN_API_MAJOR_MACRO
# define MUMBLE_PLUGIN_API_MAJOR_MACRO 1
# endif
# ifndef MUMBLE_PLUGIN_API_MINOR_MACRO
# define MUMBLE_PLUGIN_API_MINOR_MACRO 2
# endif
# ifndef MUMBLE_PLUGIN_API_PATCH_MACRO
# define MUMBLE_PLUGIN_API_PATCH_MACRO 0
# endif
# define MUMBLE_PLUGIN_FUNCTIONS_MAJOR_MACRO 1
# define MUMBLE_PLUGIN_FUNCTIONS_MINOR_MACRO 1
# define MUMBLE_PLUGIN_FUNCTIONS_PATCH_MACRO 0
/*
* MUMBLE_PLUGIN_EXPORT
*/
# if defined(__GNUC__) && !defined(__MINGW32__) // GCC on Unix-like systems
# define MUMBLE_PLUGIN_EXPORT __attribute__((visibility("default")))
# elif defined(_MSC_VER)
# define MUMBLE_PLUGIN_EXPORT __declspec(dllexport)
# elif defined(__MINGW32__)
# define MUMBLE_PLUGIN_EXPORT __attribute__((dllexport))
# else
# error No MUMBLE_PLUGIN_EXPORT definition available
# endif
/*
* MUMBLE_PLUGIN_CALLING_CONVENTION
*/
# if defined(_MSC_VER)
# define MUMBLE_PLUGIN_CALLING_CONVENTION __cdecl
# elif defined(__MINGW32__)
# define MUMBLE_PLUGIN_CALLING_CONVENTION __attribute__((cdecl))
# else
# define MUMBLE_PLUGIN_CALLING_CONVENTION
# endif
/*
* MUMBLE_PLUGIN_HAS_QT
*/
# if defined(QT_CORE_LIB) || defined(QT_VERSION)
# define MUMBLE_PLUGIN_HAS_QT
# endif
/*
* MUMBLE_PLUGIN_VERSION_CHECK
* Converts a major, minor and patch version number into a single integer to be used in preprocessor
* if conditions
*/
# define MUMBLE_PLUGIN_VERSION_CHECK(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
/*
* MUMBLE_PLUGIN_CONSTEXPR
*/
# ifdef __cplusplus
# define MUMBLE_PLUGIN_CONSTEXPR constexpr
# else
# define MUMBLE_PLUGIN_CONSTEXPR
# endif
/*
* MUMBLE_EXTERN_C_BEGIN / MUMBLE_EXTERN_C_END
*/
# ifdef __cplusplus
# define MUMBLE_EXTERN_C_BEGIN extern "C" {
# define MUMBLE_EXTERN_C_END }
# else
# define MUMBLE_EXTERN_C_BEGIN
# define MUMBLE_EXTERN_C_END
# endif
// For more info on the necessity of the with/without pattern have a look
// at https://stackoverflow.com/a/3419392
/*
* MUMBLE_CONCAT
* Concatenates the given values WITHOUT macro expansion
*/
# define MUMBLE_CONCAT(a, b) a##_##b
/**
* MUMBLE_ECONCAT
* Concatenates the given values WITH macro expansion
*/
# define MUMBLE_ECONCAT(a, b) MUMBLE_CONCAT(a, b)
/**
* MUMBLE_QUOTE
* Quotes the given value WITHOUT macro expansion
*/
# define MUMBLE_QUOTE(arg) # arg
/**
* MUMBLE_EQUOTE
* Quotes the given value WITH macro expansion
*/
# define MUMBLE_EQUOTE(arg) MUMBLE_QUOTE(arg)
#endif // EXTERNAL_MUMBLE_PLUGIN_MACROS_
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////// PLUGIN TYPES /////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef EXTERNAL_MUMBLE_PLUGIN_TYPES_
# define EXTERNAL_MUMBLE_PLUGIN_TYPES_
# include <stdint.h>
# include <stddef.h>
# include <stdbool.h>
# ifdef __cplusplus
# include <string>
# ifdef MUMBLE_PLUGIN_HAS_QT
# include <QString>
# endif
# endif
MUMBLE_EXTERN_C_BEGIN
/**
* This enum's values correspond to special feature sets a plugin may provide.
* They are meant to be or'ed together to represent the total feature set of a plugin.
*/
enum Mumble_PluginFeature {
/**
* None of the below
*/
MUMBLE_FEATURE_NONE = 0,
/**
* The plugin provides positional data from a game
*/
MUMBLE_FEATURE_POSITIONAL = 1 << 0,
/**
* The plugin modifies the input/output audio itself
*/
MUMBLE_FEATURE_AUDIO = 1 << 1,
};
/**
* This enum's values represent talking states a user can be in when using Mumble.
*/
enum Mumble_TalkingState {
MUMBLE_TS_INVALID = -1,
MUMBLE_TS_PASSIVE = 0,
MUMBLE_TS_TALKING,
MUMBLE_TS_WHISPERING,
MUMBLE_TS_SHOUTING,
MUMBLE_TS_TALKING_MUTED,
};
/**
* This enum's values represent transmission modes a user might have configured. Transmission mode
* in this context is referring to a method that determines when a user is speaking and thus when
* to transmit audio packets.
*/
enum Mumble_TransmissionMode {
MUMBLE_TM_CONTINOUS,
MUMBLE_TM_VOICE_ACTIVATION,
MUMBLE_TM_PUSH_TO_TALK,
};
/**
* This enum's values represent the error codes that are being used by the MumbleAPI.
* You can get a string-representation for each error code via the errorMessage function.
*/
enum Mumble_ErrorCode {
MUMBLE_EC_INTERNAL_ERROR = -2,
MUMBLE_EC_GENERIC_ERROR = -1,
MUMBLE_EC_OK = 0,
MUMBLE_EC_POINTER_NOT_FOUND,
MUMBLE_EC_NO_ACTIVE_CONNECTION,
MUMBLE_EC_USER_NOT_FOUND,
MUMBLE_EC_CHANNEL_NOT_FOUND,
MUMBLE_EC_CONNECTION_NOT_FOUND,
MUMBLE_EC_UNKNOWN_TRANSMISSION_MODE,
MUMBLE_EC_AUDIO_NOT_AVAILABLE,
MUMBLE_EC_INVALID_SAMPLE,
MUMBLE_EC_INVALID_PLUGIN_ID,
MUMBLE_EC_INVALID_MUTE_TARGET,
MUMBLE_EC_CONNECTION_UNSYNCHRONIZED,
MUMBLE_EC_INVALID_API_VERSION,
MUMBLE_EC_UNSYNCHRONIZED_BLOB,
MUMBLE_EC_UNKNOWN_SETTINGS_KEY,
MUMBLE_EC_WRONG_SETTINGS_TYPE,
MUMBLE_EC_SETTING_WAS_REMOVED,
MUMBLE_EC_DATA_TOO_BIG,
MUMBLE_EC_DATA_ID_TOO_LONG,
MUMBLE_EC_API_REQUEST_TIMEOUT,
MUMBLE_EC_OPERATION_UNSUPPORTED_BY_SERVER,
};
/**
* This enum's values represent error codes specific to the framework of handling positional data
* gathering (needed for Mumble's positional audio feature).
*/
enum Mumble_PositionalDataErrorCode {
/**
* Positional data has been initialized properly
*/
MUMBLE_PDEC_OK = 0,
/**
* Positional data is temporarily unavailable (e.g. because the corresponding process isn't running) but might be
* at another point in time.
*/
MUMBLE_PDEC_ERROR_TEMP,
/**
* Positional data is permanently unavailable (e.g. because the respective memory offsets are outdated).
*/
MUMBLE_PDEC_ERROR_PERM,
};
/**
* This enum's values represent keys for specific settings inside Mumble.
*/
enum Mumble_SettingsKey {
MUMBLE_SK_INVALID = -1,
MUMBLE_SK_AUDIO_INPUT_VOICE_HOLD = 0,
MUMBLE_SK_AUDIO_INPUT_VAD_SILENCE_THRESHOLD = 1,
MUMBLE_SK_AUDIO_INPUT_VAD_SPEECH_THRESHOLD = 2,
MUMBLE_SK_AUDIO_OUTPUT_PA_MINIMUM_DISTANCE = 3,
MUMBLE_SK_AUDIO_OUTPUT_PA_MAXIMUM_DISTANCE = 4,
MUMBLE_SK_AUDIO_OUTPUT_PA_BLOOM = 5,
MUMBLE_SK_AUDIO_OUTPUT_PA_MINIMUM_VOLUME = 6,
};
/**
* This enum's values represent the key-codes Mumble's API uses to reference keys on the keyboard.
*/
enum Mumble_KeyCode {
MUMBLE_KC_INVALID = -1,
// Non-printable characters first
MUMBLE_KC_NULL = 0,
MUMBLE_KC_END = 1,
MUMBLE_KC_LEFT = 2,
MUMBLE_KC_RIGHT = 4,
MUMBLE_KC_UP = 5,
MUMBLE_KC_DOWN = 6,
MUMBLE_KC_DELETE = 7,
MUMBLE_KC_BACKSPACE = 8,
MUMBLE_KC_TAB = 9,
MUMBLE_KC_ENTER = 10, // == '\n'
MUMBLE_KC_ESCAPE = 27,
MUMBLE_KC_PAGE_UP = 11,
MUMBLE_KC_PAGE_DOWN = 12,
MUMBLE_KC_SHIFT = 13,
MUMBLE_KC_CONTROL = 14,
MUMBLE_KC_META = 15,
MUMBLE_KC_ALT = 16,
MUMBLE_KC_ALT_GR = 17,
MUMBLE_KC_CAPSLOCK = 18,
MUMBLE_KC_NUMLOCK = 19,
MUMBLE_KC_SUPER = 20, // == windows key
MUMBLE_KC_HOME = 21, // == Pos1
MUMBLE_KC_PRINT = 22,
MUMBLE_KC_SCROLLLOCK = 23,
// Printable characters are assigned to their ASCII code
MUMBLE_KC_SPACE = ' ',
MUMBLE_KC_EXCLAMATION_MARK = '!',
MUMBLE_KC_DOUBLE_QUOTE = '"',
MUMBLE_KC_HASHTAG = '#',
MUMBLE_KC_DOLLAR = '$',
MUMBLE_KC_PERCENT = '%',
MUMBLE_KC_AMPERSAND = '&',
MUMBLE_KC_SINGLE_QUOTE = '\'',
MUMBLE_KC_OPEN_PARENTHESIS = '(',
MUMBLE_KC_CLOSE_PARENTHESIS = ')',
MUMBLE_KC_ASTERISK = '*',
MUMBLE_KC_PLUS = '+',
MUMBLE_KC_COMMA = ',',
MUMBLE_KC_MINUS = '-',
MUMBLE_KC_PERIOD = '.',
MUMBLE_KC_SLASH = '/',
MUMBLE_KC_0 = '0',
MUMBLE_KC_1 = '1',
MUMBLE_KC_2 = '2',
MUMBLE_KC_3 = '3',
MUMBLE_KC_4 = '4',
MUMBLE_KC_5 = '5',
MUMBLE_KC_6 = '6',
MUMBLE_KC_7 = '7',
MUMBLE_KC_8 = '8',
MUMBLE_KC_9 = '9',
MUMBLE_KC_COLON = ':',
MUMBLE_KC_SEMICOLON = ';',
MUMBLE_KC_LESS_THAN = '<',
MUMBLE_KC_EQUALS = '=',
MUMBLE_KC_GREATER_THAN = '>',
MUMBLE_KC_QUESTION_MARK = '?',
MUMBLE_KC_AT_SYMBOL = '@',
MUMBLE_KC_A = 'A',
MUMBLE_KC_B = 'B',
MUMBLE_KC_C = 'C',
MUMBLE_KC_D = 'D',
MUMBLE_KC_E = 'E',
MUMBLE_KC_F = 'F',
MUMBLE_KC_G = 'G',
MUMBLE_KC_H = 'H',
MUMBLE_KC_I = 'I',
MUMBLE_KC_J = 'J',
MUMBLE_KC_K = 'K',
MUMBLE_KC_L = 'L',
MUMBLE_KC_M = 'M',
MUMBLE_KC_N = 'N',
MUMBLE_KC_O = 'O',
MUMBLE_KC_P = 'P',
MUMBLE_KC_Q = 'Q',
MUMBLE_KC_R = 'R',
MUMBLE_KC_S = 'S',
MUMBLE_KC_T = 'T',
MUMBLE_KC_U = 'U',
MUMBLE_KC_V = 'V',
MUMBLE_KC_W = 'W',
MUMBLE_KC_X = 'X',
MUMBLE_KC_Y = 'Y',
MUMBLE_KC_Z = 'Z',
// leave out lowercase letters (for now)
MUMBLE_KC_OPEN_BRACKET = '[',
MUMBLE_KC_BACKSLASH = '\\',
MUMBLE_KC_CLOSE_BRACKET = ']',
MUMBLE_KC_CIRCUMFLEX = '^',
MUMBLE_KC_UNDERSCORE = '_',
MUMBLE_KC_GRAVE_AKCENT = '`',
MUMBLE_KC_OPEN_BRACE = '{',
MUMBLE_KC_VERTICAL_BAR = '|',
MUMBLE_KC_CLOSE_BRACE = '}',
MUMBLE_KC_TILDE = '~',
// Some characters from the extended ASCII code
MUMBLE_KC_DEGREE_SIGN = 176,
// F-keys
// Start at a value of 256 as extended ASCII codes range up to 255
MUMBLE_KC_F1 = 256,
MUMBLE_KC_F2 = 257,
MUMBLE_KC_F3 = 258,
MUMBLE_KC_F4 = 259,
MUMBLE_KC_F5 = 260,
MUMBLE_KC_F6 = 261,
MUMBLE_KC_F7 = 262,
MUMBLE_KC_F8 = 263,
MUMBLE_KC_F9 = 264,
MUMBLE_KC_F10 = 265,
MUMBLE_KC_F11 = 266,
MUMBLE_KC_F12 = 267,
MUMBLE_KC_F13 = 268,
MUMBLE_KC_F14 = 269,
MUMBLE_KC_F15 = 270,
MUMBLE_KC_F16 = 271,
MUMBLE_KC_F17 = 272,
MUMBLE_KC_F18 = 273,
MUMBLE_KC_F19 = 274,
};
/**
* A struct for representing a version of the form major.minor.patch
*/
struct MumbleVersion {
int32_t major;
int32_t minor;
int32_t patch;
# ifdef __cplusplus
explicit operator std::string() const {
return std::string("v") + std::to_string(this->major) + std::string(".") + std::to_string(this->minor)
+ std::string(".") + std::to_string(this->patch);
}
# ifdef MUMBLE_PLUGIN_HAS_QT
explicit operator QString() const {
return QString::fromLatin1("v%0.%1.%2").arg(this->major).arg(this->minor).arg(this->patch);
}
# endif
# endif // __cplusplus
};
/**
* This struct is used to return Strings from a plugin to Mumble. It is needed in order to
* work around the limitation of std::string not being part of C (it holds important information
* about the String's lifetime management requirements).
*/
struct MumbleStringWrapper {
/**
* The pointer to the actual String data
*/
const char *data;
/**
* The size of the pointed String data
*/
size_t size;
/**
* Whether the wrapped String needs to be released
* after its usage. Instances for which this would be
* false: Static Strings, String literals
*/
bool needsReleasing;
};
MUMBLE_EXTERN_C_END
#endif // EXTERNAL_MUMBLE_PLUGIN_TYPES_
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// Type aliases / Typedefs /////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef EXTERNAL_MUMBLE_PLUGIN_TYPEDEFS_
# define EXTERNAL_MUMBLE_PLUGIN_TYPEDEFS_
/**
* Typedef for the type of a talking state
*/
typedef enum Mumble_TalkingState mumble_talking_state_t;
/**
* Typedef for the type of a transmission mode
*/
typedef enum Mumble_TransmissionMode mumble_transmission_mode_t;
/**
* Typedef for the type of a version
*/
typedef struct MumbleVersion mumble_version_t;
/**
* Typedef for the type of a connection
*/
typedef int32_t mumble_connection_t;
/**
* Typedef for the type of a user
*/
typedef uint32_t mumble_userid_t;
/**
* Typedef for the type of a channel
*/
typedef int32_t mumble_channelid_t;
/**
* Typedef for the type of an error (code)
*/
typedef enum Mumble_ErrorCode mumble_error_t;
/**
* Typedef for the type of a plugin ID
*/
typedef uint32_t mumble_plugin_id_t;
/**
* Typedef for the type of a key to a setting in Mumble
*/
typedef enum Mumble_SettingsKey mumble_settings_key_t;
/**
* Typedef for the type of a key-code
*/
typedef enum Mumble_KeyCode mumble_keycode_t;
#endif // EXTERNAL_MUMBLE_PLUGIN_TYPEDEFS_
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////// Non-enum Constants /////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef EXTERNAL_MUMBLE_PLUGIN_CONSTANTS_
# define EXTERNAL_MUMBLE_PLUGIN_CONSTANTS_
/*
* Version constants
*/
static const MUMBLE_PLUGIN_CONSTEXPR int32_t MUMBLE_PLUGIN_INTERFACE_MAJOR = MUMBLE_PLUGIN_INTERFACE_MAJOR_MACRO;
static const MUMBLE_PLUGIN_CONSTEXPR int32_t MUMBLE_PLUGIN_INTERFACE_MINOR = MUMBLE_PLUGIN_INTERFACE_MINOR_MACRO;
static const MUMBLE_PLUGIN_CONSTEXPR int32_t MUMBLE_PLUGIN_INTERFACE_PATCH = MUMBLE_PLUGIN_INTERFACE_PATCH_MACRO;
static const MUMBLE_PLUGIN_CONSTEXPR mumble_version_t MUMBLE_PLUGIN_INTERFACE_VERSION = {
MUMBLE_PLUGIN_INTERFACE_MAJOR, MUMBLE_PLUGIN_INTERFACE_MINOR, MUMBLE_PLUGIN_INTERFACE_PATCH
};
static const MUMBLE_PLUGIN_CONSTEXPR int32_t MUMBLE_PLUGIN_API_MAJOR = MUMBLE_PLUGIN_API_MAJOR_MACRO;
static const MUMBLE_PLUGIN_CONSTEXPR int32_t MUMBLE_PLUGIN_API_MINOR = MUMBLE_PLUGIN_API_MINOR_MACRO;
static const MUMBLE_PLUGIN_CONSTEXPR int32_t MUMBLE_PLUGIN_API_PATCH = MUMBLE_PLUGIN_API_PATCH_MACRO;
static const MUMBLE_PLUGIN_CONSTEXPR mumble_version_t MUMBLE_PLUGIN_API_VERSION = { MUMBLE_PLUGIN_API_MAJOR,
MUMBLE_PLUGIN_API_MINOR,
MUMBLE_PLUGIN_API_PATCH };
static const MUMBLE_PLUGIN_CONSTEXPR int32_t MUMBLE_PLUGIN_FUNCTIONS_MAJOR = MUMBLE_PLUGIN_FUNCTIONS_MAJOR_MACRO;
static const MUMBLE_PLUGIN_CONSTEXPR int32_t MUMBLE_PLUGIN_FUNCTIONS_MINOR = MUMBLE_PLUGIN_FUNCTIONS_MINOR_MACRO;
static const MUMBLE_PLUGIN_CONSTEXPR int32_t MUMBLE_PLUGIN_FUNCTIONS_PATCH = MUMBLE_PLUGIN_FUNCTIONS_PATCH_MACRO;
static const MUMBLE_PLUGIN_CONSTEXPR mumble_version_t MUMBLE_PLUGIN_FUNCTIONS_VERSION = {
MUMBLE_PLUGIN_FUNCTIONS_MAJOR, MUMBLE_PLUGIN_FUNCTIONS_MINOR, MUMBLE_PLUGIN_FUNCTIONS_PATCH
};
/**
* The exit status of a successful operation
*/
static const MUMBLE_PLUGIN_CONSTEXPR mumble_error_t MUMBLE_STATUS_OK = MUMBLE_EC_OK;
/**
* A version object that is considered to correspond to an unknown version
*/
static const MUMBLE_PLUGIN_CONSTEXPR mumble_version_t MUMBLE_VERSION_UNKNOWN = { 0, 0, 0 };
#endif // EXTERNAL_MUMBLE_PLUGIN_CONSTANTS_
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// C convenience implementations /////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef EXTERNAL_MUMBLE_PLUGIN_C_CONVENIENCE_IMPLS_
# define EXTERNAL_MUMBLE_PLUGIN_C_CONVENIENCE_IMPLS_
/**
* Obtains a String representation for the given numeric error code.
* Note that the exact String representation corresponding to an error code may change and is thus
* not part of the plugin API as such. This function acts merely as a convenience helper for printing
* errors in a meaningful way.
*
* @param errorCode The error code to get the String representation for
* @returns The error message coresponding to the given error code. The message
* is encoded as a C-string and is static, meaning that it is safe to use the
* returned pointer in your code.
*/
MUMBLE_PLUGIN_CONSTEXPR inline const char *mumble_errorMessage(int16_t errorCode) {
switch (errorCode) {
case MUMBLE_EC_GENERIC_ERROR:
return "Generic error";
case MUMBLE_EC_OK:
return "Ok - this is not an error";
case MUMBLE_EC_POINTER_NOT_FOUND:
return "Can't find the passed pointer";
case MUMBLE_EC_NO_ACTIVE_CONNECTION:
return "There is currently no active connection to a server";
case MUMBLE_EC_USER_NOT_FOUND:
return "Can't find the requested user";
case MUMBLE_EC_CHANNEL_NOT_FOUND:
return "Can't find the requested channel";
case MUMBLE_EC_CONNECTION_NOT_FOUND:
return "Can't identify the requested connection";
case MUMBLE_EC_UNKNOWN_TRANSMISSION_MODE:
return "Unknown transmission mode encountered";
case MUMBLE_EC_AUDIO_NOT_AVAILABLE:
return "There is currently no audio output available";
case MUMBLE_EC_INVALID_SAMPLE:
return "Attempted to use invalid sample (can't play it)";
case MUMBLE_EC_INVALID_PLUGIN_ID:
return "Used an invalid plugin ID";
case MUMBLE_EC_INVALID_MUTE_TARGET:
return "Used an invalid mute-target";
case MUMBLE_EC_CONNECTION_UNSYNCHRONIZED:
return "The requested server connection has not yet finished synchronizing";
case MUMBLE_EC_INVALID_API_VERSION:
return "The used API version is invalid or not supported";
case MUMBLE_EC_UNSYNCHRONIZED_BLOB:
return "The requested blob (content) has not yet been synchronized between the client and the server";
case MUMBLE_EC_UNKNOWN_SETTINGS_KEY:
return "The used settings-key does not match any key known to Mumble";
case MUMBLE_EC_WRONG_SETTINGS_TYPE:
return "The referenced setting has a different type than requested";
case MUMBLE_EC_SETTING_WAS_REMOVED:
return "The referenced setting got removed from Mumble and is no longer used";
case MUMBLE_EC_DATA_TOO_BIG:
return "The given data is too large (exceeds limit)";
case MUMBLE_EC_DATA_ID_TOO_LONG:
return "The given data ID is too long (exceeds limit)";
case MUMBLE_EC_API_REQUEST_TIMEOUT:
return "A blocking API call took too long and was thus aborted (probably preventing a deadlock)";
case MUMBLE_EC_OPERATION_UNSUPPORTED_BY_SERVER:
return "The requested API operation depends on server-side functionality, not supported by the server "
"you're connected to";
}
return "Unknown error code";
}
#endif // EXTERNAL_MUMBLE_PLUGIN_C_CONVENIENCE_IMPLS_
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// C++ convenience implementations ////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
#if !defined(EXTERNAL_MUMBLE_PLUGIN_CPP_CONVENIENCE_IMPLS_) && defined(__cplusplus)
# define EXTERNAL_MUMBLE_PLUGIN_CPP_CONVENIENCE_IMPLS_
/*
* Comparison operator overloads for MumbleVersion structs
*/
constexpr bool operator<(const MumbleVersion &lhs, const MumbleVersion &rhs) {
if (lhs.major != rhs.major) {
return lhs.major < rhs.major;
}
if (lhs.minor != rhs.minor) {
return lhs.minor < rhs.minor;
}
// Major and Minor are equal
return lhs.patch < rhs.patch;
}
constexpr bool operator==(const MumbleVersion &lhs, const MumbleVersion &rhs) {
return lhs.major == rhs.major && lhs.minor == rhs.minor && lhs.patch == rhs.patch;
}
constexpr bool operator!=(const MumbleVersion &lhs, const MumbleVersion &rhs) {
return !(lhs == rhs);
}
constexpr bool operator>(const MumbleVersion &lhs, const MumbleVersion &rhs) {
return !(lhs == rhs || lhs < rhs);
}
constexpr bool operator>=(const MumbleVersion &lhs, const MumbleVersion &rhs) {
return lhs == rhs || lhs > rhs;
}
constexpr bool operator<=(const MumbleVersion &lhs, const MumbleVersion &rhs) {
return lhs == rhs || lhs < rhs;
}
#endif // EXTERNAL_MUMBLE_PLUGIN_CPP_CONVENIENCE_IMPLS_
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// Plugin functions //////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef EXTERNAL_MUMBLE_PLUGIN_FUNCTIONS_
# define EXTERNAL_MUMBLE_PLUGIN_FUNCTIONS_
# include <stdint.h>
# include <stddef.h>
# include <stdbool.h>
MUMBLE_EXTERN_C_BEGIN
// >>>>>>>>>>>>>>>>>>>> MANDATORY functions <<<<<<<<<<<<<<<<<<<<
/**
* Gets called right after loading the plugin in order to let the plugin initialize.
*
* Registers the ID of this plugin.
* @param id The ID for this plugin. This is the ID Mumble will reference this plugin with
* and by which this plugin can identify itself when communicating with Mumble.
* @returns The status of the initialization. If everything went fine, return STATUS_OK
*/
MUMBLE_PLUGIN_EXPORT mumble_error_t MUMBLE_PLUGIN_CALLING_CONVENTION mumble_init(mumble_plugin_id_t id);
/**
* Gets called when unloading the plugin in order to allow it to clean up after itself.
* Note that it is still safe to call API functions from within this callback.
*/
MUMBLE_PLUGIN_EXPORT void MUMBLE_PLUGIN_CALLING_CONVENTION mumble_shutdown();
/**
* Gets the name of the plugin.
*
* NOTE: This function may be called without the plugin being loaded
*
* @returns A String-wrapper containing the requested name
*/
MUMBLE_PLUGIN_EXPORT struct MumbleStringWrapper MUMBLE_PLUGIN_CALLING_CONVENTION mumble_getName();
/**
* Gets the Version of the plugin-API this plugin intends to use.
* Mumble will decide whether this plugin is loadable or not based on the return value of this function.
*
* NOTE: This function may be called without the plugin being loaded
*
* @returns The respective API Version
*/
MUMBLE_PLUGIN_EXPORT mumble_version_t MUMBLE_PLUGIN_CALLING_CONVENTION mumble_getAPIVersion();
/**
* Provides the MumbleAPI struct to the plugin. This struct contains function pointers that can be used
* to interact with the Mumble client. It is up to the plugin to store this struct somewhere if it wants to make use
* of it at some point.
*
* NOTE: This function may be called without the plugin being loaded
*
* @param api A pointer to the MumbleAPI struct. The API struct must be cast to the version corresponding to the
* user API version. If your plugin is e.g. using the 1.0.x API, then you have to cast this pointer to
* MumbleAPI_v_1_0_x. Note also that you **must not store this pointer**. It will become invalid. Therefore
* you have to copy the struct in order to use it later on.
*/
MUMBLE_PLUGIN_EXPORT void MUMBLE_PLUGIN_CALLING_CONVENTION mumble_registerAPIFunctions(void *apiStruct);
/**
* Releases the resource pointed to by the given pointer. If the respective resource has been allocated before,
* this would be the time to free/delete it.
* The resources processed by this functions are only those that have been specifically allocated in order to return
* them in one of the plugin functions to Mumble (e.g. the String returned by mumble_getName) and has nothing to do
* with your plugin's internal resource management.
* In short: Only resources passed from the plugin to Mumble via a return value may be processed by this function.
*
* NOTE1: This function may be called without the plugin being loaded
*
* NOTE2: that the pointer might be pointing to memory that had to be allocated without the plugin being loaded.
* Therefore you should be very sure that there'll be another callback in which you want to free this memory,
* should you decide to not do it here (which is hereby explicitly advised against).
*
* NOTE3: The pointer is const as Mumble won't mess with the memory allocated by the plugin (no modifications).
* Nontheless this function is explicitly responsible for freeing the respective memory parts. If the memory has
* been allocated using malloc(), it needs to be freed using free() which requires a const-cast. If however the
* memory has been created using the new operator you have to cast the pointer back to its original type and then
* use the delete operator on it (no const-cast necessary in this case).
* See https://stackoverflow.com/questions/2819535/unable-to-free-const-pointers-in-c
* and https://stackoverflow.com/questions/941832/is-it-safe-to-delete-a-void-pointer
*
* @param pointer The pointer to the memory that needs free-ing
*/
MUMBLE_PLUGIN_EXPORT void MUMBLE_PLUGIN_CALLING_CONVENTION mumble_releaseResource(const void *pointer);
// >>>>>>>>>>>>>>>>>>>> GENERAL functions <<<<<<<<<<<<<<<<<<<<
/**
* Tells the plugin some basic information about the Mumble client loading it.
* This function will be the first one that is being called on this plugin - even before it is decided whether to load
* the plugin at all.
*
* @param mumbleVersion The Version of the Mumble client
* @param mumbleAPIVersion The Version of the plugin-API the Mumble client runs with
* @param minimumExpectedAPIVersion The minimum Version the Mumble clients expects this plugin to meet in order to load
* it
*/
MUMBLE_PLUGIN_EXPORT void MUMBLE_PLUGIN_CALLING_CONVENTION mumble_setMumbleInfo(
mumble_version_t mumbleVersion, mumble_version_t mumbleAPIVersion, mumble_version_t minimumExpectedAPIVersion);
/**
* Gets the Version of this plugin
*
* NOTE: This function may be called without the plugin being loaded
*
* @returns The plugin's version
*/
MUMBLE_PLUGIN_EXPORT mumble_version_t MUMBLE_PLUGIN_CALLING_CONVENTION mumble_getVersion();
/**
* Gets the name of the plugin author(s).
*
* NOTE: This function may be called without the plugin being loaded
*
* @returns A String-wrapper containing the requested author name(s)
*/
MUMBLE_PLUGIN_EXPORT struct MumbleStringWrapper MUMBLE_PLUGIN_CALLING_CONVENTION mumble_getAuthor();
/**
* Gets the description of the plugin.
*
* NOTE: This function may be called without the plugin being loaded
*
* @returns A String-wrapper containing the requested description
*/
MUMBLE_PLUGIN_EXPORT struct MumbleStringWrapper MUMBLE_PLUGIN_CALLING_CONVENTION mumble_getDescription();
/**
* Gets the feature set of this plugin. The feature set is described by bitwise or'ing the elements of the
* Mumble_PluginFeature enum together.
*
* NOTE: This function may be called without the plugin being loaded
*
* @returns The feature set of this plugin
*/
MUMBLE_PLUGIN_EXPORT uint32_t MUMBLE_PLUGIN_CALLING_CONVENTION mumble_getFeatures();
/**
* Requests this plugin to deactivate the given (sub)set of provided features.
* If this is not possible, the features that can't be deactivated shall be returned by this function.
*
* Example (check if FEATURE_POSITIONAL shall be deactivated):
* @code
* if (features & FEATURE_POSITIONAL) {
* // positional shall be deactivated
* }
* @endcode
*
* @param features The feature set that shall be deactivated
* @returns The feature set that can't be disabled (bitwise or'ed). If all requested features can be disabled, return
* FEATURE_NONE. If none of the requested features can be disabled return the unmodified features parameter.
*/
MUMBLE_PLUGIN_EXPORT uint32_t MUMBLE_PLUGIN_CALLING_CONVENTION mumble_deactivateFeatures(uint32_t features);
// >>>>>>>>>>>>>>>>>>>> POSITIONAL DATA functions <<<<<<<<<<<<<<<<<<<<
/*
* If this plugin wants to provide positional data, the mumble_initPositionalData, mumble_fetchPositionalData
* and mumble_shutdownPositionalData functions have to be implemented together (implementing only a subset
* will yield the same result as if no support for positional data was implemened).
*/
/**
* Indicates that Mumble wants to use this plugin to request positional data. Therefore it should check whether it is
* currently able to do so and allocate memory that is needed for that process. As a parameter this function gets an
* array of names and an array of PIDs. They are of same length and the PID at index i belongs to a program whose name
* is listed at index i in the "name-array".
*
* @param programNames An array of pointers to the program names
* @param programPIDs An array of the corresponding program PIDs
* @param programCount The length of programNames and programPIDs
* @returns The error code. If everything went fine PDEC_OK shall be returned. In that case Mumble will start
* frequently calling fetchPositionalData. If this returns anything but PDEC_OK, Mumble will assume that the plugin is
* (currently) uncapable of providing positional data. In this case this function must not have allocated any memory
* that needs to be cleaned up later on. Depending on the returned error code, Mumble might try to call this function
* again at some point.
*/
MUMBLE_PLUGIN_EXPORT uint8_t MUMBLE_PLUGIN_CALLING_CONVENTION mumble_initPositionalData(const char *const *programNames,
const uint64_t *programPIDs,
size_t programCount);
/**
* Retrieves the positional data. If no data can be fetched, set all float-vectors to 0 and return false.
*
* @param[out] avatarPos A float-array of size 3 representing the cartesian position of the player/avatar in the ingame
* world. One unit represents one meter of distance.
* @param[out] avatarDir A float-array of size 3 representing the cartesian direction-vector of the player/avatar
* ingame (where it is facing).
* @param[out] avatarAxis A float-array of size 3 representing the vector pointing from the toes of the character to
* its head. One unit represents one meter of distance.
* @param[out] cameraPos A float-array of size 3 representing the cartesian position of the camera in the ingame world.
* One unit represents one meter of distance.
* @param[out] cameraDir A float-array of size 3 representing the cartesian direction-vector of the camera ingame
* (where it is facing).
* @param[out] cameraAxis A float-array of size 3 representing a vector from the bottom of the camera to its top. One
* unit represents one meter of distance.
* @param[out] context A pointer to where the pointer to a C-encoded string storing the context of the provided
* positional data shall be written. This context should include information about the server (and team) the player is
* on. Only players with identical context will be able to hear each other's audio. The returned pointer has to remain
* valid until the next invokation of this function or until shutdownPositionalData is called.
* @param[out] identity A pointer to where the pointer to a C-encoded string storing the identity of the player shall
* be written. It can be polled by external scripts from the server and should uniquely identify the player in the
* game. The pointer has to remain valid until the next invokation of this function or until shutdownPositionalData is
* called.
* @returns Whether this plugin can continue delivering positional data. If this function returns false,
* shutdownPositionalData will be called.
*/
MUMBLE_PLUGIN_EXPORT bool MUMBLE_PLUGIN_CALLING_CONVENTION
mumble_fetchPositionalData(float *avatarPos, float *avatarDir, float *avatarAxis, float *cameraPos,
float *cameraDir, float *cameraAxis, const char **context, const char **identity);
/**
* Indicates that this plugin will not be asked for positional data any longer. Thus any memory allocated for this
* purpose should be freed at this point.
*/
MUMBLE_PLUGIN_EXPORT void MUMBLE_PLUGIN_CALLING_CONVENTION mumble_shutdownPositionalData();
/**
* The context in positional data is used to determine whether different positional data sets from different
* clients belong to the same game (and same server). Only if the contexts matches up across these clients,
* will Mumble activate the positional audio effects, as it will assume that these clients are playing the
* same game together.
* The context is set during fetching of the other positional data and is usually something like e.g. the
* current server's name. In order to avoid clashes between different plugins (that most likely work for
* different games), the context is prefixed by Mumble. If this function is not implemented, the name of
* the plugin is used as a prefix (which tends to be the supported game's name), but sometimes a different
* prefix is desirable. For these cases, a custom prefix can be provided through this function.
*
* NOTE that while it is possible to allocate a string for this purpose every time this function is called
* and then letting mumble release the resource again (via mumble_releaseResource), it is generally not the
* advised way of doing things (it may impact overall performance negatively, since this function will be
* called very frequently). Instead you should either return a static string (if your language supports that
* and if it actually fits your needs) or you should allocate a string during mumble_initPositionalData and
* free it in mumble_shutdownPositionalData and when returning the string in this function, tell Mumble that
* the string does not need releasing.
*
* @returns The context prefix to use for positional data fetched by this plugin.
*
* @since Plugin interface v1.1.0
*/
MUMBLE_PLUGIN_EXPORT struct MumbleStringWrapper MUMBLE_PLUGIN_CALLING_CONVENTION
mumble_getPositionalDataContextPrefix();
// >>>>>>>>>>>>>>>>>>>> EVENTHANDLER / CALLBACK functions <<<<<<<<<<<<<<<<<<<<
/**
* Called when connecting to a server.
* Note that in most cases you'll want to use mumble_onServerSynchronized instead.
* Note also that this callback will be called from a DIFFERENT THREAD!
*
* @param connection The ID of the newly established server-connection
*/
MUMBLE_PLUGIN_EXPORT void MUMBLE_PLUGIN_CALLING_CONVENTION mumble_onServerConnected(mumble_connection_t connection);
/**
* Called when disconnecting from a server.
* Note that this callback is called from a DIFFERENT THREAD!
*
* @param connection The ID of the server-connection that has been terminated
*/
MUMBLE_PLUGIN_EXPORT void MUMBLE_PLUGIN_CALLING_CONVENTION mumble_onServerDisconnected(mumble_connection_t connection);
/**
* Called when the client has finished synchronizing with the server
*
* @param connection The ID of the server-connection that has been terminated
*/
MUMBLE_PLUGIN_EXPORT void MUMBLE_PLUGIN_CALLING_CONVENTION mumble_onServerSynchronized(mumble_connection_t connection);
/**
* Called whenever any user on the server enters a channel
* This function will also be called when freshly connecting to a server as each user on that
* server needs to be "added" to the respective channel as far as the local client is concerned.
*
* @param connection The ID of the server-connection this event is connected to
* @param userID The ID of the user this event has been triggered for
* @param previousChannelID The ID of the chanel the user is coming from. Negative IDs indicate that there is no
* previous channel (e.g. the user freshly connected to the server) or the channel isn't available because of any other
* reason.
* @param newChannelID The ID of the channel the user has entered. If the ID is negative, the new channel could not be
* retrieved. This means that the ID is invalid.
*/
MUMBLE_PLUGIN_EXPORT void MUMBLE_PLUGIN_CALLING_CONVENTION mumble_onChannelEntered(mumble_connection_t connection,
mumble_userid_t userID,
mumble_channelid_t previousChannelID,
mumble_channelid_t newChannelID);
/**
* Called whenever a user leaves a channel.
* This includes a client disconnecting from the server as this will also lead to the user not being in that channel
* anymore.
*
* @param connection The ID of the server-connection this event is connected to
* @param userID The ID of the user that left the channel
* @param channelID The ID of the channel the user left. If the ID is negative, the channel could not be retrieved.
* This means that the ID is invalid.
*/
MUMBLE_PLUGIN_EXPORT void MUMBLE_PLUGIN_CALLING_CONVENTION mumble_onChannelExited(mumble_connection_t connection,
mumble_userid_t userID,
mumble_channelid_t channelID);
/**
* Called when any user changes his/her talking state.
*
* @param connection The ID of the server-connection this event is connected to
* @param userID The ID of the user whose talking state has been changed
* @param talkingState The new TalkingState the user has switched to.
*/
MUMBLE_PLUGIN_EXPORT void MUMBLE_PLUGIN_CALLING_CONVENTION mumble_onUserTalkingStateChanged(
mumble_connection_t connection, mumble_userid_t userID, mumble_talking_state_t talkingState);
/**
* Called whenever there is audio input.