From 81c1326b16a108f9cad9d6fe8b520ca1899e5d90 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 4 Sep 2019 12:42:39 -0400 Subject: [PATCH 1/2] 5372 allow videos to preserve ordering --- .../autopsy/filequery/FileSearch.java | 33 ++++++++++++------- .../autopsy/filequery/ResultsPanel.java | 15 +++++---- .../filequery/VideoThumbnailsWrapper.java | 9 +++-- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java b/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java index b03920ee8d..7881ae5374 100644 --- a/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java +++ b/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java @@ -336,16 +336,18 @@ class FileSearch { } /** - * Get the video thumbnails for a specified AbstractFile. + * Get the video thumbnails for a file which exists in a + * VideoThumbnailsWrapper and update the VideoThumbnailsWrapper to include + * them. * - * @param file Video file to generate thumbnails for. + * @param thumbnailWrapper the object which contains the file to generate + * thumbnails for. * - * @return An object containing the list of video thumbnails, an array of - * their timestamps, and the AbstractFile they were generated for. */ @NbBundle.Messages({"# {0} - file name", "FileSearch.genVideoThumb.progress.text=extracting temporary file {0}"}) - static VideoThumbnailsWrapper getVideoThumbnails(AbstractFile file) { + static void getVideoThumbnails(VideoThumbnailsWrapper thumbnailWrapper) { + AbstractFile file = thumbnailWrapper.getAbstractFile(); //Currently this method always creates the thumbnails java.io.File tempFile; try { @@ -357,7 +359,8 @@ class FileSearch { 0, 0, 0}; - return new VideoThumbnailsWrapper(createDefaultThumbnailList(), framePositions, file); + thumbnailWrapper.setThumbnails(createDefaultThumbnailList(), framePositions); + return; } if (tempFile.exists() == false || tempFile.length() < file.getSize()) { ProgressHandle progress = ProgressHandle.createHandle(Bundle.FileSearch_genVideoThumb_progress_text(file.getName())); @@ -370,7 +373,8 @@ class FileSearch { 0, 0, 0}; - return new VideoThumbnailsWrapper(createDefaultThumbnailList(), framePositions, file); + thumbnailWrapper.setThumbnails(createDefaultThumbnailList(), framePositions); + return; } ContentUtils.writeToFile(file, tempFile, progress, null, true); } catch (IOException ex) { @@ -390,7 +394,8 @@ class FileSearch { 0, 0, 0}; - return new VideoThumbnailsWrapper(createDefaultThumbnailList(), framePositions, file); + thumbnailWrapper.setThumbnails(createDefaultThumbnailList(), framePositions); + return; } double fps = videoFile.get(5); // gets frame per second double totalFrames = videoFile.get(7); // gets total frames @@ -401,7 +406,8 @@ class FileSearch { 0, 0, 0}; - return new VideoThumbnailsWrapper(createDefaultThumbnailList(), framePositions, file); + thumbnailWrapper.setThumbnails(createDefaultThumbnailList(), framePositions); + return; } if (Thread.interrupted()) { int[] framePositions = new int[]{ @@ -409,7 +415,8 @@ class FileSearch { 0, 0, 0}; - return new VideoThumbnailsWrapper(createDefaultThumbnailList(), framePositions, file); + thumbnailWrapper.setThumbnails(createDefaultThumbnailList(), framePositions); + return; } double duration = 1000 * (totalFrames / fps); //total milliseconds @@ -464,11 +471,13 @@ class FileSearch { bufferedImage.getRaster().setDataElements(0, 0, matrixColumns, matrixRows, data); if (Thread.interrupted()) { - return new VideoThumbnailsWrapper(videoThumbnails, framePositions, file); + + thumbnailWrapper.setThumbnails(videoThumbnails, framePositions); + return; } videoThumbnails.add(ScalrWrapper.resizeFast(bufferedImage, ImageUtils.ICON_SIZE_LARGE)); } - return new VideoThumbnailsWrapper(videoThumbnails, framePositions, file); + thumbnailWrapper.setThumbnails(videoThumbnails, framePositions); } finally { videoFile.release(); // close the file} } diff --git a/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java b/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java index cb815fe4d2..b33d00a147 100644 --- a/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java @@ -19,6 +19,7 @@ package org.sleuthkit.autopsy.filequery; import com.google.common.eventbus.Subscribe; +import java.awt.Image; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -59,7 +60,7 @@ public class ResultsPanel extends javax.swing.JPanel { private final EamDb centralRepo; private int groupSize = 0; private PageWorker pageWorker; - private final List thumbnailWorkers = new ArrayList<>(); + private final List> thumbnailWorkers = new ArrayList<>(); /** * Creates new form ResultsPanel. @@ -123,7 +124,7 @@ public class ResultsPanel extends javax.swing.JPanel { void populateVideoViewer(List files) { //cancel any unfished thumb workers - for (SwingWorker thumbWorker : thumbnailWorkers) { + for (SwingWorker thumbWorker : thumbnailWorkers) { if (!thumbWorker.isDone()) { thumbWorker.cancel(true); } @@ -429,23 +430,23 @@ public class ResultsPanel extends javax.swing.JPanel { private class VideoThumbnailWorker extends SwingWorker { private final ResultFile file; - private VideoThumbnailsWrapper thumbnailWrapper; + private final VideoThumbnailsWrapper thumbnailWrapper; VideoThumbnailWorker(ResultFile file) { this.file = file; + thumbnailWrapper = new VideoThumbnailsWrapper(new ArrayList(), new int[4], file.getAbstractFile()); + videoThumbnailViewer.addRow(thumbnailWrapper); } @Override protected Void doInBackground() throws Exception { - thumbnailWrapper = FileSearch.getVideoThumbnails(file.getAbstractFile()); + FileSearch.getVideoThumbnails(thumbnailWrapper); + videoThumbnailViewer.repaint(); return null; } @Override protected void done() { - if (!isCancelled()) { - videoThumbnailViewer.addRow(thumbnailWrapper); - } } } diff --git a/Core/src/org/sleuthkit/autopsy/filequery/VideoThumbnailsWrapper.java b/Core/src/org/sleuthkit/autopsy/filequery/VideoThumbnailsWrapper.java index 2d8747b492..77b728b872 100644 --- a/Core/src/org/sleuthkit/autopsy/filequery/VideoThumbnailsWrapper.java +++ b/Core/src/org/sleuthkit/autopsy/filequery/VideoThumbnailsWrapper.java @@ -30,9 +30,9 @@ import org.sleuthkit.datamodel.TskCoreException; */ public class VideoThumbnailsWrapper { - private final List thumbnails; + private List thumbnails; private final AbstractFile abstractFile; - private final int[] timeStamps; + private int[] timeStamps; /** * Construct a new VideoThumbnailsWrapper. @@ -94,4 +94,9 @@ public class VideoThumbnailsWrapper { return Collections.unmodifiableList(thumbnails); } + void setThumbnails(List videoThumbnails, int[] framePositions) { + this.thumbnails = videoThumbnails; + this.timeStamps = framePositions; + } + } From 69420a0c0902cf0afe7dfa7f11a848a6c3b6e9a4 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 4 Sep 2019 13:03:41 -0400 Subject: [PATCH 2/2] 5372 remove unused code --- Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java b/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java index b33d00a147..e0ffb6defd 100644 --- a/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java @@ -429,11 +429,9 @@ public class ResultsPanel extends javax.swing.JPanel { private class VideoThumbnailWorker extends SwingWorker { - private final ResultFile file; private final VideoThumbnailsWrapper thumbnailWrapper; VideoThumbnailWorker(ResultFile file) { - this.file = file; thumbnailWrapper = new VideoThumbnailsWrapper(new ArrayList(), new int[4], file.getAbstractFile()); videoThumbnailViewer.addRow(thumbnailWrapper); } @@ -445,9 +443,6 @@ public class ResultsPanel extends javax.swing.JPanel { return null; } - @Override - protected void done() { - } } }