Revert Gst initialization on Windows since it didn't have any impact on crashes.

This commit is contained in:
esaunders 2020-03-11 12:08:56 -04:00
parent 219bb5b2e0
commit 92a3667a14

View File

@ -74,7 +74,6 @@ import org.freedesktop.gstreamer.Format;
import org.freedesktop.gstreamer.GstException; import org.freedesktop.gstreamer.GstException;
import org.freedesktop.gstreamer.event.SeekFlags; import org.freedesktop.gstreamer.event.SeekFlags;
import org.freedesktop.gstreamer.event.SeekType; import org.freedesktop.gstreamer.event.SeekType;
import org.sleuthkit.autopsy.coreutils.PlatformUtil;
/** /**
* This is a video player that is part of the Media View layered pane. It uses * This is a video player that is part of the Media View layered pane. It uses
@ -222,14 +221,6 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
//True for fairness. In other words, //True for fairness. In other words,
//acquire() calls are processed in order of invocation. //acquire() calls are processed in order of invocation.
sliderLock = new Semaphore(1, true); sliderLock = new Semaphore(1, true);
/**
* See JIRA-5888 for details. Initializing gstreamer here is more stable
* on Windows.
*/
if (PlatformUtil.isWindowsOS()) {
Gst.init();
}
} }
private void customizeComponents() { private void customizeComponents() {
@ -273,11 +264,12 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
@Override @Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
if(previousState.equals(State.PLAYING)) { if (previousState.equals(State.PLAYING)) {
gstPlayBin.play(); gstPlayBin.play();
} }
previousState = State.NULL; previousState = State.NULL;
} }
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
} }
@ -389,6 +381,7 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
gstPlayBin.getBus().disconnect(endOfStreamListener); gstPlayBin.getBus().disconnect(endOfStreamListener);
gstPlayBin.getBus().disconnect(stateChangeListener); gstPlayBin.getBus().disconnect(stateChangeListener);
gstPlayBin.getBus().disconnect(errorListener); gstPlayBin.getBus().disconnect(errorListener);
gstPlayBin.getBus().dispose();
gstPlayBin.dispose(); gstPlayBin.dispose();
fxAppSink.clear(); fxAppSink.clear();
gstPlayBin = null; gstPlayBin = null;
@ -548,10 +541,8 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
// Initialize Gstreamer. It is safe to call this for every file. // Initialize Gstreamer. It is safe to call this for every file.
// It was moved here from the constructor because having it happen // It was moved here from the constructor because having it happen
// earlier resulted in conflicts on Linux. See JIRA-5888. // earlier resulted in crashes on Linux. See JIRA-5888.
if (!PlatformUtil.isWindowsOS()) {
Gst.init(); Gst.init();
}
//Video is ready for playback. Create new components //Video is ready for playback. Create new components
gstPlayBin = new PlayBin("VideoPlayer", tempFile.toURI()); gstPlayBin = new PlayBin("VideoPlayer", tempFile.toURI());
@ -599,13 +590,15 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (!progressSlider.getValueIsAdjusting()) { if (!progressSlider.getValueIsAdjusting()) {
try {
sliderLock.acquireUninterruptibly(); sliderLock.acquireUninterruptibly();
long position = gstPlayBin.queryPosition(TimeUnit.NANOSECONDS); long position = gstPlayBin.queryPosition(TimeUnit.NANOSECONDS);
long duration = gstPlayBin.queryDuration(TimeUnit.NANOSECONDS); long duration = gstPlayBin.queryDuration(TimeUnit.NANOSECONDS);
/** /**
* Duration may not be known until there is video data in the * Duration may not be known until there is video data in
* pipeline. We start this updater when data-flow has just been * the pipeline. We start this updater when data-flow has
* initiated so buffering may still be in progress. * just been initiated so buffering may still be in
* progress.
*/ */
if (duration >= 0 && position >= 0) { if (duration >= 0 && position >= 0) {
double relativePosition = (double) position / duration; double relativePosition = (double) position / duration;
@ -615,10 +608,12 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
updateTimeLabel(position, duration); updateTimeLabel(position, duration);
}); });
} finally {
sliderLock.release(); sliderLock.release();
} }
} }
} }
}
/** /**
* Custom view for the JSlider. * Custom view for the JSlider.
@ -655,8 +650,8 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
} }
/** /**
* Modifies the View to be an oval rather than the underlying * Modifies the View to be an oval rather than the underlying rectangle
* rectangle Controller. * Controller.
*/ */
@Override @Override
public void paintThumb(Graphics graphic) { public void paintThumb(Graphics graphic) {
@ -705,11 +700,12 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
@Override @Override
protected TrackListener createTrackListener(JSlider slider) { protected TrackListener createTrackListener(JSlider slider) {
/** /**
* This track listener will force the thumb to be snapped to the mouse * This track listener will force the thumb to be snapped to the
* location. This makes grabbing and dragging the JSlider much easier. * mouse location. This makes grabbing and dragging the JSlider much
* Using the default track listener, the user would have to click * easier. Using the default track listener, the user would have to
* exactly on the slider thumb to drag it. Now the thumb positions * click exactly on the slider thumb to drag it. Now the thumb
* itself under the mouse so that it can always be dragged. * positions itself under the mouse so that it can always be
* dragged.
*/ */
return new TrackListener() { return new TrackListener() {
@Override @Override
@ -1007,14 +1003,14 @@ public class MediaPlayerPanel extends JPanel implements MediaFileViewer.MediaVie
//Don't allow skipping within 2 seconds of video ending. Skipping right to //Don't allow skipping within 2 seconds of video ending. Skipping right to
//the end causes undefined behavior for some gstreamer plugins. //the end causes undefined behavior for some gstreamer plugins.
long twoSecondsInNano = TimeUnit.NANOSECONDS.convert(2, TimeUnit.SECONDS); long twoSecondsInNano = TimeUnit.NANOSECONDS.convert(2, TimeUnit.SECONDS);
if((duration - currentTime) <= twoSecondsInNano) { if ((duration - currentTime) <= twoSecondsInNano) {
return; return;
} }
long newTime; long newTime;
if (currentTime + fastForwardDelta >= duration) { if (currentTime + fastForwardDelta >= duration) {
//If there are less than 30 seconds left, only fast forward to the midpoint. //If there are less than 30 seconds left, only fast forward to the midpoint.
newTime = currentTime + (duration - currentTime)/2; newTime = currentTime + (duration - currentTime) / 2;
} else { } else {
newTime = currentTime + fastForwardDelta; newTime = currentTime + fastForwardDelta;
} }