From nobody@FreeBSD.org  Sat Jul 16 17:54:12 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 65DC4106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 16 Jul 2011 17:54:12 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 3B2778FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 16 Jul 2011 17:54:12 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p6GHsBfs005075
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 16 Jul 2011 17:54:11 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p6GHsBnl005063;
	Sat, 16 Jul 2011 17:54:11 GMT
	(envelope-from nobody)
Message-Id: <201107161754.p6GHsBnl005063@red.freebsd.org>
Date: Sat, 16 Jul 2011 17:54:11 GMT
From: Dmitry Pryanishnikov <lynx.ripe@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: snd_uaudio fails to initialize built-in microphone in Logitech Webcam C160
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         158979
>Category:       kern
>Synopsis:       [snd_uadio] snd_uaudio fails to initialize built-in microphone in Logitech Webcam C160
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-multimedia
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 16 18:00:17 UTC 2011
>Closed-Date:    
>Last-Modified:  Sun Jul 17 15:10:08 UTC 2011
>Originator:     Dmitry Pryanishnikov
>Release:        RELENG_8 (also tried on fresh CURRENT)
>Organization:
Home
>Environment:
FreeBSD lynx.homenet 8.2-STABLE FreeBSD 8.2-STABLE #0: Thu Jun 30 02:18:39 EEST 2011     dmitry@lynx.homenet:/databig/obj/databig/ftp/RELENG_8/src.110630/sys/lynx  amd64

>Description:
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)!
>How-To-Repeat:

>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.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-multimedia 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Jul 16 20:09:39 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=158979 

From: Hans Petter Selasky <hselasky@c2i.net>
To: freebsd-bugs@freebsd.org,
 FreeBSD-gnats-submit@freebsd.org
Cc:  
Subject: Re: kern/158979: [snd_uadio] snd_uaudio fails to initialize built-in microphone in Logitech Webcam C160
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
 
 --HPS

From: Hans Petter Selasky <hselasky@c2i.net>
To: Dmytro Pryanyshnikov <lynx.ripe@gmail.com>
Cc: bug-followup@freebsd.org
Subject: Re: kern/158979: [snd_uadio] snd_uaudio fails to initialize built-in microphone in Logitech Webcam C160
Date: Sun, 17 Jul 2011 11:42:43 +0200

 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

From: Hans Petter Selasky <hselasky@c2i.net>
To: Dmytro Pryanyshnikov <lynx.ripe@gmail.com>
Cc: bug-followup@freebsd.org
Subject: Re: kern/158979: [snd_uadio] snd_uaudio fails to initialize built-in microphone in Logitech Webcam C160
Date: Sun, 17 Jul 2011 11:48:40 +0200

 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

From: Dmytro Pryanyshnikov <lynx.ripe@gmail.com>
To: bug-followup@FreeBSD.org, lynx.ripe@gmail.com, 
	Hans Petter Selasky <hselasky@c2i.net>
Cc:  
Subject: Re: kern/158979: [snd_uadio] snd_uaudio fails to initialize built-in
 microphone in Logitech Webcam C160
Date: Sun, 17 Jul 2011 12:31:25 +0300

 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

From: Dmytro Pryanyshnikov <lynx.ripe@gmail.com>
To: Hans Petter Selasky <hselasky@c2i.net>
Cc: bug-followup@freebsd.org
Subject: Re: kern/158979: [snd_uadio] snd_uaudio fails to initialize built-in
 microphone in Logitech Webcam C160
Date: Sun, 17 Jul 2011 13:11:09 +0300

 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

From: Dmytro Pryanyshnikov <lynx.ripe@gmail.com>
To: Hans Petter Selasky <hselasky@c2i.net>
Cc: bug-followup@freebsd.org
Subject: Re: kern/158979: [snd_uadio] snd_uaudio fails to initialize built-in
 microphone in Logitech Webcam C160
Date: Sun, 17 Jul 2011 13:33:24 +0300

 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

From: Hans Petter Selasky <hselasky@c2i.net>
To: Dmytro Pryanyshnikov <lynx.ripe@gmail.com>
Cc: bug-followup@freebsd.org
Subject: Re: kern/158979: [snd_uadio] snd_uaudio fails to initialize built-in microphone in Logitech Webcam C160
Date: Sun, 17 Jul 2011 13:01:57 +0200

 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

From: Dmytro Pryanyshnikov <lynx.ripe@gmail.com>
To: Hans Petter Selasky <hselasky@c2i.net>
Cc: bug-followup@freebsd.org
Subject: Re: kern/158979: [snd_uadio] snd_uaudio fails to initialize built-in
 microphone in Logitech Webcam C160
Date: Sun, 17 Jul 2011 18:08:13 +0300

 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
>Unformatted:
