Changeset 22690 in osm for applications/editors
- Timestamp:
- 2010-08-19T08:36:56+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/videomapping
- Files:
-
- 1 added
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/GpsPlayer.java
r21779 r22690 36 36 return next; 37 37 } 38 39 public WayPoint getWaypoint(long relTime) 40 { 41 int pos = Math.round(relTime/1000);//TODO ugly quick hack 42 return ls.get(pos); 43 } 38 44 39 45 public GpsPlayer(List<WayPoint> l) { … … 91 97 } 92 98 93 //wal k waypoints forward/backward99 //walk k waypoints forward/backward 94 100 public void jumpRel(int k) 95 101 { … … 99 105 jump(ls.get(ls.indexOf(curr)+k)); 100 106 } 101 Main.map.mapView.repaint(); 107 Main.map.mapView.repaint(); //seperate modell and view logic... 102 108 } 103 109 … … 113 119 Main.map.mapView.repaint(); 114 120 } 121 } 122 123 //go to the position at the timecode e.g.g "14:00:01"; 124 public void jump(Time GPSAbsTime) 125 { 126 jump(getWaypoint(GPSAbsTime.getTime()-start.getTime().getTime())); //TODO replace Time by Date? 127 } 128 129 //go to the position at 130 public void jump(Date GPSDate) 131 { 132 long s,m,h,diff; 133 //calculate which waypoint is at the offset 134 System.out.println(start.getTime()); 135 System.out.println(start.getTime().getHours()+":"+start.getTime().getMinutes()+":"+start.getTime().getSeconds()); 136 s=GPSDate.getSeconds()-start.getTime().getSeconds(); 137 m=GPSDate.getMinutes()-start.getTime().getMinutes(); 138 h=GPSDate.getHours()-start.getTime().getHours(); 139 diff=s*1000+m*60*1000+h*60*60*1000; //TODO ugly hack but nothing else works right 140 jump(getWaypoint(diff)); 115 141 } 116 142 … … 316 342 return p.getTime().getTime()-start.getTime().getTime(); //TODO assumes timeintervall is constant!!!! 317 343 } 318 344 345 319 346 //jumps to a specific time 320 347 public void jump(long relTime) { -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PlayerObserver.java
r21779 r22690 5 5 void playing(long time); 6 6 void jumping(long time); 7 void metadata(long time,boolean subtitles); 7 8 8 9 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PositionLayer.java
r22550 r22690 43 43 private SimpleDateFormat mins; 44 44 private SimpleDateFormat ms; 45 private SimpleDateFormat gpsTimeCode; 45 46 private GPSVideoPlayer gps; 46 47 … … 52 53 mins = new SimpleDateFormat("hh:mm:ss:S"); 53 54 ms= new SimpleDateFormat("mm:ss"); 55 gpsTimeCode= new SimpleDateFormat("hh:mm:ss"); 54 56 Main.map.mapView.addMouseListener(this); 55 57 Main.map.mapView.addMouseMotionListener(this); … … 109 111 //TODO make icon transparent 110 112 //draw all GPS points 111 g.setColor( Color.GREEN);113 g.setColor(new Color(0,255,0,128)); 112 114 for(WayPoint n: ls) { 113 115 p = Main.map.mapView.getPoint(n.getEastNorth()); … … 115 117 } 116 118 //draw synced points 117 g.setColor(Color. ORANGE);119 g.setColor(Color.GREEN); 118 120 for(WayPoint n: ls) { 119 121 if(n.attr.containsKey("synced")) … … 156 158 p=Main.map.mapView.getPoint(iconPosition.getEastNorth()); 157 159 icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2); 158 g.drawString(mins.format(iconPosition.getTime()),p.x-10,p.y-10); 160 //g.drawString(mins.format(iconPosition.getTime()),p.x-10,p.y-10); //TODO when synced we might wan't to use a different layout 161 g.drawString(gpsTimeCode.format(iconPosition.getTime()),p.x-10,p.y-10); 159 162 } 160 163 } … … 164 167 p=Main.map.mapView.getPoint(player.getCurr().getEastNorth()); 165 168 icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2); 166 g.drawString( ms.format(player.getRelativeTime()),p.x-10,p.y-10);169 g.drawString(gpsTimeCode.format(player.getCurr().getTime()),p.x-10,p.y-10); 167 170 } 168 171 } … … 302 305 for (PlayerObserver o : observers) { 303 306 304 o.jumping(newTime); 307 o.jumping(newTime); //TODO has to become just a single procedure? 305 308 306 309 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoMappingPlugin.java
r21779 r22690 6 6 import java.beans.PropertyChangeListener; 7 7 import java.io.File; 8 import java.sql.Time; 9 import java.text.ParseException; 10 import java.text.SimpleDateFormat; 8 11 import java.util.Collections; 12 import java.util.Date; 9 13 import java.util.LinkedList; 10 14 import java.util.List; … … 48 52 private GpxData GPSTrack; 49 53 private List<WayPoint> ls; 50 private JosmAction VAdd,VRemove,VStart,Vbackward,Vforward,V faster,Vslower,Vloop;54 private JosmAction VAdd,VRemove,VStart,Vbackward,Vforward,VJump,Vfaster,Vslower,Vloop; 51 55 private JRadioButtonMenuItem VIntBob,VIntNone,VIntLinear; 52 private JCheckBoxMenuItem VCenterIcon ;56 private JCheckBoxMenuItem VCenterIcon,VSubTitles; 53 57 private JMenuItem VJumpLength,VLoopLength; 54 58 private GPSVideoPlayer player; 55 59 private PositionLayer layer; 56 private final String VM_DEINTERLACER="videomapping.deinterlacer"; 60 private final String VM_DEINTERLACER="videomapping.deinterlacer"; //where we store settings 57 61 private final String VM_MRU="videomapping.mru"; 58 62 private final String VM_AUTOCENTER="videomapping.autocenter"; … … 74 78 enableControlMenus(true); 75 79 loadSettings(); 76 applySettings(); 80 applySettings(); 77 81 //further plugin informations are provided by build.xml properties 78 82 } … … 115 119 116 120 public void actionPerformed(ActionEvent arg0) { 117 JFileChooser fc = new JFileChooser( );121 JFileChooser fc = new JFileChooser("C:\\TEMP\\"); 118 122 //fc.setSelectedFile(new File(mru)); 119 fc.setSelectedFile(new File("C:\\TEMP"));120 123 if(fc.showOpenDialog(Main.main.parent)!=JFileChooser.CANCEL_OPTION) 121 124 { … … 126 129 Main.main.addLayer(layer); 127 130 player = new GPSVideoPlayer(fc.getSelectedFile(), layer.player); 128 //TODO Check here if we can sync by hand131 //TODO Check here if we can sync allready now 129 132 layer.setGPSPlayer(player); 130 133 layer.addObserver(player); 131 134 VAdd.setEnabled(false); 132 135 VRemove.setEnabled(true); 136 player.setSubtitleAction(VSubTitles); 133 137 } 134 138 } … … 142 146 } 143 147 }; 148 144 149 VStart = new JosmAction(tr("play/pause"), "audio-playpause", tr("starts/pauses video playback"), 145 150 Shortcut.registerShortcut("videomapping:startstop","",KeyEvent.VK_SPACE, Shortcut.GROUP_DIRECT), false) { … … 152 157 Shortcut.registerShortcut("videomapping:backward","",KeyEvent.VK_NUMPAD4, Shortcut.GROUP_DIRECT), false) { 153 158 159 /** 160 * 161 */ 162 private static final long serialVersionUID = -1060444361541900464L; 163 154 164 public void actionPerformed(ActionEvent e) { 155 165 player.backward(); 166 167 } 168 }; 169 Vbackward = new JosmAction(tr("jump"), null, tr("jumps to the entered gps time"),null, false) { 170 public void actionPerformed(ActionEvent e) { 171 String s =JOptionPane.showInputDialog(tr("please enter GPS timecode"),"10:07:57"); 172 SimpleDateFormat format= new SimpleDateFormat("hh:mm:ss"); 173 Date t; 174 try { 175 t = format.parse(s); 176 if (t!=null) 177 { 178 player.jumpToGPSTime(t.getTime()); 179 } 180 } catch (ParseException e1) { 181 // TODO Auto-generated catch block 182 e1.printStackTrace(); 183 } 156 184 157 185 } … … 197 225 applySettings(); 198 226 saveSettings(); 227 228 } 229 }); 230 //now the options menu 231 VSubTitles = new JCheckBoxMenuItem(new JosmAction(tr("Subtitles"), "cursor/crosshair", tr("Show subtitles in video"),null, false) { 232 233 public void actionPerformed(ActionEvent e) { 234 player.toggleSubtitles(); 199 235 200 236 } … … 265 301 VMenu.add(VLoopLength); 266 302 VMenu.add(VDeinterlacer); 303 VMenu.add(VSubTitles); 304 267 305 } 268 306 -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/GPSVideoPlayer.java
r21779 r22690 1 1 package org.openstreetmap.josm.plugins.videomapping.video; 2 2 import java.awt.Color; 3 import java.awt.Component; 3 4 import java.awt.event.ActionEvent; 4 5 import java.awt.event.ActionListener; 5 6 import java.io.File; 7 import java.sql.Time; 8 import java.util.Date; 9 import java.util.List; 6 10 import java.util.Timer; 7 11 import java.util.TimerTask; 8 12 13 import javax.swing.Action; 9 14 import javax.swing.JButton; 10 15 import javax.swing.JCheckBoxMenuItem; 16 17 import org.openstreetmap.josm.Main; 11 18 import org.openstreetmap.josm.data.gpx.WayPoint; 12 19 import org.openstreetmap.josm.plugins.videomapping.GpsPlayer; … … 22 29 private GPSVideoFile file; 23 30 private boolean synced=false; //do we playback the players together? 31 private JCheckBoxMenuItem subtTitleComponent; 24 32 25 33 … … 34 42 setFile(new GPSVideoFile(f, gpsT-videoT)); */ 35 43 setFile(new GPSVideoFile(f, 0L)); 36 // extend GUI44 //add Sync Button to the Player 37 45 syncBtn= new JButton("sync"); 38 46 syncBtn.setBackground(Color.RED); … … 45 53 synced=true; 46 54 markSyncedPoints(); 47 gps.play(); 55 video.play(); 56 //gps.play(); 48 57 } 49 58 }); 50 set SyncMode(true);59 setAsyncMode(true); 51 60 video.addComponent(syncBtn); 52 //a llow sync53 SimpleVideoPlayer.addObserver(new PlayerObserver() { 61 //a observer to communicate 62 SimpleVideoPlayer.addObserver(new PlayerObserver() { //TODO has o become this 54 63 55 64 public void playing(long time) { 56 65 //sync the GPS back 57 if(synced) gps.jump(getGPSTime(time)); 58 66 if(synced) gps.jump(getGPSTime(time)); 59 67 } 60 68 … … 62 70 63 71 } 64 72 73 //a push way to set video attirbutes 74 public void metadata(long time, boolean subtitles) { 75 if(subtTitleComponent!=null) subtTitleComponent.setSelected(subtitles); 76 } 65 77 66 78 }); … … 70 82 //marks all points that are covered by video AND GPS track 71 83 private void markSyncedPoints() { 72 long time; 73 //TODO this is poor, a start/end calculation would be better 74 for (WayPoint wp : gps.getTrack()) { 75 time=getVideoTime(gps.getRelativeTime(wp)); 76 if(time>0) wp.attr.put("synced", "true"); 77 } 78 79 } 80 81 public void setSyncMode(boolean b) 84 //GPS or video stream starts first in time? 85 WayPoint start,end; 86 long t; 87 if(gps.getLength()<video.getLength()) 88 { 89 //GPS is within video timeperiod 90 start=gps.getWaypoint(0); 91 end=gps.getWaypoint(gps.getLength()); 92 } 93 else 94 { 95 //video is within gps timeperiod 96 t=getGPSTime(0); 97 if(t<0) t=0; 98 start=gps.getWaypoint(t); 99 end=gps.getWaypoint(getGPSTime(video.getLength())); 100 } 101 //mark as synced 102 List<WayPoint> ls = gps.getTrack().subList(gps.getTrack().indexOf(start), gps.getTrack().indexOf(end)); 103 104 for (WayPoint wp : ls) { 105 wp.attr.put("synced", "true"); 106 } 107 } 108 109 public void setAsyncMode(boolean b) 82 110 { 83 111 if(b) … … 97 125 file=f; 98 126 video.setFile(f.getAbsoluteFile()); 99 video.play();127 //video.play(); 100 128 } 101 129 … … 119 147 120 148 //jumps in video to the corresponding linked time 149 public void jumpToGPSTime(Time GPSTime) 150 { 151 gps.jump(GPSTime); 152 } 153 154 //jumps in video to the corresponding linked time 121 155 public void jumpToGPSTime(long gpsT) 122 156 { 157 if(!synced) 158 { 159 //when not synced we can just move the icon to the right position 160 gps.jump(new Date(gpsT)); 161 Main.map.mapView.repaint(); 162 } 123 163 video.jump(getVideoTime(gpsT)); 124 164 } … … 217 257 } 218 258 259 public void toggleSubtitles() { 260 video.toggleSubs(); 261 262 } 263 264 public boolean hasSubtitles(){ 265 return video.hasSubtitles(); 266 } 267 268 public void setSubtitleAction(JCheckBoxMenuItem a) 269 { 270 subtTitleComponent=a; 271 } 272 273 public void metadata(long time, boolean subtitles) { 274 // TODO Auto-generated method stub 275 276 } 277 278 279 280 219 281 220 282 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/SimpleVideoPlayer.java
r21779 r22690 40 40 41 41 import uk.co.caprica.vlcj.binding.LibVlc; 42 import uk.co.caprica.vlcj.check.EnvironmentCheckerFactory;43 import uk.co.caprica.vlcj.player.DefaultFullScreenStrategy;44 import uk.co.caprica.vlcj.player.FullScreenStrategy;45 42 import uk.co.caprica.vlcj.player.MediaPlayer; 46 43 import uk.co.caprica.vlcj.player.MediaPlayerEventAdapter; … … 48 45 import uk.co.caprica.vlcj.player.MediaPlayerFactory; 49 46 import uk.co.caprica.vlcj.player.VideoMetaData; 47 import uk.co.caprica.vlcj.player.embedded.*; 50 48 51 49 //basic class of a videoplayer for one video 52 50 public class SimpleVideoPlayer extends JFrame implements MediaPlayerEventListener, WindowListener{ 53 private MediaPlayer mp;51 private EmbeddedMediaPlayer mp; 54 52 private Timer t; 55 53 private JPanel screenPanel,controlsPanel; 56 54 private JSlider timeline; 57 55 private JButton play,back,forward; 58 private JToggleButton loop ;56 private JToggleButton loop,mute; 59 57 private JSlider speed; 60 58 private Canvas scr; … … 76 74 */ 77 75 try 78 { 76 { 77 //we don't need any options 79 78 String[] libvlcArgs = {""}; 80 79 String[] standardMediaOptions = {""}; 81 80 82 System.out.println("libvlc version: " + LibVlc.INSTANCE.libvlc_get_version());81 //System.out.println("libvlc version: " + LibVlc.INSTANCE.libvlc_get_version()); 83 82 //setup Media Player 84 83 //TODO we have to deal with unloading things.... … … 88 87 mp.setStandardMediaOptions(standardMediaOptions); 89 88 //setup GUI 90 setSize(400, 300); //later we resize89 setSize(400, 300); //later we apply movie size 91 90 setAlwaysOnTop(true); 92 //setIconImage(); 93 ms = new SimpleDateFormat("hh:mm:ss:S"); 94 scr=new Canvas(); 95 timeline = new JSlider(0,100,0); 96 timeline.setMajorTickSpacing(10); 97 timeline.setMajorTickSpacing(5); 98 timeline.setPaintTicks(true); 99 play= new JButton(tr("play")); 100 back= new JButton("<"); 101 forward= new JButton(">"); 102 loop= new JToggleButton(tr("loop")); 103 speed = new JSlider(-200,200,0); 104 speed.setMajorTickSpacing(100); 105 speed.setPaintTicks(true); 106 speed.setOrientation(Adjustable.VERTICAL); 107 Hashtable labelTable = new Hashtable(); 108 labelTable.put( new Integer( 0 ), new JLabel("1x") ); 109 labelTable.put( new Integer( -200 ), new JLabel("-2x") ); 110 labelTable.put( new Integer( 200 ), new JLabel("2x") ); 111 speed.setLabelTable( labelTable ); 112 speed.setPaintLabels(true); 113 91 createUI(); 114 92 setLayout(); 115 addListeners(); 93 addListeners(); //registering shortcuts is task of the outer plugin class! 116 94 //embed vlc player 117 95 scr.setVisible(true); … … 119 97 mp.setVideoSurface(scr); 120 98 mp.addMediaPlayerEventListener(this); 121 mp.pause();122 jump(0);123 // setupdater99 //mp.pause(); 100 //jump(0); 101 //create updater 124 102 ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); 125 103 executorService.scheduleAtFixedRate(new Syncer(this), 0L, 1000L, TimeUnit.MILLISECONDS); … … 136 114 } 137 115 116 } 117 118 private void createUI() { 119 //setIconImage(); 120 ms = new SimpleDateFormat("hh:mm:ss"); 121 scr=new Canvas(); 122 timeline = new JSlider(0,100,0); 123 timeline.setMajorTickSpacing(10); 124 timeline.setMajorTickSpacing(5); 125 timeline.setPaintTicks(true); 126 //TODO we need Icons instead 127 play= new JButton(tr("play")); 128 back= new JButton("<"); 129 forward= new JButton(">"); 130 loop= new JToggleButton(tr("loop")); 131 mute= new JToggleButton(tr("mute")); 132 speed = new JSlider(-200,200,0); 133 speed.setMajorTickSpacing(100); 134 speed.setPaintTicks(true); 135 speed.setOrientation(Adjustable.VERTICAL); 136 Hashtable labelTable = new Hashtable(); 137 labelTable.put( new Integer( 0 ), new JLabel("1x") ); 138 labelTable.put( new Integer( -200 ), new JLabel("-2x") ); 139 labelTable.put( new Integer( 200 ), new JLabel("2x") ); 140 speed.setLabelTable( labelTable ); 141 speed.setPaintLabels(true); 138 142 } 139 143 … … 155 159 controlsPanel.add(forward); 156 160 controlsPanel.add(loop); 161 controlsPanel.add(mute); 157 162 loop.setSelected(false); 163 mute.setSelected(false); 158 164 } 159 165 … … 176 182 177 183 public void actionPerformed(ActionEvent arg0) { 178 if(mp.isPlaying()) mp. stop(); else mp.play();184 if(mp.isPlaying()) mp.pause(); else mp.play(); 179 185 } 180 186 }); … … 198 204 public void actionPerformed(ActionEvent arg0) { 199 205 loop(); 206 } 207 }); 208 209 mute.addActionListener(new ActionListener() { 210 211 public void actionPerformed(ActionEvent arg0) { 212 mute(); 200 213 } 201 214 }); … … 215 228 }); 216 229 217 } 230 } 218 231 219 232 public void finished(MediaPlayer arg0) { … … 230 243 scr.setSize(new Dimension((int)(org.width*perc), (int)(org.height*perc))); 231 244 pack(); 232 245 //send out metadatas to all observers 246 for (PlayerObserver o : observers) { 247 o.metadata(0, hasSubtitles()); 248 } 233 249 } 234 250 … … 277 293 { 278 294 String mediaPath = f.getAbsoluteFile().toString(); 279 mp.playMedia(mediaPath, mediaOptions); 295 mp.playMedia(mediaPath, mediaOptions); 280 296 pack(); 281 297 } … … 308 324 } 309 325 310 //gets called by the Syncer t o update all components326 //gets called by the Syncer thread to update all observers 311 327 public void updateTime () 312 328 { 313 329 if(mp.isPlaying()) 314 330 { 315 setTitle(ms.format(new Date(mp.getTime()))); //FIXME there is a leading hour even at the beginning331 setTitle(ms.format(new Date(mp.getTime()))); 316 332 syncTimeline=true; 317 333 timeline.setValue(Math.round(mp.getPosition()*100)); … … 369 385 370 386 } 387 388 protected void mute() { 389 mp.mute(); 390 391 } 371 392 372 393 public void forward() { … … 384 405 385 406 } 407 408 public void toggleSubs() 409 { 410 //vlc manages it's subtitles in a own list so we have to cycle trough 411 int spu = mp.getSpu(); 412 if(spu > -1) { 413 spu++; 414 if(spu > mp.getSpuCount()) { 415 spu = -1; 416 } 417 } 418 else { 419 spu = 0; 420 } 421 mp.setSpu(spu); 422 } 386 423 387 424 public static void addObserver(PlayerObserver observer) { … … 402 439 403 440 for (PlayerObserver o : observers) { 404 405 441 o.playing(newTime); 406 407 442 } 408 443 … … 432 467 } 433 468 469 public void error(MediaPlayer arg0) { 470 // TODO Auto-generated method stub 471 472 } 473 474 public void mediaChanged(MediaPlayer arg0) { 475 // TODO Auto-generated method stub 476 477 } 478 479 public boolean hasSubtitles() { 480 if (mp.getSpuCount()==0) return false; else return true; 481 } 482 434 483 435 484 -
applications/editors/josm/plugins/videomapping/test/videotest.java
r21656 r22690 26 26 public static void main(String[] args) { 27 27 final SimpleVideoPlayer sVP = new SimpleVideoPlayer(); 28 sVP.setFile(new File("C:\\TEMP\\ test.mpg"));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!!!)28 sVP.setFile(new File("C:\\TEMP\\122_0159.MOV")); 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 31 JButton b = new JButton("jump");
Note:
See TracChangeset
for help on using the changeset viewer.