public void CreateFromUri_Bad_Input()
        {
            // CreateFFmpegInteropMSSFromUri should return null when given bad uri
            FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri("http://This.is.a.bad.uri", false, false);

            Assert.IsNull(FFmpegMSS);
        }
        public void CreateFromUri_Destructor()
        {
            // CreateFFmpegInteropMSSFromUri should return valid FFmpegInteropMSS object which generates valid MediaStreamSource object
            FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(_UriSource, false, false);

            Assert.IsNotNull(FFmpegMSS);

            MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();

            Assert.IsNotNull(mss);

            // Based on the provided media, check if the following properties are set correctly
            Assert.AreEqual(true, mss.CanSeek);
            Assert.AreNotEqual(0, mss.BufferTime.TotalMilliseconds);
            Assert.AreEqual(_UriLength, mss.Duration.TotalMilliseconds);

            // Keep original reference and ensure object are not destroyed until each reference is released by setting it to nullptr
            FFmpegInteropMSS  OriginalFFmpegMSS = FFmpegMSS;
            MediaStreamSource Originalmss       = mss;

            FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri("", false, false);
            Assert.IsNull(FFmpegMSS);
            Assert.IsNotNull(OriginalFFmpegMSS);
            Assert.IsNotNull(Originalmss);

            mss = null;
            Assert.IsNull(mss);
            Assert.IsNotNull(Originalmss);

            OriginalFFmpegMSS = null;
            Originalmss       = null;
            Assert.IsNull(OriginalFFmpegMSS);
            Assert.IsNull(Originalmss);
        }
        public void CreateFromUri_Options()
        {
            // Setup options PropertySet to configure FFmpeg
            PropertySet options = new PropertySet();

            options.Add("rtsp_flags", "prefer_tcp");
            options.Add("stimeout", 100000);
            Assert.IsNotNull(options);

            // CreateFFmpegInteropMSSFromUri should return valid FFmpegInteropMSS object which generates valid MediaStreamSource object
            FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(Constants.StreamingUriSource, false, false, options);

            Assert.IsNotNull(FFmpegMSS);

            // Validate the metadata
            Assert.AreEqual(FFmpegMSS.AudioCodecName.ToLowerInvariant(), "aac");
            Assert.AreEqual(FFmpegMSS.VideoCodecName.ToLowerInvariant(), "h264");

            MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();

            Assert.IsNotNull(mss);

            // Based on the provided media, check if the following properties are set correctly
            Assert.AreEqual(true, mss.CanSeek);
            Assert.AreNotEqual(0, mss.BufferTime.TotalMilliseconds);
            Assert.AreEqual(Constants.StreamingUriLength, mss.Duration.TotalMilliseconds);
        }
Exemple #4
0
        public void Stream(Object source, EventArgs e)
        {
            try
            {
                PropertySet options = new PropertySet();
                Player.Stop();
                options.Add("rtsp_transport", "tcp");

                FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(Settings.Source, false, true, options);
                if (FFmpegMSS != null)
                {
                    MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();
                    if (mss != null)
                    {
                        Player.SetMediaStreamSource(mss);
                    }
                    else
                    {
                        Errors(1);
                        return;
                    }
                }
                else
                {
                    Errors(2);
                    return;
                }
            }
            catch
            {
                Errors(3);
                return;
            }
        }
Exemple #5
0
        private void URIBoxKeyUp(object sender, KeyRoutedEventArgs e)
        {
            var    textBox = sender as TextBox;
            String uri     = textBox.Text;

            // Only respond when the text box is not empty and after Enter key is pressed
            if (e.Key == Windows.System.VirtualKey.Enter && !String.IsNullOrWhiteSpace(uri))
            {
                // Mark event as handled to prevent duplicate event to re-triggered
                e.Handled = true;

                try
                {
                    // Read toggle switches states and use them to setup FFmpeg MSS
                    bool forceDecodeAudio = toggleSwitchAudioDecode.IsOn;
                    bool forceDecodeVideo = toggleSwitchVideoDecode.IsOn;

                    // Set FFmpeg specific options. List of options can be found in https://www.ffmpeg.org/ffmpeg-protocols.html
                    PropertySet options = new PropertySet();

                    // Below are some sample options that you can set to configure RTSP streaming
                    // options.Add("rtsp_flags", "prefer_tcp");
                    // options.Add("stimeout", 100000);

                    // Instantiate FFmpegInteropMSS using the URI
                    mediaElement.Stop();
                    FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(uri, forceDecodeAudio, forceDecodeVideo, options);
                    if (FFmpegMSS != null)
                    {
                        MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();

                        if (mss != null)
                        {
                            // Pass MediaStreamSource to Media Element
                            mediaElement.SetMediaStreamSource(mss);

                            // Close control panel after opening media
                            Splitter.IsPaneOpen = false;
                        }
                        else
                        {
                            DisplayErrorMessage("Cannot open media");
                        }
                    }
                    else
                    {
                        DisplayErrorMessage("Cannot open media");
                    }
                }
                catch (Exception ex)
                {
                    DisplayErrorMessage(ex.Message);
                }
            }
        }
        public void CreateFromUri_Null()
        {
            // CreateFFmpegInteropMSSFromUri should return null if uri is blank with default parameter
            FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(string.Empty, false, false);

            Assert.IsNull(FFmpegMSS);

            // CreateFFmpegInteropMSSFromUri should return null if uri is blank with non default parameter
            FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(string.Empty, true, true);
            Assert.IsNull(FFmpegMSS);
        }
Exemple #7
0
        public void LoadData(string url)
        {
            var options = new PropertySet();

            _fFmpegMss = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(url, false, true, options);

            _feedSource = _fFmpegMss?.GetMediaStreamSource();

            if (_feedSource != null)
            {
                meFeed.SetMediaStreamSource(_feedSource);
            }
        }
Exemple #8
0
        private void URIBoxKeyUp(object sender, KeyRoutedEventArgs e)
        {
            string uri = (sender as TextBox).Text;

            // Only respond when the text box is not empty and after Enter key is pressed
            if (e.Key == VirtualKey.Enter && !string.IsNullOrWhiteSpace(uri))
            {
                // Mark event as handled to prevent duplicate event to re-triggered
                e.Handled = true;

                bool forceDecodeAudio = toggleSwitchAudioDecode.IsOn;
                bool forceDecodeVideo = toggleSwitchVideoDecode.IsOn;

                // Set FFmpeg specific options. List of options can be found in https://www.ffmpeg.org/ffmpeg-protocols.html
                var options = new PropertySet();

                // Below are some sample options that you can set to configure RTSP streaming
                // options.Add("rtsp_flags", "prefer_tcp");
                // options.Add("stimeout", 100000);

                // http options
                options.Add("user_agent", "MediaPlayerCS");

                try
                {
                    mediaElement.Stop();

                    FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(uri, forceDecodeAudio, forceDecodeVideo, options);
                    if (FFmpegMSS == null)
                    {
                        DisplayErrorMessage("Cannot open media");
                        return;
                    }

                    var mss = FFmpegMSS.GetMediaStreamSource();
                    if (mss == null)
                    {
                        DisplayErrorMessage("Cannot open media");
                        return;
                    }

                    // Pass MediaStreamSource to Media Element
                    mediaElement.SetMediaStreamSource(mss);
                    Splitter.IsPaneOpen = false;
                }
                catch (Exception ex)
                {
                    DisplayErrorMessage(ex.Message);
                }
            }
        }
        private void URIBoxKeyUp(object sender, KeyRoutedEventArgs e)
        {
            var    textBox = sender as TextBox;
            String uri     = textBox.Text;

            // Only respond when the text box is not empty and after Enter key is pressed
            if (e.Key == Windows.System.VirtualKey.Enter && !String.IsNullOrWhiteSpace(uri))
            {
                // Mark event as handled to prevent duplicate event to re-triggered
                e.Handled = true;

                try
                {
                    // Read toggle switches states and use them to setup FFmpeg MSS
                    bool forceDecodeAudio = toggleSwitchAudioDecode.IsOn;
                    bool forceDecodeVideo = toggleSwitchVideoDecode.IsOn;

                    // Instantiate FFmpegInteropMSS using the URI
                    mediaElement.Stop();
                    FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(uri, forceDecodeAudio, forceDecodeVideo);
                    if (FFmpegMSS != null)
                    {
                        MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();

                        if (mss != null)
                        {
                            // Pass MediaStreamSource to Media Element
                            mediaElement.SetMediaStreamSource(mss);

                            // Close control panel after opening media
                            Splitter.IsPaneOpen = false;
                        }
                        else
                        {
                            DisplayErrorMessage("Cannot open media");
                        }
                    }
                    else
                    {
                        DisplayErrorMessage("Cannot open media");
                    }
                }
                catch (Exception ex)
                {
                    DisplayErrorMessage(ex.Message);
                }
            }
        }
        public void CreateFromUri_Force_Audio_Video()
        {
            // CreateFFmpegInteropMSSFromUri should return valid FFmpegInteropMSS object which generates valid MediaStreamSource object
            FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(_UriSource, true, true);

            Assert.IsNotNull(FFmpegMSS);

            MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();

            Assert.IsNotNull(mss);

            // Based on the provided media, check if the following properties are set correctly
            Assert.AreEqual(true, mss.CanSeek);
            Assert.AreNotEqual(0, mss.BufferTime.TotalMilliseconds);
            Assert.AreEqual(_UriLength, mss.Duration.TotalMilliseconds);
        }
        public void CreateFromUri_Force_Video()
        {
            // CreateFFmpegInteropMSSFromUri should return valid FFmpegInteropMSS object which generates valid MediaStreamSource object
            FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov", false, true);

            Assert.IsNotNull(FFmpegMSS);

            MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();

            Assert.IsNotNull(mss);

            // Based on the provided media, check if the following properties are set correctly
            Assert.AreEqual(true, mss.CanSeek);
            Assert.AreNotEqual(0, mss.BufferTime.TotalMilliseconds);
            Assert.AreEqual(596458, mss.Duration.TotalMilliseconds);
        }
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            url = e.Parameter as string;
            if (dispRequest == null)
            {
                // 用户观看视频,需要保持屏幕的点亮状态
                dispRequest = new DisplayRequest();
                dispRequest.RequestActive(); // 激活显示请求
            }
            DisplayInformation.AutoRotationPreferences = (DisplayOrientations)5;
            string urls = await GetDiliVideoUri(url);

            PropertySet options = new PropertySet();

            if (urls != string.Empty)
            {
                await Task.Run(async() =>
                {
                    FFmpegMSS             = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(urls, true, true, options);
                    MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();
                    //Pass MediaStreamSource to Media Element
                    await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        mediaElment.SetMediaStreamSource(mss);
                        mediaElment.RealTimePlayback = true;
                    });
                });

                // mediaElment.Source = new Uri(urls);
                // PropertySet options = new PropertySet();
                // mediaElment.Stop();
                //FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(urls, false, true, options);
                // MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();
                //Pass MediaStreamSource to Media Element
                //mediaElment.SetMediaStreamSource(mss);
            }
            else
            {
                await new MessageDialog("读取地址失败").ShowAsync();
            }
        }
        public void CreateFromUri_Force_Video()
        {
            // CreateFFmpegInteropMSSFromUri should return valid FFmpegInteropMSS object which generates valid MediaStreamSource object
            FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(Constants.StreamingUriSource, false, true);

            Assert.IsNotNull(FFmpegMSS);

            // Validate the metadata
            Assert.AreEqual(FFmpegMSS.AudioCodecName.ToLowerInvariant(), "aac");
            Assert.AreEqual(FFmpegMSS.VideoCodecName.ToLowerInvariant(), "h264");

            MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();

            Assert.IsNotNull(mss);

            // Based on the provided media, check if the following properties are set correctly
            Assert.AreEqual(true, mss.CanSeek);
            Assert.AreNotEqual(0, mss.BufferTime.TotalMilliseconds);
            Assert.AreEqual(Constants.StreamingUriLength, mss.Duration.TotalMilliseconds);
        }
Exemple #14
0
        /// <summary>
        /// 设置FFmpeg媒体源
        /// </summary>
        private void SetFFmpegSource(string url)
        {
            FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri(url, force_a, force_v);
            MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();

            if (mss != null)
            {
                media.SetMediaStreamSource(mss);
            }
            // 更新当前分段
            int index = URL.Ps.FindIndex(p => p.Url == url);

            _currentP = URL.Ps[index];
            ///更新时间偏移量,用于<see cref="Timer_danmaku_Tick(object, object)"/>
            _offsettime = 0;
            for (int i = index; i > 0; i--)
            {
                _offsettime += (int)(URL.Ps[i - 1].Length / 1000);
            }
        }
        public void CreateFromUri_Options()
        {
            // Setup options PropertySet to configure FFmpeg
            PropertySet options = new PropertySet();

            options.Add("rtsp_flags", "prefer_tcp");
            options.Add("stimeout", 100000);
            Assert.IsNotNull(options);

            // CreateFFmpegInteropMSSFromUri should return valid FFmpegInteropMSS object which generates valid MediaStreamSource object
            FFmpegInteropMSS FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromUri("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov", false, false, options);

            Assert.IsNotNull(FFmpegMSS);

            MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource();

            Assert.IsNotNull(mss);

            // Based on the provided media, check if the following properties are set correctly
            Assert.AreEqual(true, mss.CanSeek);
            Assert.AreNotEqual(0, mss.BufferTime.TotalMilliseconds);
            Assert.AreEqual(596458, mss.Duration.TotalMilliseconds);
        }