/// <summary> /// Constructor for creating a local video track from a wrapper and some user settings. /// </summary> /// <param name="track">The newly created track wrapper.</param> /// <param name="settings">The settings to initialize the newly created native track.</param> /// <seealso cref="PeerConnection.AddLocalVideoTrackAsync(LocalVideoTrackSettings)"/> public LocalVideoTrackInteropInitConfig(LocalVideoTrack track, LocalVideoTrackSettings settings) { trackHandle = Utils.MakeWrapperRef(track); if (settings != null) { VideoDeviceId = settings.videoDevice.id; VideoProfileId = settings.videoProfileId; VideoProfileKind = settings.videoProfileKind; Width = settings.width.GetValueOrDefault(0); Height = settings.height.GetValueOrDefault(0); Framerate = settings.framerate.GetValueOrDefault(0.0); EnableMixedRealityCapture = (mrsBool)settings.enableMrc; EnableMRCRecordingIndicator = (mrsBool)settings.enableMrcRecordingIndicator; } else { VideoDeviceId = string.Empty; VideoProfileId = string.Empty; VideoProfileKind = VideoProfileKind.Unspecified; Width = 0; Height = 0; Framerate = 0.0; EnableMixedRealityCapture = mrsBool.True; EnableMRCRecordingIndicator = mrsBool.True; } }
public async Task BeforeConnect() { // Add local video track channel to #1 var settings = new PeerConnection.LocalVideoTrackSettings(); LocalVideoTrack track1 = await pc1_.AddLocalVideoTrackAsync(settings); Assert.NotNull(track1); Assert.AreEqual(pc1_, track1.PeerConnection); // Wait for local SDP re-negotiation on #1. // This will not create an offer, since we're not connected yet. Assert.True(renegotiationEvent1_.Wait(TimeSpan.FromSeconds(60.0))); // Connect Assert.True(pc1_.CreateOffer()); WaitForSdpExchangeCompleted(); Assert.True(pc1_.IsConnected); Assert.True(pc2_.IsConnected); // Remove the track from #1 renegotiationEvent1_.Reset(); pc1_.RemoveLocalVideoTrack(track1); Assert.IsNull(track1.PeerConnection); track1.Dispose(); // Wait for local SDP re-negotiation on #1 Assert.True(renegotiationEvent1_.Wait(TimeSpan.FromSeconds(60.0))); // Confirm remote track was removed from #2 Assert.True(trackRemovedEvent2_.Wait(TimeSpan.FromSeconds(60.0))); // Wait until SDP renegotiation finished WaitForSdpExchangeCompleted(); }
private void CreateSender() { Debug.Assert(_senderTrack == null); if (MediaKind == MediaKind.Audio) { var audioSource = (AudioTrackSource)_source; var initConfig = new LocalAudioTrackInitConfig { trackName = _senderTrackName }; _senderTrack = LocalAudioTrack.CreateFromSource(audioSource.Source, initConfig); } else { Debug.Assert(MediaKind == MediaKind.Video); var videoSource = (VideoTrackSource)_source; var initConfig = new LocalVideoTrackInitConfig { trackName = _senderTrackName }; _senderTrack = LocalVideoTrack.CreateFromSource(videoSource.Source, initConfig); } }
protected override void OnDestroy() { if (room != null && room.State != RoomState.Disconnected) { room.Disconnect(); disconnectedFromOnDestroy = true; } /* * Release the local audio and video tracks ensuring any memory allocated to audio * or video is freed. */ if (localAudioTrack != null) { localAudioTrack.Release(); localAudioTrack = null; } if (localVideoTrack != null) { localVideoTrack.Release(); localVideoTrack = null; } base.OnDestroy(); }
public void SetLocalVideoTrack(LocalVideoTrack track) { try { if (LocalVideoTrack == null) { LocalVideoTrack = track; var trackId = track?.Name; if (LocalVideoTrackId == trackId) { LocalVideoTrack.Enable(false); } else { LocalVideoTrackId = trackId; LocalVideoTrack.Enable(false); } } else { if (LocalVideoTrack.IsEnabled) { LocalVideoTrack.Enable(false); } } } catch (Exception e) { Console.WriteLine(e); } }
public MediaPlayerViewModel() { _videoPlayer.CurrentStateChanged += OnMediaStateChanged; _videoPlayer.MediaOpened += OnMediaOpened; _videoPlayer.MediaFailed += OnMediaFailed; _videoPlayer.MediaEnded += OnMediaEnded; _videoPlayer.RealTimePlayback = true; _videoPlayer.AutoPlay = false; AudioTrackTypeList.Add(new AudioTrackTypeViewModel { DisplayName = "Local microphone (default device)", Factory = async() => { return(await LocalAudioTrack.CreateFromDeviceAsync()); } }); VideoTrackTypeList.Add(new VideoTrackTypeViewModel { DisplayName = "Local webcam (default device)", Factory = async() => { return(await LocalVideoTrack.CreateFromDeviceAsync()); } }); _videoStatsTimer.Interval = TimeSpan.FromMilliseconds(300); _videoStatsTimer.Tick += (_1, _2) => UpdateVideoStats(); }
private void StartPreview() { if (IsSimulator) { return; } camera = new CameraCapturer(); localVideoTrack = localMedia.AddVideoTrack(true, camera); if (localVideoTrack != null) { // Attach view to video track for local preview localVideoTrack.Attach(previewView); LogMessage("Video track added to localMedia."); // Should dispose of this. var tap = new UITapGestureRecognizer(FlipCamera); previewView.AddGestureRecognizer(tap); } else { LogMessage("Failed to add video track."); } }
/// <summary> /// Create the local sender track from the current media track source if that source /// is active and enabled. Otherwise do nothing. /// </summary> private void CreateSenderIfNeeded() { // Only create a sender track if the source is active, i.e. has an underlying frame source. if (_senderTrack == null && _source != null && _source.isActiveAndEnabled) { if (MediaKind == MediaKind.Audio) { var audioSource = (_source as AudioTrackSource); var initConfig = new LocalAudioTrackInitConfig { trackName = _senderTrackName }; _senderTrack = LocalAudioTrack.CreateFromSource(audioSource.Source, initConfig); } else { Debug.Assert(MediaKind == MediaKind.Video); var videoSource = (_source as VideoTrackSource); var initConfig = new LocalVideoTrackInitConfig { trackName = _senderTrackName }; _senderTrack = LocalVideoTrack.CreateFromSource(videoSource.Source, initConfig); } } }
public void SetLocalVideoTrack(LocalVideoTrack track) { try { if (LocalVideoTrack == null) { LocalVideoTrack = track; var trackId = track?.Name; if (LocalVideoTrackId == trackId) { LocalVideoTrack.Enable(false); } else { LocalVideoTrackId = trackId; LocalVideoTrack.Enable(false); } } else { if (LocalVideoTrack.IsEnabled) { LocalVideoTrack.Enable(false); } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
public Room ConnectToRoom(string roomName, string accessToken) { try { Console.WriteLine("Trying to connect to room " + roomName); localAudioTrack = LocalAudioTrack.Create(this, true); CameraCapturer cameraCapturer = new CameraCapturer(this, CameraCapturer.CameraSource.FrontCamera); // Create a video track LocalVideoTrack localVideoTrack = LocalVideoTrack.Create(this, true, cameraCapturer); //primaryVideoView.SetMirror(true); //localVideoTrack.AddRenderer(primaryVideoView); ConnectOptions connectOptions = new ConnectOptions.Builder(accessToken) .RoomName(roomName) .AudioTracks(new List <LocalAudioTrack> { localAudioTrack }) .VideoTracks(new List <LocalVideoTrack> { localVideoTrack }) .Build(); return(Video.Connect(this, connectOptions, this.roomListener)); } catch (Exception e) { Console.WriteLine("Error: trying to connect to room " + e.Message); Toast.MakeText(this, e.Message, ToastLength.Long).Show(); return(null); } }
public void SetLocalVideoTrack(LocalVideoTrack videoTracklocal) { try { if (LocalvideoTrack == null) { LocalvideoTrack = videoTracklocal; var trackId = videoTracklocal?.TrackId; if (_localVideoTrackId == trackId) { return; } else { _localVideoTrackId = trackId; LocalvideoTrack.AddRenderer(_thumbnailVideo); _thumbnailVideo.Visibility = LocalvideoTrack == null ? ViewStates.Invisible : ViewStates.Visible; } } } catch (Exception e) { Console.WriteLine(e); } }
public void SetLocalVideoTrack(LocalVideoTrack videoTracklocal) { try { if (LocalvideoTrack == null) { LocalvideoTrack = videoTracklocal; var trackId = videoTracklocal?.TrackId; if (_localVideoTrackId == trackId) { LocalvideoTrack.Enable(false); return; } else { _localVideoTrackId = trackId; LocalvideoTrack.Enable(false); } } else { if (LocalvideoTrack.IsEnabled) { LocalvideoTrack.Enable(false); } } } catch (Exception e) { Console.WriteLine(e); } }
private void addCameraVideo() { cameraCapturer = new CameraCapturer(this, CameraCapturer.CameraSource.BACK_CAMERA); localVideoTrack = localMedia.addVideoTrack(true, cameraCapturer); localVideoTrack.addRenderer(videoView); toggleFlashButton.OnClickListener = toggleFlashButtonClickListener; takePictureButton.OnClickListener = takePictureButtonClickListener; }
private void addVideo() { localVideoTrack = localMedia.addVideoTrack(true, new CameraCapturer(this, CameraCapturer.CameraSource.FRONT_CAMERA, null)); snapshotVideoRenderer = new SnapshotVideoRenderer(snapshotImageView); localVideoTrack.addRenderer(localVideoView); localVideoTrack.addRenderer(snapshotVideoRenderer); localVideoView.OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this); }
public async Task AddVideoTrackFromDeviceAsync(string trackName) { await RequestMediaAccessAsync(StreamingCaptureMode.Video); // Create the source VideoCaptureDeviceInfo deviceInfo = VideoCaptureDevices.SelectedItem; if (deviceInfo == null) { throw new InvalidOperationException("No video capture device selected"); } var deviceConfig = new LocalVideoDeviceInitConfig { videoDevice = new VideoCaptureDevice { id = deviceInfo.Id }, }; VideoCaptureFormatViewModel formatInfo = VideoCaptureFormats.SelectedItem; if (formatInfo != null) { deviceConfig.width = formatInfo.Format.width; deviceConfig.height = formatInfo.Format.height; deviceConfig.framerate = formatInfo.Format.framerate; } if (deviceInfo.SupportsVideoProfiles) { MediaCaptureVideoProfile profile = VideoProfiles.SelectedItem; deviceConfig.videoProfileId = profile?.Id; deviceConfig.videoProfileKind = SelectedVideoProfileKind; } var source = await DeviceVideoTrackSource.CreateAsync(deviceConfig); // FIXME - this leaks the source, never disposed // Crate the track var trackConfig = new LocalVideoTrackInitConfig { trackName = trackName, }; var track = LocalVideoTrack.CreateFromSource(source, trackConfig); // FIXME - this probably leaks the track, never disposed SessionModel.Current.VideoTracks.Add(new VideoTrackViewModel { Source = source, Track = track, TrackImpl = track, IsRemote = false, DeviceName = deviceInfo.DisplayName }); SessionModel.Current.LocalTracks.Add(new TrackViewModel(Symbol.Video) { DisplayName = deviceInfo.DisplayName }); }
private void startScreenCapture() { screenVideoTrack = localMedia.addVideoTrack(true, screenCapturer); screenCaptureMenuItem.Icon = R.drawable.ic_stop_screen_share_white_24dp; screenCaptureMenuItem.Title = [email protected]_screen_share; localVideoView.Visibility = View.VISIBLE; screenVideoTrack.addRenderer(localVideoView); }
public void AddVideoTrack(LocalVideoTrack track, string deviceName) { ThreadHelper.EnsureIsMainThread(); VideoTracks.Add(new VideoTrackViewModel(track, deviceName)); LocalTracks.Add(new LocalTrackViewModel(Symbol.Video) { DisplayName = deviceName }); }
void CreateLocalMedia(Context context) { _audioManager = (AudioManager)context.GetSystemService(Context.AudioService); var cameraSource = Cameras.HasFrontCamera() ? CameraCapturer.CameraSource.FrontCamera : CameraCapturer.CameraSource.BackCamera; VideoCapturer = new CameraCapturer(context, cameraSource); CurrentVideoTrack = LocalVideoTrack.Create(context, true, VideoCapturer); CurrentAudioTrack = LocalAudioTrack.Create(context, true); }
public void SetLocalVideoTrack(LocalVideoTrack videoTrack) { var trackId = videoTrack?.Name; if (_localVideoTrackId == trackId) { return; } _localVideoTrackId = trackId; UpdateTrackRenderer(videoTrack, _thumbnailVideo); }
public void RemoveLocalVideoTrack(LocalVideoTrack track) { try { SetLocalVideoTrack(null); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
public void RemoveLocalVideoTrack(LocalVideoTrack track) { try { SetLocalVideoTrack(null); } catch (Exception e) { Console.WriteLine(e); } }
private void CreateAudioAndVideoTracks() { // Share your microphone localAudioTrack = LocalAudioTrack.Create(this, true); // Share your camera cameraCapturerCompat = new CameraCapturerCompat(this, CameraCapturer.CameraSource.FrontCamera); localVideoTrack = LocalVideoTrack.Create(this, true, cameraCapturerCompat.GetVideoCapturer()); primaryVideoView.SetMirror(true); localVideoTrack.AddRenderer(primaryVideoView); localVideoView = primaryVideoView; }
/// <summary> /// Callback when the Unity component is disabled. This is the proper way to disable the /// video source and get it to stop video capture. /// </summary> protected void OnDisable() { var nativePeer = PeerConnection.Peer; if ((nativePeer != null) && nativePeer.Initialized) { VideoStreamStopped.Invoke(); Track.I420AVideoFrameReady -= I420ALocalVideoFrameReady; nativePeer.RemoveLocalVideoTrack(Track); Track.Dispose(); Track = null; _frameQueue.Clear(); } }
public static IObservable <WebRTCFrameEventArgs> VideoFrameReady(LocalVideoTrack vidtrack) { return(Observable.FromEvent <I420AVideoFrameDelegate, WebRTCFrameEventArgs>(handler => { I420AVideoFrameDelegate vfReadyHandler = (frame) => { handler(new WebRTCFrameEventArgs(frame)); }; return vfReadyHandler; }, vfReadyHandler => vidtrack.I420AVideoFrameReady += vfReadyHandler, vfReadyHandler => vidtrack.I420AVideoFrameReady -= vfReadyHandler)); }
public async Task VideoCall() { // This test use manual offers suspendOffer1_ = true; // Create video transceiver on #1. This triggers a renegotiation needed event. string name1 = "video_feed"; var initSettings = new TransceiverInitSettings { Name = name1, InitialDesiredDirection = Transceiver.Direction.SendOnly, StreamIDs = new List <string> { "id1", "id2" } }; var transceiver1 = pc1_.AddTransceiver(MediaKind.Video, initSettings); var track_config = new LocalVideoTrackInitConfig { trackName = "custom_i420a" }; // Add a local video track. using (var source = ExternalVideoTrackSource.CreateFromI420ACallback( VideoTrackSourceTests.CustomI420AFrameCallback)) { using (var localTrack = LocalVideoTrack.CreateFromSource(source, track_config)) { transceiver1.LocalVideoTrack = localTrack; // Connect await DoNegotiationStartFrom(pc1_); // Find the remote track Assert.AreEqual(1, pc2_.Transceivers.Count); var transceiver2 = pc2_.Transceivers[0]; var remoteTrack = transceiver2.RemoteVideoTrack; Assert.IsNotNull(remoteTrack); Assert.AreEqual(transceiver2, remoteTrack.Transceiver); Assert.AreEqual(pc2_, remoteTrack.PeerConnection); // Remote track receives frames. VideoTrackSourceTests.TestFrameReadyCallbacks(remoteTrack); // Cleanup. transceiver1.LocalVideoTrack = null; } } }
private void createLocalMedia() { localMedia = LocalMedia.create(this); // Share your microphone localAudioTrack = localMedia.addAudioTrack(true); // Share your camera cameraCapturer = new CameraCapturer(this, CameraCapturer.CameraSource.FRONT_CAMERA); localVideoTrack = localMedia.addVideoTrack(true, cameraCapturer); primaryVideoView.Mirror = true; localVideoTrack.addRenderer(primaryVideoView); localVideoView = primaryVideoView; }
public override void onCreate(Bundle savedInstanceState) { base.onCreate(savedInstanceState); ContentView = R.layout.activity_custom_capturer; localMedia = LocalMedia.create(this); capturedView = (LinearLayout) findViewById(R.id.captured_view); videoView = (VideoView) findViewById(R.id.video_view); timerView = (Chronometer) findViewById(R.id.timer_view); timerView.start(); // Once added we should see our linear layout rendered live below localVideoTrack = localMedia.addVideoTrack(true, new ViewCapturer(capturedView)); localVideoTrack.addRenderer(videoView); }
public override void onCreate(Bundle savedInstanceState) { base.onCreate(savedInstanceState); ContentView = R.layout.activity_custom_capturer; localMedia = LocalMedia.create(this); capturedView = (LinearLayout)findViewById(R.id.captured_view); videoView = (VideoView)findViewById(R.id.video_view); timerView = (Chronometer)findViewById(R.id.timer_view); timerView.start(); // Once added we should see our linear layout rendered live below localVideoTrack = localMedia.addVideoTrack(true, new ViewCapturer(capturedView)); localVideoTrack.addRenderer(videoView); }
public void FrameReadyCallbacks() { var track_config = new LocalVideoTrackInitConfig { trackName = "custom_i420a" }; using (var source = ExternalVideoTrackSource.CreateFromI420ACallback( VideoTrackSourceTests.CustomI420AFrameCallback)) { using (var track = LocalVideoTrack.CreateFromSource(source, track_config)) { VideoTrackSourceTests.TestFrameReadyCallbacks(track); } } }
public void ToggleWebRtcVideo(bool toggleOn) { if (Transceiver?.LocalVideoTrack != null) { Transceiver.LocalVideoTrack.Dispose(); Transceiver.LocalVideoTrack = null; } if (toggleOn) { Transceiver.LocalVideoTrack = LocalVideoTrack.CreateFromSource(VideoSource, new LocalVideoTrackInitConfig() { trackName = "ScreenCapture" }); } }
/// <summary> /// Stop the video track playback and remove the track from the peer connection. /// </summary> public void StopTrack() { if (Track != null) { var nativePeer = PeerConnection; nativePeer.RemoveLocalVideoTrack(Track); Track.Dispose(); Track = null; NotifyVideoStreamStopped(); } if (Source != null) { Source.Dispose(); Source = null; } _frameQueue.Clear(); }