Changeset 21656 in osm for applications/editors/josm/plugins/videomapping
- Timestamp:
- 2010-06-11T19:43:03+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/videomapping
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/GpsPlayer.java
r21631 r21656 2 2 3 3 import java.awt.Point; 4 import java.io.File; 4 5 import java.sql.Time; 5 6 import java.text.SimpleDateFormat; … … 21 22 private Timer t; 22 23 private TimerTask ani; //for moving trough the list 24 private boolean autoCenter; 23 25 24 26 … … 314 316 public void run() { 315 317 next(); 318 if(autoCenter) Main.map.mapView.zoomTo(getCurr().getEastNorth()); 316 319 Main.map.mapView.repaint(); 317 320 } … … 328 331 } 329 332 } 333 334 public long getLength() { 335 return ls.size()*1000; //FIXME this is a poor hack 336 } 337 338 public void setAutoCenter(boolean b) 339 { 340 this.autoCenter=b; 341 } 342 343 344 330 345 331 346 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PositionLayer.java
r21631 r21656 34 34 35 35 import org.openstreetmap.josm.Main; 36 import org.openstreetmap.josm.actions.InfoAction; 36 37 import org.openstreetmap.josm.data.Bounds; 37 38 import org.openstreetmap.josm.data.gpx.GpxData; … … 48 49 import org.openstreetmap.josm.tools.Shortcut; 49 50 51 import com.sun.jna.StringArray; 52 50 53 //Basic rendering and GPS layer interaction 51 54 public class PositionLayer extends Layer implements MouseListener,MouseMotionListener { … … 81 84 @Override 82 85 public Object getInfoComponent() { 83 return null;86 return tr("{0} covers {1}% of GPS track",gps.getVideo().getName(),gps.getCoverage()*10); 84 87 } 85 88 -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoMappingPlugin.java
r21631 r21656 4 4 import java.awt.event.ActionEvent; 5 5 import java.awt.event.KeyEvent; 6 import java.beans.PropertyChangeListener; 6 7 import java.io.File; 7 8 import java.util.Collections; … … 9 10 import java.util.List; 10 11 12 import javax.swing.Action; 13 import javax.swing.JCheckBoxMenuItem; 14 import javax.swing.JFileChooser; 11 15 import javax.swing.JMenu; 12 16 import javax.swing.JMenuItem; 13 17 import javax.swing.JOptionPane; 18 import javax.swing.JRadioButtonMenuItem; 14 19 15 20 import org.openstreetmap.josm.Main; … … 40 45 //Here we manage properties and start the other classes 41 46 public class VideoMappingPlugin extends Plugin implements LayerChangeListener{ 42 private JMenu VMenu ;47 private JMenu VMenu,VDeinterlacer; 43 48 private GpxData GPSTrack; 44 49 private List<WayPoint> ls; 45 private JosmAction VAdd,VStart,Vbackward,Vforward,Vloop; 50 private JosmAction VAdd,VRemove,VStart,Vbackward,Vforward,Vloop; 51 private JRadioButtonMenuItem VIntBob,VIntNone,VIntLinear; 52 private JCheckBoxMenuItem VCenterIcon; 53 private JMenuItem VJumpLength,VLoopLength; 46 54 private GPSVideoPlayer player; 47 55 private PositionLayer layer; … … 51 59 super(info); 52 60 //Register for GPS menu 53 VMenu = Main.main.menu.addMenu(" Video", KeyEvent.VK_V, Main.main.menu.defaultMenuPos,ht("/Plugin/Videomapping"));//TODO no more ugly " video" hack 61 VMenu = Main.main.menu.addMenu(" Video", KeyEvent.VK_V, Main.main.menu.defaultMenuPos,ht("/Plugin/Videomapping"));//TODO no more ugly " video" hack 54 62 addMenuItems(); 63 loadSettings(); 64 enableControlMenus(false); 55 65 //setup 56 66 MapView.addLayerChangeListener(this); … … 90 100 //register main controls 91 101 private void addMenuItems() { 92 VAdd= new JosmAction("Sync Video","videomapping","Sync a video against this GPS track",null,false) { 93 94 /** 95 * 96 */ 102 VAdd= new JosmAction("Import Video","videomapping","Sync a video against this GPS track",null,false) { 97 103 private static final long serialVersionUID = 1L; 98 104 … … 101 107 enableControlMenus(true); 102 108 layer = new PositionLayer("test",ls); 103 Main.main.addLayer(layer); 109 Main.main.addLayer(layer); 110 /*JFileChooser fc = new JFileChooser("Open Video file"); 111 fc.getSelectedFile();*/ 104 112 player = new GPSVideoPlayer(new File("C:\\temp\\test.mpg"), layer.player); 113 //TODO Check here if we can sync by hand 105 114 layer.setGPSPlayer(player); 115 VAdd.setEnabled(false); 116 VRemove.setEnabled(true); 117 } 118 }; 119 VRemove= new JosmAction("Remove Video","videomapping","Removes current video from Layer",null,false) { 120 private static final long serialVersionUID = 1L; 121 122 public void actionPerformed(ActionEvent arg0) { 123 player.removeVideo(); 106 124 } 107 125 }; 108 126 VStart = new JosmAction("play/pause", "audio-playpause", "starts/pauses video playback", 109 Shortcut.registerShortcut("videomapping:startstop","",KeyEvent.VK_SPACE, Shortcut.GROUP_ MENU), false) {127 Shortcut.registerShortcut("videomapping:startstop","",KeyEvent.VK_SPACE, Shortcut.GROUP_DIRECT), false) { 110 128 111 129 public void actionPerformed(ActionEvent e) { … … 118 136 }; 119 137 Vbackward = new JosmAction("backward", "audio-prev", "jumps n sec back", 120 Shortcut.registerShortcut("videomapping:backward","",KeyEvent.VK_NUMPAD4, Shortcut.GROUP_ MENU), false) {121 122 public void actionPerformed(ActionEvent e) { 123 //layer.backward();138 Shortcut.registerShortcut("videomapping:backward","",KeyEvent.VK_NUMPAD4, Shortcut.GROUP_DIRECT), false) { 139 140 public void actionPerformed(ActionEvent e) { 141 player.backward(); 124 142 125 143 } 126 144 }; 127 145 Vforward= new JosmAction("forward", "audio-next", "jumps n sec forward", 128 Shortcut.registerShortcut("videomapping:forward","",KeyEvent.VK_NUMPAD6, Shortcut.GROUP_ MENU), false) {129 130 public void actionPerformed(ActionEvent e) { 131 //layer.forward();146 Shortcut.registerShortcut("videomapping:forward","",KeyEvent.VK_NUMPAD6, Shortcut.GROUP_DIRECT), false) { 147 148 public void actionPerformed(ActionEvent e) { 149 player.forward(); 132 150 133 151 } 134 152 }; 135 153 Vloop= new JosmAction("loop", "clock", "loops n sec around current position", 136 Shortcut.registerShortcut("videomapping:loop","",KeyEvent.VK_NUMPAD5, Shortcut.GROUP_MENU), false) { 137 138 public void actionPerformed(ActionEvent e) { 139 //layer.loop(); 140 141 } 142 }; 143 VMenu.add(VAdd); 144 enableControlMenus(false); 154 Shortcut.registerShortcut("videomapping:loop","",KeyEvent.VK_NUMPAD5, Shortcut.GROUP_DIRECT), false) { 155 156 public void actionPerformed(ActionEvent e) { 157 player.loop(); 158 159 } 160 }; 161 162 //now the options menu 163 VCenterIcon = new JCheckBoxMenuItem(new JosmAction("Keep centered", null, "Follows the video icon automaticly",null, false) { 164 165 public void actionPerformed(ActionEvent e) { 166 player.setAutoCenter(VCenterIcon.isSelected()); 167 168 } 169 }); 170 171 VJumpLength = new JMenuItem(new JosmAction("Jump length", null, "Set the length of a jump",null, false) { 172 173 public void actionPerformed(ActionEvent e) { 174 Object[] possibilities = {"200", "500", "1000", "2000", "10000"}; 175 String s = (String)JOptionPane.showInputDialog(Main.parent,"Jump in video for x ms","Jump length",JOptionPane.QUESTION_MESSAGE,null,possibilities,"1000"); 176 player.setJumpLength(Integer.getInteger(s)); 177 178 } 179 }); 180 181 VLoopLength = new JMenuItem(new JosmAction("Loop length", null, "Set the length around a looppoint",null, false) { 182 183 public void actionPerformed(ActionEvent e) { 184 Object[] possibilities = {"500", "1000", "3000", "5000", "10000"}; 185 String s = (String)JOptionPane.showInputDialog(Main.parent,"Jump in video for x ms","Loop length",JOptionPane.QUESTION_MESSAGE,null,possibilities,"5000"); 186 player.setLoopLength(Integer.getInteger(s)); 187 188 } 189 }); 190 191 VDeinterlacer= new JMenu("Deinterlacer"); 192 VIntNone= new JRadioButtonMenuItem(new JosmAction("none", null, "no deinterlacing",null, false) { 193 194 public void actionPerformed(ActionEvent e) { 195 player.setDeinterlacer(null); 196 } 197 }); 198 VIntBob= new JRadioButtonMenuItem(new JosmAction("bob", null, "deinterlacing using line doubling",null, false) { 199 200 public void actionPerformed(ActionEvent e) { 201 player.setDeinterlacer("bob"); 202 } 203 }); 204 VIntLinear= new JRadioButtonMenuItem(new JosmAction("linear", null, "deinterlacing using linear interpolation",null, false) { 205 206 public void actionPerformed(ActionEvent e) { 207 player.setDeinterlacer("bob"); 208 } 209 }); 210 VDeinterlacer.add(VIntNone); 211 VDeinterlacer.add(VIntBob); 212 VDeinterlacer.add(VIntLinear); 213 214 VMenu.add(VAdd); 145 215 VMenu.add(VStart); 146 216 VMenu.add(Vbackward); 147 217 VMenu.add(Vforward); 148 218 VMenu.add(Vloop); 219 VMenu.addSeparator(); 220 VMenu.add(VCenterIcon); 221 VMenu.add(VJumpLength); 222 VMenu.add(VLoopLength); 223 VMenu.add(VDeinterlacer); 149 224 } 150 225 … … 158 233 Vforward.setEnabled(enabled); 159 234 Vloop.setEnabled(enabled); 235 } 236 237 //load all properties 238 private void loadSettings() { 239 VIntNone.setSelected(true); 160 240 } 161 241 -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/GPSVideoPlayer.java
r21631 r21656 9 9 import javax.swing.JButton; 10 10 11 import org.openstreetmap.josm.command.AddCommand;12 import org.openstreetmap.josm.data.gpx.WayPoint;13 11 import org.openstreetmap.josm.plugins.videomapping.GpsPlayer; 14 12 … … 103 101 104 102 } 103 104 public void setJumpLength(Integer integer) { 105 video.setJumpLength(integer); 106 107 } 108 109 public void setLoopLength(Integer integer) { 110 video.setLoopLength(integer); 111 112 } 113 114 public void loop() { 115 video.loop(); 116 117 } 118 119 public void forward() { 120 video.forward(); 121 122 } 123 124 public void backward() { 125 video.backward(); 126 127 } 128 129 public void removeVideo() { 130 video.removeVideo(); 131 132 } 133 134 public File getVideo() { 135 return file; 136 } 137 138 public float getCoverage() { 139 return gps.getLength()/video.getLength(); 140 } 141 142 public void setDeinterlacer(String string) { 143 video.setDeinterlacer(string); 144 145 } 146 147 public void setAutoCenter(boolean selected) { 148 gps.setAutoCenter(selected); 149 150 } 151 105 152 106 153 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/SimpleVideoPlayer.java
r21631 r21656 5 5 import java.awt.BorderLayout; 6 6 import java.awt.Canvas; 7 import java.awt.Dimension; 7 8 import java.awt.FlowLayout; 8 9 import java.awt.event.ActionEvent; … … 14 15 import java.text.SimpleDateFormat; 15 16 import java.util.Date; 17 import java.util.HashSet; 18 import java.util.Hashtable; 19 import java.util.Set; 16 20 import java.util.Timer; 17 21 import java.util.TimerTask; … … 24 28 import javax.swing.JComponent; 25 29 import javax.swing.JFrame; 30 import javax.swing.JLabel; 26 31 import javax.swing.JPanel; 27 32 import javax.swing.JSlider; … … 31 36 32 37 import org.openstreetmap.josm.Main; 38 import org.openstreetmap.josm.plugins.videomapping.PlayerObserver; 33 39 34 40 import uk.co.caprica.vlcj.binding.LibVlc; … … 56 62 private SimpleDateFormat df; 57 63 private static final Logger LOG = Logger.getLogger(SimpleVideoPlayer.class); 64 private int jumpLength=1000; 65 private int loopLength=6000; 66 private static Set<PlayerObserver> observers = new HashSet<PlayerObserver>(); //we have to implement our own Observer pattern 58 67 59 68 public SimpleVideoPlayer() { … … 78 87 //setup GUI 79 88 setSize(400, 300); 89 setAlwaysOnTop(true); 90 //setIconImage(); 80 91 df = new SimpleDateFormat("hh:mm:ss:S"); 81 92 scr=new Canvas(); 82 timeline = new JSlider(0,100,0); //TODO better setup for ticks 93 timeline = new JSlider(0,100,0); 94 timeline.setMajorTickSpacing(10); 95 timeline.setMajorTickSpacing(5); 96 timeline.setPaintTicks(true); 83 97 play= new JButton("play"); 84 98 back= new JButton("<"); 85 99 forward= new JButton(">"); 86 100 loop= new JToggleButton("loop"); 87 speed = new JSlider( 0,2,1);88 speed.setPaintTicks(true);89 speed.set MajorTickSpacing(5);101 speed = new JSlider(-200,200,0); 102 speed.setMajorTickSpacing(100); 103 speed.setPaintTicks(true); 90 104 speed.setOrientation(Adjustable.VERTICAL); 105 Hashtable labelTable = new Hashtable(); 106 labelTable.put( new Integer( 0 ), new JLabel("1x") ); 107 labelTable.put( new Integer( -200 ), new JLabel("-2x") ); 108 labelTable.put( new Integer( 200 ), new JLabel("2x") ); 109 speed.setLabelTable( labelTable ); 110 speed.setPaintLabels(true); 111 91 112 setLayout(); 92 113 addListeners(); … … 137 158 //add UI functionality 138 159 private void addListeners() { 139 final float JUMP_LENGTH=1000;140 final int LOOP_LENGTH=6000;141 160 timeline.addChangeListener(new ChangeListener() { 142 161 public void stateChanged(ChangeEvent e) { … … 162 181 163 182 public void actionPerformed(ActionEvent arg0) { 164 mp.setTime((long) (mp.getTime()- JUMP_LENGTH));183 mp.setTime((long) (mp.getTime()-jumpLength)); 165 184 //jump(600000); //10,05 166 185 … … 171 190 172 191 public void actionPerformed(ActionEvent arg0) { 173 mp.setTime((long) (mp.getTime()+ JUMP_LENGTH));192 mp.setTime((long) (mp.getTime()+jumpLength)); 174 193 175 194 } … … 185 204 else 186 205 { 187 final long resetpoint=(long) mp.getTime()- LOOP_LENGTH/2;206 final long resetpoint=(long) mp.getTime()-loopLength/2; 188 207 TimerTask ani=new TimerTask() { 189 208 … … 194 213 }; 195 214 t= new Timer(); 196 t.schedule(ani, LOOP_LENGTH/2,LOOP_LENGTH); //first run a half looptime till reset215 t.schedule(ani,loopLength/2,loopLength); //first run a half looptime till reset 197 216 } 198 217 } … … 202 221 203 222 public void stateChanged(ChangeEvent arg0) { 204 // TODO change playback speed 223 if(!speed.getValueIsAdjusting()&&(mp.isPlaying())) 224 { 225 int perc = speed.getValue(); 226 float ratio= (float) (perc/400f*1.75); 227 ratio=ratio+(9/8); 228 mp.setRate(ratio); 229 } 205 230 206 231 } … … 218 243 219 244 public void metaDataAvailable(MediaPlayer arg0, VideoMetaData data) { 220 scr.setSize(data.getVideoDimension()); 245 final float perc = 0.5f; 246 Dimension org=data.getVideoDimension(); 247 scr.setSize(new Dimension((int)(org.width*perc), (int)(org.height*perc))); 221 248 pack(); 222 249 … … 293 320 } 294 321 322 public boolean isPlaying() 323 { 324 return mp.isPlaying(); 325 } 326 295 327 //gets called by the Syncer to update all components 296 328 public void updateTime () … … 298 330 if(mp.isPlaying()) 299 331 { 300 setTitle(df.format(new Date(mp.getTime())) +" "+mp.getTime());332 setTitle(df.format(new Date(mp.getTime()))); //FIXME there is a leading hour even at the beginning 301 333 syncTimeline=true; 302 334 timeline.setValue(Math.round(mp.getPosition()*100)); … … 311 343 pack(); 312 344 } 345 346 public long getLength() { 347 return mp.getLength(); 348 } 349 350 public void setDeinterlacer(String string) { 351 mp.setDeinterlace(string); 352 353 } 354 355 public void setJumpLength(Integer integer) { 356 jumpLength=integer; 357 358 } 359 360 public void setLoopLength(Integer integer) { 361 loopLength = integer; 362 363 } 364 365 public void loop() { 366 loop.notifyAll(); 367 } 368 369 public void forward() { 370 forward.notifyAll(); 371 } 372 373 public void backward() { 374 back.notifyAll(); 375 376 } 377 378 public void removeVideo() { 379 if (mp.isPlaying()) mp.stop(); 380 mp.release(); 381 382 } 383 384 public static void addObserver(PlayerObserver observer) { 385 386 observers.add(observer); 387 388 } 389 390 391 392 public static void removeObserver(PlayerObserver observer) { 393 394 observers.remove(observer); 395 396 } 397 398 private static void notifyObservers() { 399 400 for (PlayerObserver o : observers) { 401 402 o.changeSpeed(0.0f); 403 404 } 405 406 } 407 313 408 314 409 -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/Syncer.java
r21584 r21656 19 19 //here we update 20 20 public void run() { 21 pl.updateTime(); 22 21 if (pl.isPlaying()) pl.updateTime(); //if the video is seeking we get a mess 23 22 } 24 23 }); 24 25 25 } 26 26 } -
applications/editors/josm/plugins/videomapping/test/videotest.java
r21631 r21656 28 28 sVP.setFile(new File("C:\\TEMP\\test.mpg")); 29 29 sVP.play(); //FIXME We have a bug so we get out of sync if we jump before the video is up (and this we CAN'T DETECT!!!) 30 /* 30 31 JButton b = new JButton("jump"); 31 32 b.addActionListener(new ActionListener() { … … 36 37 }); 37 38 sVP.add(b); 38 39 */ 39 40 } 40 41
Note:
See TracChangeset
for help on using the changeset viewer.