*但是我应该在 packetReceived() 函数中添加什么?*
我将其添加到单独的答案中以正确突出显示:
要将数据包写入磁盘,您需要:1)数据包,2)将数据包转换为 ITag 3)获取 ITagWriter 的实例
1) 第
50 行左右的数据包数据http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/flvrecord/listener/StreamVideoListener.java?view=markup
public void packetReceived(IBroadcastStream broadcastStream,
IStreamPacket streampacket) {
}
streampacket => 要写入磁盘的数据包。
2) 通过将数据包转换为 ITag 来写入数据包
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/flvrecord/listener/async/StreamVideoWriter.java?view=markup
90ff 行左右
IoBuffer data = streampacket.getData().asReadOnlyBuffer();
if (data.limit() == 0) {
return;
}
if (startTimeStamp == -1) {
// That will be not bigger then long value
startTimeStamp = streampacket.getTimestamp();
}
timeStamp -= startTimeStamp;
ITag tag = new Tag();
tag.setDataType(streampacket.getDataType());
// log.debug("data.limit() :: "+data.limit());
tag.setBodySize(data.limit());
tag.setTimestamp(timeStamp);
tag.setBody(data);
writer.writeTag(tag);
3) 获取一个Writer实例
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/flvrecord/listener/async/BaseStreamWriter.java?view=markup
90ff 行附近
protected ITagWriter writer = null;
private void init() throws IOException {
file = new File(OmFileHelper.getStreamsSubDir(this.scope.getName()), this.streamName + ".flv");
IStreamableFileFactory factory = (IStreamableFileFactory) ScopeUtils
.getScopeService(this.scope, IStreamableFileFactory.class,
StreamableFileFactory.class);
if (!this.file.isFile()) {
// Maybe the (previously existing) file has been deleted
this.file.createNewFile();
} else if (!file.canWrite()) {
throw new IOException("The file is read-only");
}
IStreamableFileService service = factory.getService(this.file);
IStreamableFile flv = service.getStreamableFile(this.file);
this.writer = flv.getWriter();
}
所以这是一个艰难的过程。从这个意义上说,您可以继续前进。
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/data/flvrecord/listener/async/BaseStreamWriter.java?view=markup _
类还包含一个队列来收集数据包。
IStreamPacket.getType == 9 是视频,我认为 8 是音频(但您需要验证)。
塞巴斯蒂安