Skip to content

Commit

Permalink
Miscellaneous fixes (#2969)
Browse files Browse the repository at this point in the history
* Suppressed various compilation warnings
* Fixed CodeQL warning
* Fixed build warning on Android and Linux
* Fix build warning on Visual Studio
* Update target Android SDK version to 29 (for pjsua2 & app), to avoid gradle error: 'Google Play requires that apps target API level 29 or higher'.
* Add support for Camera2 API to ipjsua android app.
* Fix assertion on Win32 app (MSVC2005) because ICE transport info size is 160 bytes while the allocated buffer is just 144 bytes.
* Enable python unit test on windows for github actions.
* Avoid assertion in pjsua test caused by double calling of pjsua_conf_remove_port()
  • Loading branch information
sauwming authored Feb 24, 2022
1 parent 062204b commit 6f19738
Show file tree
Hide file tree
Showing 45 changed files with 133 additions and 91 deletions.
34 changes: 32 additions & 2 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,25 @@ jobs:
set LIB=%LIB%;%OPENSSL_DIR%\lib
msbuild pjproject-vs14.sln /p:PlatformToolset=v143 /p:Configuration=Release /p:Platform=win32 /p:UseEnv=true
shell: cmd
- name: build test tools cmp_wav
run: |
set /P OPENSSL_DIR=<openssl_dir.txt
cd tests/pjsua/tools
set INCLUDE=%INCLUDE%;%OPENSSL_DIR%\include
set LIB=%LIB%;%OPENSSL_DIR%\lib
call "%PROGRAMFILES%\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat"
msbuild cmp_wav.vcxproj /p:PlatformToolset=v143 /p:Configuration=Release /p:Platform=win32 /p:UseEnv=true
shell: cmd
- name: set up Python 2.7 for pjsua test
uses: actions/setup-python@v2
with:
python-version: 2.7
- name: unit tests
run: |
$env:OPENSSL_DIR = Get-Content .\openssl_dir.txt
$env:PATH+=";$env:OPENSSL_DIR\bin"
cd pjsip/bin; ./pjsip-test-i386-Win32-vc14-Release.exe
cd tests/pjsua; python runall.py
cd ../../pjsip/bin; ./pjsip-test-i386-Win32-vc14-Release.exe
shell: powershell

build-windows-gnu-tls:
Expand Down Expand Up @@ -618,13 +632,29 @@ jobs:
set LIB=%LIB%;%OPENSSL_DIR%\lib;%LIBVPX_DIR%\lib\x86;%LIBSDL_DIR%\lib\x86
msbuild pjproject-vs14.sln /p:PlatformToolset=v143 /p:Configuration=Release /p:Platform=win32 /p:UseEnv=true
shell: cmd
- name: build test tools cmp_wav
run: |
set /P OPENSSL_DIR=<openssl_dir.txt
set /P LIBVPX_DIR=<libvpx_dir.txt
set /P LIBSDL_DIR=<libsdl_dir.txt
cd tests/pjsua/tools
set INCLUDE=%INCLUDE%;%OPENSSL_DIR%\include;%LIBVPX_DIR%\include;%LIBSDL_DIR%\include\SDL
set LIB=%LIB%;%OPENSSL_DIR%\lib;%LIBVPX_DIR%\lib\x86;%LIBSDL_DIR%\lib\x86
call "%PROGRAMFILES%\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat"
msbuild cmp_wav.vcxproj /p:PlatformToolset=v143 /p:Configuration=Release /p:Platform=win32 /p:UseEnv=true
shell: cmd
- name: set up Python 2.7 for pjsua test
uses: actions/setup-python@v2
with:
python-version: 2.7
- name: unit tests
run: |
$env:OPENSSL_DIR = Get-Content .\openssl_dir.txt
$env:LIBVPX_DIR = Get-Content .\libvpx_dir.txt
$env:LIBSDL_DIR = Get-Content .\libsdl_dir.txt
$env:PATH+=";$env:OPENSSL_DIR\bin;$env:LIBVPX_DIR\bin\x86;$env:LIBSDL_DIR\bin\x86;"
cd pjlib/bin; ./pjlib-test-i386-Win32-vc14-Release.exe
cd tests/pjsua; python runall.py
cd ../../pjlib/bin; ./pjlib-test-i386-Win32-vc14-Release.exe
cd ../../pjlib-util/bin; ./pjlib-util-test-i386-Win32-vc14-Release.exe
cd ../../pjmedia/bin/; ./pjmedia-test-i386-Win32-vc14-Release.exe
shell: powershell
Expand Down
1 change: 1 addition & 0 deletions pjlib/src/pj/ssl_sock_imp_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ static pj_status_t circ_write(circ_buf_t *cb,
*/

#ifndef SSL_SOCK_IMP_USE_OWN_NETWORK

/* Check IP address version. */
static int get_ip_addr_ver(const pj_str_t *host)
{
Expand Down
2 changes: 1 addition & 1 deletion pjlib/src/pj/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ static pj_status_t grow_heap(pj_timer_heap_t *ht)
memcpy(new_timer_dups, ht->timer_dups,
ht->max_size * sizeof(pj_timer_entry_dup));
for (i = 0; i < ht->cur_size; i++) {
int idx = ht->heap[i] - ht->timer_dups;
int idx = (int)(ht->heap[i] - ht->timer_dups);
// Point to the address in the new array
pj_assert(idx >= 0 && idx < (int)ht->max_size);
new_heap[i] = &new_timer_dups[idx];
Expand Down
2 changes: 1 addition & 1 deletion pjmedia/include/pjmedia/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@
* Maximum size in bytes of storage buffer of a transport specific info.
*/
#ifndef PJMEDIA_TRANSPORT_SPECIFIC_INFO_MAXSIZE
# define PJMEDIA_TRANSPORT_SPECIFIC_INFO_MAXSIZE (36*sizeof(long))
# define PJMEDIA_TRANSPORT_SPECIFIC_INFO_MAXSIZE (50*sizeof(long))
#endif


Expand Down
4 changes: 0 additions & 4 deletions pjmedia/src/pjmedia-codec/and_aud_mediacodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,6 @@ static pj_status_t and_media_codec_encode(pjmedia_codec *codec,
pj_size_t tx = 0;
pj_int16_t *pcm_in = (pj_int16_t*)input->buf;
pj_uint8_t *bits_out = (pj_uint8_t*) output->buf;
pj_uint8_t pt;

/* Invoke external VAD if codec has no internal VAD */
if (codec_data->vad && codec_data->vad_enabled) {
Expand Down Expand Up @@ -1101,7 +1100,6 @@ static pj_status_t and_media_codec_encode(pjmedia_codec *codec,
}
nsamples = input->size >> 1;
samples_per_frame = and_media_data->samples_per_frame;
pt = and_media_data->pt;
nframes = nsamples / samples_per_frame;

PJ_ASSERT_RETURN(nsamples % samples_per_frame == 0,
Expand Down Expand Up @@ -1230,7 +1228,6 @@ static pj_status_t and_media_codec_decode(pjmedia_codec *codec,
unsigned samples_per_frame;
unsigned i;

pj_uint8_t pt;
pj_ssize_t buf_idx = -1;
pj_uint8_t *input_buf;
pj_size_t input_size;
Expand All @@ -1241,7 +1238,6 @@ static pj_status_t and_media_codec_decode(pjmedia_codec *codec,
pjmedia_frame input_;

pj_bzero(&input_, sizeof(pjmedia_frame));
pt = and_media_data->pt;
samples_per_frame = and_media_data->samples_per_frame;

PJ_ASSERT_RETURN(output_buf_len >= samples_per_frame << 1,
Expand Down
2 changes: 0 additions & 2 deletions pjmedia/src/pjmedia-codec/and_vid_mediacodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1513,10 +1513,8 @@ static pj_status_t open_h264(and_media_codec_data *and_media_data)
for (i = h264_fmtp.sprop_param_sets_len - code_size;
i >= code_size; i--)
{
pj_bool_t found = PJ_TRUE;
for (j = 0; j < code_size; j++) {
if (h264_fmtp.sprop_param_sets[i + j] != start_code[j]) {
found = PJ_FALSE;
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions pjmedia/src/pjmedia-codec/openh264.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ static int write_yuv(pj_uint8_t *buf,
if (i < iHeight)
return -1;

return dst - buf;
return (int)(dst - buf);
}

static pj_status_t oh264_got_decoded_frame(pjmedia_vid_codec *codec,
Expand Down Expand Up @@ -1014,7 +1014,7 @@ static pj_status_t oh264_codec_decode(pjmedia_vid_codec *codec,
pj_memcpy( oh264_data->dec_buf + whole_len,
(pj_uint8_t*)packets[i].buf,
packets[i].size);
whole_len += packets[i].size;
whole_len += (unsigned)packets[i].size;
}

} else {
Expand Down
4 changes: 2 additions & 2 deletions pjmedia/src/pjmedia-codec/vpx_packetizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ PJ_DEF(pj_status_t) pjmedia_vpx_packetize(const pjmedia_vpx_packetizer *pktz,
{
unsigned payload_desc_size = 1;
unsigned max_size = pktz->cfg.mtu - payload_desc_size;
unsigned remaining_size = bits_len - *bits_pos;
unsigned out_size = *payload_len;
unsigned remaining_size = (unsigned)bits_len - *bits_pos;
unsigned out_size = (unsigned)*payload_len;
pj_uint8_t *bits = *payload;

*payload_len = PJ_MIN(remaining_size, max_size);
Expand Down
2 changes: 1 addition & 1 deletion pjmedia/src/pjmedia/avi_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ static pj_status_t avi_get_frame(pjmedia_port *this_port,
fport->eof = PJ_TRUE;

size_to_read -= size_read;
if (size_to_read == frame->size) {
if (size_to_read == (pj_ssize_t)frame->size) {
/* Frame is empty */
frame->type = PJMEDIA_FRAME_TYPE_NONE;
frame->size = 0;
Expand Down
4 changes: 2 additions & 2 deletions pjmedia/src/pjmedia/converter_libyuv.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ static pj_status_t libyuv_conv_convert2(
pjmedia_video_apply_fmt_param *ap = &src_fmt_info->apply_param;
unsigned j;
for (j = 0; j < src_fmt_info->vid_fmt_info->plane_cnt; ++j) {
int y = src_pos->y * ap->plane_bytes[j] / ap->strides[j] /
int y = src_pos->y * (int)ap->plane_bytes[j] / ap->strides[j] /
ap->size.h;
ap->planes[j] += y * ap->strides[j] + src_pos->x *
ap->strides[j] / ap->size.w;
Expand All @@ -701,7 +701,7 @@ static pj_status_t libyuv_conv_convert2(
unsigned j;
for (j = 0; j < dst_fmt_info->vid_fmt_info->plane_cnt; ++j)
{
int y = dst_pos->y * ap->plane_bytes[j] / ap->strides[j] /
int y = dst_pos->y * (int)ap->plane_bytes[j] / ap->strides[j] /
ap->size.h;
ap->planes[j] += y * ap->strides[j] + dst_pos->x *
ap->strides[j] / ap->size.w;
Expand Down
1 change: 1 addition & 0 deletions pjmedia/src/pjmedia/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ pjmedia_event_unsubscribe(pjmedia_event_mgr *mgr,
esub *sub;
unsigned i = 0, j = 0;

PJ_UNUSED_ARG(j);
PJ_ASSERT_RETURN(cb, PJ_EINVAL);

if (!mgr) mgr = pjmedia_event_mgr_instance();
Expand Down
2 changes: 1 addition & 1 deletion pjmedia/src/pjmedia/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ PJ_DEF(pj_status_t) pjmedia_video_format_fill_black(const pjmedia_format *fmt,
vafp.plane_bytes[1]);
} else if (fmt_id == PJMEDIA_FORMAT_YUY2) {
pj_uint8_t *ptr = (pj_uint8_t *)buf;
unsigned i;
pj_size_t i;

for (i = vafp.framebytes / 2; i > 0; i--) {
*(ptr++) = 0x10; *(ptr++) = 0x80;
Expand Down
4 changes: 2 additions & 2 deletions pjmedia/src/pjmedia/jbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ PJ_DEF(pj_status_t) pjmedia_jbuf_set_ptime( pjmedia_jbuf *jb,

jb->jb_frame_ptime = ptime;
jb->jb_min_shrink_gap = PJMEDIA_JBUF_DISC_MIN_GAP / ptime;
jb->jb_max_burst = PJ_MAX(MAX_BURST_MSEC / ptime,
jb->jb_max_burst = (int)PJ_MAX(MAX_BURST_MSEC / ptime,
jb->jb_max_count*3/4);

return PJ_SUCCESS;
Expand Down Expand Up @@ -1193,7 +1193,7 @@ PJ_DEF(pj_status_t) pjmedia_jbuf_get_state( const pjmedia_jbuf *jb,
state->frame_size = (unsigned)jb->jb_frame_size;
state->min_prefetch = jb->jb_min_prefetch;
state->max_prefetch = jb->jb_max_prefetch;
state->max_count = jb->jb_max_count;
state->max_count = (unsigned)jb->jb_max_count;

state->burst = jb->jb_eff_level;
state->prefetch = jb->jb_prefetch;
Expand Down
2 changes: 1 addition & 1 deletion pjmedia/src/pjmedia/rtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ static void parse_rtcp_bye(pjmedia_rtcp_session *sess,
*/
reason.slen = PJ_MIN(sizeof(sess->stat.peer_sdes_buf_),
*((pj_uint8_t*)pkt+8));
reason.slen = PJ_MIN(reason.slen, size-9);
reason.slen = PJ_MIN(reason.slen, (pj_ssize_t)(size-9));

pj_memcpy(sess->stat.peer_sdes_buf_, ((pj_uint8_t*)pkt+9),
reason.slen);
Expand Down
2 changes: 1 addition & 1 deletion pjmedia/src/pjmedia/rtcp_fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ PJ_DEF(pj_status_t) pjmedia_rtcp_fb_build_rpsi(

PJ_ASSERT_RETURN(session && buf && length && rpsi, PJ_EINVAL);

bitlen = rpsi->rpsi_bit_len + 16;
bitlen = (unsigned)rpsi->rpsi_bit_len + 16;
padlen = (32 - (bitlen % 32)) % 32;
len = (3 + (bitlen+padlen)/32) * 4;
if (len > *length)
Expand Down
2 changes: 1 addition & 1 deletion pjmedia/src/pjmedia/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ PJ_DEF(pj_status_t) pjmedia_rtp_decode_rtp2(

/* Decode RTP extension. */
if ((*hdr)->x) {
if (offset + sizeof (pjmedia_rtp_ext_hdr) > pkt_len)
if (offset + sizeof (pjmedia_rtp_ext_hdr) > (unsigned)pkt_len)
return PJMEDIA_RTP_EINLEN;
dec_hdr->ext_hdr = (pjmedia_rtp_ext_hdr*)(((pj_uint8_t*)pkt) + offset);
dec_hdr->ext = (pj_uint32_t*)(dec_hdr->ext_hdr + 1);
Expand Down
4 changes: 2 additions & 2 deletions pjmedia/src/pjmedia/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,15 +706,15 @@ static pj_ssize_t print_attr(const pjmedia_sdp_attr *attr,
return p-buf;
}

static int print_media_desc( pjmedia_sdp_media *m, char *buf, int len)
static int print_media_desc(const pjmedia_sdp_media *m, char *buf, pj_size_t len)
{
char *p = buf;
char *end = buf+len;
unsigned i;
int printed;

/* check length for the "m=" line. */
if (len < m->desc.media.slen+m->desc.transport.slen+12+24) {
if (len < (pj_size_t)m->desc.media.slen+m->desc.transport.slen+12+24) {
return -1;
}
*p++ = 'm'; /* m= */
Expand Down
3 changes: 2 additions & 1 deletion pjmedia/src/pjmedia/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,8 @@ static pj_status_t get_frame( pjmedia_port *port, pjmedia_frame *frame)
stream->dec_buf_count);
}
} else if (use_dec_buf) {
stream->dec_buf_count = frame_out.size / sizeof(pj_int16_t);
stream->dec_buf_count = (unsigned)frame_out.size /
sizeof(pj_int16_t);
}

if (stream->jb_last_frm != frame_type) {
Expand Down
10 changes: 5 additions & 5 deletions pjmedia/src/pjmedia/transport_srtp_dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,11 +1315,11 @@ static pj_status_t dtls_encode_sdp( pjmedia_transport *tp,
}
if (pj_sockaddr_has_addr(&ds->rem_addr) &&
pj_sockaddr_has_addr(&rem_rtp) &&
pj_sockaddr_cmp(&ds->rem_addr, &rem_rtp) ||
(!use_rtcp_mux &&
pj_sockaddr_has_addr(&ds->rem_rtcp) &&
pj_sockaddr_has_addr(&rem_rtcp) &&
pj_sockaddr_cmp(&ds->rem_rtcp, &rem_rtcp)))
(pj_sockaddr_cmp(&ds->rem_addr, &rem_rtp) ||
(!use_rtcp_mux &&
pj_sockaddr_has_addr(&ds->rem_rtcp) &&
pj_sockaddr_has_addr(&rem_rtcp) &&
pj_sockaddr_cmp(&ds->rem_rtcp, &rem_rtcp))))
{
rem_addr_changed = PJ_TRUE;
}
Expand Down
3 changes: 3 additions & 0 deletions pjmedia/src/pjmedia/transport_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,9 @@ static pj_status_t transport_simulate_lost(pjmedia_transport *tp,
static pj_status_t transport_restart(pj_bool_t is_rtp,
struct transport_udp *udp)
{
PJ_UNUSED_ARG(udp);
PJ_UNUSED_ARG(is_rtp);

return PJ_ENOTSUP;

/* This code is disabled for the following reason (see also #2881):
Expand Down
2 changes: 1 addition & 1 deletion pjmedia/src/pjmedia/vid_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ static void on_rx_rtp( pjmedia_tp_cb_param *param)
* So we need to compare the last decoded frame's timestamp with
* the current timestamp.
*/
else if (ts_diff > stream->dec_max_delay) {
else if (ts_diff > (long)stream->dec_max_delay) {
can_decode = PJ_TRUE;
}

Expand Down
2 changes: 1 addition & 1 deletion pjmedia/src/pjmedia/wav_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ PJ_DEF(pj_status_t) pjmedia_wav_player_port_create( pj_pool_t *pool,
* try to play whatever data is there instead of immediately returning
* error.
*/
wave_hdr.data_hdr.len = fport->fsize - fport->start_data;
wave_hdr.data_hdr.len = (pj_uint32_t)fport->fsize - fport->start_data;
// pj_file_close(fport->fd);
// return PJMEDIA_EWAVEUNSUPP;
}
Expand Down
2 changes: 1 addition & 1 deletion pjnath/src/pjnath/ice_strans.c
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,7 @@ static pj_status_t use_buffer( pj_ice_strans *ice_st,
pj_status_t status;

/* Allocate send buffer, if necessary. */
status = alloc_send_buf(ice_st, data_len);
status = alloc_send_buf(ice_st, (unsigned)data_len);
if (status != PJ_SUCCESS)
return status;

Expand Down
2 changes: 1 addition & 1 deletion pjnath/src/pjnath/turn_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ static pj_bool_t dataconn_on_data_read(pj_activesock_t *asock,
if (conn->state == DATACONN_STATE_READY) {
/* Application data */
if (turn_sock->cb.on_rx_data) {
(*turn_sock->cb.on_rx_data)(turn_sock, data, *remainder,
(*turn_sock->cb.on_rx_data)(turn_sock, data, (unsigned)*remainder,
&conn->peer_addr,
conn->peer_addr_len);
}
Expand Down
6 changes: 3 additions & 3 deletions pjsip-apps/src/pjsua/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 15
compileSdkVersion 26
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "org.pjsip.pjsua"
minSdkVersion 15
targetSdkVersion 15
minSdkVersion 23
targetSdkVersion 26

ndk {
moduleName "libpjsua"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@

import android.app.Activity;
import android.content.pm.ApplicationInfo;
import android.hardware.camera2.CameraManager;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
import org.pjsip.PjCameraInfo2;

class CONST {
public static final String LIB_FILENAME = "pjsua";
Expand Down Expand Up @@ -160,6 +163,8 @@ private void updateStatus(String output) {
protected void onCreate(Bundle savedInstanceState) {
LOG.DEBUG(ui_handler, "=== Activity::onCreate() ===");
super.onCreate(savedInstanceState);
CameraManager cm = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
PjCameraInfo2.SetCameraManager(cm);

init_view();

Expand Down
Loading

0 comments on commit 6f19738

Please sign in to comment.