Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        static void AddStreamProxyTest()
        {
            try
            {
                mediaServerConfig = new MediaServerConfig();
                string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini");
                ushort ret        = MediaInit(configPath);
                Console.WriteLine("初始化完成");
                RegisterEvent();
                Console.WriteLine("事件注册完成");
                int i = 0;
                foreach (var item in System.Configuration.ConfigurationManager.AppSettings.AllKeys)
                {
                    if (item.Contains("rtspurl"))
                    {
                        i++;
                        string stream = "live" + i.ToString();
                        string url    = System.Configuration.ConfigurationManager.AppSettings[item];
                        Console.WriteLine("开始拉流:" + url);
                        IntPtr playProxy = MediaServer.mk_proxy_player_create("__defaultVhost__", "fh", stream, 1, 0);
                        //rtsp://admin:123456a%[email protected]:554/h264/ch33/main/av_stream
                        MediaServer.mk_proxy_player_play(playProxy, url);
                        Task.Run(() => media_source_no_reader_check());
                    }
                }


                //IntPtr playProxy = MediaServer.mk_proxy_player_create("__defaultVhost__", "fh", "live1", 1, 0);
                ////rtsp://admin:123456a%[email protected]:554/h264/ch33/main/av_stream
                //MediaServer.mk_proxy_player_play(playProxy, "rtsp://*****:*****@10.128.23.51:554/h264/ch33/main/av_stream");
                //IntPtr playProxy1 = MediaServer.mk_proxy_player_create("__defaultVhost__", "fh", "live2", 1, 0);
                //MediaServer.mk_proxy_player_play(playProxy1, "rtsp://*****:*****@10.128.23.67:554/h264/ch33/main/av_stream");
                Console.Read();
                MediaServer.mk_stop_all_server();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                Console.Read();
            }
        }