9 | | As described in the [http://www.pjsip.org/docs/latest/pjsip/docs/html/group__PJSUA__LIB__BASE.htm#details PJSUA-API Basic API documentation], application needs to call {{{pjsua_create()}}}, {{{pjsua_pool_create()}}}, {{{pjsua_init()}}} to perform the initialization. Then app must call {{{pjsua_start()}}} to start PJSUA and finally after everything is done, call {{{pjsua_destroy()}}} to shut it down. |
| 9 | To use PJSIP, it is recommended to call {{{pj_init()}}} and {{{pj_shutdown()}}} from the main thread. After {{{pj_init()}}} is completed, application can continue with the initialization or create a secondary/worker thread and register the thread by calling {{{pj_thread_register()}}}. As described in [http://www.pjsip.org/docs/latest/pjsip/docs/html/group__PJSUA__LIB__BASE.htm#details PJSUA-API Basic API documentation], app needs to call {{{pjsua_create()}}}, {{{pjsua_pool_create()}}}, {{{pjsua_init()}}} to perform the initialization. Then app must call {{{pjsua_start()}}} to start PJSUA and finally after everything is done, call {{{pjsua_destroy()}}} to shut it down. Sample code: |
11 | | It is not necessary to call these functions from the main thread, i.e. application can perform the initialization and shutdown from a secondary/worker thread. However, it is recommended to call {{{pj_init()}}} and {{{pj_shutdown()}}} from the main thread. |
| 11 | {{{ |
| 12 | int main() |
| 13 | { |
| 14 | pj_init(); |
| 15 | // Continue with PJSUA initialization here or create a secondary thread |
| 16 | .... |
| 17 | // After pjsua_destroy() is called |
| 18 | pj_shutdown(); |
| 19 | } |
| 20 | |
| 21 | int worker_thread() |
| 22 | { |
| 23 | // Register the thread, after pj_init() is called |
| 24 | pj_thread_register(); |
| 25 | |
| 26 | // Create pjsua and pool |
| 27 | pjsua_create(); |
| 28 | pjsua_pool_create(); |
| 29 | |
| 30 | // Init pjsua |
| 31 | pjsua_init(); |
| 32 | |
| 33 | // Start pjsua |
| 34 | pjsua_start(); |
| 35 | |
| 36 | ......... |
| 37 | |
| 38 | // Destroy pjsua |
| 39 | pjsua_destroy(); |
| 40 | } |
| 41 | }}} |
| 42 | |
| 43 | When restarting the library, after {{{pjsua_destroy()}}} is completed, application needs to call {{{pj_shutdown()}}} and {{{pj_init()}}} in the main thread. |
| 44 | Application also needs to make sure that the number of calls to {{{pj_shutdown()}}} matches with the calls to {{{pj_init()}}} |