/// <summary> /// Performs action when the vbss socket send status changed event is received. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The video send status changed event arguments. /// </param> private void OnVbssSocketSendStatusChanged(object sender, VideoSendStatusChangedEventArgs e) { if (e.MediaSendStatus == MediaSendStatus.Active) { var currentTick = DateTime.Now.Ticks; var videoBuffers = Utilities.CreateVideoMediaBuffers(currentTick, e.PreferredEncodedVideoSourceFormats?.ToList(), replayed: false, logger: this.logger); if (videoBuffers.Any()) { try { foreach (var buffer in videoBuffers) { this.vbssSocket.Send(buffer); } } catch (Exception ex) { this.logger.Error(ex, "Exception in sending video buffer."); } try { foreach (var buffer in videoBuffers) { buffer.Dispose(); } } catch (Exception ex) { this.logger.Error(ex, "Exception in disposing video buffer."); } } } }
/// <summary> /// Callback for informational updates from the media plaform about video status changes. /// Once the Status becomes active, then video can be sent. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnVideoSendStatusChanged(object sender, VideoSendStatusChangedEventArgs e) { Log.Info(new CallerInfo(), LogContext.Media, "OnVideoSendStatusChanged start"); Log.Info( new CallerInfo(), LogContext.Media, "[VideoSendStatusChangedEventArgs(MediaSendStatus=<{0}>;PreferredVideoSourceFormat=<{1}>]", e.MediaSendStatus, e.PreferredVideoSourceFormat.VideoColorFormat); if (e.MediaSendStatus == MediaSendStatus.Active) { _videoSendStatusActive.SetResult(true); } }
/// <summary> /// Callback for informational updates from the media plaform about video status changes. /// Once the Status becomes active, then video can be sent. /// </summary> /// <param name="sender">The video socket.</param> /// <param name="e">Event arguments.</param> private void OnVideoSendStatusChanged(object sender, VideoSendStatusChangedEventArgs e) { this.logger.Info($"[VideoSendStatusChangedEventArgs(MediaSendStatus=<{e.MediaSendStatus}>]"); if (e.MediaSendStatus == MediaSendStatus.Active) { this.logger.Info($"[VideoSendStatusChangedEventArgs(MediaSendStatus=<{e.MediaSendStatus}>;PreferredVideoSourceFormat=<{string.Join(";", e.PreferredEncodedVideoSourceFormats.ToList())}>]"); var previousSupportedFormats = (this.knownSupportedFormats != null && this.knownSupportedFormats.Any()) ? this.knownSupportedFormats : new List <VideoFormat>(); this.knownSupportedFormats = e.PreferredEncodedVideoSourceFormats.ToList(); // when this is false it means that we have received a new event with different videoFormats // the behavior for this bot is to clean up the previous enqueued media and push the new formats, // starting from beginning if (!this.videoSendStatusActive.TrySetResult(true)) { if (this.knownSupportedFormats != null && this.knownSupportedFormats.Any() && // here it means we got a new video fromat so we need to restart the player this.knownSupportedFormats.Select(x => x.GetId()).Except(previousSupportedFormats.Select(y => y.GetId())).Any()) { // we restart the player this.audioVideoFramePlayer?.ClearAsync().ForgetAndLogExceptionAsync(this.logger); this.logger.Info($"[VideoSendStatusChangedEventArgs(MediaSendStatus=<{e.MediaSendStatus}> enqueuing new formats: {string.Join(";", this.knownSupportedFormats)}]"); // Create the AV buffers var currentTick = DateTime.Now.Ticks; this.CreateAVBuffers(currentTick, replayed: false); this.audioVideoFramePlayer?.EnqueueBuffersAsync(this.audioMediaBuffers, this.videoMediaBuffers).ForgetAndLogExceptionAsync(this.logger); } } } else if (e.MediaSendStatus == MediaSendStatus.Inactive) { if (this.videoSendStatusActive.Task.IsCompleted && this.audioVideoFramePlayer != null) { this.audioVideoFramePlayer?.ClearAsync().ForgetAndLogExceptionAsync(this.logger); } } }
/// <summary> /// Callback for informational updates from the media plaform about video status changes. /// Once the Status becomes active, then video can be sent. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnVideoSendStatusChanged(object sender, VideoSendStatusChangedEventArgs e) { CorrelationId.SetCurrentId(_correlationId); Log.Info( new CallerInfo(), LogContext.Media, "[{0}]: [VideoSendStatusChangedEventArgs(MediaSendStatus=<{1}>;PreferredVideoSourceFormat=<{2}>]", this.Id, e.MediaSendStatus, e.PreferredVideoSourceFormat.VideoColorFormat); if (e.MediaSendStatus == MediaSendStatus.Active && _sendVideo == false) { //Start sending video once the Video Status changes to Active Log.Info(new CallerInfo(), LogContext.Media, $"[{this.Id}] Start sending video"); _sendVideo = true; } }
/// <summary> /// Performs action when the vbss socket send status changed event is received. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The video send status changed event arguments. /// </param> private void OnVbssSocketSendStatusChanged(object sender, VideoSendStatusChangedEventArgs e) { this.logger.Info($"[VbssSendStatusChangedEventArgs(MediaSendStatus=<{e.MediaSendStatus}>]"); if (e.MediaSendStatus == MediaSendStatus.Active) { this.logger.Info($"[VbssSendStatusChangedEventArgs(MediaSendStatus=<{e.MediaSendStatus}>;PreferredVideoSourceFormat=<{string.Join(";", e.PreferredEncodedVideoSourceFormats.ToList())}>]"); var previousSupportedFormats = (this.vbssKnownSupportedFormats != null && this.vbssKnownSupportedFormats.Any()) ? this.vbssKnownSupportedFormats : new List <VideoFormat>(); this.vbssKnownSupportedFormats = e.PreferredEncodedVideoSourceFormats.ToList(); if (this.vbssFramePlayer == null) { this.CreateVbssFramePlayer(); } // when this is false it means that we have received a new event with different videoFormats // the behavior for this bot is to clean up the previous enqueued media and push the new formats, // starting from beginning else { // we restart the player this.vbssFramePlayer?.ClearAsync().ForgetAndLogExceptionAsync(this.logger); } // enqueue video buffers this.logger.Info($"[VbssSendStatusChangedEventArgs(MediaSendStatus=<{e.MediaSendStatus}> enqueuing new formats: {string.Join(";", this.vbssKnownSupportedFormats)}]"); // Create the video buffers this.vbssMediaBuffers = Utilities.CreateVideoMediaBuffers(DateTime.Now.Ticks, this.vbssKnownSupportedFormats, true, this.logger); this.vbssFramePlayer?.EnqueueBuffersAsync(new List <AudioMediaBuffer>(), this.vbssMediaBuffers).ForgetAndLogExceptionAsync(this.logger); } else if (e.MediaSendStatus == MediaSendStatus.Inactive) { this.vbssFramePlayer?.ClearAsync().ForgetAndLogExceptionAsync(this.logger); } }