-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy path_pjsua.h
3699 lines (3342 loc) · 115 KB
/
_pjsua.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
/* $Id: _pjsua.h 4724 2014-01-31 08:52:09Z nanang $ */
/*
* Copyright (C) 2016 Matthew Williams <mgwilliams@gmail.com>
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PY_PJSUA_H__
#define __PY_PJSUA_H__
#define _CRT_SECURE_NO_DEPRECATE
#include <Python.h>
#include <structmember.h>
#include <pjsua-lib/pjsua.h>
PJ_INLINE(pj_str_t) PyUnicode_ToPJ(const PyObject *obj)
{
pj_str_t str;
if (obj && PyUnicode_Check(obj)) {
str.ptr = PyUnicode_AsUTF8((PyObject *)obj);
str.slen = PyUnicode_GET_SIZE((PyObject *)obj);
} else {
str.ptr = NULL;
str.slen = 0;
}
return str;
}
PJ_INLINE(PyObject*) PyUnicode_FromPJ(const pj_str_t *str)
{
return PyUnicode_FromStringAndSize(str->ptr, str->slen);
}
//////////////////////////////////////////////////////////////////////////////
/*
* PyObj_pjsip_cred_info
*/
typedef struct
{
PyObject_HEAD
/* Type-specific fields go here. */
PyObject *realm;
PyObject *scheme;
PyObject *username;
int data_type;
PyObject *data;
} PyObj_pjsip_cred_info;
/*
* cred_info_dealloc
* deletes a cred info from memory
*/
static void PyObj_pjsip_cred_info_delete(PyObj_pjsip_cred_info* self)
{
Py_XDECREF(self->realm);
Py_XDECREF(self->scheme);
Py_XDECREF(self->username);
Py_XDECREF(self->data);
Py_TYPE(self)->tp_free((PyObject*)self);
}
static void PyObj_pjsip_cred_info_import(PyObj_pjsip_cred_info *obj,
const pjsip_cred_info *cfg)
{
Py_XDECREF(obj->realm);
obj->realm = PyUnicode_FromPJ(&cfg->realm);
Py_XDECREF(obj->scheme);
obj->scheme = PyUnicode_FromPJ(&cfg->scheme);
Py_XDECREF(obj->username);
obj->username = PyUnicode_FromPJ(&cfg->username);
obj->data_type = cfg->data_type;
Py_XDECREF(obj->data);
obj->data = PyUnicode_FromPJ(&cfg->data);
}
static void PyObj_pjsip_cred_info_export(pjsip_cred_info *cfg,
PyObj_pjsip_cred_info *obj)
{
cfg->realm = PyUnicode_ToPJ(obj->realm);
cfg->scheme = PyUnicode_ToPJ(obj->scheme);
cfg->username = PyUnicode_ToPJ(obj->username);
cfg->data_type = obj->data_type;
cfg->data = PyUnicode_ToPJ(obj->data);
}
/*
* cred_info_new
* constructor for cred_info object
*/
static PyObject * PyObj_pjsip_cred_info_new(PyTypeObject *type,
PyObject *args,
PyObject *kwds)
{
PyObj_pjsip_cred_info *self;
PJ_UNUSED_ARG(args);
PJ_UNUSED_ARG(kwds);
self = (PyObj_pjsip_cred_info *)type->tp_alloc(type, 0);
if (self != NULL) {
self->realm = PyBytes_FromString("");
self->scheme = PyBytes_FromString("");
self->username = PyBytes_FromString("");
self->data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
self->data = PyBytes_FromString("");
}
return (PyObject *)self;
}
/*
* PyObj_pjsip_cred_info_members
*/
static PyMemberDef PyObj_pjsip_cred_info_members[] =
{
{
"realm", T_OBJECT_EX,
offsetof(PyObj_pjsip_cred_info, realm), 0,
"Realm"
},
{
"scheme", T_OBJECT_EX,
offsetof(PyObj_pjsip_cred_info, scheme), 0,
"Scheme"
},
{
"username", T_OBJECT_EX,
offsetof(PyObj_pjsip_cred_info, username), 0,
"User name"
},
{
"data", T_OBJECT_EX,
offsetof(PyObj_pjsip_cred_info, data), 0,
"The data, which can be a plaintext password or a hashed digest, "
"depending on the value of data_type"
},
{
"data_type", T_INT,
offsetof(PyObj_pjsip_cred_info, data_type), 0,
"Type of data"
},
{NULL} /* Sentinel */
};
/*
* PyTyp_pjsip_cred_info
*/
static PyTypeObject PyTyp_pjsip_cred_info =
{
PyObject_HEAD_INIT(NULL)
"_pjsua.Pjsip_Cred_Info", /*tp_name*/
sizeof(PyObj_pjsip_cred_info), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor) PyObj_pjsip_cred_info_delete,/*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"PJSIP credential information", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
PyObj_pjsip_cred_info_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyObj_pjsip_cred_info_new, /* tp_new */
};
//////////////////////////////////////////////////////////////////////////////
/*
* PyObj_pjsua_callback
* C/python typewrapper for callback struct
*/
typedef struct PyObj_pjsua_callback
{
PyObject_HEAD
/* Type-specific fields go here. */
PyObject * on_call_state;
PyObject * on_incoming_call;
PyObject * on_call_media_state;
PyObject * on_dtmf_digit;
PyObject * on_call_transfer_request;
PyObject * on_call_transfer_status;
PyObject * on_call_replace_request;
PyObject * on_call_replaced;
PyObject * on_reg_state;
PyObject * on_incoming_subscribe;
PyObject * on_buddy_state;
PyObject * on_pager;
PyObject * on_pager_status;
PyObject * on_typing;
PyObject * on_mwi_info;
} PyObj_pjsua_callback;
/*
* PyObj_pjsua_callback_delete
* destructor function for callback struct
*/
static void PyObj_pjsua_callback_delete(PyObj_pjsua_callback* self)
{
Py_XDECREF(self->on_call_state);
Py_XDECREF(self->on_incoming_call);
Py_XDECREF(self->on_call_media_state);
Py_XDECREF(self->on_dtmf_digit);
Py_XDECREF(self->on_call_transfer_request);
Py_XDECREF(self->on_call_transfer_status);
Py_XDECREF(self->on_call_replace_request);
Py_XDECREF(self->on_call_replaced);
Py_XDECREF(self->on_reg_state);
Py_XDECREF(self->on_incoming_subscribe);
Py_XDECREF(self->on_buddy_state);
Py_XDECREF(self->on_pager);
Py_XDECREF(self->on_pager_status);
Py_XDECREF(self->on_typing);
Py_XDECREF(self->on_mwi_info);
Py_TYPE(self)->tp_free((PyObject*)self);
}
/*
* PyObj_pjsua_callback_new
* * declares constructor for callback struct
*/
static PyObject * PyObj_pjsua_callback_new(PyTypeObject *type,
PyObject *args,
PyObject *kwds)
{
PyObj_pjsua_callback *self;
PJ_UNUSED_ARG(args);
PJ_UNUSED_ARG(kwds);
self = (PyObj_pjsua_callback *)type->tp_alloc(type, 0);
if (self != NULL) {
self->on_call_state = Py_BuildValue("");
self->on_incoming_call = Py_BuildValue("");
self->on_call_media_state = Py_BuildValue("");
self->on_dtmf_digit = Py_BuildValue("");
self->on_call_transfer_request = Py_BuildValue("");
self->on_call_transfer_status = Py_BuildValue("");
self->on_call_replace_request = Py_BuildValue("");
self->on_call_replaced = Py_BuildValue("");
self->on_reg_state = Py_BuildValue("");
self->on_incoming_subscribe = Py_BuildValue("");
self->on_buddy_state = Py_BuildValue("");
self->on_pager = Py_BuildValue("");
self->on_pager_status = Py_BuildValue("");
self->on_typing = Py_BuildValue("");
self->on_mwi_info = Py_BuildValue("");
}
return (PyObject *)self;
}
/*
* PyObj_pjsua_callback_members
* declares available functions for callback object
*/
static PyMemberDef PyObj_pjsua_callback_members[] =
{
{
"on_call_state", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_call_state), 0,
"Notify application when invite state has changed. Application may "
"then query the call info to get the detail call states."
},
{
"on_incoming_call", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_incoming_call), 0,
"Notify application on incoming call."
},
{
"on_call_media_state", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_call_media_state), 0,
"Notify application when media state in the call has changed. Normal "
"application would need to implement this callback, e.g. to connect "
"the call's media to sound device."
},
{
"on_dtmf_digit", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_dtmf_digit), 0,
"Notify application upon receiving incoming DTMF digit."
},
{
"on_call_transfer_request", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_call_transfer_request), 0,
"Notify application on call being transferred. "
"Application can decide to accept/reject transfer request "
"by setting the code (default is 200). When this callback "
"is not defined, the default behavior is to accept the "
"transfer."
},
{
"on_call_transfer_status", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_call_transfer_status), 0,
"Notify application of the status of previously sent call "
"transfer request. Application can monitor the status of the "
"call transfer request, for example to decide whether to "
"terminate existing call."
},
{
"on_call_replace_request", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_call_replace_request), 0,
"Notify application about incoming INVITE with Replaces header. "
"Application may reject the request by setting non-2xx code."
},
{
"on_call_replaced", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_call_replaced), 0,
"Notify application that an existing call has been replaced with "
"a new call. This happens when PJSUA-API receives incoming INVITE "
"request with Replaces header."
" "
"After this callback is called, normally PJSUA-API will disconnect "
"old_call_id and establish new_call_id."
},
{
"on_reg_state", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_reg_state), 0,
"Notify application when registration status has changed. Application "
"may then query the account info to get the registration details."
},
{
"on_incoming_subscribe", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_incoming_subscribe), 0,
"Notification when incoming SUBSCRIBE request is received."
},
{
"on_buddy_state", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_buddy_state), 0,
"Notify application when the buddy state has changed. Application may "
"then query the buddy into to get the details."
},
{
"on_pager", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_pager), 0,
"Notify application on incoming pager (i.e. MESSAGE request). "
"Argument call_id will be -1 if MESSAGE request is not related to an "
"existing call."
},
{
"on_pager_status", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_pager_status), 0,
"Notify application about the delivery status of outgoing pager "
"request."
},
{
"on_typing", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_typing), 0,
"Notify application about typing indication."
},
{
"on_mwi_info", T_OBJECT_EX,
offsetof(PyObj_pjsua_callback, on_mwi_info), 0,
"Notify application about MWI indication."
},
{NULL} /* Sentinel */
};
/*
* PyTyp_pjsua_callback
* callback class definition
*/
static PyTypeObject PyTyp_pjsua_callback =
{
PyObject_HEAD_INIT(NULL)
"_pjsua.Callback", /*tp_name*/
sizeof(PyObj_pjsua_callback), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)PyObj_pjsua_callback_delete, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"This structure describes application callback "
"to receive various event notifications from "
"PJSUA-API", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
PyObj_pjsua_callback_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyObj_pjsua_callback_new, /* tp_new */
};
//////////////////////////////////////////////////////////////////////////////
/*
* PyObj_pjsua_media_config
* C/Python wrapper for pjsua_media_config object
*/
typedef struct
{
PyObject_HEAD
/* Type-specific fields go here. */
unsigned clock_rate;
unsigned snd_clock_rate;
unsigned channel_count;
unsigned audio_frame_ptime;
int snd_auto_close_time;
unsigned max_media_ports;
int has_ioqueue;
unsigned thread_cnt;
unsigned quality;
unsigned ptime;
int no_vad;
unsigned ilbc_mode;
unsigned tx_drop_pct;
unsigned rx_drop_pct;
unsigned ec_options;
unsigned ec_tail_len;
int jb_min;
int jb_max;
int enable_ice;
int enable_turn;
PyObject *turn_server;
int turn_conn_type;
PyObject *turn_realm;
PyObject *turn_username;
int turn_passwd_type;
PyObject *turn_passwd;
} PyObj_pjsua_media_config;
/*
* PyObj_pjsua_media_config_members
* declares attributes accessible from both C and Python for media_config file
*/
static PyMemberDef PyObj_pjsua_media_config_members[] =
{
{
"clock_rate", T_INT,
offsetof(PyObj_pjsua_media_config, clock_rate), 0,
"Clock rate to be applied to the conference bridge. If value is zero, "
"default clock rate will be used (16KHz)."
},
{
"snd_clock_rate", T_INT,
offsetof(PyObj_pjsua_media_config, snd_clock_rate), 0,
"Specify different clock rate of sound device, otherwise 0."
},
{
"channel_count", T_INT,
offsetof(PyObj_pjsua_media_config, channel_count), 0,
"Specify channel count (default 1)."
},
{
"audio_frame_ptime", T_INT,
offsetof(PyObj_pjsua_media_config, audio_frame_ptime), 0,
"Audio frame length in milliseconds."
},
{
"snd_auto_close_time", T_INT,
offsetof(PyObj_pjsua_media_config, snd_auto_close_time), 0,
"Sound idle time before it's closed."
},
{
"max_media_ports", T_INT,
offsetof(PyObj_pjsua_media_config, max_media_ports), 0,
"Specify maximum number of media ports to be created in the "
"conference bridge. Since all media terminate in the bridge (calls, "
"file player, file recorder, etc), the value must be large enough to "
"support all of them. However, the larger the value, the more "
"computations are performed."
},
{
"has_ioqueue", T_INT,
offsetof(PyObj_pjsua_media_config, has_ioqueue), 0,
"Specify whether the media manager should manage its own ioqueue for "
"the RTP/RTCP sockets. If yes, ioqueue will be created and at least "
"one worker thread will be created too. If no, the RTP/RTCP sockets "
"will share the same ioqueue as SIP sockets, and no worker thread is "
"needed."
},
{
"thread_cnt", T_INT,
offsetof(PyObj_pjsua_media_config, thread_cnt), 0,
"Specify the number of worker threads to handle incoming RTP packets. "
"A value of one is recommended for most applications."
},
{
"quality", T_INT,
offsetof(PyObj_pjsua_media_config, quality), 0,
"The media quality also sets speex codec quality/complexity to the "
"number."
},
{
"ptime", T_INT,
offsetof(PyObj_pjsua_media_config, ptime), 0,
"Specify default ptime."
},
{
"no_vad", T_INT,
offsetof(PyObj_pjsua_media_config, no_vad), 0,
"Disable VAD?"
},
{
"ilbc_mode", T_INT,
offsetof(PyObj_pjsua_media_config, ilbc_mode), 0,
"iLBC mode (20 or 30)."
},
{
"tx_drop_pct", T_INT,
offsetof(PyObj_pjsua_media_config, tx_drop_pct), 0,
"Percentage of RTP packet to drop in TX direction (to simulate packet "
"lost)."
},
{
"rx_drop_pct", T_INT,
offsetof(PyObj_pjsua_media_config, rx_drop_pct), 0,
"Percentage of RTP packet to drop in RX direction (to simulate packet "
"lost)."},
{
"ec_options", T_INT,
offsetof(PyObj_pjsua_media_config, ec_options), 0,
"Echo canceller options (see pjmedia_echo_create())"
},
{
"ec_tail_len", T_INT,
offsetof(PyObj_pjsua_media_config, ec_tail_len), 0,
"Echo canceller tail length, in miliseconds."
},
{
"jb_min", T_INT,
offsetof(PyObj_pjsua_media_config, jb_min), 0,
"Jitter buffer minimum size in milliseconds."
},
{
"jb_max", T_INT,
offsetof(PyObj_pjsua_media_config, jb_max), 0,
"Jitter buffer maximum size in milliseconds."
},
{
"enable_ice", T_INT,
offsetof(PyObj_pjsua_media_config, enable_ice), 0,
"Enable ICE."
},
{
"enable_turn", T_INT,
offsetof(PyObj_pjsua_media_config, enable_turn), 0,
"Enable TURN."
},
{
"turn_server", T_OBJECT_EX,
offsetof(PyObj_pjsua_media_config, turn_server), 0,
"Specify the TURN server."
},
{
"turn_conn_type", T_INT,
offsetof(PyObj_pjsua_media_config, turn_conn_type), 0,
"Specify TURN connection type."
},
{
"turn_realm", T_OBJECT_EX,
offsetof(PyObj_pjsua_media_config, turn_realm), 0,
"Specify the TURN realm."
},
{
"turn_username", T_OBJECT_EX,
offsetof(PyObj_pjsua_media_config, turn_username), 0,
"Specify the TURN username."
},
{
"turn_passwd_type", T_INT,
offsetof(PyObj_pjsua_media_config, turn_passwd_type), 0,
"Specify TURN password type."
},
{
"turn_passwd", T_OBJECT_EX,
offsetof(PyObj_pjsua_media_config, turn_passwd), 0,
"Specify the TURN password."
},
{NULL} /* Sentinel */
};
static PyObject *PyObj_pjsua_media_config_new(PyTypeObject *type,
PyObject *args,
PyObject *kwds)
{
PyObj_pjsua_media_config *self;
PJ_UNUSED_ARG(args);
PJ_UNUSED_ARG(kwds);
self = (PyObj_pjsua_media_config*)type->tp_alloc(type, 0);
if (self != NULL) {
self->turn_server = PyBytes_FromString("");
self->turn_realm = PyBytes_FromString("");
self->turn_username = PyBytes_FromString("");
self->turn_passwd = PyBytes_FromString("");
}
return (PyObject *)self;
}
static void PyObj_pjsua_media_config_delete(PyObj_pjsua_media_config * self)
{
Py_XDECREF(self->turn_server);
Py_XDECREF(self->turn_realm);
Py_XDECREF(self->turn_username);
Py_XDECREF(self->turn_passwd);
Py_TYPE(self)->tp_free((PyObject*)self);
}
static void PyObj_pjsua_media_config_import(PyObj_pjsua_media_config *obj,
const pjsua_media_config *cfg)
{
obj->clock_rate = cfg->clock_rate;
obj->snd_clock_rate = cfg->snd_clock_rate;
obj->channel_count = cfg->channel_count;
obj->audio_frame_ptime = cfg->audio_frame_ptime;
obj->snd_auto_close_time= cfg->snd_auto_close_time;
obj->max_media_ports = cfg->max_media_ports;
obj->has_ioqueue = cfg->has_ioqueue;
obj->thread_cnt = cfg->thread_cnt;
obj->quality = cfg->quality;
obj->ptime = cfg->ptime;
obj->no_vad = cfg->no_vad;
obj->ilbc_mode = cfg->ilbc_mode;
obj->jb_min = cfg->jb_min_pre;
obj->jb_max = cfg->jb_max;
obj->tx_drop_pct = cfg->tx_drop_pct;
obj->rx_drop_pct = cfg->rx_drop_pct;
obj->ec_options = cfg->ec_options;
obj->ec_tail_len = cfg->ec_tail_len;
obj->enable_ice = cfg->enable_ice;
obj->enable_turn = cfg->enable_turn;
Py_XDECREF(obj->turn_server);
obj->turn_server = PyUnicode_FromPJ(&cfg->turn_server);
obj->turn_conn_type = cfg->turn_conn_type;
if (cfg->turn_auth_cred.type == PJ_STUN_AUTH_CRED_STATIC) {
const pj_stun_auth_cred *cred = &cfg->turn_auth_cred;
Py_XDECREF(obj->turn_realm);
obj->turn_realm = PyUnicode_FromPJ(&cred->data.static_cred.realm);
Py_XDECREF(obj->turn_username);
obj->turn_username = PyUnicode_FromPJ(&cred->data.static_cred.username);
obj->turn_passwd_type = cred->data.static_cred.data_type;
Py_XDECREF(obj->turn_passwd);
obj->turn_passwd = PyUnicode_FromPJ(&cred->data.static_cred.data);
} else {
Py_XDECREF(obj->turn_realm);
obj->turn_realm = PyBytes_FromString("");
Py_XDECREF(obj->turn_username);
obj->turn_username = PyBytes_FromString("");
obj->turn_passwd_type = 0;
Py_XDECREF(obj->turn_passwd);
obj->turn_passwd = PyBytes_FromString("");
}
}
static void PyObj_pjsua_media_config_export(pjsua_media_config *cfg,
const PyObj_pjsua_media_config *obj)
{
cfg->clock_rate = obj->clock_rate;
cfg->snd_clock_rate = obj->snd_clock_rate;
cfg->channel_count = obj->channel_count;
cfg->audio_frame_ptime = obj->audio_frame_ptime;
cfg->snd_auto_close_time=obj->snd_auto_close_time;
cfg->max_media_ports = obj->max_media_ports;
cfg->has_ioqueue = obj->has_ioqueue;
cfg->thread_cnt = obj->thread_cnt;
cfg->quality = obj->quality;
cfg->ptime = obj->ptime;
cfg->no_vad = obj->no_vad;
cfg->jb_min_pre = obj->jb_min;
cfg->jb_max = obj->jb_max;
cfg->ilbc_mode = obj->ilbc_mode;
cfg->tx_drop_pct = obj->tx_drop_pct;
cfg->rx_drop_pct = obj->rx_drop_pct;
cfg->ec_options = obj->ec_options;
cfg->ec_tail_len = obj->ec_tail_len;
cfg->enable_ice = obj->enable_ice;
cfg->enable_turn = obj->enable_turn;
if (cfg->enable_turn) {
cfg->turn_server = PyUnicode_ToPJ(obj->turn_server);
cfg->turn_conn_type = obj->turn_conn_type;
cfg->turn_auth_cred.type = PJ_STUN_AUTH_CRED_STATIC;
cfg->turn_auth_cred.data.static_cred.realm = PyUnicode_ToPJ(obj->turn_realm);
cfg->turn_auth_cred.data.static_cred.username = PyUnicode_ToPJ(obj->turn_username);
cfg->turn_auth_cred.data.static_cred.data_type= obj->turn_passwd_type;
cfg->turn_auth_cred.data.static_cred.data = PyUnicode_ToPJ(obj->turn_passwd);
}
}
/*
* PyTyp_pjsua_media_config
*/
static PyTypeObject PyTyp_pjsua_media_config =
{
PyObject_HEAD_INIT(NULL)
"_pjsua.Media_Config", /*tp_name*/
sizeof(PyObj_pjsua_media_config),/*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)PyObj_pjsua_media_config_delete,/*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"Media Config objects", /*tp_doc*/
0, /*tp_traverse*/
0, /*tp_clear*/
0, /*tp_richcompare*/
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
PyObj_pjsua_media_config_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyObj_pjsua_media_config_new, /* tp_new */
};
//////////////////////////////////////////////////////////////////////////////
/*
* PyObj_pjsua_config
* attribute list for config object
*/
typedef struct
{
PyObject_HEAD
/* Type-specific fields go here. */
unsigned max_calls;
unsigned thread_cnt;
PyObject *outbound_proxy;
PyObject *stun_domain;
PyObject *stun_host;
PyListObject *nameserver;
PyObj_pjsua_callback *cb;
PyObject *user_agent;
} PyObj_pjsua_config;
static void PyObj_pjsua_config_delete(PyObj_pjsua_config* self)
{
Py_XDECREF(self->outbound_proxy);
Py_XDECREF(self->stun_domain);
Py_XDECREF(self->stun_host);
Py_XDECREF(self->nameserver);
Py_XDECREF(self->cb);
Py_XDECREF(self->user_agent);
Py_TYPE(self)->tp_free((PyObject*)self);
}
static void PyObj_pjsua_config_import(PyObj_pjsua_config *obj,
const pjsua_config *cfg)
{
unsigned i;
obj->max_calls = cfg->max_calls;
obj->thread_cnt = cfg->thread_cnt;
Py_XDECREF(obj->outbound_proxy);
if (cfg->outbound_proxy_cnt)
obj->outbound_proxy = PyUnicode_FromPJ(&cfg->outbound_proxy[0]);
else
obj->outbound_proxy = PyBytes_FromString("");
Py_XDECREF(obj->stun_domain);
obj->stun_domain = PyUnicode_FromPJ(&cfg->stun_domain);
Py_XDECREF(obj->stun_host);
obj->stun_host = PyUnicode_FromPJ(&cfg->stun_host);
Py_XDECREF(obj->nameserver);
obj->nameserver = (PyListObject *)PyList_New(0);
for (i=0; i<cfg->nameserver_count; ++i) {
PyObject * str;
str = PyUnicode_FromPJ(&cfg->nameserver[i]);
PyList_Append((PyObject *)obj->nameserver, str);
}
Py_XDECREF(obj->user_agent);
obj->user_agent = PyUnicode_FromPJ(&cfg->user_agent);
}
static void PyObj_pjsua_config_export(pjsua_config *cfg,
PyObj_pjsua_config *obj)
{
unsigned i;
cfg->max_calls = obj->max_calls;
cfg->thread_cnt = obj->thread_cnt;
if (PyBytes_Size(obj->outbound_proxy) > 0) {
cfg->outbound_proxy_cnt = 1;
cfg->outbound_proxy[0] = PyUnicode_ToPJ(obj->outbound_proxy);
} else {
cfg->outbound_proxy_cnt = 0;
}
cfg->nameserver_count = PyList_Size((PyObject*)obj->nameserver);
if (cfg->nameserver_count > PJ_ARRAY_SIZE(cfg->nameserver))
cfg->nameserver_count = PJ_ARRAY_SIZE(cfg->nameserver);
for (i = 0; i < cfg->nameserver_count; i++) {
PyObject *item = PyList_GetItem((PyObject *)obj->nameserver,i);
cfg->nameserver[i] = PyUnicode_ToPJ(item);
}
cfg->stun_domain = PyUnicode_ToPJ(obj->stun_domain);
cfg->stun_host = PyUnicode_ToPJ(obj->stun_host);
cfg->user_agent = PyUnicode_ToPJ(obj->user_agent);
}
static PyObject *PyObj_pjsua_config_new(PyTypeObject *type,
PyObject *args,
PyObject *kwds)
{
PyObj_pjsua_config *self;
PJ_UNUSED_ARG(args);
PJ_UNUSED_ARG(kwds);
self = (PyObj_pjsua_config *)type->tp_alloc(type, 0);
if (self != NULL) {
self->user_agent = PyBytes_FromString("");
self->outbound_proxy = PyBytes_FromString("");
self->stun_domain = PyBytes_FromString("");
self->stun_host = PyBytes_FromString("");
self->cb = (PyObj_pjsua_callback *)
PyType_GenericNew(&PyTyp_pjsua_callback, NULL, NULL);
}
return (PyObject *)self;
}
/*
* PyObj_pjsua_config_members
* attribute list accessible from Python/C
*/
static PyMemberDef PyObj_pjsua_config_members[] =
{
{
"max_calls", T_INT,
offsetof(PyObj_pjsua_config, max_calls), 0,
"Maximum calls to support (default: 4) "
},
{
"thread_cnt", T_INT,
offsetof(PyObj_pjsua_config, thread_cnt), 0,
"Number of worker threads. Normally application will want to have at "
"least one worker thread, unless when it wants to poll the library "
"periodically, which in this case the worker thread can be set to "
"zero."
},
{
"outbound_proxy", T_OBJECT_EX,
offsetof(PyObj_pjsua_config, outbound_proxy), 0,
"SIP URL of the outbound proxy (optional)"
},
{
"stun_domain", T_OBJECT_EX,
offsetof(PyObj_pjsua_config, stun_domain), 0,
"Domain of the STUN server (optional). STUN server will be resolved "
"using DNS SRV resolution only when nameserver is configured. "
"Alternatively, if DNS SRV resolution for STUN is not desired, "
"application can specify the STUN server hostname or IP address "
"in stun_host attribute."
},
{
"stun_host", T_OBJECT_EX,
offsetof(PyObj_pjsua_config, stun_host), 0,
"Hostname or IP address of the STUN server (optional)."
},
{
"nameserver", T_OBJECT_EX,
offsetof(PyObj_pjsua_config, nameserver), 0,
"IP address of the nameserver."
},
{
"cb", T_OBJECT_EX, offsetof(PyObj_pjsua_config, cb), 0,
"Application callback."
},
{
"user_agent", T_OBJECT_EX, offsetof(PyObj_pjsua_config, user_agent), 0,
"User agent string (default empty)"
},
{NULL} /* Sentinel */
};
/*
* PyTyp_pjsua_config
* type wrapper for config class
*/
static PyTypeObject PyTyp_pjsua_config =
{
PyObject_HEAD_INIT(NULL)
"_pjsua.Config", /*tp_name*/
sizeof(PyObj_pjsua_config),/*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)PyObj_pjsua_config_delete,/*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"Config object", /* tp_doc */
0, /* tp_traverse */