public bool CanHandleData(ByteBuffer data) { if (data.Limit == 0) return false;// Empty buffer byte first = data.Get(); bool result = ((first & 0x0f) == VideoCodec.AVC.Id); data.Rewind(); return result; }
public bool AddData(ByteBuffer data) { if (data.Limit == 0) return true; if (!CanHandleData(data)) return false; data.Rewind(); byte frameType = data.Get(); data.Rewind(); if ((frameType & 0xf0) != VideoCodec.FLV_FRAME_KEY) return true;// Not a keyframe //If we don't have the AVCDecoderConfigurationRecord stored... if (_blockDataAVCDCR == null) { data.Get();//FT data.Get();//CODECID byte AVCPacketType = data.Get(); //Sequence Header / here comes a AVCDecoderConfigurationRecord if (log.IsDebugEnabled) log.Debug(string.Format("AVCPacketType: {0}", AVCPacketType)); if (AVCPacketType == 0) { data.Rewind(); // Store AVCDecoderConfigurationRecord data _dataCountAVCDCR = data.Limit; if (_blockSizeAVCDCR < _dataCountAVCDCR) { _blockSizeAVCDCR = _dataCountAVCDCR; _blockDataAVCDCR = new byte[_blockSizeAVCDCR]; } data.Read(_blockDataAVCDCR, 0, _dataCountAVCDCR); } } data.Rewind(); // Store last keyframe _dataCountLKF = data.Limit; if (_blockSizeLKF < _dataCountLKF) { _blockSizeLKF = _dataCountLKF; _blockDataLKF = new byte[_blockSizeLKF]; } data.Read(_blockDataLKF, 0, _dataCountLKF); data.Rewind(); return true; }