本文整理汇总了Java中org.red5.server.net.rtmp.message.Header.setSize方法的典型用法代码示例。如果您正苦于以下问题:Java Header.setSize方法的具体用法?Java Header.setSize怎么用?Java Header.setSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.red5.server.net.rtmp.message.Header
的用法示例。
在下文中一共展示了Header.setSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHeaders
import org.red5.server.net.rtmp.message.Header; //导入方法依赖的package包/类
public void testHeaders() {
RTMP rtmp = new RTMP();
Header header = new Header();
header.setChannelId((byte) 0x12);
header.setDataType(TYPE_INVOKE);
header.setStreamId(100);
header.setTimer(2);
header.setSize(320);
IoBuffer buf = encoder.encodeHeader(rtmp, header, null);
buf.flip();
log.debug(buf.getHexDump());
Assert.assertNotNull(buf);
Header result = decoder.decodeHeader(buf, null);
Assert.assertEquals(header, result);
}
示例2: encodePacket
import org.red5.server.net.rtmp.message.Header; //导入方法依赖的package包/类
/**
* Encode packet.
*
* @param packet
* RTMP packet
* @return Encoded data
*/
public IoBuffer encodePacket(Packet packet) {
IoBuffer out = null;
Header header = packet.getHeader();
int channelId = header.getChannelId();
//log.trace("Channel id: {}", channelId);
IRTMPEvent message = packet.getMessage();
if (message instanceof ChunkSize) {
ChunkSize chunkSizeMsg = (ChunkSize) message;
((RTMPConnection) Red5.getConnectionLocal()).getState().setWriteChunkSize(chunkSizeMsg.getSize());
}
// normally the message is expected not to be dropped
if (!dropMessage(channelId, message)) {
//log.trace("Header time: {} message timestamp: {}", header.getTimer(), message.getTimestamp());
IoBuffer data = encodeMessage(header, message);
if (data != null) {
RTMP rtmp = ((RTMPConnection) Red5.getConnectionLocal()).getState();
// set last write packet
rtmp.setLastWritePacket(channelId, packet);
// ensure we're at the beginning
if (data.position() != 0) {
data.flip();
} else {
data.rewind();
}
// length of the data to be chunked
int dataLen = data.limit();
header.setSize(dataLen);
//if (log.isTraceEnabled()) {
//log.trace("Message: {}", data);
//}
// chunk size for writing
int chunkSize = rtmp.getWriteChunkSize();
// number of chunks to write
int numChunks = (int) Math.ceil(dataLen / (float) chunkSize);
// get last header
Header lastHeader = rtmp.getLastWriteHeader(channelId);
if (log.isTraceEnabled()) {
log.trace("Channel id: {} chunkSize: {}", channelId, chunkSize);
}
// attempt to properly guess the size of the buffer we'll need
int bufSize = dataLen + 18 + (numChunks * 2);
//log.trace("Allocated buffer size: {}", bufSize);
out = IoBuffer.allocate(bufSize, false);
out.setAutoExpand(true);
do {
// encode the header
encodeHeader(header, lastHeader, out);
// write a chunk
byte[] buf = new byte[Math.min(chunkSize, data.remaining())];
data.get(buf);
//log.trace("Buffer: {}", Hex.encodeHexString(buf));
out.put(buf);
// move header over to last header
lastHeader = header.clone();
} while (data.hasRemaining());
// collapse the time stamps on the last header after decode is complete
lastHeader.setTimerBase(lastHeader.getTimer());
// clear the delta
lastHeader.setTimerDelta(0);
// set last write header
rtmp.setLastWriteHeader(channelId, lastHeader);
data.free();
out.flip();
data = null;
}
}
message.release();
return out;
}
示例3: encodePacket
import org.red5.server.net.rtmp.message.Header; //导入方法依赖的package包/类
/**
* Encode packet.
*
* @param rtmp RTMP protocol state
* @param packet RTMP packet
* @return Encoded data
*/
public IoBuffer encodePacket(RTMP rtmp, Packet packet) {
IoBuffer out = null;
IoBuffer data = null;
final Header header = packet.getHeader();
final int channelId = header.getChannelId();
log.debug("Channel id: {}", channelId);
final IRTMPEvent message = packet.getMessage();
if (message instanceof ChunkSize) {
ChunkSize chunkSizeMsg = (ChunkSize) message;
rtmp.setWriteChunkSize(chunkSizeMsg.getSize());
}
// normally the message is expected not to be dropped
if (!dropMessage(rtmp, channelId, message)) {
data = encodeMessage(rtmp, header, message);
if (data != null) {
if (data.position() != 0) {
data.flip();
} else {
data.rewind();
}
int dataLen = data.limit();
header.setSize(dataLen);
// get last header
Header lastHeader = rtmp.getLastWriteHeader(channelId);
// maximum header size with extended timestamp (Chunk message header type 0 with 11 byte)
int headerSize = 18;
// set last write header
rtmp.setLastWriteHeader(channelId, header);
// set last write packet
rtmp.setLastWritePacket(channelId, packet);
int chunkSize = rtmp.getWriteChunkSize();
// maximum chunk header size with extended timestamp
int chunkHeaderSize = 7;
int numChunks = (int) Math.ceil(dataLen / (float) chunkSize);
int bufSize = dataLen + headerSize + (numChunks > 0 ? (numChunks - 1) * chunkHeaderSize : 0);
out = IoBuffer.allocate(bufSize, false);
// encode the header
encodeHeader(rtmp, header, lastHeader, out);
if (numChunks == 1) {
// we can do it with a single copy
BufferUtils.put(out, data, dataLen);
} else {
int extendedTimestamp = header.getExtendedTimestamp();
for (int i = 0; i < numChunks - 1; i++) {
BufferUtils.put(out, data, chunkSize);
dataLen -= chunkSize;
RTMPUtils.encodeHeaderByte(out, HEADER_CONTINUE, header.getChannelId());
if (extendedTimestamp != 0) {
out.putInt(extendedTimestamp);
}
}
BufferUtils.put(out, data, dataLen);
}
data.free();
out.flip();
data = null;
}
}
message.release();
return out;
}