http://pxchen.iteye.com/blog/714591
发布端(Publish):
var nc:NetConnection = new NetConnection();
nc.connect("rtmp://125.67.234.97/Red5Stream");
nc.addEventListener(NetStatusEvent.NET_STATUS,connectHandler);
function connectHandler(par:NetStatusEvent):void {
trace(par.info.code);
var camera:Camera = Camera.getCamera();
camera.setQuality(163854,100);
var stream:NetStream = new NetStream(nc);
stream.attachCamera(camera);
stream.publish("red5");
}
接收端
package {
import flash.display.*;
import flash.utils.*;
import flash.events.*;
import flash.net.*;
import flash.media.Video;
import fl.data.DataProvider;
import flash.media.Camera;
public class NetStreamTestDocument extends Sprite {
var nc:NetConnection;
public function NetStreamTestDocument() {
nc= new NetConnection();
nc.connect("rtmp://125.67.234.97/Red5Stream");
nc.addEventListener(NetStatusEvent.NET_STATUS,connectHandler);
}
public function connectHandler(par:NetStatusEvent):void {
var ns:NetStream = new NetStream(nc);
var video:Video=new Video(320,240) ;
video.attachNetStream(ns);
ns.play("red5");
addChild(video);
}
}
}
服务端:
package com.conjs;
import org.red5.server.adapter.MultiThreadedApplicationAdapter;
import org.red5.server.api.IConnection;
import org.red5.server.api.Red5;
import org.red5.server.api.stream.IBroadcastStream;
import org.red5.server.api.stream.IStreamCapableConnection;
import org.red5.server.api.stream.support.SimpleConnectionBWConfig;
public class OtherApplication extends MultiThreadedApplicationAdapter {
@Override
public void streamPublishStart(IBroadcastStream stream) {
IConnection conn=Red5.getConnectionLocal();
measureBandwidth(conn);
if (conn instanceof IStreamCapableConnection) {
IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
SimpleConnectionBWConfig bwConfig = new SimpleConnectionBWConfig();
bwConfig.getChannelBandwidth()[3] = 1048576L;
bwConfig.getChannelInitialBurst()[3] = 131072L;
streamConn.setBandwidthConfigure(bwConfig);
super.streamPublishStart(stream);
}
}
@Override
public void streamBroadcastClose(IBroadcastStream arg0) {
super.streamBroadcastClose(arg0);
}
}
以下是官方在 H.264 和 1080P 方面支持的Demo ,我没有测试过,代码如下:
package org.red5.demos.oflaDemo;
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IBandwidthConfigure;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.stream.IServerStream;
import org.red5.server.api.stream.IStreamCapableConnection;
import org.red5.server.api.stream.support.SimpleConnectionBWConfig;
public class Application extends ApplicationAdapter {
private IScope appScope;
private IServerStream serverStream;
public boolean appStart(IScope app) {
appScope = app;
return true;
}
public boolean appConnect(IConnection conn, Object[] params) {
measureBandwidth(conn);
if (conn instanceof IStreamCapableConnection) {
SimpleConnectionBWConfig bwConfig = new SimpleConnectionBWConfig();
bwConfig.getChannelBandwidth()[IBandwidthConfigure.OVERALL_CHANNEL] =
1024 * 1024;
bwConfig.getChannelInitialBurst()[IBandwidthConfigure.OVERALL_CHANNEL] =
128 * 1024;
bwConfig.setUpstreamBandwidth(1024 * 1024);
}
return super.appConnect(conn, params);
}
public void appDisconnect(IConnection conn) {
if (appScope == conn.getScope() && serverStream != null) {
serverStream.close();
}
super.appDisconnect(conn);
}
}