122 lines
4.3 KiB
Plaintext
122 lines
4.3 KiB
Plaintext
-------------------------------------------------
|
|
HOWTO stream content to/from custom directories
|
|
-------------------------------------------------
|
|
|
|
:Author: Joachim Bauch
|
|
:Contact: jojo@struktur.de
|
|
:Date: $Date: 2007-05-13 15:34:08 +0200 (Sun, 13 May 2007) $
|
|
:Revision: $Revision: 2026 $
|
|
:Id: $Id: HOWTO-StreamCustomDirectories.txt 2026 2007-05-13 13:34:08Z TTriemstra $
|
|
|
|
.. contents::
|
|
|
|
Preface
|
|
==========================
|
|
This document describes how applications can stream ondemand videos (VOD) from or
|
|
record to custom directories other than the default `streams` folder inside
|
|
the webapp.
|
|
|
|
Filename generator service
|
|
==========================
|
|
Red5 uses a concept called `scope services` for functionality that is provided
|
|
for a certain scope. One of these scope services is IStreamFilenameGenerator_
|
|
that generates filenames for VOD streams that should be played or recorded.
|
|
|
|
Custom generator
|
|
==========================
|
|
To generate filename in different folders, a new filename generator must be
|
|
implemented::
|
|
|
|
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/";
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
The above class will generate filenames for recorded streams like
|
|
`recordedStreams/red5RecordDemo1234.flv` and use the directory `videoStreams`
|
|
as source for all VOD streams.
|
|
|
|
Activate custom generator
|
|
==========================
|
|
In the next step, the custom generator must be activate in the configuration
|
|
files for the desired application.
|
|
|
|
Add the following definition to `yourApp/WEB-INF/red5-web.xml`::
|
|
|
|
<bean id="streamFilenameGenerator"
|
|
class="path.to.your.CustomFilenameGenerator" />
|
|
|
|
This will use the class defined above to generate stream filenames.
|
|
|
|
Change paths through configuration
|
|
==================================
|
|
While the class described here works as expected, it's a bit unhandy to
|
|
change the paths inside the code as every change requires recompilation
|
|
of the class.
|
|
|
|
Therefore you can pass parameters to the bean defined in the previous step
|
|
to specify the paths to use inside the configuration file.
|
|
|
|
Add two methods to your class that will be executed while the configuration
|
|
file is parsed::
|
|
|
|
public void setRecordPath(String path) {
|
|
recordPath = path;
|
|
}
|
|
|
|
public void setPlaybackPath(String path) {
|
|
playbackPath = path;
|
|
}
|
|
|
|
Now you can set the paths inside the bean definition::
|
|
|
|
<bean id="streamFilenameGenerator"
|
|
class="path.to.your.CustomFilenameGenerator">
|
|
<property name="recordPath" value="recordedStreams/" />
|
|
<property name="playbackPath" value="videoStreams/" />
|
|
</bean>
|
|
|
|
You can also move the paths to the `yourApp/WEB-INF/red5-web.properties`
|
|
file and use parameters to access them::
|
|
|
|
<bean id="streamFilenameGenerator"
|
|
class="path.to.your.CustomFilenameGenerator">
|
|
<property name="recordPath" value="${recordPath}" />
|
|
<property name="playbackPath" value="${playbackPath}" />
|
|
</bean>
|
|
|
|
In that case you will have to add the following lines to your properties
|
|
file::
|
|
|
|
recordPath=recordedStreams/
|
|
playbackPath=videoStreams/
|
|
|
|
.. _IStreamFilenameGenerator: http://dl.fancycode.com/red5/api/org/red5/server/api/stream/IStreamFilenameGenerator.html
|