public static void ImportDirectory(string dir) { // Import all files from the directory into corresponding entries. // Used for debugging and as a conveniency for first time use. List <CaptureHistoryEntry> entries = new List <CaptureHistoryEntry>(); foreach (string file in Directory.GetFiles(dir)) { string extension = Path.GetExtension(file); if (!VideoTypeManager.IsSupported(extension)) { continue; } CaptureHistoryEntry entry = CreateEntryFromFile(file); entries.Add(entry); } entries.Sort((e1, e2) => e1.Start.CompareTo(e2.Start)); foreach (CaptureHistoryEntry entry in entries) { AddEntry(entry); } }
private void watcher_Changed(object sender, FileSystemEventArgs e) { if (!VideoTypeManager.IsSupported(Path.GetExtension(e.FullPath))) { return; } if (e.FullPath == currentFile) { // In this case we can't use the normal heuristic of trying to get exclusive access on the file, // because the player screen itself already has the file opened. // First of all we need to stop the player from playing the file as it's reading frames from disk (no caching). dummy.BeginInvoke((Action) delegate { player.StopPlaying(); }); // We normally receive only two events. One at start and one on close. overwriteEventCount++; if (overwriteEventCount >= 2) { overwriteEventCount = 0; dummy.BeginInvoke((Action) delegate { LoadVideo(e.FullPath); }); } } else { if (FilesystemHelper.CanRead(e.FullPath)) { dummy.BeginInvoke((Action) delegate { LoadVideo(e.FullPath); }); } } }
public RootKernel(bool firstInstance) { CommandLineArgumentManager.Instance.ParseArguments(Environment.GetCommandLineArgs()); VideoTypeManager.LoadVideoReaders(); CameraTypeManager.LoadCameraManagers(); ToolManager.LoadTools(); BuildSubTree(); mainWindow = new KinoveaMainWindow(this, firstInstance); NotificationCenter.RecentFilesChanged += NotificationCenter_RecentFilesChanged; NotificationCenter.FullScreenToggle += NotificationCenter_FullscreenToggle; NotificationCenter.StatusUpdated += (s, e) => statusLabel.Text = e.Status; NotificationCenter.PreferenceTabAsked += NotificationCenter_PreferenceTabAsked; log.Debug("Plug sub modules at UI extension points (Menus, ToolBars, StatusBAr, Windows)."); ExtendMenu(mainWindow.menuStrip); ExtendToolBar(mainWindow.toolStrip); ExtendStatusBar(mainWindow.statusStrip); ExtendUI(); log.Debug("Register global services offered at Root level."); Services.FormsHelper.SetMainForm(mainWindow); }
private void LaunchSelectedVideo(ListView lv) { string path = GetSelectedVideoPath(lv); if (path != null) { VideoTypeManager.LoadVideo(path, -1); } }
private void LaunchWatcherSelectedVideo(ListView lv) { string path = GetSelectedVideoPath(lv); if (path != null) { path = Path.Combine(Path.GetDirectoryName(path), "*"); VideoTypeManager.LoadVideo(path, -1); } }
private void bgWorker_DoWork(object sender, DoWorkEventArgs e) { // Note: having one background worker per file and running them all in parallel was tested // but it does more harm than good. BackgroundWorker bgWorker = sender as BackgroundWorker; List <string> filenames = e.Argument as List <string>; if (filenames.Count < 1 || bgWorker == null) { e.Result = null; return; } for (int i = 0; i < filenames.Count; i++) { if (bgWorker.CancellationPending) { break; } string filename = filenames[i]; VideoSummary summary = null; try { if (string.IsNullOrEmpty(filename)) { continue; } string extension = Path.GetExtension(filename); VideoReader reader = VideoTypeManager.GetVideoReader(extension); int numberOfThumbnails = 5; if (reader != null) { summary = reader.ExtractSummary(filename, numberOfThumbnails, maxImageSize); } } catch (Exception exp) { log.ErrorFormat("Error while extracting video summary for {0}.", filename); log.Error(exp); } if (summary == null) { summary = new VideoSummary(filename); } bgWorker.ReportProgress(i, summary); } }
private void View_LaunchAsked(object sender, EventArgs e) { CapturedFileView view = sender as CapturedFileView; if (view == null || view.CapturedFile == null || string.IsNullOrEmpty(view.CapturedFile.Filepath)) { return; } VideoTypeManager.LoadVideo(view.CapturedFile.Filepath, -1); }
private void mnuOpenAsReplayWatcher_Click(object sender, EventArgs e) { CShItem item = activeTab == ActiveFileBrowserTab.Explorer ? currentExptreeItem : currentShortcutItem; if (item == null || item.Path.StartsWith("::")) { return; } string path = Path.Combine(item.Path, "*"); VideoTypeManager.LoadVideo(path, -1); }
private void View_LaunchWatcherAsked(object sender, EventArgs e) { CapturedFileView view = sender as CapturedFileView; if (view == null || view.CapturedFile == null || string.IsNullOrEmpty(view.CapturedFile.Filepath)) { return; } // Replace the filename with a wildcard to turn into a replay watcher over that folder. string path = Path.Combine(Path.GetDirectoryName(view.CapturedFile.Filepath), "*"); VideoTypeManager.LoadVideo(path, -1); }
public OpenVideoResult Load(string filePath) { // Instanciate appropriate video reader class depending on extension. string extension = Path.GetExtension(filePath); videoReader = VideoTypeManager.GetVideoReader(extension); if (videoReader != null) { videoReader.Options = new VideoOptions(PreferencesManager.PlayerPreferences.AspectRatio, PreferencesManager.PlayerPreferences.DeinterlaceByDefault); return(videoReader.Open(filePath)); } else { return(OpenVideoResult.NotSupported); } }
private void LaunchItemAt(ListView listView, MouseEventArgs e) { ListViewItem lvi = listView.GetItemAt(e.X, e.Y); if (lvi == null || listView.SelectedItems == null || listView.SelectedItems.Count != 1) { return; } string path = lvi.Tag as string; if (path == null) { return; } VideoTypeManager.LoadVideo(path, -1); }
private void NotificationCenter_LaunchOpenDialog(object sender, EventArgs e) { if (isOpening || rootKernel.ScreenManager.ScreenCount != 0) { return; } isOpening = true; string filename = FilePicker.OpenVideo(); if (!string.IsNullOrEmpty(filename)) { VideoTypeManager.LoadVideo(filename, -1); } isOpening = false; }
private void NotificationCenter_LaunchOpenDialog(object sender, EventArgs e) { if (isOpening || rootKernel.ScreenManager.ScreenCount != 0) { return; } isOpening = true; string filepath = rootKernel.LaunchOpenFileDialog(); if (filepath.Length > 0) { VideoTypeManager.LoadVideo(filepath, -1); } isOpening = false; }
private void watcher_Changed(object sender, FileSystemEventArgs e) { if (!VideoTypeManager.IsSupported(Path.GetExtension(e.FullPath))) { return; } log.DebugFormat("Replay watcher received an event: {0}, filename: \"{1}\".", e.ChangeType, e.Name); if (e.FullPath == currentFile) { // Special case where the user is overwriting the currently loaded file. // In this case we can't use the normal heuristic of trying to get exclusive access on the file, // because the player screen itself already has the file opened. // First of all we need to stop the player from playing the file as it's reading frames from disk (no caching). dummy.BeginInvoke((Action) delegate { player.StopPlaying(); }); // We normally receive only two events. One at start and one on close. overwriteEventCount++; if (overwriteEventCount >= 2) { log.DebugFormat("Loading overwritten video."); overwriteEventCount = 0; dummy.BeginInvoke((Action) delegate { LoadVideo(e.FullPath); }); } else { log.DebugFormat("The file was just created, it is not ready to be loaded yet."); } } else { if (FilesystemHelper.CanRead(e.FullPath)) { log.DebugFormat("Loading new video."); dummy.BeginInvoke((Action) delegate { LoadVideo(e.FullPath); }); } else { log.DebugFormat("The file is still being written."); } } }
public RootKernel() { log.Debug("Loading video readers."); List <Type> videoReaders = new List <Type>(); videoReaders.Add(typeof(Video.Bitmap.VideoReaderBitmap)); videoReaders.Add(typeof(Video.FFMpeg.VideoReaderFFMpeg)); videoReaders.Add(typeof(Video.GIF.VideoReaderGIF)); videoReaders.Add(typeof(Video.SVG.VideoReaderSVG)); videoReaders.Add(typeof(Video.Synthetic.VideoReaderSynthetic)); VideoTypeManager.LoadVideoReaders(videoReaders); log.Debug("Loading camera managers."); List <Type> cameraManagers = new List <Type>(); cameraManagers.Add(typeof(Camera.Basler.CameraManagerBasler)); cameraManagers.Add(typeof(Camera.Daheng.CameraManagerDaheng)); cameraManagers.Add(typeof(Camera.DirectShow.CameraManagerDirectShow)); cameraManagers.Add(typeof(Camera.FrameGenerator.CameraManagerFrameGenerator)); cameraManagers.Add(typeof(Camera.HTTP.CameraManagerHTTP)); cameraManagers.Add(typeof(Camera.IDS.CameraManagerIDS)); CameraTypeManager.LoadCameraManagers(cameraManagers); log.Debug("Loading tools."); ToolManager.LoadTools(); BuildSubTree(); mainWindow = new KinoveaMainWindow(this); NotificationCenter.RecentFilesChanged += NotificationCenter_RecentFilesChanged; NotificationCenter.FullScreenToggle += NotificationCenter_FullscreenToggle; NotificationCenter.StatusUpdated += (s, e) => statusLabel.Text = e.Status; NotificationCenter.PreferenceTabAsked += NotificationCenter_PreferenceTabAsked; log.Debug("Plug sub modules at UI extension points (Menus, Toolbars, Statusbar, Windows)."); ExtendMenu(mainWindow.menuStrip); ExtendToolBar(mainWindow.toolStrip); ExtendStatusBar(mainWindow.statusStrip); ExtendUI(); log.Debug("Register global services offered at Root level."); Services.FormsHelper.SetMainForm(mainWindow); }
private void tvCaptureHistory_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { // Launch video at node. CaptureHistoryEntry entry = e.Node.Tag as CaptureHistoryEntry; if (entry == null) { return; } string path = entry.CaptureFile; if (path == null) { return; } VideoTypeManager.LoadVideo(path, -1); }
private void LaunchSelectedCamera(ListView lv, TreeView tv) { if (lv == null || tv == null) { return; } if (lv.Focused) { if (lv.SelectedItems == null || lv.SelectedItems.Count != 1) { return; } int index = IndexOfCamera(cameraSummaries, lv.SelectedItems[0].Name); if (index >= 0) { CameraTypeManager.LoadCamera(cameraSummaries[index], -1); } } else if (tv.Focused) { if (tv.SelectedNode == null) { return; } CaptureHistoryEntry entry = tv.SelectedNode.Tag as CaptureHistoryEntry; if (entry == null) { return; } string path = entry.CaptureFile; if (path == null) { return; } VideoTypeManager.LoadVideo(path, -1); } }
/// <summary> /// Look for the most recent supported video file in the folder. /// </summary> public static string GetMostRecentFile(string path) { var directory = new DirectoryInfo(path); if (directory == null) { return(null); } FileInfo latest = directory.GetFiles() .Where(f => VideoTypeManager.IsSupported(f.Extension)) .OrderByDescending(f => f.LastWriteTime) .FirstOrDefault(); if (latest == null) { return(null); } return(latest.FullName); }
public OpenVideoResult Load(string filePath) { // Instanciate appropriate video reader class. string sequenceFilename = FilesystemHelper.GetSequenceFilename(filePath); if (!string.IsNullOrEmpty(sequenceFilename)) { videoReader = VideoTypeManager.GetImageSequenceReader(); filePath = Path.Combine(Path.GetDirectoryName(filePath), sequenceFilename); } else { if (FilesystemHelper.IsReplayWatcher(filePath)) { // This happens when we first load a file watcher into this screen. // Subsequent calls by the watcher will use the actual file name. // For this initial step, run the most recent file of the directory, if any. filePath = FilesystemHelper.GetMostRecentFile(Path.GetDirectoryName(filePath)); if (string.IsNullOrEmpty(filePath)) { // If the directory doesn't have any supported files yet it's not an error, we just load an empty player and get ready. return(OpenVideoResult.EmptyWatcher); } } videoReader = VideoTypeManager.GetVideoReader(Path.GetExtension(filePath)); } if (videoReader != null) { videoReader.Options = new VideoOptions(PreferencesManager.PlayerPreferences.AspectRatio, ImageRotation.Rotate0, Demosaicing.None, PreferencesManager.PlayerPreferences.DeinterlaceByDefault); return(videoReader.Open(filePath)); } else { return(OpenVideoResult.NotSupported); } }
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(); 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 = VideoTypeManager.GetMostRecentSupportedVideo(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 void UpdateFileList(CShItem folder, ListView listView, bool refreshThumbnails, bool shortcuts) { // Update a file list with the given folder. // Triggers an update of the thumbnails pane if requested. if (folder == null) { return; } this.Cursor = Cursors.WaitCursor; listView.BeginUpdate(); listView.View = View.Details; listView.Items.Clear(); listView.Columns.Clear(); listView.Columns.Add("", listView.Width); listView.GridLines = true; listView.HeaderStyle = ColumnHeaderStyle.None; // Each list element will store the CShItem it's referring to in its Tag property. ArrayList fileList = folder.GetFiles(); List <string> filenames = new List <string>(); foreach (object item in fileList) { CShItem shellItem = item as CShItem; if (shellItem == null) { continue; } try { string path = shellItem.Path; string extension = Path.GetExtension(path); if (string.IsNullOrEmpty(extension) || !VideoTypeManager.IsSupported(extension)) { continue; } filenames.Add(path); } catch (Exception) { // Known case : when we are in OS/X parallels context, the path of existing files are invalid. log.ErrorFormat("An error happened while trying to add a file to the file list : {0}", shellItem.Path); } } filenames.Sort(new AlphanumComparator()); foreach (string filename in filenames) { ListViewItem lvi = new ListViewItem(Path.GetFileName(filename)); lvi.Tag = filename; lvi.ImageIndex = 0; listView.Items.Add(lvi); } listView.EndUpdate(); UpdateFileWatcher(folder); // Even if we don't want to reload the thumbnails, we must ensure that // the screen manager backup list is in sync with the actual file list. // desync can happen in case of renaming and deleting files. // the screenmanager backup list is used at BringBackThumbnail, // (i.e. when we close a screen) NotificationCenter.RaiseCurrentDirectoryChanged(this, shortcuts, filenames, refreshThumbnails); this.Cursor = Cursors.Default; }