Difference between revisions of "Sound troubleshooting"

From Linuxintro
imported>ThorstenStaerk
(basically this said that pulseaudio outputs sound)
imported>ThorstenStaerk
Line 39: Line 39:
  
 
= strace'ing sound =
 
= strace'ing sound =
I can hear sound on starting
+
You know that the [[command]] <tt>speaker-test</tt> does some test noise. To find out if pulseaudio or also is in use, issue:
speaker-test
+
<abbr title="This is a prompt. The follow is a command you must enter.">#</abbr> strace <abbr title="String length should be 99 characters. It's no fun if the actual messages in strace's output are cut short.">-s 99</abbr> <abbr title="strace should follow sub-processes and show their behavior as well">-ff</abbr> speaker-test
and I can see with strace that speaker-test triggers activity inside the pulseaudio process. But how do they communicate with each other?
 
First of all let's find out all threads of the speaker-test process:
 
<pre>
 
linux-fpbq:~ # ps -A | grep speaker-test
 
29145 pts/1    00:00:07 speaker-test
 
linux-fpbq:~ # cd /proc/29145/fd
 
linux-fpbq:/proc/29145/fd # ll
 
total 0
 
lrwx------ 1 root root 64 Apr  4 15:44 0 -> /dev/pts/1
 
lrwx------ 1 root root 64 Apr  4 15:44 1 -> /dev/pts/1
 
lrwx------ 1 root root 64 Apr  4 15:44 2 -> /dev/pts/1
 
lr-x------ 1 root root 64 Apr  4 15:44 3 -> pipe:[114406]
 
l-wx------ 1 root root 64 Apr  4 15:44 4 -> pipe:[114406]
 
lr-x------ 1 root root 64 Apr  4 15:44 5 -> pipe:[114407]
 
l-wx------ 1 root root 64 Apr  4 15:44 6 -> pipe:[114407]
 
lrwx------ 1 root root 64 Apr  4 15:44 7 -> socket:[114414]
 
linux-fpbq:/proc/29145/fd # lsof +c 15 | grep 114414
 
speaker-test    29145            root    7u    unix 0xf5f19040      0t0    114414 socket
 
threaded-ml    29145 29146      root    7u    unix 0xf5f19040      0t0    114414 socket
 
</pre>
 
ok, seems a socket that is open to speaker-test is also open to threaded-ml. So threaded-ml is a thread of speaker-test.
 
  
Now process 29145 is currently speaker-test and process 2289 is pulseaudio. strace'ing speaker-test with strace -ffp 29145 I find:
+
You will find a lot of lines like
[pid 29146] recvmsg(7, {msg_name(0)=NULL, msg_iov(1)=[{"\0\0\0\0\377\377\377\377\0\0\0\20\0\0\0\0@\0\0\0", 20}], msg_controllen=24, {cmsg_len=24, cmsg_level=SOL_SOCKET, cmsg_type=SCM_CREDENTIALS{pid=2289, uid=0, gid=0}}, msg_flags=0}, 0) = 20
+
<abbr title="Process id. You get this field because you started strace with -ff">[pid 15287]</abbr> <abbr title="Syscall. Find out more with the command man 2 write.">write(6, "W", 1)            = 1</abbr>
So speaker-test definitely gets messages from process 2289 and it gets them via file descriptor 7:
+
<abbr title="Process id. You get this field because you started strace with -ff">[pid 15287]</abbr> <abbr title="Syscall. Find out more with the command man 2 recvmsg.">recvmsg</abbr>(<abbr title="As we can tell from man 2 recv, the following is a file descriptor. Find out more with the command cat /proc/PID/fd/7">7</abbr>, {msg_name(0)=NULL, msg_iov(1)=[{"L\0\0\0\2L\0\0\2+U\0\0\0\0\0\31vqU\0\0\0\0\0\0\0\0001TU \240\326\0\4\252\354TU \240\326\0\4\262%r\0\0\0\0\0\20\0\0r\0\0\0\0\0\2\260\220R\0\0\0\0\0\0\0\0R\0\0\0\0\0\2\260\220", 83}], msg_controllen=24, {cmsg_len=24, cmsg_level=SOL_SOCKET, cmsg_type=SCM_CREDENTIALS{pid=2289, uid=0, gid=0}}, msg_flags=0}, 0) = 83
  linux-fpbq:/proc/29145/fd # ll 7
+
  <abbr title="Process id. You get this field because you started strace with -ff">[pid 15287]</abbr> <abbr title="Syscall. Find out more with the command man 2 write.">write(6, "W", 1)            = 1</abbr>
lrwx------ 1 root root 64 Apr  4 15:44 7 -> socket:[114414]
 
  
Now strace'ing pulseaudio with the command strace -ffp 2289 I get:
+
'''So what happens here?''' Obviously speaker-test calls the kernel's ''recvmsg'' method. The interesting thing we get from <tt>man 2 recvmsg</tt> is that the first parameter is sockfd, the file descriptor of a socket. So it hands over a socket as a parameter. Let's look at process' file descriptors:
  [pid 2289] send(28, "\0\0\0\24\377\377\377\377\0\0\0\0\0\0\0\0\0\0\0\0L\0\0\0=L\377\377\377\377L\0"..., 40, MSG_NOSIGNAL) = 40
+
<abbr title="This is a prompt. The follow is a command you must enter.">#</abbr> cd /proc/15287/fd
 +
ls -l
 +
total 0
 +
lrwx------ 1 root root 64 Apr  4 22:55 0 -> /dev/pts/4
 +
lrwx------ 1 root root 64 Apr  4 22:55 1 -> /dev/pts/4
 +
lrwx------ 1 root root 64 Apr  4 22:55 2 -> /dev/pts/4
 +
lr-x------ 1 root root 64 Apr  4 22:55 3 -> pipe:[297487]
 +
l-wx------ 1 root root 64 Apr  4 22:55 4 -> pipe:[297487]
 +
lr-x------ 1 root root 64 Apr  4 22:55 5 -> pipe:[297488]
 +
  l-wx------ 1 root root 64 Apr  4 22:55 6 -> pipe:[297488]
 +
  lrwx------ 1 root root 64 Apr  4 22:55 7 -> socket:[297495]
  
In other words, what pulseaudio sends via file descriptor 28 is received by speaker-test via file descriptor 7
+
Aha! file descriptor 7 is the unix socket 297495. Let's look what this is connected to:
  
  linux-fpbq:/proc/2289/fd # ll 28
+
  <abbr title="This is a prompt. The follow is a command you must enter.">#</abbr> ss -p [[piping||]] [[grep]] 297495
  lrwx------ 1 root root 64 Apr 4 15:13 28 -> socket:[114415]
+
u_str  ESTAB      0      0      /run/user/0/pulse/native '''297496'''                * '''297495'''  users:(("'''pulseaudio'''",2289,28))
 +
  u_str  ESTAB      0      0                    * '''297495'''                * '''297496''' users:(("'''speaker-test'''",15286,7))
  
When restarting speaker-test with
+
We see - the socket 297495 is connected to the socket 297496. What is written into 297495 will be readable from 297496 and the other way round. This couple of sockets connects the speaker-test process with the pulseaudio process. 2289 is pulseaudio's process id, and 15286 is the root process id of speaker-test. This system is using '''pulseaudio''' for sound which is an important information for troubleshooting sound.
strace speaker-test
 
I find a line
 
connect(7, {sa_family=AF_LOCAL, sun_path="/run/user/0/pulse/native"}, 110) = 0
 
and then file descriptor 7 plays the same role as before...
 
 
 
Look at man 2 connect and man 2 getpeername.
 
 
 
in the end solution was
 
 
 
linux-fpbq:/proc/32380/fd # ss -p | grep 186820
 
u_str  ESTAB      0      0      /run/user/0/pulse/native 186821                * 186820  users:(("pulseaudio",2289,28))
 
u_str  ESTAB      0      0                    * 186820                * 186821  users:(("speaker-test",32380,7))
 
  
 
= See also =
 
= See also =
 
* [[stRace]]
 
* [[stRace]]

Revision as of 22:10, 4 April 2015

So you want your Linux system to play sound, but it does not? Follow these steps to analyze and solve the problem:

The Methodology

If your cables and volume are okay

  • Test if your sound card driver and cables are okay; play a test sound:
speaker-test

If you hear a sound

If you hear a sound, your cables and drivers are okay.

If you do not hear a sound

If you do not hear a sound, see if you get an error message.

If you do not get an error message

If you do not get an error message, it can be a driver issue. To find out, delete all sound devices and re-create them:

tweedleburg:~ # rm /dev/dsp*
tweedleburg:~ # udevtrigger

Check again with dd if=/dev/urandom of=/dev/dsp. If you still do neither get an error message nor sound, it is most probably a driver issue. Get yourself a USB soundcard and proceed.

If you get an error message

If you get an error message like this:

tweedleburg:~ # dd if=/dev/urandom of=/dev/dsp
dd: opening `/dev/dsp': Device or resource busy

You should find out what process blocks your sound card. Do this with the command lsof (list open files):

tweedleburg:~ # lsof | grep dsp              
mplayer   18251       root    4w      CHR              14,35               14320 /dev/dsp2

You see, mplayer is blocking /dev/dsp2, you third soundcard. Now find out what soundcard you are using:

tweedleburg:~ # ll /dev/dsp*
lrwxrwxrwx 1 root root       9 Jun 21 10:38 /dev/dsp -> /dev/dsp2
crw-rw---- 1 root audio 14, 19 Jun 21 10:36 /dev/dsp1
crw-rw---- 1 root audio 14, 35 Jun 21 10:36 /dev/dsp2

/dev/dsp points to /dev/dsp2, so the soundcard you are using is blocked by mplayer. So, kill mplayer if you are sure that is what you want:

killall mplayer

Knoppix

When there is no sound under Knoppix try

/etc/init.d/alsa-utils start

strace'ing sound

You know that the command speaker-test does some test noise. To find out if pulseaudio or also is in use, issue:

# strace -s 99 -ff speaker-test

You will find a lot of lines like

[pid 15287] write(6, "W", 1)            = 1
[pid 15287] recvmsg(7, {msg_name(0)=NULL, msg_iov(1)=[{"L\0\0\0\2L\0\0\2+U\0\0\0\0\0\31vqU\0\0\0\0\0\0\0\0001TU \240\326\0\4\252\354TU \240\326\0\4\262%r\0\0\0\0\0\20\0\0r\0\0\0\0\0\2\260\220R\0\0\0\0\0\0\0\0R\0\0\0\0\0\2\260\220", 83}], msg_controllen=24, {cmsg_len=24, cmsg_level=SOL_SOCKET, cmsg_type=SCM_CREDENTIALS{pid=2289, uid=0, gid=0}}, msg_flags=0}, 0) = 83
[pid 15287] write(6, "W", 1)            = 1

So what happens here? Obviously speaker-test calls the kernel's recvmsg method. The interesting thing we get from man 2 recvmsg is that the first parameter is sockfd, the file descriptor of a socket. So it hands over a socket as a parameter. Let's look at process' file descriptors:

# cd /proc/15287/fd
ls -l
total 0
lrwx------ 1 root root 64 Apr  4 22:55 0 -> /dev/pts/4
lrwx------ 1 root root 64 Apr  4 22:55 1 -> /dev/pts/4
lrwx------ 1 root root 64 Apr  4 22:55 2 -> /dev/pts/4
lr-x------ 1 root root 64 Apr  4 22:55 3 -> pipe:[297487]
l-wx------ 1 root root 64 Apr  4 22:55 4 -> pipe:[297487]
lr-x------ 1 root root 64 Apr  4 22:55 5 -> pipe:[297488]
l-wx------ 1 root root 64 Apr  4 22:55 6 -> pipe:[297488] 
lrwx------ 1 root root 64 Apr  4 22:55 7 -> socket:[297495]

Aha! file descriptor 7 is the unix socket 297495. Let's look what this is connected to:

# ss -p | grep 297495
u_str  ESTAB      0      0      /run/user/0/pulse/native 297496                * 297495  users:(("pulseaudio",2289,28))
u_str  ESTAB      0      0                    * 297495                * 297496  users:(("speaker-test",15286,7))

We see - the socket 297495 is connected to the socket 297496. What is written into 297495 will be readable from 297496 and the other way round. This couple of sockets connects the speaker-test process with the pulseaudio process. 2289 is pulseaudio's process id, and 15286 is the root process id of speaker-test. This system is using pulseaudio for sound which is an important information for troubleshooting sound.

See also