minor gstreamer tweaks

This commit is contained in:
adam-m 2012-09-11 13:25:42 -04:00
parent 373b256058
commit 8f80324fa3

View File

@ -58,7 +58,7 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
private File currentFile; private File currentFile;
private long durationMillis = 0; private long durationMillis = 0;
private boolean autoTracking = false; // true if the slider is moving automatically private boolean autoTracking = false; // true if the slider is moving automatically
private final Object playbinLock = new Object(); // lock for synchronization private final Object playbinLock = new Object(); // lock for synchronization of playbin2 player
/** /**
* Creates new form DataContentViewerVideo * Creates new form DataContentViewerVideo
@ -71,11 +71,10 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
private void customizeComponents() { private void customizeComponents() {
Gst.init(); Gst.init();
progressSlider.addChangeListener(new ChangeListener() { progressSlider.addChangeListener(new ChangeListener() {
/** /**
* Should always try to synchronize any call to * Should always try to synchronize any call to
* progressSlider.setValue() to avoid a different thread * progressSlider.setValue() to avoid a different thread changing
* changing playbin while stateChanged() is processing * playbin while stateChanged() is processing
*/ */
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
@ -89,7 +88,6 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
} }
} }
} }
}); });
} }
@ -159,21 +157,21 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseButtonActionPerformed private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseButtonActionPerformed
synchronized (playbinLock) { synchronized (playbinLock) {
if(playbin2.getState().equals(State.PLAYING)){ State state = playbin2.getState();
if (state.equals(State.PLAYING)) {
playbin2.pause(); playbin2.pause();
pauseButton.setText(""); pauseButton.setText("");
playbin2.setState(State.PAUSED); playbin2.setState(State.PAUSED);
} else if(playbin2.getState().equals(State.PAUSED)) { } else if (state.equals(State.PAUSED)) {
playbin2.play(); playbin2.play();
pauseButton.setText("||"); pauseButton.setText("||");
playbin2.setState(State.PLAYING); playbin2.setState(State.PLAYING);
} else if(playbin2.getState().equals(State.READY)) { } else if (state.equals(State.READY)) {
ExtractMedia em = new ExtractMedia(currentFile, getJFile(currentFile)); ExtractMedia em = new ExtractMedia(currentFile, getJFile(currentFile));
em.execute(); em.execute();
} }
} }
}//GEN-LAST:event_pauseButtonActionPerformed }//GEN-LAST:event_pauseButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton pauseButton; private javax.swing.JButton pauseButton;
private javax.swing.JLabel progressLabel; private javax.swing.JLabel progressLabel;
@ -185,10 +183,14 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
public void setNode(Node selectedNode) { public void setNode(Node selectedNode) {
reset(); reset();
setComponentsVisibility(false); setComponentsVisibility(false);
if(selectedNode == null) { return; } if (selectedNode == null) {
return;
}
File file = selectedNode.getLookup().lookup(File.class); File file = selectedNode.getLookup().lookup(File.class);
if(file == null) { return; } if (file == null) {
return;
}
currentFile = file; currentFile = file;
if (containsExt(file.getName(), IMAGES)) { if (containsExt(file.getName(), IMAGES)) {
@ -200,6 +202,7 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
/** /**
* Initialize vars and display the image on the panel. * Initialize vars and display the image on the panel.
*
* @param file * @param file
*/ */
private void showImage(File file) { private void showImage(File file) {
@ -233,6 +236,7 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
/** /**
* Initialize all the necessary vars to play a video/audio file. * Initialize all the necessary vars to play a video/audio file.
*
* @param file the File to play * @param file the File to play
*/ */
private void setupVideo(File file) { private void setupVideo(File file) {
@ -391,7 +395,9 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
ExtractMedia(org.sleuthkit.datamodel.File sFile, java.io.File jFile) { ExtractMedia(org.sleuthkit.datamodel.File sFile, java.io.File jFile) {
this.sFile = sFile; this.sFile = sFile;
this.jFile = jFile; this.jFile = jFile;
}; }
;
@Override @Override
protected Object doInBackground() throws Exception { protected Object doInBackground() throws Exception {
@ -438,13 +444,16 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
progressLabel.setText("Error buffering file"); progressLabel.setText("Error buffering file");
return; return;
} }
ClockTime dur = null;
synchronized (playbinLock) { synchronized (playbinLock) {
playbin2.play(); // must play, then pause and get state to get duration. playbin2.play(); // must play, then pause and get state to get duration.
playbin2.pause(); playbin2.pause();
playbin2.getState(); playbin2.getState();
duration = playbin2.queryDuration().toString(); dur = playbin2.queryDuration();
durationMillis = playbin2.queryDuration().toMillis();
} }
duration = dur.toString();
durationMillis = dur.toMillis();
progressSlider.setMaximum((int) durationMillis); progressSlider.setMaximum((int) durationMillis);
progressSlider.setMinimum(0); progressSlider.setMinimum(0);
final String finalDuration; final String finalDuration;
@ -460,17 +469,24 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
} }
pauseButton.setText("||"); pauseButton.setText("||");
new Thread(new Runnable() { new Thread(new Runnable() {
private boolean isPlayBinReady() {
synchronized (playbinLock) {
return playbin2 != null && playbin2.getState().equals(State.NULL);
}
}
@Override @Override
public void run() { public void run() {
long positionMillis = 0; long positionMillis = 0;
while (positionMillis < durationMillis while (positionMillis < durationMillis
&& playbin2 != null && isPlayBinReady() ) {
&& !playbin2.getState().equals(State.NULL)) { ClockTime pos = null;
synchronized (playbinLock) { synchronized (playbinLock) {
position = playbin2.queryPosition().toString(); pos = playbin2.queryPosition();
positionMillis = playbin2.queryPosition().toMillis();
} }
position = pos.toString();
positionMillis = pos.toMillis();
if (position.length() == 8) { if (position.length() == 8) {
position = position.substring(3); position = position.substring(3);
} }
@ -480,7 +496,8 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
autoTracking = false; autoTracking = false;
try { try {
Thread.sleep(20); Thread.sleep(20);
} catch (InterruptedException ex) { } } catch (InterruptedException ex) {
}
} }
if (finalDuration.length() == 5) { if (finalDuration.length() == 5) {
progressLabel.setText("00:00/" + finalDuration); progressLabel.setText("00:00/" + finalDuration);