Merge master

This commit is contained in:
sauwming 2023-03-14 10:24:59 +08:00
commit 4680c7add7
137 changed files with 2009 additions and 415 deletions

View File

@ -58,7 +58,7 @@ PJ_DECL(void) pj_sha1_init(pj_sha1_context *ctx);
*/
PJ_DECL(void) pj_sha1_update(pj_sha1_context *ctx,
const pj_uint8_t *data,
const pj_size_t nbytes);
pj_size_t nbytes);
/** Finish the message and return the digest.
* @param ctx SHA1 context.

View File

@ -960,10 +960,10 @@ PJ_DEF(pj_status_t) pj_cli_sess_parse(pj_cli_sess *sess,
return status;
}
PJ_DECL(pj_status_t) pj_cli_sess_exec(pj_cli_sess *sess,
char *cmdline,
pj_pool_t *pool,
pj_cli_exec_info *info)
PJ_DEF(pj_status_t) pj_cli_sess_exec(pj_cli_sess *sess,
char *cmdline,
pj_pool_t *pool,
pj_cli_exec_info *info)
{
pj_cli_cmd_val val;
pj_status_t status;

View File

@ -935,7 +935,7 @@ static pj_bool_t handle_backspace(cli_telnet_sess *sess, unsigned char *data)
echo[0] = *data;
telnet_sess_send2(sess, echo, 5);
} else {
const static unsigned char echo[3] = {0x08, 0x20, 0x08};
unsigned char echo[3] = {0x08, 0x20, 0x08};
telnet_sess_send2(sess, echo, 3);
}
return PJ_TRUE;

View File

@ -127,6 +127,9 @@ static pj_status_t get_name_len(int rec_counter, const pj_uint8_t *pkt,
return PJLIB_UTIL_EDNSINNAMEPTR;
}
if (start >= max)
return PJLIB_UTIL_EDNSINNAMEPTR;
*name_len = *parsed_len = 0;
p = start;
while (*p) {
@ -199,6 +202,9 @@ static pj_status_t get_name(int rec_counter, const pj_uint8_t *pkt,
return PJLIB_UTIL_EDNSINNAMEPTR;
}
if (start >= max)
return PJLIB_UTIL_EDNSINNAMEPTR;
p = start;
while (*p) {
if ((*p & 0xc0) == 0xc0) {
@ -359,10 +365,14 @@ static pj_status_t parse_rr(pj_dns_parsed_rr *rr, pj_pool_t *pool,
/* Parse some well known records */
if (rr->type == PJ_DNS_TYPE_A) {
if (p + 4 > max)
return PJLIB_UTIL_EDNSINSIZE;
pj_memcpy(&rr->rdata.a.ip_addr, p, 4);
p += 4;
} else if (rr->type == PJ_DNS_TYPE_AAAA) {
if (p + 16 > max)
return PJLIB_UTIL_EDNSINSIZE;
pj_memcpy(&rr->rdata.aaaa.ip_addr, p, 16);
p += 16;
@ -388,6 +398,8 @@ static pj_status_t parse_rr(pj_dns_parsed_rr *rr, pj_pool_t *pool,
p += name_part_len;
} else if (rr->type == PJ_DNS_TYPE_SRV) {
if (p + 6 > max)
return PJLIB_UTIL_EDNSINSIZE;
/* Priority */
pj_memcpy(&rr->rdata.srv.prio, p, 2);

View File

@ -1507,7 +1507,11 @@ static void str_snprintf(pj_str_t *s, size_t size,
size -= s->slen;
retval = pj_ansi_vsnprintf(s->ptr + s->slen,
size, format, arg);
s->slen += ((retval < (int)size) ? retval : size - 1);
if (retval < 0) {
pj_assert(retval >= 0);
retval = 0;
}
s->slen += (((size_t)retval < size) ? (size_t)retval : size - 1);
va_end(arg);
}

View File

@ -504,7 +504,7 @@ static pj_status_t write_children(const pj_json_list *list,
child = child->next;
}
} else {
if (st->indent < sizeof(st->indent_buf)) {
if (st->indent < (int)sizeof(st->indent_buf)) {
st->indent += PJ_JSON_INDENT_SIZE;
indent_added = PJ_TRUE;
}
@ -577,7 +577,7 @@ static pj_status_t elem_write(const pj_json_elem *elem,
len = pj_ansi_snprintf(num_buf, sizeof(num_buf), "%f",
elem->value.num);
if (len < 0 || len >= sizeof(num_buf))
if (len < 0 || len >= (int)sizeof(num_buf))
return PJ_ETOOBIG;
CHECK( st->writer( num_buf, len, st->user_data) );
}

View File

@ -203,7 +203,7 @@ PJ_DEF(void) pj_sha1_init(pj_sha1_context* context)
/* Run your data through this. */
PJ_DEF(void) pj_sha1_update(pj_sha1_context* context,
const pj_uint8_t* data, const pj_size_t len)
const pj_uint8_t* data, pj_size_t len)
{
pj_size_t i, j;

View File

@ -544,6 +544,20 @@
#endif
/**
* If enabled, when allocating memory, pool will only search for a maximum
* number of blocks specified before deciding that the pool is full and
* a new memory block needs to be created.
*
* Set it to 0 to disable the limitation (i.e. it will search all blocks).
*
* Default: 5
*/
#ifndef PJ_POOL_MAX_SEARCH_BLOCK_COUNT
# define PJ_POOL_MAX_SEARCH_BLOCK_COUNT 5
#endif
/**
* Enable timer debugging facility. When this is enabled, application
* can call pj_timer_heap_dump() to show the contents of the timer

View File

@ -78,7 +78,7 @@ PJ_BEGIN_DECL
* @param len The length of the string buffer.
*/
#define PJ_CHECK_TRUNC_STR(ret, str, len) \
if ((ret) >= (len) || (ret) < 0) pj_ansi_strcpy((str) + (len) - 3, "..")
if ((int)(ret) >= (int)(len) || (ret) < 0) pj_ansi_strcpy((str) + (len) - 3, "..")
/**
* Create string initializer from a normal C string.

View File

@ -50,7 +50,7 @@ PJ_IDEF(pj_str_t*) pj_strdup_with_null( pj_pool_t *pool,
pj_str_t *dst,
const pj_str_t *src)
{
pj_size_t src_slen = src->slen;
pj_ssize_t src_slen = src->slen;
pj_assert(src->slen >= 0);

View File

@ -193,5 +193,6 @@ PJ_DEF(pj_status_t) pj_ioqueue_connect( pj_ioqueue_t *ioqueue,
PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue )
{
PJ_UNUSED_ARG(ioqueue);
return NULL;
}

View File

@ -282,7 +282,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_create2(pj_pool_t *pool,
const unsigned type_mask = PJ_IOQUEUE_EPOLL_EXCLUSIVE |
PJ_IOQUEUE_EPOLL_ONESHOT;
unsigned epoll_support, valid_types;
int i;
pj_size_t i;
/* Check that arguments are valid. */
PJ_ASSERT_RETURN(pool != NULL && p_ioqueue != NULL &&

View File

@ -119,7 +119,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_create2(pj_pool_t *pool,
pj_ioqueue_t *ioqueue;
pj_status_t rc;
pj_lock_t *lock;
int i;
pj_size_t i;
/* Check that arguments are valid. */
PJ_ASSERT_RETURN(pool != NULL && p_ioqueue != NULL && max_fd > 0,

View File

@ -205,7 +205,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_create2(pj_pool_t *pool,
{
pj_ioqueue_t *ioqueue;
pj_lock_t *lock;
unsigned i;
pj_size_t i;
pj_status_t rc;
/* Check that arguments are valid. */
@ -1140,5 +1140,6 @@ PJ_DEF(int) pj_ioqueue_poll( pj_ioqueue_t *ioqueue, const pj_time_val *timeout)
PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue )
{
PJ_UNUSED_ARG(ioqueue);
return NULL;
}

View File

@ -866,5 +866,6 @@ PJ_DEF(pj_status_t) pj_ioqueue_unlock_key(pj_ioqueue_key_t *key)
PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue )
{
PJ_UNUSED_ARG(ioqueue);
return NULL;
}

View File

@ -364,5 +364,6 @@ PJ_DEF(int) pj_ioqueue_poll( pj_ioqueue_t *ioq,
PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue )
{
PJ_UNUSED_ARG(ioqueue);
return NULL;
}

View File

@ -115,6 +115,7 @@ struct pj_ioqueue_key_t
enum handle_type hnd_type;
pj_ioqueue_callback cb;
pj_bool_t allow_concurrent;
pj_grp_lock_t *grp_lock;
#if PJ_HAS_TCP
int connecting;
@ -320,6 +321,27 @@ PJ_DEF(const char*) pj_ioqueue_name(void)
return "iocp";
}
PJ_DEF(void) pj_ioqueue_cfg_default(pj_ioqueue_cfg *cfg)
{
pj_bzero(cfg, sizeof(*cfg));
cfg->epoll_flags = PJ_IOQUEUE_DEFAULT_EPOLL_FLAGS;
cfg->default_concurrency = PJ_IOQUEUE_DEFAULT_ALLOW_CONCURRENCY;
}
PJ_DEF(pj_status_t) pj_ioqueue_clear_key( pj_ioqueue_key_t *key )
{
PJ_ASSERT_RETURN(key, PJ_EINVAL);
pj_ioqueue_lock_key(key);
key->connecting = 0;
pj_ioqueue_unlock_key(key);
return PJ_SUCCESS;
}
/*
* pj_ioqueue_create()
*/
@ -339,7 +361,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_create2(pj_pool_t *pool,
pj_ioqueue_t **p_ioqueue)
{
pj_ioqueue_t *ioqueue;
unsigned i;
pj_size_t i;
pj_status_t rc;
PJ_UNUSED_ARG(max_fd);
@ -507,12 +529,14 @@ PJ_DEF(pj_status_t) pj_ioqueue_set_lock( pj_ioqueue_t *ioqueue,
return PJ_SUCCESS;
}
/*
* pj_ioqueue_register_sock()
* pj_ioqueue_register_sock2()
*/
PJ_DEF(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool,
PJ_DEF(pj_status_t) pj_ioqueue_register_sock2(pj_pool_t *pool,
pj_ioqueue_t *ioqueue,
pj_sock_t sock,
pj_grp_lock_t *grp_lock,
void *user_data,
const pj_ioqueue_callback *cb,
pj_ioqueue_key_t **key )
@ -535,6 +559,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool,
/* If safe unregistration is used, then get the key record from
* the free list.
*/
pj_assert(!pj_list_empty(&ioqueue->free_list));
if (pj_list_empty(&ioqueue->free_list)) {
pj_lock_release(ioqueue->lock);
return PJ_ETOOMANY;
@ -550,7 +575,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool,
rec->closing = 0;
#else
rec = pj_pool_zalloc(pool, sizeof(pj_ioqueue_key_t));
rec = (pj_ioqueue_key_t *)pj_pool_zalloc(pool, sizeof(pj_ioqueue_key_t));
#endif
/* Build the key for this socket. */
@ -586,6 +611,16 @@ PJ_DEF(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool,
return PJ_RETURN_OS_ERROR(GetLastError());
}
/* Group lock */
rec->grp_lock = grp_lock;
if (rec->grp_lock) {
/* IOCP backend doesn't have group lock functionality, so
* you should not use it other than for experimental purposes.
*/
PJ_TODO(INTEGRATE_GROUP_LOCK);
// pj_grp_lock_add_ref_dbg(rec->grp_lock, "ioqueue", 0);
}
*key = rec;
#if PJ_IOQUEUE_HAS_SAFE_UNREG
@ -598,6 +633,21 @@ PJ_DEF(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool,
}
/*
* pj_ioqueue_register_sock()
*/
PJ_DEF(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool,
pj_ioqueue_t *ioqueue,
pj_sock_t sock,
void *user_data,
const pj_ioqueue_callback *cb,
pj_ioqueue_key_t **key )
{
return pj_ioqueue_register_sock2(pool, ioqueue, sock, NULL, user_data, cb,
key);
}
/*
* pj_ioqueue_get_user_data()
*/
@ -1238,19 +1288,19 @@ PJ_DEF(pj_status_t) pj_ioqueue_accept( pj_ioqueue_key_t *key,
if (sock != INVALID_SOCKET) {
/* Yes! New socket is available! */
if (local && addrlen) {
int status;
int status_;
/* On WinXP or later, use SO_UPDATE_ACCEPT_CONTEXT so that socket
* addresses can be obtained with getsockname() and getpeername().
*/
status = setsockopt(sock, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT,
(char*)&key->hnd, sizeof(SOCKET));
status_ = setsockopt(sock, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT,
(char*)&key->hnd, sizeof(SOCKET));
/* SO_UPDATE_ACCEPT_CONTEXT is for WinXP or later.
* So ignore the error status.
*/
status = getsockname(sock, local, addrlen);
if (status != 0) {
status_ = getsockname(sock, local, addrlen);
if (status_ != 0) {
DWORD dwError = WSAGetLastError();
closesocket(sock);
return PJ_RETURN_OS_ERROR(dwError);
@ -1459,5 +1509,5 @@ PJ_DEF(pj_status_t) pj_ioqueue_unlock_key(pj_ioqueue_key_t *key)
PJ_DEF(pj_oshandle_t) pj_ioqueue_get_os_handle( pj_ioqueue_t *ioqueue )
{
return ioqueue ? (pj_oshandle_t)ioqueue->hnd : NULL;
return ioqueue ? (pj_oshandle_t)ioqueue->iocp : NULL;
}

View File

@ -515,7 +515,7 @@ static pj_status_t get_ipv6_deprecated(unsigned *count, pj_sockaddr addr[])
struct nlmsghdr *nlmsg_ptr = (struct nlmsghdr *) read_buffer;
int nlmsg_len = read_size;
if (nlmsg_len < sizeof (struct nlmsghdr)) {
if (nlmsg_len < (int)sizeof (struct nlmsghdr)) {
close(fd);
return PJ_ETOOSMALL;
}
@ -593,7 +593,7 @@ PJ_DEF(pj_status_t) pj_enum_ip_interface2( const pj_enum_ip_option *opt,
pj_sockaddr deprecatedAddrs[*p_cnt];
unsigned deprecatedCount = *p_cnt;
unsigned cnt = 0;
int i;
unsigned i;
pj_status_t status;
status = get_ipv6_deprecated(&deprecatedCount, deprecatedAddrs);
@ -605,8 +605,8 @@ PJ_DEF(pj_status_t) pj_enum_ip_interface2( const pj_enum_ip_option *opt,
return status;
for (i = 0; i < *p_cnt; ++i) {
int j;
unsigned j;
ifs[cnt++] = addrs[i];
if (addrs[i].addr.sa_family != pj_AF_INET6())

View File

@ -469,8 +469,8 @@ PJ_DEF(pj_status_t) pj_grp_lock_create_w_handler( pj_pool_t *pool,
status = pj_grp_lock_create(pool, cfg, p_grp_lock);
if (status == PJ_SUCCESS) {
pj_pool_t *pool = (*p_grp_lock)->pool;
grp_lock_add_handler(*p_grp_lock, pool, member, handler, PJ_FALSE);
pj_pool_t *grppool = (*p_grp_lock)->pool;
grp_lock_add_handler(*p_grp_lock, grppool, member, handler, PJ_FALSE);
}
return status;

View File

@ -23,6 +23,7 @@
PJ_DEF(int) pj_run_app(pj_main_func_ptr main_func, int argc, char *argv[],
unsigned flags)
{
PJ_UNUSED_ARG(flags);
return (*main_func)(argc, argv);
}
@ -79,7 +80,8 @@ PJ_DEF(int) pj_run_app(pj_main_func_ptr main_func, int argc, char *argv[],
pthread_t thread;
run_app_t param;
NSAutoreleasePool *pool;
PJ_UNUSED_ARG(flags);
pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
[DeadThread enterMultiThreadedMode];

View File

@ -138,8 +138,8 @@ struct pj_event_t
pthread_cond_t cond;
pj_bool_t auto_reset;
unsigned threads_waiting;
unsigned threads_to_release;
int threads_waiting;
int threads_to_release;
};
#endif /* PJ_HAS_EVENT_OBJ */
@ -1712,6 +1712,7 @@ PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool,
{
#if PJ_HAS_THREADS
pj_sem_t *sem;
PJ_UNUSED_ARG(max);
PJ_CHECK_STACK();
PJ_ASSERT_RETURN(pool != NULL && ptr_sem != NULL, PJ_EINVAL);
@ -1777,6 +1778,10 @@ PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool,
*ptr_sem = sem;
return PJ_SUCCESS;
#else
PJ_UNUSED_ARG(pool);
PJ_UNUSED_ARG(name);
PJ_UNUSED_ARG(initial);
PJ_UNUSED_ARG(max);
*ptr_sem = (pj_sem_t*)1;
return PJ_SUCCESS;
#endif
@ -2139,6 +2144,7 @@ PJ_DEF(pj_color_t) pj_term_get_color(void)
PJ_DEF(int) pj_run_app(pj_main_func_ptr main_func, int argc, char *argv[],
unsigned flags)
{
PJ_UNUSED_ARG(flags);
return (*main_func)(argc, argv);
}
#endif

View File

@ -71,9 +71,6 @@ PJ_DEF(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv)
return PJ_SUCCESS;
}
#endif /* !PJ_WIN32 */
static int get_tz_offset_secs()
{
time_t epoch_plus_11h = 60 * 60 * 11;
@ -110,4 +107,4 @@ PJ_DEF(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv)
return PJ_SUCCESS;
}
#endif /* !PJ_WIN32 */

View File

@ -84,14 +84,17 @@ static pj_pool_block *pj_pool_create_block( pj_pool_t *pool, pj_size_t size)
/*
* Allocate memory chunk for user from available blocks.
* This will iterate through block list to find space to allocate the chunk.
* If no space is available in all the blocks, a new block might be created
* (depending on whether the pool is allowed to resize).
* If no space is available in all the blocks (or
* PJ_POOL_MAX_SEARCH_BLOCK_COUNT blocks if the config is > 0),
* a new block might be created (depending on whether the pool is allowed
* to resize).
*/
PJ_DEF(void*) pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size)
{
pj_pool_block *block = pool->block_list.next;
void *p;
pj_size_t block_size;
unsigned i = 0;
PJ_CHECK_STACK();
@ -99,6 +102,14 @@ PJ_DEF(void*) pj_pool_allocate_find(pj_pool_t *pool, pj_size_t size)
p = pj_pool_alloc_from_block(block, size);
if (p != NULL)
return p;
#if PJ_POOL_MAX_SEARCH_BLOCK_COUNT > 0
if (i >= PJ_POOL_MAX_SEARCH_BLOCK_COUNT) {
break;
}
#endif
i++;
block = block->next;
}
/* No available space in all blocks. */

View File

@ -282,11 +282,36 @@ static void cpool_dump_status(pj_pool_factory *factory, pj_bool_t detail )
PJ_LOG(3,("cachpool", " Dumping all active pools:"));
while (pool != (void*)&cp->used_list) {
pj_size_t pool_capacity = pj_pool_get_capacity(pool);
PJ_LOG(3,("cachpool", " %16s: %8d of %8d (%d%%) used",
pj_pool_block *block = pool->block_list.next;
unsigned nblocks = 0;
while (block != &pool->block_list) {
#if 0
PJ_LOG(6, ("cachpool", " %16s block %u, size %ld",
pj_pool_getobjname(pool), nblocks,
block->end - block->buf + 1));
#endif
nblocks++;
block = block->next;
}
PJ_LOG(3,("cachpool", " %16s: %8d of %8d (%d%%) used, "
"nblocks: %d",
pj_pool_getobjname(pool),
pj_pool_get_used_size(pool),
pool_capacity,
pj_pool_get_used_size(pool)*100/pool_capacity));
pj_pool_get_used_size(pool)*100/pool_capacity,
nblocks));
#if PJ_POOL_MAX_SEARCH_BLOCK_COUNT == 0
if (nblocks >= 10) {
PJ_LOG(3,("cachpool", " %16s has too many blocks (%d), "
"consider increasing its initial and/or "
"increment size for better performance",
pj_pool_getobjname(pool), nblocks));
}
#endif
total_used += pj_pool_get_used_size(pool);
total_capacity += pool_capacity;
pool = pool->next;

View File

@ -543,8 +543,8 @@ static pj_status_t create_identity_from_cert(applessl_sock_t *assock,
pj_bzero(&key_params, sizeof(key_params));
key_params.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;
key_params.passphrase = password;
for (i = 0; i < PJ_ARRAY_SIZE(ext_format); i++) {
for (i = 0; i < (CFIndex)PJ_ARRAY_SIZE(ext_format); i++) {
items = NULL;
err = SecItemImport(cert_data, NULL, &ext_format[i],
&ext_type, 0, &key_params, NULL, &items);
@ -735,6 +735,7 @@ static pj_status_t network_send(pj_ssl_sock_t *ssock,
pj_ssize_t *size,
unsigned flags)
{
PJ_UNUSED_ARG(flags);
applessl_sock_t *assock = (applessl_sock_t *)ssock;
dispatch_data_t content;
@ -832,6 +833,8 @@ static pj_status_t network_start_read(pj_ssl_sock_t *ssock,
^(dispatch_data_t region, size_t offset,
const void *buffer, size_t inSize)
{
PJ_UNUSED_ARG(region);
PJ_UNUSED_ARG(offset);
/* This block can be invoked multiple times,
* each for every contiguous memory region in the content.
*/
@ -1013,6 +1016,7 @@ static pj_status_t network_create_params(pj_ssl_sock_t * ssock,
^(sec_protocol_metadata_t metadata,
sec_protocol_challenge_complete_t complete)
{
PJ_UNUSED_ARG(metadata);
complete(assock->identity);
}, assock->queue);
@ -1388,7 +1392,7 @@ static pj_status_t network_start_connect(pj_ssl_sock_t *ssock,
static pj_ssl_sock_t *ssl_alloc(pj_pool_t *pool)
{
applessl_sock_t *assock;
/* Create event manager */
if (event_manager_create() != PJ_SUCCESS)
return NULL;
@ -1401,7 +1405,7 @@ static pj_ssl_sock_t *ssl_alloc(pj_pool_t *pool)
ssl_destroy(&assock->base);
return NULL;
}
return (pj_ssl_sock_t *)assock;
}
@ -1410,6 +1414,7 @@ static pj_status_t ssl_create(pj_ssl_sock_t *ssock)
/* Nothing to do here. SSL has been configured before connection
* is started.
*/
PJ_UNUSED_ARG(ssock);
return PJ_SUCCESS;
}
@ -1791,7 +1796,7 @@ static void get_info_and_cn(CFArrayRef array, CFMutableStringRef info,
int i, n;
*cn = NULL;
for(i = 0; i < sizeof(keys)/sizeof(keys[0]); i++) {
for(i = 0; i < (int)PJ_ARRAY_SIZE(keys); i++) {
for (n = 0 ; n < CFArrayGetCount(array); n++) {
CFDictionaryRef dict;
CFTypeRef dictkey;
@ -2152,7 +2157,7 @@ static pj_status_t ssl_do_handshake(pj_ssl_sock_t *ssock)
/* Nothing to do here, just return EPENDING. Handshake has
* automatically been performed when starting a connection.
*/
PJ_UNUSED_ARG(ssock);
return PJ_EPENDING;
}
@ -2169,7 +2174,7 @@ static pj_status_t ssl_read(pj_ssl_sock_t *ssock, void *data, int *size)
}
circ_buf_size = circ_size(&ssock->circ_buf_input);
read_size = PJ_MIN(circ_buf_size, *size);
read_size = PJ_MIN(circ_buf_size, (pj_size_t)*size);
circ_read(&ssock->circ_buf_input, data, read_size);

View File

@ -289,8 +289,8 @@ static pj_status_t set_cert(darwinssl_sock_t *dssock, pj_ssl_cert_t *cert)
pj_bzero(&key_params, sizeof(key_params));
key_params.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;
key_params.passphrase = password;
for (i = 0; i < PJ_ARRAY_SIZE(ext_format); i++) {
for (i = 0; i < (CFIndex)PJ_ARRAY_SIZE(ext_format); i++) {
items = NULL;
err = SecItemImport(cert_data, NULL, &ext_format[i],
&ext_type, 0, &key_params, NULL, &items);
@ -472,12 +472,12 @@ static pj_status_t ssl_create(pj_ssl_sock_t *ssock)
if (ssock->param.ciphers_num > 0) {
int i, n = ssock->param.ciphers_num;
SSLCipherSuite ciphers[MAX_CIPHERS];
if (n > PJ_ARRAY_SIZE(ciphers))
n = PJ_ARRAY_SIZE(ciphers);
if (n > (int)PJ_ARRAY_SIZE(ciphers))
n = (int)PJ_ARRAY_SIZE(ciphers);
for (i = 0; i < n; i++)
ciphers[i] = (SSLCipherSuite)ssock->param.ciphers[i];
err = SSLSetEnabledCiphers(ssl_ctx, ciphers, n);
if (err != noErr)
return pj_status_from_err(dssock, "SetEnabledCiphers", err);
@ -835,7 +835,7 @@ static void get_info_and_cn(CFArrayRef array, CFMutableStringRef info,
int i, n;
*cn = NULL;
for(i = 0; i < sizeof(keys)/sizeof(keys[0]); i++) {
for(i = 0; i < (int)PJ_ARRAY_SIZE(keys); i++) {
for (n = 0 ; n < CFArrayGetCount(array); n++) {
CFDictionaryRef dict;
CFTypeRef dictkey;
@ -1281,6 +1281,7 @@ static pj_status_t verify_cert(darwinssl_sock_t * dssock, pj_ssl_cert_t *cert)
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^(SecTrustRef trust, SecTrustResultType trust_result)
{
PJ_UNUSED_ARG(trust);
/* Unfortunately SecTrustEvaluate() cannot seem to get us
* more specific verification result like the original
* error status returned directly by SSLHandshake()
@ -1413,10 +1414,10 @@ static pj_status_t ssl_write(pj_ssl_sock_t *ssock, const void *data,
*nwritten = (int)processed;
if (err != noErr) {
return pj_status_from_err(dssock, "SSLWrite", err);
} else if (processed < size) {
} else if ((pj_ssize_t)processed < size) {
return PJ_ENOMEM;
}
return PJ_SUCCESS;
}
@ -1429,7 +1430,7 @@ static pj_status_t ssl_renegotiate(pj_ssl_sock_t *ssock)
if (err != noErr) {
return pj_status_from_err(dssock, "SSLReHandshake", err);
}
return PJ_SUCCESS;
}

View File

@ -174,6 +174,7 @@ static pj_status_t tls_status_from_err(pj_ssl_sock_t *ssock, int err)
static pj_str_t tls_strerror(pj_status_t status,
char *buf, pj_size_t bufsize)
{
PJ_UNUSED_ARG(status);
pj_str_t errstr;
const char *tmp = gnutls_strerror(tls_last_error);
@ -444,7 +445,7 @@ static pj_status_t tls_priorities_set(pj_ssl_sock_t *ssock)
pj_strcat2(&priority, "%LATEST_RECORD_VERSION");
pj_strcat(&cipher_list, &priority);
for (i = 0; i < ssock->param.ciphers_num; i++) {
for (i = 0; i < (int)ssock->param.ciphers_num; i++) {
for (j = 0; ; j++) {
pj_ssl_cipher c;
const char *suite;
@ -505,7 +506,7 @@ static pj_status_t tls_priorities_set(pj_ssl_sock_t *ssock)
/* Server will be the one deciding which crypto to use */
if (ssock->is_server) {
if (cipher_list.slen + server.slen + 1 > sizeof(buf))
if (cipher_list.slen + server.slen + 1 > (pj_ssize_t)sizeof(buf))
return PJ_ETOOMANY;
else
pj_strcat(&cipher_list, &server);

View File

@ -849,8 +849,8 @@ static pj_bool_t ssock_on_data_sent (pj_ssl_sock_t *ssock,
pj_ioqueue_op_key_t *app_key = wdata->app_key;
pj_ssize_t sent_len;
sent_len = (sent > 0)? wdata->plain_data_len : sent;
sent_len = (sent > 0)? (pj_ssize_t)wdata->plain_data_len : sent;
/* Update write buffer state */
pj_lock_acquire(ssock->write_mutex);
free_send_data(ssock, wdata);

View File

@ -212,21 +212,29 @@ static pj_status_t circ_write(circ_buf_t *cb,
inline static pj_bool_t io_empty(pj_ssl_sock_t *ssock, circ_buf_t *cb)
{
PJ_UNUSED_ARG(ssock);
return circ_empty(cb);
}
inline static pj_size_t io_size(pj_ssl_sock_t *ssock, circ_buf_t *cb)
{
PJ_UNUSED_ARG(ssock);
return circ_size(cb);
}
inline static void io_reset(pj_ssl_sock_t *ssock, circ_buf_t *cb) {}
inline static void io_reset(pj_ssl_sock_t *ssock, circ_buf_t *cb)
{
PJ_UNUSED_ARG(ssock);
PJ_UNUSED_ARG(cb);
}
inline static void io_read(pj_ssl_sock_t *ssock, circ_buf_t *cb,
pj_uint8_t *dst, pj_size_t len)
{
PJ_UNUSED_ARG(ssock);
return circ_read(cb, dst, len);
}
inline static pj_status_t io_write(pj_ssl_sock_t *ssock, circ_buf_t *cb,
const pj_uint8_t *src, pj_size_t len)
{
PJ_UNUSED_ARG(ssock);
return circ_write(cb, src, len);
}

View File

@ -1454,7 +1454,7 @@ static pj_status_t init_ossl_ctx(pj_ssl_sock_t *ssock)
int i;
/* Check and load ECC & DSA certificates & private keys */
for (i = 0; i < PJ_ARRAY_SIZE(cert_types); ++i) {
for (i = 0; i < (int)PJ_ARRAY_SIZE(cert_types); ++i) {
int err;
pj_memcpy(p, cert_types[i], CERT_TYPE_LEN);

View File

@ -34,7 +34,7 @@ PJ_DEF(pj_ssize_t) pj_strspn(const pj_str_t *str, const pj_str_t *set_char)
{
pj_ssize_t i, j, count = 0;
for (i = 0; i < str->slen; i++) {
if (count != i)
if (count != i)
break;
for (j = 0; j < set_char->slen; j++) {
@ -90,7 +90,7 @@ PJ_DEF(pj_ssize_t) pj_strcspn2(const pj_str_t *str, const char *set_char)
PJ_DEF(pj_ssize_t) pj_strtok(const pj_str_t *str, const pj_str_t *delim,
pj_str_t *tok, pj_size_t start_idx)
{
{
pj_ssize_t str_idx;
pj_assert(str->slen >= 0);
@ -100,14 +100,14 @@ PJ_DEF(pj_ssize_t) pj_strtok(const pj_str_t *str, const pj_str_t *delim,
if ((str->slen <= 0) || ((pj_size_t)str->slen < start_idx)) {
return str->slen;
}
tok->ptr = str->ptr + start_idx;
tok->slen = str->slen - start_idx;
str_idx = pj_strspn(tok, delim);
if (start_idx+str_idx == (pj_size_t)str->slen) {
return str->slen;
}
}
tok->ptr += str_idx;
tok->slen -= str_idx;
@ -117,7 +117,7 @@ PJ_DEF(pj_ssize_t) pj_strtok(const pj_str_t *str, const pj_str_t *delim,
PJ_DEF(pj_ssize_t) pj_strtok2(const pj_str_t *str, const char *delim,
pj_str_t *tok, pj_size_t start_idx)
pj_str_t *tok, pj_size_t start_idx)
{
pj_ssize_t str_idx;
@ -197,9 +197,9 @@ PJ_DEF(pj_str_t*) pj_strltrim( pj_str_t *str )
{
char *end = str->ptr + str->slen;
register char *p = str->ptr;
pj_assert(str->slen >= 0);
while (p < end && pj_isspace(*p))
++p;
str->slen -= (p - str->ptr);
@ -243,18 +243,28 @@ PJ_DEF(char*) pj_create_random_string(char *str, pj_size_t len)
PJ_DEF(long) pj_strtol(const pj_str_t *str)
{
pj_bool_t is_negative = PJ_FALSE;
unsigned long uval;
long val;
PJ_CHECK_STACK();
if (str->slen > 0 && (str->ptr[0] == '+' || str->ptr[0] == '-')) {
pj_str_t s;
s.ptr = str->ptr + 1;
s.slen = str->slen - 1;
return (str->ptr[0] == '-'? -(long)pj_strtoul(&s) : pj_strtoul(&s));
uval = pj_strtoul(&s);
is_negative = (str->ptr[0] == '-');
} else
return pj_strtoul(str);
}
uval = pj_strtoul(str);
if (is_negative)
val = uval > PJ_MAXLONG ? PJ_MINLONG : -uval;
else
val = uval > PJ_MAXLONG ? PJ_MAXLONG : uval;
return val;
}
PJ_DEF(pj_status_t) pj_strtol2(const pj_str_t *str, long *value)
{
@ -301,7 +311,7 @@ PJ_DEF(pj_status_t) pj_strtol2(const pj_str_t *str, long *value)
return PJ_ETOOSMALL;
}
*value = is_negative ? (long)-retval : retval;
*value = is_negative ? -retval : retval;
return PJ_SUCCESS;
}

View File

@ -76,8 +76,8 @@ typedef struct pj_timer_entry_dup
/**
* The duplicate copy.
*/
pj_timer_entry dup;
pj_timer_entry dup;
/**
* Pointer of the original timer entry.
*/
@ -166,7 +166,7 @@ struct pj_timer_heap_t
* values are treated as "pointers" into the <heap_> array.
*/
pj_timer_id_t *timer_ids;
/**
* An array of timer entry copies.
*/
@ -207,7 +207,7 @@ static void copy_node( pj_timer_heap_t *ht, pj_size_t slot,
// Insert <moved_node> into its new location in the heap.
ht->heap[slot] = moved_node;
// Update the corresponding slot in the parallel <timer_ids_> array.
ht->timer_ids[GET_FIELD(moved_node, _timer_id)] = (int)slot;
}
@ -216,16 +216,16 @@ static pj_timer_id_t pop_freelist( pj_timer_heap_t *ht )
{
// We need to truncate this to <int> for backwards compatibility.
pj_timer_id_t new_id = ht->timer_ids_freelist;
PJ_CHECK_STACK();
// The freelist values in the <timer_ids_> are negative, so we need
// to negate them to get the next freelist "pointer."
ht->timer_ids_freelist =
-ht->timer_ids[ht->timer_ids_freelist];
return new_id;
}
static void push_freelist (pj_timer_heap_t *ht, pj_timer_id_t old_id)
@ -245,7 +245,7 @@ static void reheap_down(pj_timer_heap_t *ht, pj_timer_entry_dup *moved_node,
PJ_CHECK_STACK();
// Restore the heap property after a deletion.
while (child < ht->cur_size)
{
// Choose the smaller of the two children.
@ -255,7 +255,7 @@ static void reheap_down(pj_timer_heap_t *ht, pj_timer_entry_dup *moved_node,
{
child++;
}
// Perform a <copy> if the child has a larger timeout value than
// the <moved_node>.
if (PJ_TIME_VAL_LT(ht->heap[child]->_timer_value,
@ -269,7 +269,7 @@ static void reheap_down(pj_timer_heap_t *ht, pj_timer_entry_dup *moved_node,
// We've found our location in the heap.
break;
}
copy_node( ht, slot, moved_node);
}
@ -277,7 +277,7 @@ static void reheap_up( pj_timer_heap_t *ht, pj_timer_entry_dup *moved_node,
size_t slot, size_t parent)
{
// Restore the heap property after an insertion.
while (slot > 0)
{
// If the parent node is greater than the <moved_node> we need
@ -292,7 +292,7 @@ static void reheap_up( pj_timer_heap_t *ht, pj_timer_entry_dup *moved_node,
else
break;
}
// Insert the new node into its proper resting place in the heap and
// update the corresponding slot in the parallel <timer_ids> array.
copy_node(ht, slot, moved_node);
@ -305,11 +305,11 @@ static pj_timer_entry_dup * remove_node( pj_timer_heap_t *ht, size_t slot)
// Return this timer id to the freelist.
push_freelist( ht, GET_FIELD(removed_node, _timer_id) );
// Decrement the size of the heap by one since we're removing the
// "slot"th node.
ht->cur_size--;
// Set the ID
if (GET_FIELD(removed_node, _timer_id) !=
GET_ENTRY(removed_node)->_timer_id)
@ -336,20 +336,20 @@ static pj_timer_entry_dup * remove_node( pj_timer_heap_t *ht, size_t slot)
#if !PJ_TIMER_USE_LINKED_LIST
// Only try to reheapify if we're not deleting the last entry.
if (slot < ht->cur_size)
{
pj_size_t parent;
pj_timer_entry_dup *moved_node = ht->heap[ht->cur_size];
// Move the end node to the location being removed and update
// the corresponding slot in the parallel <timer_ids> array.
copy_node( ht, slot, moved_node);
// If the <moved_node->time_value_> is great than or equal its
// parent it needs be moved down the heap.
parent = HEAP_PARENT (slot);
if (PJ_TIME_VAL_GTE(moved_node->_timer_value,
ht->heap[parent]->_timer_value))
{
@ -380,19 +380,19 @@ static pj_status_t grow_heap(pj_timer_heap_t *ht)
pj_timer_entry_dup *tmp_dup = NULL;
pj_timer_entry_dup *new_dup;
#endif
PJ_LOG(6,(THIS_FILE, "Growing heap size from %d to %d",
ht->max_size, new_size));
// First grow the heap itself.
new_heap = (pj_timer_entry_dup**)
pj_pool_calloc(ht->pool, new_size, sizeof(pj_timer_entry_dup*));
if (!new_heap)
return PJ_ENOMEM;
#if PJ_TIMER_USE_COPY
// Grow the array of timer copies.
new_timer_dups = (pj_timer_entry_dup*)
pj_pool_alloc(ht->pool,
sizeof(pj_timer_entry_dup) * new_size);
@ -424,9 +424,9 @@ static pj_status_t grow_heap(pj_timer_heap_t *ht)
#endif
ht->heap = new_heap;
// Grow the array of timer ids.
new_timer_ids = 0;
new_timer_ids = (pj_timer_id_t*)
pj_pool_alloc(ht->pool, new_size * sizeof(pj_timer_id_t));
@ -434,16 +434,16 @@ static pj_status_t grow_heap(pj_timer_heap_t *ht)
return PJ_ENOMEM;
memcpy( new_timer_ids, ht->timer_ids, ht->max_size * sizeof(pj_timer_id_t));
//delete [] timer_ids_;
ht->timer_ids = new_timer_ids;
// And add the new elements to the end of the "freelist".
for (i = ht->max_size; i < new_size; i++)
ht->timer_ids[i] = -((pj_timer_id_t) (i + 1));
ht->max_size = new_size;
return PJ_SUCCESS;
}
@ -724,7 +724,7 @@ static pj_status_t schedule_w_grp_lock(pj_timer_heap_t *ht,
pj_gettickcount(&expires);
PJ_TIME_VAL_ADD(expires, *delay);
lock_timer_heap(ht);
/* Prevent same entry from being scheduled more than once */
@ -923,10 +923,14 @@ PJ_DEF(unsigned) pj_timer_heap_poll( pj_timer_heap_t *ht,
slot = ht->timer_ids[GET_FIELD(ht->head_list.next, _timer_id)];
#endif
min_time_node = ht->heap[slot]->_timer_value;
/* Update now */
pj_gettickcount(&now);
}
}
if (ht->cur_size && next_delay) {
*next_delay = ht->heap[0]->_timer_value;
if (count > 0)
pj_gettickcount(&now);
PJ_TIME_VAL_SUB(*next_delay, now);
if (next_delay->sec < 0 || next_delay->msec < 0)
next_delay->sec = next_delay->msec = 0;

View File

@ -602,7 +602,7 @@ int ioqueue_perf_test(void)
int i, rc;
/* Defailed performance report (concurrency=1) */
for (i=0; i<PJ_ARRAY_SIZE(epoll_flags); ++i) {
for (i=0; i<(int)PJ_ARRAY_SIZE(epoll_flags); ++i) {
pj_ioqueue_cfg_default(&cfg);
cfg.epoll_flags = epoll_flags[i];
@ -637,7 +637,7 @@ int ioqueue_perf_test(void)
return rc;
/* The benchmark across configs */
for (i=0; i<PJ_ARRAY_SIZE(epoll_flags); ++i) {
for (i=0; i<(int)PJ_ARRAY_SIZE(epoll_flags); ++i) {
int concur;
for (concur=0; concur<2; ++concur) {
pj_ioqueue_cfg_default(&cfg);

View File

@ -827,7 +827,6 @@ static test_desc tests[128] = {
.cfg.title = "basic tcp (single thread, EPOLLEXCLUSIVE)",
.cfg.max_fd = 6,
.cfg.allow_concur = 1,
.cfg.epoll_flags = PJ_IOQUEUE_DEFAULT_EPOLL_FLAGS,
.cfg.epoll_flags = PJ_IOQUEUE_EPOLL_EXCLUSIVE,
.cfg.sock_type = SOCK_STREAM,
.cfg.n_threads = 0,
@ -1223,7 +1222,7 @@ int ioqueue_stress_test(void)
test_cb.on_accept_complete = on_accept_complete;
test_cb.on_connect_complete = on_connect_complete;
for (i=0; i<PJ_ARRAY_SIZE(tests); ++i) {
for (i=0; i<(int)PJ_ARRAY_SIZE(tests); ++i) {
int r;
test_desc *test = &tests[i];

View File

@ -959,7 +959,7 @@ int tcp_ioqueue_test()
pj_bool_t concurs[] = { PJ_TRUE, PJ_FALSE };
int i, rc;
for (i=0; i<PJ_ARRAY_SIZE(epoll_flags); ++i) {
for (i=0; i<(int)PJ_ARRAY_SIZE(epoll_flags); ++i) {
pj_ioqueue_cfg cfg;
pj_ioqueue_cfg_default(&cfg);
@ -973,7 +973,7 @@ int tcp_ioqueue_test()
return rc;
}
for (i=0; i<PJ_ARRAY_SIZE(concurs); ++i) {
for (i=0; i<(int)PJ_ARRAY_SIZE(concurs); ++i) {
pj_ioqueue_cfg cfg;
pj_ioqueue_cfg_default(&cfg);

View File

@ -1243,7 +1243,7 @@ int udp_ioqueue_test()
pj_bool_t concurs[] = { PJ_TRUE, PJ_FALSE };
int i, rc, err = 0;
for (i=0; i<PJ_ARRAY_SIZE(epoll_flags); ++i) {
for (i=0; i<(int)PJ_ARRAY_SIZE(epoll_flags); ++i) {
pj_ioqueue_cfg cfg;
pj_ioqueue_cfg_default(&cfg);
@ -1257,7 +1257,7 @@ int udp_ioqueue_test()
err = rc;
}
for (i=0; i<PJ_ARRAY_SIZE(concurs); ++i) {
for (i=0; i<(int)PJ_ARRAY_SIZE(concurs); ++i) {
pj_ioqueue_cfg cfg;
pj_ioqueue_cfg_default(&cfg);
@ -1272,7 +1272,7 @@ int udp_ioqueue_test()
}
#if PJ_HAS_THREADS
for (i=0; i<PJ_ARRAY_SIZE(epoll_flags); ++i) {
for (i=0; i<(int)PJ_ARRAY_SIZE(epoll_flags); ++i) {
pj_ioqueue_cfg cfg;
pj_ioqueue_cfg_default(&cfg);

View File

@ -299,9 +299,9 @@ initialize_network()
result = write(fd, "hosts,bind\n", 11);
result = close(fd);
fd = open("/etc/hosts", O_RDWR | O_CREAT, 0744);
result = write(fd, "127.0.0.1 localhost\n", 41);
result = write(fd, "127.0.0.1 localhost\n", 26);
result = write(fd, ip_address_string, strlen(ip_address_string));
result = write(fd, " pjsip-test\n", 32);
result = write(fd, " pjsip-test\n", 19);
result = close(fd);
netdriver_config.ip_address = ip_address_string;

View File

@ -92,7 +92,7 @@ static int simple_sleep_test(void)
static int sleep_duration_test(void)
{
const int MAX_SLIP = param_ci_mode? 200 : 20;
const unsigned MAX_SLIP = param_ci_mode? 200 : 20;
unsigned duration[] = { 2000, 1000, 500, 200, 100 };
unsigned i;
unsigned avg_diff, max_diff;

View File

@ -67,13 +67,14 @@ static volatile int quit_flag=0;
* Each of the thread mainly will just execute the loop which
* increments a variable.
*/
static void* thread_proc(pj_uint32_t *pcounter)
static int thread_proc(void *data)
{
/* Test that pj_thread_register() works. */
pj_thread_desc desc;
pj_thread_t *this_thread;
unsigned id;
pj_status_t rc;
pj_uint32_t *pcounter = (pj_uint32_t *)data;
id = *pcounter;
PJ_UNUSED_ARG(id); /* Warning about unused var if TRACE__ is disabled */
@ -84,20 +85,20 @@ static void* thread_proc(pj_uint32_t *pcounter)
rc = pj_thread_register("thread", desc, &this_thread);
if (rc != PJ_SUCCESS) {
app_perror("...error in pj_thread_register", rc);
return NULL;
return rc;
}
/* Test that pj_thread_this() works */
this_thread = pj_thread_this();
if (this_thread == NULL) {
PJ_LOG(3,(THIS_FILE, "...error: pj_thread_this() returns NULL!"));
return NULL;
return -1;
}
/* Test that pj_thread_get_name() works */
if (pj_thread_get_name(this_thread) == NULL) {
PJ_LOG(3,(THIS_FILE, "...error: pj_thread_get_name() returns NULL!"));
return NULL;
return -1;
}
/* Main loop */
@ -108,7 +109,7 @@ static void* thread_proc(pj_uint32_t *pcounter)
}
TRACE__((THIS_FILE, " thread %d quitting..", id));
return NULL;
return PJ_SUCCESS;
}
/*

View File

@ -126,10 +126,10 @@ enum pjmedia_video_pt
PJMEDIA_RTP_PT_VP8, /* used by VPX */
PJMEDIA_RTP_PT_VP8_RSV1, /* used by MediaCodec */
PJMEDIA_RTP_PT_VP8_RSV2,
PJMEDIA_RTP_PT_VP8_RSV2, /* used by ffmpeg avcodec */
PJMEDIA_RTP_PT_VP9, /* used by VPX */
PJMEDIA_RTP_PT_VP9_RSV1, /* used by MediaCodec */
PJMEDIA_RTP_PT_VP9_RSV2,
PJMEDIA_RTP_PT_VP9_RSV2, /* used by ffmpeg avcodec */
/* Caution!
* Ensure the value of the last pt above is <= 127.

View File

@ -47,14 +47,14 @@
* Initial memory block for media endpoint.
*/
#ifndef PJMEDIA_POOL_LEN_ENDPT
# define PJMEDIA_POOL_LEN_ENDPT 512
# define PJMEDIA_POOL_LEN_ENDPT 8000
#endif
/**
* Memory increment for media endpoint.
*/
#ifndef PJMEDIA_POOL_INC_ENDPT
# define PJMEDIA_POOL_INC_ENDPT 512
# define PJMEDIA_POOL_INC_ENDPT 4000
#endif
/**

View File

@ -491,7 +491,7 @@ typedef struct pjmedia_sdp_media pjmedia_sdp_media;
* @param buf The buffer.
* @param size The buffer length.
*
* @return the length printed, or -1 if the buffer is too
* @return The length printed, or -1 if the buffer is too
* short.
*/
PJ_DECL(int) pjmedia_sdp_media_print(const pjmedia_sdp_media *media, char *buf, pj_size_t size);
@ -508,6 +508,18 @@ PJ_DECL(pjmedia_sdp_media*)
pjmedia_sdp_media_clone( pj_pool_t *pool,
const pjmedia_sdp_media *rhs);
/**
* Print attribute to a buffer.
*
* @param attr The attribute.
* @param buf The buffer.
* @param size The buffer length.
*
* @return The length printed, or -1 if the buffer is too
* short.
*/
PJ_DECL(int) pjmedia_sdp_attr_print(const pjmedia_sdp_attr *attr, char *buf, pj_size_t size);
/**
* Find the first occurence of the specified attribute name in the media
* descriptor. Optionally the format may be specified.

View File

@ -405,6 +405,7 @@ static pj_status_t android_get_dev_info(pjmedia_aud_dev_factory *f,
pj_bzero(info, sizeof(*info));
pj_ansi_strcpy(info->name, "Android JNI");
pj_ansi_strcpy(info->driver, DRIVER_NAME);
info->default_samples_per_sec = 8000;
info->caps = PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING |
PJMEDIA_AUD_DEV_CAP_INPUT_SOURCE;

View File

@ -413,9 +413,13 @@ static pj_status_t oboe_refresh(pjmedia_aud_dev_factory *ff)
base_adi->caps = 0;
/* Get name info */
jstring jstrtmp = (jstring)jni_env->GetObjectField(jdev_info, jobjs.dev_info.f_name);
jstring jstrtmp = (jstring)
jni_env->GetObjectField(jdev_info,
jobjs.dev_info.f_name);
const char *strtmp = jni_env->GetStringUTFChars(jstrtmp, NULL);
pj_ansi_strncpy(base_adi->name, strtmp, sizeof(base_adi->name));
pj_ansi_strncpy(base_adi->driver, DRIVER_NAME,
sizeof(base_adi->driver));
f->dev_count++;

View File

@ -403,6 +403,7 @@ static pj_status_t opensl_get_dev_info(pjmedia_aud_dev_factory *f,
pj_bzero(info, sizeof(*info));
pj_ansi_strcpy(info->name, "OpenSL ES Audio");
pj_ansi_strcpy(info->driver, DRIVER_NAME);
info->default_samples_per_sec = 8000;
info->caps = PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING;
info->input_count = 1;

View File

@ -419,7 +419,9 @@ static pj_status_t configure_decoder(and_media_codec_data *and_media_data) {
AMediaFormat_setInt32(vid_fmt, AND_MEDIA_KEY_ENCODER, 0);
AMediaFormat_setInt32(vid_fmt, AND_MEDIA_KEY_PRIORITY, 0);
if (and_media_data->prm->dec_fmt.id == PJMEDIA_FORMAT_H264) {
if (and_media_codec[and_media_data->codec_idx].fmt_id ==
PJMEDIA_FORMAT_H264)
{
h264_codec_data *h264_data = (h264_codec_data *)and_media_data->ex_data;
if (h264_data->dec_sps_len) {

View File

@ -164,7 +164,7 @@ typedef struct ffmpeg_codec_desc ffmpeg_codec_desc;
typedef struct ffmpeg_private
{
const ffmpeg_codec_desc *desc;
pjmedia_vid_codec_param param; /**< Codec param */
pjmedia_vid_codec_param *param; /**< Codec param */
pj_pool_t *pool; /**< Pool for each instance */
/* Format info and apply format param */
@ -185,8 +185,8 @@ typedef struct ffmpeg_private
pj_timestamp last_dec_keyframe_ts;
/* The ffmpeg codec states. */
AVCodec *enc;
AVCodec *dec;
const AVCodec *enc;
const AVCodec *dec;
AVCodecContext *enc_ctx;
AVCodecContext *dec_ctx;
@ -197,7 +197,7 @@ typedef struct ffmpeg_private
/**< Expected output format of
ffmpeg decoder */
void *data; /**< Codec specific data */
void *data; /**< Codec specific data */
} ffmpeg_private;
@ -207,7 +207,8 @@ typedef struct ffmpeg_private
#define FUNC_PACKETIZE(name) \
pj_status_t(name)(ffmpeg_private *ff, pj_uint8_t *bits, \
pj_size_t bits_len, unsigned *bits_pos, \
pj_uint8_t *payload, pj_size_t *payload_len, pj_bool_t is_keyframe)
pj_uint8_t *payload, pj_size_t *payload_len, \
pj_bool_t is_keyframe)
#define FUNC_UNPACKETIZE(name) \
pj_status_t(name)(ffmpeg_private *ff, const pj_uint8_t *payload, \
@ -253,8 +254,8 @@ struct ffmpeg_codec_desc
/* Init time defined info */
pj_bool_t enabled;
AVCodec *enc;
AVCodec *dec;
const AVCodec *enc;
const AVCodec *dec;
};
@ -370,13 +371,13 @@ static pj_status_t vpx_preopen(ffmpeg_private *ff)
ff->data = data;
/* Parse local fmtp */
if (!ff->param.ignore_fmtp)
if (!ff->param->ignore_fmtp)
{
pjmedia_vid_codec_vpx_fmtp vpx_fmtp;
const unsigned MAX_RX_RES = 1200;
unsigned max_res = MAX_RX_RES;
status = pjmedia_vid_codec_vpx_parse_fmtp(&ff->param.dec_fmtp, &vpx_fmtp);
status = pjmedia_vid_codec_vpx_parse_fmtp(&ff->param->dec_fmtp, &vpx_fmtp);
if (status != PJ_SUCCESS)
{
PJ_LOG(2, (THIS_FILE, "Parse vpx fmtp fail, status:%d", status));
@ -391,7 +392,7 @@ static pj_status_t vpx_preopen(ffmpeg_private *ff)
/* Create packetizer */
pktz_cfg.fmt_id = ff->desc->info.fmt_id;
pktz_cfg.mtu = ff->param.enc_mtu;
pktz_cfg.mtu = ff->param->enc_mtu;
status = pjmedia_vpx_packetizer_create(ff->pool, &pktz_cfg, &data->pktz);
if (status != PJ_SUCCESS)
{
@ -469,13 +470,13 @@ static pj_status_t h264_preopen(ffmpeg_private *ff)
ff->data = data;
/* Parse remote fmtp */
status = pjmedia_vid_codec_h264_parse_fmtp(&ff->param.enc_fmtp,
status = pjmedia_vid_codec_h264_parse_fmtp(&ff->param->enc_fmtp,
&data->fmtp);
if (status != PJ_SUCCESS)
return status;
/* Create packetizer */
pktz_cfg.mtu = ff->param.enc_mtu;
pktz_cfg.mtu = ff->param->enc_mtu;
pktz_cfg.unpack_nal_start = 0;
#if 0
if (data->fmtp.packetization_mode == 0)
@ -501,18 +502,18 @@ static pj_status_t h264_preopen(ffmpeg_private *ff)
return status;
/* Apply SDP fmtp to format in codec param */
if (!ff->param.ignore_fmtp) {
status = pjmedia_vid_codec_h264_apply_fmtp(&ff->param);
if (!ff->param->ignore_fmtp) {
status = pjmedia_vid_codec_h264_apply_fmtp(ff->param);
if (status != PJ_SUCCESS)
return status;
}
if (ff->param.dir & PJMEDIA_DIR_ENCODING) {
if (ff->param->dir & PJMEDIA_DIR_ENCODING) {
pjmedia_video_format_detail *vfd;
AVCodecContext *ctx = ff->enc_ctx;
const char *profile = NULL;
vfd = pjmedia_format_get_video_format_detail(&ff->param.enc_fmt,
vfd = pjmedia_format_get_video_format_detail(&ff->param->enc_fmt,
PJ_TRUE);
/* Override generic params after applying SDP fmtp */
@ -551,10 +552,10 @@ static pj_status_t h264_preopen(ffmpeg_private *ff)
ctx->level = data->fmtp.level;
/* Limit NAL unit size as we prefer single NAL unit packetization */
if (!AV_OPT_SET_INT(ctx->priv_data, "slice-max-size", ff->param.enc_mtu))
if (!AV_OPT_SET_INT(ctx->priv_data, "slice-max-size", ff->param->enc_mtu))
{
PJ_LOG(3, (THIS_FILE, "Failed to set H264 max NAL size to %d",
ff->param.enc_mtu));
ff->param->enc_mtu));
}
/* Apply intra-refresh */
@ -574,7 +575,7 @@ static pj_status_t h264_preopen(ffmpeg_private *ff)
}
}
if (ff->param.dir & PJMEDIA_DIR_DECODING) {
if (ff->param->dir & PJMEDIA_DIR_DECODING) {
AVCodecContext *ctx = ff->dec_ctx;
/* Apply the "sprop-parameter-sets" fmtp from remote SDP to
@ -598,12 +599,13 @@ static pj_status_t h264_postopen(ffmpeg_private *ff)
static FUNC_PACKETIZE(h264_packetize)
{
PJ_UNUSED_ARG(is_keyframe);
h264_data *data = (h264_data*)ff->data;
pj_status_t status;
pj_uint8_t *outbuf = payload;
pj_size_t out_size = *payload_len;
status = pjmedia_h264_packetize(data->pktz, bits, bits_len, bits_pos,
&payload, payload_len);
(const pj_uint8_t **)&payload, payload_len);
if (status != PJ_SUCCESS)
return status;
if (out_size < *payload_len)
@ -640,23 +642,23 @@ static pj_status_t h263_preopen(ffmpeg_private *ff)
ff->data = data;
/* Create packetizer */
pktz_cfg.mtu = ff->param.enc_mtu;
pktz_cfg.mtu = ff->param->enc_mtu;
pktz_cfg.mode = PJMEDIA_H263_PACKETIZER_MODE_RFC4629;
status = pjmedia_h263_packetizer_create(ff->pool, &pktz_cfg, &data->pktz);
if (status != PJ_SUCCESS)
return status;
/* Apply fmtp settings to codec param */
if (!ff->param.ignore_fmtp) {
status = pjmedia_vid_codec_h263_apply_fmtp(&ff->param);
if (!ff->param->ignore_fmtp) {
status = pjmedia_vid_codec_h263_apply_fmtp(ff->param);
}
/* Override generic params after applying SDP fmtp */
if (ff->param.dir & PJMEDIA_DIR_ENCODING) {
if (ff->param->dir & PJMEDIA_DIR_ENCODING) {
pjmedia_video_format_detail *vfd;
AVCodecContext *ctx = ff->enc_ctx;
vfd = pjmedia_format_get_video_format_detail(&ff->param.enc_fmt,
vfd = pjmedia_format_get_video_format_detail(&ff->param->enc_fmt,
PJ_TRUE);
/* Override generic params after applying SDP fmtp */
@ -671,12 +673,13 @@ static pj_status_t h263_preopen(ffmpeg_private *ff)
static FUNC_PACKETIZE(h263_packetize)
{
PJ_UNUSED_ARG(is_keyframe);
h263_data *data = (h263_data*)ff->data;
pj_status_t status;
pj_uint8_t *outbuf = payload;
pj_size_t out_size = *payload_len;
status = pjmedia_h263_packetize(data->pktz, bits, bits_len, bits_pos,
&payload, payload_len);
(const pj_uint8_t **)&payload, payload_len);
if (status != PJ_SUCCESS)
return status;
if (out_size < *payload_len)
@ -698,7 +701,7 @@ static FUNC_UNPACKETIZE(h263_unpacketize)
static const ffmpeg_codec_desc* find_codec_desc_by_info(
const pjmedia_vid_codec_info *info)
{
int i;
unsigned i;
for (i=0; i<PJ_ARRAY_SIZE(codec_desc); ++i) {
ffmpeg_codec_desc *desc = &codec_desc[i];
@ -719,7 +722,7 @@ static const ffmpeg_codec_desc* find_codec_desc_by_info(
static int find_codec_idx_by_fmt_id(pjmedia_format_id fmt_id)
{
int i;
unsigned i;
for (i=0; i<PJ_ARRAY_SIZE(codec_desc); ++i) {
if (codec_desc[i].info.fmt_id == fmt_id)
return i;
@ -735,7 +738,7 @@ static void init_codec(AVCodec *c, pj_bool_t is_encoder,
ffmpeg_codec_desc *desc;
pjmedia_format_id fmt_id;
int codec_info_idx;
#if LIBAVCODEC_VERSION_MAJOR <= 52
# define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
#endif
@ -789,7 +792,7 @@ static void init_codec(AVCodec *c, pj_bool_t is_encoder,
"Unrecognized ffmpeg pixel format %d", *p));
continue;
}
//raw_fmt[raw_fmt_cnt++] = fmt_id;
/* Disable some formats due to H.264 error:
* x264 [error]: baseline profile doesn't support 4:4:4
@ -839,7 +842,7 @@ static void init_codec(AVCodec *c, pj_bool_t is_encoder,
desc->info.dir |= PJMEDIA_DIR_ENCODING;
desc->enc = c;
}
/* Get ffmpeg decoder instance */
if (is_decoder && !desc->dec) {
desc->info.dir |= PJMEDIA_DIR_DECODING;
@ -871,7 +874,7 @@ PJ_DEF(pj_status_t) pjmedia_codec_ffmpeg_vid_init(pjmedia_vid_codec_mgr *mgr,
pj_pool_factory *pf)
{
pj_pool_t *pool;
AVCodec *c;
const AVCodec *c;
pj_status_t status;
unsigned i;
@ -908,7 +911,7 @@ PJ_DEF(pj_status_t) pjmedia_codec_ffmpeg_vid_init(pjmedia_vid_codec_mgr *mgr,
#endif
#if LIBAVCODEC_VER_AT_LEAST(58,137)
for (i = 0; i < PJ_ARRAY_SIZE(codec_desc); ++i) {
unsigned codec_id;
@ -1275,18 +1278,18 @@ static pj_status_t open_ffmpeg_codec(ffmpeg_private *ff,
pj_status_t status;
/* Get decoded pixel format */
status = pjmedia_format_id_to_PixelFormat(ff->param.dec_fmt.id,
status = pjmedia_format_id_to_PixelFormat(ff->param->dec_fmt.id,
&pix_fmt);
if (status != PJ_SUCCESS)
return status;
ff->expected_dec_fmt = pix_fmt;
/* Get video format detail for shortcut access to encoded format */
vfd = pjmedia_format_get_video_format_detail(&ff->param.enc_fmt,
vfd = pjmedia_format_get_video_format_detail(&ff->param->enc_fmt,
PJ_TRUE);
/* Allocate ffmpeg codec context */
if (ff->param.dir & PJMEDIA_DIR_ENCODING) {
if (ff->param->dir & PJMEDIA_DIR_ENCODING) {
#if LIBAVCODEC_VER_AT_LEAST(53,20)
ff->enc_ctx = avcodec_alloc_context3(ff->enc);
#else
@ -1295,7 +1298,7 @@ static pj_status_t open_ffmpeg_codec(ffmpeg_private *ff,
if (ff->enc_ctx == NULL)
goto on_error;
}
if (ff->param.dir & PJMEDIA_DIR_DECODING) {
if (ff->param->dir & PJMEDIA_DIR_DECODING) {
#if LIBAVCODEC_VER_AT_LEAST(53,20)
ff->dec_ctx = avcodec_alloc_context3(ff->dec);
#else
@ -1306,7 +1309,7 @@ static pj_status_t open_ffmpeg_codec(ffmpeg_private *ff,
}
/* Init generic encoder params */
if (ff->param.dir & PJMEDIA_DIR_ENCODING) {
if (ff->param->dir & PJMEDIA_DIR_ENCODING) {
AVCodecContext *ctx = ff->enc_ctx;
ctx->pix_fmt = pix_fmt;
@ -1332,12 +1335,12 @@ static pj_status_t open_ffmpeg_codec(ffmpeg_private *ff,
}
/* Init generic decoder params */
if (ff->param.dir & PJMEDIA_DIR_DECODING) {
if (ff->param->dir & PJMEDIA_DIR_DECODING) {
AVCodecContext *ctx = ff->dec_ctx;
/* Width/height may be overriden by ffmpeg after first decoding. */
ctx->width = ctx->coded_width = ff->param.dec_fmt.det.vid.size.w;
ctx->height = ctx->coded_height = ff->param.dec_fmt.det.vid.size.h;
ctx->width = ctx->coded_width = ff->param->dec_fmt.det.vid.size.w;
ctx->height = ctx->coded_height = ff->param->dec_fmt.det.vid.size.h;
ctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
ctx->workaround_bugs = FF_BUG_AUTODETECT;
ctx->opaque = ff;
@ -1353,7 +1356,7 @@ static pj_status_t open_ffmpeg_codec(ffmpeg_private *ff,
}
/* Open encoder */
if (ff->param.dir & PJMEDIA_DIR_ENCODING) {
if (ff->param->dir & PJMEDIA_DIR_ENCODING) {
int err;
pj_mutex_lock(ff_mutex);
@ -1368,7 +1371,7 @@ static pj_status_t open_ffmpeg_codec(ffmpeg_private *ff,
}
/* Open decoder */
if (ff->param.dir & PJMEDIA_DIR_DECODING) {
if (ff->param->dir & PJMEDIA_DIR_DECODING) {
int err;
pj_mutex_lock(ff_mutex);
@ -1420,11 +1423,11 @@ static pj_status_t ffmpeg_codec_open( pjmedia_vid_codec *codec,
PJ_ASSERT_RETURN(codec && attr, PJ_EINVAL);
ff = (ffmpeg_private*)codec->codec_data;
pj_memcpy(&ff->param, attr, sizeof(*attr));
ff->param = pjmedia_vid_codec_param_clone(ff->pool, attr);
/* Normalize encoding MTU in codec param */
if (attr->enc_mtu > PJMEDIA_MAX_VID_PAYLOAD_SIZE)
attr->enc_mtu = PJMEDIA_MAX_VID_PAYLOAD_SIZE;
if (ff->param->enc_mtu > PJMEDIA_MAX_VID_PAYLOAD_SIZE)
ff->param->enc_mtu = PJMEDIA_MAX_VID_PAYLOAD_SIZE;
/* Open the codec */
ff_mutex = ((struct ffmpeg_factory*)codec->factory)->mutex;
@ -1433,13 +1436,13 @@ static pj_status_t ffmpeg_codec_open( pjmedia_vid_codec *codec,
goto on_error;
/* Init format info and apply-param of decoder */
ff->dec_vfi = pjmedia_get_video_format_info(NULL, ff->param.dec_fmt.id);
ff->dec_vfi = pjmedia_get_video_format_info(NULL, ff->param->dec_fmt.id);
if (!ff->dec_vfi) {
status = PJ_EINVAL;
goto on_error;
}
pj_bzero(&ff->dec_vafp, sizeof(ff->dec_vafp));
ff->dec_vafp.size = ff->param.dec_fmt.det.vid.size;
ff->dec_vafp.size = ff->param->dec_fmt.det.vid.size;
ff->dec_vafp.buffer = NULL;
status = (*ff->dec_vfi->apply_fmt)(ff->dec_vfi, &ff->dec_vafp);
if (status != PJ_SUCCESS) {
@ -1447,13 +1450,13 @@ static pj_status_t ffmpeg_codec_open( pjmedia_vid_codec *codec,
}
/* Init format info and apply-param of encoder */
ff->enc_vfi = pjmedia_get_video_format_info(NULL, ff->param.dec_fmt.id);
ff->enc_vfi = pjmedia_get_video_format_info(NULL, ff->param->dec_fmt.id);
if (!ff->enc_vfi) {
status = PJ_EINVAL;
goto on_error;
}
pj_bzero(&ff->enc_vafp, sizeof(ff->enc_vafp));
ff->enc_vafp.size = ff->param.enc_fmt.det.vid.size;
ff->enc_vafp.size = ff->param->enc_fmt.det.vid.size;
ff->enc_vafp.buffer = NULL;
status = (*ff->enc_vfi->apply_fmt)(ff->enc_vfi, &ff->enc_vafp);
if (status != PJ_SUCCESS) {
@ -1461,7 +1464,7 @@ static pj_status_t ffmpeg_codec_open( pjmedia_vid_codec *codec,
}
/* Alloc buffers if needed */
ff->whole = (ff->param.packing == PJMEDIA_VID_PACKING_WHOLE);
ff->whole = (ff->param->packing == PJMEDIA_VID_PACKING_WHOLE);
if (!ff->whole) {
ff->enc_buf_size = (unsigned)ff->enc_vafp.framebytes;
ff->enc_buf = pj_pool_alloc(ff->pool, ff->enc_buf_size);
@ -1473,7 +1476,7 @@ static pj_status_t ffmpeg_codec_open( pjmedia_vid_codec *codec,
/* Update codec attributes, e.g: encoding format may be changed by
* SDP fmtp negotiation.
*/
pj_memcpy(attr, &ff->param, sizeof(*attr));
pj_memcpy(attr, ff->param, sizeof(*attr));
return PJ_SUCCESS;
@ -1533,7 +1536,7 @@ static pj_status_t ffmpeg_codec_get_param(pjmedia_vid_codec *codec,
PJ_ASSERT_RETURN(codec && param, PJ_EINVAL);
ff = (ffmpeg_private*)codec->codec_data;
pj_memcpy(param, &ff->param, sizeof(*param));
pj_memcpy(param, ff->param, sizeof(*param));
return PJ_SUCCESS;
}
@ -1544,7 +1547,8 @@ static pj_status_t ffmpeg_packetize ( pjmedia_vid_codec *codec,
pj_size_t bits_len,
unsigned *bits_pos,
pj_uint8_t *payload,
pj_size_t *payload_len, pj_bool_t is_keyframe)
pj_size_t *payload_len,
pj_bool_t is_keyframe)
{
ffmpeg_private *ff = (ffmpeg_private*)codec->codec_data;
@ -1569,7 +1573,7 @@ static pj_status_t ffmpeg_unpacketize(pjmedia_vid_codec *codec,
return (*ff->desc->unpacketize)(ff, payload, payload_len,
bits, bits_len, bits_pos);
}
return PJ_ENOTSUP;
}
@ -1616,7 +1620,7 @@ static pj_status_t ffmpeg_codec_encode_whole(pjmedia_vid_codec *codec,
avframe.pts = av_rescale_q(input->timestamp.u64, src_timebase,
ff->enc_ctx->time_base);
*/
for (i[0] = 0; i[0] < ff->enc_vfi->plane_cnt; ++i[0]) {
avframe.data[i[0]] = p;
avframe.linesize[i[0]] = ff->enc_vafp.strides[i[0]];
@ -1689,9 +1693,9 @@ static pj_status_t ffmpeg_codec_encode_whole(pjmedia_vid_codec *codec,
#if LIBAVCODEC_VER_AT_LEAST(54,15)
has_key_frame = (avpacket.flags & AV_PKT_FLAG_KEY);
#else
has_key_frame = ff->enc_ctx->coded_frame->key_frame;
has_key_frame = ff->enc_ctx->coded_frame->key_frame;
#endif
if (has_key_frame)
if (has_key_frame)
output->bit_info |= PJMEDIA_VID_FRM_KEYFRAME;
}
@ -1711,8 +1715,7 @@ static pj_status_t ffmpeg_codec_encode_begin(pjmedia_vid_codec *codec,
*has_more = PJ_FALSE;
if (ff->whole) {
status = ffmpeg_codec_encode_whole(codec, opt, input, out_size,
output);
status = ffmpeg_codec_encode_whole(codec, opt, input, out_size, output);
} else {
pjmedia_frame whole_frm;
pj_bzero(&whole_frm, sizeof(whole_frm));
@ -1795,17 +1798,17 @@ static pj_status_t check_decode_result(pjmedia_vid_codec *codec,
return status;
/* Update decoder format in param */
ff->param.dec_fmt.id = new_fmt_id;
ff->param.dec_fmt.det.vid.size.w = ff->dec_ctx->width;
ff->param.dec_fmt.det.vid.size.h = ff->dec_ctx->height;
ff->param->dec_fmt.id = new_fmt_id;
ff->param->dec_fmt.det.vid.size.w = ff->dec_ctx->width;
ff->param->dec_fmt.det.vid.size.h = ff->dec_ctx->height;
ff->expected_dec_fmt = ff->dec_ctx->pix_fmt;
/* Re-init format info and apply-param of decoder */
ff->dec_vfi = pjmedia_get_video_format_info(NULL, ff->param.dec_fmt.id);
ff->dec_vfi = pjmedia_get_video_format_info(NULL, ff->param->dec_fmt.id);
if (!ff->dec_vfi)
return PJ_ENOTSUP;
pj_bzero(&ff->dec_vafp, sizeof(ff->dec_vafp));
ff->dec_vafp.size = ff->param.dec_fmt.det.vid.size;
ff->dec_vafp.size = ff->param->dec_fmt.det.vid.size;
ff->dec_vafp.buffer = NULL;
status = (*ff->dec_vfi->apply_fmt)(ff->dec_vfi, &ff->dec_vafp);
if (status != PJ_SUCCESS)
@ -1823,8 +1826,8 @@ static pj_status_t check_decode_result(pjmedia_vid_codec *codec,
/* Broadcast format changed event */
pjmedia_event_init(&event, PJMEDIA_EVENT_FMT_CHANGED, ts, codec);
event.data.fmt_changed.dir = PJMEDIA_DIR_DECODING;
pj_memcpy(&event.data.fmt_changed.new_fmt, &ff->param.dec_fmt,
sizeof(ff->param.dec_fmt));
pj_memcpy(&event.data.fmt_changed.new_fmt, &ff->param->dec_fmt,
sizeof(ff->param->dec_fmt));
pjmedia_event_publish(NULL, codec, &event, 0);
}
@ -1969,7 +1972,7 @@ static pj_status_t ffmpeg_codec_decode_whole(pjmedia_vid_codec *codec,
if (avframe.linesize[i]!=vafp->strides[i]) {
/* Padding exists, copy line by line */
pj_uint8_t *q_end;
q_end = q+vafp->plane_bytes[i];
while(q < q_end) {
pj_memcpy(q, p, vafp->strides[i]);
@ -1989,7 +1992,7 @@ static pj_status_t ffmpeg_codec_decode_whole(pjmedia_vid_codec *codec,
output->type = PJMEDIA_FRAME_TYPE_NONE;
output->size = 0;
}
return PJ_SUCCESS;
}

View File

@ -163,7 +163,7 @@ PJ_DEF(pj_status_t) pjmedia_codec_gsm_init( pjmedia_endpt *endpt )
gsm_codec_factory.base.factory_data = NULL;
gsm_codec_factory.endpt = endpt;
gsm_codec_factory.pool = pjmedia_endpt_create_pool(endpt, "gsm", 4000,
gsm_codec_factory.pool = pjmedia_endpt_create_pool(endpt, "gsm", 1000,
4000);
if (!gsm_codec_factory.pool)
return PJ_ENOMEM;

View File

@ -463,6 +463,8 @@ PJ_DEF(pj_status_t) pjmedia_h264_unpacketize(pjmedia_h264_packetizer *pktz,
#if DBG_UNPACKETIZE
PJ_LOG(3, ("h264unpack", "Unpacked %d H264 NAL units (len=%d)",
cnt, payload_len));
#else
PJ_UNUSED_ARG(cnt);
#endif
}

View File

@ -164,7 +164,7 @@ PJ_DEF(pj_status_t) pjmedia_codec_l16_init(pjmedia_endpt *endpt,
l16_factory.endpt = endpt;
/* Create pool */
l16_factory.pool = pjmedia_endpt_create_pool(endpt, "l16", 4000, 4000);
l16_factory.pool = pjmedia_endpt_create_pool(endpt, "l16", 1000, 4000);
if (!l16_factory.pool)
return PJ_ENOMEM;

View File

@ -568,7 +568,7 @@ static pj_status_t factory_alloc_codec( pjmedia_codec_factory *factory,
PJ_UNUSED_ARG(ci);
TRACE_((THIS_FILE, "%s:%d: - TRACE", __FUNCTION__, __LINE__));
pool = pjmedia_endpt_create_pool(f->endpt, "opus", 512, 512);
pool = pjmedia_endpt_create_pool(f->endpt, "opus", 4000, 4000);
if (!pool) return PJ_ENOMEM;
opus_data = PJ_POOL_ZALLOC_T(pool, struct opus_data);
@ -735,7 +735,7 @@ static pj_status_t codec_open( pjmedia_codec *codec,
/* Set bitrate */
opus_encoder_ctl(opus_data->enc, OPUS_SET_BITRATE(auto_bit_rate?
OPUS_AUTO:
attr->info.avg_bps));
(int)attr->info.avg_bps));
/* Set VAD */
opus_encoder_ctl(opus_data->enc, OPUS_SET_DTX(attr->setting.vad ? 1 : 0));
/* Set PLC */
@ -824,7 +824,7 @@ static pj_status_t codec_modify( pjmedia_codec *codec,
/* Set bitrate */
opus_data->cfg.bit_rate = attr->info.avg_bps;
opus_encoder_ctl(opus_data->enc, OPUS_SET_BITRATE(attr->info.avg_bps?
attr->info.avg_bps:
(int)attr->info.avg_bps:
OPUS_AUTO));
/* Set VAD */
opus_encoder_ctl(opus_data->enc, OPUS_SET_DTX(attr->setting.vad ? 1 : 0));

View File

@ -228,7 +228,7 @@ PJ_DEF(pj_status_t) pjmedia_codec_speex_init( pjmedia_endpt *endpt,
spx_factory.endpt = endpt;
spx_factory.pool = pjmedia_endpt_create_pool(endpt, "speex",
4000, 4000);
1000, 4000);
if (!spx_factory.pool)
return PJ_ENOMEM;

View File

@ -358,7 +358,7 @@ static pj_status_t vtool_alloc_codec(pjmedia_vid_codec_factory *factory,
*p_codec = NULL;
pool = pj_pool_create(vtool_factory.pf, "vtool%p", 512, 512, NULL);
pool = pj_pool_create(vtool_factory.pf, "vtool%p", 16000, 4000, NULL);
if (!pool)
return PJ_ENOMEM;

View File

@ -175,7 +175,7 @@ pjmedia_vid_dev_factory* pjmedia_cbar_factory(pj_pool_factory *pf)
struct cbar_factory *f;
pj_pool_t *pool;
pool = pj_pool_create(pf, "cbar video", 512, 512, NULL);
pool = pj_pool_create(pf, "cbar video", 4000, 4000, NULL);
f = PJ_POOL_ZALLOC_T(pool, struct cbar_factory);
f->pf = pf;
f->pool = pool;

View File

@ -36,13 +36,8 @@
#define THIS_FILE "darwin_dev.m"
#define DEFAULT_CLOCK_RATE 90000
#if TARGET_OS_IPHONE
#define DEFAULT_WIDTH 352
#define DEFAULT_HEIGHT 288
#else
#define DEFAULT_WIDTH 1280
#define DEFAULT_HEIGHT 720
#endif
#define DEFAULT_WIDTH 640
#define DEFAULT_HEIGHT 480
#define DEFAULT_FPS 15
/* Define whether we should maintain the aspect ratio when rotating the image.
@ -144,7 +139,6 @@ struct darwin_stream
AVCaptureVideoDataOutput *video_output;
VOutDelegate *vout_delegate;
dispatch_queue_t queue;
AVCaptureVideoPreviewLayer *prev_layer;
pj_bool_t is_running;
#if TARGET_OS_IPHONE
@ -153,6 +147,8 @@ struct darwin_stream
pj_size_t render_buf_size;
CGDataProviderRef render_data_provider;
UIView *render_view;
AVCaptureVideoPreviewLayer *prev_layer;
UIView *prev_view;
#endif
pj_timestamp frame_ts;
@ -236,6 +232,7 @@ static void set_preset_str()
#endif
}
#if TARGET_OS_IPHONE
static void dispatch_sync_on_main_queue(void (^block)(void))
{
if ([NSThread isMainThread]) {
@ -244,6 +241,7 @@ static void dispatch_sync_on_main_queue(void (^block)(void))
dispatch_sync(dispatch_get_main_queue(), block);
}
}
#endif
/****************************************************************************
* Factory operations
@ -256,7 +254,7 @@ pjmedia_vid_dev_factory* pjmedia_darwin_factory(pj_pool_factory *pf)
struct darwin_factory *f;
pj_pool_t *pool;
pool = pj_pool_create(pf, "darwin video", 512, 512, NULL);
pool = pj_pool_create(pf, "darwin video", 8000, 4000, NULL);
f = PJ_POOL_ZALLOC_T(pool, struct darwin_factory);
f->pf = pf;
f->pool = pool;
@ -1020,11 +1018,18 @@ static pj_status_t darwin_stream_get_cap(pjmedia_vid_dev_stream *s,
switch (cap) {
#if TARGET_OS_IPHONE
case PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW:
{
pjmedia_vid_dev_hwnd *hwnd = (pjmedia_vid_dev_hwnd *) pval;
hwnd->type = PJMEDIA_VID_DEV_HWND_TYPE_IOS;
hwnd->info.ios.window = (void *)strm->prev_view;
return PJ_SUCCESS;
}
case PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW:
{
pjmedia_vid_dev_hwnd *hwnd = (pjmedia_vid_dev_hwnd*) pval;
hwnd->type = PJMEDIA_VID_DEV_HWND_TYPE_NONE;
hwnd->info.ios.window = (void*)strm->render_view;
pjmedia_vid_dev_hwnd *hwnd = (pjmedia_vid_dev_hwnd *) pval;
hwnd->type = PJMEDIA_VID_DEV_HWND_TYPE_IOS;
hwnd->info.ios.window = (void *)strm->render_view;
return PJ_SUCCESS;
}
#endif /* TARGET_OS_IPHONE */
@ -1045,6 +1050,7 @@ static pj_status_t darwin_stream_set_cap(pjmedia_vid_dev_stream *s,
PJ_ASSERT_RETURN(s && pval, PJ_EINVAL);
switch (cap) {
#if TARGET_OS_IPHONE
/* Native preview */
case PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW:
{
@ -1055,7 +1061,8 @@ static pj_status_t darwin_stream_set_cap(pjmedia_vid_dev_stream *s,
if (strm->prev_layer) {
CALayer *prev_layer = strm->prev_layer;
dispatch_sync_on_main_queue(^{
[prev_layer removeFromSuperlayer];
if ([prev_layer superlayer])
[prev_layer removeFromSuperlayer];
[prev_layer release];
});
strm->prev_layer = nil;
@ -1074,29 +1081,34 @@ static pj_status_t darwin_stream_set_cap(pjmedia_vid_dev_stream *s,
if (!strm->cap_session)
return PJ_EINVALIDOP;
#if TARGET_OS_IPHONE
/* Preview layer instantiation should be in main thread! */
dispatch_sync_on_main_queue(^{
/* Create view, if none */
if (!strm->render_view)
darwin_init_view(strm);
/* Create preview layer */
AVCaptureVideoPreviewLayer *prev_layer =
[[AVCaptureVideoPreviewLayer alloc]
initWithSession:strm->cap_session];
/* Attach preview layer to a UIView */
prev_layer.videoGravity = AVLayerVideoGravityResize;
prev_layer.frame = strm->render_view.bounds;
[strm->render_view.layer addSublayer:prev_layer];
strm->prev_layer = prev_layer;
strm->prev_layer = [[AVCaptureVideoPreviewLayer alloc]
initWithSession:strm->cap_session];
strm->prev_layer.videoGravity =
AVLayerVideoGravityResizeAspectFill;
/* Create preview view and init it at smaller size than
* the actual video.
*/
if (!strm->prev_view) {
CGRect rect;
rect = CGRectMake(0, 0, strm->param.fmt.det.vid.size.w/2,
strm->param.fmt.det.vid.size.h/2);
strm->prev_view = [[UIView alloc] initWithFrame:rect];
}
/* Add the preview layer as sublayer */
strm->prev_layer.frame = strm->prev_view.bounds;
[strm->prev_view.layer addSublayer:strm->prev_layer];
});
PJ_LOG(4, (THIS_FILE, "Native preview initialized"));
#endif
return PJ_SUCCESS;
}
#endif
/* Fast switch */
case PJMEDIA_VID_DEV_CAP_SWITCH:
@ -1200,8 +1212,6 @@ static pj_status_t darwin_stream_set_cap(pjmedia_vid_dev_stream *s,
r.size = CGSizeMake(strm->param.disp_size.w,
strm->param.disp_size.h);
strm->render_view.bounds = r;
if (strm->prev_layer)
strm->prev_layer.frame = r;
});
return PJ_SUCCESS;
}
@ -1452,6 +1462,15 @@ static pj_status_t darwin_stream_destroy(pjmedia_vid_dev_stream *strm)
[stream->render_view release];
stream->render_view = nil;
}
if (stream->prev_view) {
[stream->prev_view
performSelectorOnMainThread:@selector(removeFromSuperview)
withObject:nil waitUntilDone:YES];
[stream->prev_view release];
stream->prev_view = nil;
}
if (stream->render_data_provider) {
CGDataProviderRelease(stream->render_data_provider);

View File

@ -281,7 +281,7 @@ pjmedia_vid_dev_factory* pjmedia_sdl_factory(pj_pool_factory *pf)
struct sdl_factory *f;
pj_pool_t *pool;
pool = pj_pool_create(pf, "sdl video", 1000, 1000, NULL);
pool = pj_pool_create(pf, "sdl video", 4000, 4000, NULL);
f = PJ_POOL_ZALLOC_T(pool, struct sdl_factory);
f->pf = pf;
f->pool = pool;

View File

@ -200,7 +200,7 @@ PJ_DEF(const char*) pjmedia_aud_dev_cap_name(pjmedia_aud_dev_cap cap,
if (p_desc==NULL) p_desc = &desc;
for (i=0; i<PJ_ARRAY_SIZE(cap_infos); ++i) {
if ((1 << i)==cap)
if ((1 << i)==(int)cap)
break;
}

View File

@ -42,7 +42,7 @@
#define AVISF_DISABLED 0x00000001
#define AVISF_VIDEO_PALCHANGES 0x00010000
#define AVI_EOF 0xFFEEFFEE
#define AVI_EOF (int)0xFFEEFFEE
//#define COMPARE_TAG(doc_tag, tag) (doc_tag==*((pj_uint32_t*)avi_tags[tag]))
#define COMPARE_TAG(doc_tag, tag) \
@ -228,8 +228,8 @@ pjmedia_avi_player_create_streams(pj_pool_t *pool,
fport[0]->fsize = pj_file_size(filename);
/* Size must be more than AVI header size */
if (fport[0]->fsize <= sizeof(riff_hdr_t) + sizeof(avih_hdr_t) +
sizeof(strl_hdr_t))
if (fport[0]->fsize <= (pj_off_t)(sizeof(riff_hdr_t) + sizeof(avih_hdr_t) +
sizeof(strl_hdr_t)))
{
return PJMEDIA_EINVALIMEDIATYPE;
}

View File

@ -43,8 +43,8 @@ PJ_DEF(pj_status_t) pjmedia_clock_src_init( pjmedia_clock_src *clocksrc,
}
/* API: Update clock source */
PJ_DECL(pj_status_t) pjmedia_clock_src_update( pjmedia_clock_src *clocksrc,
const pj_timestamp *timestamp )
PJ_DEF(pj_status_t) pjmedia_clock_src_update( pjmedia_clock_src *clocksrc,
const pj_timestamp *timestamp )
{
PJ_ASSERT_RETURN(clocksrc, PJ_EINVAL);

View File

@ -293,7 +293,7 @@ PJ_DEF(pj_status_t) pjmedia_codec_mgr_get_codec_info( pjmedia_codec_mgr *mgr,
{
unsigned i;
PJ_ASSERT_RETURN(mgr && p_info && pt>=0 && pt < 96, PJ_EINVAL);
PJ_ASSERT_RETURN(mgr && p_info && pt < 96, PJ_EINVAL);
pj_mutex_lock(mgr->mutex);

View File

@ -76,7 +76,7 @@ typedef enum conv_func_type
SCALE_PLANAR
} conv_func_type;
typedef void (*gen_conv_func)();
typedef int (*gen_conv_func)();
typedef int (*conv_pack_to_pack_method)(const uint8* src, int src_stride,
uint8* dst, int dst_stride,

View File

@ -104,7 +104,9 @@ static pj_status_t event_mgr_distribute_events(pjmedia_event_mgr *mgr,
pj_status_t err = PJ_SUCCESS;
esub * sub = mgr->esub_list.next;
pjmedia_event *ev = &ev_queue->events[ev_queue->head];
#ifdef EVENT_TRACE
unsigned i = 0;
#endif
while (sub != &mgr->esub_list) {
*next_sub = sub->next;
@ -138,7 +140,9 @@ static pj_status_t event_mgr_distribute_events(pjmedia_event_mgr *mgr,
}
}
sub = *next_sub;
#ifdef EVENT_TRACE
i++;
#endif
}
*next_sub = NULL;
@ -281,7 +285,9 @@ PJ_DEF(pj_status_t) pjmedia_event_subscribe( pjmedia_event_mgr *mgr,
void *epub)
{
esub *sub;
#ifdef EVENT_TRACE
unsigned i = 0;
#endif
PJ_ASSERT_RETURN(cb, PJ_EINVAL);
@ -303,7 +309,9 @@ PJ_DEF(pj_status_t) pjmedia_event_subscribe( pjmedia_event_mgr *mgr,
return PJ_SUCCESS;
}
sub = next;
#ifdef EVENT_TRACE
i++;
#endif
}
if (mgr->free_esub_list.next != &mgr->free_esub_list) {

View File

@ -168,7 +168,7 @@ pj_status_t pjmedia_format_id_to_CodecID(pjmedia_format_id fmt_id,
unsigned i;
for (i=0; i<PJ_ARRAY_SIZE(ffmpeg_codec_table); ++i) {
const struct ffmpeg_codec_table_t *t = &ffmpeg_codec_table[i];
if (t->id==fmt_id && t->codec_id != AV(PIX_FMT_NONE)) {
if (t->id==fmt_id && (int)t->codec_id != AV(PIX_FMT_NONE)) {
*codec_id = t->codec_id;
return PJ_SUCCESS;
}

View File

@ -156,7 +156,7 @@ PJ_DEF(pj_status_t) pjmedia_codec_g711_init(pjmedia_endpt *endpt)
pj_list_init(&g711_factory.codec_list);
/* Create pool */
g711_factory.pool = pjmedia_endpt_create_pool(endpt, "g711", 4000, 4000);
g711_factory.pool = pjmedia_endpt_create_pool(endpt, "g711", 1000, 4000);
if (!g711_factory.pool)
return PJ_ENOMEM;

View File

@ -90,6 +90,8 @@ PJ_DEF(pj_status_t) pjmedia_resample_create( pj_pool_t *pool,
* resample->xoff = large_filter ? 32 : 6;
*/
resample->xoff = res_GetXOFF(resample->factor, (char)large_filter);
if (resample->xoff * 2 >= samples_per_frame)
resample->xoff = samples_per_frame / 2 - 1;
} else {
resample->xoff = 1;
}

View File

@ -55,6 +55,7 @@ PJ_DEF(pj_status_t) pjmedia_rtcp_fb_build_nack(
/* Build RTCP-FB NACK header */
hdr = (pjmedia_rtcp_fb_common*)buf;
pj_memcpy(hdr, &session->rtcp_fb_com, sizeof(*hdr));
hdr->ssrc_src = pj_htonl(session->peer_ssrc);
hdr->rtcp_common.pt = RTCP_RTPFB;
hdr->rtcp_common.count = 1; /* FMT = 1 */
hdr->rtcp_common.length = pj_htons((pj_uint16_t)(len/4 - 1));
@ -97,6 +98,7 @@ PJ_DEF(pj_status_t) pjmedia_rtcp_fb_build_pli(
/* Build RTCP-FB PLI header */
hdr = (pjmedia_rtcp_fb_common*)buf;
pj_memcpy(hdr, &session->rtcp_fb_com, sizeof(*hdr));
hdr->ssrc_src = pj_htonl(session->peer_ssrc);
hdr->rtcp_common.pt = RTCP_PSFB;
hdr->rtcp_common.count = 1; /* FMT = 1 */
hdr->rtcp_common.length = pj_htons((pj_uint16_t)(len/4 - 1));
@ -131,6 +133,7 @@ PJ_DEF(pj_status_t) pjmedia_rtcp_fb_build_sli(
/* Build RTCP-FB SLI header */
hdr = (pjmedia_rtcp_fb_common*)buf;
pj_memcpy(hdr, &session->rtcp_fb_com, sizeof(*hdr));
hdr->ssrc_src = pj_htonl(session->peer_ssrc);
hdr->rtcp_common.pt = RTCP_PSFB;
hdr->rtcp_common.count = 2; /* FMT = 2 */
hdr->rtcp_common.length = pj_htons((pj_uint16_t)(len/4 - 1));
@ -157,7 +160,7 @@ PJ_DEF(pj_status_t) pjmedia_rtcp_fb_build_sli(
/*
* Build an RTCP-FB Slice Loss Indication (SLI) packet.
* Build an RTCP-FB Reference Picture Selection Indicationn (RPSI) packet.
*/
PJ_DEF(pj_status_t) pjmedia_rtcp_fb_build_rpsi(
pjmedia_rtcp_session *session,
@ -180,6 +183,7 @@ PJ_DEF(pj_status_t) pjmedia_rtcp_fb_build_rpsi(
/* Build RTCP-FB RPSI header */
hdr = (pjmedia_rtcp_fb_common*)buf;
pj_memcpy(hdr, &session->rtcp_fb_com, sizeof(*hdr));
hdr->ssrc_src = pj_htonl(session->peer_ssrc);
hdr->rtcp_common.pt = RTCP_PSFB;
hdr->rtcp_common.count = 3; /* FMT = 3 */
hdr->rtcp_common.length = pj_htons((pj_uint16_t)(len/4 - 1));

View File

@ -252,7 +252,7 @@ PJ_DEF(void) pjmedia_rtp_session_update2( pjmedia_rtp_session *ses,
ses->peer_ssrc = pj_ntohl(hdr->ssrc);
if (pj_ntohl(hdr->ssrc) != ses->peer_ssrc) {
seq_st.status.flag.badssrc = 1;
seq_st.status.flag.badssrc = -1;
if (!ses->has_peer_ssrc)
ses->peer_ssrc = pj_ntohl(hdr->ssrc);
}
@ -261,8 +261,8 @@ PJ_DEF(void) pjmedia_rtp_session_update2( pjmedia_rtp_session *ses,
if (check_pt && hdr->pt != ses->out_pt) {
if (p_seq_st) {
p_seq_st->status.value = seq_st.status.value;
p_seq_st->status.flag.bad = 1;
p_seq_st->status.flag.badpt = 1;
p_seq_st->status.flag.bad = -1;
p_seq_st->status.flag.badpt = -1;
}
return;
}
@ -323,8 +323,8 @@ void pjmedia_rtp_seq_update( pjmedia_rtp_seq_session *sess,
*/
if (sess->probation) {
st.status.flag.probation = 1;
st.status.flag.probation = -1;
if (seq == sess->max_seq+ 1) {
/* packet is in sequence */
st.diff = 1;
@ -337,11 +337,11 @@ void pjmedia_rtp_seq_update( pjmedia_rtp_seq_session *sess,
st.diff = 0;
st.status.flag.bad = 1;
st.status.flag.bad = -1;
if (seq == sess->max_seq)
st.status.flag.dup = 1;
st.status.flag.dup = -1;
else
st.status.flag.outorder = 1;
st.status.flag.outorder = -1;
sess->probation = MIN_SEQUENTIAL - 1;
sess->max_seq = seq;
@ -350,7 +350,7 @@ void pjmedia_rtp_seq_update( pjmedia_rtp_seq_session *sess,
} else if (udelta == 0) {
st.status.flag.dup = 1;
st.status.flag.dup = -1;
} else if (udelta < MAX_DROPOUT) {
/* in order, with permissible gap */
@ -371,22 +371,22 @@ void pjmedia_rtp_seq_update( pjmedia_rtp_seq_session *sess,
* (i.e., pretend this was the first packet).
*/
pjmedia_rtp_seq_restart(sess, seq);
st.status.flag.restart = 1;
st.status.flag.probation = 1;
st.status.flag.restart = -1;
st.status.flag.probation = -1;
st.diff = 1;
}
else {
sess->bad_seq = (seq + 1) & (RTP_SEQ_MOD-1);
st.status.flag.bad = 1;
st.status.flag.outorder = 1;
st.status.flag.bad = -1;
st.status.flag.outorder = -1;
}
} else {
/* old duplicate or reordered packet.
* Not necessarily bad packet (?)
*/
st.status.flag.outorder = 1;
st.status.flag.outorder = -1;
}
if (seq_status) {
seq_status->diff = st.diff;

View File

@ -796,7 +796,13 @@ static int print_media_desc(const pjmedia_sdp_media *m, char *buf, pj_size_t len
PJ_DEF(int) pjmedia_sdp_media_print(const pjmedia_sdp_media *media,
char *buf, pj_size_t size)
{
return print_media_desc(media, buf, size);
return print_media_desc(media, buf, size);
}
PJ_DEF(int) pjmedia_sdp_attr_print(const pjmedia_sdp_attr *attr,
char *buf, pj_size_t size)
{
return print_attr(attr, buf, size);
}
PJ_DEF(pjmedia_sdp_media*) pjmedia_sdp_media_clone(

View File

@ -1555,7 +1555,8 @@ PJ_DEF(pj_status_t) pjmedia_sdp_neg_cancel_offer(pjmedia_sdp_neg *neg)
neg->state == PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER,
PJMEDIA_SDPNEG_EINSTATE);
if (neg->state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER &&
// No longer needed after #3322.
if (0 && neg->state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER &&
neg->active_local_sdp)
{
/* Increment next version number. This happens if for example

View File

@ -64,11 +64,11 @@
#endif
#ifndef PJMEDIA_STREAM_SIZE
# define PJMEDIA_STREAM_SIZE 1000
# define PJMEDIA_STREAM_SIZE 4000
#endif
#ifndef PJMEDIA_STREAM_INC
# define PJMEDIA_STREAM_INC 1000
# define PJMEDIA_STREAM_INC 4000
#endif
/* Number of DTMF E bit transmissions */
@ -1962,7 +1962,7 @@ static void on_rx_rtp( pjmedia_tp_cb_param *param)
if (!check_pt && hdr->pt != channel->rtp.out_pt &&
hdr->pt != stream->rx_event_pt)
{
seq_st.status.flag.badpt = 1;
seq_st.status.flag.badpt = -1;
}
#endif
if (seq_st.status.value) {

View File

@ -85,7 +85,7 @@ PJ_DEF(pj_status_t) pjmedia_stream_info_parse_fmtp( pj_pool_t *pool,
/* Get token */
start = p;
while (p < p_end && *p != ';' && *p != '=') ++p;
while (p < p_end && *p != ';') ++p;
end = p - 1;
/* Right trim */
@ -98,20 +98,41 @@ PJ_DEF(pj_status_t) pjmedia_stream_info_parse_fmtp( pj_pool_t *pool,
/* Store token */
if (end > start) {
char *p2 = start;
if (pool) {
token = (char*)pj_pool_alloc(pool, end - start);
pj_memcpy(token, start, end - start);
} else {
token = start;
}
if (*p == '=')
/* Got param name */
pj_strset(&fmtp->param[fmtp->cnt].name, token, end - start);
else
/* Got param value */
pj_strset(&fmtp->param[fmtp->cnt++].val, token, end - start);
} else if (*p != '=') {
++fmtp->cnt;
/* Check if it contains '=' */
while (p2 < end && *p2 != '=') ++p2;
if (p2 < end) {
char *p3;
pj_assert (*p2 == '=');
/* Trim whitespace before '=' */
p3 = p2 - 1;
while (p3 >= start && (*p3 == ' ' || *p3 == '\t')) --p3;
/* '=' found, get param name */
pj_strset(&fmtp->param[fmtp->cnt].name, token, p3 - start + 1);
/* Trim whitespace after '=' */
p3 = p2 + 1;
while (p3 < end && (*p3 == ' ' || *p3 == '\t')) ++p3;
/* Advance token to first char after '=' */
token = token + (p3 - start);
start = p3;
}
/* Got param value */
pj_strset(&fmtp->param[fmtp->cnt++].val, token, end - start);
}
/* Next */

View File

@ -2603,6 +2603,8 @@ static void ice_on_rx_data(pj_ice_strans *ice_st, unsigned comp_id,
sizeof(addr_text), 3)));
}
}
#else
PJ_UNUSED_ARG(rem_switch);
#endif
} else if (comp_id==2 && tp_ice->rtcp_cb) {

View File

@ -56,7 +56,7 @@ PJ_DEF(const char*) pjmedia_type_name(pjmedia_type t)
PJ_DEF(pjmedia_type) pjmedia_get_type(const pj_str_t *name)
{
int i;
for (i = 0; i < PJ_ARRAY_SIZE(media_type_names); ++i) {
for (i = 0; i < (int)PJ_ARRAY_SIZE(media_type_names); ++i) {
if (pj_stricmp2(name, media_type_names[i].name)==0)
return media_type_names[i].type;
}

View File

@ -98,10 +98,11 @@ typedef struct vconf_port
pj_timestamp ts_next; /**< Time for next put/get_frame(). */
void *get_buf; /**< Buffer for get_frame(). */
pj_size_t get_buf_size; /**< Buffer size for get_frame(). */
pj_size_t get_frm_size; /**< Frame size for get_frame(). */
pj_bool_t got_frame; /**< Last get_frame() got frame? */
void *put_buf; /**< Buffer for put_frame(). */
pj_size_t put_buf_size; /**< Buffer size for put_frame(). */
pj_size_t put_frm_size; /**< Frame size for put_frame(). */
unsigned listener_cnt; /**< Number of listeners. */
unsigned *listener_slots;/**< Array of listeners (for info). */
@ -482,7 +483,7 @@ PJ_DEF(pj_status_t) pjmedia_vid_conf_add_port( pjmedia_vid_conf *vid_conf,
goto on_error;
}
if (port->put_frame) {
cport->put_buf_size = vafp.framebytes;
cport->put_buf_size = cport->put_frm_size = vafp.framebytes;
cport->put_buf = pj_pool_zalloc(cport->pool, cport->put_buf_size);
/* Initialize sink buffer with black color. */
@ -496,7 +497,7 @@ PJ_DEF(pj_status_t) pjmedia_vid_conf_add_port( pjmedia_vid_conf *vid_conf,
}
}
if (port->get_frame) {
cport->get_buf_size = vafp.framebytes;
cport->get_buf_size = cport->get_frm_size = vafp.framebytes;
cport->get_buf = pj_pool_zalloc(cport->pool, cport->get_buf_size);
/* Initialize source buffer with black color. */
@ -1107,7 +1108,7 @@ static void on_clock_tick(const pj_timestamp *now, void *user_data)
frame.type = PJMEDIA_FRAME_TYPE_VIDEO;
frame.timestamp = *now;
frame.buf = src->get_buf;
frame.size = src->get_buf_size;
frame.size = src->get_frm_size;
status = pjmedia_port_get_frame(src->port, &frame);
if (status != PJ_SUCCESS) {
PJ_PERROR(5, (THIS_FILE, status,
@ -1115,7 +1116,7 @@ static void on_clock_tick(const pj_timestamp *now, void *user_data)
src->idx, src->port->info.name.ptr));
src->got_frame = PJ_FALSE;
} else {
src->got_frame = (frame.size == src->get_buf_size);
src->got_frame = (frame.size == src->get_frm_size);
/* There is a possibility that the source port's format has
* changed, but we haven't received the event yet.
@ -1163,7 +1164,7 @@ static void on_clock_tick(const pj_timestamp *now, void *user_data)
frame.timestamp = *now;
if (frame_rendered) {
frame.buf = sink->put_buf;
frame.size = sink->put_buf_size;
frame.size = sink->put_frm_size;
}
status = pjmedia_port_put_frame(sink->port, &frame);
if (frame_rendered && status != PJ_SUCCESS) {
@ -1449,19 +1450,19 @@ static pj_status_t render_src_frame(vconf_port *src, vconf_port *sink,
if (sink->transmitter_cnt == 1 && (!rs || !rs->converter)) {
/* The only transmitter and no conversion needed */
if (src->get_buf_size != sink->put_buf_size)
if (src->get_frm_size != sink->put_frm_size)
return PJMEDIA_EVID_BADFORMAT;
pj_memcpy(sink->put_buf, src->get_buf, src->get_buf_size);
pj_memcpy(sink->put_buf, src->get_buf, src->get_frm_size);
} else if (rs && rs->converter) {
pjmedia_frame src_frame, dst_frame;
pj_bzero(&src_frame, sizeof(src_frame));
src_frame.buf = src->get_buf;
src_frame.size = src->get_buf_size;
src_frame.size = src->get_frm_size;
pj_bzero(&dst_frame, sizeof(dst_frame));
dst_frame.buf = sink->put_buf;
dst_frame.size = sink->put_buf_size;
dst_frame.size = sink->put_frm_size;
status = pjmedia_converter_convert2(rs->converter,
&src_frame,
@ -1586,9 +1587,11 @@ static void op_update_port(pjmedia_vid_conf *vid_conf,
return;
}
if (cport->port->put_frame) {
if (cport->put_buf_size < vafp.framebytes)
if (cport->put_buf_size < vafp.framebytes) {
cport->put_buf = pj_pool_zalloc(cport->pool, vafp.framebytes);
cport->put_buf_size = vafp.framebytes;
cport->put_buf_size = vafp.framebytes;
}
cport->put_frm_size = vafp.framebytes;
/* Initialize sink buffer with black color. */
status = pjmedia_video_format_fill_black(&cport->port->info.fmt,
@ -1601,9 +1604,11 @@ static void op_update_port(pjmedia_vid_conf *vid_conf,
}
}
if (cport->port->get_frame) {
if (cport->get_buf_size < vafp.framebytes)
if (cport->get_buf_size < vafp.framebytes) {
cport->get_buf = pj_pool_zalloc(cport->pool, vafp.framebytes);
cport->get_buf_size = vafp.framebytes;
cport->get_buf_size = vafp.framebytes;
}
cport->get_frm_size = vafp.framebytes;
/* When source port is updated, buffer should contain a new image
* with the correct latest format already, so don't fill black

View File

@ -97,6 +97,7 @@ struct pjmedia_vid_port
pjmedia_clock *clock;
pjmedia_clock_src clocksrc;
pjmedia_event fmt_event;
struct sync_clock_src_t
{
@ -353,7 +354,7 @@ static struct fmt_prop find_closest_fmt(pj_uint32_t req_fmt_id,
/* Fill the nearest width list. */
if (diff_width1 <= diff_width2) {
int k = 0;
unsigned k = 0;
while (((k < PJ_ARRAY_SIZE(nearest_width)) &&
(!((vfd->size.w == nearest_width[k].w) &&
(vfd->size.h == nearest_width[k].h))))) {
@ -740,7 +741,7 @@ pjmedia_vid_port_get_clock_src( pjmedia_vid_port *vid_port )
return &vid_port->clocksrc;
}
PJ_DECL(pj_status_t)
PJ_DEF(pj_status_t)
pjmedia_vid_port_set_clock_src( pjmedia_vid_port *vid_port,
pjmedia_clock_src *clocksrc)
{
@ -967,6 +968,20 @@ static pj_status_t client_port_event_cb(pjmedia_event *event,
pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data;
if (event->type == PJMEDIA_EVENT_FMT_CHANGED) {
/* Copy the event to avoid race condition with put_frame() */
pj_memcpy(&vp->fmt_event, event, sizeof(*event));
}
/* Republish the event, post the event to the event manager
* to avoid deadlock if vidport is trying to stop the clock.
*/
return pjmedia_event_publish(NULL, vp, event,
PJMEDIA_EVENT_PUBLISH_POST_EVENT);
}
static pj_status_t handle_format_change(pjmedia_vid_port *vp)
{
if (vp->fmt_event.type != PJMEDIA_EVENT_NONE) {
const pjmedia_video_format_detail *vfd;
const pjmedia_video_format_detail *vfd_cur;
pjmedia_vid_dev_param vid_param;
@ -981,7 +996,7 @@ static pj_status_t client_port_event_cb(pjmedia_event *event,
/* Retrieve the new video format detail */
vfd = pjmedia_format_get_video_format_detail(
&event->data.fmt_changed.new_fmt, PJ_TRUE);
&vp->fmt_event.data.fmt_changed.new_fmt, PJ_TRUE);
if (!vfd || !vfd->fps.num || !vfd->fps.denum)
return PJMEDIA_EVID_BADFORMAT;
@ -1003,7 +1018,7 @@ static pj_status_t client_port_event_cb(pjmedia_event *event,
clock_param.clock_rate = vid_param.clock_rate;
pjmedia_clock_modify(vp->clock, &clock_param);
return pjmedia_event_publish(NULL, vp, event,
return pjmedia_event_publish(NULL, vp, &vp->fmt_event,
PJMEDIA_EVENT_PUBLISH_POST_EVENT);
}
}
@ -1019,10 +1034,10 @@ static pj_status_t client_port_event_cb(pjmedia_event *event,
/* Change the destination format to the new format */
pjmedia_format_copy(&vp->conv.conv_param.src,
&event->data.fmt_changed.new_fmt);
&vp->fmt_event.data.fmt_changed.new_fmt);
/* Only copy the size here */
vp->conv.conv_param.dst.det.vid.size =
event->data.fmt_changed.new_fmt.det.vid.size;
vp->fmt_event.data.fmt_changed.new_fmt.det.vid.size;
status = create_converter(vp);
if (status != PJ_SUCCESS) {
@ -1080,15 +1095,13 @@ static pj_status_t client_port_event_cb(pjmedia_event *event,
/* Update passive port info from the video stream */
if (vp->role == ROLE_PASSIVE) {
pjmedia_format_copy(&vp->pasv_port->base.info.fmt,
&event->data.fmt_changed.new_fmt);
&vp->fmt_event.data.fmt_changed.new_fmt);
}
pj_bzero(&vp->fmt_event, sizeof(pjmedia_event));
}
/* Republish the event, post the event to the event manager
* to avoid deadlock if vidport is trying to stop the clock.
*/
return pjmedia_event_publish(NULL, vp, event,
PJMEDIA_EVENT_PUBLISH_POST_EVENT);
return PJ_SUCCESS;
}
static pj_status_t convert_frame(pjmedia_vid_port *vp,
@ -1228,7 +1241,9 @@ static pj_status_t vidstream_render_cb(pjmedia_vid_dev_stream *stream,
{
pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data;
pj_status_t status = PJ_SUCCESS;
handle_format_change(vp);
pj_bzero(frame, sizeof(pjmedia_frame));
if (vp->role==ROLE_ACTIVE) {
unsigned frame_ts = vp->clocksrc.clock_rate / 1000 *
@ -1367,6 +1382,8 @@ static pj_status_t vid_pasv_port_put_frame(struct pjmedia_port *this_port,
if (vp->pasv_port->is_destroying)
return PJ_EGONE;
handle_format_change(vp);
if (vp->stream_role==ROLE_PASSIVE) {
/* We are passive and the stream is passive.
* The encoding counterpart is in vid_pasv_port_get_frame().

View File

@ -60,11 +60,11 @@
#endif
#ifndef PJMEDIA_VSTREAM_SIZE
# define PJMEDIA_VSTREAM_SIZE 1000
# define PJMEDIA_VSTREAM_SIZE 16000
#endif
#ifndef PJMEDIA_VSTREAM_INC
# define PJMEDIA_VSTREAM_INC 1000
# define PJMEDIA_VSTREAM_INC 4000
#endif
/* Due to network MTU limitation, a picture bitstream may be splitted into
@ -816,7 +816,7 @@ static void on_rx_rtp( pjmedia_tp_cb_param *param)
PJMEDIA_VID_STREAM_CHECK_RTP_PT);
#if !PJMEDIA_VID_STREAM_CHECK_RTP_PT
if (hdr->pt != channel->rtp.out_pt) {
seq_st.status.flag.badpt = 1;
seq_st.status.flag.badpt = -1;
}
#endif
if (seq_st.status.value) {

View File

@ -87,7 +87,7 @@ PJ_DEF(const char*) pjmedia_vid_dev_cap_name(pjmedia_vid_dev_cap cap,
if (p_desc==NULL) p_desc = &desc;
for (i=0; i<PJ_ARRAY_SIZE(cap_infos); ++i) {
if ((1 << i)==cap)
if ((1 << i)==(int)cap)
break;
}

View File

@ -224,7 +224,7 @@ PJ_DEF(pj_status_t) pjmedia_wav_player_port_create( pj_pool_t *pool,
fport->fsize = pj_file_size(filename);
/* Size must be more than WAVE header size */
if (fport->fsize <= sizeof(pjmedia_wave_hdr)) {
if (fport->fsize <= (pj_off_t)sizeof(pjmedia_wave_hdr)) {
return PJMEDIA_ENOTVALIDWAVE;
}

View File

@ -428,9 +428,9 @@ PJ_DEF(pj_status_t) pjmedia_wav_playlist_create(pj_pool_t *pool,
/* Get the file size. */
fport->current_file = index;
fport->fsize_list[index] = pj_file_size(filename);
/* Size must be more than WAVE header size */
if (fport->fsize_list[index] <= sizeof(pjmedia_wave_hdr)) {
if (fport->fsize_list[index] <= (pj_off_t)sizeof(pjmedia_wave_hdr)) {
status = PJMEDIA_ENOTVALIDWAVE;
goto on_error;
}

View File

@ -104,7 +104,7 @@ static pj_bool_t parse_test_headers(char *line, test_param_t *param,
static pj_bool_t process_test_data(char data, pjmedia_jbuf *jb,
pj_uint16_t *seq, pj_uint16_t *last_seq)
{
char frame[1];
char frame[1] = {0};
char f_type;
pj_bool_t print_state = PJ_TRUE;
pj_bool_t data_eos = PJ_FALSE;
@ -183,7 +183,7 @@ int jbuf_main(void)
/* If that fails, try to open test data file in specified search paths */
if (input == NULL) {
char input_path[PJ_MAXPATH];
int i;
unsigned i;
for (i = 0; !input && i < PJ_ARRAY_SIZE(input_search_path); ++i) {
pj_ansi_snprintf(input_path, PJ_MAXPATH, "%s/%s",

View File

@ -1717,6 +1717,9 @@ static pjmedia_port* create_stream( pj_pool_t *pool,
unsigned flags,
struct test_entry *te)
{
PJ_UNUSED_ARG(srtp_enabled);
PJ_UNUSED_ARG(srtp_80);
PJ_UNUSED_ARG(srtp_auth);
struct stream_port *sp;
pj_str_t codec_id;
pjmedia_port *port;

View File

@ -149,7 +149,7 @@ static const char* dump_codec_info(const pjmedia_vid_codec_info *info)
char *p = str;
/* Raw format ids */
for (i=0; (i<info->dec_fmt_id_cnt) && (p-str+5<sizeof(str)); ++i) {
for (i=0; (i<info->dec_fmt_id_cnt) && (p-str+5<(int)sizeof(str)); ++i) {
pj_memcpy(p, &info->dec_fmt_id[i], 4);
p += 4;
*p++ = ' ';

View File

@ -204,7 +204,7 @@ static int vidport_test(void)
continue;
/* Check various formats to test format conversion. */
for (l = 0; l < PJ_ARRAY_SIZE(test_fmts); ++l) {
for (l = 0; l < (int)PJ_ARRAY_SIZE(test_fmts); ++l) {
pjmedia_format fmt;
PJ_LOG(3,(THIS_FILE,

View File

@ -582,6 +582,26 @@ PJ_DECL(pj_status_t) pj_turn_session_create(const pj_stun_config *cfg,
PJ_DECL(pj_status_t) pj_turn_session_shutdown(pj_turn_session *sess);
/**
* Shutdown TURN client session. This will gracefully deallocate and
* destroy the client session.
*
* @param sess The TURN client session.
* @param last_err Optional error code to be set to the session,
* which would be returned back in the \a info
* parameter of #pj_turn_session_get_info(). If
* this argument value is PJ_SUCCESS, the error
* code will not be set. If the session already
* has an error code set, this function will not
* overwrite that error code either.
*
* @return PJ_SUCCESS if the operation has been successful,
* or the appropriate error code on failure.
*/
PJ_DECL(pj_status_t) pj_turn_session_shutdown2(pj_turn_session *sess,
pj_status_t last_err);
/**
* Forcefully destroy the TURN session. This will destroy the session
* immediately. If there is an active allocation, the server will not

View File

@ -249,7 +249,7 @@ static void turn_on_state(pj_turn_sock *turn_sock,
sess->result.state_called |= (1 << new_state);
if (new_state >= sess->destroy_on_state && !sess->destroy_called) {
if ((int)new_state >= sess->destroy_on_state && !sess->destroy_called) {
sess->destroy_called = PJ_TRUE;
pj_turn_sock_destroy(turn_sock);
}
@ -495,8 +495,8 @@ static int destroy_test(pj_stun_config *stun_cfg,
poll_events(stun_cfg, 1, PJ_FALSE);
pj_turn_sock_get_info(sess->turn_sock, &info);
if (info.state >= target_state) {
if ((int)info.state >= target_state) {
pj_turn_sock_destroy(sess->turn_sock);
break;
}

View File

@ -1937,7 +1937,7 @@ on_return:
return status;
if (call_cb) {
on_data_sent(ice_st, (status == PJ_SUCCESS? data_len: -status));
on_data_sent(ice_st, (status == PJ_SUCCESS? (pj_ssize_t)data_len: -status));
} else {
check_pending_send(ice_st);
}

View File

@ -551,7 +551,7 @@ PJ_DEF(void*) pj_stun_sock_get_user_data(pj_stun_sock *stun_sock)
}
/* Get group lock */
PJ_DECL(pj_grp_lock_t *) pj_stun_sock_get_grp_lock(pj_stun_sock *stun_sock)
PJ_DEF(pj_grp_lock_t *) pj_stun_sock_get_grp_lock(pj_stun_sock *stun_sock)
{
PJ_ASSERT_RETURN(stun_sock, NULL);
return stun_sock->grp_lock;

View File

@ -448,11 +448,20 @@ static void sess_shutdown(pj_turn_session *sess,
* Public API to destroy TURN client session.
*/
PJ_DEF(pj_status_t) pj_turn_session_shutdown(pj_turn_session *sess)
{
return pj_turn_session_shutdown2(sess, PJ_SUCCESS);
}
PJ_DEF(pj_status_t) pj_turn_session_shutdown2(pj_turn_session *sess,
pj_status_t last_err)
{
PJ_ASSERT_RETURN(sess, PJ_EINVAL);
pj_grp_lock_acquire(sess->grp_lock);
if (last_err != PJ_SUCCESS && sess->last_status == PJ_SUCCESS)
sess->last_status = last_err;
sess_shutdown(sess, PJ_SUCCESS);
pj_grp_lock_release(sess->grp_lock);

View File

@ -416,7 +416,8 @@ static void destroy(pj_turn_sock *turn_sock)
pj_grp_lock_release(turn_sock->grp_lock);
}
PJ_DEF(void) pj_turn_sock_destroy(pj_turn_sock *turn_sock)
static void turn_sock_destroy(pj_turn_sock *turn_sock,
pj_status_t last_err)
{
pj_grp_lock_acquire(turn_sock->grp_lock);
if (turn_sock->is_destroying) {
@ -425,7 +426,7 @@ PJ_DEF(void) pj_turn_sock_destroy(pj_turn_sock *turn_sock)
}
if (turn_sock->sess) {
pj_turn_session_shutdown(turn_sock->sess);
pj_turn_session_shutdown2(turn_sock->sess, last_err);
/* This will ultimately call our state callback, and when
* session state is DESTROYING we will schedule a timer to
* destroy ourselves.
@ -437,6 +438,10 @@ PJ_DEF(void) pj_turn_sock_destroy(pj_turn_sock *turn_sock)
pj_grp_lock_release(turn_sock->grp_lock);
}
PJ_DEF(void) pj_turn_sock_destroy(pj_turn_sock *turn_sock)
{
turn_sock_destroy(turn_sock, PJ_SUCCESS);
}
/* Timer callback */
static void timer_cb(pj_timer_heap_t *th, pj_timer_entry *e)
@ -1238,7 +1243,7 @@ static void turn_on_state(pj_turn_session *sess,
/* Init socket */
status = pj_sock_socket(turn_sock->af, sock_type, 0, &sock);
if (status != PJ_SUCCESS) {
pj_turn_sock_destroy(turn_sock);
turn_sock_destroy(turn_sock, status);
return;
}
@ -1248,7 +1253,7 @@ static void turn_on_state(pj_turn_session *sess,
max_bind_retry);
if (status != PJ_SUCCESS) {
pj_sock_close(sock);
pj_turn_sock_destroy(turn_sock);
turn_sock_destroy(turn_sock, status);
return;
}
/* Apply QoS, if specified */
@ -1259,7 +1264,7 @@ static void turn_on_state(pj_turn_session *sess,
if (status != PJ_SUCCESS && !turn_sock->setting.qos_ignore_error)
{
pj_sock_close(sock);
pj_turn_sock_destroy(turn_sock);
turn_sock_destroy(turn_sock, status);
return;
}
@ -1375,7 +1380,7 @@ static void turn_on_state(pj_turn_session *sess,
&turn_sock->cert);
}
if (status != PJ_SUCCESS) {
pj_turn_sock_destroy(turn_sock);
turn_sock_destroy(turn_sock, status);
return;
}
if (turn_sock->cert) {
@ -1386,7 +1391,7 @@ static void turn_on_state(pj_turn_session *sess,
&turn_sock->ssl_sock);
if (status != PJ_SUCCESS) {
pj_turn_sock_destroy(turn_sock);
turn_sock_destroy(turn_sock, status);
return;
}
@ -1403,7 +1408,7 @@ static void turn_on_state(pj_turn_session *sess,
#endif
if (status != PJ_SUCCESS) {
pj_turn_sock_destroy(turn_sock);
turn_sock_destroy(turn_sock, status);
return;
}
@ -1445,7 +1450,7 @@ static void turn_on_state(pj_turn_session *sess,
"Failed to connect to %s",
pj_sockaddr_print(&info.server, addrtxt,
sizeof(addrtxt), 3)));
pj_turn_sock_destroy(turn_sock);
turn_sock_destroy(turn_sock, status);
return;
}

View File

@ -677,10 +677,10 @@ PJ_DEF(pj_status_t) pj_upnp_deinit(void)
/* Send request to add port mapping. */
PJ_DECL(pj_status_t)pj_upnp_add_port_mapping(unsigned sock_cnt,
const pj_sock_t sock[],
unsigned ext_port[],
pj_sockaddr mapped_addr[])
PJ_DEF(pj_status_t)pj_upnp_add_port_mapping(unsigned sock_cnt,
const pj_sock_t sock[],
unsigned ext_port[],
pj_sockaddr mapped_addr[])
{
unsigned max_wait = 20;
unsigned i;

View File

@ -318,6 +318,8 @@ static void turn_on_rx_data(pj_turn_sock *relay,
const pj_sockaddr_t *peer_addr,
unsigned addr_len)
{
PJ_UNUSED_ARG(relay);
PJ_UNUSED_ARG(addr_len);
char addrinfo[80];
pj_sockaddr_print(peer_addr, addrinfo, sizeof(addrinfo), 3);
@ -386,6 +388,7 @@ static pj_bool_t stun_sock_on_rx_data(pj_stun_sock *stun_sock,
const pj_sockaddr_t *src_addr,
unsigned addr_len)
{
PJ_UNUSED_ARG(addr_len);
struct peer *peer = (struct peer*) pj_stun_sock_get_user_data(stun_sock);
char straddr[PJ_INET6_ADDRSTRLEN+10];

View File

@ -460,7 +460,7 @@ static void destroy_allocation(pj_turn_allocation *alloc)
}
PJ_DECL(void) pj_turn_allocation_destroy(pj_turn_allocation *alloc)
PJ_DEF(void) pj_turn_allocation_destroy(pj_turn_allocation *alloc)
{
destroy_allocation(alloc);
}

View File

@ -354,37 +354,30 @@ void displayWindow(pjsua_vid_win_id wid)
for (;i < last; ++i) {
pjsua_vid_win_info wi;
if (pjsua_vid_win_get_info(i, &wi) == PJ_SUCCESS) {
if (pjsua_vid_win_get_info(i, &wi) == PJ_SUCCESS &&
wi.hwnd.info.ios.window)
{
dispatch_async(dispatch_get_main_queue(), ^{
UIView *parent = app.viewController.view;
UIView *view = (__bridge UIView *)wi.hwnd.info.ios.window;
if (view) {
/* Add the video window as subview */
if (![view isDescendantOfView:parent])
[parent addSubview:view];
if (!wi.is_native) {
/* Resize it to fit width */
view.bounds = CGRectMake(0, 0, parent.bounds.size.width,
(parent.bounds.size.height *
1.0*parent.bounds.size.width/
view.bounds.size.width));
/* Center it horizontally */
view.center = CGPointMake(parent.bounds.size.width/2.0,
view.bounds.size.height/2.0);
} else {
/* Preview window, move it to the bottom */
view.center = CGPointMake(parent.bounds.size.width/2.0,
parent.bounds.size.height-
view.bounds.size.height/2.0);
}
if (![view isDescendantOfView:parent])
[parent addSubview:view];
if (!wi.is_native) {
/* Video window */
view.contentMode = UIViewContentModeScaleAspectFit;
view.center = parent.center;
view.frame = parent.bounds;
} else {
/* Preview window */
view.contentMode = UIViewContentModeBottomLeft;
view.frame = CGRectMake(0, parent.frame.size.height - view.frame.size.height,
view.frame.size.width, view.frame.size.height);
}
});
}
}
#endif
}

View File

@ -1135,7 +1135,6 @@ static void simple_registrar(pjsip_rx_data *rdata)
pjsip_tx_data *tdata;
const pjsip_expires_hdr *exp;
const pjsip_hdr *h;
unsigned cnt = 0;
pjsip_generic_string_hdr *srv;
pj_status_t status;
@ -1165,7 +1164,6 @@ static void simple_registrar(pjsip_rx_data *rdata)
tdata->pool, h);
nc->expires = e;
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)nc);
++cnt;
}
}
h = h->next;

1
pjsip-apps/src/rust/demo/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target

378
pjsip-apps/src/rust/demo/Cargo.lock generated Normal file
View File

@ -0,0 +1,378 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
dependencies = [
"memchr",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bindgen"
version = "0.60.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6"
dependencies = [
"bitflags",
"cexpr",
"clang-sys",
"clap",
"env_logger",
"lazy_static",
"lazycell",
"log",
"peeking_take_while",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
"which",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clang-sys"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "clap"
version = "3.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5"
dependencies = [
"atty",
"bitflags",
"clap_lex",
"indexmap",
"strsim",
"termcolor",
"textwrap",
]
[[package]]
name = "clap_lex"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
dependencies = [
"os_str_bytes",
]
[[package]]
name = "demo"
version = "0.1.0"
dependencies = [
"pjsua",
]
[[package]]
name = "either"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
[[package]]
name = "env_logger"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "indexmap"
version = "1.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "libloading"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
dependencies = [
"cfg-if",
"winapi",
]
[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
name = "once_cell"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
[[package]]
name = "os_str_bytes"
version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "pjsua"
version = "0.1.0"
dependencies = [
"bindgen",
"pkg-config",
]
[[package]]
name = "pkg-config"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
[[package]]
name = "proc-macro2"
version = "1.0.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "shlex"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "termcolor"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d"
[[package]]
name = "unicode-ident"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
[[package]]
name = "which"
version = "4.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269"
dependencies = [
"either",
"libc",
"once_cell",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@ -0,0 +1,9 @@
[package]
name = "demo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
pjsua = { path = "../pjsua" }

View File

@ -0,0 +1,86 @@
use pjsua::*;
use std::{ffi::CString, mem::MaybeUninit, os::raw::c_int, ptr};
const CSTRING_NEW_FAILED: &str = "CString::new failed!";
const SIP_DOMAIN: &str = "pjsip.org";
const SIP_USER: &str = "username";
const SIP_PASSWD: &str = "secret";
/* Callback called by the library upon receiving incoming call */
pub unsafe extern "C" fn on_incoming_call(
_acc_id: pjsua_acc_id,
call_id: pjsua_call_id,
_rdata: *mut pjsip_rx_data,
) {
let ci = MaybeUninit::<pjsua_call_info>::uninit().as_mut_ptr();
pjsua_call_get_info(call_id, ci);
/* Automatically answer incoming calls with 200/OK */
pjsua_call_answer(call_id, 200, ptr::null(), ptr::null());
}
fn main() {
unsafe {
let mut _status = pjsua_create();
let mut cfg = MaybeUninit::<pjsua_config>::uninit().as_mut_ptr();
pjsua_config_default(cfg);
(*cfg).cb.on_incoming_call = Some(on_incoming_call);
let log_cfg = MaybeUninit::<pjsua_logging_config>::uninit().as_mut_ptr();
pjsua_logging_config_default(log_cfg);
_status = pjsua_init(cfg, log_cfg, ptr::null());
let mut t_cfg = MaybeUninit::<pjsua_transport_config>::uninit().as_mut_ptr();
pjsua_transport_config_default(t_cfg);
(*t_cfg).port = 0;
let mut transport_id = 0 as c_int;
_status = pjsua_transport_create(
pjsip_transport_type_e_PJSIP_TRANSPORT_UDP,
t_cfg,
&mut transport_id,
);
_status = pjsua_start();
let mut acc_cfg = MaybeUninit::<pjsua_acc_config>::uninit().as_mut_ptr();
pjsua_acc_config_default(acc_cfg);
let id =
CString::new(&*format!("sip:{}@{}", SIP_USER, SIP_DOMAIN)).expect(CSTRING_NEW_FAILED);
(*acc_cfg).id = pj_str(id.as_ptr() as *mut i8);
let uri = CString::new(&*format!("sip:{}", SIP_DOMAIN)).expect(CSTRING_NEW_FAILED);
(*acc_cfg).reg_uri = pj_str(uri.as_ptr() as *mut i8);
(*acc_cfg).cred_count = 1;
let sip_domain = CString::new(SIP_DOMAIN).expect(CSTRING_NEW_FAILED);
(*acc_cfg).cred_info[0].realm = pj_str(sip_domain.as_ptr() as *mut i8);
let digest = CString::new("digest").expect(CSTRING_NEW_FAILED);
(*acc_cfg).cred_info[0].scheme = pj_str(digest.as_ptr() as *mut i8);
let username = CString::new(SIP_USER).expect(CSTRING_NEW_FAILED);
(*acc_cfg).cred_info[0].username = pj_str(username.as_ptr() as *mut i8);
(*acc_cfg).cred_info[0].data_type =
pjsip_cred_data_type_PJSIP_CRED_DATA_PLAIN_PASSWD as i32;
let password = CString::new(SIP_PASSWD).expect(CSTRING_NEW_FAILED);
(*acc_cfg).cred_info[0].data = pj_str(password.as_ptr() as *mut i8);
let acc_id = MaybeUninit::<pjsua_acc_id>::uninit().as_mut_ptr();
_status = pjsua_acc_add(acc_cfg, pj_constants__PJ_TRUE as i32, acc_id);
pj_thread_sleep(10000);
/* Destroy pjsua */
pjsua_destroy();
}
}

2
pjsip-apps/src/rust/pjsua/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target
Cargo.lock

View File

@ -0,0 +1,11 @@
[package]
name = "pjsua"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[build-dependencies]
bindgen = "0.60.1"
pkg-config = "0.3.26"

Some files were not shown because too many files have changed in this diff Show More