public synchronized ITag readTag(){
  if (!firstTags.isEmpty()) {
    return firstTags.removeFirst();
  }
  MP4Frame frame=frames.get(currentFrame);
  log.debug("Playback #{} {}",currentFrame,frame);
  int sampleSize=frame.getSize();
  int time=(int)Math.round(frame.getTime() * 1000.0);
  long samplePos=frame.getOffset();
  byte type=frame.getType();
  int pad=5;
  if (type == TYPE_AUDIO) {
    pad=2;
  }
  ByteBuffer data=ByteBuffer.allocate(sampleSize + pad);
  try {
    if (type == TYPE_VIDEO) {
      if (frame.isKeyFrame()) {
        data.put(PREFIX_VIDEO_KEYFRAME);
      }
 else {
        data.put(PREFIX_VIDEO_FRAME);
      }
      int timeOffset=prevVideoTS != -1 ? time - prevVideoTS : 0;
      data.put((byte)((timeOffset >>> 16) & 0xff));
      data.put((byte)((timeOffset >>> 8) & 0xff));
      data.put((byte)(timeOffset & 0xff));
      if (log.isTraceEnabled()) {
        byte[] prefix=new byte[5];
        int p=data.position();
        data.position(0);
        data.get(prefix);
        data.position(p);
        log.trace("{}",prefix);
      }
      videoCount++;
      prevVideoTS=time;
    }
 else {
      data.put(PREFIX_AUDIO_FRAME);
      audioCount++;
    }
    channel.position(samplePos);
    channel.read(data);
  }
 catch (  IOException e) {
    log.error("Error on channel position / read",e);
  }
  IoBuffer payload=IoBuffer.wrap(data.array());
  ITag tag=new Tag(type,time,payload.limit(),payload,prevFrameSize);
  currentFrame++;
  prevFrameSize=tag.getBodySize();
  return tag;
}

public synchronized ITag readTag ( ) { if ( ! firstTags . isEmpty ( ) ) { return firstTags . removeFirst ( ) ; } MP4Frame frame = frames . get ( currentFrame ) ; log . debug ( "Playback #{} {}" , currentFrame , frame ) ; int sampleSize = frame . getSize ( ) ; int time = ( int ) Math . round ( frame . getTime ( ) * 1000.0 ) ; long samplePos = frame . getOffset ( ) ; byte type = frame . getType ( ) ; int pad = 5 ; if ( type == TYPE_AUDIO ) { pad = 2 ; } ByteBuffer data = ByteBuffer . allocate ( sampleSize + pad ) ; try { if ( type == TYPE_VIDEO ) { if ( frame . isKeyFrame ( ) ) { data . put ( PREFIX_VIDEO_KEYFRAME ) ; } else { data . put ( PREFIX_VIDEO_FRAME ) ; } int timeOffset = prevVideoTS != - 1 ? time - prevVideoTS : 0 ; data . put ( ( byte ) ( ( timeOffset > > > 16 ) & 0xff ) ) ; data . put ( ( byte ) ( ( timeOffset > > > 8 ) & 0xff ) ) ; data . put ( ( byte ) ( timeOffset & 0xff ) ) ; if ( log . isTraceEnabled ( ) ) { byte [ ] prefix = new byte [ 5 ] ; int p = data . position ( ) ; data . position ( 0 ) ; data . get ( prefix ) ; data . position ( p ) ; log . trace ( "{}" , prefix ) ; } videoCount ++ ; prevVideoTS = time ; } else { data . put ( PREFIX_AUDIO_FRAME ) ; audioCount ++ ; } channel . position ( samplePos ) ; channel . read ( data ) ; } catch ( IOException e ) { log . error ( "Error on channel position / read" , e ) ; } IoBuffer payload = IoBuffer . wrap ( data . array ( ) ) ; ITag tag = new Tag ( type , time , payload . limit ( ) , payload , prevFrameSize ) ; currentFrame ++ ; prevFrameSize = tag . getBodySize ( ) ; return tag ; }
packages media data for return to providers
