MayamaTakeshi / sip-lab

A node module that helps to write SIP functional tests
3 stars 2 forks source link

Switch media processing to conference bridge architecture #60

Closed MayamaTakeshi closed 4 months ago

MayamaTakeshi commented 6 months ago

Better do this before #22, #56 and #57.

MayamaTakeshi commented 4 months ago

And before doing this, we should solve #66 so that we can prepare a test with something like 256 simultaneous calls checking DTMF in all channel so that it can be used to confirm there was no negative impact in performance after the change.

MayamaTakeshi commented 4 months ago

We should study the code in https://github.com/pjsip/pjproject/blob/master/pjsip/src/pjsua-lib/pjsua_aud.c It indicates we create a single pjmedia_conf to handle media for all calls.

And this is confirmed by nanang:

Just an opinion, I don't see any advantage of creating conf bridge for each call, since it's just wasting resources (and perhaps increasing code complexity). So I would suggest you an alternative design:

  • For all calls: a shared conference bridge driven by master port/null audio.
  • For each call: just create a separate memplayer port, add conf port for memplayer port & portChannel port to the shared conference bridge, and connect them.

FYI, pjsua-lib also uses a single conference bridge to handle multiple calls simultaneously. (Btw, why not just using pjsua-lib for your app, it should be simpler).

https://pjsip.pjsip.narkive.com/93IWjFGF/handle-mutiple-media-flows-simultaneously

Also, check: https://github.com/pjsip/pjproject/blob/5ef8463d562db34adaf5ba6969b50d3814f3939f/pjsip/src/pjsua-lib/pjsua_call.c#L5273 and https://github.com/pjsip/pjproject/blob/master/pjsip/src/pjsua-lib/pjsua_media.c#L3764 https://github.com/pjsip/pjproject/blob/master/pjsip-apps/src/samples/confsample.c

and maybe: https://github.com/Ardameon/experiments/tree/master/pjsip_inv_example

MayamaTakeshi commented 4 months ago

I tried using a single pjmedia_conf but samples/100_calls.js got stuck when adding tonegen ports to it. So I tried with one pjmedia_conf per call and after that the issue was solved.

MayamaTakeshi commented 4 months ago

Test evidence:

takeshi@takeshi-desktop:sip-lab$ time ./runtests 
... ABRIDGED ...
Success. All tests passed

Successful tests:
  - samples/100_calls.js: duration=57.30 seconds
  - samples/16_audio_streams.js: duration=4.68 seconds
  - samples/183_session_progress.js: duration=7.91 seconds
  - samples/delayed_media.js: duration=5.20 seconds
  - samples/four_audio_streams_two_refused.js: duration=3.70 seconds
  - samples/g729.js: duration=0.99 seconds
  - samples/mrcp_and_audio.js: duration=1.14 seconds
  - samples/mrcp_and_audio.simplified_media.js: duration=2.39 seconds
  - samples/options.js: duration=0.18 seconds
  - samples/refer.js: duration=0.87 seconds
  - samples/refuse_telephone_event.js: duration=1.90 seconds
  - samples/register_no_expires.js: duration=0.18 seconds
  - samples/register_subscribe.js: duration=0.59 seconds
  - samples/reinvite_and_dtmf.js: duration=4.61 seconds
  - samples/reinvite_audio_audio.js: duration=4.90 seconds
  - samples/reinvite_with_hold_unhold.js: duration=8.46 seconds
  - samples/rtp_and_srtp.js: duration=5.60 seconds
  - samples/rtp_and_srtp.rtp_refused.js: duration=5.30 seconds
  - samples/send_and_receive_fax.js: duration=63.97 seconds
  - samples/simple.js: duration=0.47 seconds
  - samples/sip_cancel.js: duration=0.44 seconds
  - samples/srtp.js: duration=5.30 seconds
  - samples/tcp_and_extra_headers.js: duration=9.94 seconds
  - samples/two_audio_streams.js: duration=5.72 seconds
  - samples/two_audio_streams.port_zero.js: duration=5.71 seconds

Everything OK

real    3m27.539s
user    0m20.691s
sys     0m8.487s
takeshi@takeshi-desktop:sip-lab$