public Segmenter(Int32 frameSize, Byte[] buffer, Frame.FrameTypes frameType, Frame.ProtocolVersion version) { fType = frameType; buf = buffer; fSize = frameSize; if (frameType.Equals(Frame.FrameTypes.IType)) { // // Call the IFRame segmenter. This segmenter does not use fragmented packets // SegmentIFrames(frameSize, buffer); } else { // // Call the UIFRame segmenter. This segmenter does use fragmented packets if we're running V22 protocol // SegmentUIFrames(frameSize, buffer, version); } }
public Byte[] GetNextSegment() { Byte[] tmpB; Int32 bufLen = fSize; // // Return a specific segment from a larger packet. Adds the appropriate PID & Segmentation information // as appropriate // if (_segmentPtr == _segmentTotal) { // // At the end, so return null // return(null); } if (fType.Equals(Frame.FrameTypes.IType)) { // // Iframes don't use fragmented frames // if (_segmentPtr == (_segmentTotal - 1)) { // // Calculate buffer size of the final buffer // bufLen = (buf.Length % fSize); if (bufLen == 0) { bufLen = fSize; } } tmpB = new Byte[bufLen + 1]; tmpB[0] = (Byte)(Frame.PidInfo.PidTypes.NoL3Proto); for (Int32 i = 0; i < bufLen; i++) { tmpB[i + 1] = buf[(_segmentPtr * fSize) + i]; } _segmentPtr++; return(tmpB); } // // UIFrames use fragmented frames // if (_segmentTotal == 1) { // // Buffer fits in a single packet // tmpB = new Byte[buf.Length + 1]; tmpB[0] = (Byte)(Frame.PidInfo.PidTypes.NoL3Proto); buf.CopyTo(tmpB, 1); _segmentPtr++; return(tmpB); } if (_segmentPtr == (_segmentTotal - 1)) { // // Calculate buffer size of the final buffer // bufLen = (buf.Length % fSize); if (bufLen == 0) { bufLen = fSize; } } tmpB = new Byte[bufLen + 2]; tmpB[0] = (Byte)Frame.PidInfo.PidTypes.SegFrag; tmpB[1] = (Byte)((_segmentTotal - _segmentPtr - 1) & 0x7f); if (_segmentPtr == 0) { tmpB[1] |= StartOfSegment; // Set the start of segment bit } for (Int32 i = 0; i < bufLen; i++) { // // Populate the return buffer // tmpB[i + 2] = buf[(_segmentPtr * fSize) + i]; } _segmentPtr++; return(tmpB); }