private void Peer_RemoteI420AFrameReady(I420AVideoFrame frame) { lock (_remoteVideoLock) { if (!_remoteVideoPlaying) { _remoteVideoPlaying = true; uint width = frame.width; uint height = frame.height; RunOnMainThread(() => { // Bridge the remote video track with the remote media player UI int framerate = 30; // for lack of an actual value _remoteVideoSource = CreateI420VideoStreamSource(width, height, framerate); var remoteVideoPlayer = new MediaPlayer(); remoteVideoPlayer.Source = MediaSource.CreateFromMediaStreamSource( _remoteVideoSource); remoteVideoPlayerElement.SetMediaPlayer(remoteVideoPlayer); remoteVideoPlayer.Play(); }); } } _remoteVideoBridge.HandleIncomingVideoFrame(frame); }
private void Peer_RemoteI420FrameReady(I420AVideoFrame frame) { // Lazily start the remote video media player when receiving // the first video frame from the remote peer. Currently there // is no exposed API to tell once connected that the remote peer // will be sending some video track. //< TODO - See if we can add an API to enumerate the remote channels, // or an On(Audio|Video|Data)Channel(Added|Removed) event? lock (_isRemoteVideoPlayingLock) { if (!_isRemoteVideoPlaying) { _isRemoteVideoPlaying = true; uint width = frame.width; uint height = frame.height; RunOnMainThread(() => { remoteVideoSource = CreateVideoStreamSource(width, height); remoteVideoPlayer.Source = MediaSource.CreateFromMediaStreamSource(remoteVideoSource); remoteVideoPlayer.Play(); }); } } remoteVideoBridge.HandleIncomingVideoFrame(frame); }
private void Peer_LocalI420AFrameReady(I420AVideoFrame frame) { lock (_localVideoLock) { if (!_localVideoPlaying) { _localVideoPlaying = true; // Capture the resolution into local variable useable from the lambda below uint width = frame.width; uint height = frame.height; // Defer UI-related work to the main UI thread RunOnMainThread(() => { // Bridge the local video track with the local media player UI int framerate = 30; // for lack of an actual value _localVideoSource = CreateI420VideoStreamSource( width, height, framerate); var localVideoPlayer = new MediaPlayer(); localVideoPlayer.Source = MediaSource.CreateFromMediaStreamSource( _localVideoSource); //localVideoPlayerElement.SetMediaPlayer(localVideoPlayer); remoteVideoPlayerElement.SetMediaPlayer(localVideoPlayer); localVideoPlayer.Play(); }); } } _localVideoBridge.HandleIncomingVideoFrame(frame); }
/// <summary> /// Callback on video frame received from the local video capture device, /// for local rendering before (or in parallel of) being sent to the remote peer. /// </summary> /// <param name="frame">The newly captured video frame.</param> private void VideoTrack_I420AFrameReady(I420AVideoFrame frame) { // Lazily start the video media player when receiving the first video frame from // the video track. Currently there is no exposed API to tell once connected that // the remote peer will be sending some video track, so handle local and remote // video tracks the same for simplicity. bool needNewSource = false; uint width = frame.width; uint height = frame.height; lock (_mediaPlaybackLock) { if (!_isVideoPlaying) { _isVideoPlaying = true; _videoWidth = width; _videoHeight = height; needNewSource = true; } else if ((width != _videoWidth) || (height != _videoHeight)) { _videoWidth = width; _videoHeight = height; needNewSource = true; } } if (needNewSource) { // We don't know the remote video framerate yet, so use a default. uint framerate = 30; //RunOnMainThread(() => { Logger.Log($"Creating new video source: {width}x{height}@{framerate}"); _videoPlayer.Pause(); //_videoPlayer.Source = null; _videoStreamSource?.NotifyError(MediaStreamSourceErrorStatus.Other); _videoSource?.Dispose(); _videoStreamSource = CreateVideoStreamSource(width, height, framerate); _videoSource = MediaSource.CreateFromMediaStreamSource(_videoStreamSource); _videoPlayer.Source = _videoSource; }//); ThreadHelper.RunOnMainThread(() => { RaisePropertyChanged("FrameWidth"); RaisePropertyChanged("FrameHeight"); }); } _videoBridge.HandleIncomingVideoFrame(frame); }
private void Peer_LocalI420FrameReady(I420AVideoFrame frame) { localVideoBridge.HandleIncomingVideoFrame(frame); }