/// <summary>
        /// Initialize the media element for playback
        /// </summary>
        /// <param name="streamConfig">Object containing stream configuration details</param>
        void InitializeMediaPlayer(MoonlightStreamConfiguration streamConfig, AvStreamSource streamSource)
        {
            this._streamSource = streamSource;

            // This code is based upon the MS FFmpegInterop project on GitHub
            VideoEncodingProperties videoProps = VideoEncodingProperties.CreateH264();

            videoProps.ProfileId = H264ProfileIds.High;
            videoProps.Width     = (uint)streamConfig.GetWidth();
            videoProps.Height    = (uint)streamConfig.GetHeight();
            videoProps.Bitrate   = (uint)streamConfig.GetBitrate();

            _videoMss                  = new MediaStreamSource(new VideoStreamDescriptor(videoProps));
            _videoMss.BufferTime       = TimeSpan.Zero;
            _videoMss.CanSeek          = false;
            _videoMss.Duration         = TimeSpan.Zero;
            _videoMss.SampleRequested += _videoMss_SampleRequested;

            XAudio2        xaudio         = new XAudio2();
            MasteringVoice masteringVoice = new MasteringVoice(xaudio, 2, 48000);
            WaveFormat     format         = new WaveFormat(48000, 16, 2);

            // Set for low latency playback
            StreamDisplay.RealTimePlayback = true;

            // Render on the full window to avoid extra compositing
            StreamDisplay.IsFullWindow = true;

            // Disable built-in transport controls
            StreamDisplay.AreTransportControlsEnabled = false;

            StreamDisplay.SetMediaStreamSource(_videoMss);
            AvStream.SetSourceVoice(new SourceVoice(xaudio, format));
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StreamFrame"/> class.
        /// </summary>
        public StreamFrame()
        {
            InitializeComponent();

            // Audio/video stream source init
            AvStream = new AvStreamSource(frameWidth, frameHeight);
            StreamDisplay.SetMediaStreamSource(AvStream);
            StreamDisplay.AutoPlay = true;
            StreamDisplay.Play();

            // Show the progress bar
            Waitgrid.Visibility         = Visibility.Visible;
            currentStateText.Visibility = Visibility.Visible;
        }
Beispiel #3
0
        /// <summary>
        /// Initialize the media element for playback
        /// </summary>
        /// <param name="streamConfig">Object containing stream configuration details</param>
        void InitializeMediaPlayer(LimelightStreamConfiguration streamConfig, AvStreamSource streamSource)
        {
            this._streamSource = streamSource;

            AudioEncodingProperties audioProperties = AudioEncodingProperties.CreatePcm(48000, 2, 16);

            VideoEncodingProperties videoProperties = VideoEncodingProperties.CreateUncompressed(MediaEncodingSubtypes.H264Es,
                                                                                                 (uint)streamConfig.GetWidth(), (uint)streamConfig.GetHeight());

            videoProperties.ProfileId = H264ProfileIds.High;

            _videoDesc = new VideoStreamDescriptor(videoProperties);
            _audioDesc = new AudioStreamDescriptor(audioProperties);

            _mss                  = new MediaStreamSource(_videoDesc, _audioDesc);
            _mss.BufferTime       = TimeSpan.Zero;
            _mss.CanSeek          = false;
            _mss.Duration         = TimeSpan.Zero;
            _mss.SampleRequested += _mss_SampleRequested;

            // Set for low latency playback
            StreamDisplay.RealTimePlayback = true;

            // Set the audio category to take advantage of hardware audio offload
            StreamDisplay.AudioCategory = AudioCategory.ForegroundOnlyMedia;

            // Render on the full window to avoid extra compositing
            StreamDisplay.IsFullWindow = true;

            // Disable built-in transport controls
            StreamDisplay.AreTransportControlsEnabled = false;

            // Start playing right away
            StreamDisplay.AutoPlay = true;

            StreamDisplay.SetMediaStreamSource(_mss);
        }