pion / mediadevices

Go implementation of the MediaDevices API.
https://pion.ly/
MIT License
528 stars 121 forks source link

GetUserMedia call after PeerConnection.Close() fails due to driver issue. #412

Closed earlzero closed 2 years ago

earlzero commented 2 years ago

First of all, thanks for a great library!

Your environment.

If I have a PeerConnection that outlived it usefulness (failed, disconnected, etc), I'd like to close it and be able to connect to new client. When new client connects I'm getting the following error panic: invalid state: driver is already opened.

I've read that it is caused by having media tracks not being closed. I tried the following things:

It seems that there is some issue in initialization/deinitialization of device. I tried both mmal/x264 on Raspberry PI and USB camera with x264 on Quartz64.

I'm not trying to change any video settings on existing client, instead I'm trying to allow multiple clients to connect sequentially.

What did you do?

I used my own signaling server allowing to connect multiple times. I close PeerConnection when client disconnects.

What did you expect?

I expected that second call to GetUserMedia should return media tracks.

What happened?

I'm getting the following error panic: invalid state: driver is already opened.

earlzero commented 2 years ago

defer track.Close() in combination with better management for ICE candidates resolve my issue. This finally stopped the drivers and allowed me to reconnect and rerun GetUserMedia.