예제 #1
0
        private static void Cleanup()
        {
            Logger.WARN("Shutting down protocols manager");
            ProtocolManager.Shutdown();
            ProtocolManager.CleanupDeadProtocols();

            Logger.WARN("Shutting down I/O handlers manager");
            IOHandlerManager.ShutdownIOHandlers();
            IOHandlerManager.DeleteDeadHandlers();
            IOHandlerManager.Shutdown();

            Logger.WARN("Unregister and delete default protocol handler");
            ProtocolFactoryManager.UnRegisterProtocolFactory(_protocolFactory);

            Logger.WARN("Shutting down applications");
            ClientApplicationManager.Shutdown();

            Logger.WARN("Delete the configuration");

            _configFile = null;

            //Logger.WARN("Doing final OpenSSL cleanup");
            //CleanupSSL();

            Logger.WARN("Shutting down the logger leaving you in the dark. Bye bye... :(");
            Console.ReadKey();
        }
예제 #2
0
        public override bool SignalInputData(int recAmount)
        {
            var reader    = new StreamReader(InputBuffer);
            var firstLine = reader.ReadLine();
            var ss        = firstLine.Split(' ')[1].Split('/');

            ClientApplicationManager.SwitchRoom(this, ss[1] + (ss.Length == 4?"/" + ss[2]:""), Application.Configuration);
            var name = ss.Last().Split('.')[0];
            var pss  = ss.Last().Split('?');

            if (pss.Length == 2)
            {
                var ps = pss[1].GetURLParam();
            }
            var writer = new StreamWriter(OutputBuffer);

            writer.WriteLine("HTTP/1.1 200 OK");
            writer.WriteLine("Content-Type: video/mp4");
            writer.WriteLine("Connection = Keep-Alive");
            writer.WriteLine("Transfer-Encoding = chunked");
            writer.WriteLine("");
            var stream = new OutNetMP4RTMPStream(this, Application.StreamsManager, name)
            {
                Writer = writer
            };

            InputBuffer.IgnoreAll();
            return(true);
        }
예제 #3
0
 public void OnAppListSynchronization(DirtyInfo dirty)
 {
     if (dirty.Type == Defines.SOT_SC_UPDATE_DATA && Application.SOManager["appList"][dirty.PropertyName] != null)
     {
         var appId = Application.SOManager["appList"][dirty.PropertyName];
         Logger.INFO("sync applist:{0},{1}", dirty.PropertyName, appId);
         ClientApplicationManager.GetOrCreateRoom(dirty.PropertyName, appId);
         if (GotAppIdTasks.ContainsKey(dirty.PropertyName))
         {
             GotAppIdTasks[dirty.PropertyName](appId);
         }
     }
 }
예제 #4
0
        public static bool SignalProtocolCreated(BaseProtocol protocol, Variant customParameters)
        {
            var application = ClientApplicationManager.FindAppByName(customParameters[Defines.CONF_APPLICATION_NAME]);

            if (application == null)
            {
                Logger.FATAL("Application {0} not found", customParameters[Defines.CONF_APPLICATION_NAME]);
                return(false);
            }
            if (protocol == null)
            {
                Logger.WARN("OutboundCluster Connection failed:{0}", customParameters.ToString());

                application.GetProtocolHandler <SlaveClusterAppProtocolHandler>().ReconnectTimer.Start();
                return(false);
            }
            protocol.CustomParameters = customParameters;
            protocol.Application      = application;
            return(true);
        }
예제 #5
0
        public static bool SignalProtocolCreated(BaseProtocol protocol, Variant customParameters)
        {
            var application = ClientApplicationManager.FindAppByName(customParameters[Defines.CONF_APPLICATION_NAME]);

            if (application == null)
            {
                Logger.FATAL("Application {0} not found", customParameters[Defines.CONF_APPLICATION_NAME]);
                return(false);
            }
            if (protocol == null)
            {
                Logger.FATAL("Connection failed:{0}", customParameters.ToString());
                return(application.OutboundConnectionFailed(customParameters));
            }
            protocol.Application = application;
            var outboundRTMPProtocol = protocol as OutboundRTMPProtocol;

            outboundRTMPProtocol.CustomParameters = customParameters;
            return(outboundRTMPProtocol.SignalInputData(0));
        }
예제 #6
0
        public override bool OnConnection(Session session, Variant parameters, AMFObjectWriter response)
        {
            string appName = parameters[0][Defines.RM_INVOKE_PARAMS_CONNECT_APP];
            //var parameters = pFrom.CustomParameters;
            //var instanceName = index == -1?"_default_": appName.Substring(index + 1);
            var oldApplication = Application;
            var newApp         = ClientApplicationManager.SwitchRoom(this, appName, Application.Configuration);

            if (newApp != null && newApp != oldApplication)
            {
                var handler = newApp.GetProtocolHandler <BaseRtmfpAppProtocolHandler>(this);
                return(handler.CurrentProtocol.OnConnection(session, parameters, response));
            }

            if (newApp == null || (newApp == oldApplication && !Application.OnConnect(session, parameters)))
            {
                return(false);
            }

            return(true);
        }
예제 #7
0
        protected override void OnReceive(ClusterMessageType type)
        {
            string         streamName;
            uint           appId;
            StreamsManager streamManager;

            switch (type)
            {
            case ClusterMessageType.GetAppId:
                var appName = InputBuffer.Reader.ReadString();
                ClientApplicationManager.GetOrCreateRoom(appName);    //创建房间自动广播appId
                break;

            case ClusterMessageType.Publish:

                appId      = InputBuffer.Reader.Read7BitValue();
                streamName = InputBuffer.Reader.ReadString();
                var streamType  = InputBuffer.Reader.ReadUInt64();
                var streamId    = InputBuffer.Reader.Read7BitValue();
                var chunkSize   = InputBuffer.Reader.Read7BitValue();
                var publishType = InputBuffer.Reader.ReadString();

                streamManager = GetRoom(appId).StreamsManager;
                var getWaitings = streamManager.GetWaitingSubscribers(streamName, streamType);
                var inStream    = new InClusterStream(appId, this, streamName, streamType, chunkSize);
                InStreams[streamId] = inStream;
                foreach (var pBaseOutStream in getWaitings)
                {
                    pBaseOutStream.Link(inStream);
                }
                if (publishType == "append" || publishType == "record")
                {
                    streamManager.CreateOutFileStream(this, inStream, publishType == "append");
                }
                Application.GetProtocolHandler <BaseClusterAppProtocolHandler>().PublishStream(appId, inStream, publishType);
                break;

            case ClusterMessageType.NoSubscriber:
                appId         = InputBuffer.Reader.Read7BitValue();
                streamName    = InputBuffer.Reader.ReadString();
                streamManager = GetRoom(appId).StreamsManager;
                foreach (var streams in streamManager.FindByTypeByName(StreamTypes.ST_OUT_NET_CLUSTER, streamName, false, false).Values)
                {
                    streams.Dispose();
                }
                break;

            case ClusterMessageType.Play:
                appId         = InputBuffer.Reader.Read7BitValue();
                streamName    = InputBuffer.Reader.ReadString();
                streamManager = GetRoom(appId).StreamsManager;
                Logger.INFO(appId + ":Play:" + streamName);
                foreach (var streams in streamManager.FindByTypeByName(StreamTypes.ST_IN, streamName, true, false).Values)
                {
                    PublishStream(appId, streams as IInStream);
                }
                break;

            default:
                base.OnReceive(type);
                break;
            }
        }