root/misc/red5/encoder-pipe-r3603.diff

Revision c88c1e106f88bb7392eaa36fe11844a2b1940d4f, 2.4 kB (checked in by Robin Gareus <robin@…>, 3 years ago)

red5 patch and thusnelda encoder script.

  • Property mode set to 100644
  • src/org/red5/io/flv/impl/FLVWriter.java

     
    2121 
    2222import java.io.File; 
    2323import java.io.FileOutputStream; 
     24import java.io.OutputStream; 
     25import java.nio.ByteBuffer; 
     26import java.lang.Process; 
    2427import java.io.IOException; 
    2528import java.io.RandomAccessFile; 
    2629import java.nio.channels.FileChannel; 
     
    115118         * need direct access to file to append full duration metadata 
    116119         */ 
    117120        private File file; 
     121 
     122        /** 
     123         * custom encoder pipe 
     124         */ 
     125        private Process encoder; 
    118126         
    119127        /** 
    120128         * Creates writer implementation with given file output stream and last tag 
     
    154162                channel = this.fos.getChannel(); 
    155163                out = IoBuffer.allocate(1024); 
    156164                out.setAutoExpand(true);                 
     165                try { 
     166                        // TODO make this configurable 
     167                        // and pass file-name and some meta-info along 
     168                        this.encoder = Runtime.getRuntime().exec(new String[] {"/home/rgareus/data/coding/inoutC2/misc/red5/myenc"}); 
     169                } catch (IOException e) { 
     170                        log.error("IO error on FLVpipe", e); 
     171                }  
    157172        } 
    158173         
    159174        /** 
     
    185200                out.putInt(0); 
    186201 
    187202                out.flip(); 
    188  
     203                 
     204                this.encpipe(out.buf()); 
    189205                channel.write(out.buf()); 
    190206        } 
    191207 
     208        /** 
     209         *  write bytebuffer to encoder pipeline 
     210         */ 
     211        private void encpipe(ByteBuffer bb) { 
     212                ByteBuffer bc = bb.duplicate(); 
     213                byte[] dst= new byte[bc.remaining()]; 
     214                bc.get(dst,0,dst.length); 
     215                try { 
     216                        this.encoder.getOutputStream().write(dst); 
     217                } catch (IOException e) { ; } 
     218        } 
     219 
    192220        /** {@inheritDoc} 
    193221         */ 
    194222        public IStreamableFile getFile() { 
     
    260288                out.putInt(0x00); 
    261289 
    262290                out.flip(); 
     291 
     292                this.encpipe(out.buf()); 
    263293                bytesWritten += channel.write(out.buf()); 
    264294 
    265295                IoBuffer bodyBuf = tag.getBody(); 
     296 
     297                this.encpipe(bodyBuf.buf()); 
    266298                bytesWritten += channel.write(bodyBuf.buf()); 
    267299 
    268300                if (audioCodecId == -1 && tag.getDataType() == ITag.TYPE_AUDIO) { 
     
    280312                out.clear(); 
    281313                out.putInt(tag.getBodySize() + 11); 
    282314                out.flip(); 
     315 
     316                this.encpipe(out.buf()); 
    283317                bytesWritten += channel.write(out.buf()); 
     318                log.debug("written: {}", bytesWritten); 
    284319 
    285320                return false; 
    286321        } 
     
    296331        public void close() { 
    297332                RandomAccessFile appender = null; 
    298333                try { 
     334                        this.encoder.getOutputStream().close();  
    299335                        if (metaPosition > 0) { 
    300336                                long oldPos = channel.position(); 
    301337                                try { 
Note: See TracBrowser for help on using the browser.