コード例 #1
0
        public void Setup(VideoEncoderSettings encoderSettings, NetworkSettings networkSettings)
        {
            logger.Debug("ScreenStreamer::Setup()");

            this.Id = "VideoStreamer_" + Guid.NewGuid().ToString();

            this.EncoderSettings = encoderSettings;
            this.NetworkSettings = networkSettings;

            try
            {
                H264Session = new H264Session();
                if (networkSettings.TransportMode == TransportMode.Tcp)
                {
                    RtpSender = new RtpTcpSender(H264Session);
                }
                else if (networkSettings.TransportMode == TransportMode.Udp)
                {
                    RtpSender = new RtpUdpSender(H264Session);
                }
                else
                {
                    throw new FormatException("NotSupportedFormat " + networkSettings.TransportMode);
                }

                //rtpStreamer = new RtpStreamer(h264Session);
                RtpSender.Setup(networkSettings);

                networkSettings.SSRC = H264Session.SSRC;

                RtpSender.Start();

                //var hwContext = screenSource.hwContext;
                //var hwDevice = hwContext.device;

                //var srcSize = videoSource.SrcSize; //new Size(screenSource.Buffer.bitmap.Width, screenSource.Buffer.bitmap.Height);

                //if (encodingSettings.UseResoulutionFromSource)
                //{
                //    encodingSettings.Resolution = srcSize;
                //}

                //encoder = new FFmpegVideoEncoder();
                //encoder.Open(encodingParams);
                //encoder.DataEncoded += Encoder_DataEncoded;

                videoEncoder = new VideoEncoder(videoSource);
                videoEncoder.Open(encoderSettings);
                videoEncoder.DataEncoded += VideoEncoder_DataEncoded;

                videoSource.BufferUpdated += ScreenSource_BufferUpdated;

                state = StreamerState.Initialized;
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                CleanUp();

                throw;
            }
        }
コード例 #2
0
        public void Setup(AudioEncoderSettings encoderSettings, NetworkSettings networkSettings)
        {
            logger.Debug("AudioStreamer::Start(...) ");

            this.Id = "AudioStreamer_" + Guid.NewGuid().ToString();
            this.EncoderSettings = encoderSettings;
            this.NetworkSettings = networkSettings;

            try
            {
                // var capture = audioSource.Capture;
                var waveFormat = audioSource.WaveFormat;

                //bufferedWaveProvider = new BufferedWaveProvider(waveFormat);
                //bufferedWaveProvider.DiscardOnBufferOverflow = true;

                //sampleChannel = new SampleChannel(bufferedWaveProvider);

                audioResampler = new AudioEncoder();

                var captureParams = new AudioEncoderSettings
                {
                    SampleRate = waveFormat.SampleRate,
                    Channels   = waveFormat.Channels,
                };


                audioResampler.Open(captureParams, encoderSettings);

                session = new PCMUSession();

                if (networkSettings.TransportMode == TransportMode.Tcp)
                {
                    RtpSender = new RtpTcpSender(session);
                }
                else if (networkSettings.TransportMode == TransportMode.Udp)
                {
                    RtpSender = new RtpUdpSender(session);
                }
                else
                {
                    throw new FormatException("NotSupportedFormat " + networkSettings.TransportMode);
                }


                audioSource.DataAvailable += AudioSource_DataAvailable;
                RtpSender.Setup(networkSettings);
                networkSettings.SSRC = session.SSRC;



                RtpSender.Start();



                IsStreaming = true;
                OnStateChanged();
            }
            catch (Exception ex)
            {
                logger.Error(ex);

                Close();
            }
        }