Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A small cleanup in AudioVideoPlaybackBot #306

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ public BotMediaStream(ILocalMediaSession mediaSession, IGraphLogger logger)
}

this.audioSocket.AudioSendStatusChanged += this.OnAudioSendStatusChanged;
this.audioSocket.AudioMediaReceived += this.OnAudioMediaReceived;

this.mainVideoSocket = this.mediaSession.VideoSockets?.FirstOrDefault();
if (this.mainVideoSocket != null)
{
this.mainVideoSocket.VideoSendStatusChanged += this.OnVideoSendStatusChanged;
this.mainVideoSocket.VideoKeyFrameNeeded += this.OnVideoKeyFrameNeeded;
this.mainVideoSocket.VideoMediaReceived += this.OnVideoMediaReceived;
}

this.videoSockets = this.mediaSession.VideoSockets?.ToList();
Expand Down Expand Up @@ -185,12 +187,14 @@ public async Task ShutdownAsync()
if (this.audioSocket != null)
{
this.audioSocket.AudioSendStatusChanged -= this.OnAudioSendStatusChanged;
this.audioSocket.AudioMediaReceived -= this.OnAudioMediaReceived;
}

if (this.mainVideoSocket != null)
{
this.mainVideoSocket.VideoKeyFrameNeeded -= this.OnVideoKeyFrameNeeded;
this.mainVideoSocket.VideoSendStatusChanged -= this.OnVideoSendStatusChanged;
this.mainVideoSocket.VideoMediaReceived -= this.OnVideoMediaReceived;
}

if (this.vbssSocket != null)
Expand Down Expand Up @@ -325,6 +329,25 @@ private void OnAudioSendStatusChanged(object sender, AudioSendStatusChangedEvent
}
}

/// <summary>
/// Save screenshots when we receive audio from the subscribed participant.
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The audio media received arguments.
/// </param>
private void OnAudioMediaReceived(object sender, AudioMediaReceivedEventArgs e)
{
// leave only logging in here
this.logger.Info($"[AudioMediaReceivedEventArgs(Data=<{e.Buffer.Data.ToString()}>, Length={e.Buffer.Length}, Timestamp={e.Buffer.Timestamp}, AudioFormat={e.Buffer.AudioFormat}, IsSilence={e.Buffer.IsSilence}, ActiveSpeakers=[{string.Join(", ", e.Buffer.ActiveSpeakers)}])]");

/* TODO: Do something with audio here */

e.Buffer.Dispose();
}

/// <summary>
/// Callback for informational updates from the media plaform about video status changes.
/// Once the Status becomes active, then video can be sent.
Expand All @@ -348,9 +371,9 @@ private void OnVideoSendStatusChanged(object sender, VideoSendStatusChangedEvent
// starting from beginning
if (!this.videoSendStatusActive.TrySetResult(true))
{
if (this.videoKnownSupportedFormats != null && this.videoKnownSupportedFormats.Any() &&

// here it means we got a new video fromat so we need to restart the player
if (this.videoKnownSupportedFormats != null && this.videoKnownSupportedFormats.Any() &&
Identifier marked this conversation as resolved.
Show resolved Hide resolved
// here it means we got a new video fromat so we need to restart the player
this.videoKnownSupportedFormats.Select(x => x.GetId()).Except(previousSupportedFormats.Select(y => y.GetId())).Any())
{
// we restart the player
Expand All @@ -375,6 +398,25 @@ private void OnVideoSendStatusChanged(object sender, VideoSendStatusChangedEvent
}
}

/// <summary>
/// Save screenshots when we receive video from the subscribed participant.
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The video media received arguments.
/// </param>
private void OnVideoMediaReceived(object sender, VideoMediaReceivedEventArgs e)
{
// leave only logging in here
this.logger.Info($"[VideoMediaReceivedEventArgs(Data=<{e.Buffer.Data.ToString()}>, Length={e.Buffer.Length}, Timestamp={e.Buffer.Timestamp}, Width={e.Buffer.VideoFormat.Width}, Height={e.Buffer.VideoFormat.Height}, ColorFormat={e.Buffer.VideoFormat.VideoColorFormat}, FrameRate={e.Buffer.VideoFormat.FrameRate})]");

/* TODO: Do something with video here */

e.Buffer.Dispose();
}

/// <summary>
/// If the application has configured the VideoSocket to receive encoded media, this
/// event is raised each time a key frame is needed. Events are serialized, so only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ public CallHandler(ICall statefulCall)
// subscribe to dominant speaker event on the audioSocket
this.Call.GetLocalMediaSession().AudioSocket.DominantSpeakerChanged += this.OnDominantSpeakerChanged;

// subscribe to the VideoMediaReceived event on the main video socket
this.Call.GetLocalMediaSession().VideoSockets.FirstOrDefault().VideoMediaReceived += this.OnVideoMediaReceived;

// susbscribe to the participants updates, this will inform the bot if a particpant left/joined the conference
this.Call.Participants.OnUpdated += this.ParticipantsOnUpdated;

Expand Down Expand Up @@ -91,7 +88,6 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);

this.Call.GetLocalMediaSession().AudioSocket.DominantSpeakerChanged -= this.OnDominantSpeakerChanged;
this.Call.GetLocalMediaSession().VideoSockets.FirstOrDefault().VideoMediaReceived -= this.OnVideoMediaReceived;

this.Call.OnUpdated -= this.CallOnUpdated;
this.Call.Participants.OnUpdated -= this.ParticipantsOnUpdated;
Expand Down Expand Up @@ -289,23 +285,6 @@ private void OnDominantSpeakerChanged(object sender, DominantSpeakerChangedEvent
}
}

/// <summary>
/// Save screenshots when we receive video from subscribed participant.
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The video media received arguments.
/// </param>
private void OnVideoMediaReceived(object sender, VideoMediaReceivedEventArgs e)
{
// leave only logging in here
this.GraphLogger.Info($"[{this.Call.Id}]: Capturing image: [VideoMediaReceivedEventArgs(Data=<{e.Buffer.Data.ToString()}>, Length={e.Buffer.Length}, Timestamp={e.Buffer.Timestamp}, Width={e.Buffer.VideoFormat.Width}, Height={e.Buffer.VideoFormat.Height}, ColorFormat={e.Buffer.VideoFormat.VideoColorFormat}, FrameRate={e.Buffer.VideoFormat.FrameRate})]");

e.Buffer.Dispose();
}

/// <summary>
/// Gets the participant with the corresponding MSI.
/// </summary>
Expand Down