zoukankan      html  css  js  c++  java
  • Red5实现直播

    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); 
        } 
    }

  • 相关阅读:
    .NET Core/.NET5/.NET6 开源项目汇总7:电商项目
    .NET Core/.NET5/.NET6 开源项目汇总6:框架与架构设计(DDD、云原生/微服务/容器/DevOps/CICD等)项目
    .NET Core/.NET5/.NET6 开源项目汇总5:(权限)管理系统项目
    .NET Core/.NET5/.NET6 开源项目汇总4:CMS、Blog项目
    .NET Core/.NET5/.NET6 开源项目汇总3:工作流组件
    .NET Core/.NET5/.NET6 开源项目汇总2:任务调度组件
    .NET Core/.NET5/.NET6 开源项目汇总1:常用必备组件
    .NET平台系列31:.NET团队送给.NET开发人员的云原生学习资源汇总
    .NET平台系列30:.NET Core/.NET 学习资源汇总
    .NET平台系列29:.NET Core 跨平台奥秘
  • 原文地址:https://www.cnblogs.com/jukan/p/5289358.html
Copyright © 2011-2022 走看看