【发布时间】:2011-12-23 06:00:24
【问题描述】:
我正在使用 red5 和 flex 组合进行麦克风直播。场景是将 Web 客户端麦克风流发送到服务器并在服务器端播放流。同样,做相反的事情,即将麦克风流从服务器发送到客户端并在客户端播放流。
我已经发布了关于堆栈溢出的类似查询,链接如下:
red5: how can i send microphone stream?
我有客户端代码,我认为它也可以在不同的博客上找到。但我的问题是我如何在 red5 服务器端编写代码。我已经在我的机器上安装了 red5 服务器,还读出了 red5 API。但是从那里我不清楚我如何处理服务器端的实时流。
我还做了一个red5示例代码。
Application.java
public class Application extends ApplicationAdapter {
@Override
public boolean appConnect(IConnection arg0, Object[] arg1) {
out.println("appConnect");
return super.appConnect(arg0, arg1);
}
@Override
public void appDisconnect(IConnection arg0) {
out.println("appConnect");
super.appDisconnect(arg0);
}
}
StreamManager.java
public class StreamManager {
private static final Log log = LogFactory.getLog(StreamManager.class);
private Application app;
/**
* Start recording the publishing stream for the specified IConnection.
*
* @param conn
*/
private ClientBroadcastStream stream;
public void recordShow(IConnection conn) {
try {
log.debug("Recording show for: " + conn.getScope().getContextPath());
String streamName = String.valueOf(System.currentTimeMillis());
log.debug("Stream Name : " + streamName);
// Get a reference to the current broadcast stream.
stream = (ClientBroadcastStream) app.getBroadcastStream(conn.getScope(), "hostStream");
// Save the stream to disk.
stream.saveAs(streamName, false);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
public void setApplication(Application app) {
this.app = app;
}
}
samplescope-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd">
<bean id="samplescope.context" class="org.red5.server.Context" autowire="byType" />
<bean id="samplescope.scope" class="org.red5.server.WebScope"
init-method="register">
<property name="server" ref="red5.server" />
<property name="parent" ref="global.scope" />
<property name="context" ref="samplescope.context" />
<property name="handler" ref="samplescope.handler" />
<property name="contextPath" value="/samplescope" />
<property name="virtualHosts"
value="*,localhost, localhost:5080, 127.0.0.1:5080" />
</bean>
<bean id="samplescope.handler" class="my.first.Application" />
<bean id="streamManager.service" class="my.first.StreamManager">
<property name="application" ref="samplescope.handler"/>
</bean>
</beans>
上面的代码将流保存在服务器端的 FLV 文件中,但我希望这样,而不是将流保存在服务器上,我可以获得原始数据流,从而轻松地对流进行编码。同样,在服务器上发送流之前解码流。 red5 怎么办?
【问题讨论】:
标签: red5