Ejemplo n.º 1
0
        private void OnBandwidthChanged(int index)
        {
            if (_pc1 == null || _pc2 == null)
            {
                return;
            }
            ulong?               bandwidth  = bandwidthOptions.Values.ElementAt(index);
            RTCRtpSender         sender     = _pc1.GetSenders().First();
            RTCRtpSendParameters parameters = sender.GetParameters();

            if (bandwidth == null)
            {
                parameters.encodings[0].maxBitrate = null;
                parameters.encodings[0].minBitrate = null;
            }
            else
            {
                parameters.encodings[0].maxBitrate = bandwidth * 1000;
                parameters.encodings[0].minBitrate = bandwidth * 1000;
            }

            RTCError error = sender.SetParameters(parameters);

            if (error.errorType != RTCErrorType.None)
            {
                Debug.LogErrorFormat("RTCRtpSender.SetParameters failed {0}", error.errorType);
            }

            Debug.Log("SetParameters:" + bandwidth);
        }
Ejemplo n.º 2
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.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public RTCRtpSendParameters GetParameters()
        {
            NativeMethods.SenderGetParameters(self, out var ptr);
            RTCRtpSendParametersInternal parametersInternal = Marshal.PtrToStructure <RTCRtpSendParametersInternal>(ptr);
            RTCRtpSendParameters         parameters         = new RTCRtpSendParameters(ref parametersInternal);

            Marshal.FreeHGlobal(ptr);
            return(parameters);
        }
Ejemplo n.º 4
0
        public RTCErrorType SetParameters(RTCRtpSendParameters parameters)
        {
            IntPtr       ptr   = parameters.CreatePtr();
            RTCErrorType error = NativeMethods.SenderSetParameters(self, ptr);

            RTCRtpSendParameters.DeletePtr(ptr);

            return(error);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public RTCErrorType SetParameters(RTCRtpSendParameters parameters)
        {
            parameters.CreateInstance(out RTCRtpSendParametersInternal instance);
            IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(instance));

            Marshal.StructureToPtr(instance, ptr, false);
            RTCErrorType error = NativeMethods.SenderSetParameters(self, ptr);

            Marshal.FreeCoTaskMem(ptr);
            return(error);
        }