Unity-Technologies / com.unity.webrtc

WebRTC package for Unity
Other
739 stars 185 forks source link

[BUG]: Track is disposed after calling ReplaceTrack #912

Closed kayy closed 8 months ago

kayy commented 1 year ago

Package version

3.0.0-pre.5

Environment

* OS: Windows 11
* Unity version: 2020.3.45

Steps To Reproduce

Current Behavior

After a few seconds the stream gets frozen

Expected Behavior

The stream remains active

Anything else?

The initial track created with MediaStream.AddTrack is cached internally in a HashSet cacheTracks. Thus this will run without any issues.
Replacing a track breaks this behaviour. Thus the caller need to hold a reference to avoid disposing the track.

Underlying use case: Dynamic resizing of tracks in response to size changes in the HTML part. Calling ReplaceTrack method avoids renegotiation and the tracks are created on the fly without any need to to take care them.

kayy commented 1 year ago

The following patch modifies the ReplaceTrackSample.cs in that stream2 is created on the fly. After 1-2 seconds it freezes.

Maybe this was intentionally and by design, but in this case this should be documented and MediaStream.AddTrack should behave the same way. ReplaceTrackSample_stream2-local.patch

karasusan commented 1 year ago

memo: WRS-478

karasusan commented 9 months ago

@kayy I am sorry to reply lately. I checked the sample code. As you said, this behaviour is by design.

I would like to add comments to MediaStream class and Camera.CaptureStreamTrack method.

karasusan commented 8 months ago

@kayy Can I close this issue?

kayy commented 8 months ago

@kayy Can I close this issue?

Yes. Adding some comments is fine

karasusan commented 8 months ago