本文整理汇总了Java中org.red5.io.ITag.getBodySize方法的典型用法代码示例。如果您正苦于以下问题:Java ITag.getBodySize方法的具体用法?Java ITag.getBodySize怎么用?Java ITag.getBodySize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.red5.io.ITag
的用法示例。
在下文中一共展示了ITag.getBodySize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readTag
import org.red5.io.ITag; //导入方法依赖的package包/类
/** {@inheritDoc} */
public ITag readTag() {
ITag tag = null;
try {
lock.acquire();
long oldPos = getCurrentPosition();
tag = readTagHeader();
if (tag != null) {
boolean isMetaData = tag.getDataType() == TYPE_METADATA;
log.debug("readTag, oldPos: {}, tag header: \n{}", oldPos, tag);
if (!metadataSent && !isMetaData && generateMetadata) {
// Generate initial metadata automatically
setCurrentPosition(oldPos);
KeyFrameMeta meta = analyzeKeyFrames();
if (meta != null) {
metadataSent = true;
return createFileMeta();
}
}
int bodySize = tag.getBodySize();
IoBuffer body = IoBuffer.allocate(bodySize, false);
// XXX Paul: this assists in 'properly' handling damaged FLV files
long newPosition = getCurrentPosition() + bodySize;
if (newPosition <= getTotalBytes()) {
int limit;
while (getCurrentPosition() < newPosition) {
fillBuffer(newPosition - getCurrentPosition());
if (getCurrentPosition() + in.remaining() > newPosition) {
limit = in.limit();
in.limit((int) (newPosition - getCurrentPosition()) + in.position());
body.put(in);
in.limit(limit);
} else {
body.put(in);
}
}
body.flip();
tag.setBody(body);
}
} else {
log.debug("Tag was null");
}
} catch (InterruptedException e) {
log.warn("Exception acquiring lock", e);
} finally {
lock.release();
}
return tag;
}
示例2: write
import org.red5.io.ITag; //导入方法依赖的package包/类
/**
* Adjust timestamp and write to the file.
*
* @param queued
* queued data for write
*/
private final void write(QueuedData queued) {
// get data type
byte dataType = queued.getDataType();
// get timestamp
int timestamp = queued.getTimestamp();
log.debug("Write - timestamp: {} type: {}", timestamp, dataType);
// get queued
ITag tag = queued.getData();
if (tag != null) {
// only allow blank tags if they are of audio type
if (tag.getBodySize() > 0 || dataType == ITag.TYPE_AUDIO) {
// if the last message was a reset or we just started, use the header timer
if (startTimestamp == -1) {
startTimestamp = timestamp;
timestamp = 0;
} else {
timestamp -= startTimestamp;
}
// update the timestamp
tag.setTimestamp(timestamp);
try {
if (timestamp >= 0) {
if (!writer.writeTag(tag)) {
log.warn("Tag was not written");
}
} else {
log.warn("Skipping message with negative timestamp.");
}
} catch (ClosedChannelException cce) {
// the channel we tried to write to is closed, we should not try
// again on that writer
log.error("The writer is no longer able to write to the file: {} writable: {}", path.getFileName(), path.toFile().canWrite());
} catch (IOException e) {
log.warn("Error writing tag", e);
if (e.getCause() instanceof ClosedChannelException) {
// the channel we tried to write to is closed, we should not
// try again on that writer
log.error("The writer is no longer able to write to the file: {} writable: {}", path.getFileName(), path.toFile().canWrite());
}
} finally {
queued.dispose();
}
}
}
}
示例3: write
import org.red5.io.ITag; //导入方法依赖的package包/类
/**
* Write incoming data to the file.
*
* @param timestamp adjusted timestamp
* @param msg stream data
*/
private final void write(int timestamp, IRTMPEvent msg) {
byte dataType = msg.getDataType();
log.debug("Write - timestamp: {} type: {}", timestamp, dataType);
//if the last message was a reset or we just started, use the header timer
if (startTimestamp == -1) {
startTimestamp = timestamp;
timestamp = 0;
} else {
timestamp -= startTimestamp;
}
// create a tag
ITag tag = new Tag();
tag.setDataType(dataType);
tag.setTimestamp(timestamp);
// get data bytes
IoBuffer data = ((IStreamData<?>) msg).getData().duplicate();
if (data != null) {
tag.setBodySize(data.limit());
tag.setBody(data);
}
// only allow blank tags if they are of audio type
if (tag.getBodySize() > 0 || dataType == ITag.TYPE_AUDIO) {
try {
if (timestamp >= 0) {
if (!writer.writeTag(tag)) {
log.warn("Tag was not written");
}
} else {
log.warn("Skipping message with negative timestamp.");
}
} catch (IOException e) {
log.error("Error writing tag", e);
} finally {
if (data != null) {
data.clear();
data.free();
}
}
}
data = null;
}