Merge pull request #1153 from Bond-009/dlna

Check if disposed first
pull/1158/head
Joshua M. Boniface 6 years ago committed by GitHub
commit 31607fbb37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -102,9 +102,10 @@ namespace Emby.Dlna.PlayTo
{ {
_sessionManager.ReportSessionEnded(_session.Id); _sessionManager.ReportSessionEnded(_session.Id);
} }
catch catch (Exception ex)
{ {
// Could throw if the session is already gone // Could throw if the session is already gone
_logger.LogError(ex, "Error reporting the end of session {Id}", _session.Id);
} }
} }
@ -112,20 +113,14 @@ namespace Emby.Dlna.PlayTo
{ {
var info = e.Argument; var info = e.Argument;
info.Headers.TryGetValue("NTS", out string nts); if (!_disposed
&& info.Headers.TryGetValue("USN", out string usn)
if (!info.Headers.TryGetValue("USN", out string usn)) usn = string.Empty; && usn.IndexOf(_device.Properties.UUID, StringComparison.OrdinalIgnoreCase) != -1
&& (usn.IndexOf("MediaRenderer:", StringComparison.OrdinalIgnoreCase) != -1
if (!info.Headers.TryGetValue("NT", out string nt)) nt = string.Empty; || (info.Headers.TryGetValue("NT", out string nt)
&& nt.IndexOf("MediaRenderer:", StringComparison.OrdinalIgnoreCase) != -1)))
if (usn.IndexOf(_device.Properties.UUID, StringComparison.OrdinalIgnoreCase) != -1 &&
!_disposed)
{ {
if (usn.IndexOf("MediaRenderer:", StringComparison.OrdinalIgnoreCase) != -1 || OnDeviceUnavailable();
nt.IndexOf("MediaRenderer:", StringComparison.OrdinalIgnoreCase) != -1)
{
OnDeviceUnavailable();
}
} }
} }
@ -612,22 +607,34 @@ namespace Emby.Dlna.PlayTo
public void Dispose() public void Dispose()
{ {
if (!_disposed) Dispose(true);
{ GC.SuppressFinalize(this);
_disposed = true; }
_device.PlaybackStart -= _device_PlaybackStart; protected virtual void Dispose(bool disposing)
_device.PlaybackProgress -= _device_PlaybackProgress; {
_device.PlaybackStopped -= _device_PlaybackStopped; if (_disposed)
_device.MediaChanged -= _device_MediaChanged; {
//_deviceDiscovery.DeviceLeft -= _deviceDiscovery_DeviceLeft; return;
_device.OnDeviceUnavailable = null; }
if (disposing)
{
_device.Dispose(); _device.Dispose();
} }
_device.PlaybackStart -= _device_PlaybackStart;
_device.PlaybackProgress -= _device_PlaybackProgress;
_device.PlaybackStopped -= _device_PlaybackStopped;
_device.MediaChanged -= _device_MediaChanged;
_deviceDiscovery.DeviceLeft -= _deviceDiscovery_DeviceLeft;
_device.OnDeviceUnavailable = null;
_device = null;
_disposed = true;
} }
private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private static readonly CultureInfo _usCulture = CultureInfo.ReadOnly(new CultureInfo("en-US"));
private Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken) private Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken)
{ {

Loading…
Cancel
Save