SandBox/Pavel: natives.patch

File natives.patch, 14.2 KB (added by pap, 15 years ago)
  • sophie2-platform/modules/org.sophie2.main.media.natlib/src/test/java/org/sophie2/main/media/natlib/demo/AudioDemo.java

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
     
    1616import javax.swing.SwingUtilities; 
    1717 
    1818import org.sophie2.base.commons.util.ImmImage; 
    19 import org.sophie2.base.commons.util.bindata.RawBinData; 
     19import org.sophie2.base.commons.util.bindata.BinData; 
     20import org.sophie2.base.commons.util.bindata.FileBinData; 
    2021import org.sophie2.base.media.AudioChunk; 
    2122import org.sophie2.base.media.BaseMediaModule; 
    2223import org.sophie2.base.media.MediaComposite; 
     
    4243@SuppressWarnings("serial") 
    4344public class AudioDemo extends Component { 
    4445 
    45         private RawBinData binData; 
     46        private BinData binData; 
    4647        private int time = 0; 
    4748 
    48         private MediaHandler handler; 
     49        private MediaHandler audioHandler; 
     50        private MediaHandler videoHandler; 
    4951        private final MediaInfo info; 
    5052 
    5153        @Override 
    5254        public void paint(Graphics g) { 
    53                 if (this.getHandler().getInfo().getDimensions().getHeight() > 0 
    54                                 && this.getHandler().getInfo().getDimensions().getWidth() > 0) { 
     55                if (this.getVideoHandler().getInfo().getDimensions().getHeight() > 0 
     56                                && this.getVideoHandler().getInfo().getDimensions().getWidth() > 0) { 
    5557                        ImmImage img; 
    5658                        //SophieLog.debug(this.time); 
    5759                        try { 
    58                                 img = this.handler.getFrame(this.time); 
     60                                img = this.videoHandler.getFrame(this.time); 
    5961                        } catch (RuntimeException e) { 
    6062                                img = new ImmImage(new BufferedImage((int) this.info 
    6163                                                .getDimensions().getWidth(),(int) this.info.getDimensions() 
     
    7577         * @throws IOException 
    7678         */ 
    7779        public AudioDemo(String file) throws IOException { 
    78                 this.binData = new RawBinData(new File(file)); 
    79                 this.handler = new NativeMediaHandler(this.binData); 
    80                 this.info = this.getHandler().getInfo(); 
     80                this.binData = FileBinData.create(new File(file)); 
     81                this.audioHandler = new NativeMediaHandler(this.binData); 
     82                this.videoHandler = new NativeMediaHandler(this.binData); 
     83                this.info = this.getAudioHandler().getInfo(); 
    8184        } 
    8285 
    8386        /** 
     
    103106         * the specific media file. 
    104107         */ 
    105108        protected void stop() { 
    106                 this.getHandler().dispose(); 
    107                 this.handler = null; 
     109                this.getAudioHandler().dispose(); 
     110                this.getVideoHandler().dispose(); 
     111                this.audioHandler = null; 
     112                this.videoHandler = null; 
    108113        } 
    109114 
    110115        /** 
     
    120125         *         starts at <tt>millis</tt>. 
    121126         */ 
    122127        protected AudioChunk getAudio(int millis) { 
    123                 AudioChunk audio = this.getHandler().getAudio(millis); 
     128                AudioChunk audio = this.getAudioHandler().getAudio(millis); 
    124129                return audio; 
    125130        } 
    126131 
     
    143148//              String path = "/home/stefan/Desktop/41_30secMP3pro-64.mp3"; 
    144149//              String path = "/home/stefan/Desktop/93613 (copy).mpg"; 
    145150                //String path = "/home/pavel/Desktop/6jfzqz42iz0i2u3jwwx2ax1ts.mov"; 
    146 //              String path = "/home/stefan/media samples/soxmas_s.mov"; 
    147151                //String path = "/home/milo/Desktop/07 - The Mirror.mp3"; 
    148152                // String path = "/home/stefan/11k16bitpcm.wav"; 
    149153                //String path = "/home/stefan/media samples/media samples/41_30secMP3pro-64.wav"; 
     
    162166//              path += "Umbro Commercial.avi"; 
    163167                //audio 
    164168                 
    165                 String path = "/home/stefan/Desktop/Audio/"; 
    166                 path += "Autotamponneuse.ogg"; 
     169                //String path = "/home/stefan/Desktop/Audio/"; 
     170                //path += "Autotamponneuse.ogg"; 
    167171//              path += "Bugs Bunny.wav"; 
    168172//              String path = "/home/stefan/Desktop/tempFile15139tempFile44832tempFile26989tempFile26966CanadaGeese.wav"; 
    169173                 
     174                //String path = "/home/pavel/Desktop/res/carcass - swansong - 03 - blackstar.mp3"; 
     175//              String path = "/home/pavel/Desktop/res/two.divx6.avi"; 
     176//              String path = "/media/other/Music/Marduk/1999 - Panzer Division Marduk/01 - Marduk - Panzer Division Marduk.mp3"; 
     177//              String path = "/home/pavel/Desktop/res/alice in chains - junkhead-singlesreleaseparty.mpg"; 
     178                //String path = "/home/pavel/Desktop/res/02 - Hype! (bonus performances).avi"; 
     179//              String path = "/home/pavel/Desktop/res/8uksomunz336d4ai7414zfhkx.mov"; 
     180//              String path = "/home/pavel/Desktop/res/6jfzqz42iz0i2u3jwwx2ax1ts.mov"; 
     181                String path = "/home/pavel/Desktop/res/ulica_sezam_mana_mana_vbox7.avi"; 
    170182 
    171183                final AudioDemo audioDemo = new AudioDemo(path); 
    172184                final NativeAudioOutput output = new NativeAudioOutput(); 
     
    204216                                        } 
    205217 
    206218                                        int localTime(TimePos time) { 
    207                                                 double d = audioDemo.getHandler().getInfo() 
     219                                                double d = audioDemo.getAudioHandler().getInfo() 
    208220                                                                .getDuration(); 
    209221                                                int hundreds = (int) (d * 100) - 1; 
    210222                                                return (int) (time.getMillis() / 10 % hundreds) * 10; 
     
    224236         *  
    225237         * @return current demo's {@link MediaHandler}. 
    226238         */ 
    227         public MediaHandler getHandler() { 
    228                 return this.handler; 
     239        MediaHandler getVideoHandler() { 
     240                return this.videoHandler; 
    229241        } 
     242 
     243        /** 
     244         * Getter for {@link MediaHandler} that is contained in the demo. 
     245         *  
     246         * @return current demo's {@link MediaHandler}. 
     247         */ 
     248        MediaHandler getAudioHandler() { 
     249                return this.audioHandler; 
     250        } 
     251 
    230252} 
     253 No newline at end of file 
  • sophie2-platform/modules/org.sophie2.main.media.natlib/src/test/java/org/sophie2/main/media/natlib/demo/VideoDemo.java

     
    1313import javax.swing.SwingUtilities; 
    1414 
    1515import org.sophie2.base.commons.util.ImmImage; 
    16 import org.sophie2.base.commons.util.bindata.RawBinData; 
     16import org.sophie2.base.commons.util.bindata.BinData; 
     17import org.sophie2.base.commons.util.bindata.FileBinData; 
    1718import org.sophie2.base.media.MediaHandler; 
    1819import org.sophie2.base.media.MediaInfo; 
    1920import org.sophie2.base.natlib.BaseNatlibModule; 
     
    3536         */ 
    3637        private static final long serialVersionUID = 1L; 
    3738         
    38         private RawBinData binData; 
     39        private BinData binData; 
    3940        private int time = 0; 
    4041 
    4142        private MediaHandler handler; 
     
    5455         * @throws IOException on io error. 
    5556         */ 
    5657        public VideoDemo(String fileToOpen) throws IOException { 
    57                 this.binData = new RawBinData(new File(fileToOpen)); 
     58                this.binData = FileBinData.create(new File(fileToOpen)); 
    5859                this.handler = new NativeMediaHandler(this.binData); 
    5960                this.info = this.handler.getInfo(); 
    6061        } 
  • sophie2-platform/modules/org.sophie2.main.func.media/src/main/java/org/sophie2/main/func/media/MediaImportManager.java

     
    6969                ImportBinDataType importTyppe =  
    7070                        ((Map<File, ImportBinDataType>) additionalData).get(resFile); 
    7171                 
    72                 assert importTyppe != null; 
     72                //assert importTyppe != null; 
    7373                 
     74                if (importTyppe == null) { 
     75                        importTyppe = ImportBinDataType.LINK; 
     76                } 
     77                 
    7478                try { 
    7579                        if (importTyppe == ImportBinDataType.EMBED) { 
    7680                                media = new RawBinData(resFile); 
  • sophie2-platform/modules/org.sophie2.dev/src/main/java/org/sophie2/dev/author/FakeAuthorMain.java

     
    102102                //SophieLog.setMinLevel("org.sophie2.base.model.resources.r4", LogLevel.DEBUG); 
    103103                //SophieLog.setMinLevel("org.sophie2.base.model.resources.r4.access", LogLevel.INFO); 
    104104                //SophieLog.setMinLevel("org.sophie2.main.media", LogLevel.ALL); 
    105                 SophieLog.setMinLevel("org.sophie2.main.media.natlib", LogLevel.NONE); 
    106                 SophieLog.setMinLevel("org.sophie2.base.natlib", LogLevel.NONE); 
     105                //SophieLog.setMinLevel("org.sophie2.main.media.natlib", LogLevel.ALL); 
     106                //SophieLog.setMinLevel("org.sophie2.base.natlib", LogLevel.ALL); 
    107107                //SophieLog.setMinLevel("org.sophie2.main.func.timelines", LogLevel.DEBUG); 
    108108                //SophieLog.setMinLevel("org.sophie2.main.func.media.view", LogLevel.ALL); 
    109109                //SophieLog.setMinLevel("org.sophie2.base.bound", LogLevel.ALL); 
  • sophie2-platform/modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/dialogs/BookPropertiesDialog.java

     
    210210                        if (this.input.getHasLoopedPages()) { 
    211211                                Response response = DialogManager.get().showDialog( 
    212212                                                BINDING_INPUT_WITH_LOOPED_PAGES); 
    213                                 if (response.equals(Response.CANCEL)) { 
     213                                if (Response.CANCEL.equals(response)) { 
    214214                                        getBindAudioToPagesCheck().setSelected(false); 
    215215                                } 
    216216                        } else { 
  • sophie2-platform/modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/book/BookView.java

     
    166166                getPageView(curPage).setTime(newState.getPageTime()); 
    167167        } 
    168168 
    169         private TimePos getPageTime(TimelineOptions pageOptions,  
    170                         TimePos oldPageTime, long distance) { 
     169        private TimePos getPageTime(TimelineOptions pageOptions, TimePos oldPageTime, long distance) { 
    171170                boolean sync = model().get().getSyncAudioToPages(); 
    172171                 
    173172                return sync ? pageOptions.setLooped(false).advance(oldPageTime, distance) : 
  • sophie2-native/src/media_decoder/media_decoder.h

     
    2626static const int CHUNK_BYTES = CHUNK_SAMPLES * 4; 
    2727static const int BUFFER_SIZE = (AVCODEC_MAX_AUDIO_FRAME_SIZE * 6) / 2; 
    2828static const int CHUNK_MILLIS = 10; 
    29 static const int BUFFER_STEP = 10000; //ms 
    30 static const int BUFFER_EXTRA = 2000; //ms 
     29static const int BUFFER_STEP = 1000; //ms 
     30static const int BUFFER_EXTRA = 200; //ms 
    3131static const int BUFFER_LEN = BUFFER_STEP + BUFFER_EXTRA; //ms 
    3232static const int ALLOWED_DIST_MILLIS = 2000; 
    3333 
     
    3636        Decoder() { 
    3737                isOpen = false; 
    3838        } 
     39 
    3940        virtual ~Decoder() { 
    4041                if (isOpen) { 
    4142                        if (videoStream > -1) { 
     
    4445                                av_free(pFrame); 
    4546                                avcodec_close(pVideoCodecCtx); 
    4647                        } 
    47                         if (audioStream > -1) 
     48                        if (audioStream > -1) { 
    4849                                avcodec_close(pAudioCodecCtx); 
     50                        } 
    4951                        av_close_input_file(pFormatContext); 
    5052                        isOpen = false; 
    5153                } 
    5254        } 
     55 
    5356        int seek(int millis, int flags) { 
    5457                assert(isOpen); 
    5558                if (av_seek_frame(pFormatContext, -1, millis * 1000, flags) >= 0) { 
     
    5962                return -1; 
    6063 
    6164        } 
     65 
    6266        int seekStream(int millis, int stream, int flags) { 
    6367                assert(isOpen); 
    6468                int64_t rescaleMillis = rescaleToStream(millis, stream); 
     
    7074                return -1; 
    7175 
    7276        } 
     77 
    7378        int rescaleToStream(int millis, int stream) { 
    7479                int num = pFormatContext->streams[stream]->time_base.num; 
    7580                int den = pFormatContext->streams[stream]->time_base.den; 
    7681                return av_rescale(millis * 1000, den, AV_TIME_BASE * (int64_t) num); 
    7782        } 
     83 
    7884        double rescaleToSeconds(int timeStamp, int stream) { 
    7985                int num = pFormatContext->streams[stream]->time_base.num; 
    8086                int den = pFormatContext->streams[stream]->time_base.den; 
     
    106112                                while (currentTime <= targetTime && av_read_frame(pFormatContext, 
    107113                                                &packet) >= 0) { 
    108114 
     115                                        //DUMP(packet.size); 
     116 
    109117                                        if (first && packet.stream_index == audioStream) { 
    110118                                                double firstSeconds = rescaleToSeconds(packet.pts, 
    111119                                                                audioStream); 
     
    129137                                        } 
    130138                                        if (packet.stream_index == audioStream) { 
    131139 
    132                                                 vector<byte> packetSamples = decodeAudio(packet); 
    133                                                 lastAudioBuffer.insert(lastAudioBuffer.end(), 
    134                                                                 packetSamples.begin(), packetSamples.end()); 
    135                                                 currentTime = packet.pts + packet.duration; 
     140                                                try { 
     141                                                        vector<byte> packetSamples = decodeAudio(packet); 
     142                                                        lastAudioBuffer.insert(lastAudioBuffer.end(), 
     143                                                                        packetSamples.begin(), packetSamples.end()); 
     144                                                        currentTime = packet.pts + packet.duration; 
    136145 
    137                                                 //currentTime += packet.duration; 
    138                                                 packetSamples.clear(); 
     146                                                        //currentTime += packet.duration; 
     147                                                        packetSamples.clear(); 
     148                                                } catch(runtime_error const& ex) { 
     149                                                        cerr << ex.what() << endl; 
     150                                                } 
    139151                                        } 
    140152                                        if (packet.data) { 
    141153                                                av_free_packet(&packet); 
     
    152164 
    153165                        return lastAudioBuffer; 
    154166        } 
     167 
    155168        vector<byte> getAudio(int millis) { 
    156169                assert(isOpen); 
    157170                assert(millis >= 0); 
     
    517530}; 
    518531 
    519532#endif /* MEDIA_MESSAGES_H_ */ 
     533 
  • sophie2-native/Makefile

     
    33 
    44all : main  
    55 
    6 libs : 
    7         cd lib-src && $(MAKE) 
     6#libs : 
     7#       cd lib-src && $(MAKE) 
    88 
    9 include ${ROOT}/qt_env 
     9#include ${ROOT}/qt_env 
    1010 
    1111#the only one for now 
    1212main : libs  
    1313        cd src/media_decoder && $(MAKE) 
    14         cd src/audio_output && $(MAKE) 
    15         cd src/browser_embed && qmake && ${MAKE} -f makefile.${PLATF} 
     14#       cd src/audio_output && $(MAKE) 
     15#       cd src/browser_embed && qmake && ${MAKE} -f makefile.${PLATF} 
    1616 
    1717clean-main: 
    1818        -rm -r $(MAIN_TARGET_ROOT)