/// <summary> /// Sends the current buffer using data_buffer as the source of data. The size /// is determined from the position in outputBuff. /// </summary> /// <param name="header">The header to prepend to the amf packet.</param> private void chunkBufferAndSend(AMFHeader header) { //the size remaining in the data buffer int size = (int)outputBuff.Position; //the position in the data buffer (from which to start sending bytes) int position = 0; //reset the chunkBuff position chunkBuff.Position = 0; //write the header to the chunk buffer header.writeHeader(chunkBuff); //copy <= 128 bytes from the data buffer into the chunk buffer to send. Array.Copy(dataBuffer, 0, chunk_buffer, header.getHeaderSize(), size > 128 ? 128 : size); //send the first packet of information connectionSocket.Send(chunk_buffer, (header.getHeaderSize() + (size > 128 ? 128 : size)), SocketFlags.None); size -= 128; position += 128; while (size > 0) { //add a header byte dataBuffer[position - 1] = header.get_1_HeaderByte(); //send out the data connectionSocket.Send(dataBuffer, position - 1, size > 128 ? 129 : size + 1, SocketFlags.None); position += 128; size -= 128; } }
/// <summary> /// Sends the flv tag to the RTMP server. /// </summary> /// <param name="tagData"></param> /// <param name="tag"></param> public override bool sendFLVTag(byte[] tagData, FLVTag tag) { if (!isConnected) return false; outputBuff.Position = 0; chunkBuff.Position = 0; AMFHeader header = new AMFHeader(AMFHeader.HEADER_12, 0x8); header.RTMPType = AMFHeader.RTMP_TYPE_VIDEO; header.TimeStamp = tag.TimeStamp; header.EndPoint = 0x00000001; header.BodySize = tag.getTagSizeInBytes() - 11; //write the header to teh chunkbuffer header.writeHeader(chunkBuff); //the size remaining in the data buffer int size = tag.getTagSizeInBytes() - 11; //the position in the data buffer (from which to start sending bytes) int position = 0; //write the header to the chunk buffer header.writeHeader(chunkBuff); //copy <= 128 bytes from the tagData into the chunk buffer to send. Array.Copy(tagData, 11, chunk_buffer, header.getHeaderSize(), size > 128 ? 128 : size); //send the first packet of information connectionSocket.Send(chunk_buffer, (header.getHeaderSize() + (size > 128 ? 128 : size)), SocketFlags.None); size -= 128; position += 128 + 11; //while there is still bytes while (size > 0) { //add a header byte byte t = tagData[position - 1]; tagData[position - 1] = header.get_1_HeaderByte(); //send out the data connectionSocket.Send(tagData, position - 1, size > 128 ? 129 : size + 1, SocketFlags.None); //restore where the header was tagData[position - 1] = t; position += 128; size -= 128; } return true; }