Ignore:
Timestamp:
2010-08-19T08:36:56+02:00 (14 years ago)
Author:
guardian
Message:
 
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  
    3636                return next;
    3737        }
     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        }
    3844
    3945        public GpsPlayer(List<WayPoint> l) {
     
    9197        }
    9298       
    93         //wal k waypoints forward/backward
     99        //walk k waypoints forward/backward
    94100        public void jumpRel(int k)
    95101        {
     
    99105                        jump(ls.get(ls.indexOf(curr)+k));
    100106                }
    101                 Main.map.mapView.repaint();
     107                Main.map.mapView.repaint(); //seperate modell and view logic...
    102108        }
    103109       
     
    113119                        Main.map.mapView.repaint();
    114120                }
     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));
    115141        }
    116142       
     
    316342                return p.getTime().getTime()-start.getTime().getTime(); //TODO assumes timeintervall is constant!!!!
    317343        }
    318 
     344       
     345       
    319346        //jumps to a specific time
    320347        public void jump(long relTime) {
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PlayerObserver.java

    r21779 r22690  
    55        void playing(long time);
    66        void jumping(long time);
     7        void metadata(long time,boolean subtitles);
    78
    89}
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PositionLayer.java

    r22550 r22690  
    4343        private SimpleDateFormat mins;
    4444        private SimpleDateFormat ms;
     45        private SimpleDateFormat gpsTimeCode;
    4546        private GPSVideoPlayer gps;
    4647
     
    5253                mins = new SimpleDateFormat("hh:mm:ss:S");
    5354                ms= new SimpleDateFormat("mm:ss");
     55                gpsTimeCode= new SimpleDateFormat("hh:mm:ss");
    5456                Main.map.mapView.addMouseListener(this);
    5557                Main.map.mapView.addMouseMotionListener(this);
     
    109111                //TODO make icon transparent
    110112                //draw all GPS points
    111                 g.setColor(Color.GREEN);
     113                g.setColor(new Color(0,255,0,128));
    112114                for(WayPoint n: ls) {
    113115                        p = Main.map.mapView.getPoint(n.getEastNorth());
     
    115117                }
    116118                //draw synced points
    117                 g.setColor(Color.ORANGE);
     119                g.setColor(Color.GREEN);
    118120                for(WayPoint n: ls) {
    119121                        if(n.attr.containsKey("synced"))
     
    156158                                p=Main.map.mapView.getPoint(iconPosition.getEastNorth());
    157159                                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);
    159162                        }
    160163                }
     
    164167                        p=Main.map.mapView.getPoint(player.getCurr().getEastNorth());
    165168                        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);
    167170                        }
    168171                }
     
    302305        for (PlayerObserver o : observers) {
    303306
    304             o.jumping(newTime);
     307            o.jumping(newTime); //TODO has to become just a single procedure?
    305308
    306309        }
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoMappingPlugin.java

    r21779 r22690  
    66import java.beans.PropertyChangeListener;
    77import java.io.File;
     8import java.sql.Time;
     9import java.text.ParseException;
     10import java.text.SimpleDateFormat;
    811import java.util.Collections;
     12import java.util.Date;
    913import java.util.LinkedList;
    1014import java.util.List;
     
    4852          private GpxData GPSTrack;
    4953          private List<WayPoint> ls;
    50           private JosmAction VAdd,VRemove,VStart,Vbackward,Vforward,Vfaster,Vslower,Vloop;
     54          private JosmAction VAdd,VRemove,VStart,Vbackward,Vforward,VJump,Vfaster,Vslower,Vloop;
    5155          private JRadioButtonMenuItem VIntBob,VIntNone,VIntLinear;
    52           private JCheckBoxMenuItem VCenterIcon;
     56          private JCheckBoxMenuItem VCenterIcon,VSubTitles;
    5357          private JMenuItem VJumpLength,VLoopLength;
    5458          private GPSVideoPlayer player;
    5559          private PositionLayer layer;
    56           private final String VM_DEINTERLACER="videomapping.deinterlacer";
     60          private final String VM_DEINTERLACER="videomapping.deinterlacer"; //where we store settings
    5761          private final String VM_MRU="videomapping.mru";
    5862          private final String VM_AUTOCENTER="videomapping.autocenter";
     
    7478                enableControlMenus(true);
    7579                loadSettings();
    76                 applySettings();               
     80                applySettings();
    7781                //further plugin informations are provided by build.xml properties
    7882        }
     
    115119
    116120                        public void actionPerformed(ActionEvent arg0) {                                 
    117                                         JFileChooser fc = new JFileChooser();
     121                                        JFileChooser fc = new JFileChooser("C:\\TEMP\\");
    118122                                        //fc.setSelectedFile(new File(mru));
    119                                         fc.setSelectedFile(new File("C:\\TEMP"));
    120123                                        if(fc.showOpenDialog(Main.main.parent)!=JFileChooser.CANCEL_OPTION)
    121124                                        {
     
    126129                                                Main.main.addLayer(layer);
    127130                                                player = new GPSVideoPlayer(fc.getSelectedFile(), layer.player);
    128                                                 //TODO Check here if we can sync by hand
     131                                                //TODO Check here if we can sync allready now
    129132                                                layer.setGPSPlayer(player);
    130133                                                layer.addObserver(player);
    131134                                                VAdd.setEnabled(false);
    132135                                                VRemove.setEnabled(true);
     136                                                player.setSubtitleAction(VSubTitles);
    133137                                        }
    134138                                }
     
    142146                        }
    143147                };
     148               
    144149                VStart = new JosmAction(tr("play/pause"), "audio-playpause", tr("starts/pauses video playback"),
    145150                                Shortcut.registerShortcut("videomapping:startstop","",KeyEvent.VK_SPACE, Shortcut.GROUP_DIRECT), false) {
     
    152157                                Shortcut.registerShortcut("videomapping:backward","",KeyEvent.VK_NUMPAD4, Shortcut.GROUP_DIRECT), false) {
    153158                       
     159                        /**
     160                                         *
     161                                         */
     162                                        private static final long serialVersionUID = -1060444361541900464L;
     163
    154164                        public void actionPerformed(ActionEvent e) {
    155165                                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                                }
    156184                                                       
    157185                        }
     
    197225                                applySettings();
    198226                                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();
    199235                                                       
    200236                        }
     
    265301                VMenu.add(VLoopLength);
    266302                VMenu.add(VDeinterlacer);
     303                VMenu.add(VSubTitles);
     304               
    267305        }
    268306       
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/GPSVideoPlayer.java

    r21779 r22690  
    11package org.openstreetmap.josm.plugins.videomapping.video;
    22import java.awt.Color;
     3import java.awt.Component;
    34import java.awt.event.ActionEvent;
    45import java.awt.event.ActionListener;
    56import java.io.File;
     7import java.sql.Time;
     8import java.util.Date;
     9import java.util.List;
    610import java.util.Timer;
    711import java.util.TimerTask;
    812
     13import javax.swing.Action;
    914import javax.swing.JButton;
    10 
     15import javax.swing.JCheckBoxMenuItem;
     16
     17import org.openstreetmap.josm.Main;
    1118import org.openstreetmap.josm.data.gpx.WayPoint;
    1219import org.openstreetmap.josm.plugins.videomapping.GpsPlayer;
     
    2229        private GPSVideoFile file;
    2330        private boolean synced=false; //do we playback the players together?
     31        private JCheckBoxMenuItem subtTitleComponent;
    2432       
    2533
     
    3442                setFile(new GPSVideoFile(f, gpsT-videoT)); */
    3543                setFile(new GPSVideoFile(f, 0L));
    36                 //extend GUI
     44                //add Sync Button to the Player
    3745                syncBtn= new JButton("sync");
    3846                syncBtn.setBackground(Color.RED);
     
    4553                                synced=true;
    4654                                markSyncedPoints();
    47                                 gps.play();
     55                                video.play();
     56                                //gps.play();
    4857                        }
    4958                });
    50                 setSyncMode(true);
     59                setAsyncMode(true);
    5160                video.addComponent(syncBtn);
    52                 //allow sync
    53                 SimpleVideoPlayer.addObserver(new PlayerObserver() {
     61                //a observer to communicate
     62                SimpleVideoPlayer.addObserver(new PlayerObserver() { //TODO has o become this
    5463
    5564                        public void playing(long time) {
    5665                                //sync the GPS back
    57                                 if(synced) gps.jump(getGPSTime(time));
    58                                
     66                                if(synced) gps.jump(getGPSTime(time));                 
    5967                        }
    6068
     
    6270                       
    6371                        }
    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                        }
    6577                       
    6678                });
     
    7082        //marks all points that are covered by video AND GPS track
    7183        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)
    82110        {
    83111                if(b)
     
    97125                file=f;
    98126                video.setFile(f.getAbsoluteFile());
    99                 video.play();
     127                //video.play();
    100128        }
    101129       
     
    119147       
    120148        //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
    121155        public void jumpToGPSTime(long gpsT)
    122156        {
     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                }
    123163                video.jump(getVideoTime(gpsT));
    124164        }
     
    217257        }
    218258
     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
    219281       
    220282}
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/SimpleVideoPlayer.java

    r21779 r22690  
    4040
    4141import 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;
    4542import uk.co.caprica.vlcj.player.MediaPlayer;
    4643import uk.co.caprica.vlcj.player.MediaPlayerEventAdapter;
     
    4845import uk.co.caprica.vlcj.player.MediaPlayerFactory;
    4946import uk.co.caprica.vlcj.player.VideoMetaData;
     47import uk.co.caprica.vlcj.player.embedded.*;
    5048
    5149//basic class of a videoplayer for one video
    5250public class SimpleVideoPlayer extends JFrame implements MediaPlayerEventListener, WindowListener{
    53         private MediaPlayer mp;
     51        private EmbeddedMediaPlayer mp;
    5452        private Timer t;
    5553        private JPanel screenPanel,controlsPanel;
    5654        private JSlider timeline;
    5755        private JButton play,back,forward;
    58         private JToggleButton loop;
     56        private JToggleButton loop,mute;
    5957        private JSlider speed;
    6058        private Canvas scr;
     
    7674                 */
    7775                try
    78                 {                       
     76                {
     77                        //we don't need any options
    7978                        String[] libvlcArgs = {""};
    8079                        String[] standardMediaOptions = {""};
    8180                       
    82                         System.out.println("libvlc version: " + LibVlc.INSTANCE.libvlc_get_version());
     81                        //System.out.println("libvlc version: " + LibVlc.INSTANCE.libvlc_get_version());
    8382                        //setup Media Player
    8483                        //TODO we have to deal with unloading things....
     
    8887                    mp.setStandardMediaOptions(standardMediaOptions);
    8988                    //setup GUI
    90                     setSize(400, 300); //later we resize
     89                    setSize(400, 300); //later we apply movie size
    9190                    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();
    11492                    setLayout();
    115                         addListeners();
     93                        addListeners(); //registering shortcuts is task of the outer plugin class!
    11694                    //embed vlc player
    11795                        scr.setVisible(true);
     
    11997                        mp.setVideoSurface(scr);
    12098                        mp.addMediaPlayerEventListener(this);
    121                         mp.pause();
    122                         jump(0);
    123                         //set updater
     99                        //mp.pause();
     100                        //jump(0);
     101                        //create updater
    124102                        ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
    125103                        executorService.scheduleAtFixedRate(new Syncer(this), 0L, 1000L, TimeUnit.MILLISECONDS);
     
    136114                }
    137115               
     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);
    138142        }
    139143       
     
    155159                controlsPanel.add(forward);
    156160                controlsPanel.add(loop);
     161                controlsPanel.add(mute);
    157162                loop.setSelected(false);
     163                mute.setSelected(false);
    158164        }
    159165
     
    176182                       
    177183                        public void actionPerformed(ActionEvent arg0) {
    178                                 if(mp.isPlaying()) mp.stop(); else mp.play();                           
     184                                if(mp.isPlaying()) mp.pause(); else mp.play();                         
    179185                        }
    180186                });
     
    198204                        public void actionPerformed(ActionEvent arg0) {
    199205                                loop();
     206                        }
     207                });
     208               
     209                mute.addActionListener(new ActionListener() {
     210
     211                        public void actionPerformed(ActionEvent arg0) {
     212                                mute();
    200213                        }
    201214                });
     
    215228                });
    216229               
    217         }
     230        }       
    218231
    219232        public void finished(MediaPlayer arg0) {
     
    230243                scr.setSize(new Dimension((int)(org.width*perc), (int)(org.height*perc)));
    231244                pack();
    232 
     245                //send out metadatas to all observers
     246                for (PlayerObserver o : observers) {
     247            o.metadata(0, hasSubtitles());
     248        }
    233249        }
    234250
     
    277293        {
    278294                String mediaPath = f.getAbsoluteFile().toString();
    279                 mp.playMedia(mediaPath, mediaOptions);         
     295                mp.playMedia(mediaPath, mediaOptions);
    280296                pack();
    281297        }
     
    308324        }
    309325       
    310         //gets called by the Syncer to update all components
     326        //gets called by the Syncer thread to update all observers
    311327        public void updateTime ()
    312328        {
    313329                if(mp.isPlaying())
    314330                {
    315                         setTitle(ms.format(new Date(mp.getTime()))); //FIXME there is a leading hour even at the beginning
     331                        setTitle(ms.format(new Date(mp.getTime())));
    316332                        syncTimeline=true;
    317333                        timeline.setValue(Math.round(mp.getPosition()*100));
     
    369385               
    370386        }
     387       
     388        protected void mute() {
     389                mp.mute();
     390               
     391        }
    371392
    372393        public void forward() {
     
    384405               
    385406        }
     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        }
    386423
    387424        public static void addObserver(PlayerObserver observer) {
     
    402439
    403440                for (PlayerObserver o : observers) {
    404 
    405441                    o.playing(newTime);
    406 
    407442                }
    408443
     
    432467                }
    433468
     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
    434483       
    435484
  • applications/editors/josm/plugins/videomapping/test/videotest.java

    r21656 r22690  
    2626        public static void main(String[] args) {
    2727                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!!!)
    3030                /*
    3131                JButton b = new JButton("jump");
Note: See TracChangeset for help on using the changeset viewer.