Skip to content

Commit

Permalink
Fix build errors & warnings on MSVC2005 (#3722)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanangizz authored Oct 2, 2023
1 parent e43a6da commit b8fbdb2
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 33 deletions.
9 changes: 7 additions & 2 deletions pjlib/src/pj/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ PJ_DEF(long) pj_strtol(const pj_str_t *str)
uval = pj_strtoul(str);

if (is_negative)
val = uval > PJ_MAXLONG ? PJ_MINLONG : -uval;
val = uval > PJ_MAXLONG ? PJ_MINLONG : -(long)uval;
else
val = uval > PJ_MAXLONG ? PJ_MAXLONG : uval;

Expand Down Expand Up @@ -310,7 +310,12 @@ PJ_DEF(pj_status_t) pj_strtol2(const pj_str_t *str, long *value)
return PJ_ETOOSMALL;
}

*value = is_negative ? -retval : retval;
if (is_negative && retval == PJ_MAXLONG + 1UL) {
*value = PJ_MINLONG;
return PJ_SUCCESS;
}

*value = is_negative ? -(long)retval : retval;

return PJ_SUCCESS;
}
Expand Down
10 changes: 5 additions & 5 deletions pjlib/src/pjlib-test/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static int simple_sleep_test(void)
static int sleep_duration_test(void)
{
const unsigned MAX_SLIP = param_ci_mode? 200 : 20;
unsigned duration[] = { 2000, 1000, 500, 200, 100 };
long duration[] = { 2000, 1000, 500, 200, 100 };
unsigned i;
unsigned avg_diff, max_diff;
pj_status_t rc;
Expand All @@ -103,7 +103,7 @@ static int sleep_duration_test(void)
/* Test pj_thread_sleep() and pj_gettimeofday() */
for (i=0, avg_diff=0, max_diff=0; i<PJ_ARRAY_SIZE(duration); ++i) {
pj_time_val start, stop;
pj_uint32_t msec;
long msec;
unsigned diff;

/* Mark start of test. */
Expand Down Expand Up @@ -139,7 +139,7 @@ static int sleep_duration_test(void)
max_diff = diff>max_diff ? diff : max_diff;
if (diff > MAX_SLIP) {
PJ_LOG(3,(THIS_FILE,
"...error: slept for %d ms instead of %d ms "
"...error: slept for %ld ms instead of %ld ms "
"(outside %d msec tolerance)",
msec, duration[i], MAX_SLIP));
}
Expand All @@ -153,7 +153,7 @@ static int sleep_duration_test(void)
for (i=0, avg_diff=0, max_diff=0; i<PJ_ARRAY_SIZE(duration); ++i) {
pj_time_val t1, t2;
pj_timestamp start, stop;
pj_uint32_t msec;
long msec;
unsigned diff;

pj_thread_sleep(0);
Expand Down Expand Up @@ -196,7 +196,7 @@ static int sleep_duration_test(void)
max_diff = diff>max_diff ? diff : max_diff;
if (diff > MAX_SLIP) {
PJ_LOG(3,(THIS_FILE,
"...error: slept for %d ms instead of %d ms "
"...error: slept for %ld ms instead of %ld ms "
"(outside %d msec tolerance)",
msec, duration[i], MAX_SLIP));
PJ_TIME_VAL_SUB(t2, t1);
Expand Down
7 changes: 4 additions & 3 deletions pjmedia/src/pjmedia/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ PJ_DEF(pj_status_t) pjmedia_codec_mgr_unregister_factory(
pj_bool_t found;
pj_str_t codec_str = pj_str(mgr->codec_desc[i].id);

codec_idx = pjmedia_codec_mgr_find_codec(mgr->dyn_codecs,
codec_idx = (pj_int8_t)pjmedia_codec_mgr_find_codec(
mgr->dyn_codecs,
mgr->dyn_codecs_cnt,
&codec_str,
&found);
Expand Down Expand Up @@ -815,8 +816,8 @@ pj_status_t pjmedia_codec_mgr_get_dyn_codecs(pjmedia_codec_mgr* mgr,

pj_mutex_lock(mgr->mutex);

if (mgr->dyn_codecs_cnt < *count)
*count = mgr->dyn_codecs_cnt;
if (mgr->dyn_codecs_cnt < (unsigned)*count)
*count = (pj_int8_t)mgr->dyn_codecs_cnt;

pj_memcpy(dyn_codecs, mgr->dyn_codecs, *count * sizeof(pj_str_t));

Expand Down
16 changes: 9 additions & 7 deletions pjmedia/src/pjmedia/sdp_neg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,8 @@ static pj_status_t assign_pt_and_update_map(pj_pool_t *pool,
{
unsigned i, j;

PJ_UNUSED_ARG(pool);

for (i = 0; i < sess->media_count; ++i) {
pjmedia_type med_type;
unsigned count;
Expand Down Expand Up @@ -1785,8 +1787,8 @@ static pj_status_t assign_pt_and_update_map(pj_pool_t *pool,
codec = rtpmap.enc_name;
}

codec_idx = pjmedia_codec_mgr_find_codec(dyn_codecs, count,
&codec, NULL);
codec_idx = (pj_int8_t)pjmedia_codec_mgr_find_codec(dyn_codecs,
count, &codec, NULL);
if (codec_idx < 0) {
/* This typically happens when remote offers unknown
* codec.
Expand All @@ -1798,7 +1800,7 @@ static pj_status_t assign_pt_and_update_map(pj_pool_t *pool,
/* Update the mapping. */
neg->pt_to_codec[i][pt - START_DYNAMIC_PT] = codec_idx;
if (codec_idx != UNKNOWN_CODEC)
neg->codec_to_pt[i][codec_idx] = pt;
neg->codec_to_pt[i][codec_idx] = (pj_int8_t)pt;
continue;
}

Expand Down Expand Up @@ -1841,15 +1843,15 @@ static pj_status_t assign_pt_and_update_map(pj_pool_t *pool,
* find the first unused one.
*/
if (need_new_pt && new_pt == 0) {
new_pt = find_new_pt(&neg->pt_to_codec[i], pt_used,
&codec, codec_idx);
new_pt = (pj_int8_t)find_new_pt(&neg->pt_to_codec[i], pt_used,
&codec, codec_idx);
}

if (new_pt != 0 && new_pt != pt) {
if (new_pt != 0 && new_pt != (pj_int8_t)pt) {
rewrite_pt2(neg->pool_active, (pj_str_t *)&attr->value,
pt, new_pt);
} else {
new_pt = pt;
new_pt = (pj_int8_t)pt;
}

/* Mark the PT number as used and keep track of the change
Expand Down
4 changes: 2 additions & 2 deletions pjmedia/src/pjmedia/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -2656,14 +2656,14 @@ PJ_DEF(pj_status_t) pjmedia_stream_create( pjmedia_endpt *endpt,

ptime = afd->frame_time_usec;

if (stream->codec_param.info.enc_ptime * 1000 >
if (stream->codec_param.info.enc_ptime * (unsigned)1000 >
ptime * stream->codec_param.info.enc_ptime_denum)
{
ptime = stream->codec_param.info.enc_ptime * 1000 /
stream->codec_param.info.enc_ptime_denum;
}

if (stream->codec_param.info.frm_ptime * 1000 >
if (stream->codec_param.info.frm_ptime * (unsigned)1000 >
ptime * stream->codec_param.info.frm_ptime_denum)
{
ptime = stream->codec_param.info.frm_ptime * 1000 /
Expand Down
7 changes: 4 additions & 3 deletions pjmedia/src/pjmedia/vid_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ PJ_DEF(pj_status_t) pjmedia_vid_codec_mgr_unregister_factory(
pj_bool_t found;
pj_str_t codec_str = pj_str(mgr->codec_desc[i].id);

codec_idx = pjmedia_codec_mgr_find_codec(mgr->dyn_codecs,
codec_idx = (pj_int8_t)pjmedia_codec_mgr_find_codec(
mgr->dyn_codecs,
mgr->dyn_codecs_cnt,
&codec_str,
&found);
Expand Down Expand Up @@ -823,8 +824,8 @@ pj_status_t pjmedia_vid_codec_mgr_get_dyn_codecs(pjmedia_vid_codec_mgr* mgr,

pj_mutex_lock(mgr->mutex);

if (mgr->dyn_codecs_cnt < *count)
*count = mgr->dyn_codecs_cnt;
if (mgr->dyn_codecs_cnt < (unsigned)*count)
*count = (pj_int8_t)mgr->dyn_codecs_cnt;

pj_memcpy(dyn_codecs, mgr->dyn_codecs, *count * sizeof(pj_str_t));

Expand Down
9 changes: 6 additions & 3 deletions pjmedia/src/test/mips_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1717,9 +1717,6 @@ 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;
Expand All @@ -1729,6 +1726,12 @@ static pjmedia_port* create_stream( pj_pool_t *pool,
pjmedia_stream_info si;
pj_status_t status;

#if !PJMEDIA_HAS_SRTP
PJ_UNUSED_ARG(srtp_enabled);
PJ_UNUSED_ARG(srtp_80);
PJ_UNUSED_ARG(srtp_auth);
#endif

PJ_UNUSED_ARG(flags);

codec_id = pj_str((char*)codec);
Expand Down
4 changes: 2 additions & 2 deletions pjsip-apps/src/pjsua/pjsua_app_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ static void get_video_codec_id(pj_cli_dyn_choice_param *param)
pjsua_vid_enum_codecs(ci, &count);
for (i = 0; i <= count; ++i) {
pjmedia_vid_codec_param cp;
pjmedia_video_format_detail *vfd;
pjmedia_video_format_detail *vfd = NULL;
pj_status_t status = PJ_SUCCESS;
pj_str_t cur_ci;

Expand Down Expand Up @@ -1519,7 +1519,7 @@ static pj_status_t cmd_make_single_call(pj_cli_cmd_val *cval)
loop = PJ_TRUE;
result.nb_result = 1;
}
if (result.nb_result > pjsua_get_buddy_count()) break;
if (result.nb_result > (int)pjsua_get_buddy_count()) break;

if (result.nb_result == 0) {
const pj_str_t err_msg =
Expand Down
2 changes: 1 addition & 1 deletion pjsip-apps/src/pjsua/pjsua_app_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ static void ui_make_new_call()
loop = PJ_TRUE;
result.nb_result = 1;
}
if (result.nb_result > pjsua_get_buddy_count()) break;
if (result.nb_result > (int)pjsua_get_buddy_count()) break;

if (result.nb_result == 0) {
puts("You can't do that with make call!");
Expand Down
9 changes: 6 additions & 3 deletions pjsip/src/pjsip/sip_transport_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,21 @@ static pj_status_t update_factory_addr(struct tls_listener *listener,

if (addr_name && addr_name->host.slen) {
pj_sockaddr tmp;
int af = pjsip_transport_type_get_af(listener->factory.type);
pj_uint16_t af = (pj_uint16_t)
pjsip_transport_type_get_af(listener->factory.type);

tmp.addr.sa_family = af;

/* Validate IP address only */
if (pj_inet_pton(af, &addr_name->host, pj_sockaddr_get_addr(&tmp)) == PJ_SUCCESS)
if (pj_inet_pton(af, &addr_name->host, pj_sockaddr_get_addr(&tmp)) ==
PJ_SUCCESS)
{
/* Verify that address given in a_name (if any) is valid */
status = pj_sockaddr_init(af, &tmp, &addr_name->host,
(pj_uint16_t)addr_name->port);
if (status != PJ_SUCCESS || !pj_sockaddr_has_addr(&tmp) ||
(af == pj_AF_INET() && tmp.ipv4.sin_addr.s_addr == PJ_INADDR_NONE))
(af == pj_AF_INET() &&
tmp.ipv4.sin_addr.s_addr == PJ_INADDR_NONE))
{
/* Invalid address */
return PJ_EINVAL;
Expand Down
4 changes: 2 additions & 2 deletions pjsip/src/pjsua2/media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1945,9 +1945,9 @@ pjmedia_codec_param CodecParam::toPj() const
param.info.max_bps= (pj_uint32_t)info.maxBps;
param.info.max_rx_frame_size = info.maxRxFrameSize;
param.info.frm_ptime = (pj_uint16_t)info.frameLen;
param.info.frm_ptime_denum = (pj_uint16_t)info.frameLenDenum;
param.info.frm_ptime_denum = (pj_uint8_t)info.frameLenDenum;
param.info.enc_ptime = (pj_uint16_t)info.encFrameLen;
param.info.enc_ptime_denum = (pj_uint16_t)info.encFrameLenDenum;
param.info.enc_ptime_denum = (pj_uint8_t)info.encFrameLenDenum;
param.info.pcm_bits_per_sample = (pj_uint8_t)info.pcmBitsPerSample;
param.info.pt = (pj_uint8_t)info.pt;
param.info.fmt_id = info.fmtId;
Expand Down

0 comments on commit b8fbdb2

Please sign in to comment.