pjsip 无法播放音频:无法打开文件进行播放:未找到 (PJ_ENOTFOUND) [status=70006]

pjsip cannot play audio: Unable to open file for playback: Not found (PJ_ENOTFOUND) [status=70006]

这不是一个重复的问题,其他用户有同样的问题,但这个问题添加了更多信息。我正在研究 Ubuntu 18.

当我收到一个使用 VoIP 和星号服务器的呼叫时,我的 python 脚本崩溃了。此 python 脚本在其他计算机上有效,但在我的计算机上无效。所以我尝试诊断 pjsip 依赖性,因为问题出在这里。

我使用 pjsip 作为 Python Most Voip Library

的依赖项

pjsip安装过程如下:

mkdir -p pjsip
cd pjsip
svn co http://svn.pjsip.org/repos/pjproject/trunk/
cd trunk
./configure CFLAGS='-fPIC' -with-ffmpeg
make dep -j4
make clean
make -j4
sudo make install
cd pjsip-apps/src/python/
python2 setup.py install --user

之后,我使用测试二进制文件检查我的计算机:

./pjsip/trunk/pjsip-apps/bin/pjsystest-x86_64-unknown-linux-gnu

测试菜单如下:

17:54:00.264         os_core_unix.c !pjlib 2.8-svn for POSIX initialized
17:54:00.265         sip_endpoint.c  .Creating endpoint instance...
17:54:00.265                  pjlib  .select() I/O Queue created (0x55d462ccde00)
17:54:00.265         sip_endpoint.c  .Module "mod-msg-print" registered
17:54:00.265        sip_transport.c  .Transport manager created.
17:54:00.265           pjsua_core.c  .PJSUA state changed: NULL --> CREATED
17:54:00.266         sip_endpoint.c  .Module "mod-pjsua-log" registered
17:54:00.266         sip_endpoint.c  .Module "mod-tsx-layer" registered
17:54:00.266         sip_endpoint.c  .Module "mod-stateful-util" registered
17:54:00.266         sip_endpoint.c  .Module "mod-ua" registered
17:54:00.266         sip_endpoint.c  .Module "mod-100rel" registered
17:54:00.266         sip_endpoint.c  .Module "mod-pjsua" registered
17:54:00.266         sip_endpoint.c  .Module "mod-invite" registered
17:54:01.427             alsa_dev.c  ..ALSA driver found 32 devices
17:54:01.427             alsa_dev.c  ..ALSA initialized
17:54:01.427                  pjlib  ..select() I/O Queue created (0x55d462d58e28)
17:54:01.430         sip_endpoint.c  .Module "mod-evsub" registered
17:54:01.430         sip_endpoint.c  .Module "mod-presence" registered
17:54:01.430         sip_endpoint.c  .Module "mod-mwi" registered
17:54:01.430         sip_endpoint.c  .Module "mod-refer" registered
17:54:01.430         sip_endpoint.c  .Module "mod-pjsua-pres" registered
17:54:01.430         sip_endpoint.c  .Module "mod-pjsua-im" registered
17:54:01.430         sip_endpoint.c  .Module "mod-pjsua-options" registered
17:54:01.430           pjsua_core.c  .1 SIP worker threads created
17:54:01.430           pjsua_core.c  .pjsua version 2.8-svn for Linux-4.15.0.43/x86_64/glibc-2.27 initialized
17:54:01.430           pjsua_core.c  .PJSUA state changed: CREATED --> INIT
17:54:01.430           pjsua_core.c  PJSUA state changed: INIT --> STARTING
17:54:01.430         sip_endpoint.c  .Module "mod-unsolicited-mwi" registered
17:54:01.430           pjsua_core.c  .PJSUA state changed: STARTING --> RUNNING
M E N U :
---------
0: Tests
  00: Run test wizard
  01: Device Test
  02: Play Tone
  03: Play WAV File1
  04: Play WAV File2
  05: Record Audio
  06: Latency Test
  07: AEC/AES Test

  09: Exit
1: Options
  10: View Devices
  11: View Settings

Enter the menu number: 03

选择选项 03 我得到以下输出:

This test will play input.8.wav file to the speaker. Please listen carefully for audio impairments such as stutter. Let this test run for a while to make sure that everything is okay. Press OK to start, CANCEL to skip
1:OK  9:Cancel  
1
17:54:28.350              systest.c  Running WAV File Playback Test
17:54:28.350            pjsua_aud.c  Creating file player: input.8.wav..
17:54:28.350            pjsua_aud.c  .Unable to open file for playback: Not found (PJ_ENOTFOUND) [status=70006]
17:54:28.351            pjsua_aud.c  Creating file player: ../../tests/pjsua/wavs/input.8.wav..
17:54:28.351           wav_player.c  .File player '../../tests/pjsua/wavs/input.8.wav' created: samp.rate=8000, ch=1, bufsize=4KB, filesize=67KB
17:54:28.351            pjsua_aud.c  .Player created, id=0, slot=1
17:54:28.351            pjsua_aud.c  Conf connect: 1 --> 0
17:54:28.351            pjsua_aud.c  .Set sound device: capture=-1, playback=-2
17:54:28.351            pjsua_aud.c  ..Opening sound device (speaker + mic) PCM@8000/1/20ms
17:54:28.412           conference.c !.Port 1 (../../tests/pjsua/wavs/input.8.wav) transmitting to port 0 (default)

这与当我有来电时使我的 python 脚本崩溃的问题相同:

Incoming call from "test_user" <sip:test_user@192.168.30.30>
in _start_call_sound_in
[Wed Jan 23 17:56:31 2019] 17:56:31.426            pjsua_aud.c  ...Unable to open file for playback: Not found (PJ_ENOTFOUND) [status=70006]
Unhandled exception in thread started by <function _worker_thread_main at 0x7fb34d50ba28>
Traceback (most recent call last):
  File "/home/ubuntu_user/.local/lib/python2.7/site-packages/pjsua.py", line 2951, in _worker_thread_main
    time.sleep(0.050)
  File "/home/ubuntu_user/.local/lib/python2.7/site-packages/pjsua.py", line 2899, in _cb_on_incoming_call
    _lib._cb_on_incoming_call(acc_id, call_id, rdata)
  File "/home/ubuntu_user/.local/lib/python2.7/site-packages/pjsua.py", line 2781, in _cb_on_incoming_call
    acc._cb.on_incoming_call( Call(self, call_id) )
  File "/home/ubuntu_user/.local/lib/python2.7/site-packages/most/voip/api_backend.py", line 602, in on_incoming_call
    _start_call_sound_in()
  File "/home/ubuntu_user/.local/lib/python2.7/site-packages/most/voip/api_backend.py", line 128, in _start_call_sound_in
    player_in_id = pj.Lib.instance().create_player(sound_file,loop=True)
  File "/home/ubuntu_user/.local/lib/python2.7/site-packages/pjsua.py", line 2579, in create_player
    self._err_check("create_player()", self, err)
  File "/home/ubuntu_user/.local/lib/python2.7/site-packages/pjsua.py", line 2723, in _err_check
    raise Error(op_name, obj, err_code, err_msg)
pjsua.Error: Object: Lib, operation=create_player(), error=Not found (PJ_ENOTFOUND)

问题出自pjsip,与播放流式音频有关。

Ubuntu 默认使用 ALSA,看起来一切正常。我有 sox utils,可以正常播放 wav 文件。

一些想法?

调试python库后,发现来电时,会尝试使用wav文件。我使用 --user 选项安装了 python 库,库查找文件的地方是错误的。

使用--user 选项在非标准系统路径中进行安装。如果有来电,将找不到 wav 文件并且 python 库崩溃。要解决这个问题,只需在正确的路径中添加一个符号 link:

sudo ln -s /usr/local/lib/python2.7/dist-packages/data/ ${HOME}/.local/lib/python2.7/site-packages/
ls # output shall contain sounds folder

有了这个 link,库接受调用播放 wav 文件。