示例#1
0
        private void View_StartWatcherAsked(object sender, EventArgs e)
        {
            // Start watching the parent directory of the current file.
            // This is normally coming from the infobar icon.
            // We do not want to switch to the latest video immediately.

            if (!frameServer.Loaded)
            {
                return;
            }

            string currentFile = frameServer.VideoReader.FilePath;

            if (string.IsNullOrEmpty(currentFile))
            {
                return;
            }

            // Prepare the screen descriptor. All replay watchers must have a valid screen descriptor.
            ScreenDescriptionPlayback sdp = new ScreenDescriptionPlayback();

            sdp.FullPath        = Path.Combine(Path.GetDirectoryName(currentFile), "*");
            sdp.IsReplayWatcher = true;
            sdp.Autoplay        = true;
            //sdp.Stretch = view.IsStretched;
            sdp.Stretch         = false;
            sdp.SpeedPercentage = view.SpeedPercentage;

            StartReplayWatcher(sdp, currentFile);
        }
示例#2
0
        private void OpenFromPath(string path)
        {
            if (Path.GetFileName(path).Contains("*"))
            {
                // Replay watcher.
                ScreenDescriptionPlayback screenDescription = new ScreenDescriptionPlayback();
                screenDescription.FullPath        = path;
                screenDescription.IsReplayWatcher = true;
                screenDescription.Stretch         = true;
                screenDescription.Autoplay        = true;
                screenDescription.SpeedPercentage = PreferencesManager.PlayerPreferences.DefaultReplaySpeed;
                LoaderVideo.LoadVideoInScreen(screenManager, path, screenDescription);

                screenManager.OrganizeScreens();
            }
            else
            {
                // Normal file.
                if (File.Exists(path))
                {
                    LoaderVideo.LoadVideoInScreen(screenManager, path, -1);
                    screenManager.OrganizeScreens();
                }
                else
                {
                    MessageBox.Show(ScreenManagerLang.LoadMovie_FileNotOpened, ScreenManagerLang.LoadMovie_Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
        private static ScreenDescriptionPlayback GetRecoverable(string dir)
        {
            if (!Directory.Exists(dir))
            {
                return(null);
            }

            ScreenDescriptionPlayback sdp = null;

            try
            {
                string dirName = Path.GetFileName(dir);
                Guid   id      = new Guid(dirName);

                string   filename = null;
                DateTime lastSave = DateTime.MinValue;
                foreach (string entry in Directory.GetFiles(dir))
                {
                    if (Path.GetFileName(entry) != "autosave.kva")
                    {
                        continue;
                    }

                    filename = MetadataSerializer.ExtractFullPath(entry);
                    lastSave = File.GetLastWriteTime(entry);
                    break;
                }

                if (!string.IsNullOrEmpty(filename) && File.Exists(filename))
                {
                    sdp                  = new ScreenDescriptionPlayback();
                    sdp.Id               = id;
                    sdp.FullPath         = filename;
                    sdp.RecoveryLastSave = lastSave;
                }
                else
                {
                    log.ErrorFormat("Recovery data were found but the referenced file couldn't be found.");
                }
            }
            catch (Exception e)
            {
                log.ErrorFormat("An error happened while trying to get description of autosaved file");
                log.ErrorFormat(e.ToString());
            }

            return(sdp);
        }
示例#4
0
        public void Start(ScreenDescriptionPlayback sdp, string currentFile)
        {
            log.DebugFormat("Starting replay watcher");

            // We should only come here when initializing the player on a watched folder.
            // currentFile might be null if we started a watcher on an empty directory.
            // the screen descriptor should never be null.
            if (sdp == null)
            {
                log.ErrorFormat("Replay watcher started without screen description.");
                Stop();
                return;
            }

            this.screenDescription = sdp;
            this.currentFile       = currentFile;
            this.filter            = Path.GetFileName(sdp.FullPath);
            string targetDir = Path.GetDirectoryName(sdp.FullPath);

            if (watcher != null)
            {
                if (watcher.Path == targetDir)
                {
                    return;
                }

                Stop();
            }

            if (!Directory.Exists(targetDir))
            {
                return;
            }

            watcher = new FileSystemWatcher(targetDir);

            overwriteEventCount           = 0;
            watcher.NotifyFilter          = NotifyFilters.LastWrite;
            watcher.Filter                = filter;
            watcher.IncludeSubdirectories = false;
            watcher.Changed              += watcher_Changed;
            watcher.Created              += watcher_Changed;
            watcher.EnableRaisingEvents   = true;

            IsEnabled = true;
            log.DebugFormat("Started replay watcher on \"{0}\".", Path.GetFileName(targetDir));
        }
示例#5
0
        public override IScreenDescription GetScreenDescription()
        {
            ScreenDescriptionPlayback sd = new ScreenDescriptionPlayback();

            sd.Id = Id;
            if (Full)
            {
                sd.FullPath        = replayWatcher.IsEnabled ? Path.Combine(Path.GetDirectoryName(FilePath), "*") : FilePath;
                sd.IsReplayWatcher = replayWatcher.IsEnabled;
                sd.Autoplay        = replayWatcher.IsEnabled;
            }
            else
            {
                sd.FullPath        = "";
                sd.IsReplayWatcher = false;
                sd.Autoplay        = false;
            }

            sd.SpeedPercentage = RealtimePercentage;
            sd.Stretch         = view.ImageFill;
            return(sd);
        }
示例#6
0
        public override IScreenDescription GetScreenDescription()
        {
            ScreenDescriptionPlayback sd = new ScreenDescriptionPlayback();

            sd.Id = Id;
            if (Full && replayWatcher != null)
            {
                sd.FullPath        = replayWatcher.IsEnabled ? replayWatcher.FullPath : FilePath;
                sd.IsReplayWatcher = replayWatcher.IsEnabled;
                sd.Autoplay        = replayWatcher.IsEnabled;
            }
            else
            {
                sd.FullPath        = "";
                sd.IsReplayWatcher = false;
                sd.Autoplay        = false;
            }

            sd.SpeedPercentage = RealtimePercentage;
            sd.Stretch         = view.ImageFill;
            return(sd);
        }
示例#7
0
        private void mnuOpenReplayWatcherOnClick(object sender, EventArgs e)
        {
            NotificationCenter.RaiseStopPlayback(this);

            string path = FilePicker.OpenReplayWatcher();

            if (path == null || !Directory.Exists(Path.GetDirectoryName(path)))
            {
                return;
            }

            ScreenDescriptionPlayback screenDescription = new ScreenDescriptionPlayback();

            screenDescription.FullPath        = path;
            screenDescription.IsReplayWatcher = true;
            screenDescription.Stretch         = true;
            screenDescription.Autoplay        = true;
            screenDescription.SpeedPercentage = PreferencesManager.PlayerPreferences.DefaultReplaySpeed;
            LoaderVideo.LoadVideoInScreen(screenManager, path, screenDescription);

            screenManager.OrganizeScreens();
        }
        public void Start(ScreenDescriptionPlayback sdp, string currentFile)
        {
            // We'll pass here upon initialization and also everytime the player is reloaded with a video.
            // Verifiy the file watcher is on the right directory.
            double oldSpeed = screenDescription == null ? 0 : screenDescription.SpeedPercentage;

            this.screenDescription = sdp;
            this.currentFile       = currentFile;

            string watchedDir = Path.GetDirectoryName(sdp.FullPath);

            if (watcher != null)
            {
                if (watcher.Path == watchedDir && oldSpeed == screenDescription.SpeedPercentage)
                {
                    return;
                }

                Close();
            }

            if (!Directory.Exists(watchedDir))
            {
                return;
            }

            watcher = new FileSystemWatcher(watchedDir);

            overwriteEventCount           = 0;
            watcher.NotifyFilter          = NotifyFilters.LastWrite;
            watcher.Filter                = "*.*";
            watcher.IncludeSubdirectories = false;
            watcher.Changed              += watcher_Changed;
            watcher.Created              += watcher_Changed;
            watcher.EnableRaisingEvents   = true;

            IsEnabled = true;
        }
        public static List <ScreenDescriptionPlayback> GetRecoverables()
        {
            if (!Directory.Exists(Software.TempDirectory))
            {
                return(null);
            }

            List <ScreenDescriptionPlayback> recoverables = new List <ScreenDescriptionPlayback>();

            foreach (string dir in Directory.GetDirectories(Software.TempDirectory))
            {
                ScreenDescriptionPlayback sdp = GetRecoverable(dir);
                if (sdp != null)
                {
                    recoverables.Add(sdp);
                }
                else
                {
                    Directory.Delete(dir, true);
                }
            }
            return(recoverables);
        }
示例#10
0
        /// <summary>
        /// Actually loads the video into the chosen screen.
        /// </summary>
        private static void LoadVideo(PlayerScreen player, string path, ScreenDescriptionPlayback screenDescription)
        {
            log.DebugFormat("Loading video {0}.", path);

            NotificationCenter.RaiseStopPlayback(null);

            if (player.FrameServer.Loaded)
            {
                player.view.ResetToEmptyState();
            }

            if (screenDescription != null)
            {
                player.view.SetLaunchDescription(screenDescription);
            }

            OpenVideoResult res = player.FrameServer.Load(path);

            player.Id = Guid.NewGuid();

            if (screenDescription != null && screenDescription.Id != Guid.Empty)
            {
                player.Id = screenDescription.Id;
            }

            switch (res)
            {
            case OpenVideoResult.Success:
            {
                AfterLoadSuccess(player);
                break;
            }

            case OpenVideoResult.FileNotOpenned:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_FileNotOpened);
                break;
            }

            case OpenVideoResult.StreamInfoNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_StreamInfoNotFound);
                break;
            }

            case OpenVideoResult.VideoStreamNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_VideoStreamNotFound);
                break;
            }

            case OpenVideoResult.CodecNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotFound);
                break;
            }

            case OpenVideoResult.CodecNotOpened:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotOpened);
                break;
            }

            case OpenVideoResult.CodecNotSupported:
            case OpenVideoResult.NotSupported:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotSupported);
                break;
            }

            case OpenVideoResult.Cancelled:
            {
                break;
            }

            default:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_UnkownError);
                break;
            }
            }
        }
示例#11
0
        private static void LoadInSpecificTarget(ScreenManagerKernel manager, int targetScreen, string path, ScreenDescriptionPlayback screenDescription)
        {
            AbstractScreen screen = manager.GetScreenAt(targetScreen);

            if (screen is CaptureScreen)
            {
                // Loading a video onto a capture screen should not close the capture screen.
                // If there is room to add a second screen, we add a playback screen and load the video there, otherwise, we don't do anything.
                if (manager.ScreenCount == 1)
                {
                    manager.AddPlayerScreen();
                    manager.UpdateCaptureBuffers();
                    LoadInSpecificTarget(manager, 1, path, screenDescription);
                }
            }
            else if (screen is PlayerScreen)
            {
                PlayerScreen playerScreen = screen as PlayerScreen;
                bool         confirmed    = manager.BeforeReplacingPlayerContent(targetScreen);
                if (!confirmed)
                {
                    return;
                }

                LoadVideo(playerScreen, path, screenDescription);

                if (playerScreen.FrameServer.Loaded)
                {
                    NotificationCenter.RaiseFileOpened(null, path);
                    PreferencesManager.FileExplorerPreferences.AddRecentFile(path);
                    PreferencesManager.Save();
                }

                manager.OrganizeScreens();
                manager.OrganizeCommonControls();
                manager.OrganizeMenus();
                manager.UpdateStatusBar();
            }
        }
示例#12
0
 public void StartReplayWatcher(ScreenDescriptionPlayback sdp, string path)
 {
     replayWatcher.Start(sdp, path);
     view.UpdateReplayWatcher(replayWatcher.IsEnabled, replayWatcher.WatchedFolder);
 }
示例#13
0
 public void StartReplayWatcher(ScreenDescriptionPlayback sdp, string path)
 {
     replayWatcher.Start(sdp, path);
 }
示例#14
0
        /// <summary>
        /// Actually loads the video into the chosen screen.
        /// </summary>
        public static void LoadVideo(PlayerScreen player, string path, ScreenDescriptionPlayback screenDescription)
        {
            log.DebugFormat("Loading video {0}.", Path.GetFileName(path));

            NotificationCenter.RaiseStopPlayback(null);

            if (player.FrameServer.Loaded)
            {
                player.view.ResetToEmptyState();
            }

            player.view.LaunchDescription = screenDescription;
            player.Id = Guid.NewGuid();
            if (screenDescription != null && screenDescription.Id != Guid.Empty)
            {
                player.Id = screenDescription.Id;
            }

            // This can happen when we load an empty screen from launch settings / workspace.
            if (string.IsNullOrEmpty(path))
            {
                player.view.EnableDisableActions(false);
                return;
            }

            OpenVideoResult res = player.FrameServer.Load(path);

            switch (res)
            {
            case OpenVideoResult.Success:
            {
                AfterLoadSuccess(player);
                break;
            }

            case OpenVideoResult.FileNotOpenned:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_FileNotOpened);
                break;
            }

            case OpenVideoResult.StreamInfoNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_StreamInfoNotFound);
                break;
            }

            case OpenVideoResult.VideoStreamNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_VideoStreamNotFound);
                break;
            }

            case OpenVideoResult.CodecNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotFound);
                break;
            }

            case OpenVideoResult.CodecNotOpened:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotOpened);
                break;
            }

            case OpenVideoResult.CodecNotSupported:
            case OpenVideoResult.NotSupported:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotSupported);
                break;
            }

            case OpenVideoResult.Cancelled:
            {
                break;
            }

            case OpenVideoResult.EmptyWatcher:
            {
                break;
            }

            default:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_UnkownError);
                break;
            }
            }

            if (res != OpenVideoResult.Success && player.view.LaunchDescription != null && player.view.LaunchDescription.IsReplayWatcher)
            {
                // Even if we can't load the latest video, or there's no video at all, we should still start watching this folder.
                player.view.EnableDisableActions(false);
                player.StartReplayWatcher(player.view.LaunchDescription, null);
                PreferencesManager.FileExplorerPreferences.LastReplayFolder = path;
                PreferencesManager.Save();
            }
        }
        private static void LoadInSpecificTarget(ScreenManagerKernel manager, int targetScreen, string path, ScreenDescriptionPlayback screenDescription)
        {
            AbstractScreen screen = manager.GetScreenAt(targetScreen);

            if (screen is CaptureScreen)
            {
                // Loading a video onto a capture screen should not close the capture screen.
                // If there is room to add a second screen, we add a playback screen and load the video there, otherwise, we don't do anything.
                if (manager.ScreenCount == 1)
                {
                    manager.AddPlayerScreen();
                    manager.UpdateCaptureBuffers();
                    LoadInSpecificTarget(manager, 1, path, screenDescription);
                }
            }
            else if (screen is PlayerScreen)
            {
                PlayerScreen playerScreen = screen as PlayerScreen;

                if (playerScreen.IsWaitingForIdle)
                {
                    // The player screen will yield its thread after having loaded the first frame and come back later.
                    // We must not launch a new video while it's waiting.
                    log.ErrorFormat("Player screen is currently busy loading the previous video. Aborting load.");
                    return;
                }

                bool confirmed = manager.BeforeReplacingPlayerContent(targetScreen);
                if (!confirmed)
                {
                    return;
                }

                LoadVideo(playerScreen, path, screenDescription);

                bool prefsNeedSaving = false;
                if (screenDescription != null && screenDescription.IsReplayWatcher)
                {
                    PreferencesManager.FileExplorerPreferences.AddRecentWatcher(path);
                    PreferencesManager.FileExplorerPreferences.LastReplayFolder = path;
                    prefsNeedSaving = true;
                }

                if (playerScreen.FrameServer.Loaded)
                {
                    NotificationCenter.RaiseFileOpened(null, path);

                    if (screenDescription != null && screenDescription.IsReplayWatcher)
                    {
                        // At this point we have lost the actual file that was loaded. The path here still contaiins the special '*' to indicate the watched folder.
                        // The actual file is the latest file in the folder this was computed right before loading.
                        string actualPath = FilesystemHelper.GetMostRecentFile(Path.GetDirectoryName(path));
                        PreferencesManager.FileExplorerPreferences.AddRecentFile(actualPath);
                    }
                    else
                    {
                        PreferencesManager.FileExplorerPreferences.AddRecentFile(path);
                    }

                    prefsNeedSaving = true;
                }

                if (prefsNeedSaving)
                {
                    PreferencesManager.Save();
                }

                manager.OrganizeScreens();
                manager.OrganizeCommonControls();
                manager.OrganizeMenus();
                manager.UpdateStatusBar();
            }
        }
 private static void LoadUnspecified(ScreenManagerKernel manager, string path, ScreenDescriptionPlayback screenDescription)
 {
     if (manager.ScreenCount == 0)
     {
         manager.AddPlayerScreen();
         LoadInSpecificTarget(manager, 0, path, screenDescription);
     }
     else if (manager.ScreenCount == 1)
     {
         LoadInSpecificTarget(manager, 0, path, screenDescription);
     }
     else if (manager.ScreenCount == 2)
     {
         int target = manager.FindTargetScreen(typeof(PlayerScreen));
         if (target != -1)
         {
             LoadInSpecificTarget(manager, target, path, screenDescription);
         }
     }
 }
 public static void LoadVideoInScreen(ScreenManagerKernel manager, string path, ScreenDescriptionPlayback screenDescription)
 {
     LoadUnspecified(manager, path, screenDescription);
 }
 public static void LoadVideoInScreen(ScreenManagerKernel manager, string path, int targetScreen, ScreenDescriptionPlayback screenDescription = null)
 {
     if (targetScreen < 0)
     {
         LoadUnspecified(manager, path, screenDescription);
     }
     else
     {
         LoadInSpecificTarget(manager, targetScreen, path, screenDescription);
     }
 }
        /// <summary>
        /// Actually loads the video into the chosen screen.
        /// </summary>
        public static void LoadVideo(PlayerScreen player, string path, ScreenDescriptionPlayback screenDescription)
        {
            // In the case of replay watcher this will only be called the first time, to setup the screen.
            // Subsequent video loads will be done directly by the replay watcher.

            log.DebugFormat("Loading video {0}.", Path.GetFileName(path));

            NotificationCenter.RaiseStopPlayback(null);

            if (player.FrameServer.Loaded)
            {
                player.view.ResetToEmptyState();
            }

            player.view.LaunchDescription = screenDescription;

            OpenVideoResult res = player.FrameServer.Load(path);

            player.Id = Guid.NewGuid();

            if (screenDescription != null && screenDescription.Id != Guid.Empty)
            {
                player.Id = screenDescription.Id;
            }

            switch (res)
            {
            case OpenVideoResult.Success:
            {
                AfterLoadSuccess(player);
                break;
            }

            case OpenVideoResult.FileNotOpenned:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_FileNotOpened);
                break;
            }

            case OpenVideoResult.StreamInfoNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_StreamInfoNotFound);
                break;
            }

            case OpenVideoResult.VideoStreamNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_VideoStreamNotFound);
                break;
            }

            case OpenVideoResult.CodecNotFound:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotFound);
                break;
            }

            case OpenVideoResult.CodecNotOpened:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotOpened);
                break;
            }

            case OpenVideoResult.CodecNotSupported:
            case OpenVideoResult.NotSupported:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_CodecNotSupported);
                break;
            }

            case OpenVideoResult.Cancelled:
            {
                break;
            }

            case OpenVideoResult.EmptyWatcher:
            {
                break;
            }

            default:
            {
                DisplayErrorAndDisable(player, ScreenManagerLang.LoadMovie_UnkownError);
                break;
            }
            }

            if (res != OpenVideoResult.Success && player.view.LaunchDescription != null && player.view.LaunchDescription.IsReplayWatcher)
            {
                // Even if we can't load the latest video, or there's no video at all, we should still start watching this folder.
                player.view.EnableDisableActions(false);
                player.StartReplayWatcher(player.view.LaunchDescription, null);
                PreferencesManager.FileExplorerPreferences.LastReplayFolder = path;
                PreferencesManager.Save();
            }
        }
示例#20
0
        private static void LoadUnspecified(ScreenManagerKernel manager, string path, ScreenDescriptionPlayback screenDescription)
        {
            if (manager.ScreenCount == 0)
            {
                manager.AddPlayerScreen();
                LoadInSpecificTarget(manager, 0, path, screenDescription);
            }
            else if (manager.ScreenCount == 1)
            {
                LoadInSpecificTarget(manager, 0, path, screenDescription);
            }
            else if (manager.ScreenCount == 2)
            {
                int emptyScreen = manager.FindEmptyScreen();

                if (emptyScreen != -1)
                {
                    LoadInSpecificTarget(manager, emptyScreen, path, screenDescription);
                }
                else
                {
                    LoadInSpecificTarget(manager, 1, path, screenDescription);
                }
            }
        }
示例#21
0
        public static void LoadVideoInScreen(ScreenManagerKernel manager, string path, int targetScreen, ScreenDescriptionPlayback screenDescription = null)
        {
            CameraTypeManager.CancelThumbnails();
            CameraTypeManager.StopDiscoveringCameras();

            if (targetScreen < 0)
            {
                LoadUnspecified(manager, path, screenDescription);
            }
            else
            {
                LoadInSpecificTarget(manager, targetScreen, path, screenDescription);
            }
        }
示例#22
0
        public static void LoadVideoInScreen(ScreenManagerKernel manager, string path, ScreenDescriptionPlayback screenDescription)
        {
            CameraTypeManager.CancelThumbnails();
            CameraTypeManager.StopDiscoveringCameras();

            LoadUnspecified(manager, path, screenDescription);
        }