예제 #1
0
        public async Task ReadSimple_WmvVideo_Seek()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            ResourceLink videoLink = new AssemblyResourceLink(
                this.GetType().Assembly,
                "SeeingSharp.Tests.Rendering.Ressources.Videos",
                "DummyVideo.wmv");

            GDI.Bitmap bitmapFrame = null;
            using (FrameByFrameVideoReader videoReader = new FrameByFrameVideoReader(videoLink))
                using (MemoryMappedTexture32bpp actFrameBuffer = new MemoryMappedTexture32bpp(videoReader.FrameSize))
                {
                    videoReader.SetCurrentPosition(TimeSpan.FromSeconds(2.0));
                    videoReader.ReadFrame(actFrameBuffer);

                    actFrameBuffer.SetAllAlphaValuesToOne_ARGB();

                    using (bitmapFrame = GraphicsHelper.LoadBitmapFromMappedTexture(actFrameBuffer))
                    {
                        Assert.NotNull(bitmapFrame);
                        Assert.True(videoReader.CurrentPosition > TimeSpan.FromSeconds(1.9));
                        Assert.True(videoReader.CurrentPosition < TimeSpan.FromSeconds(2.1));
                        Assert.True(videoReader.Duration > TimeSpan.FromSeconds(3.9));
                        Assert.True(videoReader.Duration < TimeSpan.FromSeconds(4.1));
                        Assert.True(videoReader.IsSeekable);
                        Assert.True(
                            BitmapComparison.IsNearEqual(bitmapFrame, Properties.Resources.ReferenceImage_VideoFrameWmv_Seek));
                    }
                }
        }
예제 #2
0
        public async Task ReadSimple_WmvVideo()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            ResourceLink videoLink = new AssemblyResourceLink(
                this.GetType().Assembly,
                "SeeingSharp.Tests.Rendering.Ressources.Videos",
                "DummyVideo.wmv");

            GDI.Bitmap bitmapFrame10 = null;
            using (FrameByFrameVideoReader videoReader = new FrameByFrameVideoReader(videoLink))
                using (MemoryMappedTexture32bpp actFrameBuffer = new MemoryMappedTexture32bpp(videoReader.FrameSize))
                {
                    int frameIndex = 0;
                    while (!videoReader.EndReached)
                    {
                        if (videoReader.ReadFrame(actFrameBuffer))
                        {
                            actFrameBuffer.SetAllAlphaValuesToOne_ARGB();

                            frameIndex++;
                            if (frameIndex != 10)
                            {
                                continue;
                            }

                            bitmapFrame10 = GraphicsHelper.LoadBitmapFromMappedTexture(actFrameBuffer);
                            break;
                        }
                    }

                    Assert.NotNull(bitmapFrame10);
                    Assert.True(videoReader.Duration > TimeSpan.FromSeconds(3.9));
                    Assert.True(videoReader.Duration < TimeSpan.FromSeconds(4.1));
                    Assert.True(videoReader.IsSeekable);
                    Assert.True(
                        BitmapComparison.IsNearEqual(bitmapFrame10, Properties.Resources.ReferenceImage_VideoFrameWmv));
                }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VideoThumbnailTextureResource"/> class.
        /// </summary>
        /// <param name="videoSource">The video source.</param>
        /// <param name="timestamp">The Timestamp from which to create the timestamp.</param>
        public VideoThumbnailTextureResource(ResourceLink videoSource, TimeSpan timestamp)
        {
            videoSource.EnsureNotNull(nameof(videoSource));
            timestamp.EnsureLongerOrEqualZero(nameof(timestamp));

            // Create the FrameByFrameVideoReader
            try
            {
                m_videoReader = new FrameByFrameVideoReader(videoSource);
                m_videoReader.EnsureSeekable(nameof(m_videoReader));
            }
            catch
            {
                GraphicsHelper.SafeDispose(ref m_videoReader);
                throw;
            }

            // Store width and height of the video (to prepare target texture)
            m_videoWidth  = m_videoReader.FrameSize.Width;
            m_videoHeight = m_videoReader.FrameSize.Height;

            m_thumbnailTimestamp = timestamp;
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LevelData"/> class.
        /// </summary>
        /// <param name="directoryName">Name of the directory.</param>
        private LevelData(string directoryName)
        {
            m_musicFilePaths = new List<string>();

            // Search all main textures
            this.MainTextures = new MainTextureData(directoryName);

            // Handle tilemap file
            string tilemapPath = Path.Combine(directoryName, Constants.FILENAME_TILEMAP);
            if (File.Exists(tilemapPath))
            {
                this.Tilemap = TilemapData.FromFile(tilemapPath);
            }
            else
            {
                this.Tilemap = new TilemapData();
            }

            // Set reference to the main icon
            string appIconPath = Path.Combine(directoryName, Constants.FILENAME_APPICON);
            if (File.Exists(appIconPath))
            {
                this.AppIconPath = appIconPath;
            }

            // Load common level settings
            string levelSettingsPath = Path.Combine(directoryName, Constants.FILENAME_LEVELSETTINGS);
            if (File.Exists(levelSettingsPath))
            {
                this.LevelSettings = CommonTools.DeserializeFromXmlFile<LevelSettings>(levelSettingsPath);
            }
            else
            {
                this.LevelSettings = LevelSettings.Default;
            }

            // Load music folder
            string musicFolder = Path.Combine(directoryName, Constants.FOLDERNAME_MUSIC);
            if (Directory.Exists(musicFolder))
            {
                foreach (string actFileName in Directory.GetFiles(musicFolder))
                {
                    string actFileExtension = Path.GetExtension(actFileName);
                    if (!Constants.SUPPORTED_MUSIC_FORMATS.ContainsString(actFileExtension, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    m_musicFilePaths.Add(actFileName);
                }
            }

            // Load ending folder
            string endingFolder = Path.Combine(directoryName, Constants.FOLDERNAME_ENDING);
            if (Directory.Exists(endingFolder))
            {
                foreach (string actFileName in Directory.GetFiles(endingFolder))
                {
                    if (Constants.SUPPORTED_VIDEO_FORMATS.Contains(Path.GetExtension(actFileName)))
                    {
                        this.EndingVideo = actFileName;

                        using (FrameByFrameVideoReader videoReader = new FrameByFrameVideoReader(actFileName))
                        {
                            // Read the first frame
                            this.EndingVideoFirstFrame = videoReader.ReadFrame();
                            this.EndingVideoFirstFrame.SetAllAlphaValuesToOne_ARGB();

                            // Read the last frame
                            videoReader.SetCurrentPosition(videoReader.Duration, false);

                            this.EndingVideoLastFrame = videoReader.ReadFrame();
                            this.EndingVideoLastFrame.SetAllAlphaValuesToOne_ARGB();
                        }

                        continue;
                    }

                    if (Constants.SUPPORTED_IMAGE_FORMATS.Contains(Path.GetExtension(actFileName)))
                    {
                        this.EndingImage = actFileName;
                        continue;
                    }

                    if (Constants.SUPPORTED_MUSIC_FORMATS.Contains(Path.GetExtension(actFileName)))
                    {
                        this.EndingMusic = actFileName;
                        continue;
                    }
                }
            }

            // Load all screens
            IEnumerable<string> screenDirectories =
                from actScreenDirectory in Directory.GetDirectories(directoryName)
                where Path.GetFileName(actScreenDirectory).StartsWith(Constants.FOLDERPREFIX_SCREEN, StringComparison.OrdinalIgnoreCase)
                orderby Path.GetFileName(actScreenDirectory)
                select actScreenDirectory;
            this.Screens = new List<ScreenData>();
            foreach (string actScreenDirectory in screenDirectories)
            {
                ScreenData actScreen = new ScreenData(actScreenDirectory);
                if (actScreen.MemoryPairs.Count > 0)
                {
                    this.Screens.Add(actScreen);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Processes the given video file.
        /// </summary>
        /// <param name="filePath">The path to the vide file.</param>
        internal void ProcessVideoFile(string filePath)
        {
            m_childVideoFiles.Add(filePath);

            using (FrameByFrameVideoReader videoReader = new FrameByFrameVideoReader(filePath))
            {
                // Read the first frame
                this.FirstVideoFrame = videoReader.ReadFrame();
                this.FirstVideoFrame.SetAllAlphaValuesToOne_ARGB();

                // Read the last frame
                videoReader.SetCurrentPosition(videoReader.Duration, false);

                this.LastVideoFrame = videoReader.ReadFrame();
                this.LastVideoFrame.SetAllAlphaValuesToOne_ARGB();
            }
        }