Skip to content
Merged
10 changes: 5 additions & 5 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
run: make
- name: swig bindings
run: cd pjsip-apps/src/swig && make
- name: set up Python 2.7 for pjsua test
- name: set up Python 3.10 for pjsua test
uses: actions/setup-python@v2
with:
python-version: 2.7
python-version: '3.10'
- name: unit tests
run: make pjlib-test-ci pjlib-util-test pjmedia-test pjsua-test

Expand Down Expand Up @@ -122,10 +122,10 @@ jobs:
run: make
- name: swig bindings
run: cd pjsip-apps/src/swig && make
- name: set up Python 2.7 for pjsua test
uses: actions/setup-python@v2
- name: set up Python 3.10 for pjsua test
uses: actions/setup-python@v4
with:
python-version: 2.7
python-version: '3.10'
- name: unit tests
run: make pjlib-test-ci pjlib-util-test pjmedia-test pjsua-test

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
run: cd pjsip-apps/src/swig && make
- name: disable firewall
run: sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off
- name: set up Python 2.7 for pjsua test
uses: actions/setup-python@v2
- name: set up Python 3.10 for pjsua test
uses: actions/setup-python@v4
with:
python-version: 2.7
python-version: '3.10'
- name: unit tests
run: make pjlib-test-ci pjmedia-test pjlib-util-test pjsua-test

Expand Down Expand Up @@ -126,10 +126,10 @@ jobs:
run: cd pjsip-apps/src/swig && make
- name: disable firewall
run: sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate off
- name: set up Python 2.7 for pjsua test
- name: set up Python 3.10 for pjsua test
uses: actions/setup-python@v2
with:
python-version: 2.7
python-version: '3.10'
- name: unit tests
run: make pjlib-test-ci pjmedia-test pjlib-util-test pjsua-test

Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/ci-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ jobs:
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
- name: set up Python 3.10 for pjsua test
uses: actions/setup-python@v4
with:
python-version: 2.7
python-version: '3.10'
- name: unit tests
run: |
$env:OPENSSL_DIR = Get-Content .\openssl_dir.txt
Expand Down Expand Up @@ -262,10 +262,10 @@ jobs:
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
- name: set up Python 3.10 for pjsua test
uses: actions/setup-python@v4
with:
python-version: 2.7
python-version: '3.10'
- name: unit tests
run: |
$env:OPENSSL_DIR = Get-Content .\openssl_dir.txt
Expand Down Expand Up @@ -332,4 +332,4 @@ jobs:
set INCLUDE=%INCLUDE%;%LIBFFMPEG_DIR%\include;%SDL_DIR%\include
set LIB=%LIB%;%FFMPEG_DIR%\lib;%SDL_DIR%\lib\x86
msbuild pjproject-vs14.sln /p:PlatformToolset=v143 /p:Configuration=Release /p:Platform=win32 /p:UseEnv=true
shell: cmd
shell: cmd
27 changes: 18 additions & 9 deletions pjsip/src/pjsip-ua/sip_inv.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ static void mod_inv_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e)
{
pjsip_dialog *dlg;
pjsip_inv_session *inv;
pj_bool_t cb_called = PJ_FALSE;

dlg = pjsip_tsx_get_dlg(tsx);
if (dlg == NULL)
Expand All @@ -829,6 +830,17 @@ static void mod_inv_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e)
if (inv == NULL)
return;

/* Call on_tsx_state_changed() upon receipt of request (tsx state is
* PJSIP_TSX_STATE_TRYING). We need to do this before calling the state
* handler since the handler will send response and change the tsx state.
*/
if (mod_inv.cb.on_tsx_state_changed && inv->notify &&
e->body.tsx_state.tsx->state == PJSIP_TSX_STATE_TRYING)
{
cb_called = PJ_TRUE;
(*mod_inv.cb.on_tsx_state_changed)(inv, tsx, e);
}

/* Call state handler for the invite session. */
(*inv_state_handler[inv->state])(inv, e);

Expand All @@ -845,13 +857,8 @@ static void mod_inv_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e)
}
}

/* Call on_tsx_state. CANCEL request is a special case and has been
* reported earlier in inv_respond_incoming_cancel()
*/
if (mod_inv.cb.on_tsx_state_changed && inv->notify &&
!(tsx->method.id==PJSIP_CANCEL_METHOD &&
e->body.tsx_state.type==PJSIP_EVENT_RX_MSG))
{
/* Call on_tsx_state. */
if (mod_inv.cb.on_tsx_state_changed && inv->notify && !cb_called) {
(*mod_inv.cb.on_tsx_state_changed)(inv, tsx, e);
}

Expand Down Expand Up @@ -3839,9 +3846,11 @@ static void inv_respond_incoming_cancel(pjsip_inv_session *inv,
* may not see the CANCEL request at all because by the time the CANCEL
* request is reported, call has been disconnected and further events
* from the INVITE session has been suppressed.
*
* Update: we have called this in mod_inv_on_tsx_state()
*/
if (mod_inv.cb.on_tsx_state_changed && inv->notify)
(*mod_inv.cb.on_tsx_state_changed)(inv, cancel_tsx, e);
// if (mod_inv.cb.on_tsx_state_changed && inv->notify)
// (*mod_inv.cb.on_tsx_state_changed)(inv, cancel_tsx, e);

/* See if we have matching INVITE server transaction: */

Expand Down
12 changes: 9 additions & 3 deletions pjsip/src/pjsua-lib/pjsua_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -5034,15 +5034,21 @@ static void pjsua_call_on_state_changed(pjsip_inv_session *inv,
PJSUA_UNLOCK();
}

/* Ticket #1627: Invoke on_call_tsx_state() when call is disconnected. */
/* Ticket #1627: Invoke on_call_tsx_state() when call is disconnected.
*
* Update: No longer necessary. Since #2600 (immediate hangup), call is
* disconnected before BYE is sent.
*/
/*
if (inv->state == PJSIP_INV_STATE_DISCONNECTED &&
e->type == PJSIP_EVENT_TSX_STATE &&
!call->hanging_up && call->inv &&
call->inv &&
pjsua_var.ua_cfg.cb.on_call_tsx_state)
{
(*pjsua_var.ua_cfg.cb.on_call_tsx_state)(call->index,
e->body.tsx_state.tsx, e);
}
*/

if (!call->hanging_up && pjsua_var.ua_cfg.cb.on_call_state)
(*pjsua_var.ua_cfg.cb.on_call_state)(call->index, e);
Expand Down Expand Up @@ -6189,7 +6195,7 @@ static void pjsua_call_on_tsx_state_changed(pjsip_inv_session *inv,
}

/* Notify application callback first */
if (pjsua_var.ua_cfg.cb.on_call_tsx_state) {
if (!call->hanging_up && pjsua_var.ua_cfg.cb.on_call_tsx_state) {
(*pjsua_var.ua_cfg.cb.on_call_tsx_state)(call->index, tsx, e);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/pjsua/inc_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__( self,
s.bind(("0.0.0.0", port))
except socket.error as serr:
s.close()
if serr.errno == errno.EADDRINUSE:
if serr.errno == errno.EADDRINUSE or serr.errno == errno.EACCES:
continue
s.close()
break;
Expand All @@ -89,7 +89,7 @@ def __init__( self,
s.bind(("0.0.0.0", port))
except socket.error as serr:
s.close()
if serr.errno == errno.EADDRINUSE:
if serr.errno == errno.EADDRINUSE or serr.errno == errno.EACCES:
continue
s.close()
break;
Expand Down Expand Up @@ -148,7 +148,7 @@ def __init__( self,

###################################
# TestError exception
class TestError:
class TestError(Exception):
desc = ""
def __init__(self, desc):
self.desc = desc
Expand Down
28 changes: 16 additions & 12 deletions tests/pjsua/inc_sip.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def __init__(self, dst_addr, dst_port=5060, tcp=False, trace=True, local_port=0)

def trace(self, txt):
if self.trace_enabled:
print str(time.strftime("%H:%M:%S ")) + txt
try:
print(str(time.strftime("%H:%M:%S ")) + txt)
except UnicodeEncodeError:
print((str(time.strftime("%H:%M:%S ")) + txt).encode('utf-8'))

def update_fields(self, msg):
if self.tcp:
Expand Down Expand Up @@ -157,7 +160,7 @@ def send_msg(self, msg, dst_addr=None):
if not dst_addr:
dst_addr = (self.dst_addr, self.dst_port)
self.trace("============== TX MSG to " + str(dst_addr) + " ============= \n" + msg)
self.sock.sendto(msg, 0, dst_addr)
self.sock.sendto(msg.encode('utf-8'), 0, dst_addr)

def wait_msg_from(self, timeout):
endtime = time.time() + timeout
Expand All @@ -167,29 +170,30 @@ def wait_msg_from(self, timeout):
readset = select([self.sock], [], [], 1)
if len(readset[0]) < 1 or not self.sock in readset[0]:
if len(readset[0]) < 1:
print "select() timeout (will wait for " + str(int(endtime - time.time())) + "more secs)"
print("select() timeout (will wait for " + str(int(endtime - time.time())) + "more secs)")
elif not self.sock in readset[0]:
print "select() alien socket"
print("select() alien socket")
else:
print "select other error"
print("select other error")
continue
try:
msg, src_addr = self.sock.recvfrom(4096)
break
except:
print "recv() exception: ", sys.exc_info()[0]
print("recv() exception: ", sys.exc_info()[0])
continue

if msg=="":

msgstr = msg.decode('utf-8')
if msgstr=="":
return "", None
if self.last_request=="INVITE" and self.rem_tag=="":
self.rem_tag = get_tag(msg, "To")
self.rem_tag = get_tag(msgstr, "To")
self.rem_tag = self.rem_tag.rstrip("\r\n;")
if self.rem_tag != "":
self.rem_tag = ";tag=" + self.rem_tag
self.trace("=== rem_tag:" + self.rem_tag)
self.trace("=========== RX MSG from " + str(src_addr) + " ===========\n" + msg)
return (msg, src_addr)
self.trace("=========== RX MSG from " + str(src_addr) + " ===========\n" + msgstr)
return (msgstr, src_addr)

def wait_msg(self, timeout):
return self.wait_msg_from(timeout)[0]
Expand Down Expand Up @@ -263,7 +267,7 @@ def __init__(self, name, pjsua_args, sdp, resp_code,
resp_inc=[], resp_exc=[], use_tcp=False,
extra_headers="", body="", complete_msg="",
enable_buffer = False):
self.complete_msg = complete_msg
self.complete_msg = complete_msg
self.sdp = sdp
self.resp_code = resp_code
self.resp_include = resp_inc
Expand Down
13 changes: 13 additions & 0 deletions tests/pjsua/inc_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys

def load_module_from_file(module_name, module_path):
if sys.version_info[0] == 3 and sys.version_info[1] >= 5:
import importlib.util
spec = importlib.util.spec_from_file_location(module_name, module_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
elif sys.version_info[0] == 3 and sys.version_info[1] < 5:
import importlib.machinery
loader = importlib.machinery.SourceFileLoader(module_name, module_path)
module = loader.load_module()
return module
4 changes: 2 additions & 2 deletions tests/pjsua/mod_call.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import time
import imp
import sys
import inc_const as const
import inc_util as util
from inc_cfg import *

# Load configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])
cfg_file = util.load_module_from_file("cfg_file", ARGS[1])

# Trigger address switch for media flow between ua1 and ua2.
# When the receiver uses STUN while both sides are actually in the same
Expand Down
6 changes: 3 additions & 3 deletions tests/pjsua/mod_media_playrec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
# wav input must be more than 3 seconds long

import time
import imp
import sys
import re
import subprocess
import inc_const as const
import inc_util as util
from inc_cfg import *

# Load configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])
cfg_file = util.load_module_from_file("cfg_file", ARGS[1])

# WAV similarity calculator
COMPARE_WAV_EXE = ""
Expand Down Expand Up @@ -95,7 +95,7 @@ def post_func(t):

# Evaluate the similarity value
sim_val = mo_sim_val.group(1)
if (sim_val >= COMPARE_THRESHOLD):
if (int(sim_val) >= COMPARE_THRESHOLD):
endpt.trace("WAV similarity = " + sim_val)
else:
raise TestError("WAV degraded heavily, similarity = " + sim_val)
Expand Down
10 changes: 5 additions & 5 deletions tests/pjsua/mod_pesq.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
# - clock-rate of those files can only be 8khz or 16khz

import time
import imp
import os
import sys
import re
import subprocess
import wave
import shutil
import inc_const as const
import inc_util as util

from inc_cfg import *

# Load configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])
cfg_file = util.load_module_from_file("cfg_file", ARGS[1])

# PESQ configs
PESQ = "tools/pesq" # PESQ executable path
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_func(t):
inwavlen = fin.getnframes() * 1.0 / fin.getframerate()
inwavlen += 0.2
fin.close()
print "WAV input len = " + str(inwavlen) + "s"
print("WAV input len = " + str(inwavlen) + "s")

# Get clock rate of the output
mo_clock_rate = re.compile("\.(\d+)\.wav").search(output_filename)
Expand Down Expand Up @@ -159,9 +159,9 @@ def post_func(t):
wavoutname = "logs/" + wavoutname
try:
shutil.copyfile(output_filename, wavoutname)
print "Output WAV is copied to " + wavoutname
print("Output WAV is copied to " + wavoutname)
except:
print "Couldn't copy output WAV, please check if 'logs' directory exists."
print("Couldn't copy output WAV, please check if 'logs' directory exists.")

raise TestError("WAV seems to be degraded badly, PESQ = "+ pesq_res + " (target=" + str(threshold) + ").")

Expand Down
4 changes: 2 additions & 2 deletions tests/pjsua/mod_pres.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import time
import imp
import sys
import inc_const as const
import inc_util as util
from inc_cfg import *

# Load configuration
cfg_file = imp.load_source("cfg_file", ARGS[1])
cfg_file = util.load_module_from_file("cfg_file", ARGS[1])


# Test body function
Expand Down
Loading