Bug 158979 - [snd_uadio] snd_uaudio fails to initialize built-in microphone in Logitech Webcam C160
Summary: [snd_uadio] snd_uaudio fails to initialize built-in microphone in Logitech We...
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-16 19:00 UTC by Dmitry Pryanishnikov
Modified: 2017-12-31 22:32 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Pryanishnikov 2011-07-16 19:00:17 UTC
I'm unable to record via the Logitech Webcam C160 built-in microphone. The webcam (including the mic) gets detected by the kernel:

Jul 16 20:26:03 lynx kernel: ugen4.2: <vendor 0x046d> at usbus4
Jul 16 20:26:03 lynx kernel: uaudio0: <vendor 0x046d product 0x0824, class 239/2, rev 2.00/0.10, addr 2> on usbus4
Jul 16 20:26:03 lynx kernel: uaudio0: No playback!
Jul 16 20:26:03 lynx kernel: uaudio0: Record: 48000 Hz, 1 ch, 16-bit S-LE PCM format
Jul 16 20:26:03 lynx kernel: uaudio0: No midi sequencer
Jul 16 20:26:03 lynx kernel: pcm3: <USB audio> on uaudio0

and a picture is visible via pwcview. But the microphone doesn't record and causes timeout:

AUDIODEV='/dev/dsp3' rec -c 1 -t wav - | AUDIODEV='/dev/dsp0' play -t wav -
sox: `/dev/dsp3' lsx_readbuf: Invalid argument

Kernel timeout message:

pcm3: chn_read(): pcm3:virtual:dsp3.vr0: record interrupt timeout, channel dead

The problem can also be confirmed by the lack of voice recording in the Skype. Tried this both on RELENG_8 (sources are csupped 2011-06-30) and on CURRENT (sources 2011-07-15), results are the same.

  OTOH, the microphone works quite well under Xubuntu 11.04 (Linux kernel 2.6.38-8 x86_64). Also, I've found non-trivial workaround procedure (tried under RELENG_8), see 'Fix' section, after which the microphone IS usable under the FreeBSD (including Skype)!

Fix: 

Under RELENG_8 with the virtualbox-ose-4.0.10 installed:

0) plug the camera, check that recording times out;

1) service devd stop

2) kldunload snd_uaudio

3) attach the camera to the VirtualBox instance with the running Xubuntu 11.04 (Linux kernel 2.6.38-8 x86_64). Don't run the utilities there, just observe in the logfile that Linux kernel has seen the device. A couple of seconds later, detach the camera from the VirtualBox instance.

4) service devd start

(this could fail with the message "devd already running, pid: XXXX" - confirm that process pid=XXXX does NOT exist and do 'rm /var/run/devd.pid; service devd start' - apparently a buglet in the devd).

After this, both the 'rec | play' command above and Skype start to work correctly (until the camera detachment). So it looks like some bit of device initialization that Linux kernel does but snd_uaudio doesn't.
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2011-07-16 21:09:39 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-multimedia

Over to maintainer(s).
Comment 2 Hans Petter Selasky 2011-07-17 08:45:41 UTC
Hi,

Can you try and see if any of the quirks mentioned at the following link 
helps:

http://wiki.freebsd.org/WebcamCompat

--HPS
Comment 3 Dmitry Pryanishnikov 2011-07-17 10:31:25 UTC
Hello!

>From:	Hans Petter Selasky <hselasky@c2i.net>
>Date:	Sun, 17 Jul 2011 09:45:41 +0200
>Hi,

>Can you try and see if any of the quirks mentioned at the following link
>helps:
> http://wiki.freebsd.org/WebcamCompat

  Well, it helps only partially. Indeed, after

1) plugging in my Logitech Webcam C160;
2) running 'pwcview' and exiting from it;
3) issuing 'usbconfig -d ugen4.2 do_request 0x22 0x01 0x100 0x86 0x03
0x80 0xBB 0x00'

timeout problem has gone, BUT the sensitivity of the microphone
becomes very low (I could only hear knocks on the camera hull, but
almost can't hear my own voice in the recorded samples). And
/dev/mixer3, which corresponds to the webcam microphone, doesn't
affect it's sensitivity at all:


dmitry@lynx$ mixer -f /dev/mixer3
Mixer vol      is currently set to  75:75
Mixer pcm      is currently set to  75:75

dmitry@lynx$ mixer -f /dev/mixer3 vol 100 pcm 100
Setting the mixer vol from 75:75 to 100:100.
Setting the mixer pcm from 75:75 to 100:100.

(doesn't change mic sensitivity)

dmitry@lynx$ mixer -f /dev/mixer3 vol 0 pcm 0
Setting the mixer vol from 100:100 to 0:0.
Setting the mixer pcm from 100:100 to 0:0.

(doesn't change mic sensitivity)

  OTOH after using my workaround involving attaching device to the
Linux kernel, microphone sensitivity is normal (I hear all surrounding
sounds in the room).


-- 
Sincerely, Dmytro
Comment 4 Hans Petter Selasky 2011-07-17 10:42:43 UTC
On Sunday 17 July 2011 11:31:25 Dmytro Pryanyshnikov wrote:
> Hello!
> 
> >From:	Hans Petter Selasky <hselasky@c2i.net>
> >Date:	Sun, 17 Jul 2011 09:45:41 +0200
> >Hi,
> >
> >Can you try and see if any of the quirks mentioned at the following link
> >
> >helps:
> > http://wiki.freebsd.org/WebcamCompat
> 
>   Well, it helps only partially. Indeed, after
> 
> 1) plugging in my Logitech Webcam C160;
> 2) running 'pwcview' and exiting from it;
> 3) issuing 'usbconfig -d ugen4.2 do_request 0x22 0x01 0x100 0x86 0x03
> 0x80 0xBB 0x00'
> 
> timeout problem has gone, BUT the sensitivity of the microphone
> becomes very low (I could only hear knocks on the camera hull, but
> almost can't hear my own voice in the recorded samples). And
> /dev/mixer3, which corresponds to the webcam microphone, doesn't
> affect it's sensitivity at all:
> 
> 
> dmitry@lynx$ mixer -f /dev/mixer3
> Mixer vol      is currently set to  75:75
> Mixer pcm      is currently set to  75:75
> 
> dmitry@lynx$ mixer -f /dev/mixer3 vol 100 pcm 100
> Setting the mixer vol from 75:75 to 100:100.
> Setting the mixer pcm from 75:75 to 100:100.
> 
> (doesn't change mic sensitivity)
> 
> dmitry@lynx$ mixer -f /dev/mixer3 vol 0 pcm 0
> Setting the mixer vol from 100:100 to 0:0.
> Setting the mixer pcm from 100:100 to 0:0.
> 
> (doesn't change mic sensitivity)
> 

Hi,

Can you build a kernel with "options USB_DEBUG" or when using the module to 
build add "CFLAGS+=-DUSB_DEBUG" in the sys/modules/sound/.../uaudio/Makefile ?

Then set:

sysctl hw.usb.uaudio.debug=15

Then plug the device and send resulting dmesg.

--HPS
Comment 5 Hans Petter Selasky 2011-07-17 10:48:40 UTC
On Sunday 17 July 2011 11:42:43 Hans Petter Selasky wrote:
> On Sunday 17 July 2011 11:31:25 Dmytro Pryanyshnikov wrote:
> > Hello!
> > 
> > >From:	Hans Petter Selasky <hselasky@c2i.net>
> > >Date:	Sun, 17 Jul 2011 09:45:41 +0200
> > >Hi,
> > >
> > >Can you try and see if any of the quirks mentioned at the following link
> > >
> > >helps:
> > > http://wiki.freebsd.org/WebcamCompat
> > > 
> >   Well, it helps only partially. Indeed, after
> > 
> > 1) plugging in my Logitech Webcam C160;
> > 2) running 'pwcview' and exiting from it;
> > 3) issuing 'usbconfig -d ugen4.2 do_request 0x22 0x01 0x100 0x86 0x03
> > 0x80 0xBB 0x00'
> > 
> > timeout problem has gone, BUT the sensitivity of the microphone
> > becomes very low (I could only hear knocks on the camera hull, but
> > almost can't hear my own voice in the recorded samples). And
> > /dev/mixer3, which corresponds to the webcam microphone, doesn't
> > affect it's sensitivity at all:
> > 
> > 
> > dmitry@lynx$ mixer -f /dev/mixer3
> > Mixer vol      is currently set to  75:75
> > Mixer pcm      is currently set to  75:75
> > 
> > dmitry@lynx$ mixer -f /dev/mixer3 vol 100 pcm 100
> > Setting the mixer vol from 75:75 to 100:100.
> > Setting the mixer pcm from 75:75 to 100:100.
> > 
> > (doesn't change mic sensitivity)
> > 
> > dmitry@lynx$ mixer -f /dev/mixer3 vol 0 pcm 0
> > Setting the mixer vol from 100:100 to 0:0.
> > Setting the mixer pcm from 100:100 to 0:0.
> > 
> > (doesn't change mic sensitivity)
> 
> Hi,
> 
> Can you build a kernel with "options USB_DEBUG" or when using the module to
> build add "CFLAGS+=-DUSB_DEBUG" in the
> sys/modules/sound/.../uaudio/Makefile ?
> 
> Then set:
> 
> sysctl hw.usb.uaudio.debug=15
> 
> Then plug the device and send resulting dmesg.
> 
> --HPS

HI,

If you are running this in a VM, then try using usbdump to figure out which 
control endpoint requests are issued for this device.

Probably you can make a similar usbconfig do_request line to change the 
microphone volume back to normal!

--HPS
Comment 6 Dmitry Pryanishnikov 2011-07-17 11:11:09 UTC
Hello!

On Sun, Jul 17, 2011 at 12:42 PM, Hans Petter Selasky <hselasky@c2i.net> wrote:
> Can you build a kernel with "options USB_DEBUG" or when using the module to
> build add "CFLAGS+=-DUSB_DEBUG" in the sys/modules/sound/.../uaudio/Makefile ?
>
> Then set:
>
> sysctl hw.usb.uaudio.debug=15
>
> Then plug the device and send resulting dmesg.
>
> --HPS
>

I've rebuilt just snd_uaudio module with "CFLAGS+=-DUSB_DEBUG",
reloaded it, then set "sysctl hw.usb.uaudio.debug=15" and
replugged the camera. Here is the resulting log lines:


Jul 17 13:04:44 lynx kernel: ugen4.2: <vendor 0x046d> at usbus4
Jul 17 13:04:44 lynx kernel: uaudio0: <vendor 0x046d product 0x0824,
class 239/2, rev 2.00/0.10, addr 2> on usbus4
Jul 17 13:04:44 lynx kernel: uaudio_chan_dump_ep_desc:
endpoint=0xffffff021c0e3dfd bLength=9 bDescriptorType=5
Jul 17 13:04:44 lynx kernel: bEndpointAddress=134 bmAttributes=0x5
Jul 17 13:04:44 lynx kernel: wMaxPacketSize=196 bInterval=4
Jul 17 13:04:44 lynx kernel: bRefresh=0 bSynchAddress=0
Jul 17 13:04:44 lynx kernel: uaudio_chan_fill_info_sub: FREQ_CONTROL
Jul 17 13:04:44 lynx kernel: uaudio_chan_fill_info_sub: Sample rate =
48000Hz, channels = 1, bits = 16, format = 16-bit S-LE PCM
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info: found AC header,
vers=100, len=29
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info: Maximum ID=3
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info: id 3:
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info:  - AC_OUTPUT
type=UAT_STREAM src=5
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info: Inputs to this ID are:
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info: Outputs from this ID are:
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info: id 1:
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info:  - AC_INPUT
type=UATI_MICROPHONE
Jul 17 13:04:44 lynx kernel: uaudio_mixer_dump_cluster: cluster:
bNrChannels=0 iChannelNames=1 wChannelConfig=0x0000:
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info: Inputs to this ID are:
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info:   -- ID=1
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info: Outputs from this ID are:
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info: id=3 subtype=3
Jul 17 13:04:44 lynx kernel: uaudio_mixer_add_output: bTerminalId=3
wTerminalType=0x0101 bAssocTerminal=1 bSourceId=5 iTerminal=0
Jul 17 13:04:44 lynx kernel: uaudio_mixer_fill_info: id=1 subtype=2
Jul 17 13:04:44 lynx kernel: uaudio_mixer_add_input: bTerminalId=1
wTerminalType=0x0201 bAssocTerminal=0 bNrChannels=1 wChannelConfig=0
iChannelNames=0
Jul 17 13:04:44 lynx kernel: uaudio_attach: audio rev 1.00
Jul 17 13:04:44 lynx kernel: uaudio_attach: 0 mixer controls
Jul 17 13:04:44 lynx kernel: uaudio0: No playback!
Jul 17 13:04:44 lynx kernel: uaudio0: Record: 48000 Hz, 1 ch, 16-bit
S-LE PCM format
Jul 17 13:04:44 lynx kernel: uaudio0: No midi sequencer
Jul 17 13:04:44 lynx kernel: uaudio_attach: doing child attach
Jul 17 13:04:44 lynx kernel: pcm3: <USB audio> on uaudio0
Jul 17 13:04:44 lynx kernel: uaudio_attach_sub: emulating master volume
Jul 17 13:04:44 lynx kernel: uaudio_mixer_init_sub:
Jul 17 13:04:44 lynx kernel: uaudio_chan_init: endpoint=0x86,
speed=48000, iface=3 alt=4
Jul 17 13:04:44 lynx kernel: uaudio_set_speed: endpt=134 speed=48000
Jul 17 13:04:44 lynx kernel: uaudio_chan_init: fps=1000 sample_rem=0





-- 
Sincerely, Dmytro
Comment 7 Dmitry Pryanishnikov 2011-07-17 11:33:24 UTC
On Sun, Jul 17, 2011 at 12:48 PM, Hans Petter Selasky <hselasky@c2i.net> wrote:
>
> HI,
>
> If you are running this in a VM, then try using usbdump to figure out which
> control endpoint requests are issued for this device.
>
> Probably you can make a similar usbconfig do_request line to change the
> microphone volume back to normal!

  Yes, I've recorded packet interchange on the USB bus during the
(device) <-> (Linux kernel in the VirtualBox) data exchange with the
command:

usbdump -i usbus4 -s 0 -w 20110717_1320.dmp

and placed the resulting file at

https://sites.google.com/site/lynxripe/freebsd/pr/158979/20110717_1320.dmp

Alas, I haven't got sufficient USB protocol knowlege in order to
comprehend this data ;(

>
> --HPS
>



-- 
Sincerely, Dmytro
Comment 8 Hans Petter Selasky 2011-07-17 12:01:57 UTC
On Sunday 17 July 2011 12:33:24 Dmytro Pryanyshnikov wrote:
> On Sun, Jul 17, 2011 at 12:48 PM, Hans Petter Selasky <hselasky@c2i.net> 
wrote:
> > HI,
> > 
> > If you are running this in a VM, then try using usbdump to figure out
> > which control endpoint requests are issued for this device.
> > 
> > Probably you can make a similar usbconfig do_request line to change the
> > microphone volume back to normal!
> 
>   Yes, I've recorded packet interchange on the USB bus during the
> (device) <-> (Linux kernel in the VirtualBox) data exchange with the
> command:
> 
> usbdump -i usbus4 -s 0 -w 20110717_1320.dmp
> 
> and placed the resulting file at
> 
> https://sites.google.com/site/lynxripe/freebsd/pr/158979/20110717_1320.dmp
> 
> Alas, I haven't got sufficient USB protocol knowlege in order to
> comprehend this data ;(
> 

Hi,

I think one of the following requests should do the trick. Please let me know 
the test result:

usbconfig -d X.Y do_request 0x21 0x01 0x0200 0x0502 0x0002 0x01 0x1b
usbconfig -d X.Y do_request 0x21 0x01 0x0200 0x0502 0x0002 0x00 0x1b

--HPS
Comment 9 Dmitry Pryanishnikov 2011-07-17 16:08:13 UTC
On Sun, Jul 17, 2011 at 2:01 PM, Hans Petter Selasky <hselasky@c2i.net> wrote:
> I think one of the following requests should do the trick. Please let me know
> the test result:

Yes, that's it! So, after plugging the device in, the following steps
make the microphone working with the normal sensitivity:

1) launch and exit pwcview;

2) usbconfig -d ugen4.2 do_request 0x22 0x01 0x100 0x86 0x03 0x80 0xBB 0x00

3) one of the following (I don't hear differences - either command
"unlocks" the microphone sensitivity):

> usbconfig -d X.Y do_request 0x21 0x01 0x0200 0x0502 0x0002 0x01 0x1b
> usbconfig -d X.Y do_request 0x21 0x01 0x0200 0x0502 0x0002 0x00 0x1b
>
> --HPS
>



-- 
Sincerely, Dmytro
Comment 10 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:13 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped