/// <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.GetEncoderType()); WebRTC.ValidateGraphicsFormat(format); WebRTC.Context.SetVideoEncoderParameter(GetSelfOrThrow(), width, height, format, texturePtr); WebRTC.Context.InitializeEncoder(GetSelfOrThrow()); tracks.Add(this); }
/// <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 }); }
/// <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()); }