pion / mediadevices

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

Fix closing a camera not closing the associated track #414

Closed EmrysMyrddin closed 2 years ago

EmrysMyrddin commented 2 years ago

Description

Closing a record session on macOS does not close the reader.

This PR fixes this by closing the channel used to read incoming video frames directly in the Close function. Calling it in the data callback is not working because since the record session is closed, the callback will never be called again. So the reader will indefinitely wait for a incoming frame/the channel to be closed, which will never happen.

By fixing this, i have also discover a bug, where closing a peer connection with some tracks already closed triggers a panic due to the stop mechanism.

Reference issue

Fixes #379

codecov[bot] commented 2 years ago

Codecov Report

Merging #414 (b50fce7) into master (d038133) will decrease coverage by 0.02%. The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master     #414      +/-   ##
==========================================
- Coverage   47.23%   47.21%   -0.03%     
==========================================
  Files          67       67              
  Lines        4452     4454       +2     
==========================================
  Hits         2103     2103              
- Misses       2224     2226       +2     
  Partials      125      125              
Impacted Files Coverage Δ
track.go 19.93% <0.00%> (-0.13%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d038133...b50fce7. Read the comment docs.