Search code examples
pythonlinuxpjsipalsaubuntu-18.04

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


This is not a duplicated question, other user had the same problem but this question add more info. I'm working on Ubuntu 18.

When I receive a call using VoIP with and asterisk server, my python script crash. This python script works in other computer but not in mine. So I tried to diagnose the pjsip dependency because the problem come from there.

I use pjsip as dependency of Python Most Voip Library

The pjsip installation process is the following:

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

After that, I use the test binary to check my computer:

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

The test menu is the following:

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

Choosing option 03 I get the following output:

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)

That is the same problem that crash my python script when I have an incoming call:

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)

The problem comes from pjsip, and is related with play streaming audio.

Ubuntu is using ALSA by default, and it seems that everything works. I have sox utils, and play wav files properly.

  • UPDATE: It seems that PJ_ENOTFOUND its just an common error that cannot find a file to play. The problem with the test is just the path. Moving the file wav to binary path make works directly without error. The problem with python wrapper is other.

Some ideas?


Solution

  • After debugging the python library, I found that when a call arrive, a wav file try to be used. I installed python library using --user option, and the point where the library look for the file was wrong.

    Using --user option make installation in a non-standard system path. If a call arrives the wav file won't be found and python library crash. To solve this, just add a symbolic link to the correct path:

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

    With this link, the library accept calls playing the wav file.