/// <summary> /// Unsubscribes from all audio/video send/receive-related events, cancels tasks and disposes sockets /// </summary> public void Dispose() { try { if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 0) { Log.Info(new CallerInfo(), LogContext.FrontEnd, $"[{this.Id}]: Disposing Call"); if (_audioSocket != null) { _audioSocket.DominantSpeakerChanged -= OnDominantSpeakerChanged; _audioSocket.Dispose(); } if (_videoSocket != null) { _videoSocket.VideoMediaReceived -= OnVideoMediaReceived; _videoSocket.Dispose(); } } } catch (Exception ex) { Log.Warning(new CallerInfo(), LogContext.FrontEnd, $"[{this.Id}]: Ignoring exception in dispose {ex}"); } }
/// <summary> /// Unsubscribes all audio send/receive-related events, cancels tasks and disposes sockets /// </summary> public void Dispose() { if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 1) { return; } try { Log.Info(new CallerInfo(), LogContext.FrontEnd, "Disposing Call with Id={0}.", Id); if (_audioSocket != null) { _audioSocket.AudioSendStatusChanged -= OnAudioSendStatusChanged; _audioSocket.Dispose(); } if (_videoSocket != null) { _videoSocket.VideoSendStatusChanged -= OnVideoSendStatusChanged; _videoSocket.Dispose(); } Log.Info(new CallerInfo(), LogContext.FrontEnd, "disposed videoMediaBuffers Id={0}.", Id); } catch (Exception ex) { Log.Warning(new CallerInfo(), LogContext.FrontEnd, "Ignoring exception in dispose" + ex); } }
/// <summary> /// Unsubscribes all audio/video send/receive-related events, cancels tasks and disposes sockets /// </summary> public void Dispose() { if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 1) { return; } try { Log.Info(new CallerInfo(), LogContext.FrontEnd, "Disposing Call with Id={0}.", Id); if (_audioVideoFramePlayer != null) { _audioVideoFramePlayer.LowOnFrames -= OnLowOnFrames; Log.Verbose(new CallerInfo(), LogContext.FrontEnd, "shutting down the player LocalId={0}.", Id); _audioVideoFramePlayer.ShutdownAsync().GetAwaiter().GetResult(); Log.Info(new CallerInfo(), LogContext.FrontEnd, "player shutdown LocalId={0}.", Id); if (!_startVideoPlayerCompleted.WaitOne(_startPlayerTimeOut)) { Log.Error(new CallerInfo(), LogContext.FrontEnd, "StartFramePlayerOperation timed out, LocalId={0}.", Id); } Log.Info(new CallerInfo(), LogContext.FrontEnd, "StartFramePlayerOperation Completed, LocalId={0}.", Id); } if (_audioSocket != null) { _audioSocket.AudioSendStatusChanged -= OnAudioSendStatusChanged; _audioSocket.Dispose(); } if (_videoSocket != null) { _videoSocket.VideoSendStatusChanged -= OnVideoSendStatusChanged; _videoSocket.Dispose(); } // make sure all the audio and video buffers are disposed, it can happen that, // the buffers were not enqueued but the call was disposed if the caller hangs up quickly foreach (var audioMediaBuffer in _audioMediaBuffers) { audioMediaBuffer.Dispose(); } Log.Info(new CallerInfo(), LogContext.FrontEnd, "disposed audioMediaBUffers Id={0}.", Id); foreach (var videoMediaBuffer in _videoMediaBuffers) { videoMediaBuffer.Dispose(); } Log.Info(new CallerInfo(), LogContext.FrontEnd, "disposed videoMediaBuffers Id={0}.", Id); _audioMediaBuffers.Clear(); _videoMediaBuffers.Clear(); } catch (Exception ex) { Log.Warning(new CallerInfo(), LogContext.FrontEnd, "Ignoring exception in dispose" + ex); } }
/// <summary> /// Unsubscribes all audio send/receive-related events, cancels tasks and disposes sockets /// </summary> public void Dispose() { try { if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 0) { Log.Info(new CallerInfo(), LogContext.FrontEnd, $"[{this.Id}]: Disposing Call"); if (_audioSocket != null) { _audioSocket.AudioSendStatusChanged -= OnAudioSendStatusChanged; _audioSocket.Dispose(); } } } catch (Exception ex) { Log.Warning(new CallerInfo(), LogContext.FrontEnd, $"[{this.Id}]: Ignoring exception in dispose {ex}"); } }