UVC Camera freezes when livestreaming
Hi.
I am working with UVC Camera and SRT protocol.
On Samsung S22 Ultra, everything works fine without any additional setup (audio + video with 30fps).
But when running on Samsung A35 5G, it freezes as soon as it starts streaming and the signal is not pushed to the server.
Both devices are running Android 14, API 34
If I set audioDeviceInfo with type AudioDeviceInfo.TYPE_BUILTIN_MIC, it works fine (using the phone's microphone).
Because I want to use UVC Camera audio, I set audioDeviceInfo with type AudioDeviceInfo.TYPE_USB_DEVICE) but it also freezes as soon as it starts streaming as above.
Please help me with the solution.
Here is the code I used:
private fun changeVideoSource() {
genericStream.changeVideoSource(CameraUvcSource())
val audioManager = context?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager ?: return
val devices = audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)
var adiSelected: AudioDeviceInfo? = null
for (adi in devices) {
if (adi.type == AudioDeviceInfo.TYPE_USB_DEVICE) {
adiSelected = adi
Log.e("AudioDeviceInfo_SELECTED", "id: ${adi.id}, type: ${adi.type}, address: ${adi.address}, productName: ${adi.productName}, isSource: ${adi.isSource}, isSink: ${adi.isSink}")
} else {
Log.e("AudioDeviceInfo", "id: ${adi.id}, type: ${adi.type}, address: ${adi.address}, productName: ${adi.productName}, isSource: ${adi.isSource}, isSink: ${adi.isSink}")
}
}
adiSelected?.let {
(genericStream.audioSource as MicrophoneSource).setPreferredDevice(adiSelected)
}
}
And logs:
11:36:21.993 AudioDeviceInfo com.app.uvc id: 15, type: 15, address: bottom, productName: SM-A356E, isSource: true, isSink: false
11:36:21.993 AudioDeviceInfo com.app.uvc id: 16, type: 18, address: , productName: SM-A356E, isSource: true, isSink: false
11:36:21.993 AudioDeviceInfo com.app.uvc id: 17, type: 15, address: back, productName: SM-A356E, isSource: true, isSink: false
11:36:21.993 AudioDeviceInfo com.app.uvc id: 21, type: 25, address: 0, productName: SM-A356E, isSource: true, isSink: false
11:36:21.993 AudioDeviceInfo_SELECTED com.app.uvc E id: 205, type: 11, address: card=3;device=0, productName: USB-Audio - MS2109, isSource: true, isSink: false
Hello,
If you means that the video freeze, I can't do so much about it. The USB library used is here: https://github.com/shiyinghan/UVCAndroid
Possible test:
- Try open the USB camera after open the microphone. Since the microphone is opened when you call startStream/startRecord (maybe the freeze is produced in that moment), you can try change the video source to camera1 and usb again after call that method to refresh the video source and check if this solve the freeze.
Hi.
Possible test: Try open the USB camera after open the microphone. Since the microphone is opened when you call startStream/startRecord (maybe the freeze is produced in that moment), you can try change the video source to camera1 and usb again after call that method to refresh the video source and check if this solve the freeze.
I tried that but it still doesn't work.
If I setPreferredDevice for MicrophoneSource to AudioDeviceInfo.TYPE_BUILTIN_MIC or AudioDeviceInfo.TYPE_BLUETOOTH_SCO everything works fine.
It just freezes the video when I set the source to AudioDeviceInfo.TYPE_USB_DEVICE
Crash? Can you share the crash logcat?
Crash? Can you share the crash logcat?
Sorry, It's not a crash, just a video freeze error. Logs:
@pedroSG94 Hi.
Before calling fun genericStream.startStream(), the image signal is still transmitted normally.
Only when calling genericStream.startStream() does the image freeze (no longer receiving signal from the USB camera).
The log then only shows sending Audio packet (wrote AUDIO packet)
So I think the problem may come from RootEncoder library.
Currently I am experiencing this error on my Samsung A35 5G device (Android 14)
Hello,
As you reported before, if you never change the AudioDeviceInfo, the preview never freeze. So it seem a problem with the camera when you change the AudioDeviceInfo with the USB device.