Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public RTCError SetParameters(RTCRtpSendParameters parameters)
        {
            if (Track is VideoStreamTrack videoTrack)
            {
                foreach (var encoding in parameters.encodings)
                {
                    var scale = encoding.scaleResolutionDownBy;
                    if (!scale.HasValue)
                    {
                        continue;
                    }

                    var error = WebRTC.ValidateTextureSize((int)(videoTrack.Texture.width / scale),
                                                           (int)(videoTrack.Texture.height / scale), Application.platform, WebRTC.GetEncoderType());
                    if (error.errorType != RTCErrorType.None)
                    {
                        return(error);
                    }
                }
            }

            parameters.CreateInstance(out RTCRtpSendParametersInternal instance);
            IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(instance));

            Marshal.StructureToPtr(instance, ptr, false);
            RTCErrorType type = NativeMethods.SenderSetParameters(GetSelfOrThrow(), ptr);

            Marshal.FreeCoTaskMem(ptr);
            return(new RTCError {
                errorType = type
            });
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new VideoStream object.
 /// The track is created with a source texture `ptr`.
 /// It is noted that streamed video might be flipped when not action was taken. Almost case it has no problem to use other constructor instead.
 ///
 /// See Also: Texture.GetNativeTexturePtr
 /// </summary>
 /// <param name="texturePtr"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="format"></param>
 public VideoStreamTrack(IntPtr texturePtr, int width, int height, GraphicsFormat format)
     : this(Guid.NewGuid().ToString(), new VideoTrackSource())
 {
     WebRTC.ValidateTextureSize(width, height, Application.platform, WebRTC.GetEncoderType());
     WebRTC.ValidateGraphicsFormat(format);
     WebRTC.Context.SetVideoEncoderParameter(GetSelfOrThrow(), width, height, format, texturePtr);
     WebRTC.Context.InitializeEncoder(GetSelfOrThrow());
 }
 /// <summary>
 /// Creates a new VideoStream object.
 /// The track is created with a source texture `ptr`.
 /// It is noted that streamed video might be flipped when not action was taken. Almost case it has no problem to use other constructor instead.
 ///
 /// See Also: Texture.GetNativeTexturePtr
 /// </summary>
 /// <param name="label"></param>
 /// <param name="texturePtr"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="format"></param>
 public VideoStreamTrack(string label, IntPtr texturePtr, int width, int height, GraphicsFormat format)
     : base(WebRTC.Context.CreateVideoTrack(label))
 {
     WebRTC.ValidateTextureSize(width, height, Application.platform);
     WebRTC.ValidateGraphicsFormat(format);
     WebRTC.Context.SetVideoEncoderParameter(GetSelfOrThrow(), width, height, format, texturePtr);
     WebRTC.Context.InitializeEncoder(GetSelfOrThrow());
     tracks.Add(this);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new VideoStream object.
        /// The track is created with a source texture `ptr`.
        /// It is noted that streamed video might be flipped when not action was taken. Almost case it has no problem to use other constructor instead.
        ///
        /// See Also: Texture.GetNativeTexturePtr
        /// </summary>
        /// <param name="texturePtr"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="format"></param>
        public VideoStreamTrack(IntPtr texturePtr, int width, int height, GraphicsFormat format, bool needFlip)
            : this(Guid.NewGuid().ToString(), new VideoTrackSource(), needFlip)
        {
            var error = WebRTC.ValidateTextureSize(width, height, Application.platform, WebRTC.GetEncoderType());

            if (error.errorType != RTCErrorType.None)
            {
                throw new ArgumentException(error.message);
            }
            WebRTC.ValidateGraphicsFormat(format);
            WebRTC.Context.SetVideoEncoderParameter(GetSelfOrThrow(), width, height, format, texturePtr);
            WebRTC.Context.InitializeEncoder(GetSelfOrThrow());
        }
Ejemplo n.º 5
0
        internal VideoStreamTrack(Texture texture, RenderTexture dest, string label, VideoTrackSource source, bool needFlip)
            : base(WebRTC.Context.CreateVideoTrack(label, source.self))
        {
            var error = WebRTC.ValidateTextureSize(texture.width, texture.height, Application.platform);

            if (error.errorType != RTCErrorType.None)
            {
                throw new ArgumentException(error.message);
            }
            WebRTC.ValidateGraphicsFormat(texture.graphicsFormat);

            if (!s_tracks.TryAdd(self, new WeakReference <VideoStreamTrack>(this)))
            {
                throw new InvalidOperationException();
            }

            m_source = source;
            m_source.sourceTexture_ = texture;
            m_source.destTexture_   = dest;
            m_source.needFlip_      = needFlip;
        }