要在不同的文件里生成文件名,必须实现一个新的文件名生成器:
import org.red5.server.api.IScope; import org.red5.server.api.stream.IStreamFilenameGenerator; public class CustomFilenameGenerator implements IStreamFilenameGenerator { /** Path that will store recorded videos. */ public String recordPath = "recordedStreams/"; /** Path that contains VOD streams. */ public String playbackPath = "videoStreams/"; /** Set if the path is absolute or relative */ public boolean resolvesAbsolutePath = false; public String generateFilename(IScope scope, String name, GenerationType type) { // Generate filename without an extension. return generateFilename(scope, name, null, type); } public String generateFilename(IScope scope, String name, String extension, GenerationType type) { String filename; if (type == GenerationType.RECORD) filename = recordPath + name; else filename = playbackPath + name; if (extension != null) // Add extension filename += extension; return filename; } public boolean resolvesToAbsolutePath() { return resolvesAbsolutePath; } }
将以下定义添加到 yourApp/WEB-INF/red5-web.xml:
<bean id="streamFilenameGenerator" class="path.to.your.CustomFilenameGenerator" />
添加三个方法到你的类,这些方法会在配置文件被解析时执行:
public void setRecordPath(String path) { recordPath = path; } public void setPlaybackPath(String path) { playbackPath = path; } public void setAbsolutePath(Boolean absolute) { resolvesAbsolutePath = absolute; }
现在你可以在 bean 定义里设置路径了:
<bean id="streamFilenameGenerator" class="path.to.your.CustomFilenameGenerator"> <property name="recordPath" value="recordedStreams/" /> <property name="playbackPath" value="videoStreams/" /> <property name="absolutePath" value="false" /> </bean> <bean id="streamFilenameGenerator" class="path.to.your.CustomFilenameGenerator"> <property name="recordPath" value="/path/to/recordedStreams/" /> <property name="playbackPath" value="/path/to/videoStreams/" /> <property name="absolutePath" value="true" /> </bean>
你也可以把路径放到 yourApp/WEB-INF/red5-web.properties 文件里并使用参数对它们进行访问:
<bean id="streamFilenameGenerator" class="path.to.your.CustomFilenameGenerator"> <property name="recordPath" value="${recordPath}" /> <property name="playbackPath" value="${playbackPath}" /> <property name="absolutePath" value="${absolutePath}" /> </bean>
这时你需要把以下行添加到你的 properties 文件(red5-web.properties):
recordPath=recordedStreams/ playbackPath=videoStreams/ absolutePath=false recordPath=/path/to/recordedStreams/ playbackPath=/path/to/videoStreams/ absolutePath=true