/// <summary> /// Handler for the wrapped media sink object's IncomingConnectionEvent. Expose the wrapped event to /// listeners as own IncomingConnectionArrived event. /// </summary> private void mediaSink_IncomingConnectionEvent(StspMediaSink sender, IncomingConnectionEventArgs args) { if (IncomingConnectionArrived != null && forwardEvents) { IncomingConnectionArrived(sender, args); } }
/// <summary> /// Starts media recording asynchronously /// </summary> /// <param name="encodingProfile"> /// Encoding profile used for the recording session /// </param> public async Task StartRecordingAsync(MediaEncodingProfile encodingProfile) { try { // We cannot start recording twice. if (mediaSink != null && recordingStarted) { throw new InvalidOperationException("Recording already started."); } // Release sink if there is one already. CleanupSink(); // Create new sink mediaSink = new StspMediaSink(); mediaSink.IncomingConnectionEvent += mediaSink_IncomingConnectionEvent; await mediaSink.InitializeAsync(encodingProfile.Audio, encodingProfile.Video); await mediaCapture.StartRecordToCustomSinkAsync(encodingProfile, mediaSink); recordingStarted = true; } catch (Exception e) { CleanupSink(); throw e; } }
/// <summary> /// Cleans up the resources. /// </summary> private void CleanupSink() { if (mediaSink != null) { mediaSink.IncomingConnectionEvent -= mediaSink_IncomingConnectionEvent; mediaSink.Close(); mediaSink = null; recordingStarted = false; } }
/// <summary> /// Handler for the wrapped media sink object's IncomingConnectionEvent. Expose the wrapped event to /// listeners as own IncomingConnectionArrived event. /// </summary> private void mediaSink_IncomingConnectionEvent(StspMediaSink sender, IncomingConnectionEventArgs args) { if (IncomingConnectionArrived != null && forwardEvents) IncomingConnectionArrived(sender, args); }