0

我有 1 台运行 Red5 的服务器和大约 5-6 台运行 icecast2 作为频道的其他服务器现在我想使用 Red5 从 icecast2 重新流式传输

当用户请求内容时,Red5会知道该内容属于哪个icecast2服务器,并连接到正确的服务器以获取媒体并重新流式传输给用户

我的问题是,通常 Red5 流式传输静态内容,但在我的情况下,我必须以指定的速度和带宽从 icecast2 重新传输动态内容?那可能吗?有什么我可以看的例子来了解这个想法吗?

4

1 回答 1

1

要将一个服务器重新流式传输到另一台服务器,请使用StreamingProxy

import java.util.HashMap;
import java.util.Map;

import org.red5.server.adapter.MultiThreadedApplicationAdapter;
import org.red5.server.api.IBasicScope;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.stream.IBroadcastStream;
import org.red5.server.stream.IBroadcastScope;
import org.red5.server.stream.StreamingProxy;

public class Application extends MultiThreadedApplicationAdapter implements IStreamListener {

private Map<String, StreamingProxy> streamingProxyMap = new HashMap<String, StreamingProxy>();

public IBroadcastScope getBroadcastScope(IScope scope, String name) {
    IBasicScope basicScope = scope.getBasicScope(IBroadcastScope.TYPE,
            name);
    if (!(basicScope instanceof IBroadcastScope)) {
        return null;
    } else {
        return (IBroadcastScope) basicScope;
    }
}

/** {@inheritDoc} */
@Override
public boolean connect(IConnection conn, IScope scope, Object[] params) {
    return true;
}

public void streamBroadcastStart(IBroadcastStream stream)
{
    IScope scope = stream.getScope();
    IBroadcastScope bsScope = getBroadcastScope(scope, stream.getPublishedName());
    StreamingProxy proxy = new StreamingProxy();
    proxy.setHost("live.justin.tv");
    proxy.setApp("app");
    proxy.setPort(1935);
    proxy.init();
    bsScope.subscribe(proxy, null);
    proxy.start("MY_STRING", StreamingProxy.LIVE, null);
    streamingProxyMap.put(stream.getPublishedName(), proxy);
    stream.addStreamListener(this);
}

public void packetReceived(IBroadcastStream stream, IStreamPacket packet) 
{
    RTMPMessage m = RTMPMessage.build((IRTMPEvent) packet,packet.getTimestamp());
    streamer.pushMessage(null, m);
}       

synchronized public void streamBroadcastClose(IBroadcastStream stream) {
    StreamingProxy proxy =
            streamingProxyMap.get(stream.getPublishedName());
    if (proxy != null) {
            proxy.stop();
            IScope scope = stream.getScope();
            IBroadcastScope bsScope = getBroadcastScope(scope, stream.getPublishedName());
            if (bsScope != null) {
                bsScope.unsubscribe(proxy);
        }
    }
}

/** {@inheritDoc} */
@Override
public void disconnect(IConnection conn, IScope scope) {
    super.disconnect(conn, scope);
}

}
于 2012-04-26T07:08:10.647 回答