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

UVC Camera freezes when livestreaming #1759

Open
cryinrain69 opened this issue Mar 18, 2025 · 5 comments
Open

UVC Camera freezes when livestreaming #1759

cryinrain69 opened this issue Mar 18, 2025 · 5 comments

Comments

@cryinrain69
Copy link

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
@pedroSG94
Copy link
Owner

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.

@cryinrain69
Copy link
Author

cryinrain69 commented Mar 18, 2025

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

@pedroSG94
Copy link
Owner

Crash? Can you share the crash logcat?

@cryinrain69
Copy link
Author

Crash? Can you share the crash logcat?

Sorry, It's not a crash, just a video freeze error.
Logs:

log_uvc.txt

@cryinrain69
Copy link
Author

@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)

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

2 participants