@Override
    public boolean addData(IoBuffer data, int timestamp) {
        //log.trace("addData timestamp: {} remaining: {}", timestamp, data.remaining());
        if (data.hasRemaining()) {
            // mark
            int start = data.position();
            // get frame type
            byte frameType = data.get();
            byte avcType = data.get();
            if ((frameType & 0x0f) == VideoCodec.AVC.getId()) {
                // check for keyframe
                if ((frameType & 0xf0) == FLV_FRAME_KEY) {
                    //log.trace("Key frame");
                    if (log.isDebugEnabled()) {
                        log.debug("Keyframe - AVC type: {}", avcType);
                    }
                    // rewind
                    data.rewind();
                    switch (avcType) {
                        case 1: // keyframe
                            //log.trace("Keyframe - keyframeTimestamp: {} {}", keyframeTimestamp, timestamp);
                            // get the time stamp and compare with the current value
                            if (timestamp != keyframeTimestamp) {
                                //log.trace("New keyframe");
                                // new keyframe
                                keyframeTimestamp = timestamp;
                                // if its a new keyframe, clear keyframe and interframe collections
                                softReset();
                            }
                            // store keyframe
                            keyframes.add(new FrameData(data));
                            break;
                        case 0: // configuration
                            //log.trace("Decoder configuration");
                            // Store AVCDecoderConfigurationRecord data
                            decoderConfiguration.setData(data);
                            softReset();
                            break;
                    }
                    //log.trace("Keyframes: {}", keyframes.size());
                } else if (bufferInterframes) {
                    //log.trace("Interframe");
                    if (log.isDebugEnabled()) {
                        log.debug("Interframe - AVC type: {}", avcType);
                    }
                    // rewind
                    data.rewind();
                    try {
                        int lastInterframe = numInterframes.getAndIncrement();
                        //log.trace("Buffering interframe #{}", lastInterframe);
                        if (lastInterframe < interframes.size()) {
                            interframes.get(lastInterframe).setData(data);
                        } else {
                            interframes.add(new FrameData(data));
                        }
                    } catch (Throwable e) {
                        log.error("Failed to buffer interframe", e);
                    }
                    //log.trace("Interframes: {}", interframes.size());
                }
            } else {
                // not AVC data
                log.debug("Non-AVC data, rejecting");
                // go back to where we started
                data.position(start);
                return false;
            }
            // go back to where we started
            data.position(start);
        }
        return true;
    }
@ Override public boolean addData ( IoBuffer data , int timestamp ) { if ( data . hasRemaining ( ) ) { int start = data . position ( ) ; byte frameType = data . get ( ) ; byte avcType = data . get ( ) ; if ( ( frameType & 0x0f ) == VideoCodec . AVC . getId ( ) ) { if ( ( frameType & 0xf0 ) == FLV_FRAME_KEY ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Keyframe - AVC type: {}" , avcType ) ; } data . rewind ( ) ; switch ( avcType ) { case 1 : if ( timestamp != keyframeTimestamp ) { keyframeTimestamp = timestamp ; softReset ( ) ; } keyframes . add ( new FrameData ( data ) ) ; break ; case 0 : decoderConfiguration . setData ( data ) ; softReset ( ) ; break ; } } else if ( bufferInterframes ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Interframe - AVC type: {}" , avcType ) ; } data . rewind ( ) ; try { int lastInterframe = numInterframes . getAndIncrement ( ) ; if ( lastInterframe < interframes . size ( ) ) { interframes . get ( lastInterframe ) . setData ( data ) ; } else { interframes . add ( new FrameData ( data ) ) ; } } catch ( Throwable e ) { log . error ( "Failed to buffer interframe" , e ) ; } } } else { log . debug ( "Non-AVC data, rejecting" ) ; data . position ( start ) ; return false ; } data . position ( start ) ; } return true ; }
{@inheritDoc}