the main environment is docker, python3.8, pjsua2
I use this code to get a call, in microsip can accept, but no sound
the main code is
#!/usr/bin/env python3
import sys
import os
import logging
import pjsua2 as pj
# ep = pj.Endpoint()
ep = None
class Call(pj.Call):
def __init__(self, acc, call_id=pj.PJSUA_INVALID_ID):
pj.Call.__init__(self, acc, call_id)
self.call_state = None
def onCallState(self, prm):
ci = self.getInfo()
print("==== ==== Call state: {}".format(ci.state))
print("==== ==== Call stateText: {}".format(ci.stateText))
# save call state to some class var
self.call_state = ci.state
# playing the wav file
play_dev_med = pj.Endpoint.instance().audDevManager().getPlaybackDevMedia()
print(f"==== ==== {play_dev_med}")
player = pj.AudioMediaPlayer()
player.createPlayer("/workspace/pjsua/input.16.wav")
player.startTransmit(play_dev_med)
class Account(pj.Account):
def __init__(self):
super().__init__()
def main():
# Create and initialize the library
global ep
ep_cfg = pj.EpConfig()
ep_cfg.uaConfig.threadCnt = 0
ep_cfg.uaConfig.mainThreadOnly = True
ep_cfg.logConfig.level = 5
ep_cfg.logConfig.consoleLevel = 5
ep = pj.Endpoint()
ep.libCreate()
ep.libInit(ep_cfg)
# ep.audDevManager().setNullDev()
# Create SIP transport. Error handling sample is shown
sipTpConfig = pj.TransportConfig()
ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig)
# Start the library
ep.libStart()
ep.audDevManager().setNullDev()
acfg = pj.AccountConfig()
acfg.idUri = "sip:[email protected]"
cred = pj.AuthCredInfo("digest", "*", "505", 0, "505")
acfg.sipConfig.authCreds.append(cred)
# Create the account
acc = Account()
acc.create(acfg)
ep.audDevManager().setNullDev()
call = Call(acc)
call_param = pj.CallOpParam()
call_param.opt.audioCount = 1
call_param.opt.videoCount = 0
call_prm = pj.CallOpParam(True)
call.makeCall("sip:[email protected]", call_prm)
# while not call.done:
while True:
ep.libHandleEvents(10000)
# check your saved call_state here
if not call.call_state:
continue
if call.call_state == pj.PJSIP_INV_STATE_CONFIRMED:
call.done = True
# Destroy the library
ep.libDestroy()
if __name__ == "__main__":
main()
when oncallstate, the log show that
16:00:37.804 pjsua_aud.c .....Creating file player: /workspace/pjsua/input.16.wav..
16:00:37.804 wav_player.c ......File player '/workspace/pjsua/input.16.wav' created: samp.rate=16000, ch=1, bufsize=4KB, filesize=134KB
16:00:37.804 pjsua_aud.c ......Player created, id=0, slot=1
16:00:37.804 pjsua_aud.c .....Conf connect: 1 --> 0
16:00:37.804 conference.c ......Port 1 (/workspace/pjsua/input.16.wav) transmitting to port 0 (Master/sound)
16:00:37.804 pjsua_aud.c .....Destroying player 0..
I notice that the player is destroyed soon, and how to resolve it
when accept the call, it's no sound