diff --git a/.github/workflows/ci-mac.yml b/.github/workflows/ci-mac.yml index cc3047bc14..78316c303a 100644 --- a/.github/workflows/ci-mac.yml +++ b/.github/workflows/ci-mac.yml @@ -30,14 +30,14 @@ jobs: run: CFLAGS="-g -I/usr/local/include -I/usr/local/opt/openssl@1.1/include -fPIC" LDFLAGS="-L/usr/local/lib -L/usr/local/opt/openssl@1.1/lib" CXXFLAGS="-g -fPIC" ./configure - name: make run: make + - name: set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' - name: swig bindings run: cd pjsip-apps/src/swig && make - name: disable firewall run: sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off - - name: set up Python 3.10 for pjsua test - uses: actions/setup-python@v4 - with: - python-version: '3.10' - name: unit tests run: make pjlib-test-ci pjmedia-test pjlib-util-test pjsua-test @@ -91,6 +91,10 @@ jobs: run: CFLAGS="-I/usr/local/include -I/usr/local/opt/openssl@1.1/include -fPIC" LDFLAGS="-L/usr/local/lib -L/usr/local/opt/openssl@1.1/lib" CXXFLAGS="-fPIC" ./configure - name: make run: make + - name: set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' - name: swig bindings run: cd pjsip-apps/src/swig && make @@ -105,6 +109,10 @@ jobs: run: CFLAGS="-fPIC" CXXFLAGS="-fPIC" ./configure --with-gnutls=/usr/local/ - name: make run: make + - name: set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' - name: swig bindings run: cd pjsip-apps/src/swig && make @@ -122,14 +130,14 @@ jobs: run: CFLAGS="-g -I/usr/local/include -I/usr/local/opt/openssl@1.1/include -DHAS_VID_CODEC_TEST=0 -fPIC" LDFLAGS="-L/usr/local/lib -L/usr/local/opt/openssl@1.1/lib" CXXFLAGS="-g -fPIC" ./configure - name: make run: make + - name: set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' - name: swig bindings run: cd pjsip-apps/src/swig && make - name: disable firewall run: sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off - - name: set up Python 3.10 for pjsua test - uses: actions/setup-python@v2 - with: - python-version: '3.10' - name: unit tests run: make pjlib-test-ci pjmedia-test pjlib-util-test pjsua-test @@ -188,6 +196,10 @@ jobs: run: CFLAGS="-I/usr/local/include -I/usr/local/opt/openssl@1.1/include -fPIC" LDFLAGS="-L/usr/local/lib -L/usr/local/opt/openssl@1.1/lib" CXXFLAGS="-fPIC" ./configure - name: make run: make + - name: set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' - name: swig bindings run: cd pjsip-apps/src/swig && make @@ -204,5 +216,9 @@ jobs: run: CFLAGS="-I/usr/local/include -I/usr/local/opt/openssl@1.1/include -fPIC" LDFLAGS="-L/usr/local/lib -L/usr/local/opt/openssl@1.1/lib" CXXFLAGS="-fPIC" ./configure - name: make run: make + - name: set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' - name: swig bindings run: cd pjsip-apps/src/swig && make diff --git a/pjlib-util/src/pjlib-util-test/http_client.c b/pjlib-util/src/pjlib-util-test/http_client.c index 5d78b0adf6..ddda5d4a86 100644 --- a/pjlib-util/src/pjlib-util-test/http_client.c +++ b/pjlib-util/src/pjlib-util-test/http_client.c @@ -163,7 +163,7 @@ static void on_data_read(pj_http_req *hreq, void *data, pj_size_t size) PJ_UNUSED_ARG(hreq); PJ_UNUSED_ARG(data); - PJ_LOG(5, (THIS_FILE, "\nData received: %ld bytes", size)); + PJ_LOG(5, (THIS_FILE, "\nData received: %lu bytes", (unsigned long)size)); if (size > 0) { #ifdef VERBOSE printf("%.*s\n", (int)size, (char *)data); @@ -190,8 +190,8 @@ static void on_send_data(pj_http_req *hreq, *data = sdata; *size = sendsz; - PJ_LOG(5, (THIS_FILE, "\nSending data progress: %ld out of %ld bytes", - send_size, total_size)); + PJ_LOG(5, (THIS_FILE, "\nSending data progress: %lu out of %lu bytes", + (unsigned long)send_size, (unsigned long)total_size)); } @@ -210,7 +210,8 @@ static void on_complete(pj_http_req *hreq, pj_status_t status, PJ_LOG(3, (THIS_FILE, "Error %d", status)); return; } - PJ_LOG(5, (THIS_FILE, "\nData completed: %ld bytes", resp->size)); + PJ_LOG(5, (THIS_FILE, "\nData completed: %lu bytes", + (unsigned long)resp->size)); if (resp->size > 0 && resp->data) { #ifdef VERBOSE printf("%.*s\n", (int)resp->size, (char *)resp->data); diff --git a/pjlib-util/src/pjlib-util/resolver.c b/pjlib-util/src/pjlib-util/resolver.c index dcdeff83f5..0fd0cf7efa 100644 --- a/pjlib-util/src/pjlib-util/resolver.c +++ b/pjlib-util/src/pjlib-util/resolver.c @@ -1942,12 +1942,12 @@ PJ_DEF(void) pj_dns_resolver_dump(pj_dns_resolver *resolver, } } PJ_LOG(3,(resolver->name.ptr, " Nb. of pending query free nodes: %lu", - pj_list_size(&resolver->query_free_nodes))); + (unsigned long)pj_list_size(&resolver->query_free_nodes))); PJ_LOG(3,(resolver->name.ptr, " Nb. of timer entries: %lu", - pj_timer_heap_count(resolver->timer))); + (unsigned long)pj_timer_heap_count(resolver->timer))); PJ_LOG(3,(resolver->name.ptr, " Pool capacity: %lu, used size: %lu", - pj_pool_get_capacity(resolver->pool), - pj_pool_get_used_size(resolver->pool))); + (unsigned long)pj_pool_get_capacity(resolver->pool), + (unsigned long)pj_pool_get_used_size(resolver->pool))); pj_grp_lock_release(resolver->grp_lock); #endif diff --git a/pjlib-util/src/pjlib-util/stun_simple.c b/pjlib-util/src/pjlib-util/stun_simple.c index d4233c9d4f..6cc6cc14b6 100644 --- a/pjlib-util/src/pjlib-util/stun_simple.c +++ b/pjlib-util/src/pjlib-util/stun_simple.c @@ -76,7 +76,8 @@ PJ_DEF(pj_status_t) pjstun_parse_msg( void *buf, pj_size_t buf_len, msg_len = pj_ntohs(msg->hdr->length); if (msg_len != buf_len - sizeof(pjstun_msg_hdr)) { PJ_LOG(4,(THIS_FILE, "Error: invalid msg_len %d (expecting %lu)", - msg_len, buf_len - sizeof(pjstun_msg_hdr))); + msg_len, (unsigned long) + (buf_len - sizeof(pjstun_msg_hdr)))); return PJLIB_UTIL_ESTUNINMSGLEN; } diff --git a/pjlib-util/src/pjlib-util/stun_simple_client.c b/pjlib-util/src/pjlib-util/stun_simple_client.c index 78b1eb5f88..5f7e818f16 100644 --- a/pjlib-util/src/pjlib-util/stun_simple_client.c +++ b/pjlib-util/src/pjlib-util/stun_simple_client.c @@ -345,8 +345,9 @@ PJ_DEF(pj_status_t) pjstun_get_mapped_addr2(pj_pool_factory *pf, } } - TRACE_((THIS_FILE, " Pool usage=%ld of %ld", pj_pool_get_used_size(pool), - pj_pool_get_capacity(pool))); + TRACE_((THIS_FILE, " Pool usage=%lu of %lu", + (unsigned long)pj_pool_get_used_size(pool), + (unsigned long)pj_pool_get_capacity(pool))); pj_pool_release(pool); diff --git a/pjlib/include/pj/list.h b/pjlib/include/pj/list.h index fa667296df..1ca6445c7c 100644 --- a/pjlib/include/pj/list.h +++ b/pjlib/include/pj/list.h @@ -170,6 +170,27 @@ PJ_IDECL(void) pj_list_insert_nodes_after(pj_list_type *lst, pj_list_type *nodes); +/** + * Insert a list to another list before the specified element position. + * + * @param pos The element to which the node will be inserted before. + * @param lst The list to be inserted. + */ +PJ_IDECL(void) pj_list_insert_list_before(pj_list_type *pos, + pj_list_type *lst); + + +/** + * Insert a list to another list after the specified element position. + * + * @param pos The element in the list which will precede the inserted + * list. + * @param lst The list to be inserted. + */ +PJ_IDECL(void) pj_list_insert_list_after(pj_list_type *pos, + pj_list_type *lst); + + /** * Remove elements from the source list, and insert them to the destination * list. The elements of the source list will occupy the diff --git a/pjlib/include/pj/list_i.h b/pjlib/include/pj/list_i.h index 90718d74dd..cb134f264e 100644 --- a/pjlib/include/pj/list_i.h +++ b/pjlib/include/pj/list_i.h @@ -54,6 +54,23 @@ PJ_IDEF(void) pj_list_insert_nodes_before(pj_list_type *pos, pj_list_type *lst) pj_list_insert_nodes_after(((pj_list*)pos)->prev, lst); } +PJ_IDEF(void) pj_list_insert_list_after(pj_list_type *pos, pj_list_type *lst) +{ + if (!pj_list_empty(lst)) { + pj_list *lst_last = (pj_list *) ((pj_list*)lst)->prev; + pj_list *pos_next = (pj_list *) ((pj_list*)pos)->next; + + pj_link_node(pos, (pj_list *) ((pj_list*)lst)->next); + pj_link_node(lst_last, pos_next); + pj_list_init(lst); + } +} + +PJ_IDEF(void) pj_list_insert_list_before(pj_list_type *pos, pj_list_type *lst) +{ + pj_list_insert_list_after(((pj_list*)pos)->prev, lst); +} + PJ_IDEF(void) pj_list_merge_last(pj_list_type *lst1, pj_list_type *lst2) { if (!pj_list_empty(lst2)) { diff --git a/pjlib/src/pj/hash.c b/pjlib/src/pj/hash.c index 70226f7fa2..977dac345d 100644 --- a/pjlib/src/pj/hash.c +++ b/pjlib/src/pj/hash.c @@ -188,8 +188,8 @@ static pj_hash_entry **find_entry( pj_pool_t *pool, pj_hash_table_t *ht, entry = PJ_POOL_ALLOC_T(pool, pj_hash_entry); PJ_LOG(6, ("hashtbl", "%p: New p_entry %p created, pool used=%lu, cap=%lu", - ht, entry, pj_pool_get_used_size(pool), - pj_pool_get_capacity(pool))); + ht, entry, (unsigned long)pj_pool_get_used_size(pool), + (unsigned long)pj_pool_get_capacity(pool))); } entry->next = NULL; entry->hash = hash; diff --git a/pjlib/src/pj/pool.c b/pjlib/src/pj/pool.c index 5615931592..0f7910a0ca 100644 --- a/pjlib/src/pj/pool.c +++ b/pjlib/src/pj/pool.c @@ -53,7 +53,8 @@ static pj_pool_block *pj_pool_create_block( pj_pool_t *pool, pj_size_t size) pj_assert(size >= sizeof(pj_pool_block)); LOG((pool->obj_name, "create_block(sz=%lu), cur.cap=%lu, cur.used=%lu", - size, pool->capacity, pj_pool_get_used_size(pool))); + (unsigned long)size, (unsigned long)pool->capacity, + (unsigned long)pj_pool_get_used_size(pool))); /* Request memory from allocator. */ block = (pj_pool_block*) @@ -118,7 +119,8 @@ PJ_DEF(void*) pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size) if (pool->increment_size == 0) { LOG((pool->obj_name, "Can't expand pool to allocate %lu bytes " "(used=%lu, cap=%lu)", - size, pj_pool_get_used_size(pool), pool->capacity)); + (unsigned long)size, (unsigned long)pj_pool_get_used_size(pool), + (unsigned long)pool->capacity)); (*pool->callback)(pool, size); return NULL; } @@ -143,7 +145,9 @@ PJ_DEF(void*) pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size) LOG((pool->obj_name, "%lu bytes requested, resizing pool by %lu bytes (used=%lu, cap=%lu)", - size, block_size, pj_pool_get_used_size(pool), pool->capacity)); + (unsigned long)size, (unsigned long)block_size, + (unsigned long)pj_pool_get_used_size(pool), + (unsigned long)pool->capacity)); block = pj_pool_create_block(pool, block_size); if (!block) @@ -233,7 +237,8 @@ PJ_DEF(pj_pool_t*) pj_pool_create_int( pj_pool_factory *f, const char *name, /* Pool initial capacity and used size */ pool->capacity = initial_size; - LOG((pool->obj_name, "pool created, size=%lu", pool->capacity)); + LOG((pool->obj_name, "pool created, size=%lu", + (unsigned long)pool->capacity)); return pool; } @@ -278,9 +283,10 @@ static void reset_pool(pj_pool_t *pool) */ PJ_DEF(void) pj_pool_reset(pj_pool_t *pool) { - LOG((pool->obj_name, "reset(): cap=%ld, used=%ld(%ld%%)", - pool->capacity, pj_pool_get_used_size(pool), - pj_pool_get_used_size(pool)*100/pool->capacity)); + LOG((pool->obj_name, "reset(): cap=%lu, used=%lu(%lu%%)", + (unsigned long)pool->capacity, + (unsigned long)pj_pool_get_used_size(pool), + (unsigned long)(pj_pool_get_used_size(pool)*100/pool->capacity))); reset_pool(pool); } @@ -292,9 +298,10 @@ PJ_DEF(void) pj_pool_destroy_int(pj_pool_t *pool) { pj_size_t initial_size; - LOG((pool->obj_name, "destroy(): cap=%ld, used=%ld(%ld%%), block0=%p-%p", - pool->capacity, pj_pool_get_used_size(pool), - pj_pool_get_used_size(pool)*100/pool->capacity, + LOG((pool->obj_name, "destroy(): cap=%lu, used=%lu(%lu%%), block0=%p-%p", + (unsigned long)pool->capacity, + (unsigned long)pj_pool_get_used_size(pool), + (unsigned long)(pj_pool_get_used_size(pool)*100/pool->capacity), ((pj_pool_block*)pool->block_list.next)->buf, ((pj_pool_block*)pool->block_list.next)->end)); diff --git a/pjlib/src/pj/pool_caching.c b/pjlib/src/pj/pool_caching.c index cb8896b488..666ab1473a 100644 --- a/pjlib/src/pj/pool_caching.c +++ b/pjlib/src/pj/pool_caching.c @@ -188,7 +188,8 @@ static pj_pool_t* cpool_create_pool(pj_pool_factory *pf, cp->capacity = 0; } - PJ_LOG(6, (pool->obj_name, "pool reused, size=%lu", pool->capacity)); + PJ_LOG(6, (pool->obj_name, "pool reused, size=%lu", + (unsigned long)pool->capacity)); } /* Put in used list. */ @@ -245,9 +246,11 @@ static void cpool_release_pool( pj_pool_factory *pf, pj_pool_t *pool) } /* Reset pool. */ - PJ_LOG(6, (pool->obj_name, "recycle(): cap=%ld, used=%ld(%ld%%)", - pool_capacity, pj_pool_get_used_size(pool), - pj_pool_get_used_size(pool)*100/pool_capacity)); + PJ_LOG(6, (pool->obj_name, "recycle(): cap=%lu, used=%lu(%lu%%)", + (unsigned long)pool_capacity, + (unsigned long)pj_pool_get_used_size(pool), + (unsigned long)(pj_pool_get_used_size(pool)*100/ + pool_capacity))); pj_pool_reset(pool); pool_capacity = pj_pool_get_capacity(pool); @@ -279,8 +282,9 @@ static void cpool_dump_status(pj_pool_factory *factory, pj_bool_t detail ) pj_lock_acquire(cp->lock); PJ_LOG(3,("cachpool", " Dumping caching pool:")); - PJ_LOG(3,("cachpool", " Capacity=%lu, max_capacity=%lu, used_cnt=%lu", \ - cp->capacity, cp->max_capacity, cp->used_count)); + PJ_LOG(3,("cachpool", " Capacity=%lu, max_capacity=%lu, used_cnt=%lu", + (unsigned long)cp->capacity, (unsigned long)cp->max_capacity, + (unsigned long)cp->used_count)); if (detail) { pj_pool_t *pool = (pj_pool_t*) cp->used_list.next; pj_size_t total_used = 0, total_capacity = 0; @@ -294,7 +298,7 @@ static void cpool_dump_status(pj_pool_factory *factory, pj_bool_t detail ) #if 0 PJ_LOG(6, ("cachpool", " %16s block %u, size %ld", pj_pool_getobjname(pool), nblocks, - block->end - block->buf + 1)); + (long)(block->end - block->buf + 1))); #endif nblocks++; block = block->next; @@ -303,9 +307,10 @@ static void cpool_dump_status(pj_pool_factory *factory, pj_bool_t detail ) PJ_LOG(3,("cachpool", " %16s: %8lu of %8lu (%lu%%) used, " "nblocks: %d", pj_pool_getobjname(pool), - pj_pool_get_used_size(pool), - pool_capacity, - pj_pool_get_used_size(pool)*100/pool_capacity, + (unsigned long)pj_pool_get_used_size(pool), + (unsigned long)pool_capacity, + (unsigned long)(pj_pool_get_used_size(pool)* + 100/pool_capacity), nblocks)); #if PJ_POOL_MAX_SEARCH_BLOCK_COUNT == 0 @@ -323,8 +328,10 @@ static void cpool_dump_status(pj_pool_factory *factory, pj_bool_t detail ) } if (total_capacity) { PJ_LOG(3,("cachpool", " Total %9lu of %9lu (%lu %%) used!", - total_used, total_capacity, - total_used * 100 / total_capacity)); + (unsigned long)total_used, + (unsigned long)total_capacity, + (unsigned long)(total_used * 100 / + total_capacity))); } } diff --git a/pjlib/src/pj/ssl_sock_ossl.c b/pjlib/src/pj/ssl_sock_ossl.c index 6777b51b3b..5253fec053 100644 --- a/pjlib/src/pj/ssl_sock_ossl.c +++ b/pjlib/src/pj/ssl_sock_ossl.c @@ -161,7 +161,7 @@ static void update_certs_info(pj_ssl_sock_t* ssock, #if OPENSSL_VERSION_NUMBER >= 0x10100000L # define OPENSSL_NO_SSL2 /* seems to be removed in 1.1.0 */ -# if !USING_LIBRESSL +# ifndef M_ASN1_STRING_data # define M_ASN1_STRING_data(x) ASN1_STRING_get0_data(x) # define M_ASN1_STRING_length(x) ASN1_STRING_length(x) # endif diff --git a/pjlib/src/pj/timer.c b/pjlib/src/pj/timer.c index f902dbc6e6..65a837763c 100644 --- a/pjlib/src/pj/timer.c +++ b/pjlib/src/pj/timer.c @@ -381,8 +381,9 @@ static pj_status_t grow_heap(pj_timer_heap_t *ht) pj_timer_entry_dup *new_dup; #endif - PJ_LOG(6,(THIS_FILE, "Growing heap size from %ld to %ld", - ht->max_size, new_size)); + PJ_LOG(6,(THIS_FILE, "Growing heap size from %lu to %lu", + (unsigned long)ht->max_size, + (unsigned long)new_size)); // First grow the heap itself. new_heap = (pj_timer_entry_dup**) diff --git a/pjlib/src/pjlib-test/ioq_perf.c b/pjlib/src/pjlib-test/ioq_perf.c index 16d52d7886..d4195ae9e3 100644 --- a/pjlib/src/pjlib-test/ioq_perf.c +++ b/pjlib/src/pjlib-test/ioq_perf.c @@ -121,8 +121,8 @@ static void on_read_complete(pj_ioqueue_key_t *key, PJ_LOG(3,(THIS_FILE, ".....additional info: type=%s, total read=%lu, " "total sent=%lu", - item->type_name, item->bytes_recv, - item->bytes_sent)); + item->type_name, (unsigned long)item->bytes_recv, + (unsigned long)item->bytes_sent)); } } else { last_error_counter++; @@ -480,8 +480,10 @@ static int perform_test(const pj_ioqueue_cfg *cfg, if (display_report) { PJ_LOG(3,(THIS_FILE, " %s %d threads, %d pairs", type_name, thread_cnt, sockpair_cnt)); - PJ_LOG(3,(THIS_FILE, " Elapsed : %lu msec", total_elapsed_usec/1000)); - PJ_LOG(3,(THIS_FILE, " Bandwidth: %lu KB/s", *p_bandwidth)); + PJ_LOG(3,(THIS_FILE, " Elapsed : %lu msec", + (unsigned long)(total_elapsed_usec/1000))); + PJ_LOG(3,(THIS_FILE, " Bandwidth: %lu KB/s", + (unsigned long)*p_bandwidth)); PJ_LOG(3,(THIS_FILE, " Threads statistics:")); PJ_LOG(3,(THIS_FILE, " =============================")); PJ_LOG(3,(THIS_FILE, " Thread Loops Events Errors")); @@ -506,7 +508,7 @@ static int perform_test(const pj_ioqueue_cfg *cfg, } else { PJ_LOG(3,(THIS_FILE, " %.4s %2d %2d %8lu KB/s", type_name, thread_cnt, sockpair_cnt, - *p_bandwidth)); + (unsigned long)*p_bandwidth)); } /* Done. */ @@ -578,7 +580,7 @@ static int ioqueue_perf_test_imp(const pj_ioqueue_cfg *cfg) test_param[best_index].type_name, test_param[best_index].thread_cnt, test_param[best_index].sockpair_cnt, - best_bandwidth)); + (unsigned long)best_bandwidth)); PJ_LOG(3,(THIS_FILE, " (Note: packet size=%d, total errors=%u)", BUF_SIZE, last_error_counter)); return 0; diff --git a/pjlib/src/pjlib-test/pool.c b/pjlib/src/pjlib-test/pool.c index 897d7ee2f7..344ab28477 100644 --- a/pjlib/src/pjlib-test/pool.c +++ b/pjlib/src/pjlib-test/pool.c @@ -69,7 +69,7 @@ static int capacity_test(void) if (pj_pool_alloc(pool, freesize) == NULL) { PJ_LOG(3,("test", "...error: wrong freesize %lu reported", - freesize)); + (unsigned long)freesize)); pj_pool_release(pool); return -210; } @@ -175,7 +175,8 @@ static int drain_test(pj_size_t size, pj_size_t increment) void *p; int status = 0; - PJ_LOG(3,("test", "...drain_test(%lu,%lu)", size, increment)); + PJ_LOG(3,("test", "...drain_test(%lu,%lu)", (unsigned long)size, + (unsigned long)increment)); if (!pool) return -10; @@ -208,7 +209,7 @@ static int drain_test(pj_size_t size, pj_size_t increment) /* Check that capacity is zero. */ if (GET_FREE(pool) != 0) { PJ_LOG(3,("test", "....error: returned free=%lu (expecting 0)", - GET_FREE(pool))); + (unsigned long)(GET_FREE(pool)))); status=-30; goto on_error; } diff --git a/pjlib/src/pjlib-test/sock.c b/pjlib/src/pjlib-test/sock.c index ef3f52d261..284b1c403f 100644 --- a/pjlib/src/pjlib-test/sock.c +++ b/pjlib/src/pjlib-test/sock.c @@ -541,14 +541,15 @@ static int send_recv_test(int sock_type, rc = -155; goto on_error; } if (received <= 0) { - PJ_LOG(3,("", "...error: socket has closed! (received=%ld)", - received)); + PJ_LOG(3,("", "...error: socket has closed! (received=%lu)", + (unsigned long)received)); rc = -156; goto on_error; } if (received != DATA_LEN-total_received) { if (sock_type != pj_SOCK_STREAM()) { PJ_LOG(3,("", "...error: expecting %lu bytes, got %lu bytes", - DATA_LEN-total_received, received)); + (unsigned long)(DATA_LEN-total_received), + (unsigned long)received)); rc = -157; goto on_error; } } @@ -599,14 +600,15 @@ static int send_recv_test(int sock_type, rc = -170; goto on_error; } if (received <= 0) { - PJ_LOG(3,("", "...error: socket has closed! (received=%ld)", - received)); + PJ_LOG(3,("", "...error: socket has closed! (received=%lu)", + (unsigned long)received)); rc = -173; goto on_error; } if (received != BIG_DATA_LEN-total_received) { if (sock_type != pj_SOCK_STREAM()) { PJ_LOG(3,("", "...error: expecting %lu bytes, got %lu bytes", - BIG_DATA_LEN-total_received, received)); + (unsigned long)BIG_DATA_LEN-total_received, + (unsigned long)received)); rc = -176; goto on_error; } } diff --git a/pjlib/src/pjlib-test/ssl_sock.c b/pjlib/src/pjlib-test/ssl_sock.c index bece11179e..39ec158b0a 100644 --- a/pjlib/src/pjlib-test/ssl_sock.c +++ b/pjlib/src/pjlib-test/ssl_sock.c @@ -350,7 +350,8 @@ static pj_bool_t ssl_on_data_read(pj_ssl_sock_t *ssock, } pj_sockaddr_print((pj_sockaddr_t*)&info.local_addr, buf, sizeof(buf), 1); - PJ_LOG(3, ("", "...%s successfully recv %lu bytes echo", buf, st->recv)); + PJ_LOG(3, ("", "...%s successfully recv %lu bytes echo", buf, + (unsigned long)st->recv)); st->done = PJ_TRUE; } } @@ -501,7 +502,8 @@ static int https_client_test(unsigned ms_timeout) } PJ_LOG(3, ("", "...Done!")); - PJ_LOG(3, ("", ".....Sent/recv: %lu/%lu bytes", state.sent, state.recv)); + PJ_LOG(3, ("", ".....Sent/recv: %lu/%lu bytes", (unsigned long)state.sent, + (unsigned long)state.recv)); on_return: if (ssock && !state.err && !state.done) @@ -755,7 +757,8 @@ static int echo_test(pj_ssl_sock_proto srv_proto, pj_ssl_sock_proto cli_proto, } PJ_LOG(3, ("", "...Done!")); - PJ_LOG(3, ("", ".....Sent/recv: %lu/%lu bytes", state_cli.sent, state_cli.recv)); + PJ_LOG(3, ("", ".....Sent/recv: %lu/%lu bytes", (unsigned long)state_cli.sent, + (unsigned long)state_cli.recv)); on_return: #if (PJ_SSL_SOCK_IMP == PJ_SSL_SOCK_IMP_DARWIN) || \ @@ -1464,7 +1467,8 @@ static int perf_test(unsigned clients, unsigned ms_handshake_timeout) } PJ_LOG(3, ("", ".....Clients: %d (%d errors)", clients, cli_err)); - PJ_LOG(3, ("", ".....Total sent/recv: %lu/%lu bytes", tot_sent, tot_recv)); + PJ_LOG(3, ("", ".....Total sent/recv: %lu/%lu bytes", + (unsigned long)tot_sent, (unsigned long)tot_recv)); on_return: if (ssock_serv) diff --git a/pjlib/src/pjlib-test/timer.c b/pjlib/src/pjlib-test/timer.c index 7a4a9d44ab..7acfefaaf8 100644 --- a/pjlib/src/pjlib-test/timer.c +++ b/pjlib/src/pjlib-test/timer.c @@ -68,7 +68,7 @@ static int test_timer_heap(void) pool = pj_pool_create( mem, NULL, size, 4000, NULL); if (!pool) { PJ_LOG(3,("test", "...error: unable to create pool of %lu bytes", - size)); + (unsigned long)size)); return -10; } @@ -161,8 +161,8 @@ static int test_timer_heap(void) } while (PJ_TIME_VAL_LTE(now, expire)&&pj_timer_heap_count(timer) > 0); if (pj_timer_heap_count(timer)) { - PJ_LOG(3, (THIS_FILE, "ERROR: %ld timers left", - pj_timer_heap_count(timer))); + PJ_LOG(3, (THIS_FILE, "ERROR: %lu timers left", + (unsigned long)pj_timer_heap_count(timer))); ++err; } t_sched.u32.lo /= count; @@ -715,8 +715,8 @@ static int timer_stress_test(void) if (timer) pj_timer_heap_destroy(timer); - PJ_LOG(3,("test", "Total memory of timer heap: %ld", - pj_timer_heap_mem_size(ST_ENTRY_COUNT))); + PJ_LOG(3,("test", "Total memory of timer heap: %lu", + (unsigned long)pj_timer_heap_mem_size(ST_ENTRY_COUNT))); if (tparam.idx) pj_atomic_destroy(tparam.idx); diff --git a/pjmedia/src/pjmedia-codec/and_aud_mediacodec.cpp b/pjmedia/src/pjmedia-codec/and_aud_mediacodec.cpp index fbc1fa6c99..5b95181d78 100644 --- a/pjmedia/src/pjmedia-codec/and_aud_mediacodec.cpp +++ b/pjmedia/src/pjmedia-codec/and_aud_mediacodec.cpp @@ -1141,7 +1141,8 @@ static pj_status_t and_media_codec_encode(pjmedia_codec *codec, } else { PJ_LOG(4,(THIS_FILE, "Encoder getInputBuffer " "size: %lu, expecting %d.", - output_size, input_size)); + (unsigned long)output_size, + input_size)); } goto on_return; } @@ -1262,7 +1263,8 @@ static pj_status_t and_media_codec_decode(pjmedia_codec *codec, &input_size); if (input_buf == 0) { PJ_LOG(4,(THIS_FILE, "Decoder getInputBuffer failed " - "return input_buf=%d, size=%lu", *input_buf, input_size)); + "return input_buf=%d, size=%lu", *input_buf, + (unsigned long)input_size)); goto on_return; } diff --git a/pjmedia/src/pjmedia-codec/and_vid_mediacodec.cpp b/pjmedia/src/pjmedia-codec/and_vid_mediacodec.cpp index 4ee7e17a61..6391e479cf 100644 --- a/pjmedia/src/pjmedia-codec/and_vid_mediacodec.cpp +++ b/pjmedia/src/pjmedia-codec/and_vid_mediacodec.cpp @@ -1033,7 +1033,8 @@ static pj_status_t and_media_codec_encode_begin(pjmedia_vid_codec *codec, } else { PJ_LOG(4,(THIS_FILE, "Encoder getInputBuffer " "size: %lu, expecting %lu.", - output_size, input->size)); + (unsigned long)output_size, + (unsigned long)input->size)); } goto on_return; } diff --git a/pjmedia/src/pjmedia-codec/openh264.cpp b/pjmedia/src/pjmedia-codec/openh264.cpp index bda2edbc16..6f8f86f1fa 100644 --- a/pjmedia/src/pjmedia-codec/openh264.cpp +++ b/pjmedia/src/pjmedia-codec/openh264.cpp @@ -1182,7 +1182,7 @@ static pj_status_t oh264_codec_decode(pjmedia_vid_codec *codec, PJ_LOG(5,(THIS_FILE, "Decode couldn't produce picture, " "input nframes=%lu, concatenated size=%d bytes, ret=%d", - count, whole_len, ret)); + (unsigned long)count, whole_len, ret)); } return status; diff --git a/pjmedia/src/pjmedia-codec/opus.c b/pjmedia/src/pjmedia-codec/opus.c index 1925c7a202..7841792fc4 100644 --- a/pjmedia/src/pjmedia-codec/opus.c +++ b/pjmedia/src/pjmedia-codec/opus.c @@ -931,7 +931,7 @@ static pj_status_t codec_parse( pjmedia_codec *codec, sizeof(tmp_buf)); if (size < 0) { PJ_LOG(5, (THIS_FILE, "Parse failed! (pkt_size=%lu, err=%d)", - pkt_size, size)); + (unsigned long)pkt_size, size)); pj_mutex_unlock (opus_data->mutex); return PJMEDIA_CODEC_EFAILED; } diff --git a/pjmedia/src/pjmedia-codec/vid_toolbox.m b/pjmedia/src/pjmedia-codec/vid_toolbox.m index dc27c45611..f12050f43d 100644 --- a/pjmedia/src/pjmedia-codec/vid_toolbox.m +++ b/pjmedia/src/pjmedia-codec/vid_toolbox.m @@ -1404,8 +1404,8 @@ static pj_status_t vtool_codec_decode(pjmedia_vid_codec *codec, PJMEDIA_EVENT_PUBLISH_DEFAULT); PJ_LOG(5,(THIS_FILE, "Decode couldn't produce picture, " - "input nframes=%ld, concatenated size=%d bytes", - count, whole_len)); + "input nframes=%lu, concatenated size=%d bytes", + (unsigned long)count, whole_len)); output->type = PJMEDIA_FRAME_TYPE_NONE; output->size = 0; diff --git a/pjmedia/src/pjmedia-codec/vpx.c b/pjmedia/src/pjmedia-codec/vpx.c index 9edfb6256b..d71ca63114 100644 --- a/pjmedia/src/pjmedia-codec/vpx.c +++ b/pjmedia/src/pjmedia-codec/vpx.c @@ -830,7 +830,7 @@ static pj_status_t vpx_codec_decode_(pjmedia_vid_codec *codec, PJ_LOG(4,(THIS_FILE, "Decode couldn't produce picture, " "input nframes=%lu, concatenated size=%d bytes", - count, whole_len)); + (unsigned long)count, whole_len)); output->type = PJMEDIA_FRAME_TYPE_NONE; output->size = 0; diff --git a/pjmedia/src/pjmedia/conference.c b/pjmedia/src/pjmedia/conference.c index 8b53798ad3..28d1d5b042 100644 --- a/pjmedia/src/pjmedia/conference.c +++ b/pjmedia/src/pjmedia/conference.c @@ -1049,6 +1049,7 @@ PJ_DEF(pj_status_t) pjmedia_conf_disconnect_port( pjmedia_conf *conf, unsigned sink_slot ) { struct conf_port *src_port, *dst_port; + pj_bool_t no_conn = PJ_FALSE; unsigned i; /* Check arguments */ @@ -1098,9 +1099,12 @@ PJ_DEF(pj_status_t) pjmedia_conf_disconnect_port( pjmedia_conf *conf, pjmedia_delay_buf_reset(src_port->delay_buf); } + /* Evaluate connect_cnt with mutex, but pause sound dev outside mutex */ + no_conn = (conf->connect_cnt == 0); + pj_mutex_unlock(conf->mutex); - if (conf->connect_cnt == 0) { + if (no_conn) { pause_sound(conf); } diff --git a/pjmedia/src/pjmedia/transport_srtp_dtls.c b/pjmedia/src/pjmedia/transport_srtp_dtls.c index 97c2f3ec01..c1daa4223a 100644 --- a/pjmedia/src/pjmedia/transport_srtp_dtls.c +++ b/pjmedia/src/pjmedia/transport_srtp_dtls.c @@ -745,7 +745,7 @@ static pj_status_t send_raw(dtls_srtp *ds, unsigned idx, const void *buf, { #if DTLS_DEBUG PJ_LOG(2,(ds->base.name, "DTLS-SRTP %s sending %lu bytes", - CHANNEL_TO_STRING(idx), len)); + CHANNEL_TO_STRING(idx), (unsigned long)len)); #endif return (idx == RTP_CHANNEL? @@ -1280,7 +1280,7 @@ static pj_status_t dtls_on_recv(pjmedia_transport *tp, unsigned idx, #if DTLS_DEBUG PJ_LOG(2,(ds->base.name, "DTLS-SRTP %s receiving %lu bytes", - CHANNEL_TO_STRING(idx), size)); + CHANNEL_TO_STRING(idx), (unsigned long)size)); #endif /* This is DTLS packet, let's process it. Note that if DTLS nego has diff --git a/pjmedia/src/pjmedia/vid_port.c b/pjmedia/src/pjmedia/vid_port.c index 358ff52509..52fe49ab4b 100644 --- a/pjmedia/src/pjmedia/vid_port.c +++ b/pjmedia/src/pjmedia/vid_port.c @@ -1398,7 +1398,8 @@ static pj_status_t vid_pasv_port_put_frame(struct pjmedia_port *this_port, if (frame->size != vp->src_size) { if (frame->size > 0) { PJ_LOG(4,(THIS_FILE, "Unexpected frame size %lu, expected %lu", - frame->size, vp->src_size)); + (unsigned long)frame->size, + (unsigned long)vp->src_size)); } pj_memcpy(&frame_, frame, sizeof(pjmedia_frame)); diff --git a/pjmedia/src/pjmedia/wav_writer.c b/pjmedia/src/pjmedia/wav_writer.c index 25214adadd..dbe491c9ce 100644 --- a/pjmedia/src/pjmedia/wav_writer.c +++ b/pjmedia/src/pjmedia/wav_writer.c @@ -220,7 +220,7 @@ PJ_DEF(pj_status_t) pjmedia_wav_writer_port_create( pj_pool_t *pool, (int)fport->base.info.name.slen, fport->base.info.name.ptr, PJMEDIA_PIA_SRATE(&fport->base.info), - fport->bufsize / 1000)); + (unsigned long)(fport->bufsize / 1000))); return PJ_SUCCESS; diff --git a/pjmedia/src/test/codec_vectors.c b/pjmedia/src/test/codec_vectors.c index fd34664ba1..f561354d2d 100644 --- a/pjmedia/src/test/codec_vectors.c +++ b/pjmedia/src/test/codec_vectors.c @@ -178,7 +178,8 @@ static int codec_test_encode(pjmedia_codec_mgr *mgr, break; } - PJ_LOG(1,(THIS_FILE," failed: mismatch at pos %ld", pos+i)); + PJ_LOG(1,(THIS_FILE," failed: mismatch at pos %lu", + (unsigned long)(pos+i))); rc = -200; break; } diff --git a/pjnath/src/pjnath-test/server.c b/pjnath/src/pjnath-test/server.c index 2b375f09a8..5b6699df4b 100644 --- a/pjnath/src/pjnath-test/server.c +++ b/pjnath/src/pjnath-test/server.c @@ -1047,8 +1047,8 @@ static pj_bool_t alloc_on_data_recvfrom(pj_activesock_t *asock, } } if (i==alloc->perm_cnt) { - PJ_LOG(5,("", "Client %s received %ld bytes unauthorized data from peer %s", - client_info, size, peer_info)); + PJ_LOG(5,("", "Client %s received %lu bytes unauthorized data from peer %s", + client_info, (unsigned long)size, peer_info)); if (alloc->perm_cnt == 0) PJ_LOG(5,("", "Client %s has no permission", client_info)); return PJ_TRUE; @@ -1073,8 +1073,8 @@ static pj_bool_t alloc_on_data_recvfrom(pj_activesock_t *asock, /* Send */ sent = size; - PJ_LOG(5,("", "Forwarding %ld bytes data from peer %s to client %s", - sent, peer_info, client_info)); + PJ_LOG(5,("", "Forwarding %lu bytes data from peer %s to client %s", + (unsigned long)sent, peer_info, client_info)); pj_activesock_sendto(alloc->test_srv->turn_sock, &alloc->send_key, buffer, &sent, 0, &alloc->client_addr, diff --git a/pjnath/src/pjnath/stun_msg.c b/pjnath/src/pjnath/stun_msg.c index 23f9ee3230..48b061e5b4 100644 --- a/pjnath/src/pjnath/stun_msg.c +++ b/pjnath/src/pjnath/stun_msg.c @@ -2547,8 +2547,8 @@ PJ_DEF(pj_status_t) pj_stun_msg_decode(pj_pool_t *pool, if (pdu_len > 0) { /* Stray trailing bytes */ PJ_LOG(4,(THIS_FILE, - "Error decoding STUN message: unparsed trailing %ld bytes", - pdu_len)); + "Error decoding STUN message: unparsed trailing %lu bytes", + (unsigned long)pdu_len)); return PJNATH_EINSTUNMSGLEN; } diff --git a/pjnath/src/pjnath/turn_session.c b/pjnath/src/pjnath/turn_session.c index d14204aef8..1ed0a40564 100644 --- a/pjnath/src/pjnath/turn_session.c +++ b/pjnath/src/pjnath/turn_session.c @@ -1199,7 +1199,7 @@ PJ_DEF(pj_status_t) pj_turn_session_connection_bind( PJ_STUN_ATTR_CONNECTION_ID, conn_id); - conn_bind = PJ_POOL_ZALLOC_T(pool, struct conn_bind_t); + conn_bind = PJ_POOL_ZALLOC_T(tdata->pool, struct conn_bind_t); conn_bind->id = conn_id; pj_sockaddr_cp(&conn_bind->peer_addr, peer_addr); conn_bind->peer_addr_len = addr_len; diff --git a/pjnath/src/pjnath/upnp.c b/pjnath/src/pjnath/upnp.c index 0747432a56..f16a679ee0 100644 --- a/pjnath/src/pjnath/upnp.c +++ b/pjnath/src/pjnath/upnp.c @@ -325,12 +325,14 @@ static void add_device(const char *dev_id, const char *url) { unsigned i; + pj_mutex_lock(upnp_mgr.mutex); + if (upnp_mgr.igd_cnt >= MAX_DEVS) { + pj_mutex_unlock(upnp_mgr.mutex); PJ_LOG(3, (THIS_FILE, "Warning: Too many UPnP devices discovered")); return; } - pj_mutex_lock(upnp_mgr.mutex); for (i = 0; i < upnp_mgr.igd_cnt; i++) { if (!pj_strcmp2(&upnp_mgr.igd_devs[i].dev_id, dev_id) && !pj_strcmp2(&upnp_mgr.igd_devs[i].url, url)) @@ -358,6 +360,8 @@ static void set_device_online(const char *dev_id) { unsigned i; + pj_mutex_lock(upnp_mgr.mutex); + for (i = 0; i < upnp_mgr.igd_cnt; i++) { struct igd *igd = &upnp_mgr.igd_devs[i]; @@ -367,15 +371,15 @@ static void set_device_online(const char *dev_id) if (upnp_mgr.primary_igd_idx < 0) { /* If we don't have a primary IGD, use this. */ - pj_mutex_lock(upnp_mgr.mutex); upnp_mgr.primary_igd_idx = i; - pj_mutex_unlock(upnp_mgr.mutex); PJ_LOG(4, (THIS_FILE, "Using primary IGD %s", upnp_mgr.igd_devs[i].dev_id.ptr)); } } } + + pj_mutex_unlock(upnp_mgr.mutex); } /* Update IGD status to offline. */ @@ -383,6 +387,8 @@ static void set_device_offline(const char *dev_id) { int i; + pj_mutex_lock(upnp_mgr.mutex); + for (i = 0; i < (int)upnp_mgr.igd_cnt; i++) { struct igd *igd = &upnp_mgr.igd_devs[i]; @@ -390,7 +396,6 @@ static void set_device_offline(const char *dev_id) if (!pj_strcmp2(&igd->dev_id, dev_id) && igd->valid) { igd->alive = PJ_FALSE; - pj_mutex_lock(upnp_mgr.mutex); if (i == upnp_mgr.primary_igd_idx) { unsigned j; @@ -409,9 +414,10 @@ static void set_device_offline(const char *dev_id) (upnp_mgr.primary_igd_idx < 0? "(none)": igd->dev_id.ptr))); } - pj_mutex_unlock(upnp_mgr.mutex); } } + + pj_mutex_unlock(upnp_mgr.mutex); } /* UPnP client callback. */ @@ -849,7 +855,6 @@ PJ_DEF(pj_status_t)pj_upnp_del_port_mapping(const pj_sockaddr *mapped_addr) } igd = &upnp_mgr.igd_devs[upnp_mgr.primary_igd_idx]; - pj_mutex_unlock(upnp_mgr.mutex); /* Compare IGD's public IP to the mapped public address. */ pj_sockaddr_cp(&host_addr, mapped_addr); @@ -870,7 +875,8 @@ PJ_DEF(pj_status_t)pj_upnp_del_port_mapping(const pj_sockaddr *mapped_addr) } } } - + pj_mutex_unlock(upnp_mgr.mutex); + if (!igd) { /* Either the IGD we previously requested to add port mapping has become * offline, or the address is actually not a valid. diff --git a/pjnath/src/pjturn-srv/allocation.c b/pjnath/src/pjturn-srv/allocation.c index b0ecbafaa0..640c87a3dc 100644 --- a/pjnath/src/pjturn-srv/allocation.c +++ b/pjnath/src/pjturn-srv/allocation.c @@ -1034,8 +1034,8 @@ static void handle_peer_pkt(pj_turn_allocation *alloc, char peer_addr[80]; pj_sockaddr_print(src_addr, peer_addr, sizeof(peer_addr), 3); PJ_LOG(4,(alloc->obj_name, "Client %s: discarded data from %s " - "because it's too long (%ld bytes)", - alloc->info, peer_addr, len)); + "because it's too long (%lu bytes)", + alloc->info, peer_addr, (unsigned long)len)); return; } diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c index b6eeda3483..de0e7b77c1 100644 --- a/pjsip-apps/src/pjsua/pjsua_app.c +++ b/pjsip-apps/src/pjsua/pjsua_app.c @@ -1111,8 +1111,10 @@ void on_ip_change_progress(pjsua_ip_change_op op, case PJSUA_IP_CHANGE_OP_COMPLETED: pj_ansi_snprintf(info_str, sizeof(info_str), "done"); + break; default: - info_str[0] = '\0'; + pj_ansi_snprintf(info_str, sizeof(info_str), + "unknown-op"); break; } PJ_LOG(3,(THIS_FILE, "IP change progress report : %s", info_str)); diff --git a/pjsip-apps/src/pygui/chat.py b/pjsip-apps/src/pygui/chat.py index 00b8e47c46..41ded97231 100644 --- a/pjsip-apps/src/pygui/chat.py +++ b/pjsip-apps/src/pygui/chat.py @@ -207,7 +207,7 @@ def addParticipant(self, uri, call_inst=None): # it is a temporary one and not really registered to acc bud = None try: - bud = self._acc.findBuddy(uri_str) + bud = self._acc.findBuddy2(uri_str) except: bud = buddy.Buddy(None) bud_cfg = pj.BuddyConfig() diff --git a/pjsip-apps/src/swig/pjsua2.i b/pjsip-apps/src/swig/pjsua2.i index d33e843ffd..0aba16c0f0 100644 --- a/pjsip-apps/src/swig/pjsua2.i +++ b/pjsip-apps/src/swig/pjsua2.i @@ -121,6 +121,13 @@ using namespace pj; %feature("director") FindBuddyMatch; %feature("director") AudioMediaPlayer; %feature("director") AudioMediaPort; +// PendingJob is only used on Python +#ifdef SWIGPYTHON + %feature("director") PendingJob; +#else + %ignore pj::PendingJob; + %ignore pj::Endpoint::utilAddPendingJob; +#endif // // STL stuff. @@ -237,4 +244,11 @@ using namespace pj; %} #endif +#ifdef SWIGPYTHON +%pythonprepend pj::Endpoint::utilAddPendingJob(PendingJob *job) %{ + # print('disowning job') + job.__disown__() +%} +#endif + %include "pjsua2/endpoint.hpp" diff --git a/pjsip-apps/src/swig/python/test.py b/pjsip-apps/src/swig/python/test.py index 894420b5c4..0deb77d3db 100644 --- a/pjsip-apps/src/swig/python/test.py +++ b/pjsip-apps/src/swig/python/test.py @@ -3,6 +3,9 @@ import time from collections import deque import struct +import gc +from random import randint +import threading write=sys.stdout.write @@ -210,6 +213,69 @@ def ua_tonegen_test(): ep.libDestroy() +class RandomIntVal(): + def __init__(self): + self.value = randint(0, 100000) + +class TestJob(pj.PendingJob): + def __init__(self): + super().__init__() + self.val = RandomIntVal() + print("Job created id:", id(self), "value:", self.val.value) + + def execute(self, is_pending): + print("Executing job value:", self.val.value, is_pending) + + def __del__(self): + print("Job deleted id:", id(self), "value:", self.val.value) + +def add_new_job1(ep): + print("Creating job 1") + job = TestJob() + print("Adding job 1") + ep.utilAddPendingJob(job) + +# Function to be executed in a separate thread +def add_new_job2(ep): + ep.libRegisterThread("thread") + print("Creating job 2") + job = TestJob() + print("Adding job 2") + ep.utilAddPendingJob(job) + +def ua_pending_job_test(): + write("PendingJob test.." + "\r\n") + ep_cfg = pj.EpConfig() + ep_cfg.uaConfig.threadCnt = 0 + ep_cfg.uaConfig.mainThreadOnly = True + + ep = pj.Endpoint() + ep.libCreate() + ep.libInit(ep_cfg) + ep.libStart() + + # test 1 + # adding job from a separate function + add_new_job1(ep) + + # test 2 + # adding job from a different thread + my_thread = threading.Thread(target=add_new_job2, args=(ep,)) + my_thread.start() + + time.sleep(1) + print("Collecting gc 1") + gc.collect() + + print("Handling events") + for _ in range(100): + ep.libHandleEvents(10) + + print("Collecting gc 2") + gc.collect() + + ep.libDestroy() + # # main() # @@ -219,6 +285,7 @@ def ua_tonegen_test(): ua_run_log_test() ua_run_ua_test() ua_tonegen_test() + ua_pending_job_test() sys.exit(0) diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h index d7ee2c68aa..08fe11fc64 100644 --- a/pjsip/include/pjsua-lib/pjsua_internal.h +++ b/pjsip/include/pjsua-lib/pjsua_internal.h @@ -772,6 +772,7 @@ void pjsua_ice_check_start_trickling(pjsua_call *call, pj_bool_t pjsua_call_media_is_changing(pjsua_call *call); pj_status_t pjsua_call_media_init(pjsua_call_media *call_med, pjmedia_type type, + const pjmedia_sdp_session *rem_sdp, const pjsua_transport_config *tcfg, int security_level, int *sip_err_code, diff --git a/pjsip/src/pjsip-simple/publishc.c b/pjsip/src/pjsip-simple/publishc.c index a18a32f9ae..58222eea1f 100644 --- a/pjsip/src/pjsip-simple/publishc.c +++ b/pjsip/src/pjsip-simple/publishc.c @@ -777,7 +777,6 @@ PJ_DEF(pj_status_t) pjsip_publishc_send(pjsip_publishc *pubc, return PJ_EBUSY; } } - pj_mutex_unlock(pubc->mutex); /* If via_addr is set, use this address for the Via header. */ if (pubc->via_addr.host.slen > 0) { @@ -798,6 +797,9 @@ PJ_DEF(pj_status_t) pjsip_publishc_send(pjsip_publishc *pubc, * may be called even before send_request() returns! */ ++pubc->pending_tsx; + + pj_mutex_unlock(pubc->mutex); + status = pjsip_endpt_send_request(pubc->endpt, tdata, -1, pubc, &tsx_callback); if (status!=PJ_SUCCESS) { diff --git a/pjsip/src/pjsip-ua/sip_100rel.c b/pjsip/src/pjsip-ua/sip_100rel.c index df38e3c410..3cfd8dcc4e 100644 --- a/pjsip/src/pjsip-ua/sip_100rel.c +++ b/pjsip/src/pjsip-ua/sip_100rel.c @@ -857,8 +857,9 @@ PJ_DEF(pj_status_t) pjsip_100rel_tx_response(pjsip_inv_session *inv, status = PJ_SUCCESS; PJ_LOG(4,(dd->inv->dlg->obj_name, - "Reliable %d response enqueued (%ld pending)", - code, pj_list_size(&dd->uas_state->tx_data_list))); + "Reliable %d response enqueued (%lu pending)", + code, (unsigned long) + pj_list_size(&dd->uas_state->tx_data_list))); } else { pj_list_push_back(&dd->uas_state->tx_data_list, tl); diff --git a/pjsip/src/pjsip/sip_endpoint.c b/pjsip/src/pjsip/sip_endpoint.c index 62c6f2b9ea..4f9c6e99f4 100644 --- a/pjsip/src/pjsip/sip_endpoint.c +++ b/pjsip/src/pjsip/sip_endpoint.c @@ -788,7 +788,8 @@ PJ_DEF(pj_status_t) pjsip_endpt_schedule_timer_dbg(pjsip_endpoint *endpt, int src_line) { PJ_LOG(6, (THIS_FILE, "pjsip_endpt_schedule_timer(entry=%p, delay=%lu.%lu)", - entry, delay->sec, delay->msec)); + entry, (unsigned long)delay->sec, + (unsigned long)delay->msec)); return pj_timer_heap_schedule_dbg(endpt->timer_heap, entry, delay, src_file, src_line); } @@ -797,8 +798,9 @@ PJ_DEF(pj_status_t) pjsip_endpt_schedule_timer( pjsip_endpoint *endpt, pj_timer_entry *entry, const pj_time_val *delay ) { - PJ_LOG(6, (THIS_FILE, "pjsip_endpt_schedule_timer(entry=%p, delay=%u.%u)", - entry, delay->sec, delay->msec)); + PJ_LOG(6, (THIS_FILE, "pjsip_endpt_schedule_timer(entry=%p, delay=%lu.%lu)", + entry, (unsigned long)delay->sec, + (unsigned long)delay->msec)); return pj_timer_heap_schedule( endpt->timer_heap, entry, delay ); } #endif @@ -817,8 +819,9 @@ PJ_DEF(pj_status_t) pjsip_endpt_schedule_timer_w_grp_lock_dbg( int src_line) { PJ_LOG(6, (THIS_FILE, "pjsip_endpt_schedule_timer_w_grp_lock" - "(entry=%p, delay=%ld.%ld, grp_lock=%p)", - entry, delay->sec, delay->msec, grp_lock)); + "(entry=%p, delay=%lu.%lu, grp_lock=%p)", + entry, (unsigned long)delay->sec, + (unsigned long)delay->msec, grp_lock)); return pj_timer_heap_schedule_w_grp_lock_dbg(endpt->timer_heap, entry, delay, id_val, grp_lock, src_file, src_line); @@ -832,8 +835,9 @@ PJ_DEF(pj_status_t) pjsip_endpt_schedule_timer_w_grp_lock( pj_grp_lock_t *grp_lock ) { PJ_LOG(6, (THIS_FILE, "pjsip_endpt_schedule_timer_w_grp_lock" - "(entry=%p, delay=%u.%u, grp_lock=%p)", - entry, delay->sec, delay->msec, grp_lock)); + "(entry=%p, delay=%lu.%lu, grp_lock=%p)", + entry, (unsigned long)delay->sec, + (unsigned long)delay->msec, grp_lock)); return pj_timer_heap_schedule_w_grp_lock( endpt->timer_heap, entry, delay, id_val, grp_lock ); } @@ -1314,8 +1318,8 @@ PJ_DEF(void) pjsip_endpt_dump( pjsip_endpoint *endpt, pj_bool_t detail ) /* Pool health. */ PJ_LOG(3, (THIS_FILE," Endpoint pool capacity=%lu, used_size=%lu", - pj_pool_get_capacity(endpt->pool), - pj_pool_get_used_size(endpt->pool))); + (unsigned long)pj_pool_get_capacity(endpt->pool), + (unsigned long)pj_pool_get_used_size(endpt->pool))); /* Resolver */ #if PJSIP_HAS_RESOLVER @@ -1333,7 +1337,7 @@ PJ_DEF(void) pjsip_endpt_dump( pjsip_endpoint *endpt, pj_bool_t detail ) pj_timer_heap_dump(endpt->timer_heap); #else PJ_LOG(3,(THIS_FILE, " Timer heap has %lu entries", - pj_timer_heap_count(endpt->timer_heap))); + (unsigned long)pj_timer_heap_count(endpt->timer_heap))); #endif /* Unlock mutex. */ diff --git a/pjsip/src/pjsip/sip_transaction.c b/pjsip/src/pjsip/sip_transaction.c index e89c6d6fa5..a669f8f7a8 100644 --- a/pjsip/src/pjsip/sip_transaction.c +++ b/pjsip/src/pjsip/sip_transaction.c @@ -880,6 +880,7 @@ pjsip_tsx_detect_merged_requests(pjsip_rx_data *rdata) { pj_str_t key, key2; pj_uint32_t hval = 0; + pjsip_transaction *tsx = NULL; pj_status_t status; PJ_ASSERT_RETURN(rdata->msg_info.msg->type == PJSIP_REQUEST_MSG, NULL); @@ -895,12 +896,15 @@ pjsip_tsx_detect_merged_requests(pjsip_rx_data *rdata) if (status != PJ_SUCCESS) return NULL; + pj_mutex_lock( mod_tsx_layer.mutex ); + /* This request must not match any transaction in our primary hash * table. */ if (pj_hash_get_lower(mod_tsx_layer.htable, key.ptr, (unsigned)key.slen, &hval) != NULL) { + pj_mutex_unlock( mod_tsx_layer.mutex); return NULL; } @@ -910,14 +914,18 @@ pjsip_tsx_detect_merged_requests(pjsip_rx_data *rdata) status = create_tsx_key_2543(rdata->tp_info.pool, &key2, PJSIP_ROLE_UAS, &rdata->msg_info.cseq->method, rdata, PJ_FALSE); - if (status != PJ_SUCCESS) + if (status != PJ_SUCCESS) { + pj_mutex_unlock( mod_tsx_layer.mutex); return NULL; + } hval = 0; - return (pjsip_transaction *) pj_hash_get_lower(mod_tsx_layer.htable2, - key2.ptr, - (unsigned)key2.slen, - &hval); + tsx = pj_hash_get_lower(mod_tsx_layer.htable2, key2.ptr, + (unsigned)key2.slen, &hval); + + pj_mutex_unlock( mod_tsx_layer.mutex); + + return tsx; } /* This module callback is called when endpoint has received an @@ -2187,11 +2195,12 @@ static void send_msg_callback( pjsip_send_state *send_state, else sc = PJSIP_SC_TSX_TRANSPORT_ERROR; - /* We terminate the transaction for 502 error. For 503, - * we will retry it. - * See https://github.com/pjsip/pjproject/pull/3805 + /* For UAC tsx, we directly terminate the transaction. + * For UAS tsx, we terminate the transaction for 502 error, + * and will retry for 503. + * See #3805 and #3806. */ - if (sc == PJSIP_SC_BAD_GATEWAY && + if ((tsx->role == PJSIP_ROLE_UAC || sc == PJSIP_SC_BAD_GATEWAY) && tsx->state != PJSIP_TSX_STATE_TERMINATED && tsx->state != PJSIP_TSX_STATE_DESTROYED) { @@ -2212,6 +2221,13 @@ static void send_msg_callback( pjsip_send_state *send_state, tsx_set_state( tsx, PJSIP_TSX_STATE_DESTROYED, PJSIP_EVENT_TRANSPORT_ERROR, send_state->tdata, 0); + } else if (tsx->role == PJSIP_ROLE_UAS && + tsx->transport_flag & TSX_HAS_PENDING_RESCHED && + tsx->state != PJSIP_TSX_STATE_TERMINATED && + tsx->state != PJSIP_TSX_STATE_DESTROYED) + { + tsx->transport_flag &= ~(TSX_HAS_PENDING_RESCHED); + tsx_resched_retransmission(tsx); } } else { @@ -2266,7 +2282,16 @@ static void transport_callback(void *token, pjsip_tx_data *tdata, pj_grp_lock_acquire(tsx->grp_lock); tsx->transport_flag &= ~(TSX_HAS_PENDING_TRANSPORT); - if (sent > 0) { + if (sent > 0 || tsx->role == PJSIP_ROLE_UAS) { + if (sent < 0) { + /* For UAS transactions, we just print error log + * and continue as per normal. + */ + PJ_PERROR(2,(tsx->obj_name, (pj_status_t)-sent, + "Transport failed to send %s!", + pjsip_tx_data_get_info(tdata))); + } + /* Pending destroy? */ if (tsx->transport_flag & TSX_HAS_PENDING_DESTROY) { tsx_set_state( tsx, PJSIP_TSX_STATE_DESTROYED, @@ -2299,7 +2324,7 @@ static void transport_callback(void *token, pjsip_tx_data *tdata, } pj_grp_lock_release(tsx->grp_lock); - if (sent < 0) { + if (sent < 0 && tsx->role == PJSIP_ROLE_UAC) { pj_time_val delay = {0, 0}; PJ_PERROR(2,(tsx->obj_name, (pj_status_t)-sent, @@ -2434,8 +2459,11 @@ static pj_status_t tsx_send_msg( pjsip_transaction *tsx, /* If we have resolved the server, we treat the error as permanent error. * Terminate transaction with transport error failure. + * Only applicable for UAC transactions. */ - if (tsx->transport_flag & TSX_HAS_RESOLVED_SERVER) { + if (tsx->role == PJSIP_ROLE_UAC && + (tsx->transport_flag & TSX_HAS_RESOLVED_SERVER)) + { char errmsg[PJ_ERR_MSG_SIZE]; pj_str_t err; diff --git a/pjsip/src/pjsip/sip_transport.c b/pjsip/src/pjsip/sip_transport.c index 0d103f0997..7ce37a4874 100644 --- a/pjsip/src/pjsip/sip_transport.c +++ b/pjsip/src/pjsip/sip_transport.c @@ -2225,8 +2225,8 @@ PJ_DEF(pj_ssize_t) pjsip_tpmgr_receive_packet( pjsip_tpmgr *mgr, */ if (tmp.slen) { PJ_LOG(2, (THIS_FILE, - "Dropping %ld bytes packet from %s %s:%d %.*s\n", - msg_fragment_size, + "Dropping %lu bytes packet from %s %s:%d %.*s\n", + (unsigned long)msg_fragment_size, rdata->tp_info.transport->type_name, rdata->pkt_info.src_name, rdata->pkt_info.src_port, diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c index d951ccb45c..b2a4df9295 100644 --- a/pjsip/src/pjsua-lib/pjsua_acc.c +++ b/pjsip/src/pjsua-lib/pjsua_acc.c @@ -834,8 +834,7 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id, pjsip_name_addr *id_name_addr = NULL; pjsip_sip_uri *id_sip_uri = NULL; pjsip_sip_uri *reg_sip_uri = NULL; - pj_uint32_t local_route_crc, global_route_crc; - pjsip_route_hdr global_route; + pj_uint32_t local_route_crc; pjsip_route_hdr local_route; pj_str_t acc_proxy[PJSUA_ACC_MAX_PROXIES]; pj_bool_t update_reg = PJ_FALSE; @@ -887,6 +886,7 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id, /* Registrar URI */ if (pj_strcmp(&acc->cfg.reg_uri, &cfg->reg_uri) && cfg->reg_uri.slen) { pjsip_uri *reg_uri; + unsigned rcnt; /* Need to parse reg_uri to get the elements: */ reg_uri = pjsip_parse_uri(acc->pool, cfg->reg_uri.ptr, @@ -907,6 +907,23 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id, } reg_sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(reg_uri); + + /* Clear route headers from the previous registrar. */ + rcnt = (unsigned)pj_list_size(&acc->route_set); + if (rcnt != pjsua_var.ua_cfg.outbound_proxy_cnt + acc->cfg.proxy_cnt) { + pjsip_route_hdr *hr; + unsigned i; + + for (i=pjsua_var.ua_cfg.outbound_proxy_cnt + acc->cfg.proxy_cnt, + hr=acc->route_set.prev; + iprev; + pj_list_erase(hr); + hr = prev; + } + } } /* REGISTER header list */ @@ -918,22 +935,6 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id, /* SUBSCRIBE header list */ update_hdr_list(acc->pool, &acc->cfg.sub_hdr_list, &cfg->sub_hdr_list); - /* Global outbound proxy */ - global_route_crc = calc_proxy_crc(pjsua_var.ua_cfg.outbound_proxy, - pjsua_var.ua_cfg.outbound_proxy_cnt); - if (global_route_crc != acc->global_route_crc) { - pjsip_route_hdr *r; - - /* Copy from global outbound proxies */ - pj_list_init(&global_route); - r = pjsua_var.outbound_proxy.next; - while (r != &pjsua_var.outbound_proxy) { - pj_list_push_back(&global_route, - pjsip_hdr_shallow_clone(acc->pool, r)); - r = r->next; - } - } - /* Account proxy */ local_route_crc = calc_proxy_crc(cfg->proxy, cfg->proxy_cnt); if (local_route_crc != acc->local_route_crc) { @@ -966,6 +967,33 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id, local_route_crc = calc_proxy_crc(acc_proxy, cfg->proxy_cnt); } + if (local_route_crc != acc->local_route_crc) { + unsigned i; + pjsip_route_hdr *r = &acc->route_set; + + /* Remove the current account proxies from the route set */ + for (i = 0; i < pjsua_var.ua_cfg.outbound_proxy_cnt; i++) + r = r->next; + for (i = 0; i < acc->cfg.proxy_cnt; ++i) { + pjsip_route_hdr *r_ = r->next; + pj_list_erase(r_); + } + + /* Insert new proxy setting to the route set */ + pj_list_insert_list_after(r, &local_route); + + /* Update the proxy setting */ + acc->cfg.proxy_cnt = cfg->proxy_cnt; + for (i = 0; i < cfg->proxy_cnt; ++i) + acc->cfg.proxy[i] = acc_proxy[i]; + + /* Update local route CRC */ + acc->local_route_crc = local_route_crc; + + update_reg = PJ_TRUE; + unreg_first = PJ_TRUE; + } + /* == Apply the new config == */ @@ -1160,53 +1188,6 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id, unreg_first = PJ_TRUE; } - /* Global outbound proxy */ - if (global_route_crc != acc->global_route_crc) { - unsigned i; - pj_size_t rcnt; - - /* Remove the outbound proxies from the route set */ - rcnt = pj_list_size(&acc->route_set); - for (i=0; i < rcnt - acc->cfg.proxy_cnt; ++i) { - pjsip_route_hdr *r = acc->route_set.next; - pj_list_erase(r); - } - - /* Insert the outbound proxies to the beginning of route set */ - pj_list_merge_first(&acc->route_set, &global_route); - - /* Update global route CRC */ - acc->global_route_crc = global_route_crc; - - update_reg = PJ_TRUE; - unreg_first = PJ_TRUE; - } - - /* Account proxy */ - if (local_route_crc != acc->local_route_crc) { - unsigned i; - - /* Remove the current account proxies from the route set */ - for (i=0; i < acc->cfg.proxy_cnt; ++i) { - pjsip_route_hdr *r = acc->route_set.prev; - pj_list_erase(r); - } - - /* Insert new proxy setting to the route set */ - pj_list_merge_last(&acc->route_set, &local_route); - - /* Update the proxy setting */ - acc->cfg.proxy_cnt = cfg->proxy_cnt; - for (i = 0; i < cfg->proxy_cnt; ++i) - acc->cfg.proxy[i] = acc_proxy[i]; - - /* Update local route CRC */ - acc->local_route_crc = local_route_crc; - - update_reg = PJ_TRUE; - unreg_first = PJ_TRUE; - } - /* Credential info */ { unsigned i; @@ -2002,7 +1983,7 @@ static void update_service_route(pjsua_acc *acc, pjsip_rx_data *rdata) pj_size_t rcnt; /* Find and parse Service-Route headers */ - for (;;) { + for (;(rdata);) { char saved; int parsed_len; @@ -2054,9 +2035,6 @@ static void update_service_route(pjsua_acc *acc, pjsip_rx_data *rdata) break; } - if (uri_cnt == 0) - return; - /* * Update account's route set */ @@ -2416,6 +2394,9 @@ static void regc_cb(struct pjsip_regc_cbparam *param) (int)param->reason.slen, param->reason.ptr)); destroy_regc(acc, PJ_TRUE); + /* Clear Service-Route header */ + update_service_route(acc, NULL); + /* Stop keep-alive timer if any. */ update_keep_alive(acc, PJ_FALSE, NULL); } else if (PJSIP_IS_STATUS_IN_CLASS(param->code, 200)) { diff --git a/pjsip/src/pjsua-lib/pjsua_aud.c b/pjsip/src/pjsua-lib/pjsua_aud.c index 5ee718dad9..1b7756dfb1 100644 --- a/pjsip/src/pjsua-lib/pjsua_aud.c +++ b/pjsip/src/pjsua-lib/pjsua_aud.c @@ -2228,7 +2228,7 @@ PJ_DEF(pj_status_t) pjsua_set_snd_dev2(const pjsua_snd_dev_param *snd_param) unsigned alt_cr_cnt = 1; unsigned alt_cr[] = {0, 44100, 48000, 32000, 16000, 8000}; unsigned i; - pj_status_t status = -1; + pj_status_t status = PJ_SUCCESS; unsigned orig_snd_dev_mode = pjsua_var.snd_mode; PJ_ASSERT_RETURN(snd_param, PJ_EINVAL); @@ -2267,7 +2267,8 @@ PJ_DEF(pj_status_t) pjsua_set_snd_dev2(const pjsua_snd_dev_param *snd_param) PJSUA_UNLOCK(); PJ_LOG(4, (THIS_FILE, "No sound device, mode setting is ignored")); if (!pjsua_var.no_snd) - pjsua_set_no_snd_dev(); + PJ_ASSERT_RETURN(pjsua_set_no_snd_dev(), PJ_ENOTFOUND); + pj_log_pop_indent(); return status; } diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c index d340b9e9f4..f051857c9c 100644 --- a/pjsip/src/pjsua-lib/pjsua_call.c +++ b/pjsip/src/pjsua-lib/pjsua_call.c @@ -2744,8 +2744,8 @@ PJ_DEF(pj_status_t) pjsua_call_answer2(pjsua_call_id call_id, if (status != PJ_SUCCESS) goto on_return; - if (call->inv->role == PJSIP_ROLE_UAC || - !call->inv->invite_tsx || + if (!call->inv->invite_tsx || + call->inv->invite_tsx->role != PJSIP_ROLE_UAS || call->inv->invite_tsx->state >= PJSIP_TSX_STATE_COMPLETED) { PJ_LOG(3,(THIS_FILE, "Unable to answer call (no incoming INVITE or " diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c index c2a20df637..85088d98b4 100644 --- a/pjsip/src/pjsua-lib/pjsua_core.c +++ b/pjsip/src/pjsua-lib/pjsua_core.c @@ -1929,14 +1929,14 @@ PJ_DEF(pj_status_t) pjsua_destroy2(unsigned flags) /* Terminate all calls. */ if ((flags & PJSUA_DESTROY_NO_TX_MSG) == 0) { pjsua_call_hangup_all(); - } - - /* Deinit media channel of all calls (see #1717) */ - for (i=0; i<(int)pjsua_var.ua_cfg.max_calls; ++i) { - /* TODO: check if we're not allowed to send to network in the - * "flags", and if so do not do TURN allocation... - */ - pjsua_media_channel_deinit(i); + } else { + /* Deinit media channel of all calls (see #1717) */ + for (i=0; i<(int)pjsua_var.ua_cfg.max_calls; ++i) { + /* TODO: check if we're not allowed to send to network in the + * "flags", and if so do not do TURN allocation... + */ + pjsua_media_channel_deinit(i); + } } /* Set all accounts to offline */ diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c index b7dde8bdd3..f70eb18fd3 100644 --- a/pjsip/src/pjsua-lib/pjsua_media.c +++ b/pjsip/src/pjsua-lib/pjsua_media.c @@ -246,9 +246,9 @@ pj_status_t pjsua_media_subsys_destroy(unsigned flags) return PJ_SUCCESS; } -static int get_media_ip_version(pjsua_call_media *call_med) +static int get_media_ip_version(pjsua_call_media *call_med, + const pjmedia_sdp_session *rem_sdp) { - pjmedia_sdp_session *rem_sdp = call_med->call->async_call.rem_sdp; pjsua_ipv6_use ipv6_use; ipv6_use = pjsua_var.acc[call_med->call->acc_id].cfg.ipv6_media_use; @@ -287,7 +287,8 @@ static int get_media_ip_version(pjsua_call_media *call_med) */ static pj_status_t create_rtp_rtcp_sock(pjsua_call_media *call_med, const pjsua_transport_config *cfg, - pjmedia_sock_info *skinfo) + pjmedia_sock_info *skinfo, + const pjmedia_sdp_session *rem_sdp) { enum { RTP_RETRY = 100 @@ -302,7 +303,7 @@ static pj_status_t create_rtp_rtcp_sock(pjsua_call_media *call_med, pjsua_acc *acc = &pjsua_var.acc[call_med->call->acc_id]; pj_sock_t sock[2]; - use_ipv6 = (get_media_ip_version(call_med) == 6); + use_ipv6 = (get_media_ip_version(call_med, rem_sdp) == 6); use_nat64 = (acc->cfg.nat64_opt != PJSUA_NAT64_DISABLED); af = (use_ipv6 || use_nat64) ? pj_AF_INET6() : pj_AF_INET(); @@ -705,12 +706,13 @@ static pj_status_t create_rtp_rtcp_sock(pjsua_call_media *call_med, /* Create normal UDP media transports */ static pj_status_t create_udp_media_transport(const pjsua_transport_config *cfg, - pjsua_call_media *call_med) + pjsua_call_media *call_med, + const pjmedia_sdp_session *rem_sdp) { pjmedia_sock_info skinfo; pj_status_t status; - status = create_rtp_rtcp_sock(call_med, cfg, &skinfo); + status = create_rtp_rtcp_sock(call_med, cfg, &skinfo, rem_sdp); if (status != PJ_SUCCESS) { pjsua_perror(THIS_FILE, "Unable to create RTP/RTCP socket", status); @@ -745,7 +747,8 @@ static pj_status_t create_udp_media_transport(const pjsua_transport_config *cfg, /* Create loop media transport */ static pj_status_t create_loop_media_transport( const pjsua_transport_config *cfg, - pjsua_call_media *call_med) + pjsua_call_media *call_med, + const pjmedia_sdp_session *rem_sdp) { pj_status_t status; pjmedia_loop_tp_setting opt; @@ -753,7 +756,7 @@ static pj_status_t create_loop_media_transport( int af; pjsua_acc *acc = &pjsua_var.acc[call_med->call->acc_id]; - use_ipv6 = (get_media_ip_version(call_med) == 6); + use_ipv6 = (get_media_ip_version(call_med, rem_sdp) == 6); use_nat64 = (acc->cfg.nat64_opt != PJSUA_NAT64_DISABLED); af = (use_ipv6 || use_nat64) ? pj_AF_INET6() : pj_AF_INET(); @@ -992,36 +995,11 @@ static void on_ice_complete(pjmedia_transport *tp, } -/* Parse "HOST:PORT" format */ -static pj_status_t parse_host_port(const pj_str_t *host_port, - pj_str_t *host, pj_uint16_t *port) -{ - pj_str_t str_port; - - str_port.ptr = pj_strchr(host_port, ':'); - if (str_port.ptr != NULL) { - int iport; - - host->ptr = host_port->ptr; - host->slen = (str_port.ptr - host->ptr); - str_port.ptr++; - str_port.slen = host_port->slen - host->slen - 1; - iport = (int)pj_strtoul(&str_port); - if (iport < 1 || iport > 65535) - return PJ_EINVAL; - *port = (pj_uint16_t)iport; - } else { - *host = *host_port; - *port = 0; - } - - return PJ_SUCCESS; -} - /* Create ICE media transports (when ice is enabled) */ static pj_status_t create_ice_media_transport( const pjsua_transport_config *cfg, pjsua_call_media *call_med, + const pjmedia_sdp_session *remote_sdp, pj_bool_t async) { char stunip[PJ_INET6_ADDRSTRLEN]; @@ -1036,7 +1014,7 @@ static pj_status_t create_ice_media_transport( pjmedia_sdp_session *rem_sdp; acc_cfg = &pjsua_var.acc[call_med->call->acc_id].cfg; - use_ipv6 = (get_media_ip_version(call_med) == 6); + use_ipv6 = (get_media_ip_version(call_med, remote_sdp) == 6); use_nat64 = (acc_cfg->nat64_opt != PJSUA_NAT64_DISABLED); /* Make sure STUN server resolution has completed */ @@ -1183,9 +1161,13 @@ static pj_status_t create_ice_media_transport( } /* Configure TURN server */ - status = parse_host_port(&acc_cfg->turn_cfg.turn_server, - &ice_cfg.turn_tp[0].server, - &ice_cfg.turn_tp[0].port); + + /* Parse the server entry into host:port */ + status = pj_sockaddr_parse2(pj_AF_UNSPEC(), 0, + &acc_cfg->turn_cfg.turn_server, + &ice_cfg.turn_tp[0].server, + &ice_cfg.turn_tp[0].port, + NULL); if (status != PJ_SUCCESS || ice_cfg.turn_tp[0].server.slen == 0) { PJ_LOG(1,(THIS_FILE, "Invalid TURN server setting")); return PJ_EINVAL; @@ -2006,6 +1988,7 @@ pj_bool_t pjsua_call_media_is_changing(pjsua_call *call) /* Initialize the media line */ pj_status_t pjsua_call_media_init(pjsua_call_media *call_med, pjmedia_type type, + const pjmedia_sdp_session *rem_sdp, const pjsua_transport_config *tcfg, int security_level, int *sip_err_code, @@ -2049,9 +2032,10 @@ pj_status_t pjsua_call_media_init(pjsua_call_media *call_med, pjsua_set_media_tp_state(call_med, PJSUA_MED_TP_CREATING); if (acc->cfg.use_loop_med_tp) { - status = create_loop_media_transport(tcfg, call_med); + status = create_loop_media_transport(tcfg, call_med, rem_sdp); } else if (acc->cfg.ice_cfg.enable_ice) { - status = create_ice_media_transport(tcfg, call_med, async); + status = create_ice_media_transport(tcfg, call_med, rem_sdp, + async); if (async && status == PJ_EPENDING) { /* We will resume call media initialization in the * on_ice_complete() callback. @@ -2062,7 +2046,7 @@ pj_status_t pjsua_call_media_init(pjsua_call_media *call_med, return PJ_EPENDING; } } else { - status = create_udp_media_transport(tcfg, call_med); + status = create_udp_media_transport(tcfg, call_med, rem_sdp); } if (status != PJ_SUCCESS) { @@ -2538,15 +2522,17 @@ pj_status_t pjsua_media_channel_init(pjsua_call_id call_id, PJ_LOG(4,(THIS_FILE, "Call %d: setting media direction " "#%d to %d.", call_id, mi, call_med->def_dir)); - } else if (!reinit) { - /* Initialize default initial media direction as bidirectional */ + } else if (!reinit || mi >= call->med_cnt) { + /* Initialize default media direction as bidirectional, + * for initial media or newly added media. + */ call_med->def_dir = PJMEDIA_DIR_ENCODING_DECODING; } if (enabled) { call_med->enable_rtcp_mux = acc->cfg.enable_rtcp_mux; - status = pjsua_call_media_init(call_med, media_type, + status = pjsua_call_media_init(call_med, media_type, rem_sdp, &acc->cfg.rtp_cfg, security_level, sip_err_code, async, diff --git a/pjsip/src/pjsua-lib/pjsua_vid.c b/pjsip/src/pjsua-lib/pjsua_vid.c index c34001d13f..e73badf8cb 100644 --- a/pjsip/src/pjsua-lib/pjsua_vid.c +++ b/pjsip/src/pjsua-lib/pjsua_vid.c @@ -2088,7 +2088,7 @@ static pj_status_t call_add_video(pjsua_call *call, /* Initialize call media */ call_med = &call->media_prov[call->med_prov_cnt++]; - status = pjsua_call_media_init(call_med, PJMEDIA_TYPE_VIDEO, + status = pjsua_call_media_init(call_med, PJMEDIA_TYPE_VIDEO, NULL, &acc_cfg->rtp_cfg, call->secure_level, NULL, PJ_FALSE, NULL); if (status != PJ_SUCCESS) @@ -2134,6 +2134,7 @@ static pj_status_t call_add_video(pjsua_call *call, pjmedia_sdp_media_add_attr(sdp_m, a); } + call_med->def_dir = dir; /* Update SDP media line by media transport */ status = pjmedia_transport_encode_sdp(call_med->tp, pool, @@ -2237,7 +2238,7 @@ static pj_status_t call_modify_video(pjsua_call *call, call->opt.vid_cnt++; } - status = pjsua_call_media_init(call_med, PJMEDIA_TYPE_VIDEO, + status = pjsua_call_media_init(call_med, PJMEDIA_TYPE_VIDEO, NULL, &acc_cfg->rtp_cfg, call->secure_level, NULL, PJ_FALSE, NULL); if (status != PJ_SUCCESS) diff --git a/pjsip/src/test/test.c b/pjsip/src/test/test.c index 7e9741327f..1730fb3366 100644 --- a/pjsip/src/test/test.c +++ b/pjsip/src/test/test.c @@ -503,7 +503,8 @@ int test_main(char *testlist) /* Dumping memory pool usage */ PJ_LOG(3,(THIS_FILE, "Peak memory size=%lu MB", - caching_pool.peak_used_size / 1000000)); + (unsigned long) + (caching_pool.peak_used_size / 1000000))); pjsip_endpt_destroy(endpt); pj_caching_pool_destroy(&caching_pool); diff --git a/pjsip/src/test/tsx_bench.c b/pjsip/src/test/tsx_bench.c index dd8c1971a8..30b2aa2209 100644 --- a/pjsip/src/test/tsx_bench.c +++ b/pjsip/src/test/tsx_bench.c @@ -138,7 +138,7 @@ static int uas_tsx_bench(unsigned working_set, pj_timestamp *p_elapsed) rdata.msg_info.from = (pjsip_from_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_FROM, NULL); rdata.msg_info.to = (pjsip_to_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_TO, NULL); rdata.msg_info.cseq = (pjsip_cseq_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_CSEQ, NULL); - rdata.msg_info.cid = (pjsip_cid_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_FROM, NULL); + rdata.msg_info.cid = (pjsip_cid_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_CALL_ID, NULL); rdata.msg_info.via = via; pj_sockaddr_in_init(&remote, 0, 0); diff --git a/pjsip/src/test/tsx_uas_test.c b/pjsip/src/test/tsx_uas_test.c index f2460fcfb6..815cbe069e 100644 --- a/pjsip/src/test/tsx_uas_test.c +++ b/pjsip/src/test/tsx_uas_test.c @@ -710,10 +710,11 @@ static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e) if (!test_complete) test_complete = 1; - if (tsx->status_code != PJSIP_SC_TSX_TRANSPORT_ERROR) { + if (tsx->status_code != PJSIP_SC_REQUEST_TIMEOUT) { PJ_LOG(3,(THIS_FILE," error: incorrect status code" " (expecting %d, got %d)", - PJSIP_SC_TSX_TRANSPORT_ERROR, + PJSIP_SC_REQUEST_TIMEOUT, + // PJSIP_SC_TSX_TRANSPORT_ERROR, tsx->status_code)); test_complete = -170; } @@ -726,12 +727,13 @@ static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e) if (!test_complete) test_complete = 1; - if (tsx->status_code != PJSIP_SC_TSX_TRANSPORT_ERROR && + if (tsx->status_code != PJSIP_SC_REQUEST_TIMEOUT && tsx->status_code != PJSIP_SC_OK) { PJ_LOG(3,(THIS_FILE," error: incorrect status code" " (expecting %d, got %d)", - PJSIP_SC_TSX_TRANSPORT_ERROR, + PJSIP_SC_REQUEST_TIMEOUT, + // PJSIP_SC_TSX_TRANSPORT_ERROR, tsx->status_code)); test_complete = -170; } @@ -1199,9 +1201,11 @@ static int perform_test( char *target_uri, char *from_uri, int sent_cnt; pj_status_t status; - PJ_LOG(3,(THIS_FILE, - " please standby, this will take at most %d seconds..", - test_time)); + if (test_time > 0) { + PJ_LOG(3,(THIS_FILE, + " please standby, this will take at most %d seconds..", + test_time)); + } /* Reset test. */ recv_count = 0; @@ -1481,24 +1485,29 @@ int tsx_transport_failure_test(void) { struct test_desc { + int result; int transport_delay; int fail_delay; char *branch_id; char *title; } tests[] = { - { 0, 10, TEST10_BRANCH_ID, "test10: failed transport in TRYING state (no delay)" }, - { 50, 10, TEST10_BRANCH_ID, "test10: failed transport in TRYING state (50 ms delay)" }, - { 0, 1500, TEST11_BRANCH_ID, "test11: failed transport in PROCEEDING state (no delay)" }, - // After ticket #2076, transport error will be ignored if tsx is in COMPLETED state, note that - // tsx state will be shifted to COMPLETED state once 200 response is sent due to transport delay. - //{ 50, 1500, TEST11_BRANCH_ID, "test11: failed transport in PROCEEDING state (50 ms delay)" }, - { 0, 2500, TEST12_BRANCH_ID, "test12: failed transport in COMPLETED state (no delay)" }, - //Not applicable (maybe) - //This test may expect transport failure notification in COMPLETED state. This may not be - //possible because the loop transport can only notify failure when it has something to send, - //while in this case, there is nothing to send because UAS already sends 200/OK - //{ 50, 2500, TEST12_BRANCH_ID, "test12: failed transport in COMPLETED state (50 ms delay)" }, + // After #3805 and #3806, transport error will be ignored and + // the tests will time out. + // All tests are valid, but it will take too long to complete, + // so we disable some of the similar ones. + { 0, 0, 10, TEST10_BRANCH_ID, + "test10: failed transport in TRYING state (no delay)" }, + //{ 0, 50, 10, TEST10_BRANCH_ID, + // "test10: failed transport in TRYING state (50 ms delay)" }, + //{ 1, 0, 1500, TEST11_BRANCH_ID, + // "test11: failed transport in PROCEEDING state (no delay)" }, + { 1, 50, 1500, TEST11_BRANCH_ID, + "test11: failed transport in PROCEEDING state (50 ms delay)" }, + { 1, 0, 2500, TEST12_BRANCH_ID, + "test12: failed transport in COMPLETED state (no delay)" }, + //{ 1, 50, 2500, TEST12_BRANCH_ID, + // "test12: failed transport in COMPLETED state (50 ms delay)" }, }; int i, status; @@ -1532,7 +1541,7 @@ int tsx_transport_failure_test(void) PJ_LOG(5,(THIS_FILE, " transport loop fail mode set")); end_test = now; - end_test.sec += 5; + end_test.sec += 33; do { pj_time_val interval = { 0, 1 }; @@ -1540,13 +1549,10 @@ int tsx_transport_failure_test(void) pjsip_endpt_handle_events(endpt, &interval); } while (!test_complete && PJ_TIME_VAL_LT(now, end_test)); - if (test_complete == 0) { - PJ_LOG(3,(THIS_FILE, " error: test has timed out")); + if (test_complete != tests[i].result) { + PJ_LOG(3,(THIS_FILE, " error: expecting timeout")); return -41; } - - if (test_complete != 1) - return test_complete; } return 0;