예제 #1
0
        private void OpenMedia(Action <MediaStreamSource, FFmpegInteropMSSConfig> createFunc)
        {
            // Stop any media currently playing
            mediaElement.Stop();

            try
            {
                // Create the media source
                IActivationFactory mssFactory = WindowsRuntimeMarshal.GetActivationFactory(typeof(MediaStreamSource));
                MediaStreamSource  mss        = mssFactory.ActivateInstance() as MediaStreamSource;

                var config = new FFmpegInteropMSSConfig
                {
                    ForceAudioDecode = toggleSwitchAudioDecode.IsOn,
                    ForceVideoDecode = toggleSwitchVideoDecode.IsOn
                };

                createFunc(mss, config);

                // Set the MSS as the media element's source
                mediaElement.SetMediaStreamSource(mss);

                // Close the control panel
                splitter.IsPaneOpen = false;
            }
            catch (Exception)
            {
                OnError("Failed to open media");
            }
        }
예제 #2
0
        public void CreateFromUri_Null()
        {
            // CreateFFmpegInteropMSSFromUri should throw if uri is blank with default parameter
            try
            {
                CreateMSSFromUri(string.Empty, null);
                Assert.IsTrue(false);
            }
            catch (Exception)
            {
                // Call threw as expected
            }

            // CreateFFmpegInteropMSSFromUri should throw if uri is blank with non default parameter
            try
            {
                var config = new FFmpegInteropMSSConfig
                {
                    ForceAudioDecode = true,
                    ForceVideoDecode = true
                };

                CreateMSSFromUri(string.Empty, config);
                Assert.IsTrue(false);
            }
            catch (Exception)
            {
                // Call threw as expected
            }
        }
        public void CreateFromStream_Null()
        {
            // FFmpegInteropMSS.CreateFromStream should throw if stream is null with default parameter
            try
            {
                CreateMSSFromStream(null, null);
                Assert.IsTrue(false);
            }
            catch (Exception)
            {
                // Call threw as expected
            }

            // FFmpegInteropMSS.CreateFromStream should return null if stream is null with non default parameter
            try
            {
                var config = new FFmpegInteropMSSConfig
                {
                    ForceAudioDecode = true,
                    ForceVideoDecode = true
                };

                CreateMSSFromStream(null, config);
                Assert.IsTrue(false);
            }
            catch (Exception)
            {
                // Call threw as expected
            }
        }
예제 #4
0
        private MediaStreamSource CreateMSSFromStream(IRandomAccessStream stream, FFmpegInteropMSSConfig config)
        {
            // Create the MSS
            IActivationFactory mssFactory = WindowsRuntimeMarshal.GetActivationFactory(typeof(MediaStreamSource));
            MediaStreamSource  mss        = mssFactory.ActivateInstance() as MediaStreamSource;

            // Create the FFmpegInteropMSS from the provided stream
            FFmpegInteropMSS.CreateFromStream(stream, mss, config);

            return(mss);
        }
예제 #5
0
        public void CreateFromUri_Force_Video()
        {
            // Create the MSS with forced video decode
            var config = new FFmpegInteropMSSConfig
            {
                ForceVideoDecode = true
            };

            MediaStreamSource mss = CreateMSSFromUri(Constants.StreamingUriSource, config);

            // Based on the provided media, check if the following properties are set correctly
            Assert.IsTrue(mss.CanSeek);
            Assert.IsTrue(mss.BufferTime.TotalMilliseconds > 0);
            Assert.AreEqual(Constants.StreamingUriLength, mss.Duration.TotalMilliseconds);

            // TODO: Verify expected stream types (aac, NV12)
        }
예제 #6
0
        public void CreateFromUri_Options()
        {
            // Create the MSS with the set FFmpeg options
            var config  = new FFmpegInteropMSSConfig();
            var options = config.FFmpegOptions;

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

            MediaStreamSource mss = CreateMSSFromUri(Constants.StreamingUriSource, config);

            // Based on the provided media, check if the following properties are set correctly
            Assert.IsTrue(mss.CanSeek);
            Assert.IsTrue(mss.BufferTime.TotalMilliseconds > 0);
            Assert.AreEqual(Constants.StreamingUriLength, mss.Duration.TotalMilliseconds);

            // TODO: Verify expected stream types (aac, h264)
        }
        public async Task CreateFromStream_Force_Video()
        {
            Uri         uri  = new Uri(Constants.DownloadUriSource);
            StorageFile file = await StorageFile.CreateStreamedFileFromUriAsync(Constants.DownloadStreamedFileName, uri, null);

            IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

            // Create the MSS with forced video decode
            var config = new FFmpegInteropMSSConfig
            {
                ForceVideoDecode = true
            };

            MediaStreamSource mss = CreateMSSFromStream(stream, config);

            // Based on the provided media, check if the following properties are set correctly
            Assert.IsTrue(mss.CanSeek);
            Assert.IsTrue(mss.BufferTime.TotalMilliseconds > 0);
            Assert.AreEqual(Constants.DownloadUriLength, mss.Duration.TotalMilliseconds);
        }
        public async Task CreateFromStream_Options()
        {
            Uri         uri  = new Uri(Constants.DownloadUriSource);
            StorageFile file = await StorageFile.CreateStreamedFileFromUriAsync(Constants.DownloadStreamedFileName, uri, null);

            IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

            // Create the MSS with FFmpeg options set
            var config  = new FFmpegInteropMSSConfig();
            var options = config.FFmpegOptions;

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

            MediaStreamSource mss = CreateMSSFromStream(stream, config);

            // Based on the provided media, check if the following properties are set correctly
            Assert.IsTrue(mss.CanSeek);
            Assert.IsTrue(mss.BufferTime.TotalMilliseconds > 0);
            Assert.AreEqual(Constants.DownloadUriLength, mss.Duration.TotalMilliseconds);

            // TODO: Verify expected stream types (aac, h264)
        }