| 1 | = Background = |
| 2 | |
| 3 | Currently this is how the media channel interacts with SIP call in PJSUA-LIB: |
| 4 | |
| 5 | {{{ |
| 6 | pjsua_call_make_call(): |
| 7 | pjsua_call_on_incoming(): |
| 8 | pjsua_call_update(): |
| 9 | pjsua_call_reinvite(): |
| 10 | pjsua_call_on_rx_offer(): |
| 11 | pjsua_call_on_create_offer(): |
| 12 | { |
| 13 | pjsua_media_channel_init(); |
| 14 | pjsua_media_channel_create_sdp(); |
| 15 | } |
| 16 | |
| 17 | pjsua_call_on_media_update(): |
| 18 | { |
| 19 | pjsua_media_channel_update(); |
| 20 | } |
| 21 | |
| 22 | pjsua_call_on_state_changed(DISCONNECTED): |
| 23 | pjsua_call_on_media_update(HOLD): |
| 24 | { |
| 25 | pjsua_media_channel_deinit(); |
| 26 | } |
| 27 | }}} |
| 28 | |
| 29 | and this is the implementation of media channel functions above: |
| 30 | |
| 31 | {{{ |
| 32 | pjsua_media_channel_init() |
| 33 | { |
| 34 | pjmedia_transport_srtp_create(); |
| 35 | } |
| 36 | |
| 37 | pjsua_media_channel_create_sdp(): |
| 38 | { |
| 39 | pjmedia_endpt_create_sdp(); |
| 40 | pjmedia_transport_media_create(); |
| 41 | } |
| 42 | |
| 43 | pjsua_media_channel_update(): |
| 44 | { |
| 45 | pjmedia_transport_media_start(); |
| 46 | pjmedia_session_create(); |
| 47 | } |
| 48 | |
| 49 | pjsua_media_channel_deinit(): |
| 50 | { |
| 51 | stop_media_session(); |
| 52 | pjmedia_transport_media_stop(); |
| 53 | pjmedia_transport_close(srtp); |
| 54 | } |
| 55 | }}} |
| 56 | |
| 57 | = Reasons for Fix/Change = |
| 58 | |
| 59 | The interface above has some drawbacks: |
| 60 | |
| 61 | 1. The main drawback is it does not distinguish between a new/freshly created call and existing call (which needs updating the media because of re-INVITE/UPDATE), functions such as pjsua_call_on_create_offer() will actually re-initialize the media, hence causing problems such as ticket #525 (crash on UPDATE/re-INVITE). |
| 62 | 1. It requires media transports to be re-created during application startup and kept-alive throughout the application lifetime. The drawbacks of this are (as documented by ticket #539): |
| 63 | a. it requires STUN and TURN transport to be kept-alive, which means it needs to send periodic keep-alive packets, and this is not good for battery consumption in mobile devices. |
| 64 | a. it requires TURN long-term allocation, which will fail if the NAT/mapped public IP address mapping has changed. |
| 65 | a. even when TURN is not used it may still fail when normal UDP media transport (i.e. not ICE) is used and the IP address (STUN or not) changes. |
| 66 | a. it allocates a lot of resources when the number of max_calls is large. |
| 67 | |
| 68 | |
| 69 | |
| 70 | = New Design Specification = |
| 71 | |
| 72 | |
| 73 | |
| 74 | |