Exemple #1
0
        /// <summary>
        /// Create a video track from an existing video track source.
        ///
        /// This does not add the track to any peer connection. Instead, the track must be added manually to
        /// a video transceiver to be attached to a peer connection and transmitted to a remote peer.
        /// </summary>
        /// <param name="source">The track source which provides the raw video frames to the newly created track.</param>
        /// <param name="initConfig">Configuration to initialize the track being created.</param>
        /// <returns>Asynchronous task completed once the track is created.</returns>
        public static LocalVideoTrack CreateFromSource(VideoTrackSource source, LocalVideoTrackInitConfig initConfig)
        {
            if (source == null)
            {
                throw new ArgumentNullException();
            }

            // Parse and marshal the settings
            string trackName = initConfig?.trackName;

            if (string.IsNullOrEmpty(trackName))
            {
                trackName = Guid.NewGuid().ToString();
            }
            var config = new LocalVideoTrackInterop.TrackInitConfig
            {
                TrackName = trackName
            };

            // Create interop wrappers
            var track = new LocalVideoTrack(trackName);

            // Create native implementation objects
            uint res = LocalVideoTrackInterop.LocalVideoTrack_CreateFromSource(in config,
                                                                               source._nativeHandle, out LocalVideoTrackHandle trackHandle);

            Utils.ThrowOnErrorCode(res);

            // Finish creating the track, and bind it to the source
            track.FinishCreate(trackHandle, source);

            return(track);
        }
Exemple #2
0
        internal void FinishCreate(LocalVideoTrackHandle handle, VideoTrackSource source)
        {
            Debug.Assert(!handle.IsClosed);
            // Either first-time assign or no-op (assign same value again)
            Debug.Assert(_nativeHandle.IsInvalid || (_nativeHandle == handle));
            if (_nativeHandle != handle)
            {
                _nativeHandle = handle;
                RegisterInteropCallbacks();
            }

            Debug.Assert(source != null);
            Source = source;
            source.OnTrackAddedToSource(this);
        }
Exemple #3
0
        /// <summary>
        /// Create a video track from an existing video track source.
        ///
        /// This does not add the track to any peer connection. Instead, the track must be added manually to
        /// a video transceiver to be attached to a peer connection and transmitted to a remote peer.
        /// </summary>
        /// <param name="source">The track source which provides the raw video frames to the newly created track.</param>
        /// <param name="initConfig">Configuration to initialize the track being created.</param>
        /// <returns>Asynchronous task completed once the track is created.</returns>
        public static LocalVideoTrack CreateFromSource(VideoTrackSource source, LocalVideoTrackInitConfig initConfig)
        {
            if (source == null)
            {
                throw new ArgumentNullException();
            }

            // Parse and marshal the settings
            string trackName = initConfig?.trackName;

            if (string.IsNullOrEmpty(trackName))
            {
                trackName = Guid.NewGuid().ToString();
            }
            var config = new LocalVideoTrackInterop.TrackInitConfig
            {
                TrackName = trackName
            };

            // Create interop wrappers
            var track = new LocalVideoTrack(trackName);

            // Create native implementation objects
            uint res = LocalVideoTrackInterop.LocalVideoTrack_CreateFromSource(in config,
                                                                               source._nativeHandle, out LocalVideoTrackHandle trackHandle);

            Utils.ThrowOnErrorCode(res);

            // Finish creating the track, and bind it to the source
            Debug.Assert(!trackHandle.IsClosed);
            track._nativeHandle = trackHandle;
            track.Source        = source;
            source.OnTrackAddedToSource(track);

            // Note that this prevents the object from being garbage-collected until it is disposed.
            track._selfHandle = Utils.MakeWrapperRef(track);

            return(track);
        }