Changeset 32630 in osm for applications/editors/josm/plugins/videomapping/src
- Timestamp:
- 2016-07-10T23:37:30+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoObserver.java
r32513 r32630 5 5 public interface VideoObserver { 6 6 void playing(long time); 7 7 8 void jumping(long time); 8 void metadata(long time,boolean subtitles);9 9 10 void metadata(long time, boolean subtitles); 10 11 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoPlugin.java
r32513 r32630 49 49 */ 50 50 public class VideoPlugin extends Plugin implements LayerChangeListener, ActiveLayerChangeListener { 51 private JMenu VMenu, VDeinterlacer;52 private JosmAction VAdd, /*VRemove,*/VStart,Vbackward,Vforward,VJump,Vfaster,Vslower,Vloop;53 private JRadioButtonMenuItem VIntBob, VIntNone,VIntLinear;54 private JCheckBoxMenuItem VCenterIcon, VSubTitles;55 private JMenuItem VJumpLength, VLoopLength;56 private final String PROP_MRU ="videomapping.mru";57 private final String PROP_AUTOCENTER ="videomapping.autocenter";58 private final String PROP_JUMPLENGTH ="videomapping.jumplength";59 private final String PROP_LOOPLENGTH ="videomapping.looplength";51 private JMenu VMenu, VDeinterlacer; 52 private JosmAction VAdd, /*VRemove,*/ VStart, Vbackward, Vforward, VJump, Vfaster, Vslower, Vloop; 53 private JRadioButtonMenuItem VIntBob, VIntNone, VIntLinear; 54 private JCheckBoxMenuItem VCenterIcon, VSubTitles; 55 private JMenuItem VJumpLength, VLoopLength; 56 private final String PROP_MRU = "videomapping.mru"; 57 private final String PROP_AUTOCENTER = "videomapping.autocenter"; 58 private final String PROP_JUMPLENGTH = "videomapping.jumplength"; 59 private final String PROP_LOOPLENGTH = "videomapping.looplength"; 60 60 // private String deinterlacer; 61 61 private boolean autoCenter; 62 private Integer jumpLength, loopLength;62 private Integer jumpLength, loopLength; 63 63 private String mostRecentFolder; 64 64 private GpxLayer gpsLayer; … … 71 71 super(info); 72 72 VideoEngine.setupPlayer(); 73 Main.getLayerManager().addLayerChangeListener(this); 74 Main.getLayerManager().addActiveLayerChangeListener(this); 73 Main.getLayerManager().addLayerChangeListener(this); 74 Main.getLayerManager().addActiveLayerChangeListener(this); 75 75 createMenusAndShortCuts(); 76 76 enableVideoControlMenus(false); … … 80 80 81 81 private void createMenusAndShortCuts() { 82 VMenu = Main.main.menu.addMenu("Video", tr("Video"), KeyEvent.VK_Q, Main.main.menu.getDefaultMenuPos(), ht("/Plugin/Videomapping"));82 VMenu = Main.main.menu.addMenu("Video", tr("Video"), KeyEvent.VK_Q, Main.main.menu.getDefaultMenuPos(), ht("/Plugin/Videomapping")); 83 83 VMenu.setEnabled(false); 84 VAdd = new JosmAction(tr("Import Video"),"videomapping",tr("Sync a video against this GPS track"),null,false) {85 @Override public void actionPerformed(ActionEvent arg0) { 84 VAdd = new JosmAction(tr("Import Video"), "videomapping", tr("Sync a video against this GPS track"), null, false) { 85 @Override public void actionPerformed(ActionEvent arg0) { 86 86 importVideoFile(); 87 87 } 88 88 }; 89 /*VRemove=*/ new JosmAction(tr("Remove Video"), "videomapping",tr("removes current video from layer"),null,false) {89 /*VRemove=*/ new JosmAction(tr("Remove Video"), "videomapping", tr("removes current video from layer"), null, false) { 90 90 @Override public void actionPerformed(ActionEvent arg0) { 91 91 } 92 92 }; 93 // CHECKSTYLE.OFF: LineLength 93 94 VStart = new JosmAction(tr("Play/Pause"), "audio-playpause", tr("starts/pauses video playback"), 94 Shortcut.registerShortcut("videomapping:startstop", tr("Video: {0}", tr("Play/Pause")),KeyEvent.VK_NUMPAD5, Shortcut.DIRECT), false, "vm_play_pause",false) {95 Shortcut.registerShortcut("videomapping:startstop", tr("Video: {0}", tr("Play/Pause")), KeyEvent.VK_NUMPAD5, Shortcut.DIRECT), false, "vm_play_pause", false) { 95 96 @Override public void actionPerformed(ActionEvent e) { 96 97 if (gpsVideoPlayer != null) { … … 100 101 }; 101 102 Vbackward = new JosmAction(tr("Backward"), "audio-prev", tr("jumps n sec back"), 102 Shortcut.registerShortcut("videomapping:backward", tr("Video: {0}", tr("Backward")),KeyEvent.VK_NUMPAD4, Shortcut.DIRECT), false, "vm_prev",false) {103 Shortcut.registerShortcut("videomapping:backward", tr("Video: {0}", tr("Backward")), KeyEvent.VK_NUMPAD4, Shortcut.DIRECT), false, "vm_prev", false) { 103 104 @Override public void actionPerformed(ActionEvent e) { 104 105 if (gpsVideoPlayer != null) { … … 107 108 } 108 109 }; 109 Vforward = new JosmAction(tr("Forward"), "audio-next", tr("jumps n sec forward"),110 Shortcut.registerShortcut("videomapping:forward", tr("Video: {0}", tr("Forward")),KeyEvent.VK_NUMPAD6, Shortcut.DIRECT), false, "vm_next",false) {110 Vforward = new JosmAction(tr("Forward"), "audio-next", tr("jumps n sec forward"), 111 Shortcut.registerShortcut("videomapping:forward", tr("Video: {0}", tr("Forward")), KeyEvent.VK_NUMPAD6, Shortcut.DIRECT), false, "vm_next", false) { 111 112 @Override public void actionPerformed(ActionEvent e) { 112 113 if (gpsVideoPlayer != null) { … … 115 116 } 116 117 }; 117 Vfaster= new JosmAction(tr("Faster"), "audio-faster", tr("faster playback"), 118 Shortcut.registerShortcut("videomapping:faster",tr("Video: {0}", tr("Faster")),KeyEvent.VK_NUMPAD8, Shortcut.DIRECT), false, "vm_faster",false) { 119 118 Vfaster = new JosmAction(tr("Faster"), "audio-faster", tr("faster playback"), 119 Shortcut.registerShortcut("videomapping:faster", tr("Video: {0}", tr("Faster")), KeyEvent.VK_NUMPAD8, Shortcut.DIRECT), false, "vm_faster", false) { 120 120 @Override public void actionPerformed(ActionEvent e) { 121 121 if (gpsVideoPlayer != null) { … … 124 124 } 125 125 }; 126 Vslower= new JosmAction(tr("Slower"), "audio-slower", tr("slower playback"), 127 Shortcut.registerShortcut("videomapping:slower",tr("Video: {0}", tr("Slower")),KeyEvent.VK_NUMPAD2, Shortcut.DIRECT), false, "vm_slower",false) {128 126 127 Vslower = new JosmAction(tr("Slower"), "audio-slower", tr("slower playback"), 128 Shortcut.registerShortcut("videomapping:slower", tr("Video: {0}", tr("Slower")), KeyEvent.VK_NUMPAD2, Shortcut.DIRECT), false, "vm_slower", false) { 129 129 @Override public void actionPerformed(ActionEvent e) { 130 130 if (gpsVideoPlayer != null) { … … 133 133 } 134 134 }; 135 VJump= new JosmAction(tr("Jump To"), "jumpto", tr("jumps to the entered gps time"),null, false) { 136 @Override public void actionPerformed(ActionEvente) {137 showJumpTo();138 }139 140 141 }; 142 Vloop = new JosmAction(tr("Loop"), "loop", tr("loops n sec around current position"),143 Shortcut.registerShortcut("videomapping:loop", tr("Video: {0}", tr("Loop")),KeyEvent.VK_NUMPAD7, Shortcut.DIRECT), false) {135 136 VJump = new JosmAction(tr("Jump To"), "jumpto", tr("jumps to the entered gps time"), null, false) { 137 @Override public void actionPerformed(ActionEvent e) { 138 showJumpTo(); 139 } 140 }; 141 142 Vloop = new JosmAction(tr("Loop"), "loop", tr("loops n sec around current position"), 143 Shortcut.registerShortcut("videomapping:loop", tr("Video: {0}", tr("Loop")), KeyEvent.VK_NUMPAD7, Shortcut.DIRECT), false) { 144 144 @Override public void actionPerformed(ActionEvent e) { 145 145 if (gpsVideoPlayer != null) { … … 148 148 } 149 149 }; 150 150 151 151 //now the options menu 152 VCenterIcon = new JCheckBoxMenuItem(new JosmAction(tr("Keep centered"), (String) null, tr("follows the video icon automatically"),null, false,"vm_keepcentered",false) {152 VCenterIcon = new JCheckBoxMenuItem(new JosmAction(tr("Keep centered"), (String) null, tr("follows the video icon automatically"), null, false, "vm_keepcentered", false) { 153 153 @Override public void actionPerformed(ActionEvent e) { 154 154 if (videoPositionLayer != null) { … … 157 157 } 158 158 }); 159 160 VSubTitles = new JCheckBoxMenuItem(new JosmAction(tr("Subtitles"), (String) null, tr("Show subtitles in video"),null, false,"vm_subtitles",false) {159 160 VSubTitles = new JCheckBoxMenuItem(new JosmAction(tr("Subtitles"), (String) null, tr("Show subtitles in video"), null, false, "vm_subtitles", false) { 161 161 @Override public void actionPerformed(ActionEvent e) { 162 162 if (gpsVideoPlayer != null) { … … 165 165 } 166 166 }); 167 168 VJumpLength = new JMenuItem(new JosmAction(tr("Jump length"), (String) null, tr("Set the length of a jump"),null, false,"vm_jumplen",false) {169 @Override public void actionPerformed(ActionEvent e) { 170 171 String s = (String) JOptionPane.showInputDialog(Main.parent,tr("Jump in video for x ms"),tr("Jump length"),JOptionPane.QUESTION_MESSAGE,null,possibilities,jumpLength);172 jumpLength =Integer.getInteger(s);167 168 VJumpLength = new JMenuItem(new JosmAction(tr("Jump length"), (String) null, tr("Set the length of a jump"), null, false, "vm_jumplen", false) { 169 @Override public void actionPerformed(ActionEvent e) { 170 Object[] possibilities = {"200", "500", "1000", "2000", "10000"}; 171 String s = (String) JOptionPane.showInputDialog(Main.parent, tr("Jump in video for x ms"), tr("Jump length"), JOptionPane.QUESTION_MESSAGE, null, possibilities, jumpLength); 172 jumpLength = Integer.getInteger(s); 173 173 saveProperties(); 174 174 } 175 175 }); 176 177 VLoopLength = new JMenuItem(new JosmAction(tr("Loop length"), (String) null, tr("Set the length around a looppoint"),null, false,"vm_looplen",false) {178 @Override public void actionPerformed(ActionEvent e) { 179 180 String s = (String) JOptionPane.showInputDialog(Main.parent,tr("Jump in video for x ms"),tr("Loop length"),JOptionPane.QUESTION_MESSAGE,null,possibilities,loopLength);181 loopLength =Integer.getInteger(s);176 177 VLoopLength = new JMenuItem(new JosmAction(tr("Loop length"), (String) null, tr("Set the length around a looppoint"), null, false, "vm_looplen", false) { 178 @Override public void actionPerformed(ActionEvent e) { 179 Object[] possibilities = {"500", "1000", "3000", "5000", "10000"}; 180 String s = (String) JOptionPane.showInputDialog(Main.parent, tr("Jump in video for x ms"), tr("Loop length"), JOptionPane.QUESTION_MESSAGE, null, possibilities, loopLength); 181 loopLength = Integer.getInteger(s); 182 182 saveProperties(); 183 183 } 184 184 }); 185 185 //TODO read deinterlacers list out of videoengine 186 VDeinterlacer = new JMenu("Deinterlacer");187 VIntNone = new JRadioButtonMenuItem(new JosmAction(tr("none"), (String)null, tr("no deinterlacing"),null, false,"vm_deinterlacer",false) {186 VDeinterlacer = new JMenu("Deinterlacer"); 187 VIntNone = new JRadioButtonMenuItem(new JosmAction(tr("none"), (String) null, tr("no deinterlacing"), null, false, "vm_deinterlacer", false) { 188 188 @Override public void actionPerformed(ActionEvent e) { 189 189 if (gpsVideoPlayer != null) { … … 192 192 } 193 193 }); 194 VIntBob = new JRadioButtonMenuItem(new JosmAction("bob", (String)null, tr("deinterlacing using line doubling"),null, false,"vm_bobdeinterlace",false) {194 VIntBob = new JRadioButtonMenuItem(new JosmAction("bob", (String) null, tr("deinterlacing using line doubling"), null, false, "vm_bobdeinterlace", false) { 195 195 @Override public void actionPerformed(ActionEvent e) { 196 196 if (gpsVideoPlayer != null) { … … 199 199 } 200 200 }); 201 VIntLinear = new JRadioButtonMenuItem(new JosmAction("linear", (String)null, tr("deinterlacing using linear interpolation"),null, false,"vm_lineardeinterlace",false) {201 VIntLinear = new JRadioButtonMenuItem(new JosmAction("linear", (String) null, tr("deinterlacing using linear interpolation"), null, false, "vm_lineardeinterlace", false) { 202 202 @Override public void actionPerformed(ActionEvent e) { 203 203 if (gpsVideoPlayer != null) { … … 206 206 } 207 207 }); 208 // CHECKSTYLE.ON: LineLength 208 209 VDeinterlacer.add(VIntNone); 209 210 VDeinterlacer.add(VIntBob); 210 VDeinterlacer.add(VIntLinear); 211 VMenu.add(VAdd); 211 VDeinterlacer.add(VIntLinear); 212 VMenu.add(VAdd); 212 213 VMenu.add(VStart); 213 214 VMenu.add(Vbackward); … … 229 230 fc.setSelectedFile(new File(mostRecentFolder)); 230 231 if (fc.showOpenDialog(Main.parent) != JFileChooser.CANCEL_OPTION) { 231 mostRecentFolder =fc.getSelectedFile().getAbsolutePath();232 mostRecentFolder = fc.getSelectedFile().getAbsolutePath(); 232 233 saveProperties(); 233 234 if (videoPositionLayer == null && gpsLayer != null) { 234 235 videoPositionLayer = new VideoPositionLayer(gpsLayer); 235 gpsVideoPlayer = new GPSVideoPlayer(new SimpleDateFormat("hh:mm:ss") ,videoPositionLayer);236 gpsVideoPlayer = new GPSVideoPlayer(new SimpleDateFormat("hh:mm:ss"), videoPositionLayer); 236 237 gpsVideoPlayer.setJumpLength(jumpLength); 237 238 gpsVideoPlayer.setLoopLength(loopLength); … … 241 242 gpsVideoPlayer.addVideo(fc.getSelectedFile()); 242 243 } else { 243 JOptionPane.showMessageDialog(Main.parent, 244 JOptionPane.showMessageDialog(Main.parent, 244 245 tr("VLC library is not correctly initialized."+ 245 246 " Please check that VLC {0} is correctly installed on your system."+ … … 247 248 tr("Error"), JOptionPane.ERROR_MESSAGE); 248 249 } 249 } 250 } 250 251 } 251 252 … … 257 258 Vfaster.setEnabled(b); 258 259 Vslower.setEnabled(b); 259 VJump.setEnabled(b); 260 } 261 260 VJump.setEnabled(b); 261 } 262 262 263 private void setDefaults() { 263 autoCenter =false;264 // 265 jumpLength =1000;266 loopLength =6000;267 mostRecentFolder =System.getProperty("user.home");268 } 269 264 autoCenter = false; 265 // deinterlacer=""; 266 jumpLength = 1000; 267 loopLength = 6000; 268 mostRecentFolder = System.getProperty("user.home"); 269 } 270 270 271 private void loadProperties() { 271 String temp; 272 temp =Main.pref.get(PROP_AUTOCENTER);273 if ((temp!=null)&&(temp.length()!=0))274 autoCenter=Boolean.getBoolean(temp);275 temp =Main.pref.get(PROP_JUMPLENGTH);276 if ((temp!=null)&&(temp.length()!=0))277 jumpLength=Integer.valueOf(temp);278 temp =Main.pref.get(PROP_LOOPLENGTH);279 if ((temp!=null)&&(temp.length()!=0))280 loopLength=Integer.valueOf(temp);281 temp =Main.pref.get(PROP_MRU);282 if ((temp!=null)&&(temp.length()!=0))283 mostRecentFolder=Main.pref.get(PROP_MRU);284 } 285 286 private void saveProperties() {272 String temp; 273 temp = Main.pref.get(PROP_AUTOCENTER); 274 if ((temp != null) && (temp.length() != 0)) 275 autoCenter = Boolean.getBoolean(temp); 276 temp = Main.pref.get(PROP_JUMPLENGTH); 277 if ((temp != null) && (temp.length() != 0)) 278 jumpLength = Integer.valueOf(temp); 279 temp = Main.pref.get(PROP_LOOPLENGTH); 280 if ((temp != null) && (temp.length() != 0)) 281 loopLength = Integer.valueOf(temp); 282 temp = Main.pref.get(PROP_MRU); 283 if ((temp != null) && (temp.length() != 0)) 284 mostRecentFolder = Main.pref.get(PROP_MRU); 285 } 286 287 private void saveProperties() { 287 288 Main.pref.put(PROP_AUTOCENTER, autoCenter); 288 289 Main.pref.put(PROP_JUMPLENGTH, jumpLength.toString()); 289 Main.pref.put(PROP_LOOPLENGTH, loopLength.toString()); 290 291 } 292 290 Main.pref.put(PROP_LOOPLENGTH, loopLength.toString()); 291 Main.pref.put(PROP_MRU, mostRecentFolder); 292 } 293 293 294 private void showJumpTo() { 294 295 try { 295 JOptionPane d =new JOptionPane(tr("Jump to"), JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);296 SimpleDateFormat gpsTimeFormat = new SimpleDateFormat("HH:mm:ss");297 String timerange =gpsTimeFormat.format(videoPositionLayer.getFirstWayPoint().getTime())+" - ";298 timerange =timerange+gpsTimeFormat.format(videoPositionLayer.getLastWayPoint().getTime());296 JOptionPane d = new JOptionPane(tr("Jump to"), JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 297 SimpleDateFormat gpsTimeFormat = new SimpleDateFormat("HH:mm:ss"); 298 String timerange = gpsTimeFormat.format(videoPositionLayer.getFirstWayPoint().getTime())+" - "; 299 timerange = timerange+gpsTimeFormat.format(videoPositionLayer.getLastWayPoint().getTime()); 299 300 d.add(new JLabel(timerange)); //TODO for some reason this doesn't work -> use dialog 300 301 final JFormattedTextField inp = new JFormattedTextField(new MaskFormatter("##:##:##")); 301 inp.setText(gpsTimeFormat.format( 302 inp.setInputVerifier(new InputVerifier() { 302 inp.setText(gpsTimeFormat.format(videoPositionLayer.getGPSDate())); 303 inp.setInputVerifier(new InputVerifier() { 303 304 @Override 304 305 public boolean verify(JComponent input) { … … 314 315 } 315 316 }); 316 if (JOptionPane.showConfirmDialog(Main.parent,inp, tr("Jump to GPS time"),JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) 317 { 317 if (JOptionPane.showConfirmDialog(Main.parent, inp, tr("Jump to GPS time"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { 318 318 //add the day to the time 319 Date t = gpsTimeFormat.parse(inp.getText()); 319 Date t = gpsTimeFormat.parse(inp.getText()); 320 320 Calendar time = Calendar.getInstance(); 321 321 Calendar date = Calendar.getInstance(); … … 323 323 date.setTime(videoPositionLayer.getFirstWayPoint().getTime()); 324 324 time.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DATE)); 325 if (t!=null) 326 { 325 if (t != null) { 327 326 videoPositionLayer.jump(time.getTime()); 328 } 329 } 330 327 } 328 } 329 } catch (ParseException e1) { 331 330 e1.printStackTrace(); 332 331 } … … 337 336 if (l instanceof GpxLayer) { 338 337 VAdd.setEnabled(true); 339 gpsLayer = (GpxLayer) l; 338 gpsLayer = (GpxLayer) l; 340 339 //TODO append to GPS Layer menu 341 } 342 } 343 340 } 341 } 342 344 343 @Override 345 344 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 346 handleLayer(Main.getLayerManager().getActiveLayer()); 345 handleLayer(Main.getLayerManager().getActiveLayer()); 347 346 } 348 347 -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoPositionLayer.java
r32513 r32630 41 41 private DateFormat gpsTimeFormat; 42 42 private WayPoint iconPosition; 43 private final int GPS_INTERVALL =1000;43 private final int GPS_INTERVALL = 1000; 44 44 private GPSVideoPlayer gpsVideoPlayer; 45 45 private boolean autoCenter; … … 48 48 super("videolayer"); 49 49 layerIcon = new ImageIcon("images/videomapping.png"); 50 gpsTrack =importGPSLayer(gpsLayer.data);51 gpsTimeFormat = new SimpleDateFormat("HH:mm:ss");52 iconPosition =gpsTrack.get(0);53 Main.getLayerManager().addLayer(this); 50 gpsTrack = importGPSLayer(gpsLayer.data); 51 gpsTimeFormat = new SimpleDateFormat("HH:mm:ss"); 52 iconPosition = gpsTrack.get(0); 53 Main.getLayerManager().addLayer(this); 54 54 } 55 55 … … 76 76 private void paintGpsTrack(Graphics2D g, MapView map) { 77 77 g.setColor(Color.YELLOW); 78 for (WayPoint n: gpsTrack) {78 for (WayPoint n: gpsTrack) { 79 79 Point p = map.getPoint(n.getEastNorth()); 80 80 g.drawOval(p.x - 2, p.y - 2, 4, 4); 81 81 } 82 82 } 83 83 84 84 private void paintSyncedTrack(Graphics2D g, MapView map) { 85 85 g.setColor(Color.GREEN); … … 88 88 Point p = map.getPoint(n.getEastNorth()); 89 89 g.drawOval(p.x - 2, p.y - 2, 4, 4); 90 } 91 } 90 } 91 } 92 92 } 93 93 … … 96 96 Point p = map.getPoint(iconPosition.getEastNorth()); 97 97 layerIcon.paintIcon(null, g, p.x-layerIcon.getIconWidth()/2, p.y-layerIcon.getIconHeight()/2); 98 g.drawString(gpsTimeFormat.format(iconPosition.getTime()), p.x-15,p.y-15);99 } 100 } 101 /* 98 g.drawString(gpsTimeFormat.format(iconPosition.getTime()), p.x-15, p.y-15); 99 } 100 } 101 /* 102 102 private void paintInterpolatedSegment(Graphics2D g) { 103 103 g.setColor(Color.CYAN); … … 107 107 g.drawOval(p.x - 2, p.y - 2, 4, 4); 108 108 } 109 109 110 110 } 111 111 … … 129 129 test.setHours(14); 130 130 test.setMinutes(50); 131 test.setSeconds(33); 131 test.setSeconds(33); 132 132 ls.add(getWayPointBefore(new Date(test.getTime()+500))); 133 133 ls.add(interpolate(new Date(test.getTime()+500))); 134 134 return ls; 135 135 } 136 */ 136 */ 137 137 //creates a waypoint for the corresponding time 138 138 public WayPoint interpolate(Date GPSTime) { … … 142 142 } 143 143 long diff = GPSTime.getTime() - before.getTime().getTime(); 144 assert diff >=0;145 assert diff <GPS_INTERVALL;146 float perc =((float)diff/(float)GPS_INTERVALL)*100;147 return interpolate(before, perc);148 } 149 144 assert diff >= 0; 145 assert diff < GPS_INTERVALL; 146 float perc = ((float) diff/(float) GPS_INTERVALL)*100; 147 return interpolate(before, perc); 148 } 149 150 150 public WayPoint getWayPointBefore(Date GPSTime) { 151 assert GPSTime.after(getFirstWayPoint().getTime()) ==true;152 assert GPSTime.before(getLastWayPoint().getTime()) ==true;153 154 Date first =getFirstWayPoint().getTime();155 long diff =GPSTime.getTime()-first.getTime();151 assert GPSTime.after(getFirstWayPoint().getTime()) == true; 152 assert GPSTime.before(getLastWayPoint().getTime()) == true; 153 154 Date first = getFirstWayPoint().getTime(); 155 long diff = GPSTime.getTime()-first.getTime(); 156 156 //assumes that GPS intervall is constant 157 int id = (int) (diff/GPS_INTERVALL); 157 int id = (int) (diff/GPS_INTERVALL); 158 158 return 0 <= id && id < gpsTrack.size() ? gpsTrack.get(id) : null; 159 159 } 160 160 161 161 public WayPoint getFirstWayPoint() { 162 162 return gpsTrack.isEmpty() ? null : gpsTrack.get(0); 163 163 } 164 164 165 165 public WayPoint getLastWayPoint() { 166 166 return gpsTrack.isEmpty() ? null : gpsTrack.get(gpsTrack.size()-1); … … 169 169 //interpolates a waypoint between this and the following waypoint at percent 170 170 private WayPoint interpolate(WayPoint first, float percent) { 171 assert (percent >0);172 assert (percent <100);173 double dX, dY;174 WayPoint leftP, rightP;175 176 WayPoint next =gpsTrack.get(gpsTrack.indexOf(first)+1);171 assert (percent > 0); 172 assert (percent < 100); 173 double dX, dY; 174 WayPoint leftP, rightP; 175 176 WayPoint next = gpsTrack.get(gpsTrack.indexOf(first)+1); 177 177 //determine which point is what 178 leftP =getLeftPoint(first, next);179 rightP =getRightPoint(first,next);178 leftP = getLeftPoint(first, next); 179 rightP = getRightPoint(first, next); 180 180 //calc increment 181 percent =percent/100;182 dX =(rightP.getCoor().lon()-leftP.getCoor().lon())*percent;183 dY =(rightP.getCoor().lat()-leftP.getCoor().lat())*percent;181 percent = percent/100; 182 dX = (rightP.getCoor().lon()-leftP.getCoor().lon())*percent; 183 dY = (rightP.getCoor().lat()-leftP.getCoor().lat())*percent; 184 184 //move in the right direction 185 if (first ==leftP) {186 return new WayPoint(new LatLon(leftP.getCoor().lat()+dY, leftP.getCoor().lon()+dX));185 if (first == leftP) { 186 return new WayPoint(new LatLon(leftP.getCoor().lat()+dY, leftP.getCoor().lon()+dX)); 187 187 } else { 188 return new WayPoint(new LatLon(rightP.getCoor().lat()-dY, rightP.getCoor().lon()-dX));189 } 190 } 191 192 private WayPoint getLeftPoint(WayPoint p1, WayPoint p2) {193 if (p1.getCoor().lon()<p2.getCoor().lon()) return p1; else return p2;194 } 195 188 return new WayPoint(new LatLon(rightP.getCoor().lat()-dY, rightP.getCoor().lon()-dX)); 189 } 190 } 191 192 private WayPoint getLeftPoint(WayPoint p1, WayPoint p2) { 193 if (p1.getCoor().lon() < p2.getCoor().lon()) return p1; else return p2; 194 } 195 196 196 private WayPoint getRightPoint(WayPoint p1, WayPoint p2) { 197 if (p1.getCoor().lon()>p2.getCoor().lon()) return p1; else return p2;198 } 199 197 if (p1.getCoor().lon() > p2.getCoor().lon()) return p1; else return p2; 198 } 199 200 200 public Date getGPSDate() { 201 201 return iconPosition.getTime(); 202 202 } 203 203 204 204 public WayPoint getCurrentWayPoint() { 205 205 return iconPosition; … … 209 209 return gpsTrack; 210 210 } 211 211 212 212 public void jump(Date GPSTime) { 213 213 setIconPosition(getWayPointBefore(GPSTime)); … … 225 225 public void mouseReleased(MouseEvent e) { 226 226 //only leftclicks on our layer 227 if (e.getButton() == MouseEvent.BUTTON1) {228 WayPoint wp = getNearestWayPoint(e.getPoint()); 227 if (e.getButton() == MouseEvent.BUTTON1) { 228 WayPoint wp = getNearestWayPoint(e.getPoint()); 229 229 if (wp != null) { 230 230 if (gpsVideoPlayer.areAllVideosSynced()) { … … 233 233 } 234 234 setIconPosition(wp); 235 } 235 } 236 236 } 237 237 } … … 239 239 //finds the first waypoint that is nearby the given point 240 240 private WayPoint getNearestWayPoint(Point mouse) { 241 final int MAX =10;241 final int MAX = 10; 242 242 Point p; 243 Rectangle rect = new Rectangle(mouse.x-MAX/2, mouse.y-MAX/2,MAX,MAX);243 Rectangle rect = new Rectangle(mouse.x-MAX/2, mouse.y-MAX/2, MAX, MAX); 244 244 //iterate through all possible notes 245 for (WayPoint n : gpsTrack) {245 for (WayPoint n : gpsTrack) { 246 246 p = Main.map.mapView.getPoint(n.getEastNorth()); 247 247 if (rect.contains(p)) { … … 279 279 280 280 @Override 281 public boolean isMergable(Layer arg0) { 281 public boolean isMergable(Layer arg0) { 282 282 return false; 283 283 } … … 290 290 public void visitBoundingBox(BoundingXYVisitor arg0) { 291 291 } 292 292 293 293 public void setGPSVideoPlayer(GPSVideoPlayer player) { 294 294 gpsVideoPlayer = player; -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/GPSVideo.java
r32513 r32630 15 15 // a specific synced video 16 16 public class GPSVideo extends Video { 17 private static final String SYNC_KEY = "synced"; 18 public JComponent SyncComponent; 19 private WayPoint syncWayPoint; 20 private long syncVideoTime; 21 private Date start; 22 private Date end; 23 public WayPoint firstWayPoint; 24 public WayPoint lastWayPoint; 25 private VideoPositionLayer videoPositionLayer; 26 27 public GPSVideo(File filename, String id, MediaPlayerFactory mediaPlayerFactory) { 28 super(filename,id,mediaPlayerFactory); 29 } 30 31 public GPSVideo(Video video) { 32 super(video.filename, video.id, video.mediaPlayerFactory); 33 this.player = video.player; 34 } 35 36 //calculates attributes basing upon the current position 37 public void doSync(VideoPositionLayer layer) { 38 this.videoPositionLayer = layer; 39 if (isSynced()) 40 removeSyncedWayPoints(); 41 syncWayPoint = layer.getCurrentWayPoint(); 42 syncVideoTime = getCurrentTime(); 43 //calc now, to avoid calculations on every click 44 if (syncWayPoint != null) { 45 start = new Date(syncWayPoint.getTime().getTime()-syncVideoTime); 46 end = new Date(start.getTime()+player.getLength()); 47 } else { 48 start = null; 49 end = null; 50 } 51 firstWayPoint = getFirstGPS(); 52 lastWayPoint = getLastGPS(); 53 markSyncedWayPoints(); 54 Main.map.mapView.repaint(); 55 } 17 private static final String SYNC_KEY = "synced"; 18 public JComponent SyncComponent; 19 private WayPoint syncWayPoint; 20 private long syncVideoTime; 21 private Date start; 22 private Date end; 23 public WayPoint firstWayPoint; 24 public WayPoint lastWayPoint; 25 private VideoPositionLayer videoPositionLayer; 56 26 57 //make sure we don't leave the GPS track 58 private WayPoint getFirstGPS() { 59 if (start == null || start.before(videoPositionLayer.getFirstWayPoint().getTime())) { 60 return videoPositionLayer.getFirstWayPoint(); 61 } else { 62 return videoPositionLayer.getWayPointBefore(start); 63 } 64 } 65 66 //make sure we don't leave the GPS track 67 private WayPoint getLastGPS() { 68 if (end == null || end.after(videoPositionLayer.getLastWayPoint().getTime())) { 69 return videoPositionLayer.getLastWayPoint(); 70 } else { 71 return videoPositionLayer.getWayPointBefore(end); 72 } 73 } 74 75 private void removeSyncedWayPoints() { 76 List <WayPoint> track = videoPositionLayer.getTrack(); 77 int start = track.indexOf(firstWayPoint); 78 int end = track.indexOf(lastWayPoint); 27 public GPSVideo(File filename, String id, MediaPlayerFactory mediaPlayerFactory) { 28 super(filename, id, mediaPlayerFactory); 29 } 30 31 public GPSVideo(Video video) { 32 super(video.filename, video.id, video.mediaPlayerFactory); 33 this.player = video.player; 34 } 35 36 //calculates attributes basing upon the current position 37 public void doSync(VideoPositionLayer layer) { 38 this.videoPositionLayer = layer; 39 if (isSynced()) 40 removeSyncedWayPoints(); 41 syncWayPoint = layer.getCurrentWayPoint(); 42 syncVideoTime = getCurrentTime(); 43 //calc now, to avoid calculations on every click 44 if (syncWayPoint != null) { 45 start = new Date(syncWayPoint.getTime().getTime()-syncVideoTime); 46 end = new Date(start.getTime()+player.getLength()); 47 } else { 48 start = null; 49 end = null; 50 } 51 firstWayPoint = getFirstGPS(); 52 lastWayPoint = getLastGPS(); 53 markSyncedWayPoints(); 54 Main.map.mapView.repaint(); 55 } 56 57 //make sure we don't leave the GPS track 58 private WayPoint getFirstGPS() { 59 if (start == null || start.before(videoPositionLayer.getFirstWayPoint().getTime())) { 60 return videoPositionLayer.getFirstWayPoint(); 61 } else { 62 return videoPositionLayer.getWayPointBefore(start); 63 } 64 } 65 66 //make sure we don't leave the GPS track 67 private WayPoint getLastGPS() { 68 if (end == null || end.after(videoPositionLayer.getLastWayPoint().getTime())) { 69 return videoPositionLayer.getLastWayPoint(); 70 } else { 71 return videoPositionLayer.getWayPointBefore(end); 72 } 73 } 74 75 private void removeSyncedWayPoints() { 76 List<WayPoint> track = videoPositionLayer.getTrack(); 77 int start = track.indexOf(firstWayPoint); 78 int end = track.indexOf(lastWayPoint); 79 79 if (0 <= start && start <= end && end < track.size()) { 80 81 82 80 for (WayPoint n : track.subList(start, end)) { 81 n.attr.keySet().remove(SYNC_KEY); 82 } 83 83 } 84 84 } 85 85 86 87 List<WayPoint> track = videoPositionLayer.getTrack();88 89 90 91 92 93 94 95 86 private void markSyncedWayPoints() { 87 List<WayPoint> track = videoPositionLayer.getTrack(); 88 int start = track.indexOf(firstWayPoint); 89 int end = track.indexOf(lastWayPoint); 90 if (0 <= start && start <= end && end < track.size()) { 91 for (WayPoint n : track.subList(start, end)) { 92 n.attr.put(SYNC_KEY, id); 93 } 94 } 95 } 96 96 97 98 99 97 public boolean isSynced() { 98 return syncWayPoint != null; 99 } 100 100 101 //if synced jump in video to this GPS timecode 102 103 if((GPSTime.after(firstWayPoint.getTime())&(GPSTime.before(lastWayPoint.getTime())))) {104 105 106 107 108 109 110 111 112 113 114 115 116 117 101 //if synced jump in video to this GPS timecode 102 public void jumpTo(Date GPSTime) { 103 if ((GPSTime.after(firstWayPoint.getTime()) & (GPSTime.before(lastWayPoint.getTime())))) { 104 long diff = GPSTime.getTime()-start.getTime(); 105 player.setTime(diff); 106 System.out.println(diff); 107 } 108 } 109 110 public WayPoint getCurrentWayPoint() { 111 if (isSynced()) { 112 long videotime = player.getTime(); 113 Date gpstime = new Date(start.getTime()+videotime); 114 return videoPositionLayer.interpolate(gpstime); 115 } 116 return null; 117 } 118 118 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/GPSVideoPlayer.java
r32513 r32630 20 20 //extends video playback, major control has the video player 21 21 public class GPSVideoPlayer extends VideoPlayer { 22 23 22 private List<GPSVideo> videos; 23 private VideoPositionLayer videoPositionLayer; 24 24 25 public GPSVideoPlayer(DateFormat videoTimeFormat,VideoPositionLayer videoPositionLayer) throws HeadlessException {26 27 28 this.videoPositionLayer=videoPositionLayer;29 30 25 public GPSVideoPlayer(DateFormat videoTimeFormat, VideoPositionLayer videoPositionLayer) throws HeadlessException { 26 super(videoTimeFormat); 27 videos = new LinkedList<>(); 28 this.videoPositionLayer = videoPositionLayer; 29 videoPositionLayer.setGPSVideoPlayer(this); 30 } 31 31 32 public GPSVideo addVideo(File videofile) { 33 GPSVideo video = new GPSVideo(super.addVideo(videofile,Integer.toString(videos.size())));34 35 36 37 38 32 public GPSVideo addVideo(File videofile) { 33 GPSVideo video = new GPSVideo(super.addVideo(videofile, Integer.toString(videos.size()))); 34 enableSingleVideoMode(true); 35 videos.add(video); 36 addSyncButton(video); 37 return video; 38 } 39 39 40 41 JButton syncButton= new JButton(tr("Sync"));42 syncButton.setBackground(Color.RED); 43 40 private void addSyncButton(GPSVideo video) { 41 JButton syncButton = new JButton(tr("Sync")); 42 syncButton.setBackground(Color.RED); 43 syncButton.addActionListener(new ActionListener() { 44 44 @Override 45 45 public void actionPerformed(ActionEvent e) { 46 47 } 48 49 video.SyncComponent=syncButton;50 51 52 } 46 resync(e); 47 } 48 }); 49 video.SyncComponent = syncButton; 50 //video.panel.add(syncButton,BorderLayout.SOUTH); 51 controlsPanel.add(syncButton); 52 } 53 53 54 //do a (re)sync 55 private void resync(ActionEvent e) { 56 JButton btn =(JButton)e.getSource(); 57 GPSVideo v=findVideo(btn); 58 v.doSync(videoPositionLayer); 59 btn.setBackground(Color.GREEN); 60 enableSingleVideoMode(false); 61 } 62 63 protected GPSVideo findVideo(JButton source) { 64 for (GPSVideo v : videos) { 65 if (v.SyncComponent==source) return v; 66 } 67 return null; 68 } 69 70 //jump in all videos this date, if possible 71 public void jumpTo(Date date) { 72 for (GPSVideo video : videos) { 73 video.jumpTo(date); 74 } 75 } 76 77 public boolean areAllVideosSynced() { 78 for (GPSVideo video : videos) { 79 if (!video.isSynced()) return false; 80 } 81 return true; 82 } 54 //do a (re)sync 55 private void resync(ActionEvent e) { 56 JButton btn = (JButton) e.getSource(); 57 GPSVideo v = findVideo(btn); 58 v.doSync(videoPositionLayer); 59 btn.setBackground(Color.GREEN); 60 enableSingleVideoMode(false); 61 } 83 62 84 @Override 85 public void update_plays() { 86 super.update_plays(); 87 if (areAllVideosSynced()) 88 videoPositionLayer.setIconPosition( videos.get(0).getCurrentWayPoint()); 89 } 90 91 @Override 92 public void windowClosing(WindowEvent arg0) { 93 videoPositionLayer.unload(); 94 super.windowClosing(arg0); 95 } 63 protected GPSVideo findVideo(JButton source) { 64 for (GPSVideo v : videos) { 65 if (v.SyncComponent == source) return v; 66 } 67 return null; 68 } 69 70 //jump in all videos this date, if possible 71 public void jumpTo(Date date) { 72 for (GPSVideo video : videos) { 73 video.jumpTo(date); 74 } 75 } 76 77 public boolean areAllVideosSynced() { 78 for (GPSVideo video : videos) { 79 if (!video.isSynced()) return false; 80 } 81 return true; 82 } 83 84 @Override 85 public void update_plays() { 86 super.update_plays(); 87 if (areAllVideosSynced()) 88 videoPositionLayer.setIconPosition(videos.get(0).getCurrentWayPoint()); 89 } 90 91 @Override 92 public void windowClosing(WindowEvent arg0) { 93 videoPositionLayer.unload(); 94 super.windowClosing(arg0); 95 } 96 96 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/Video.java
r32513 r32630 15 15 //basic informations about one single video playback instance 16 16 public class Video { 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 17 public final File filename; 18 public final String id; //unique id to make it easy to identify 19 public MediaPlayer player; 20 public Canvas canvas; 21 public CanvasVideoSurface videoSurface; 22 public final JPanel panel; 23 public final MediaPlayerFactory mediaPlayerFactory; 24 25 public Video(File filename, String id, MediaPlayerFactory mediaPlayerFactory) { 26 this.filename = filename; 27 this.id = id; 28 this.mediaPlayerFactory = mediaPlayerFactory; 29 this.canvas = new Canvas(); 30 this.videoSurface = mediaPlayerFactory.newVideoSurface(canvas); 31 this.panel = new JPanel(); 32 this.panel.setLayout(new FlowLayout()); 33 this.panel.add(videoSurface.canvas(), BorderLayout.CENTER); 34 } 35 36 public long getCurrentTime() { 37 return player.getTime(); 38 } 39 39 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/VideoEngine.java
r32513 r32630 9 9 10 10 import org.openstreetmap.josm.Main; 11 12 import com.sun.jna.NativeLibrary; 13 import com.sun.jna.platform.win32.Advapi32Util; 14 import com.sun.jna.platform.win32.WinReg; 11 15 12 16 import uk.co.caprica.vlcj.binding.internal.libvlc_media_t; … … 21 25 import uk.co.caprica.vlcj.runtime.windows.WindowsRuntimeUtil; 22 26 23 import com.sun.jna.NativeLibrary;24 import com.sun.jna.platform.win32.Advapi32Util;25 import com.sun.jna.platform.win32.WinReg;26 27 27 //concrete Player library that is able to playback multiple videos 28 28 public class VideoEngine implements MediaPlayerEventListener { 29 30 31 32 33 29 private FullScreenStrategy fullScreenStrategy; 30 public MediaPlayerFactory mediaPlayerFactory; 31 private List<Video> videos; 32 private List<VideosObserver> observers; 33 private final String[] libvlcArgs = {""}; 34 34 private final String[] standardMediaOptions = {""}; 35 private final static String[] deinterlacers = {"bob","linear"};35 private static final String[] deinterlacers = {"bob", "linear"}; 36 36 //private final float initialCanvasFactor = 0.5f; 37 private boolean singleVideoMode; //commands will only affect the last added video 38 private Video lastAddedVideo; 39 40 //called at plugin start to setup library 41 public static void setupPlayer() { 42 String vlcInstallDir = null; 43 44 if (RuntimeUtil.isWindows()) { 45 vlcInstallDir = WindowsRuntimeUtil.getVlcInstallDir(); 46 String arch = System.getProperty("os.arch"); 47 if (vlcInstallDir == null && arch.equals("amd64")) { 48 try { 49 vlcInstallDir = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, 50 WindowsRuntimeUtil.VLC_REGISTRY_KEY.replaceFirst("\\\\", "\\\\Wow6432Node\\\\"), 51 WindowsRuntimeUtil.VLC_INSTALL_DIR_KEY); 52 } catch (RuntimeException e) { 53 Main.error(e); 54 } 55 } 56 } else if (RuntimeUtil.isMac()) { 57 // TODO 58 } else if (RuntimeUtil.isNix()) { 37 private boolean singleVideoMode; //commands will only affect the last added video 38 private Video lastAddedVideo; 39 40 //called at plugin start to setup library 41 public static void setupPlayer() { 42 String vlcInstallDir = null; 43 44 if (RuntimeUtil.isWindows()) { 45 vlcInstallDir = WindowsRuntimeUtil.getVlcInstallDir(); 46 String arch = System.getProperty("os.arch"); 47 if (vlcInstallDir == null && arch.equals("amd64")) { 48 try { 49 vlcInstallDir = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, 50 WindowsRuntimeUtil.VLC_REGISTRY_KEY.replaceFirst("\\\\", "\\\\Wow6432Node\\\\"), 51 WindowsRuntimeUtil.VLC_INSTALL_DIR_KEY); 52 } catch (RuntimeException e) { 53 Main.error(e); 54 } 55 } 56 } else if (RuntimeUtil.isMac()) { 59 57 // TODO 60 } 58 } else if (RuntimeUtil.isNix()) { 59 // TODO 60 } 61 61 62 62 if (vlcInstallDir != null) { … … 66 66 Main.error("videomapping: unable to locate VLC install dir"); 67 67 } 68 69 70 71 System.setProperty("logj4.configuration","file:log4j.xml"); //TODO still unsure if we can't link this to the JOSM log4j instance72 73 74 75 76 77 78 68 } 69 70 public VideoEngine(Window parent) { 71 System.setProperty("logj4.configuration", "file:log4j.xml"); //TODO still unsure if we can't link this to the JOSM log4j instance 72 videos = new LinkedList<>(); 73 observers = new LinkedList<>(); 74 try { 75 mediaPlayerFactory = new MediaPlayerFactory(libvlcArgs); 76 fullScreenStrategy = new DefaultFullScreenStrategy(parent); 77 } catch (NoClassDefFoundError e) { 78 Main.error(tr("Unable to find JNA Java library!")); 79 79 } catch (UnsatisfiedLinkError e) { 80 80 Main.error(tr("Unable to find native libvlc library!")); … … 82 82 Main.error(t); 83 83 } 84 85 86 87 88 89 video.player=mp;90 91 92 lastAddedVideo=video;93 94 95 96 97 98 99 84 } 85 86 public void add(Video video) { 87 try { 88 EmbeddedMediaPlayer mp = mediaPlayerFactory.newEmbeddedMediaPlayer(fullScreenStrategy); 89 video.player = mp; 90 mp.setStandardMediaOptions(standardMediaOptions); 91 videos.add(video); 92 lastAddedVideo = video; 93 mp.setVideoSurface(video.videoSurface); 94 mp.addMediaPlayerEventListener(this); 95 String mediaPath = video.filename.getAbsoluteFile().toString(); 96 mp.playMedia(mediaPath); 97 //now fetching and playback starts automatically 98 } catch (NoClassDefFoundError e) { 99 Main.error(tr("Unable to find JNA Java library!")); 100 100 } catch (UnsatisfiedLinkError e) { 101 101 Main.error(tr("Unable to find native libvlc library!")); 102 102 } 103 } 104 /* 105 private Video getVideo(MediaPlayer mp) 106 { 107 for (Video video : videos) { 108 if (video.player==mp) return video; 109 } 110 return null; 111 } 103 } 104 105 /* 106 private Video getVideo(MediaPlayer mp) 107 { 108 for (Video video : videos) { 109 if (video.player==mp) return video; 110 } 111 return null; 112 } 112 113 */ 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 long start=lastAddedVideo.player.getTime();150 151 152 153 long start=video.player.getTime();154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 if (video.player.getSpuCount()>0) return true;214 215 216 217 218 public void setSubtitles(boolean enabled) {219 220 221 222 223 224 225 226 227 228 229 230 231 public void setDeinterlacer(DeinterlaceMode deinterlacer) {232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 video.player=null;259 video.videoSurface=null;260 video.canvas=null;261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 @Override 276 114 public List<Video> getVideos() { 115 return videos; 116 } 117 118 public void play() { 119 if (singleVideoMode) { 120 lastAddedVideo.player.play(); 121 } else { 122 for (Video video : videos) { 123 video.player.play(); 124 } 125 } 126 } 127 128 //toggles pause and play 129 public void pause() { 130 if (singleVideoMode) { 131 lastAddedVideo.player.pause(); 132 } else { 133 for (Video video : videos) { 134 video.player.pause(); 135 } 136 } 137 } 138 139 //ensures that all stop 140 public void pauseAll() { 141 for (Video video : videos) { 142 if (video.player.isPlaying()) 143 video.player.pause(); 144 } 145 } 146 147 //jumps relative for ms in all videos 148 public void jumpFor(long ms) { 149 if (singleVideoMode) { 150 long start = lastAddedVideo.player.getTime(); 151 lastAddedVideo.player.setTime(start+ms); 152 } else { 153 for (Video video : videos) { 154 long start = video.player.getTime(); 155 video.player.setTime(start+ms); 156 } 157 } 158 notifyObservers(VideoObserversEvents.jumping); 159 } 160 161 //jumps in all videos to this absolute video time 162 public void jumpTo(long msVideo) { 163 if (singleVideoMode) { 164 lastAddedVideo.player.setTime(msVideo); 165 } else { 166 for (Video video : videos) { 167 video.player.setTime(msVideo); 168 } 169 } 170 notifyObservers(VideoObserversEvents.jumping); 171 } 172 173 //TODO muss evtl. auf Rückgabe für alle Videos erweitert werden 174 public long getVideoTime() { 175 return videos.get(0).player.getTime(); 176 } 177 178 //jumps in all videos to this absolute video time percentage 179 public void jumpToPosition(int percent) { 180 float position = (percent/100f); 181 if (singleVideoMode) { 182 lastAddedVideo.player.setPosition(position); 183 } else { 184 for (Video video : videos) { 185 video.player.setPosition(position); 186 } 187 } 188 notifyObservers(VideoObserversEvents.jumping); 189 } 190 191 //TODO muss evtl. auf Rückgabe für alle Videos erweitert werden 192 public int getPosition() { 193 return (int) (videos.get(0).player.getPosition()*100); 194 } 195 196 public void setSpeed(int percent) { 197 if (singleVideoMode) { 198 lastAddedVideo.player.setRate(percent/100f); 199 } 200 for (Video video : videos) { 201 video.player.setRate(percent/100f); 202 } 203 notifyObservers(VideoObserversEvents.speeding); 204 } 205 206 //TODO muss evtl. auf Rückgabe für alle Videos erweitert werden 207 public int getSpeed() { 208 return (int) (videos.get(0).player.getRate()*100); 209 } 210 211 //returns if at least one video has subtitles 212 public boolean hasSubtitles() { 213 for (Video video : videos) { 214 if (video.player.getSpuCount() > 0) return true; 215 } 216 return false; 217 } 218 219 public void setSubtitles(boolean enabled) { 220 if (enabled) { 221 //VLC uses a list of sub picture units 222 for (Video video : videos) { 223 video.player.setSpu(0); 224 } 225 } else { 226 for (Video video : videos) { 227 video.player.setSpu(-1); 228 } 229 } 230 } 231 232 public void setDeinterlacer(DeinterlaceMode deinterlacer) { 233 if (singleVideoMode) { 234 lastAddedVideo.player.setDeinterlace(deinterlacer); 235 } else { 236 for (Video video : videos) { 237 video.player.setDeinterlace(deinterlacer); 238 } 239 } 240 } 241 242 public static String[] getDeinterlacers() { 243 return deinterlacers; 244 } 245 246 public void mute() { 247 if (singleVideoMode) { 248 lastAddedVideo.player.mute(); 249 } 250 for (Video video : videos) { 251 video.player.mute(); 252 } 253 } 254 255 public void unload() { 256 for (Video video : videos) { 257 video.player.stop(); 258 video.player.release(); 259 video.player = null; 260 video.videoSurface = null; 261 video.canvas = null; 262 } 263 mediaPlayerFactory.release(); 264 } 265 266 public void addObserver(VideosObserver observer) { 267 observers.add(observer); 268 } 269 270 private void notifyObservers(VideoObserversEvents event) { 271 for (VideosObserver observer : observers) { 272 observer.update(event); 273 } 274 } 275 276 @Override 277 public void backward(MediaPlayer arg0) { } 277 278 /* 278 279 280 279 public void buffering(MediaPlayer arg0) { 280 281 } 281 282 */ 282 283 @Override 283 284 285 @Override 286 287 288 @Override 289 290 291 @Override 292 284 public void error(MediaPlayer arg0) { } 285 286 @Override 287 public void finished(MediaPlayer arg0) { } 288 289 @Override 290 public void forward(MediaPlayer arg0) { } 291 292 @Override 293 public void lengthChanged(MediaPlayer arg0, long arg1) { } 293 294 /* 294 295 296 297 298 299 300 301 302 295 public void mediaChanged(MediaPlayer arg0) { 296 297 } 298 299 public void metaDataAvailable(MediaPlayer mp, VideoMetaData data) { 300 Dimension org=data.getVideoDimension(); 301 getVideo(mp).canvas.setSize(new Dimension((int)(org.width*initialCanvasFactor), (int)(org.height*initialCanvasFactor))); 302 notifyObservers(VideoObserversEvents.resizing); 303 } 303 304 */ 304 305 @Override 305 public void opening(MediaPlayer arg0) {}306 307 @Override 308 309 310 @Override 311 312 313 @Override 314 315 316 @Override 317 318 319 @Override 320 321 322 @Override 323 324 325 @Override 326 327 328 @Override 329 330 331 @Override 332 333 334 335 336 337 338 339 340 341 342 343 344 306 public void opening(MediaPlayer arg0) { } 307 308 @Override 309 public void pausableChanged(MediaPlayer arg0, int arg1) { } 310 311 @Override 312 public void paused(MediaPlayer arg0) { } 313 314 @Override 315 public void playing(MediaPlayer arg0) { } 316 317 @Override 318 public void positionChanged(MediaPlayer arg0, float arg1) { } 319 320 @Override 321 public void seekableChanged(MediaPlayer arg0, int arg1) { } 322 323 @Override 324 public void snapshotTaken(MediaPlayer arg0, String arg1) { } 325 326 @Override 327 public void stopped(MediaPlayer arg0) { } 328 329 @Override 330 public void timeChanged(MediaPlayer arg0, long arg1) { } 331 332 @Override 333 public void titleChanged(MediaPlayer arg0, int arg1) { } 334 335 public boolean isNoVideoPlaying() { 336 for (Video video : videos) { 337 if (video.player.isPlaying()) 338 return false; 339 } 340 return true; 341 } 342 343 public void enableSingleVideoMode(boolean enabled) { 344 singleVideoMode = true; 345 } 345 346 346 347 @Override … … 429 430 } 430 431 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 432 @Override 433 public void corked(MediaPlayer mediaPlayer, boolean corked) { 434 // TODO Auto-generated method stub 435 436 } 437 438 @Override 439 public void muted(MediaPlayer mediaPlayer, boolean muted) { 440 // TODO Auto-generated method stub 441 442 } 443 444 @Override 445 public void volumeChanged(MediaPlayer mediaPlayer, float volume) { 446 // TODO Auto-generated method stub 447 448 } 449 450 @Override 451 public void audioDeviceChanged(MediaPlayer mediaPlayer, String audioDevice) { 452 // TODO Auto-generated method stub 453 454 } 455 456 @Override 457 public void chapterChanged(MediaPlayer mediaPlayer, int newChapter) { 458 // TODO Auto-generated method stub 459 460 } 461 462 @Override 463 public void mediaSubItemTreeAdded(MediaPlayer mediaPlayer, libvlc_media_t item) { 464 // TODO Auto-generated method stub 465 466 } 466 467 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/VideoObserversEvents.java
r32513 r32630 4 4 //basic categories of what might be interesting for a single video 5 5 public enum VideoObserversEvents { 6 7 8 6 resizing, 7 speeding, 8 jumping 9 9 10 10 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/VideoPlayer.java
r32513 r32630 37 37 public class VideoPlayer extends JFrame implements WindowListener, VideosObserver, VideoPlayerObserver { 38 38 private static final int notificationIntervall = 500; 39 protected JPanel screenPanel, controlsPanel,canvasPanel;39 protected JPanel screenPanel, controlsPanel, canvasPanel; 40 40 private JSlider timeline; 41 private JButton play, back,forward;42 private JToggleButton loop, mute;41 private JButton play, back, forward; 42 private JToggleButton loop, mute; 43 43 private JSlider speed; 44 44 // private DateFormat videoTimeFormat; … … 50 50 private Timer notificationTimer; 51 51 private List<VideoPlayerObserver> observers; 52 52 53 53 public VideoPlayer(DateFormat videoTimeFormat) throws HeadlessException { 54 super(); 54 super(); 55 55 // this.videoTimeFormat=videoTimeFormat; 56 56 //setup playback notifications 57 videoengine =new VideoEngine(this);57 videoengine = new VideoEngine(this); 58 58 videoengine.addObserver(this); 59 observers =new LinkedList<>();59 observers = new LinkedList<>(); 60 60 addObserver(this); 61 61 //setup GUI … … 64 64 createUI(); 65 65 addUI(); 66 addUIListeners(); 66 addUIListeners(); 67 67 setVisible(true); 68 setAlwaysOnTop(true); 68 setAlwaysOnTop(true); 69 69 this.addWindowListener(this); 70 70 } 71 71 72 72 public Video addVideo(File videofile, String id) { 73 Video video = new Video(videofile, id,videoengine.mediaPlayerFactory);73 Video video = new Video(videofile, id, videoengine.mediaPlayerFactory); 74 74 canvasPanel.add(video.panel); 75 75 video.canvas.setSize(new Dimension(300, 300)); // will be updated by the video engine itself … … 79 79 return video; 80 80 } 81 82 public List 81 82 public List<Video> getVideos() { 83 83 return videoengine.getVideos(); 84 84 } 85 85 86 86 public void pause() { 87 87 videoengine.pause(); … … 91 91 startNotificationTimer(); 92 92 } 93 93 94 94 public void pauseAll() { 95 95 stopNotificationTimer(); … … 98 98 99 99 public void backward() { 100 videoengine.jumpFor(-jumpLength); 100 videoengine.jumpFor(-jumpLength); 101 101 } 102 102 103 103 public void forward() { 104 videoengine.jumpFor(jumpLength); 104 videoengine.jumpFor(jumpLength); 105 105 } 106 106 107 107 public void setSpeed(Integer percent) { 108 speed.setValue(percent); 109 } 110 108 speed.setValue(percent); 109 } 110 111 111 public Integer getSpeed() { 112 112 return speed.getValue(); 113 113 } 114 114 115 115 public void setDeinterlacer(DeinterlaceMode deinterlacer) { 116 116 videoengine.setDeinterlacer(deinterlacer); 117 117 } 118 118 119 119 public void setSubtitles(boolean enabled) { 120 120 videoengine.setSubtitles(enabled); … … 127 127 //TODO auf mehrere Videos umstellen 128 128 public void toggleLooping() { 129 if (loopingTimer ==null) {129 if (loopingTimer == null) { 130 130 //do reset after loop time experienced 131 final long videoResetTime = (long)videoengine.getVideoTime()-loopLength/2;132 TimerTask reset = new TimerTask() { 131 final long videoResetTime = videoengine.getVideoTime()-loopLength/2; 132 TimerTask reset = new TimerTask() { 133 133 @Override 134 134 public void run() { … … 136 136 } 137 137 }; 138 loopingTimer = new Timer();139 loopingTimer.schedule(reset, loopLength/2,loopLength);138 loopingTimer = new Timer(); 139 loopingTimer.schedule(reset, loopLength/2, loopLength); 140 140 } else { 141 141 loopingTimer.cancel(); 142 loopingTimer =null;142 loopingTimer = null; 143 143 } 144 144 } … … 147 147 private void createUI() { 148 148 //setIconImage(); 149 timeline = new JSlider(0, 100,0);149 timeline = new JSlider(0, 100, 0); 150 150 timeline.setMajorTickSpacing(5); 151 151 timeline.setMinorTickSpacing(1); 152 152 timeline.setPaintTicks(true); 153 play = new JButton(tr("play"));154 back = new JButton("<");155 forward = new JButton(">");156 loop = new JToggleButton(tr("loop"));157 mute = new JToggleButton(tr("mute"));158 speed = new JSlider(0, 200,100);153 play = new JButton(tr("play")); 154 back = new JButton("<"); 155 forward = new JButton(">"); 156 loop = new JToggleButton(tr("loop")); 157 mute = new JToggleButton(tr("mute")); 158 speed = new JSlider(0, 200, 100); 159 159 speed.setMajorTickSpacing(50); 160 speed.setPaintTicks(true); 160 speed.setPaintTicks(true); 161 161 speed.setOrientation(Adjustable.VERTICAL); 162 162 Hashtable<Integer, JLabel> labelTable = new Hashtable<>(); 163 labelTable.put( new Integer( 100 ), new JLabel("1x"));164 labelTable.put( new Integer( 50 ), new JLabel("-2x"));165 labelTable.put( new Integer( 200 ), new JLabel("2x"));166 speed.setLabelTable( labelTable);163 labelTable.put(new Integer(100), new JLabel("1x")); 164 labelTable.put(new Integer(50), new JLabel("-2x")); 165 labelTable.put(new Integer(200), new JLabel("2x")); 166 speed.setLabelTable(labelTable); 167 167 speed.setPaintLabels(true); 168 168 } 169 169 170 170 //puts all player controls to screen 171 171 private void addUI() { 172 172 //create layouts 173 173 this.setLayout(new BorderLayout()); 174 screenPanel =new JPanel();174 screenPanel = new JPanel(); 175 175 screenPanel.setLayout(new BorderLayout()); 176 controlsPanel =new JPanel();176 controlsPanel = new JPanel(); 177 177 controlsPanel.setLayout(new FlowLayout()); 178 canvasPanel =new JPanel();178 canvasPanel = new JPanel(); 179 179 canvasPanel.setLayout(new FlowLayout()); 180 add(screenPanel, BorderLayout.CENTER);181 add(controlsPanel, BorderLayout.SOUTH);180 add(screenPanel, BorderLayout.CENTER); 181 add(controlsPanel, BorderLayout.SOUTH); 182 182 //fill screen panel 183 screenPanel.add(canvasPanel, BorderLayout.CENTER);184 screenPanel.add(timeline, BorderLayout.SOUTH);185 screenPanel.add(speed, BorderLayout.EAST);183 screenPanel.add(canvasPanel, BorderLayout.CENTER); 184 screenPanel.add(timeline, BorderLayout.SOUTH); 185 screenPanel.add(speed, BorderLayout.EAST); 186 186 controlsPanel.add(play); 187 187 controlsPanel.add(back); … … 192 192 mute.setSelected(false); 193 193 } 194 194 195 195 //add UI functionality 196 private void addUIListeners() { 197 198 play.addActionListener(new ActionListener() { 199 @Override 200 public void actionPerformed(ActionEvent arg0) { 201 pause(); 202 } 203 }); 204 196 private void addUIListeners() { 197 198 play.addActionListener(new ActionListener() { 199 @Override 200 public void actionPerformed(ActionEvent arg0) { 201 pause(); 202 } 203 }); 204 205 205 back.addActionListener(new ActionListener() { 206 206 @Override … … 209 209 } 210 210 }); 211 211 212 212 forward.addActionListener(new ActionListener() { 213 213 @Override … … 216 216 } 217 217 }); 218 218 219 219 loop.addActionListener(new ActionListener() { 220 220 @Override … … 223 223 } 224 224 }); 225 225 226 226 mute.addActionListener(new ActionListener() { 227 227 @Override … … 230 230 } 231 231 }); 232 232 233 233 timeline.addChangeListener(new ChangeListener() { 234 234 @Override 235 235 public void stateChanged(ChangeEvent e) { 236 //skip events, fired by this sliede, one cycle ago 236 //skip events, fired by this sliede, one cycle ago 237 237 if (!isManualJump) { 238 238 isManualJump = true; … … 241 241 } 242 242 }); 243 244 speed.addChangeListener(new ChangeListener() { 245 @Override 246 public void stateChanged(ChangeEvent arg0) { 247 if (!speed.getValueIsAdjusting()) {243 244 speed.addChangeListener(new ChangeListener() { 245 @Override 246 public void stateChanged(ChangeEvent arg0) { 247 if (!speed.getValueIsAdjusting()) { 248 248 videoengine.setSpeed(speed.getValue()); 249 249 } … … 251 251 }); 252 252 } 253 253 254 254 public void setJumpLength(long ms) { 255 255 jumpLength = ms; 256 256 } 257 257 258 258 public void setLoopLength(long ms) { 259 259 loopLength = ms; 260 260 } 261 261 262 262 public void enableSingleVideoMode(boolean enabled) { 263 263 pauseAll(); 264 264 videoengine.enableSingleVideoMode(enabled); 265 265 } 266 266 267 267 public void addObserver(VideoPlayerObserver observer) { 268 268 observers.add(observer); 269 269 } 270 270 271 271 private void stopNotificationTimer() { 272 272 /* … … 280 280 281 281 private void startNotificationTimer() { 282 notificationTimer = new Timer();283 notificationTimer.schedule(new TimerTask() { 282 notificationTimer = new Timer(); 283 notificationTimer.schedule(new TimerTask() { 284 284 @Override 285 285 public void run() { 286 286 notifyObservers(); 287 288 } 289 }, notificationIntervall,notificationIntervall);290 } 291 292 private void 287 288 } 289 }, notificationIntervall, notificationIntervall); 290 } 291 292 private void notifyObservers() { 293 293 for (VideoPlayerObserver observer : observers) { 294 observer.update_plays(); //TODO hier müssten gleich die Zeiten übergeben werden294 observer.update_plays(); // TODO hier müssten gleich die Zeiten übergeben werden 295 295 } 296 296 } … … 303 303 304 304 @Override 305 public void windowClosing(WindowEvent arg0) { 305 public void windowClosing(WindowEvent arg0) { 306 306 videoengine.unload(); 307 307 } … … 321 321 @Override 322 322 public void update(VideoObserversEvents event) { 323 switch (event) 324 { 323 switch (event) { 325 324 case resizing: 326 325 { … … 334 333 } 335 334 case jumping: 336 { 335 { 337 336 break; 338 337 } 339 } 338 } 340 339 } 341 340 … … 352 351 isManualJump = false; 353 352 } 354 353 355 354 public boolean isCorrectlyInitiliazed() { 356 355 return videoengine != null && videoengine.mediaPlayerFactory != null; -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/VideoPlayerObserver.java
r32513 r32630 5 5 */ 6 6 public interface VideoPlayerObserver { 7 publicvoid update_plays();7 void update_plays(); 8 8 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/VideosObserver.java
r32513 r32630 5 5 */ 6 6 public interface VideosObserver { 7 7 void update(VideoObserversEvents event); 8 8 }
Note:
See TracChangeset
for help on using the changeset viewer.