コード例 #1
0
ファイル: Program.cs プロジェクト: bozang/ZLMediaKit
        private static void StartMain()
        {
            try
            {
                mediaServerConfig           = new MediaServerConfig();
                mediaServerConfig.Ipaddress = System.Configuration.ConfigurationManager.AppSettings["sms_ipaddress"];
                mediaServerConfig.weight    = int.Parse(System.Configuration.ConfigurationManager.AppSettings["weight"]);
                redisAddress        = System.Configuration.ConfigurationManager.AppSettings["cms_ipaddress"];
                mediaKeepLiveSecond = int.Parse(System.Configuration.ConfigurationManager.AppSettings["media_keeplive_second"]);
                smsMsg = "sms_" + mediaServerConfig.Ipaddress + "_" + mediaServerConfig.weight;
                string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini");
                DoMedia.MEDIA_PORT_START_STATIC = int.Parse(System.Configuration.ConfigurationManager.AppSettings["udp_start_port"]);
                DoMedia.MEDIA_PORT_START        = int.Parse(System.Configuration.ConfigurationManager.AppSettings["udp_start_port"]);
                DoMedia.MEDIA_PORT_END          = int.Parse(System.Configuration.ConfigurationManager.AppSettings["udp_end_port"]);
                ushort ret = MediaInit(configPath);
                RegisterEvent();
                Task.Run(() => media_source_no_reader_check());
                //AddStreamProxy();
#if useRedis
                InitRedis();
                try
                {
                    RedisHelper.GetDatabase().StringSet(smsMsg, httpServerPort);
                    Task.Factory.StartNew(new Action(KeepLive));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("未能连接上redis,仅支持部分功能测试");
                }
                string str = url + ":" + httpServerPort + "/";
                nancyHost = new NancyHost(new Url(str));
                nancyHost.Start();
                Console.WriteLine("开始监听服务端口:" + httpServerPort);
#else
                ret = MediaServer.mk_rtp_server_start(20000, "34020000001320000001");
#endif
                Console.Read();
                MediaServer.mk_stop_all_server();
#if useRedis
                nancyHost.Stop();
#endif
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                Console.Read();
            }
        }
コード例 #2
0
ファイル: DoMedia.cs プロジェクト: bozang/ZLMediaKit
        public static string StartRealPlay(string channelCode)
        {
            try
            {
                if (dic_playProxy_media.ContainsKey(GetKeyGb(channelCode)))
                {
                    return(channelCode + ":已经在拉流");
                }
                dic_playProxy_media.Add(GetKeyGb(channelCode), new MediaCache()
                {
                    ctx = IntPtr.Zero, mediaSrcType = MediaSrcType.gb
                });

                int[]  port = SetMediaPort();
                ushort ret  = MediaServer.mk_rtp_server_start((ushort)port[0], channelCode);
                return(ret.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(0.ToString());
            }
        }