Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB camera and headset do not work #811

Open
Aleksa2022 opened this issue Feb 27, 2024 · 27 comments
Open

USB camera and headset do not work #811

Aleksa2022 opened this issue Feb 27, 2024 · 27 comments

Comments

@Aleksa2022
Copy link

USB headset and USB camera do not want to work properly.
In the headset the sound comes with artifacts - gurgling, wheezing, etc. Through the mini-jack 3.5 mm everything works normally. The camera does not work at all.
I thought updating the ports would help - I did, it didn't help.

These errors were recorded in the logs:
Wa(03) usbArb USBGL: Failed to open '/sys/bus/usb/devices/8-1/serial', error(0x2).
Wa(03) usbArb USBGL: Failed to open '/sys/bus/usb/devices/8-1/serial', error(0x2).
Wa(03) usbArb USBGL: Failed to open '/sys/bus/usb/devices/1-3/manufacturer', error(0x2).

Added to buildtime:
MOUNT_1="usbdevfs /proc/bus/usb usbdevfs devmode=0666,noauto 0 0 0"

That didn't help either - the camera doesn't work, it behaves as if it's not alive at all. I plugged it into another port and the system froze completely - it's the first time I've seen such a trick.

There is no USB: /proc/bus/ - nothing mounted. The camera seems to be connected:
Bus 001 Device 002: ID 046d:0817 Logitech, Inc.

In the list of USB devices, by camera shows this:
T: Bus=01 Lev=01 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#= 2 Spd=480 MxCh= 0
D: Ver= 2.00 Cls=ef(misc ) Sub=02 Prot=01 MxPS=64 #Cfgs= 1
P: Vendor=046d ProdID=0817 Rev=00.10
S: SerialNumber=83177780
C: #Ifs= 2 Cfg#= 1 Atr=80 MxPwr=500mA
I: If#=0x0 Alt= 0 #EPs= 1 Cls=0e(video) Sub=01 Prot=00 Driver=(none)
I: If#=0x1 Alt= 0 #EPs= 0 Cls=0e(video) Sub=02 Prot=00 Driver=(none)

There are no problems with this one:
Bus 008 Device 003: ID 04ca:009c Lite-On Technology Corp. USB Keyboard
Bus 008 Device 002: ID 04ca:008a Lite-On Technology Corp. USB Optical Mouse

T: Bus=08 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=1.5 MxCh= 0
D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=04ca ProdID=008a Rev=01.00
S: Manufacturer=PixArt
S: Product=USB Optical Mouse
C: #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA
I: If#=0x0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=usbhid

T: Bus=08 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 3 Spd=1.5 MxCh= 0
D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=04ca ProdID=009c Rev=02.65
S: Manufacturer=Lite-On Technology Corp
S: Product=USB Keyboard
C: #Ifs= 2 Cfg#= 1 Atr=a0 MxPwr=100mA
I: If#=0x0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=01 Driver=usbhid
I: If#=0x1 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=00 Prot=00 Driver=usbhid

What else can I do? I can't think of anything practical to do yet.....
Kernel: 6.1.78
Vmview: 8.12

@Aleksa2022
Copy link
Author

I solved the USB camera problem by updating the firmware and adding a line to buildtime:
USB_MOUNT_DIR="/proc/bus/usb"
But, it didn't solve the problem with sound through USB-headset - there are still artifacts - sound is gurgling and lags behind (sometimes it goes exactly with video, sometimes it lags behind by some milliseconds). If you just switch to a regular headset with a 3.5 mm plug, the problems disappear immediately - the sound works perfectly.

I haven't thought of anything else to try yet....

@Maksim-Garikov
Copy link

Hello!
I've also noticed some interesting behavior. When connecting USB headphones or a webcam, the microphone and camera work, but there is no sound. However, with 3.5mm jack headphones, the situation is reversed. The sound works, but the microphone does not.

Currently, I'm trying to fix the audio output through these two commands. I'm attaching them here in case you come up with a solution. They need to be added to thinstation.conf.buildtime.

pactl set-card-profile 0 "output:analog-stereo+input:analog-stereo"
pactl set-sink-port "alsa_output.pci-0000_00_1b.0.analog-stereo" "analog-output-headphones"

@Thinstation
Copy link
Collaborator

Have a look at this ts/build/packages/alsa/build/extra/etc/init.d/audio

This script is executed once during system init. Possibly you could write a rule that will re-execute it when a usb headphone is plugged/unplugged.

@Aleksa2022
Copy link
Author

pactl set-card-profile 0 "output:analog-stereo+input:analog-stereo" pactl set-sink-port "alsa_output.pci-0000_00_1b.0.analog-stereo" "analog-output-headphones"

Hello!
Didn't help. When assembling, errors were generated:
Connection failure: Connection refused
pa_context_connect() failed: Connection refused
The image assembled normally, but the sound is with artifacts. Not only that, maybe now I paid special attention to it, - video is also slowed down.
Video from webcam works fine. But video, for example, from youtube, with an analog headset connected works fine - both video and sound.
The error pa_context_connect() failed is clear:
"The regular systemctl, the PID 1, indeed cannot access the environement variables of the current user when launching a service. Since pactl relies on those variables to find what instance of pulseaudio it needs to connect to, it is unable to do so when launched though a service."
If we use this solution, we need to insert a script launch by event somewhere. Although, in our build everything works under root - in this case we will have to add something else.
In general, everything is interesting because in old builds USB-headsets did not work at all. Now they work, shitty, but they work. Progress is evident! If only all this beauty worked properly - it would be worth it.

@Maksim-Garikov
Copy link

I noticed a strange thing. Before this, my USB_MOUNT_DIR parameter was set to "/mnt/usbdevice/sda1." I changed it to "/proc/bus/usb," as you have, and this miracle started working. The sound appeared in the USB headphones, the microphone was functioning, and the webcam was working. However, after a reboot, everything stopped working. Moreover, the boot is through PXE, so each time there's a new session on boot. This was also the case when I initially set the parameter to "/mnt/usbdevice/sda1," but it stopped working after a reboot.

It might indeed be worth trying to fix ts/build/packages/alsa/build/extra/etc/init.d/audio.

@Aleksa2022
Copy link
Author

My parameters are as follows:
AUDIO_LEVEL=90
MIC_LEVEL=90


Other parameters


USB_MOUNT_DIR="/mnt/usbdevice"
USB_MOUNT_DIR="/proc/bus/usb"

@Aleksa2022
Copy link
Author

In /packages/base/base/etc/udev/rules.d I added a line for my headset, similar to other devices described there. SUBSYSTEM=="usb" etc. I tried specifying a reference to /etc/init.d/audio
RUN+="/etc/init.d/audio"
didn't help. I made my own file with parameters and specified in udev:

pactl set-card-profile 0 "output:analog-stereo+input:analog-stereo"
pactl set-sink-port "alsa_output.pci-0000_00_1b.0.analog-stereo" "analog-output-headphones".

Didn't help either.
The changes I made had no effect on the result - video and sound are with artifacts, and even slower than they should be.
I don't understand what kind of retarder is glued on. Video goes as soon as I disconnect the USB headset and connect the analog headset, everything is fine. I switch back to USB, without stopping the video, the brakes and gurgling come back again.

@Maksim-Garikov
Copy link

Are changes to /build/packages/alsa/build/extra/etc/init.d/audio really affecting the image? I made edits to the code, but I don't see any changes. Could there be any dependency on the pulseaudio package in ThinStation?

@Aleksa2022
Copy link
Author

God is in you - how can pulseaudio affect the image? Sound quality - yes, its presence - too, but it has nothing to do with the picture.
These are system components and everyone can bring problems and joys from themselves. Sound - pulseaudio, alsa. That's the minimum.
Images, video - Xorg, etc.
Although even here everything is not so clear-cut - one can influence and interfere with the other. I have already had the good fortune to encounter such things - it's Linux! - It's a big constructor with a lot of stuff. :-)

@Maksim-Garikov
Copy link

Yes, I understand. It's just that my situation is the opposite. The webcam and microphone are working, but there's no sound in the headphones. However, if I connect headphones via the 3.5mm jack, the sound works but not the microphone. Are you using 6.2-stable?
The video camera, by the way, started working after adding parameters to thinstation.conf.buildtime is USB_SYNC_ON and USB_MOUNT_DIR.

@Maksim-Garikov
Copy link

Forgot the mentioned parameter USE_XRANDR

@Aleksa2022
Copy link
Author

Yes, I'm using 6.2-stable. I thought maybe there was something in the 6.1 kernel that caused these problems, but no. Rolled the kernel back to 5.15.150, updated the firmware and reassembled - everything is exactly the same.
I tweaked the kernel config:

  • Generic Driver Options
    --Automount devtmpfs at /dev, after the kernel mounted the rootfs
  • Advanced Linux Sound Architecture
    -- Support old ALSA API
    -- ALSA for SoC audio support
    Thought maybe this would help. After the build I got an error. I must have twisted it somewhere...
    I didn't twist XRANDR - it works as it is. Although, 2 years ago I experimented with it, but I didn't get much improvement and left it.
    By the way, I noticed this: on kernel 6.1, if you take the headset out of the 3.5 mm jack and insert USB, the switching was noticeably faster than on 5.15. On kernel 5.15 the switching happened in about 5-7 seconds, on 6.1 - about 1-3 seconds. But! Absolutely the same brakes - just turned on the USB, as soon as you turn on the USB, the playback speed immediately drops sharply (about 1.5-2 times slower) - I specially turned on fast videos with Aria songs, where these slowdowns are very noticeable. This is both on 6.1 and 5.15.
    It feels like some kind of flow limiter or some kind of retarder is turned on when the headset is connected. The camera works fine - it gives 15 FPS on tests (normal), but the sound is a mess.

@Aleksa2022
Copy link
Author

ALSA has a file for configuring USB-Audio!

/alsa/lib/alsa/cards/USB_Audio.conf

Here you can write rules for working with USB-devices. I added a rule for my headset Logitech Clear Chat Comfort USB Headset. After the build it started working better. Artifacts are there, slowdowns are there. Ugly, but not as ugly. Now "wave-like" slowdowns with artifacts - then slowed down, then at normal speed. There are fewer artifacts.
Still looking suspiciously at the bitrate of the audio stream. But I'm not sure.
I need to dig some more... There is a feeling that some small thing is missing.

@Maksim-Garikov
Copy link

Please advise, in which section should I add the device name in the code? Is it in USB-Audio.pcm.iec958_device? And should I enter the device name as it appears in lsusb output?

@Maksim-Garikov
Copy link

Maksim-Garikov commented Mar 6, 2024

Or you named it separately and added parameters that are present in the config. For example:

USB-Audio.pcm.default."YourUSBDevice" {
@args [ CARD ]
@args.CARD { type string }

@Doncuppjr
Copy link
Collaborator

Doncuppjr commented Mar 6, 2024 via email

@Maksim-Garikov
Copy link

@Doncuppjr
Hello, Donald.
I'm trying to set up sound, microphone, and video playback in the ThinStation image. After that, I test it on a remote desktop through Citrix. I added specific parameters to thinstation.conf.buildtime for sound, video, and microphone redirection.

ICA_AUDIO=ON
ICA_AUDIO_QUALITY=High
ICA_WFCLIENT_AllowAudioInput=True
ICA_WFCLIENT_HDXWebCamDevice=True

If sound and microphone work in USB headphones within the ThinStation image, everything works on the remote desktop. However, I managed to configure sound output twice after changing the USB_MOUNT_DIR parameter, but after a reboot, the settings reset, and sound output stops working. The image is loaded via PXE.

Can you advise why the ThinStation settings reset after a reboot, causing the sound output to stop working, even after configuring the parameters?

@Thinstation
Copy link
Collaborator

Thinstation commented Mar 6, 2024 via email

@Maksim-Garikov
Copy link

@Doncuppjr
What parameter needs to be added/modified to enable sound output on USB headphones and make it work consistently? Or what should be added to the ALSA package to ensure continuous functionality of sound on USB headphones? And why did I only succeed in achieving sound output twice after changing a parameter in thinstation.conf.buildtime? After modifying the parameter, the image build remains unchanged after loading it onto the TFTP server, so sound output should work after system reboot. However, it behaves differently after reboot.

@Thinstation
Copy link
Collaborator

Thinstation commented Mar 6, 2024 via email

@Aleksa2022
Copy link
Author

Please advise, in which section should I add the device name in the code? Is it in USB-Audio.pcm.iec958_device? And should I enter the device name as it appears in lsusb output?

I added my device to the same place where the other "Logitec" devices were listed, I got the name from lsusb.

@Aleksa2022
Copy link
Author

If your using freerdp with usb redirection, perhaps that is the issue. Instead of just sending audio, it might be sending the whole usb stream and letting the server do the conversion. Maybe there is a filter that can be enabled in freerdp to prevent that.
For testing I would recommend trying to playback some local media without making a freerdp connection.

No, I'm using VMware Horizon. I can assume that RTAV is involved in this problem. Previously, my USB headset did not work at all. Now I've decided to do a little bit more work and started looking into the problem.
That's an interesting idea about redirecting the entire stream. I suppose it could be like that. Although, VMware must have thought about thread separation and redirection of USB, MMR, etc. should not conflict or create mutual problems....

@Doncuppjr
Copy link
Collaborator

Doncuppjr commented Mar 7, 2024 via email

@Aleksa2022
Copy link
Author

The USB_MOUNT_DIR only comes into play when mounting usb storage devices, and then only if the automount package is included. Perhaps restarting the application is producing the difference, not the changes you are making.

Yes, but I, for example, did not take this parameter from the sky - in a number of sources I came across, it was just stated that such a mounting solves the problem with video cameras. As you can see, to a certain extent it does.

@Aleksa2022
Copy link
Author

I have errors in the log
RTAV: ConnectPulseAudioDaemon - pa_context_connect() failed
I'm trying to do something about it now. Default_context was disabled in the configs. I enabled it and changed some parameters at the same time.
By the way, pulseaudio is very outdated. According to the existing port settings, I was able to update it to 14.2. Further, the ./configure script is excluded and meson should be used instead. I haven't managed to get the build and installation with meson yet - I don't understand something and I'm doing something wrong.
Here I tried to raise the version to at least 15:

+ build
+ cd pulseaudio-15.0
+ meson setup

ERROR: Must specify at least one directory name.
=======> ERROR: Building '/ts/ports/opt/pulseaudio/pulseaudio/pulseaudio#15.0-1.pkg.tar.xz' failed.

@Aleksa2022
Copy link
Author

Changed parameters in pulseaudio configs: enabled default_context, increased parameters of working with fragments now artifacts are almost gone, but the speed (subjectively) is about 0.8-0.9 from the actual one when connecting a USB headset.
I still don't understand what else is interfering.
I will try to reduce the realtime-priority value - now it is 5, I will try to set it to 3. Or turn on high-priority.

@Aleksa2022
Copy link
Author

Changing these parameters did nothing - nothing changed at all.
Looked in the logs again:

In(05) host-13361 RTAV: Init - Starting audio device monitor
2024-03-07T07:45:17.722Z Wa(03) host-13361 RTAV: ConnectPulseAudioDaemon - pa_context_connect() failed
2024-03-07T07:45:17.722Z Wa(03) host-13361 RTAV: StartPulseAudioDaemon - Start PulseAudio daemon failed
2024-03-07T07:45:17.722Z Wa(03) host-13361 RTAV: Init - Failed to init mAudioDevMonitor
In(05) host-13361 RTAV: Init - Started audio device monitor
In(05) host-13361 RTAV: Start - The thread starts successfully: 7FEAC40022D0.
In(05) host-13361 RTAV: Init - Starting UI config monitor
In(05) host-13361 RTAV: Init: Monitor file path: /home/mon/.vmware.
In(05)+ host-13361 
In(05) host-13361 RTAV: Start - The thread starts successfully: 7FEAC00021F8.
In(05) host-13361 RTAV: StartMonitoring: start monitoring.
In(05) host-13361 RTAV: Init - Started ConfigMonitor
In(05) host-13361 RTAV: Start - The thread starts successfully: 7FEAC0003670.
In(05) host-13361 RTAV: Init - Started video device monitor
In(05) host-13375 RTAV: DevChangeEventProcessThreadCB - Audio device changed
In(05) host-13361 RTAV: Start - The thread starts successfully: 7FEAC4003930.

I rewired this - I had a USB headset first, then took it out and plugged in an analog headset.
So far I've run out of ideas on what else to tweak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants