Esempio n. 1
0
        public bool Start(StreamSession session)
        {
            logger.Debug("ScreenStreamer::Start(...)");

            Debug.Assert(session != null, "session!=null");

            if (state != MediaStreamerState.Shutdown)
            {
                logger.Warn("ScreenStreamer::Start(...) return invalid state: " + state);
                return(false);
            }

            state = MediaStreamerState.Starting;
            StateChanged?.Invoke();

            streamerThread = new Thread(DoStreaming);
            streamerThread.IsBackground = true;
            streamerThread.Start(session);

            return(true);
        }
Esempio n. 2
0
        public static StreamSession Default()
        {
            //int port = -1;

            //var freeTcpPorts = MediaToolkit.Utils.NetTools.GetFreePortRange(System.Net.Sockets.ProtocolType.Tcp, 1, 808);
            //if (freeTcpPorts != null && freeTcpPorts.Count() > 0)
            //{
            //	port = freeTcpPorts.FirstOrDefault();
            //}

            var session = new StreamSession
            {
                StreamName        = Environment.MachineName,
                NetworkIpAddress  = "0.0.0.0",
                MutlicastAddress  = "239.0.0.1",
                CommunicationPort = 0,
                IsMulticast       = false,
                TransportMode     = TransportMode.Tcp,
            };

            var videoEncoderSettings = new VideoEncoderSettings
            {
                Width         = 1920,
                Height        = 1080,
                EncoderFormat = VideoCodingFormat.H264,
                Profile       = H264Profile.Main,
                BitrateMode   = BitrateControlMode.CBR,
                Bitrate       = 2500,
                MaxBitrate    = 5000,
                FrameRate     = new MediaRatio(30, 1),
                LowLatency    = true,
            };

            var videoSettings = new VideoStreamSettings
            {
                Enabled = true,
                //Id = "video_" + Guid.NewGuid().ToString(),
                NetworkSettings = new NetworkSettings(),
                CaptureDevice   = null,
                EncoderSettings = videoEncoderSettings,
                StreamFlags     = VideoStreamFlags.UseEncoderResoulutionFromSource,

                //ScreenCaptureProperties = captureProperties,
            };

            var audioEncoderSettings = new AudioEncoderSettings
            {
                SampleRate = 8000,
                Channels   = 1,
                Encoding   = "PCMU",
            };

            var audioSettings = new AudioStreamSettings
            {
                Enabled = false,
                //Id = "audio_" + Guid.NewGuid().ToString(),
                NetworkSettings = new NetworkSettings(),
                CaptureDevice   = new AudioCaptureDevice(),
                EncoderSettings = audioEncoderSettings,
            };

            session.AudioSettings = audioSettings;
            session.VideoSettings = videoSettings;

            return(session);
        }