Ejemplo n.º 1
0
        /// <summary>
        /// 启动直播
        /// </summary>
        /// <param name="param"></param>
        public LivingcastTask(LivingcastStartParam param)
        {
            StartParam = param;

            if (!config.ContainsKey("fms_ip"))
            {
                config["fms_ip"] = "127.0.0.1";
            }

            if (!config.ContainsKey("cloud_ip"))
            {
                config["cloud_ip"] = "127.0.0.1";
            }

            if (!config.ContainsKey("cloud_port"))
            {
                config["cloud_port"] = "80";
            }

            if (!config.ContainsKey("teacher"))
            {
                config["teacher"] = "admin";
            }

            if (!config.ContainsKey("grade"))
            {
                config["grade"] = "";
            }

            if (!config.ContainsKey("domain"))
            {
                config["domain"] = "space.whhc";
            }

            if (!config.ContainsKey("device_id"))
            {
                config["device_id"] = "000000000000";
            }

            if (!config.ContainsKey("title"))
            {
                config["title"] = "互动";
            }

            Streams = new List <LivingcastStream>();
            foreach (LivingcastStreamDesc desc in param.streams)
            {
                string rtmp_url = build_rtmp_livingcast_url(param.mcu_cid, desc);
                Streams.Add(new LivingcastStream(param.mcu_jid, param.mcu_cid, desc.aid, desc.vid, rtmp_url));
            }

            // 发布到nabo平台
            SendStart(param.uuid);

            th_ = new Thread(new ParameterizedThreadStart(proc_HeartBeat));
            th_.Start(new Params()
            {
                machine_id = config["device_id"], uuid = param.uuid,
            });
        }
Ejemplo n.º 2
0
        static LivingcastStartParam parse_cmd_node(XmlElement node, string mcu_jid, int mcu_cid)
        {
            // 根据 cmd node 构造 LivingcastStartParam

            XmlNode uuid = null, subject = null, streams = null;

            foreach (XmlNode c in node.ChildNodes)
            {
                if (c.Name == "uuid")
                {
                    uuid = c;
                }
                else if (c.Name == "subject")
                {
                    subject = c;
                }
                else if (c.Name == "streams")
                {
                    streams = c;
                }
            }

            if (uuid == null || subject == null || streams == null)
            {
                return(null);
            }

            LivingcastStartParam param = new LivingcastStartParam();

            param.uuid    = uuid.InnerText;
            param.subject = subject.InnerText;
            foreach (XmlNode s in streams.ChildNodes)
            {
                if (s.Name != "stream")
                {
                    continue;
                }
                LivingcastStreamDesc d = parse_stream_node(s);
                if (d != null)
                {
                    param.streams.Add(d);
                }
            }

            param.mcu_cid = mcu_cid;
            param.mcu_jid = mcu_jid;

            return(param);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// body 为 xml 格式
        ///  <zonekey app="record_livingcast_service">
        ///     <cmd command="livingcast_start">
        ///         <uuid>xxxxx</uuid>   与录像一致
        ///         <subject>xxxx</subject> 与录像一致
        ///         <streams>
        ///             <stream>
        ///                 <aid>xx</aid>   音频
        ///                 <vid>xxx</vid> 视频
        ///             </stream>
        ///         </streams>
        ///     </cmd>
        ///     <mcu>
        ///         <jid>xxx</jid>
        ///         <cid>xxx</cid>
        ///     </mcu>
        ///  </zonekey>
        ///
        /// </summary>
        /// <param name="req"></param>
        /// <param name="res"></param>
        public static void Start(HttpListenerRequest req, HttpListenerResponse res)
        {
            string     command, mcu_jid;
            int        mcu_cid;
            XmlElement node;

            string body_b64 = Utility.BodyFromStream.read(req.InputStream, req.ContentLength64, Encoding.ASCII);
            string body     = Encoding.UTF8.GetString(Convert.FromBase64String(body_b64));

            if (body == null)
            {
                Console.WriteLine("Record.Start: Net broken!");
                return;
            }

            Log.log("Livingcast_Start: xml=" + body);

            if (Utility.BodyParser.parse(body, out command, out node, out mcu_jid, out mcu_cid))
            {
                if (command != "livingcast_start")
                {
                    format_error(res);
                    return;
                }
                LivingcastStartParam start_param = parse_cmd_node(node, mcu_jid, mcu_cid);
                if (start_param == null)
                {
                    format_error(res);
                    return;
                }

                // 这里启动 ....
                lock (LivingcastTasks) {
                    if (LivingcastTasks.ContainsKey(mcu_cid))
                    {
                        livingcast_exist(res);
                        return;
                    }
                }

                LivingcastTask task = new LivingcastTask(start_param);
                lock (LivingcastTasks) {
                    LivingcastTasks.Add(mcu_cid, task);
                }

                done(res, "ok");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 启动直播
        /// </summary>
        /// <param name="param"></param>
        public LivingcastTask(LivingcastStartParam param)
        {
            StartParam = param;

            if (!config.ContainsKey("fms_ip"))
                config["fms_ip"] = "127.0.0.1";

            if (!config.ContainsKey("cloud_ip"))
                config["cloud_ip"] = "127.0.0.1";

            if (!config.ContainsKey("cloud_port"))
                config["cloud_port"] = "80";

            if (!config.ContainsKey("teacher"))
                config["teacher"] = "admin";

            if (!config.ContainsKey("grade"))
                config["grade"] = "";

            if (!config.ContainsKey("domain"))
                config["domain"] = "space.whhc";

            if (!config.ContainsKey("device_id"))
                config["device_id"] = "000000000000";

            if (!config.ContainsKey("title"))
                config["title"] = "互动";

            Streams = new List<LivingcastStream>();
            foreach (LivingcastStreamDesc desc in param.streams) {
                string rtmp_url = build_rtmp_livingcast_url(param.mcu_cid, desc);
                Streams.Add(new LivingcastStream(param.mcu_jid, param.mcu_cid, desc.aid, desc.vid, rtmp_url));
            }

            // 发布到nabo平台
            SendStart(param.uuid);

            th_ = new Thread(new ParameterizedThreadStart(proc_HeartBeat));
            th_.Start(new Params() { machine_id = config["device_id"], uuid = param.uuid, });
        }
Ejemplo n.º 5
0
        static LivingcastStartParam parse_cmd_node(XmlElement node, string mcu_jid, int mcu_cid)
        {
            // 根据 cmd node 构造 LivingcastStartParam

            XmlNode uuid = null, subject = null, streams = null;
            foreach (XmlNode c in node.ChildNodes) {
                if (c.Name == "uuid")
                    uuid = c;
                else if (c.Name == "subject")
                    subject = c;
                else if (c.Name == "streams")
                    streams = c;
            }

            if (uuid == null || subject == null || streams == null) return null;

            LivingcastStartParam param = new LivingcastStartParam();
            param.uuid = uuid.InnerText;
            param.subject = subject.InnerText;
            foreach (XmlNode s in streams.ChildNodes) {
                if (s.Name != "stream") continue;
                LivingcastStreamDesc d = parse_stream_node(s);
                if (d != null)
                    param.streams.Add(d);
            }

            param.mcu_cid = mcu_cid;
            param.mcu_jid = mcu_jid;

            return param;
        }