0

I have 1 server running Red5 and about 5-6 other server running icecast2 as channel Now i want to using Red5 to re-streaming from icecast2

When user request a content, Red5 will know that content belong to which icecast2 server, and it will connect to corrected server to get media and re-stream to user

My question is, normally, Red5 streaming a static content, but in my situation, i must re-streaming a dynamic content from icecast2 with specify speed and bandwidth? Is that possible? Is there any example i could look at to get the idea?

kiennt
  • 1,514
  • 2
  • 14
  • 13

1 Answers1

1

For restreaming one server to another server use 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);
}

}
arulraj.net
  • 4,579
  • 3
  • 36
  • 37
  • Do you have a new version of this – Juan Diego Nov 28 '16 at 01:49
  • @JuanDiego I don't have – arulraj.net Nov 30 '16 at 15:03
  • If I want to restream a selected stream at will It should work the same way in any method? – Juan Diego Nov 30 '16 at 15:08
  • In this code, how does StreamingProxy know which stream it should broadcast – Juan Diego Dec 02 '16 at 16:50
  • `streamBroadcastStart` function will be called whenever new stream started publishing. From `stream.getPublishedName()` you will get to know the name of the stream. More info on http://red5.org/javadoc/red5-server-common/org/red5/server/api/stream/IStreamListener.html – arulraj.net Dec 03 '16 at 11:33
  • Ok, correct me if I am wrong. I understand that streamBroadcast is called every time a stream starts broadcasting, and I get that you have a listener. But at no point I see the "proxy" class recieving a parameter telling it to use stream or bscope or else. I just see that you set proxy initial values, then proxy init, then start, and I assume "MY_STRING" is the name of the stream on the other server. In packatReceived, is it here where you set that up? streamer is of type Streaming proxy right? – Juan Diego Dec 04 '16 at 01:22
  • let me clarify, Its 4 year old code (I think red5-0.8.0). It will not work newer version of red5, because they are not implemented all methods. `bsScope.subscribe(proxy, null);` here proxy subscribed the broadcasted stream. "MY_STRING" - In which name you want to publish in proxy server. `streamer` - I am clueless now. May be its came from extended class. Have to check. – arulraj.net Dec 04 '16 at 15:02
  • Hey thanks, well I fixed my problem, there was problem with the version I think, tried with 1.0.8.M3 and it worked – Juan Diego Dec 05 '16 at 19:03
  • in this example I see that you are using live.justin.tv, how did you passed Stream Key to streamingproxy – Juan Diego Dec 10 '16 at 00:21