-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdevjournal
More file actions
2645 lines (2063 loc) · 104 KB
/
devjournal
File metadata and controls
2645 lines (2063 loc) · 104 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
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
------------------------------------------------------------
2019/05/25 takeshi:
Development and test using node v10.15.3
------------------------------------------------------------
2019/06/08 takeshi:
We needed to use pjproject built from source to permit to debug it as pjw_call_respond gets stuck.
To be able to generate addon.node SO file we needed to build pjsip with -pPIC by doing:
cd pjproject-2.7.2
cat > user.mak <<EOF
export CFLAGS += -fPIC -g
export LDFLAGS +=
EOF
./configure
make dep && make clean && make
After preparing binding.gyp to use pjproject built from source, build of addon was successful:
takeshi@takeshi-desktop:node-sip$ node-gyp configure
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@10.15.3 | linux | x64
gyp info spawn /usr/bin/python2
gyp info spawn args [ '/home/takeshi/.nvm/versions/node/v10.15.3/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/home/takeshi/src/git/themonks/node-sip/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/home/takeshi/.nvm/versions/node/v10.15.3/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/home/takeshi/.node-gyp/10.15.3/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/home/takeshi/.node-gyp/10.15.3',
gyp info spawn args '-Dnode_gyp_dir=/home/takeshi/.nvm/versions/node/v10.15.3/lib/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/home/takeshi/.node-gyp/10.15.3/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/home/takeshi/src/git/themonks/node-sip',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.' ]
ngyp info ok
takeshi@takeshi-desktop:node-sip$ node-gyp build
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@10.15.3 | linux | x64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/takeshi/src/git/themonks/node-sip/build'
SOLINK_MODULE(target) Release/obj.target/addon.node
COPY Release/addon.node
make: Leaving directory '/home/takeshi/src/git/themonks/node-sip/build'
gyp info ok
Howevever, when trying to use it we got:
takeshi@takeshi-desktop:node-sip$ node test.js
internal/modules/cjs/loader.js:730
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: /home/takeshi/src/git/themonks/node-sip/build/Release/addon.node: undefined symbol: srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80
at Object.Module._extensions..node (internal/modules/cjs/loader.js:730:18)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/home/takeshi/src/git/themonks/node-sip/index.js:1:77)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
This was solved by checking the pjproject from apt dependencies:
takeshi@takeshi-desktop:node-sip$ pkg-config --libs libpjproject
-lpjsua2 -lstdc++ -lpjsua -lpjsip-ua -lpjsip-simple -lpjsip -lpjmedia-codec -lpjmedia -lpjmedia-videodev -lpjmedia-audiodev -lpjmedia -lpjnath -lpjlib-util -lsrtp2 -lpj -lopus -lssl -lcrypto -luuid -lm -lrt -lpthread -lasound -lSDL2 -lavdevice -lavformat -lavcodec -lswscale -lavutil -lv4l2 -lopencore-amrnb -lopencore-amrwb -lvo-amrwbenc
and adding them to the binding.gyp link_settings.libraries.
It also complained about a function from libspeex which was not mentioned in the the pkg-config output. So we addded it.
Then, it failed with:
takeshi@takeshi-desktop:node-sip$ node test.js
pjw_init thread_id=1319614176
22:39:16.787 os_core_unix.c !pjlib 2.7.2 for POSIX initialized
node: symbol lookup error: /home/takeshi/src/git/themonks/node-sip/build/Release/addon.node: undefined symbol: pj_cis_buf_init
We found this in libpjlib-util:
takeshi@takeshi-desktop:node-sip$ nm pjproject-2.7.2/pjlib-util/lib/libpjlib-util-x86_64-unknown-linux-gnu.a |grep pj_cis
U pj_cis_add_str
U pj_cis_buf_init
U pj_cis_init
0000000000000170 T pj_cis_add_alpha
00000000000001f0 T pj_cis_add_cis
00000000000001a0 T pj_cis_add_num
0000000000000100 T pj_cis_add_range
00000000000001b0 T pj_cis_add_str
0000000000000000 T pj_cis_buf_init
0000000000000230 T pj_cis_del_range
0000000000000270 T pj_cis_del_str
0000000000000090 T pj_cis_dup
0000000000000040 T pj_cis_init
00000000000002b0 T pj_cis_invert
takeshi@takeshi-desktop:node-sip$ nm pjproject-2.7.2/pjlib-util/lib/libpjlib-util-x86_64-unknown-linux-gnu.a |grep pj_cis_buf_init
U pj_cis_buf_init
0000000000000000 T pj_cis_buf_init
We solved the above by putting -lpjlib-util-x86_64-unknown-linux-gnu as the last library in the list of pjprojects libs.
------------------------------------------------------------
2019/06/08 takeshi:
Problem of having pjw_call_respond stuck was narrowed down to:
pjsip/src/pjsip-ua/sip_inv.c
in function
pjsip_inv_answer
The code stops at this line:
pjsip_dlg_inc_lock(inv->dlg);
We tried to use latest pjproject 2.8 but the same problem happens.
UPDATE:
this is happening because pjsip get stuck in call to pjsip_mutex_lock.
It seems the cause is because we are using a separate thread (boost/thread) to do periodic poll of events
So we changed to make js to periodically do the poll and after that pjw_call_respond worked as expected.
Obs: while investigating this issue, we found this:
#####
Deadlocks
A deadlock is a situation wherein two or more competing actions are waiting for the other to finish, and thus neither ever does.
The internal PJSIP synchronization should be free from deadlock problem. However, deadlock may still arise when PJSIP has to interract with application's mutex.
To avoid deadlock introduced by application's mutex, the following rule MUST be obeyed at all times:
Mutexes MUST always be acquired with the same order, and the order is:
acquire PJSIP mutex first, then
acquire application mutex.
###
https://www.pjsip.org/locking.htm
However, to confirm this is not related to the problem we replaced this:
#define PJW_LOCK() pthread_mutex_lock(&g_mutex)
#define PJW_UNLOCK() pthread_mutex_unlock(&g_mutex)
with this:
#define PJW_LOCK() printf("");
#define PJW_UNLOCK() printf("");
and the problem persisted.
------------------------------------------------------------
2019/06/08 takeshi:
Due to:
https://trac.pjsip.org/repos/changeset/5942
we reverted from pjproject-2.8 to pjproject-2.7.2
------------------------------------------------------------
2019/06/08 takeshi:
Failure to compile due change in definition of struct pjmedia_port_info:
takeshi@takeshi-desktop:node-sip$ node-gyp build
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@10.15.3 | linux | x64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/takeshi/src/git/themonks/node-sip/build'
CC(target) Release/obj.target/addon/src/pjmedia/src/pjmedia/dtmfdet.o
../src/pjmedia/src/pjmedia/dtmfdet.c: In function ‘pjmedia_dtmfdet_create’:
../src/pjmedia/src/pjmedia/dtmfdet.c:90:29: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
dtmfdet->base.put_frame = &dtmfdet_put_frame;
^
../src/pjmedia/src/pjmedia/dtmfdet.c: In function ‘dtmfdet_put_frame’:
../src/pjmedia/src/pjmedia/dtmfdet.c:115:19: error: ‘pjmedia_port_info {aka struct pjmedia_port_info}’ has no member named ‘samples_per_frame’
dport->base.info.samples_per_frame);
^
addon.target.mk:133: recipe for target 'Release/obj.target/addon/src/pjmedia/src/pjmedia/dtmfdet.o' failed
make: *** [Release/obj.target/addon/src/pjmedia/src/pjmedia/dtmfdet.o] Error 1
make: Leaving directory '/home/takeshi/src/git/themonks/node-sip/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/home/takeshi/.nvm/versions/node/v10.15.3/lib/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:189:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 4.15.0-43-generic
gyp ERR! command "/home/takeshi/.nvm/versions/node/v10.15.3/bin/node" "/home/takeshi/.nvm/versions/node/v10.15.3/bin/node-gyp" "build"
gyp ERR! cwd /home/takeshi/src/git/themonks/node-sip
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
UPDATE: actually dtmfdet.c is not necessary as it was just a plain pjmedia sample. Same for simpleua_dtmfdet.c.
So these were removed from binding.gyp target sources list.
------------------------------------------------------------
2020/08/02 takeshi:
Installation using 'npm install' tested on Ubuntu 18.04.
------------------------------------------------------------
2020/08/08 takeshi:
When trying to build on Debian 10 I got:
$ npm install
npm WARN lifecycle sip-lab@1.0.0~install: cannot run in wd sip-lab@1.0.0 ./install.sh (wd=/usr/local/src/git/github_MayamaTakeshi/sip-lab)
audited 124 packages in 2.618s
found 0 vulnerabilities
But the process exit without error:
$ echo $?
0
which is bad because the addon was left unbuilt.
I had to use:
npm install --unsafe-perm
otherwise, it doesn't run the install.sh script
Then build went further but now I got:
CXX(target) Release/obj.target/addon/src/addon.o
../src/addon.cpp: In function 'Napi::Object init(Napi::Env, Napi::Object)':
../src/addon.cpp:1361:60: error: no matching function for call to 'Napi::Function::New(Napi::Env&, <unresolved overloaded function type>)'
exports.Set("shutdown", Napi::Function::New(env, shutdown));
^
In file included from /usr/local/src/git/github_MayamaTakeshi/sip-lab/node_modules/node-addon-api/napi.h:2051,
from ../src/addon.cpp:3:
/usr/local/src/git/github_MayamaTakeshi/sip-lab/node_modules/node-addon-api/napi-inl.h:1678:17: note: candidate: 'template<class Callable> static Napi::Function Napi::Function::New(napi_env, Callable, con
st char*, void*)'
inline Function Function::New(napi_env env,
^~~~~~~~
/usr/local/src/git/github_MayamaTakeshi/sip-lab/node_modules/node-addon-api/napi-inl.h:1678:17: note: template argument deduction/substitution failed:
../src/addon.cpp:1361:60: note: couldn't deduce template parameter 'Callable'
exports.Set("shutdown", Napi::Function::New(env, shutdown));
^
Suspecting the name shutdown was conflicting with something else, I renamed the function as
shutdown_
and after that, build went further.
But then I got:
/usr/bin/ld: cannot find -lsrtp
collect2: error: ld returned 1 exit status
make: *** [addon.target.mk:226: Release/obj.target/addon.node] Error 1
make: Leaving directory '/usr/local/src/git/github_MayamaTakeshi/sip-lab/build'
This seems to be because in Debian 10, srtp library changed from libsrtp to libsrtp2.
But, actually, we should not use OS libs and instead we should the ThirdParty ones.
And in the binding.gyp we were actually using this unnecessary line:
'-lsrtp',
But we already got this one:
'-L ../pjproject/third_party/lib',
So, I removed '-lsrtp' and built was successful but then when running the sample I got:
$ node samples/simple.js
internal/modules/cjs/loader.js:730
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: /usr/local/src/git/github_MayamaTakeshi/sip-lab/build/Release/addon.node: undefined symbol: crypto_policy_set_aes_cm_256_hmac_sha1_80
at Object.Module._extensions..node (internal/modules/cjs/loader.js:730:18)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/usr/local/src/git/github_MayamaTakeshi/sip-lab/index.js:1:77)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
So I disable SRTP by setting:
#define PJMEDIA_HAS_SRTP 0
in config_site.h
However, when trying to run
node samples/simple.js
we are frequently (almost all the time) getting this:
$ node samples/simple.js
pjw_init thread_id=583253000
21:12:20.187 os_core_unix.c !pjlib 2.5.5-svn for POSIX initialized
undefined
t1 { id: 0, ip: '127.0.0.1', port: 5090 }
t2 { id: 1, ip: '127.0.0.1', port: 5092 }
inv=22c3c118 tdata=3779318
on_state_changed
status=583254296
21:12:20.260 !: Success
wait (line /usr/local/src/git/github_MayamaTakeshi/sip-lab/samples/simple.js:24) started. Waiting for expected_events:
[
partial_match({
event: 'incoming_call',
call_id: collect['call_id']()
}),
partial_match({
event: 'response',
call_id: 0,
method: 'INVITE',
msg: sip_msg({
$rs: '100',
$rr: 'Trying',
$(hdrcnt(via)): 1,
$hdr(call-id): collect['sip_call_id'](),
$fU: 'a',
$fd: 't',
$tU: 'b',
$hdr(l): '0'
})
})
]
Segmentation fault
Checking with gdb:
Thread 1 "node" received signal SIGSEGV, Segmentation fault.
__strlen_sse2 () at ../sysdeps/x86_64/multiarch/../strlen.S:120
120 ../sysdeps/x86_64/multiarch/../strlen.S: No such file or directory.
(gdb) bt
#0 0x00007ffff7b40206 in __strlen_sse2 () at ../sysdeps/x86_64/multiarch/../strlen.S:120
#1 0x00007ffff7af99ef in _IO_vfprintf_internal (s=0x7fffffff6af0, format=0x7ffff52533ec "on_rx_request %.*s\n\n", ap=0x7fffffff91b0) at vfprintf.c:1638
#2 0x00007ffff7afa866 in buffered_vfprintf (s=s@entry=0x7ffff7c64760 <_IO_2_1_stdout_>, format=format@entry=0x7ffff52533ec "on_rx_request %.*s\n\n", args=args@entry=0x7fffffff91b0) at vfprintf.c:2322
#3 0x00007ffff7af7eb2 in _IO_vfprintf_internal (s=0x7ffff7c64760 <_IO_2_1_stdout_>, format=0x7ffff52533ec "on_rx_request %.*s\n\n", ap=ap@entry=0x7fffffff91b0) at vfprintf.c:1296
#4 0x00007ffff7b00606 in __printf (format=<optimized out>) at printf.c:33
#5 0x00007ffff51ccbe6 in _addon_log(int, char const*, ...) () at /usr/local/src/git/github_MayamaTakeshi/sip-lab/build/Release/addon.node
#6 0x00007ffff51d81a9 in on_rx_request(pjsip_rx_data*) () at /usr/local/src/git/github_MayamaTakeshi/sip-lab/build/Release/addon.node
#7 0x00007ffff520b94b in pjsip_endpt_process_rx_data (p_handled=0x7fffffffa75c, p=0x7fffffffa780, rdata=0x266f488, endpt=0x261e7a8) at ../src/pjsip/sip_endpoint.c:887
#8 0x00007ffff520b94b in pjsip_endpt_process_rx_data (endpt=0x261e7a8, rdata=0x266f488, p=<optimized out>, p_handled=0x7fffffffa75c) at ../src/pjsip/sip_endpoint.c:824
#9 0x00007ffff520bb56 in endpt_on_rx_msg (endpt=0x261e7a8, status=<optimized out>, rdata=0x266f488) at ../src/pjsip/sip_endpoint.c:1037
#10 0x00007ffff52117a6 in pjsip_tpmgr_receive_packet (mgr=<optimized out>, rdata=rdata@entry=0x266f488) at ../src/pjsip/sip_transport.c:1938
#11 0x00007ffff5213a4f in udp_on_read_complete (key=0x26257e8, op_key=<optimized out>, bytes_read=<optimized out>) at ../src/pjsip/sip_transport_udp.c:170
#12 0x00007ffff5236e28 in ioqueue_dispatch_read_event (h=0x26257e8, ioqueue=0x2629600) at ../src/pj/ioqueue_common_abs.c:605
#13 0x00007ffff5236e28 in ioqueue_dispatch_read_event (ioqueue=0x2629600, h=0x26257e8) at ../src/pj/ioqueue_common_abs.c:433
#14 0x00007ffff52386cf in pj_ioqueue_poll (ioqueue=0x2629600, timeout=timeout@entry=0x7fffffffb190) at ../src/pj/ioqueue_select.c:981
#15 0x00007ffff520b70a in pjsip_endpt_handle_events2 (endpt=0x261e7a8, max_timeout=0x7fffffffb1d0, p_count=0x0) at ../src/pjsip/sip_endpoint.c:742
#16 0x00007ffff51cf824 in handle_events() () at /usr/local/src/git/github_MayamaTakeshi/sip-lab/build/Release/addon.node
#17 0x00007ffff51d00a4 in __pjw_poll(char*) () at /usr/local/src/git/github_MayamaTakeshi/sip-lab/build/Release/addon.node
#18 0x00007ffff51dab71 in do_poll(Napi::CallbackInfo const&) () at /usr/local/src/git/github_MayamaTakeshi/sip-lab/build/Release/addon.node
#19 0x00007ffff51e4923 in Napi::details::CallbackData<Napi::Value (*)(Napi::CallbackInfo const&), Napi::Value>::Wrapper(napi_env__*, napi_callback_info__*) ()
at /usr/local/src/git/github_MayamaTakeshi/sip-lab/build/Release/addon.node
#20 0x00000000008e85b5 in (anonymous namespace)::v8impl::FunctionCallbackWrapper::Invoke(v8::FunctionCallbackInfo<v8::Value> const&) ()
#21 0x0000000000b62a3f in v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObj
ect>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) ()
#22 0x0000000000b635a9 in v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) ()
#23 0x0000309d62fdbe1d in ()
So it is a bug in our code.
But building it with these changes in on ubuntu 18.04.4 doesn't cause this crash which means in Debian 10 a condition that increases the chances of crash was introduced.
Anyway, we will commit these changes and solve the crash later.
------------------------------------------------------------
2020/08/09 takeshi:
We had to disable SRTP pjsip support (config_site.h) because of this:
$ node samples/simple.js
internal/modules/cjs/loader.js:730
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: /mnt/backup/takeshi_tmp/sip-lab/build/Release/addon.node: undefined symbol: crypto_policy_set_aes_cm_256_hmac_sha1_80
at Object.Module._extensions..node (internal/modules/cjs/loader.js:730:18)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/mnt/backup/takeshi_tmp/sip-lab/index.js:1:77)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
------------------------------------------------------------
2020/08/12 takeshi:
We did adjustments to support late negotiation.
For this we split original callback on_rx_offer in new callbacks on_rx_offer and on_rx_reinvite.
This worked with initial INVITE late negotiation.
However, it crashed with RE-INVITE late negotiation.
The problem is that on_rx_reinvite is getting an offer without media (due RE-INVITE without SDP).
Instead, I think we should go back to use original on_rx_offer because it seems this is called only when we get media offer and so we would avoid this problem.
------------------------------------------------------------
2022/08/12 takeshi:
When rebuilding the addon, this should be enough (it should be fast):
```
npm install --unsafe-perm
```
------------------------------------------------------------
2022/09/11 takeshi:
To try to solve #21, we upraded pjproject to commit 797088ed133c98492519b7d042b75735f6f9388c.
However, after doing it we verified sending CANCEL doesn't cause the other side to send '497 Request Terminated' by itself anymore (see samples/sip_cancel.js)
------------------------------------------------------------
2022/09/17 takeshi:
We will start shipping prebuilt binaries of the addon.
We create them by doing:
```
prebuildify --strip -t 15.0.0 -t 16.0.0 -t 17.0.0 -t 18.0.0
```
2022/09/18 takeshi:
Tried to statically link to openssl but then prebuilt file increased from:
```
$ ls -l prebuilds/linux-x64/
total 7240
-rwxr-xr-x 1 root root 1858744 Sep 17 14:04 node.abi102.node
-rwxr-xr-x 1 root root 1858744 Sep 17 14:04 node.abi108.node
-rwxr-xr-x 1 root root 1846424 Sep 17 14:04 node.abi88.node
-rwxr-xr-x 1 root root 1846424 Sep 17 14:04 node.abi93.node
```
to
```
$ ls -l prebuilds/linux-x64/
total 27328
-rwxr-xr-x 1 root root 6994712 Sep 18 08:58 node.abi102.node
-rwxr-xr-x 1 root root 6994712 Sep 18 08:58 node.abi108.node
-rwxr-xr-x 1 root root 6994680 Sep 18 08:58 node.abi88.node
-rwxr-xr-x 1 root root 6994680 Sep 18 08:58 node.abi93.node
```
For now, I will keep linking openssl so libs.
------------------------------------------------------------
2022/09/17 takeshi:
For reference, the addon doesn't work on Debian 8:
```
$ node samples/delayed_media.js
node:internal/modules/cjs/loader:1210
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.27' not found (required by /root/tmp/sip-lab/prebuilds/linux-x64/node.abi93.node)
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1210:18)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at load (/root/tmp/sip-lab/node_modules/node-gyp-build/index.js:22:10)
at Object.<anonymous> (/root/tmp/sip-lab/index.js:1:40)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32) {
code: 'ERR_DLOPEN_FAILED'
}
```
------------------------------------------------------------
2022/09/17 takeshi:
To force a build of the addon when a prebuilt is not available, we need to add an 'actions' list for the targe in the binding.gyp file.
We followed a tip from here:
https://stackoverflow.com/questions/27275340/run-configure-in-gyp-file
------------------------------------------------------------
2022/11/12 takeshi:
Building docker images to use prebuildify-cross:
Smoke test:
cd docker-images/debian10
cp ../../build_deps.sh .
docker build -t mayamatakeshi/sip-lab-debian10:latest .
cd ../..
npx prebuildify-cross -i mayamatakeshi/sip-lab-debian10:latest -t 16.0.0 --strip
The above worked and the resulting addon:
takeshi@takeshi-desktop:~/src/git/MayamaTakeshi/sip-lab$ file prebuilds/linux-x64/node.abi93.node
prebuilds/linux-x64/node.abi93.node: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=16ca20da2663c49f1f232e7d99b46709d4f57285, stripped
could be used in both debian10 and debian11.
Then I tried with Ubuntu 22.04:
cd docker-images/jammy
cp ../../build_deps.sh .
docker build -t mayamatakeshi/sip-lab-jammy:latest .
cd ../..
npx prebuildify-cross -i mayamatakeshi/sip-lab-jammy:latest -t 16.0.0 --strip
and it generated an addon with the same path/name:
takeshi@takeshi-desktop:~/src/git/MayamaTakeshi/sip-lab$ file prebuilds/linux-x64/node.abi93.node
prebuilds/linux-x64/node.abi93.node: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=6587c79403de026748fccf7ec224d75426d20892, stripped
But when I tried to use it on debian11 I got:
[root@lab225201-basix sip-lab]$ node samples/simple.js
node:internal/modules/cjs/loader:1183
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: libssl.so.3: cannot open shared object file: No such file or directory
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1183:18)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at load (/root/tmp/sip-lab/node_modules/node-gyp-build/index.js:22:10)
at Object.<anonymous> (/root/tmp/sip-lab/index.js:1:40)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
code: 'ERR_DLOPEN_FAILED'
}
So, the problem is that there is no way to differentiate between distros and distro versions. We can only identify the platform like linux-x64.
What we can try to do is to build all dependencies and link to them statically so to not depend on what is installed in the OS:
takeshi@takeshi-desktop:~/src/git/MayamaTakeshi/sip-lab$ ldd prebuilds/linux-x64/node.abi93.node
linux-vdso.so.1 (0x00007fff6f751000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f0749f35000)
libssl.so.3 => /lib/x86_64-linux-gnu/libssl.so.3 (0x00007f0749e91000)
libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 (0x00007f0749a4f000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f0749a46000)
libtiff.so.5 => /lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f07499c0000)
libspeex.so.1 => /lib/x86_64-linux-gnu/libspeex.so.1 (0x00007f07499a0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f07498b9000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0749899000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0749671000)
/lib64/ld-linux-x86-64.so.2 (0x00007f074a34c000)
libwebp.so.7 => /lib/x86_64-linux-gnu/libwebp.so.7 (0x00007f0749605000)
libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007f0749536000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f0749509000)
libjbig.so.0 => /lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f07494f8000)
libjpeg.so.8 => /lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f0749477000)
libdeflate.so.0 => /lib/x86_64-linux-gnu/libdeflate.so.0 (0x00007f0749453000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f0749437000)
takeshi@takeshi-desktop:~/src/git/MayamaTakeshi/sip-lab$
I think this will minimize problems but it will not completely eliminate them.
------------------------------------------------------------
2022/11/12 takeshi:
Here is what ldd on Debian11 outputs to an addon built on ubuntu 22.04:
[root@lab225201-basix tmp]$ ldd addon.node
./addon.node: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by ./addon.node)
./addon.node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./addon.node)
./addon.node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by ./addon.node)
linux-vdso.so.1 (0x00007ffe98ecf000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb8e8e57000)
libssl.so.3 => not found
libcrypto.so.3 => not found
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007fb8e8e4e000)
libtiff.so.5 => /lib/x86_64-linux-gnu/libtiff.so.5 (0x00007fb8e8dc8000)
libspeex.so.1 => /lib/x86_64-linux-gnu/libspeex.so.1 (0x00007fb8e8dad000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb8e8c67000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb8e8c4d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb8e8a88000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb8e9208000)
libwebp.so.6 => /lib/x86_64-linux-gnu/libwebp.so.6 (0x00007fb8e8a1f000)
libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007fb8e8944000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007fb8e891c000)
libjbig.so.0 => /lib/x86_64-linux-gnu/libjbig.so.0 (0x00007fb8e870c000)
libjpeg.so.62 => /lib/x86_64-linux-gnu/libjpeg.so.62 (0x00007fb8e8688000)
libdeflate.so.0 => /lib/x86_64-linux-gnu/libdeflate.so.0 (0x00007fb8e866c000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fb8e864f000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb8e862d000)
[root@lab225201-basix tmp]$
So, if we build and statically link to libssl and libcrypto, we should avoid problems.
And here it is for old Centos 7:
[root@IPX029 tmp]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@IPX029 tmp]# ldd addon.node
./addon.node: /usr/lib64/libm.so.6: version `GLIBC_2.27' not found (required by ./addon.node)
./addon.node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by ./addon.node)
./addon.node: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by ./addon.node)
./addon.node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by ./addon.node)
./addon.node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./addon.node)
./addon.node: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ./addon.node)
./addon.node: /usr/lib64/libc.so.6: version `GLIBC_2.22' not found (required by ./addon.node)
./addon.node: /usr/lib64/libc.so.6: version `GLIBC_2.34' not found (required by ./addon.node)
./addon.node: /usr/lib64/libc.so.6: version `GLIBC_2.33' not found (required by ./addon.node)
linux-vdso.so.1 => (0x00007fffa6cdf000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f8fd946e000)
libssl.so.3 => not found
libcrypto.so.3 => not found
libuuid.so.1 => /usr/lib64/libuuid.so.1 (0x00007f8fd9269000)
libtiff.so.5 => /usr/lib64/libtiff.so.5 (0x00007f8fd8ff5000)
libspeex.so.1 => /usr/lib64/libspeex.so.1 (0x00007f8fd8ddc000)
libm.so.6 => /usr/lib64/libm.so.6 (0x00007f8fd8ada000)
libgcc_s.so.1 => /usr/lib64/libgcc_s.so.1 (0x00007f8fd88c4000)
libc.so.6 => /usr/lib64/libc.so.6 (0x00007f8fd84f6000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8fd9776000)
libjbig.so.2.0 => /usr/lib64/libjbig.so.2.0 (0x00007f8fd82ea000)
libjpeg.so.62 => /usr/lib64/libjpeg.so.62 (0x00007f8fd8095000)
libz.so.1 => /usr/lib64/libz.so.1 (0x00007f8fd7e7f000)
[root@IPX029 tmp]#
Update: it will not be done. See #37.
------------------------------------------------------------
2023/01/05 takeshi:
I will need to add support for MRCP, MSRP etc.
For this, I should use pjlib networking functions so that they can be integrated with existing code using the same ioqueue in place for sip/rtp.
Sockets should be allocated in sip session pool so that they can be reclained when the session ends.
I asked ChatGPT:
"write a sample echo server using pjlib and ioqueue."
and it replied with:
"Here is a simple example of how you might implement an echo server using PJLIB and the ioqueue library:"
```
#include <pjlib.h>
#include <pjlib-util.h>
#include <pjnath.h>
#define PORT 4000
/* Callback called by the library when incoming data is received */
static pj_bool_t on_data_received(pj_activesock_t *asock,
void *data,
pj_size_t size,
pj_status_t status,
pj_size_t *remainder)
{
/* Send the data back to the client */
pj_ssize_t sent = pj_activesock_send(asock, data, size, 0);
if (sent < 0) {
/* Error sending data */
return PJ_FALSE;
} else {
/* Successfully sent data, update the remainder */
*remainder = size - sent;
return PJ_TRUE;
}
}
/* Callback called by the library when a new client connects */
static pj_bool_t on_accept_complete(pj_activesock_t *asock,
pj_sock_t sock,
const pj_sockaddr_t *src_addr,
int src_addr_len)
{
/* Start reading data from the client */
pj_activesock_start_read(asock, NULL, 0, 0);
return PJ_TRUE;
}
int main()
{
pj_status_t status;
pj_caching_pool cp;
pj_pool_t *pool;
pj_sock_t sock;
pj_activesock_t *asock;
/* Initialize PJLIB */
status = pj_init();
if (status != PJ_SUCCESS) {
/* Error initializing PJLIB */
return 1;
}
/* Create a pool factory */
pj_caching_pool_init(&cp, NULL, 0);
pool = pj_pool_create(&cp.factory, "echo-server", 1000, 1000, NULL);
/* Create a socket */
status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_STREAM, 0, &sock);
if (status != PJ_SUCCESS) {
/* Error creating socket */
return 1;
}
/* Bind the socket to a port */
pj_sockaddr_in addr;
pj_bzero(&addr, sizeof(addr));
addr.sin_family = PJ_AF_INET;
addr.sin_addr.s_addr = pj_htonl(PJ_INADDR_ANY);
addr.sin_port = pj_htons(PORT);
status = pj_sock_bind(sock, &addr, sizeof(addr));
if (status != PJ_SUCCESS) {
/* Error binding socket */
return 1;
}
/* Start listening for incoming connections
status = pj_sock_listen(sock, 5);
if (status != PJ_SUCCESS) {
/* Error listening for connections */
return 1;
}
/* Create an active socket */
pj_activesock_cfg asock_cfg;
pj_activesock_cfg_default(&asock_cfg);
asock_cfg.grp_lock = NULL;
status = pj_activesock_create(pool, sock, pj_SOCK_STREAM(), &asock_cfg, &asock);
if (status != PJ_SUCCESS) {
/* Error creating active socket */
return 1;
}
/* Set the callbacks for the active socket */
pj_activesock_set_recv_cb(asock, pool, &on_data_received);
pj_activesock_set_accept_cb(asock, pool, &on_accept_complete);
/* Start accepting connections */
pj_sockaddr_in local_addr;
int addr_len = sizeof(local_addr);
pj_sock_getsockname(sock, &local_addr, &addr_len);
printf("Echo server listening on %s:%d\n",
pj_inet_ntoa(local_addr.sin_addr),
pj_ntohs(local_addr.sin_port));
status = pj_activesock_start_accept(asock, pool);
if (status != PJ_SUCCESS) {
/* Error starting accept */
return 1;
}
/* Run the event loop */
pj_bool_t running= PJ_TRUE;
while (running) {
pj_time_val timeout = { 0, 10 };
pj_ioqueue_poll(pj_get_ioqueue_default(), &timeout);
}
/* Clean up */
pj_activesock_close(asock);
pj_sock_close(sock);
pj_pool_release(pool);
pj_caching_pool_destroy(&cp);
pj_shutdown();
return 0;
}
```
"This code creates a socket, binds it to a port, and starts listening for incoming connections. When a new connection is accepted, it creates an active socket and sets the callbacks for receiving data and accepting new connections. The event loop runs continuously, calling the ioqueue's poll function to process incoming data and events. When the server is no longer needed, it closes the active socket and the underlying socket, releases the memory pool, and shuts down PJLIB."
I eventually implemented working smoke test code by reading docs and samples and it seems the above indeed would work as it is very similar to what I came up with.
So although ChatGPT frequently generates bogus code with an authoritative tone, for some cases it seems to be usable.
------------------------------------------------------------
2022/01/06 takeshi:
Regarding on_rx_reinvite:
If we enable it like this:
inv_cb.on_rx_offer = NULL;
inv_cb.on_rx_offer2 = &on_rx_offer2;
inv_cb.on_rx_reinvite = &on_rx_reinvite;
static pj_status_t on_rx_reinvite(pjsip_inv_session *inv, const pjmedia_sdp_session *offer, pjsip_rx_data *rdata) {
printf("on_rx_reinvite\n");
return PJ_SUCCESS;
}
then when we do a reinvite on a call like this:
sip.call.reinvite(oc.id, {hold: true})
we will get '200 OK' without a body like this:
INVITE sip:sip-lab@127.0.0.1:5092 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5090;rport;branch=z9hG4bKPj95c7dd9c-5f1f-489c-90b6-dd90d03bc905
Max-Forwards: 70
From: sip:alice@test.com;tag=86bee9d5-ca74-41a8-b135-8a7d6eda2de0
To: sip:bob@127.0.0.1;tag=b7808a74-9613-458a-82a1-20d033347001
Contact: <sip:sip@127.0.0.1:5090>
Call-ID: fd1e8d7f-1627-4fae-b886-c64b88670eaa
CSeq: 22618 INVITE
Allow: MESSAGE, SUBSCRIBE, NOTIFY, REFER, INVITE, ACK, BYE, CANCEL, UPDATE
Supported: replaces
Content-Type: application/sdp
Content-Length: 586
v=0
o=- 3881951753 3881951754 IN IP4 127.0.0.1
s=pjmedia
t=0 0
m=audio 10000 RTP/AVP 0 8 3 96 97 98 99 9 18 120 121 122
c=IN IP4 127.0.0.1
b=TIAS:64000
a=rtcp:10001 IN IP4 127.0.0.1
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:3 GSM/8000
a=rtpmap:96 iLBC/8000
a=fmtp:96 mode=30
a=rtpmap:97 speex/32000
a=rtpmap:98 speex/16000
a=rtpmap:99 speex/8000
a=rtpmap:9 G722/8000
a=rtpmap:18 G729/8000
a=rtpmap:120 telephone-event/8000
a=fmtp:120 0-16
a=rtpmap:121 telephone-event/32000
a=fmtp:121 0-16
a=rtpmap:122 telephone-event/16000
a=fmtp:122 0-16
a=sendonly
SIP/2.0 200 OK
Via: SIP/2.0/UDP 127.0.0.1:5090;rport=5090;received=127.0.0.1;branch=z9hG4bKPj95c7dd9c-5f1f-489c-90b6-dd90d03bc905
Call-ID: fd1e8d7f-1627-4fae-b886-c64b88670eaa
From: <sip:alice@test.com>;tag=86bee9d5-ca74-41a8-b135-8a7d6eda2de0
To: <sip:bob@127.0.0.1>;tag=b7808a74-9613-458a-82a1-20d033347001
CSeq: 22618 INVITE
Contact: <sip:sip-lab@127.0.0.1:5092>
Allow: MESSAGE, SUBSCRIBE, NOTIFY, REFER, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK
Supported: replaces, 100rel
Content-Length: 0
------------------------------------------------------------
2022/01/06 takeshi:
ChatGPT test:
Write sample code creating SDP for MRCP using pjmedia.
Here is an example of how you could create an SDP (Session Description Protocol) for MRCP (Media Resource Control Protocol) using PJSIP and PJMedia:
```
#include <pjmedia.h>
#include <pjmedia-codec.h>
#include <pjlib-util.h>
#include <pjlib.h>
/* Create the SDP for MRCP */
pj_status_t create_mrcp_sdp(pjmedia_sdp_session **sdp)
{
pj_pool_t *pool;
pjmedia_sdp_media *m;
pjmedia_sdp_attr *attr;
pj_status_t status;
/* Create a pool for the SDP */
pool = pj_pool_create(NULL, "sdp%p", 1024, 1024, NULL);
if (!pool) {
return PJ_ENOMEM;
}
/* Create the SDP session */
*sdp = pj_pool_zalloc(pool, sizeof(pjmedia_sdp_session));
if (!*sdp) {
pj_pool_release(pool);
return PJ_ENOMEM;
}
/* Set the SDP version */
(*sdp)->origin.version = 0;
/* Set the SDP origin */
pj_strdup2((*sdp)->pool, &(*sdp)->origin.user, "mrcp");
pj_strdup2((*sdp)->pool, &(*sdp)->origin.addr, "127.0.0.1");
/* Set the SDP session name */
pj_strdup2((*sdp)->pool, &(*sdp)->name, "MRCP Session");
/* Create the SDP media */
m = pj_pool_zalloc(pool, sizeof(pjmedia_sdp_media));
if (!m) {
pj_pool_release(pool);
return PJ_ENOMEM;
}
/* Set the media type and port */
pj_strdup2(pool, &m->desc.media, "audio");
m->desc.port = 0;
/* Set the media transport */
pj_strdup2(pool, &m->desc.transport, "RTP/AVP");
/* Add the media to the SDP */
status = pjmedia_sdp_media_add_attr(m, &attr);
if (status != PJ_SUCCESS) {
pj_pool_release(pool);
return status;
}
attr->name = pj_str("rtpmap");
attr->value = pj_str("0 pcmu/8000");
pjmedia_sdp_media_add_attr(m, &attr);
if (status != PJ_SUCCESS) {
pj_pool_release(pool);
return status;
}
attr->name = pj_str("fmtp");
attr->value = pj_str("0-15");
pjmedia_sdp_session_add_media(sdp, m);
/* Return success */
return PJ_SUCCESS;
}
```
But we should have media for application TCP/MRCPv2 in the SDP.
Yes, you are correct. If you want to include a media description for the MRCPv2 application over TCP in the SDP, you can modify the create_mrcp_sdp function as follows:
```
pj_status_t create_mrcp_sdp(pjmedia_sdp_session **sdp)
{
pj_pool_t *pool;
pjmedia_sdp_media *m;
pjmedia_sdp_attr *attr;
pj_status_t status;
/* Create a pool for the SDP */
pool = pj_pool_create(NULL, "sdp%p", 1024, 1024, NULL);
if (!pool) {
return PJ_ENOMEM;
}
/* Create the SDP session */
*sdp = pj_pool_zalloc(pool, sizeof(pjmedia_sdp_session));
if (!*sdp) {
pj_pool_release(pool);
return PJ_ENOMEM;
}
/* Set the SDP version */
(*sdp)->origin.version = 0;
/* Set the SDP origin */
pj_strdup2((*sdp)->pool, &(*sdp)->origin.user, "mrcp");
pj_strdup2((*sdp)->pool, &(*sdp)->origin.addr, "127.0.0.1");