Package org.apache.mina.core.buffer

Examples of org.apache.mina.core.buffer.IoBuffer


                throw e;
            }
            tmpBuf.flip();
            final int length = tmpBuf.getInt();
            tmpBuf.rewind();
            IoBuffer ioBuf = IoBuffer.wrap(tmpBuf);
            out.write(ioBuf);
            // attempt zero-copy sendfile
            long position = offset + 4;
            long count = length;
            FileRegion fileRegion = new DefaultFileRegion(fileChannel, position, count);
View Full Code Here


            popSession.reply(session, "+OK " + m.size() + " octets");
            Session mailSess = null;
            ChunkWriter store = new ChunkWriter() {

                public void newChunk(int i, byte[] data) {
                    IoBuffer bb = IoBuffer.wrap(data);
                    session.write(bb);
                }
            };
            ChunkingOutputStream out = new ChunkingOutputStream(store, 1024);
            try {
View Full Code Here

  //    log.debug("width "+width);
  //    log.debug("height "+height);
  //    log.debug("lengthPayload "+lengthPayload);
  //    log.debug("publicSID "+request.getPublicSID());
       
      IoBuffer buffer = IoBuffer.allocate(frameSize, false);
     
      //mode is weather 1(sharing) or 2(recording) or 3(sharing + recording)
      buffer.put(this.convertIntToByteArray(clientFrameBean.getMode()));// 4 Byte
     
      buffer.put(this.convertIntToByteArray(clientFrameBean.getSequenceNumber()));//4 Byte
      buffer.put(this.convertIntToByteArray(lengthSecurityToken));//4 Byte
      buffer.put(this.convertIntToByteArray(clientFrameBean.getXValue()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientFrameBean.getYValue()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientFrameBean.getWidth()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientFrameBean.getHeight()));//4 Byte
      buffer.put(this.convertIntToByteArray(lengthPayload));//4 Byte
      buffer.put(securityTokenAsByte);//32 Byte usually
      buffer.put(clientFrameBean.getImageBytes());
     
  //        IoBuffer buffer = IoBuffer.allocate(12, false);
  //
  //        buffer.putInt(request.getWidth());
  //
  //        buffer.putInt(request.getHeight());
  //
  //        buffer.putInt(request.getNumberOfCharacters());
  //
  //        buffer.flip();
     
      buffer.flip();
     
          out.write(buffer);
       
      } else if (message instanceof ServerStatusBean) {
       
        ServerStatusBean clientStatusBean = (ServerStatusBean) message;
       
        byte[] securityTokenAsByte = clientStatusBean.getPublicSID().getBytes();
       
        Integer lengthSecurityToken = securityTokenAsByte.length;
       
        Integer frameSize = 4 * 10 + lengthSecurityToken;
       
        IoBuffer buffer = IoBuffer.allocate(frameSize, false);
       
        //mode is weather 0(start) or 4(stop)
      buffer.put(this.convertIntToByteArray(clientStatusBean.getMode()));// 4 Byte
      buffer.put(this.convertIntToByteArray(0));//4 Byte
      buffer.put(this.convertIntToByteArray(lengthSecurityToken));//4 Byte
      buffer.put(this.convertIntToByteArray(clientStatusBean.getXValue()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientStatusBean.getYValue()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientStatusBean.getWidth()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientStatusBean.getHeight()));//4 Byte
      buffer.put(this.convertIntToByteArray(0));//4 Byte => this data is not needed
      buffer.put(securityTokenAsByte);//32 Byte usually
      buffer.put(this.convertIntToByteArray(clientStatusBean.getTileWidth()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientStatusBean.getTileHeight()));//4 Byte
     
      buffer.flip();
     
          out.write(buffer);
       
      } else if (message instanceof ServerFrameCursorStatus) {
       
        ServerFrameCursorStatus cursorStatus = (ServerFrameCursorStatus) message;
       
        byte[] securityTokenAsByte = cursorStatus.getPublicSID().getBytes();
       
        Integer lengthSecurityToken = securityTokenAsByte.length;
       
        Integer frameSize = 4 * 8 + lengthSecurityToken;
       
        IoBuffer buffer = IoBuffer.allocate(frameSize, false);
       
        log.debug("######################### 1Send Cursor Bean "+cursorStatus.getMode());
        log.debug("######################### Send Cursor Bean");
        log.debug("######################### Send Cursor Bean");
        log.debug("######################### Send Cursor Bean");
        log.debug("######################### Send Cursor Bean");
        log.debug("######################### Send Cursor Bean");
        log.debug("######################### Send Cursor Bean");
        log.debug("######################### Send Cursor Bean");
        log.debug("######################### Send Cursor Bean");
        log.debug("######################### Send Cursor Bean");
        log.debug("######################### Send Cursor Bean");
        log.debug("######################### 9Send Cursor Bean");
       
        //mode is 6
      buffer.put(this.convertIntToByteArray(cursorStatus.getMode()));// 4 Byte
      buffer.put(this.convertIntToByteArray(cursorStatus.getSequenceNumber()));//4 Byte
      buffer.put(this.convertIntToByteArray(lengthSecurityToken));//4 Byte
      buffer.put(this.convertIntToByteArray(cursorStatus.getX()));//4 Byte
      buffer.put(this.convertIntToByteArray(cursorStatus.getY()));//4 Byte
      buffer.put(this.convertIntToByteArray(0));//4 Byte
      buffer.put(this.convertIntToByteArray(0));//4 Byte
      buffer.put(this.convertIntToByteArray(0));//4 Byte => this data is not needed
      buffer.put(securityTokenAsByte);//32 Byte usually
     
      buffer.flip();
     
          //out.write(buffer);
       
      }

View Full Code Here

  //    log.debug("width "+width);
  //    log.debug("height "+height);
  //    log.debug("lengthPayload "+lengthPayload);
  //    log.debug("publicSID "+request.getPublicSID());
       
      IoBuffer buffer = IoBuffer.allocate(frameSize, false);
     
      //mode is weather 1(sharing) or 2(recording) or 3(sharing + recording)
      buffer.put(this.convertIntToByteArray(clientFrameBean.getMode()));// 4 Byte
     
      buffer.put(this.convertIntToByteArray(clientFrameBean.getSequenceNumber()));//4 Byte
      buffer.put(this.convertIntToByteArray(lengthSecurityToken));//4 Byte
      buffer.put(this.convertIntToByteArray(clientFrameBean.getXValue()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientFrameBean.getYValue()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientFrameBean.getWidth()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientFrameBean.getHeight()));//4 Byte
      buffer.put(this.convertIntToByteArray(lengthPayload));//4 Byte
      buffer.put(securityTokenAsByte);//32 Byte usually
      buffer.put(clientFrameBean.getImageBytes());
     
      log.debug("FRAME SIZE "+ClientCaptureScreen.frameCalculated+"||"+frameSize+"||"+buffer.array().length);
 
  //        IoBuffer buffer = IoBuffer.allocate(12, false);
  //
  //        buffer.putInt(request.getWidth());
  //
  //        buffer.putInt(request.getHeight());
  //
  //        buffer.putInt(request.getNumberOfCharacters());
  //
  //        buffer.flip();
     
      //byte counter
      ClientCaptureScreen.frameCalculated += frameSize;
      if (ClientStartScreen.instance!=null) {
        ClientStartScreen.instance.updateScreen();
      }
     
      buffer.flip();
     
          out.write(buffer);
       
      } else if (message instanceof ClientStatusBean) {
       
        ClientStatusBean clientStatusBean = (ClientStatusBean) message;
       
        byte[] securityTokenAsByte = clientStatusBean.getPublicSID().getBytes();
       
        Integer lengthSecurityToken = securityTokenAsByte.length;
       
        Integer frameSize = 4 * 10 + lengthSecurityToken;
       
        IoBuffer buffer = IoBuffer.allocate(frameSize, false);
       
        //mode is weather 0(start) or 4(stop)
      buffer.put(this.convertIntToByteArray(clientStatusBean.getMode()));// 4 Byte
      buffer.put(this.convertIntToByteArray(ClientConnectionBean.getFrameNumber()));//4 Byte
      buffer.put(this.convertIntToByteArray(lengthSecurityToken));//4 Byte
      buffer.put(this.convertIntToByteArray(clientStatusBean.getXValue()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientStatusBean.getYValue()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientStatusBean.getWidth()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientStatusBean.getHeight()));//4 Byte
      buffer.put(this.convertIntToByteArray(0));//4 Byte => this data is not needed
      buffer.put(securityTokenAsByte);//32 Byte usually
      buffer.put(this.convertIntToByteArray(clientStatusBean.getTileWidth()));//4 Byte
      buffer.put(this.convertIntToByteArray(clientStatusBean.getTileHeight()));//4 Byte
     
        //byte counter
      ClientCaptureScreen.frameCalculated += frameSize;
      if (ClientStartScreen.instance!=null) {
        ClientStartScreen.instance.updateScreen();
      }
     
      buffer.flip();
     
          out.write(buffer);
       
      } else if (message instanceof ClientViewerRegisterBean) {
       
        ClientViewerRegisterBean clientViewerRegisterBean = (ClientViewerRegisterBean) message;
       
       
        byte[] securityTokenAsByte = clientViewerRegisterBean.getPublicSID().getBytes();
       
        Integer lengthSecurityToken = securityTokenAsByte.length;
       
        Integer frameSize = 4 * 8 + lengthSecurityToken;
       
        IoBuffer buffer = IoBuffer.allocate(frameSize, false);
       
        //mode is 5
      buffer.put(this.convertIntToByteArray(clientViewerRegisterBean.getMode()));// 4 Byte
      buffer.put(this.convertIntToByteArray(ClientConnectionBean.getFrameNumber()));//4 Byte
      buffer.put(this.convertIntToByteArray(lengthSecurityToken));//4 Byte
      buffer.put(this.convertIntToByteArray(0));//4 Byte => Empty
      buffer.put(this.convertIntToByteArray(0));//4 Byte => Empty
      buffer.put(this.convertIntToByteArray(0));//4 Byte => Empty
      buffer.put(this.convertIntToByteArray(0));//4 Byte => Empty
      buffer.put(this.convertIntToByteArray(0));//4 Byte => this data is not needed
      buffer.put(securityTokenAsByte);//32 Byte usually
     
      //byte counter
      ClientCaptureScreen.frameCalculated += frameSize;
      if (ClientStartScreen.instance!=null) {
        ClientStartScreen.instance.updateScreen();
      }
     
      buffer.flip();
     
          out.write(buffer);
     
      } else if (message instanceof ClientCursorStatus) {
       
        ClientCursorStatus clientCursorStatus = (ClientCursorStatus) message;
       
        byte[] securityTokenAsByte = clientCursorStatus.getPublicSID().getBytes();
       
        Integer lengthSecurityToken = securityTokenAsByte.length;
       
        Integer frameSize = 4 * 8 + lengthSecurityToken;
       
        IoBuffer buffer = IoBuffer.allocate(frameSize, false);
       
        //mode is 6
      buffer.put(this.convertIntToByteArray(clientCursorStatus.getMode()));// 4 Byte
      buffer.put(this.convertIntToByteArray(ClientConnectionBean.getFrameNumber()));//4 Byte
      buffer.put(this.convertIntToByteArray(lengthSecurityToken));//4 Byte
      buffer.put(this.convertIntToByteArray(clientCursorStatus.getX()));//4 Byte => X-Position
      buffer.put(this.convertIntToByteArray(clientCursorStatus.getY()));//4 Byte => Y-Position
      buffer.put(this.convertIntToByteArray(0));//4 Byte => Empty
      buffer.put(this.convertIntToByteArray(0));//4 Byte => Empty
      buffer.put(this.convertIntToByteArray(0));//4 Byte => this data is not needed
      buffer.put(securityTokenAsByte);//32 Byte usually
     
      //byte counter
      ClientCaptureScreen.frameCalculated += frameSize;
      if (ClientStartScreen.instance!=null) {
        ClientStartScreen.instance.updateScreen();
      }
     
      buffer.flip();
     
          out.write(buffer);
     
      }

View Full Code Here

    out.putInt(0x00);

    out.flip();
    bytesWritten += channel.write(out.buf());

    IoBuffer bodyBuf = tag.getBody();
    bytesWritten += channel.write(bodyBuf.buf());

    if (audioCodecId == -1 && tag.getDataType() == ITag.TYPE_AUDIO) {
      bodyBuf.flip();
      byte id = bodyBuf.get();
      audioCodecId = (id & ITag.MASK_SOUND_FORMAT) >> 4;
    } else if (videoCodecId == -1 && tag.getDataType() == ITag.TYPE_VIDEO) {
      bodyBuf.flip();
      byte id = bodyBuf.get();
      videoCodecId = id & ITag.MASK_VIDEO_CODEC;
    }
    duration = Math.max(duration, tag.getTimestamp() + offset);
    log.debug("Writer duration: {} offset: {}"+ tag.getTimestamp()+ duration+ offset)
    // We add the tag size
View Full Code Here

     * @param audioCodecId    Id of the audio codec used while recording.
     * @throws IOException if the tag could not be written
     */
  private void writeMetadataTag(double duration, Integer videoCodecId, Integer audioCodecId) throws IOException {
    metaPosition = channel.position();
    IoBuffer buf = IoBuffer.allocate(1024);
    buf.setAutoExpand(true);
    Output out = new Output(buf);
    out.writeString("onMetaData");
    Map<Object, Object> params = new HashMap<Object, Object>(4);
    params.put("duration", duration);
    if (videoCodecId != null) {
      params.put("videocodecid", videoCodecId.intValue());
    }
    if (audioCodecId != null) {
      params.put("audiocodecid", audioCodecId.intValue());
    }
    params.put("canSeekToEnd", true);
    out.writeMap(params, new Serializer());
    buf.flip();

    if (fileMetaSize == 0) {
      fileMetaSize = buf.limit();
    }

    ITag onMetaData = new Tag(ITag.TYPE_METADATA, 0, fileMetaSize, buf, 0);
    writeTag(onMetaData);
  }
View Full Code Here

        if (streampacket.getTimestamp() <= 0) {
          log.warn("Negative TimeStamp");
          return;
        }
       
        IoBuffer data = streampacket.getData().asReadOnlyBuffer();
       
        if (data.limit() == 0) {
          return;
        }
       
        this.byteCount += data.limit();
       
        if (startTimeStamp == -1) {
         
          //Calculate the delta between the initial start and the first audio-packet data
         
          this.initialDelta = new Date().getTime() - this.startedSessionTimeDate.getTime();
         
          FlvRecordingMetaDelta flvRecordingMetaDelta = new FlvRecordingMetaDelta();
         
          flvRecordingMetaDelta.setDeltaTime(this.initialDelta);
          flvRecordingMetaDelta.setFlvRecordingMetaDataId(this.flvRecordingMetaDataId);
          flvRecordingMetaDelta.setTimeStamp(0);
          flvRecordingMetaDelta.setDebugStatus("INIT AUDIO");
          flvRecordingMetaDelta.setOffset(this.offset);
          flvRecordingMetaDelta.setIsStartPadding(true);
          flvRecordingMetaDelta.setIsEndPadding(false);
          flvRecordingMetaDelta.setDataLengthPacket(data.limit());
          flvRecordingMetaDelta.setReceivedAudioDataLength(this.byteCount);
          flvRecordingMetaDelta.setStartTime(this.startedSessionTimeDate);
          flvRecordingMetaDelta.setStreamCreationTime(broadcastStream.getCreationTime());
          flvRecordingMetaDelta.setStreamCreationTimeDate(new Date(broadcastStream.getCreationTime()));
          flvRecordingMetaDelta.setPacketTimeStamp(streampacket.getTimestamp());
         
          Date current_date = new Date();
          Long deltaTimeStamp = current_date.getTime() - this.startedSessionTimeDate.getTime();
         
          //this.duration = Math.max(this.duration, 0 + this.writer.getOffset());
          flvRecordingMetaDelta.setDuration(0);
         
          Long missingTime = deltaTimeStamp - 0;
         
          flvRecordingMetaDelta.setMissingTime(missingTime);
         
          flvRecordingMetaDelta.setCurrentTime(current_date);
          flvRecordingMetaDelta.setDeltaTimeStamp(deltaTimeStamp);
          flvRecordingMetaDelta.setStartTimeStamp(startTimeStamp);
         
          this.flvRecordingMetaDeltas.add(flvRecordingMetaDelta);
         
          FlvRecordingMetaDeltaDaoImpl.getInstance().addFlvRecordingMetaDelta(flvRecordingMetaDelta);
         
          //That will be not bigger then long value
          this.startTimeStamp = (int) (streampacket.getTimestamp());
         
          //We have to set that to bypass the initial delta
          //lastTimeStamp = startTimeStamp;
        }
       
       
       
        if (writer == null) {
         
          File folder = new File(ScopeApplicationAdapter.webAppPath + File.separatorChar +
                    "streams" + File.separatorChar +
                    this.scope.getName());
         
          if (!folder.exists()) {
            folder.mkdir();
          }
         
          String flvName = ScopeApplicationAdapter.webAppPath + File.separatorChar +
                      "streams" + File.separatorChar +
                      this.scope.getName() + File.separatorChar +
                      this.streamName+".flv";
         
          file = new File(flvName);
          init();
        }
       
        int timeStamp = streampacket.getTimestamp();
       
        this.lastStreamPacketTimeStamp = streampacket.getTimestamp();
       
        timeStamp -= this.startTimeStamp;
       
        timeStamp += this.offset;
       
        long deltaTime = 0;
        if (lastTimeStamp == -1) {
          deltaTime = 0; //Offset at the beginning is calculated above
        } else {
          deltaTime = timeStamp - lastTimeStamp;
        }
       
        Long preLastTimeStamp = Long.parseLong(lastTimeStamp.toString());
       
        lastTimeStamp = timeStamp;
       
        if (deltaTime > 75){
         
          FlvRecordingMetaDelta flvRecordingMetaDelta = new FlvRecordingMetaDelta();
         
          flvRecordingMetaDelta.setDeltaTime(deltaTime);
          flvRecordingMetaDelta.setFlvRecordingMetaDataId(this.flvRecordingMetaDataId);
          flvRecordingMetaDelta.setTimeStamp(timeStamp);
          flvRecordingMetaDelta.setDebugStatus("RUN AUDIO");
          flvRecordingMetaDelta.setIsStartPadding(false);
          flvRecordingMetaDelta.setLastTimeStamp(preLastTimeStamp);
          flvRecordingMetaDelta.setOffset(this.offset);
          flvRecordingMetaDelta.setIsEndPadding(false);
          flvRecordingMetaDelta.setDataLengthPacket(data.limit());
          flvRecordingMetaDelta.setReceivedAudioDataLength(this.byteCount);
          flvRecordingMetaDelta.setStartTime(this.startedSessionTimeDate);
          flvRecordingMetaDelta.setStreamCreationTime(broadcastStream.getCreationTime());
          flvRecordingMetaDelta.setStreamCreationTimeDate(new Date(broadcastStream.getCreationTime()));
          flvRecordingMetaDelta.setPacketTimeStamp(streampacket.getTimestamp());
         
          Date current_date = new Date();
          Long deltaTimeStamp = current_date.getTime() - this.startedSessionTimeDate.getTime();
         
          this.duration = Math.max(this.duration, timeStamp + this.writer.getOffset());
          flvRecordingMetaDelta.setDuration(this.duration);
         
          Long missingTime = deltaTimeStamp - timeStamp;
         
          flvRecordingMetaDelta.setMissingTime(missingTime);
         
          flvRecordingMetaDelta.setCurrentTime(current_date);
          flvRecordingMetaDelta.setDeltaTimeStamp(deltaTimeStamp);
          flvRecordingMetaDelta.setStartTimeStamp(startTimeStamp);
         
          this.flvRecordingMetaDeltas.add(flvRecordingMetaDelta);
         
          FlvRecordingMetaDeltaDaoImpl.getInstance().addFlvRecordingMetaDelta(flvRecordingMetaDelta);
         
        }
       
              ITag tag = new Tag();
              tag.setDataType(streampacket.getDataType());
             
              //log.debug("data.limit() :: "+data.limit());
        tag.setBodySize(data.limit());
        tag.setTimestamp(timeStamp);
        tag.setBody(data);
       
        writer.writeTag(tag);
     
View Full Code Here

      if (streampacket.getTimestamp() <= 0) {
        log.warn("Negative TimeStamp");
        return;
      }
     
      IoBuffer data = streampacket.getData().asReadOnlyBuffer();
     
      if (data.limit() == 0) {
        return;
      }
     
      this.byteCount += data.limit();

      long deltaTime = 0;
     
      //log.debug("hasAudio :: "+streampacket.getDataType()); //8 == audio data
     
      if (writer == null) {
       
        File folder = new File(ScopeApplicationAdapter.webAppPath + File.separatorChar +
                  "streams" + File.separatorChar +
                  this.scope.getName());
       
        if (!folder.exists()) {
          folder.mkdir();
        }
       
        String flvName = ScopeApplicationAdapter.webAppPath + File.separatorChar +
                    "streams" + File.separatorChar +
                    this.scope.getName() + File.separatorChar +
                    this.streamName+".flv";
       
        file = new File(flvName);
       
        if (debug) {
         
          this.folderPath  = ScopeApplicationAdapter.webAppPath + File.separatorChar + file.getName().substring(0, file.getName().length()-4);
         
          File folder_debug = new File (folderPath);
          if (!folder_debug.exists()) {
            folder_debug.mkdir();
          }
        }
       
        init();
        //writer = new FLVWriter(,false);
        //writer.writeHeader();
      }
     
      if (streampacket.getDataType() == 8) {
       
        int timeStamp = streampacket.getTimestamp();
       
        this.lastStreamPacketTimeStamp = streampacket.getTimestamp();
       
        timeStamp -= startTimeStamp;
       
        if (lastTimeStamp == -1) {
          deltaTime = timeStamp;
        } else {
          deltaTime = timeStamp - lastTimeStamp;
        }
       
        lastTimeStamp = timeStamp;
       
        //log.debug("---- Is Audio Data :: "+streampacket.getTimestamp());
        //log.debug("---- Is Audio Length :: "+streampacket.getData().array().length);
       
        //log.debug("hasAudio :: "+streampacket.getTimestamp());
        //audioTs += streampacket.getTimestamp();
 
        //IoBuffer audioData = streampacket.getData().asReadOnlyBuffer();
        //byte[] data = SerializeUtils.ByteBufferToByteArray( audioData );
       
       
        //Try to fix missing packets, Standard packet Sizes are 46/47 ms long
       
        if (deltaTime > 55){
         
          FlvRecordingMetaDelta flvRecordingMetaDelta = new FlvRecordingMetaDelta();
         
          flvRecordingMetaDelta.setDeltaTime(deltaTime);
          flvRecordingMetaDelta.setFlvRecordingMetaDataId(this.flvRecordingMetaDataId);
          flvRecordingMetaDelta.setTimeStamp(timeStamp);
          flvRecordingMetaDelta.setIsEndPadding(false);
          flvRecordingMetaDelta.setDataLengthPacket(data.limit());
          flvRecordingMetaDelta.setReceivedAudioDataLength(this.byteCount);
          flvRecordingMetaDelta.setStartTime(this.startedSessionTimeDate);
         
         
          Date current_date = new Date();
          Long deltaTimeStamp = this.startedSessionTimeDate.getTime() - current_date.getTime();
         
          this.duration = Math.max(this.duration, timeStamp + this.writer.getOffset());
          flvRecordingMetaDelta.setDuration(this.duration);
         
          Long missingTime = deltaTimeStamp - timeStamp;
         
          flvRecordingMetaDelta.setMissingTime(missingTime);
         
          flvRecordingMetaDelta.setCurrentTime(current_date);
          flvRecordingMetaDelta.setDeltaTimeStamp(deltaTimeStamp);
          flvRecordingMetaDelta.setStartTimeStamp(startTimeStamp);
         
         
          this.flvRecordingMetaDeltas.add(flvRecordingMetaDelta);
         
          //Trying to simulate Packets, does not work, Packets must contains some decoded header Information
//          int numberOfMissingPackets = (int) Math.round(deltaTime/47);
//         
//          log.debug("deltaTime :: numberOfMissingPackets "+deltaTime+" :: "+numberOfMissingPackets);
//         
//          for (int i=0;i<numberOfMissingPackets;i++){
//           
//            ITag tag = new Tag();
//                 
//                  tag.setDataType(streampacket.getDataType());
//                 
//                  IoBuffer data = FLVWriterHelper.getAudioBuffer();
//     
//                  log.debug("write packet to :: "+timeStamp + (numberOfMissingPackets * 47));
//                 
//            tag.setBodySize(data.limit());
//            tag.setTimestamp(timeStamp + (numberOfMissingPackets * 47));
//            tag.setBody(data);
//           
//            //writer.writeTag(tag);
//           
//          }
         
        }
             
              ITag tag = new Tag();
              tag.setDataType(streampacket.getDataType());
             
              //log.debug("data.limit() :: "+data.limit());
        tag.setBodySize(data.limit());
        tag.setTimestamp(timeStamp);
        tag.setBody(data);
       
        //log.debug("duration: "+flvWriter.getDuration());
       
        if (debug) {
         
          String filePath = folderPath + File.separatorChar
              + "Packet"
              +"_t_"+tag.getTimestamp()
              +"_d_"+deltaTime
              +"_s_"+tag.getBodySize()
              +".flv";
         
          //File out = new File();
         
          FLVDebugWriter flvWriterDebug = new FLVDebugWriter( new File( filePath ), false);
         
          flvWriterDebug.writeBytesFromTag(streampacket.getData().asReadOnlyBuffer());

          flvWriterDebug.closeBytesFile();
         
        }

        writer.writeTag(tag);
 
      } else if (streampacket.getDataType() == 9) {
       
        //Video data is handled just without calculating deltas
        int timeStamp = streampacket.getTimestamp();
       
        timeStamp -= startTimeStamp;
       
        ITag tag = new Tag();
              tag.setDataType(streampacket.getDataType());
             
              //log.debug("data.limit() :: "+data.limit());
        tag.setBodySize(data.limit());
        tag.setTimestamp(timeStamp);
        tag.setBody(data);
       
        writer.writeTag(tag);
       
View Full Code Here

        if (streampacket.getTimestamp() <= 0) {
          log.warn("Negative TimeStamp");
          return;
        }
       
        IoBuffer data = streampacket.getData().asReadOnlyBuffer();
       
        if (data.limit() == 0) {
          return;
        }
       
        this.byteCount += data.limit();
       
        if (startTimeStamp == -1) {
         
          //That will be not bigger then long value
          startTimeStamp = streampacket.getTimestamp();
        }
       
        if (writer == null) {
         
          File folder = new File(ScopeApplicationAdapter.webAppPath + File.separatorChar +
                    "streams" + File.separatorChar +
                    this.scope.getName());
         
          if (!folder.exists()) {
            folder.mkdir();
          }
         
          String flvName = ScopeApplicationAdapter.webAppPath + File.separatorChar +
                      "streams" + File.separatorChar +
                      this.scope.getName() + File.separatorChar +
                      this.streamName+".flv";
         
          file = new File(flvName);
          init();
        }
       
        int timeStamp = streampacket.getTimestamp();
       
        timeStamp -= startTimeStamp;
       
              ITag tag = new Tag();
              tag.setDataType(streampacket.getDataType());
             
              //log.debug("data.limit() :: "+data.limit());
        tag.setBodySize(data.limit());
        tag.setTimestamp(timeStamp);
        tag.setBody(data);
       
       
        if (this.isInterview) {
View Full Code Here

        if ((req = writeRequestQueue.poll(session)) != null) {
            Object message = req.getMessage();
           
            if (message instanceof IoBuffer) {
                IoBuffer buf = (IoBuffer)message;

                // The first unwritten empty buffer must be
                // forwarded to the filter chain.
                if (buf.hasRemaining()) {
                    buf.reset();
                    failedRequests.add(req);
                } else {
                    IoFilterChain filterChain = session.getFilterChain();
                    filterChain.fireMessageSent(req);
                }
View Full Code Here

TOP

Related Classes of org.apache.mina.core.buffer.IoBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.